akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
struct aa {
	int x;
	int y;
	int time;
};
class Compare {
public :
	bool operator()(const aa&l, const aa&r) {
		return l.time > r.time;
	}
};
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
	while (1) {
		int W, H; cin >> W >> H;
		if (!W)break;
		vector<vector<int>>field(H,vector<int>(W));
	
		for (int i = 0; i <H; ++i) {
			string st; cin >> st;
			for (int j = 0; j < W; ++j) {
				if (st[j] == '&')field[i][j] = 2;
				else if (st[j] == '.')field[i][j] = 1;
				else field[i][j] = 0;
			}
		}
		priority_queue<aa, vector<aa>, Compare>que;
		vector<vector<int>>memo(H, vector<int>(W, 1e8));
		for (int i = 0; i < H; ++i) {
			{
				int j = 0;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;

				j = W - 1;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;
			}
		}
		for (int j = 0; j < W; ++j) {
			{
				int i = 0;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;

				i= H - 1;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;
			}
		}
		int ans = -1;
		while (!que.empty()) {
			aa atop(que.top());
			if (field[atop.y][atop.x] == 2) {
				ans = atop.time;
				break;
			}
			que.pop();
			for (int way = 0; way < 4; ++way) {
				const int nextx = atop.x + dx[way];
				const int nexty = atop.y + dy[way];
				if (nextx < W&&nextx >= 0 && nexty >= 0 && nexty < H) {
					const int nexttime = atop.time + (field[nexty][nextx] && !field[atop.y][atop.x]);
					if (memo[nexty][nextx] > nexttime) {
						memo[nexty][nextx] = nexttime;
						que.push(aa{ nextx,nexty,nexttime });
					}
				}
			}
		}
		cout << ans << endl;
		
	}

	return 0;
}

Measured memory_bytes: 3124
import Control.Monad
main=do
 [n,m]<-map read.words<$>getLine
 ed<-replicateM m (map ((\n->n-1).read).words<$>getLine)
 print(f n ed [(0,take n (repeat 0))] 0)
  where f _ _ [] ans = ans
        f n ed ((ve,arc):st) ans = f n ed ((g ve arc ed)++st) (if (sum arc)==(n-1) then (ans+1) else ans)
        g ve arc [] = []
        g ve arc ([a,b]:ed) | ve==a = if (arc!!b)==0 then ((h ve b arc):(g ve arc ed)) else (g ve arc ed)
                            | ve==b = if (arc!!a)==0 then ((h ve a arc):(g ve arc ed)) else (g ve arc ed)
                            |otherwise = g ve arc ed
        h ve a arc = (a,(take ve arc)++(1:(drop (ve+1) arc)))

Measured memory_bytes: 1020
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())
    res = 0
    cnt = 1
    while cnt<=n:
        if cnt <= k:
            res += x
        else:
            res += y
        cnt += 1
    print(res)

if __name__ == '__main__':
    main()

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

struct data {
	llong place;
	llong cost;

	data() {};
	data(llong place, llong cost) :
		place(place),
		cost(cost)
	{}

	bool operator<(const data &ri) const {
		return cost < ri.cost;
	}
	bool operator<=(const data &ri) const {
		return cost <= ri.cost;
	}
	bool operator>(const data &ri) const {
		return cost > ri.cost;
	}
};

vector<vector<data> > edges;

vector<data> dijkstra(int start) {
	priority_queue<data, vector<data>, greater<data> > que;
	vector<data> dis(edges.size(), data(-1, inf));
	dis[start] = data(start, 0);

	que.push(dis[start]);
	while (que.size()) {
		data now = que.top();
		que.pop();
		if (dis[now.place] < now) continue;

		for (auto &edge: edges[now.place]) {
			data next(edge.place, now.cost + edge.cost);
			if(dis[next.place] <= next) continue;
			dis[next.place] = next;
			que.push(next);
		}
	}

	return dis;
}


int main() {
	llong n;
	llong u, k, v, c;

	cin >> n;
	edges.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v >> c;
			edges[u].push_back(data(v, c));
		}
	}

	auto ans = dijkstra(0);
	for (int i = 0; i < n; ++i) {
		cout << i << " " << ans[i].cost << endl;
	}

	return 0;
}


Measured memory_bytes: 11924
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, Q; cin >> N >> Q;
    vector<tuple<int, int, int>> A(N);
    vector<int> D(Q);
    for (int i = 0; i < N; i++) {
        int S, T, X; cin >> S >> T >> X;
        A[i] = make_tuple(X, S, T);
    }
    for (auto &d : D) cin >> d;
    sort(rbegin(A), rend(A));
    map<int, int> M;
    M[0] = -1;
    for (int i = 0; i < N; i++) {
        int S, T, X; tie(X, S, T) = A[i];
        int s = S - X;
        int t = T - X;
        if (s < 0) s = 0;
        if (t < 0) t = 0;
        if (s == t) continue;
        int k = prev(M.upper_bound(t))->second;
        M[t] = k;
        M[s] = X;
        M.erase(next(M.find(s)), M.find(t));
    }
    for (auto d : D) {
        cout << prev(M.upper_bound(d))->second << '\n';
    }
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int>x(n);
  int sum=0;
  int d_sum=0;
  rep(i,n){
    cin>>x.at(i);
    sum+=x.at(i);
    d_sum+=pow(x.at(i),2);
    
  }
  int ans=1000000;
  for(int i=1;i<=100;i++){
    int p=i;
    int pa=d_sum-2*sum*p+n*p*p;
    ans=min(pa,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc123/tasks/abc123_c

import java.util.Scanner;

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

        long N = sc.nextLong();

        long min = Long.MAX_VALUE;
        long[] list = new long[5];
        for (int i = 0; i < 5; i++) {
            list[i] = sc.nextLong();
            if (list[i] < min) {
                min = list[i];
            }
        }

        System.out.println((long)Math.ceil(N/(double)min) + 4);
    }
}

Measured memory_bytes: 22996
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int d[] = fs.nextIntArray(n);
		Arrays.sort(d);
		if(n%2!=0) {
			System.out.println(0);
			return;
		}
		int m = n/2;
		int ans = d[m] - d[m-1];
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

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

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

Measured memory_bytes: 35324
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int A[310][310];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, N) {
        rep(j, M) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    int ans = N;
    bool used[310];
    rep(i, M) used[i] = true;
    rep(k, M - 1) {
        int cnt[310] = {};
        int tmp = 0;
        int idx = 0;
        rep(i, N) {
            rep(j, M) {
                if(!used[A[i][j]]) continue;
                cnt[A[i][j]]++;
                if(cnt[A[i][j]] > tmp) {
                    tmp = cnt[A[i][j]];
                    idx = A[i][j];
                }
                break;
            }
        }
        ans = min(ans, tmp);
        used[idx] = false;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    int ans=0;
    rep(i,3) if(S[i]=='o') ans++;
    cout << 700+ans*100 << endl;
    return 0;
}


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

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    //sort(A.begin(), A.end());
    //reverse(A.begin(), A.end());

    int total = 0;
    rep(i, N) total += A[i];

    if(total >= H) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 640
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let nkq = lines.next().unwrap().unwrap();
    let mut nkq = nkq.split_whitespace();
    let n: usize = nkq.next().unwrap().parse().unwrap();
    let k: i32 = nkq.next().unwrap().parse().unwrap();
    let q: i32 = nkq.next().unwrap().parse().unwrap();
    let mut a = vec![k - q; n + 1];
    for _ in 0..q {
        let i: usize = lines.next().unwrap().unwrap().parse().unwrap();
        a[i] += 1;
    }
    for &a_i in a.iter().skip(1) {
        if a_i > 0 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 4732
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    int N, H, Max;
    cin >> N >> Max;
    string ans = "Yes";

    for (int i = 1; i < N; i++) {
        cin >> H;
        if (H  < Max -1) {
            ans = "No";
            break;
        }
        else {
            Max = max(Max, H);
        }
    }

    cout << ans;

    return 0;

}



Measured memory_bytes: 256
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

mi = 10**15
for i in make_divisors(n):
    a = i;b = n//i
    mi = min(mi,a+b-2)

print(mi)

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll a,b;
     cin>>a>>b;
     ll i,ct=0;

     ll x=a;
     while(x<=b)
     {
         x = x*2;
         ct++;
     }
     cout<<ct<<endl;
}


Measured memory_bytes: 256
def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    K = int(buflist[1])
    edge = dict()
    for i in range(N):
        edge[i] = set()
        for j in range(i+1, N):
            edge[i].add(j)
    removed = 0
    for i in range(N):
        for j in range(i+1, N-1):
            if removed < K:
                edge[i].remove(j)
                removed += 1
    if removed < K:
        print(-1) # impossible
        return
    print((N * (N - 1)) // 2 - K)
    for i in range(N):
        for x in edge[i]:
            print(i+1, x+1)

if __name__ == '__main__':
    main()


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

int main(void) {
  int n;
  cin >> n;
  vector<int> as(n);
  for (int &a : as) cin >> a;
  int q;
  cin >> q;
  vector<int> bs(q);
  vector<int> cs(q);
  for (int i = 0; i < q; i++) {
    cin >> bs[i] >> cs[i];
  }

  vector<int> count(100000);
  long long total = 0;

  for (const int &a : as) {
    count[a]++;
    total += a;
  }
  
  for (int i = 0; i < q; i++) {
    total += count[bs[i]] * (cs[i] - bs[i]);
    count[cs[i]] += count[bs[i]];
    count[bs[i]] = 0;

    cout << total << endl;
  }

  return 0;
}

Measured memory_bytes: 4712
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        string s;
        cin >> s;
        ll dp[4] = {0};
        ll ans = 0;
        for(i = 0; i < 3; i++){
            if(s[i] == 'R'){
                dp[i + 1] = dp[i] + 1;
                ans = max(ans, dp[i + 1]);
            }
        }
        cout << ans;
    }
    return 0;
}

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

int n,a;
vector<int> c, rui;

bool f(int x,int k){
    auto it = lower_bound(c.begin(), c.end(), x);
    int i = (int)(it - c.begin()) - 1;
    return (!x) || (n-i) + rui[i] / x >= k;
}

signed main(){
    cin >> n;
    c.resize(n+1);
    REP(i,n){
        cin >> a;
        c[a]++;
    }
    sort(c.begin(), c.end());
    rui.resize(n+1);
    REP(i,n) rui[i+1] = rui[i] + c[i+1];

    int ans = n;
    REP(i,n){
        while(!f(ans, i+1)) ans--;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <ctime>
#include <string>
#include <cstring>
#include <random>
#define mp make_pair
#define pb push_back
#define NAME ""
#define y1 y1_423
#define list lista

using namespace std;

typedef long long ll;
typedef long double ld;

template<typename T>
ostream& operator << (ostream& cout, const vector<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "()");
	}
	cout << "(" << a[0];
	for (int i = 1; i < (int)a.size(); i++) {
		cout << "; " << a[i];
	}
	return (cout << ")");
}

template<typename T>
ostream& operator << (ostream& cout, const set<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T>
ostream& operator << (ostream& cout, const multiset<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T1, typename T2>
ostream& operator << (ostream& cout, const pair<T1, T2> &a) {
	return cout << "(" << a.first << "; " << a.second << ")";
}

random_device gen;
mt19937 rnd(gen());

const int nmax = 2000;
const int inf = 2000 * 1000 * 1000;
const ll infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const ld pi = acos(-1.0);

int n, m, k, answer[nmax][nmax], sz[nmax * nmax];

int main() {
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	//freopen(NAME".in", "r", stdin);freopen(NAME".out", "w", stdout);
	cin >> n >> m >> k;
	for (int i = 0; i < k; i++) {
		scanf("%d", &sz[i]);
	}
	int ind = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < m; j++) {
				while (!sz[ind]) ind++;
				sz[ind]--;
				answer[i][j] = ind + 1;
			}
		} else {
			for (int j = m - 1; j >= 0; j--) {
				while (!sz[ind]) ind++;
				sz[ind]--;
				answer[i][j] = ind + 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			printf("%d ", answer[i][j]);
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 4480
n = int(input())
"""
6:3
3141:13
314159265358:9
"""
#約分
def make_divisors(n):  
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
r = len(make_divisors(n-1)) - 1
w = make_divisors(n)
for wi in w:
  if wi == 1:
    continue
  i = 1
  while n % (wi**i) == 0:
    i += 1
  if (n / (wi**(i-1))) % wi == 1:
    r += 1
print(r)

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	vector<int> X;
	int ans = INF;
	
	cin>>N;
	
	X.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>X[i];
	}
	
	for(int i = 0; i < 200; i++){
		int sum = 0;
		
		for(int j = 0; j < N; j++){
			sum += (X[j] - i) * (X[j] - i);
		}
		
		ans = min(ans, sum);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

#define MAX 2002
#define MOD 1000000007

long long int dp[MAX][MAX];

#define MOD 1000000007
class Combination{
	long long int ppow(long long int i, long long int j){
		long long int res = 1LL;
		while (j){
			if ((j & 1LL)){
				res *= i;
				if (res >= MOD){
					res %= MOD;
				}
			}
			j >>= 1;
			i *= i;
			if (i >= MOD){
				i %= MOD;
			}
		}
		return res;
	}
public:
	vector<long long int> k;
	vector<long long int> r;
	void resize(int N){
		k.resize(N + 2);
		r.resize(N + 2);
		k[0] = 1;
		for (int i = 1; i < k.size(); i++){
			k[i] = k[i - 1];
			k[i] *= i;
			if (k[i] >= MOD)k[i] %= MOD;
		}
		for (int i = 0; i < r.size(); i++){
			r[i] = ppow(k[i], MOD - 2);
		}
	}
	long long int C(int a, int b){
		if (a < b)return 0;
		while (k.size() <= a){
			k.push_back((k.back()*(long long int)(k.size())) % MOD);
		}
		long long int up = k[a];
		long long int dw = r[b] * r[a - b];
		dw %= MOD;
		up *= dw;
		up %= MOD;
		return up;
	}
	long long int H(int a, int b){
		return C(a + b - 1, b);
	}
	long long int catalan_number(int n){
		return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD;
	}
};


Combination C;
int main(){
	int n;
	int k;
	cin >> n >> k;
	C.resize(2002*2002);
	dp[0][0] = 1;
	if (k == 1){
		puts("1");
		return 0;
	}
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= n; j++){
			dp[i + 1][j] += dp[i][j];
			if (dp[i + 1][j] >= MOD){
				dp[i + 1][j] %= MOD;
			}
			if (j + 1 <= i){
				dp[i][j + 1] += dp[i][j] * C.C(n*k-((k-2)*j+j+i+1), k-2);
				if (dp[i][j + 1] >= MOD){
					dp[i][j + 1] %= MOD;
				}
			}
		}
	}
	long long int ans = dp[n][n]*C.k[n];
	if (ans >= MOD)ans %= MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 94208
#include <stdio.h>

typedef unsigned long long int ULLI;

ULLI y(ULLI, ULLI);

int main() {
	ULLI a, b, c, d, e;
	ULLI sum = 0;

	scanf("%llu %llu %llu %llu", &a, &b, &c, &d);

	a--;
    e = y(c, d);

	sum = b - a;

	sum -= (b / c - a / c);
	sum -= (b / d - a / d);
	sum += (b / e - a / e);

	printf("%llu\n", sum);

	return 0;
}

ULLI y(ULLI a, ULLI b)
{
	ULLI r, x, tmp;

    x = a * b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }


    return (x / b);
}

Measured memory_bytes: 128
/*
  大文字と小文字に入れ替え
  (与えられた文字列の小文字と大文字を入れ替えるプログラム)
  2018/02/13
*/

#include<stdio.h>
int main(void){
  char str[1200];
  int i=0;
  while(1){
    scanf("%c",&str[i]);
    if(str[i] == '\n')
      break;
    if('A' <= str[i] && str[i] <= 'Z'){
      str[i] += 32;
    }
    else{
      if('a' <= str[i] && 'z'>= str[i]){
	str[i] = str[i] - 32;
      }
    }
    printf("%c",str[i]);
    i++;
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2044
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

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

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


const int NM = 1000;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//ll P[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//ll dp[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//int B[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//double Perf[NM];

ll MOD = 1000000007;
int digit_length(int num)
{
    int count = 0;
    while (num) {
        num = num / 10;
        ++count;
    }
    return count;
}


ll gcd(ll a, ll b) {
    ll v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0) {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    };
    return v1;
}


// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

ll lcm(ll a, ll b) {
    return( (a % MOD) *modinv(gcd(a, b), MOD) * (b % MOD)) % MOD;
}
       // Main program


struct Info
{
    int A;
    int B;
    double Perf;

    bool operator<(const Info& another) const
    {
        return Perf == another.Perf ? A < another.A : Perf < another.Perf;//年齢を比較
    };
    //2つのconstを付けないとコンパイルエラーになるので注意!!
};


void solve() {
  ll  N,X[100];
  cin >> N;
  ll min=0;
  
  for(int i=0;i<N;i++){
  	cin >> X[i];
    min += pow((X[i]),2);
  }

  ll tmp;
  for(int j=0;j<100;j++){
    tmp = 0;
    for(int i=0;i<N;i++){
      tmp += pow((X[i] - j),2);
    } 
    if(min >= tmp){
      min = tmp;
    }
  }

  cout << min;
  return;

}



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








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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

template<typename T1,typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 & a, T2 b) { if (a < b) a = b; }

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kMax9 = 1000000010;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, int n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

double dist(double lhs, double rhs) {
  return sqrt(lhs * lhs + rhs * rhs);
}

// int binary(int bina){
//   int ans = 0;
//   for (int i = 0; bina>0 ; i++)
//   {
//     ans = ans+(bina%2)*pow(10,i);
//     bina = bina/2;
//   }
//   return ans;
// }

const long km = 62;

long n, m, k, t;
string binary(ll dec){
  string s;
  while (dec > 0) {
    s.pb((dec % 2) + '0');
    dec /= 2;
  }
  auto j = km - long(s.size());
  rep(i, 0, j - 1) { s.pb('0'); }
  // reverse(s.begin(), s.end());
  return s;
}

ll exp2k(long x) {
  ll ans = 1;
  rep(i, 1, x) {
    ans = (ans * x) % kMod;
  }
  return ans;
}

int main() {
  ll ans = 0;
  long n, m, a, b, x, y;
  string s, t;
  vector<string> ss;
  vector<ll> aa;
  vector<ll> ba;
  vector<ll> xx;
  vector<ll> yy;

  cin >> a >> b;


  cout << 6 - a - b << endl;

  return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int n;
  cin >> n;
  vi A(n);
  rep(i, 0, n) {
    cin >> A[i];
    A[i]--;
  }


  set<int> s;
  s.insert(0);
  int cur = 0;
  int ans = 0;

  bool ok = false;
  while (1) {
    ans++;
    int nxt = A[cur];
    if (nxt == 1) {
      ok = true;
      break;
    }

    if (Find(s, nxt)) {
      break;
    } else {
      s.insert(nxt);
      cur = nxt;
    }
  }

  if (ok) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
};


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

cnt_1 = 0
for i in a:
    if i % 2 != 0:
        cnt_1 += 1

cnt_2 = 0
for i in a:
    if i % 2 == 0 and i % 4 != 0:
        cnt_2 += 1

cnt_4 = 0
for i in a:
    if i % 4 == 0:
        cnt_4 += 1

if cnt_4*2 + 1 >= n:
    print("Yes")
else:
    if cnt_4*2 + cnt_2 >= n:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 62576
S=input()[::-1]
l=[0]*2019
a=1
d=0

for s in S:
  d=d+int(s)*a
  l[d%2019]+=1
  a*=10
  a%=2019
  
ans=l[0]
for i in l:
  if i>=2:
    ans+=i*(i-1)//2
    
print(ans)

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int cnt[333333];

signed main(){
    cin>>N;
    rep(i,N){
        int a,b;
        cin>>a>>b;
        cnt[a+b]++;
    }

    for(int i=0;i<333333-1;i++){
        cnt[i+1]+=cnt[i]/2;
        cnt[i]%=2;
        if(cnt[i]){
            cout<<i<<" "<<0<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5656
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e6 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
int dx[] = {1, 0, -1, 0}; // {down , right , up , left}
int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
//int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; //Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

int k;

int main()
{
  //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  int gcd = 1;
  scanf("%d", &k);
  ll ans = 0;
  for (int a = 1; a <= k; ++a)
  {
    for (int b = 1; b <= k; ++b)
    {
      for (int c = 1; c <= k; ++c)
      {
        gcd = __gcd(a, __gcd(b , c));
        ans += gcd;
      }
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 3692
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        v: [i64; n],
    }
    let m = n as i64;
    let ans = v.iter().fold(0, |s, a| s + *a) - m * (m + 1) / 2;
    println!("{}", ans);
}

fn main() {
    run();
}



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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    long long cnt = 0;
    while (true) {
        long long s = 0;
        for (int i = 0; i < n; i++) {
            s += a.at(i) / n;
        }
        cnt += s;
        
        bool ok = true;
        for (int i = 0; i < n; i++) {
            a.at(i) = a.at(i) - a.at(i) / n * n + s - a.at(i) / n;
            if (a.at(i) >= n) ok = false;
        }
        if (ok) break;
    }
    cout << cnt << endl;
}

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

int main(void)
{
    intmax_t A, B;
    intmax_t ans = 0;

    scanf("%jd", &A);
    scanf("%jd", &B);

    ans = 6 - A - B;

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define re register
using namespace std;
const int maxn=17;
template<typename T> void read(T &x){
	T f=1;x=0;
	char c=getchar();
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	x*=f;
}
int n;
ll a[maxn][maxn];
ll f[1<<17];
ll pre[1<<17];
int main(){
	read(n);
	for(re int i=1;i<=n;i++){
		for(re int j=1;j<=n;j++){
			read(a[i][j]);
		}
	} 
	for(re int i=1;i<=(1<<n)-1;i++){
		for(re int j=1;j<=n;j++){
			for(re int k=1;k<=n;k++){
				if(i&(1<<(k-1)) && i&(1<<(j-1))){
					pre[i]+=a[j][k];
				}
			}
		}
	}
	for(re int i=1;i<=(1<<n)-1;i++){
		f[i]=pre[i];
		for(re int j=i;j;j=(j-1)&i){
			int k=j^i;
			f[i]=max(f[i],f[j]+f[k]);
		}
	}
	cout<<f[(1<<n)-1]/2<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int x[n];
  for (int i = 0; i < n; i++)
    cin >> x[i];
  
  sort(x, x+n);
  int beg = x[0], end = x[n-1];
  int ans;
  
  for (int i = 0; i < end-beg+1; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += pow((x[j]-(beg + i)), 2);
    }
    if (i == 0)
      ans = sum;
    else if (sum < ans)
      ans = sum;
  }
  cout << ans;
}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;
ll x, y, z, l, m, n, r, q, k;

void solve() {
    ll mdiff = LONG_LONG_MAX;
    string s;
    cin>>s; n = s.size();
    for(int i=0;i<n-2;i++){
        ll diff = abs(stoll(s.substr(i, 3))-753);
        mdiff = min(mdiff, diff);
    }
    cout<<mdiff<<'\n';

}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test = 1;
    while (test--) {
        solve();
    }
    return 0;
}

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

"""
・メモ化再帰
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import defaultdict

N, W = map(int, input().split())
wN = [0] * N
vN = [0] * N
for i in range(N):
    wN[i], vN[i] = map(int, input().split())

# memo[i][j]: i番目以降の品物から重さの和がj以下なるように選んだときの価値の和の最大値
memo = [defaultdict(lambda: -1) for i in range(N+1)]

def dfs(cur, wei):
    # 既に調べた場所はそのまま返却
    if memo[cur][wei] != -1:
        return memo[cur][wei]
    # 品物を最後まで見た
    if cur == N:
        res = 0
    # まだ余力があるから両方試す
    elif wei >= wN[cur]:
        res = max(dfs(cur+1, wei-wN[cur]) + vN[cur], dfs(cur+1, wei))
    # もうこの回の荷物は入らない
    else:
        res = dfs(cur+1, wei)
    # ここまでのベストな値をメモに記録してから返却
    memo[cur][wei] = res
    return res
# 0番目以降で容量W以下の場合の結果を表示
print(dfs(0, W))


Measured memory_bytes: 11104
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,l;
    cin>>n>>l;
    int sum = n*l + (n-1)*n / 2;
    if(l<=0 && l+n-1>=0) cout<<sum<<endl;
    else if(l>=0) cout<<sum-l<<endl;
    else
        cout<<sum-l-n+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, k, a = 0, b = 0, c = 0, d = 0; cin >> n >> k;
	a = k / 10000; b = k % 10000 / 5000; c = k % 5000 / 1000;
	d = a;
	if (a + b + c > n) {
		cout << "-1" << ' ' << "-1" << ' ' << "-1" << endl;
		return 0;
	}
	else if (a + b + c == n) {
		cout << a << ' ' << b << ' ' << c << endl;
		return 0;
	}
	else {
		for (int h = 0; h < 10000; h++) {
			if (a + b + c <= n - 9 && a != 0) {
				a--; c += 10;
			}
			else if (a + b + c <= n - 4 && b != 0) {
				b--; c += 5;
			}
			else if (a + b + c <= n - 1 && a != 0) {
				a--; b += 2;
			}
			if (a + b + c == n) {
				cout << a << ' ' << b << ' ' << c << endl;
				cin >> n; return 0;
			}
		}
	}
	cout << -1 << ' ' << -1 << ' ' << -1 << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

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

int main() {
    int N; cin >> N;
    ll Y; cin >> Y;
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N - i; ++j) {
            int k = N - i - j;
            if (10000 * i + 5000 * j + 1000 * k == Y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
n = int(input().strip())
A = [int(s) for s in input().strip().split()]
M = 10 ** 9 + 7

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

factors = [0] * 1001
large_factors = set()
for a in A:
    d = 0
    while a % 2 == 0:
        d += 1
        a //= 2
    factors[2] = max(factors[2], d)
    for i in range(3, int(a ** 0.5) + 1, 2):
        d = 0
        while a % i == 0:
            d += 1
            a //= i
        factors[i] = max(factors[i], d)
        if a == 1:
            break
    if a > 1000:
        large_factors.add(a)
    elif a > 1:
        factors[a] = max(factors[a], 1)

m = 1
for k, v in enumerate(factors):
    if v > 0:
        m = (m * pow(k, v, M)) % M
for k in large_factors:
    m = (m * k) % M

result = 0
for a in A:
    result = (result + m * modinv(a, M)) % M
print(result)

Measured memory_bytes: 92636
N, M = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

res = 0
for i in range(2 ** N):
    ok = True

    for j in range(M):
        cnt = 0
        for k in range(N):
            if i >> k & 1 and (k + 1) in S[j][1:]:
                cnt += 1
        if cnt % 2 != P[j]:
            break

    else:
        res += 1

print(res)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
	int n;
	cin >> n;
	ll c = 100000;
	while (n>0) {
		ll add = c*5/100;
		int i = add%10;
		int j = (add-i)%100;
		int k = (add-i-j)%1000;
		if ((add%1000)!=0) add = add-i-j-k+1000;
		c += add;
		n--;
	}
	cout << c << endl;
	return 0;
}

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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

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

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string s;
	cin >> s;
	int sSize = s.size();
	int ans = 1000;
	for(int i = 0; i < sSize-2; i++){
		int n = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
		ans = min(ans, abs(n - 753));
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

#define endl "\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = 1e9;
const int MAX=100000;
const ll lim=1e18;
const int MOD=1e9+7;


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

	int n;
	while(cin>>n){
		vector<pair<int,pair<int,int>>>v(n);
		for(int i=0;i<n;i++)
			cin>>v[i].first>>v[i].second.first>>v[i].second.second;
		sort(all(v));
		int x=0,y=0;
		int t=0;
		bool val=true;
		for(int i=0;i<n;i++){
			int tmp=abs(v[i].second.first-x)+abs(v[i].second.second-y);
//			cerr<<tmp<<endl;
			if(tmp+t<=v[i].first&&(v[i].first-(tmp+t))%2==0){
				t=v[i].first;
				x=v[i].second.first;
				y=v[i].second.second;
			}
			else{
				val=false;
				break;
			}
//			cerr<<t<<" "<<x<<" "<<y<<endl;
		}
		if(val)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<complex>
#include<math.h>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
int x[100];
int y[100];
int r[100];
double g[200][200];
P wolf[200];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			scanf("%d%d%d",x+i,y+i,r+i);
		}
		wolf[0]=P(x[0],y[0]);
		wolf[2*a-1]=P(x[a-1],y[a-1]);
		for(int i=0;i<a-1;i++){
			double d=sqrt((x[i+1]-x[i])*(x[i+1]-x[i])+(y[i+1]-y[i])*(y[i+1]-y[i]));
			double theta=acos((d*d+r[i]*r[i]-r[i+1]*r[i+1])/(2.0*d*r[i]));
			double T=atan2(y[i+1]-y[i],x[i+1]-x[i]);
			wolf[i*2+1]=P((double)x[i]+cos(theta+T)*r[i],(double)y[i]+sin(theta+T)*r[i]);
			wolf[i*2+2]=P((double)x[i]+cos(-theta+T)*r[i],(double)y[i]+sin(-theta+T)*r[i]);
		}
		for(int i=0;i<2*a;i++)
			for(int j=0;j<2*a;j++)
				g[i][j]=999999999;
		for(int i=0;i<2*a;i++)g[i][i]=0;
		for(int i=0;i<2*a;i++)
			for(int j=i+1;j<2*a;j++){
				int left=(i+1)/2;
				int right=(j-1)/2;
				bool ok=true;
				for(int k=left;k<right;k++){
					if(!intersectSS(L(wolf[i],wolf[j]),L(wolf[k*2+1],wolf[k*2+2])))ok=false;
				}
				if(ok){
					g[j][i]=g[i][j]=sqrt(norm(wolf[i]-wolf[j]));
				}
			}
		for(int k=0;k<2*a;k++)
			for(int i=0;i<2*a;i++)
				for(int j=0;j<2*a;j++)
					g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
		printf("%f\n",g[0][2*a-1]);
	}
}

Measured memory_bytes: 1524
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll n,tmp=0,ans=0;cin>>n;
  vll a(n+1),b(n);
  rep(i,0,n+1){
    cin>>a[i];
  }
  rep(i,0,n){
    cin>>b[i];
  }
  rep(i,0,n){
    if(a[i]<=b[i]){
      ans+=a[i];
      b[i]-=a[i];
      if(a[i+1]<=b[i]){
        ans+=a[i+1];
        a[i+1]=0;
      }
      else{
        ans+=b[i];
        a[i+1]-=b[i];
      }
    }
    else{
      ans+=b[i];
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  return 0;
}

Measured memory_bytes: 3132
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
constexpr ll mod = 1000000007;

ll n, m, s[2000], t[2000];

ll rec1(ll, ll);

ll rec2(ll, ll);

ll dp[2][2000][2000];

ll rec1(ll a, ll b) {
    if (a < 0 || b < 0 || s[a] != t[b]) return 0;
    if (dp[0][a][b] == -1) {
        dp[0][a][b] = (rec2(a - 1, b - 1) + 1) % mod;
    }
    return dp[0][a][b];
}

ll rec2(ll a, ll b) {
    if (a < 0 || b < 0) return 0;
    if (dp[1][a][b] == -1) {
        dp[1][a][b] = (rec2(a - 1, b) + rec2(a, b - 1) - rec2(a - 1, b - 1) + rec1(a, b) + mod) % mod;
    }
    return dp[1][a][b];
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < 2000; i++) for (int j = 0; j < 2000; j++) dp[0][i][j] = dp[1][i][j] = -1;
    for (ll i = 0; i < n; i++) cin >> s[i];
    for (ll i = 0; i < m; i++) cin >> t[i];
    cout << (rec2(n - 1, m - 1) + 1) % mod << endl;
}

Measured memory_bytes: 62976
#include<bits/stdc++.h>
 using namespace std;
 int main(){
 	int n,m;
 	cin>>n>>m;
 	int sum=0;
 	for(int i=1;i<=n;i++){
 		sum+=n-i;	
	 }
	 for(int i=1;i<=m;i++)
	 sum+=m-i;
 	cout<<sum;
 	return 0;
 }
 
 // 2 4 6 8 1 3 5 

Measured memory_bytes: 256