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

// 多項式vを (x^p - x) で割りきれるかどうか (F_p 上)
bool divPoly(vector<int> v, int p){
    if(v.size() > p){ // 次数がp以上なら
        vector<int> res(v.size()-p); // 商
        for (int i = v.size() - p - 1; i >= 0; --i) {
            res[i] = v[i+p];
            v[i+p] -= res[i]; // = 0
            v[i+1] += res[i];
            v[i+1] %= p;
        }
    }
    for (int x: v) {
        if(x % p != 0) return false;
    }
    return true;
}

// エラトステネスの篩 (x以下の全素数が昇順に入ったvectorを返す関数), O(n loglog n)
vector<int> AllPrime(int x){
    vector<int>res;
    res.reserve(x);
    vector<int>is_prime(x+1, 1);
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= x; ++i) {
        if(is_prime[i] == 1){
            res.push_back(i);
            for (int j = i*2; j <= x; j += i) is_prime[j] = 0;
        }
    }
    return res;
}

// 素因数分解, 2^3 なら (2, 3)
vector<pair<ll, int>> factoring(ll n){
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; ++i) {
        int k = 0;
        while (n % i == 0){
            n /= i;
            k++;
        }
        if(k != 0) res.push_back({i, k});
    }
    if(n != 1) res.push_back({n, 1});
    return res;
}

// 互除法で2正数x,yのgcdを返す関数
ll gcd (ll x, ll y) {
    ll p = x % y;
    while(p){
        x = y;
        y = p;
        p = x % y;
    }
    return y;
}

int main() {
    int N;
    cin >> N;
    vector<int>a(N+1);
    for (int i = N; i >= 0; --i) {
        cin >> a[i];
    }

    int a_gcd = abs(a[N]);
    for (int i = 0; i < N; ++i) {
        if(a[i] == 0) continue;
        a_gcd = gcd(a_gcd, abs(a[i]));
    }
    auto fa = factoring(a_gcd);
    auto pr = AllPrime(N);

    vector<int>ans;
    for (auto x: fa) {
        ans.push_back(x.first);
    }
    for (auto x: pr) {
        if(divPoly(a, x)) ans.push_back(x);
    }

    sort(ans.begin(), ans.end());
    if(ans.size() == 0) return 0;
    cout << ans[0] << "\n";
    for (int i = 1; i < ans.size(); ++i) {
        if(ans[i] != ans[i-1]) cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, M) = read!(usize, usize);
    let mut X = read![[i64]];

    X.sort();

    let mut ds = X.windows(2).map(|w| w[1] - w[0]).collect::<Vec<_>>();
    ds.sort();

    let total = ds[..(M - 1).saturating_sub(N - 1)].iter().sum::<i64>();

    println!("{}", total)
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define umap unordered_map
#define RESET   "\033[0m"
#define RED     "\033[31m"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const ll lINF = 1e18+7;
const int INF = 1e9+7;

template <class T> ostream& operator<<(ostream& s, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s << v[i] << ' ';
    return s;
}

template <class T> istream& operator>>(istream& s, vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s >> v[i];
    return s;
}


//########################################################################################




void solve(int CASE=0) {
	int n;
	cin >> n;
	int d = n%1000;
	if (d) cout << 1000-d;
	else cout << 0;
}


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

    int TEST = 1;
    //cin >> q;
    for (int i = 1; i <= TEST; i++) 
		solve(i);
}


Measured memory_bytes: 3560
#include<stdio.h>
int main(){
    char line[1200];
    int i=0,j,count[26];
    for(j=0;j<26;j++){
        count[j]=0;
    }
    while(scanf("%c",&line[i]) != EOF){
        if('a'<=line[i]&&line[i]<='z'){
            count[line[i] - 'a']++;
        }else if('A'<=line[i]&&line[i]<='Z'){
            count[line[i] - 'A']++;
        }
        i++;
    }
    for(j=0;j<26;j++){
        printf("%c : %d\n",'a'+j,count[j]);
    }
    return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int x;
	cin >> x;
	ll ans = 0;
	ans += x / 500;
	x -= ans * 500;
	// cerr << x << endl;
	ans *= 1000;
	ans += x/5*5;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

myqueue = deque(input())
#print("queue is {}".format(myqueue))

normal = True

num = int(input())

for i in range(num):
    query = input().split()
#    print(query)
    if len(query) == 1:
        normal = not normal
    else:
        if query[1] == "1":
            if normal:
                myqueue.appendleft(query[2])
            else:
                myqueue.append(query[2])
        else:
            if normal:
                myqueue.append(query[2])
            else:
                myqueue.appendleft(query[2])
#    print("queue is {}".format(myqueue))

counter = len(myqueue)

if normal:
    for i in range(counter):
        print(myqueue.popleft(), end="")
else:
    for i in range(counter):
        print(myqueue.pop(), end="")


Measured memory_bytes: 7536
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x[5];
	for(int i=0;i<5;i++) cin>>x[i];
	for(int i=0;i<5;i++){
		if(x[i]==0){
			cout<<i+1<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3628
main :: IO ()
main = do
  a <- readLn
  b <- readLn 
  c <- readLn 
  x <- readLn 
  print $ selection a b c x

selection
  :: Int -> Int -> Int -> Int -> Int
selection a b c x
  = length [(s,t,u) | s<-[0..a], t<-[0..b], u<-[0..c]
                    , 500*s + 100*t + 50*u == x]

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin>>n>>m;
	vector<pair<int,int>> arr;
	vector<int> level[N];
	priority_queue<int> pq;
	int curr_level = 1;
	for(int i=0; i<n; ++i){
		int x,y;
		cin>>x>>y;
		level[x].push_back(y);
	}
	int ans = 0;
	for(int i=1; i<=m; ++i){
		for(auto j : level[i]){
			pq.push(j);
		}
		if(!pq.empty()){
			auto get = pq.top(); pq.pop();
			ans += get;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    string s; cin >> s;
    vector<int> alllist[10];
    rep(i,s.size()) alllist[s[i]-'0'].push_back(i);
    int ans = 0;
    rep(i,10) {

        if(alllist[i].size()==0) continue;
        rep(j,10) {

            if(alllist[j].size()==0) continue;
            rep(k,10) {

                if(alllist[k].size()==0) continue;

                int first = alllist[i][0];

                if(alllist[j][alllist[j].size()-1]<=first) continue;

                int second = *upper_bound(ALL(alllist[j]),first);

                if(alllist[k][alllist[k].size()-1]<=second) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        int countRectangles = 0;
        int countLozenges = 0;
        while (true) {
            String input = inputReader.readLine();
            if (input == null) {
                break;
            }
            String[] temp = input.split(",");
            int[] l = new int[temp.length];
            for (int i = 0; i < temp.length; i++) {
                l[i] = Integer.parseInt(temp[i]);
            }
            if (Math.pow(l[0], 2) + Math.pow(l[1], 2) == Math.pow(l[2], 2)) {
                countRectangles++;
            } else if (l[0] == l[1] && l[0] + l[1] > l[2]) {
                countLozenges++;
            }
        }
        System.out.println(countRectangles);
        System.out.println(countLozenges);
    }
}

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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	int max=0, smax=0, maxId;
	for(int i=0; i<N; i++){
		cin >> A[i];
		if(A[i]>max){
			smax = max;
			max = A[i];
			maxId = i;
		}else if(A[i]>smax){
			smax = A[i];
		}
	}
	
	for(int i=0; i<N; i++){
		if(i==maxId) cout << smax << endl;
		else cout << max << endl;
	}
}

Measured memory_bytes: 2432
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common

typedef int  i32;
typedef long long i64,ll;
typedef long double ld;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(int)l;i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#define NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}
#define nextInt(n) scanf("%d",&n)
#define defInt(n) int n;nextInt(n)
#define nextLong(n) scanf("%lld",&n)
#define defLong(n) ll n;nextLong(n)
#define nextDouble(n) scanf("%lf",&n)


class Main{
public:
	void run(){
	//	ifstream cin("in");
	//	ofstream cout( "out" );
		string str;cin >>  str;
		int N=str.size();

		int Mv=0;
		for(int i=0;i<N;){
			// JOJOI
			int jlv=0;while(i<N && str[i]=='J')i++,jlv++;
			int olv=0;while(i<N && str[i]=='O')i++,olv++;
			int ilv=0;while(i<N && str[i]=='I')i++,ilv++;
			if(olv<=min(jlv,ilv))
				Mv=max(Mv,olv);
		}

		cout << Mv <<endl;
	}
};
int main(){
	cout <<fixed<<setprecision(3);	
	ios::sync_with_stdio(false);
	Main().run();
	return 0;
}

Measured memory_bytes: 2712
from heapq import *

# G : [to/from, cap, cost, rev]
def minimumCostFlow(N: int, G: list, s: int, t: int, flow: int):
	ret = 0
	INF = 1 << 60
	potential = [0] * N
	pre_vtx = [None] * N
	pre_edge = [None] * N

	while flow > 0:
		dist = [INF] * N
		dist[s] = 0
		visited = [False] * N
		q = [(0, s)]
		while q:
			d, cur = heappop(q)
			if visited[cur]:
				continue
			visited[cur] = True
			for i in range(len(G[cur])):
				e = G[cur][i]
				nxt = e[0]
				if e[1] > 0 and dist[nxt] > dist[cur] + e[2] + potential[cur] - potential[nxt]:
					dist[nxt] = dist[cur] + e[2] + potential[cur] - potential[nxt]
					pre_vtx[nxt] = cur
					pre_edge[nxt] = i
					heappush(q, (dist[nxt], nxt))
		if dist[t] == INF:
			return -1
		for i in range(N):
			potential[i] += dist[i]
		df = flow
		now = t
		while now != s:
			df = min(df, G[pre_vtx[now]][pre_edge[now]][1])
			now = pre_vtx[now]
		flow -= df
		ret += df * potential[t]
		now = t
		while now != s:
			G[pre_vtx[now]][pre_edge[now]][1] -= df
			G[now][G[pre_vtx[now]][pre_edge[now]][3]][1] += df
			now = pre_vtx[now]
	return ret


import sys
input = sys.stdin.buffer.readline


def main():
	N, M, F = map(int, input().split())
	G = [[] for _ in range(N)]  # [to/from, cap, cost, rev]
	for _ in range(M):
		u, v, c, d = map(int, input().split())
		G[u].append([v, c, d, len(G[v])])
		G[v].append([u, 0, -d, len(G[u]) - 1])
	print(minimumCostFlow(N, G, 0, N - 1, F))


if __name__ == '__main__':
	main()



Measured memory_bytes: 5916
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;

int main(){fast ;
	int n,k ;
	cin >> n ;
	if( n == 3 or n == 5 or n == 7)
		cout << "YES" ;
	else
		cout << "NO" ;
}




Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: 2019/03/21
 *      Author: londo
 */

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct shop{
	int price;
	int amnt;
};

bool cmp(const shop &a, const shop &b){
	return a.price < b.price;
}

int main(){
	int N, M;
	scanf("%d %d\n", &N, &M);

	vector<shop> enegy(N);//Nこの要素を持つベクターのコンストラクタenegyを生成
	for(int i = 0;i < N;i++){
		scanf("%d %d",&enegy[i].price,&enegy[i].amnt);
	}
	sort(enegy.begin(),enegy.end(),cmp);

	int sum = 0;
	unsigned long long fee = 0;
	for(int i = 0;i < N;i++){
		for(int j = 0; j < enegy[i].amnt;j++){
			fee += enegy[i].price;
			sum++;
//			printf("buy for %d at %d\n",enegy[i].price,i);
			if(sum == M) break;
		}
		if(sum == M) break;
	}
	printf("%lld\n",fee);

	return 0;
}


Measured memory_bytes: 1024
#include<bits//stdc++.h>
using namespace std;
int main() {
	string s;cin >> s;int cnt = 0,mx = 0;
	for (int i = 0; i < s.size();i++) {
		if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
			cnt++; mx = max(mx, cnt);
		}
		else cnt = 0;
	}cout << mx << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
  return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}
i64 inv(i64 x) {
  return ipow(x, mod - 2);
}
i64 n;
vector<i64> a;
bool ps[1000001];
i64 cnt[1000001];
int main() {
    cin >> n;
    read_n(a, n);
    
    ps[1] = true;
    for (i64 x = 2; x <= 1000000; ++x) {
        if (ps[x]) continue;
        for (i64 y = 2 * x; y <= 1000000; y += x) {
            ps[y] = true;
        }
    }

    for (i64 x : a) {
        for (i64 y = 1; y * y <= x; ++y) {
            if (x % y == 0) {
                if (!ps[y]) {
                    i64 c = 0;
                    i64 z = y;
                    while (x % z == 0) {
                        ++c;
                        z *= y;
                    }
                    cnt[y] = max(cnt[y], c);
                }
                i64 z = x / y;
                if (!ps[z]) {
                    cnt[z] = max(cnt[z], i64(1));
                }
            }
        }
    }

    i64 y = 1;
    for (i64 x = 2; x <= 1000000; ++x) {
        (y *= ipow(x, cnt[x])) %= mod;
    }

    i64 ans = 0;
    for (i64 x : a) {
        ans += y * inv(x) % mod;
    }
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8576
/*********************************
Date: Wed Apr 18 19:54:51 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define ll long long
#define ull unsigned long long
const int mod = 1e9 + 7;
const int maxn = 1e2 + 100;
int a[10100];
int m[maxn][maxn];
int main()
{
	int h,w,n;
	scanf("%d%d%d",&h,&w,&n);
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	int t=1;
	int r = 0;
	while (r < h){
		for (int i=0;i<w;++i){
			while (t<n && a[t]==0) ++t;
			m[r][i] = t;
			a[t]--;
		}
		++r;
		if (r>=h) break;
		for (int i=w-1;i>=0;--i){
			while (t<n && a[t]==0) ++t;
			m[r][i] = t;
			a[t]--;
		}
		++r;
	}
	for (int i=0;i<h;++i){
		for (int j=0;j<w;++j){
			printf("%d ",m[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    string s, t;
    cin >> s >> t;
    ll i;
    ll start[26]={}, goal[26]={};
    for(i=0; i<26; i++) {
        start[i]=-1;
        goal[i]=-1;
    }
    
    
    for(i=0; i<s.size(); i++) {
        ll a=s[i]-'a';
        ll b=t[i]-'a';
        
        if(start[a]==-1 && goal[b]==-1) {
            start[a]=b;
            goal[b]=a;
        }else if(start[a]!=b) {
            puts("No");
            return 0;
        }
    }
    
    puts("Yes");
    
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>

#define rep(i,m,n) for(unsigned long long int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll =long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

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

	cout << N * N * N << '\n';
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];

    int aa[n], bb[n];
    rep(i,n){
        aa[i] = a[i];
        bb[i] = b[i];
    }
    sort(aa, aa+n);
    sort(bb, bb+n);
    rep(i,n){
        if(aa[i] > bb[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i,n-1){
        if(aa[i+1] <= bb[i]){
            cout << "Yes" << endl;
            return 0;
        }
    }

    // 座標圧縮
    rep(i,n){
        a[i] = lower_bound(aa, aa+n, a[i]) - aa;
        b[i] = lower_bound(bb, bb+n, b[i]) - bb;
    }

    vector<P> v;
    rep(i,n)v.push_back(P(b[i], a[i]));
    sort(v.begin(), v.end());
    rep(i,n){
        a[i] = v[i].second;
        b[i] = v[i].first;
    }

    int cnt = 0;
    int now = 0;
    int f[n] = {};
    while(true){
        if(f[now] == 1)break;
        f[now] = 1;
        now = a[now];
        cnt++;
    }

    if(cnt < n)yn;

    return 0;
}
 
 


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<string.h>
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main(){
	fastIO
	string str1,str2;
	cin>>str1>>str2;
	int count=0;
	for(int i=0;i<str1.length();i++){
		if(str1[i]!=str2[i]){
			count++;
		}
	}
	cout<<count<<endl;
	
	return 0;
}

Measured memory_bytes: 3796
use proconio::input;
use std::collections::BTreeSet;

fn main() {
    input! {
        a: usize,
        b: usize
    }

    let set = {
        let mut set = BTreeSet::new();
        for &(p,_) in &factor(a) {
            set.insert(p);
        }
        set
    };

    println!("{}",factor(b).iter().filter(|(p,_)| set.contains(&p)).count()+1)
}

pub fn factor(n: usize) -> Vec<(usize, usize)> {
    let mut n = n;
    let mut ret = vec![];
    let ps = primes((n as f64).sqrt() as usize + 2);
    for p in ps {
        let mut cnt = 0;
        while n % p == 0 {
            n /= p;
            cnt += 1;
        }
        if cnt > 0 {
            ret.push((p, cnt));
        }
    }
    if n > 1 {
        ret.push((n, 1));
    }
    ret
}

pub fn primes(n: usize) -> Vec<usize> {
    let mut tbl = vec![true; n];
    let mut ps = vec![];
    tbl[0] = false;
    tbl[1] = false;
    for i in 2..n {
        if tbl[i] {
            ps.push(i);
            let mut j = i + i;
            while j < n {
                tbl[j] = false;
                j += i;
            }
        }
    }
    ps
}

Measured memory_bytes: 4016
package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n+2)
	a[0], a[len(a)-1] = 0, 0
	for i := 1; i < len(a)-1; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	mv := 0
	for i := 1; i < len(a); i++ {
		mv += abs(a[i-1] - a[i])
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 1; i < len(a)-1; i++ {
		ans := mv - (abs(a[i-1]-a[i]) + abs(a[i+1]-a[i])) + abs(a[i+1]-a[i-1])
		wr.WriteString(strconv.Itoa(ans) + "\n")
	}
	wr.Flush()
}


Measured memory_bytes: 4608
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  string s;cin>>s;
  rep(i,26){
    ll count=0;
    rep(j,s.size()){
      if(abc[i]==s[j])count++;
    }
    if(count==0){
      cout<<abc[i]<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
  fastIO;
  ll n;
  cin>>n;
  ll x,y,val,a[n],val1;
  val=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    val+=a[i];
  }
  y=0;
  ll ans,y1=0,val2;
  val1=(val+n-1)/n;
  val2=val/n;
  for(int i=0;i<n;i++)
  {
    x=abs(val1-a[i]);
    x*=x;
    y1+=abs(val2-a[i])*abs(val2-a[i]);
    y+=x;
  }
  ans=min(y,y1);
  cout<<ans<<endl;
}


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

#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 x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000000000007LL
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,W,w[101],v[101];
int dp[101][100005];
void solve(){
    cin>>n>>W;
    rep(i,1,n+1) cin>>w[i]>>v[i];
    rep(i,1,100005) dp[0][i]=hell;
    rep(i,1,n+1){
        rep(j,0,100005){
            dp[i][j]=dp[i-1][j];
            if(j>=v[i]) dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
        }
    }
    int ans=0;
    rep(j,0,100005) if(dp[n][j]<=W) ans=j;
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 79232
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        Strategy strategy = new MyStrategy();
        strategy.solve(out, sc);
        out.flush();
    }
}

class MyStrategy implements Strategy {
    @Override
    public void solve(PrintWriter out, FastScanner sc) {
        String s = sc.next();
        char c = s.charAt(0);
        char[] a = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
        for (int i = 0; i < a.length-1; i++) {
            if (c == a[i]) {
                out.println(a[i+1]);
                return;
            }
        }
        out.println('a');
    }
}

interface Strategy {
    void solve(PrintWriter out, FastScanner sc);
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21204
n = int(input())
B = list(map(int, input().split()))
ans = 0
ans += B[0]
for i in range(n - 2):
    if B[i] > B[i + 1]:
        ans += B[i + 1]
    else:
        ans += B[i]
ans += B[-1]
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  string S;
  int N;
  cin >> N >> S;

  for(auto &c: S) {
    int i = ((c - 'A') + N) % 26;
    c = 'A' + i;
  }

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
//#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using namespace std;


int main(){
    int N;
    cin >> N;
    int i = 1;
    while(1){
        if(N < i*i){
            cout << (i-1)*(i-1) << endl;
            return 0;
        }
        i++;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb      push_back
#define all(v)  v.begin(),v.end()
#define endl    "\n"
#define FAST    ios_base::sync_with_stdio(0);cin.tie(0);
 
typedef long long     ll;
typedef long double   ld;
typedef pair<int,int> ii;
 
const int    inf = 2e9;
const ll     INF = 4e17;
const int    mod = 1e9+7;
const double eps = 1e-9;
 
ll b[100010];
 
int main() {
	ll n, h, last = 0, power = -inf, rel;
	scanf("%lld %lld", &n, &h);
	for(int i = 0; i < n; i++) {
		ll x;
		scanf("%lld %lld", &x, &b[i]);
		if(x > power) {
			power = x;
			rel = b[i];
		}
	}
	sort(b,b+n);
	ll sum = 0, ans = inf;
	for(int i = n-1; i >= 0; i--) {
		sum += b[i];
		if(sum >= h) {
			ans = n-i;
			break;
		}
	}
	sum = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++) {
		if(b[i] >= power) sum += b[i], cnt++;
	}
	h -= sum;
	if(h <= 0){ printf("%lld\n", min(ans, cnt)); return 0; }
	ll asdf = ceil((double)h/power);
	printf("%lld\n", min(cnt + asdf, ans));
	return 0;
}


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

N = int(input())
A = [int(input()) for _ in range(N)]
coef1, coef2 = [], []

for i in range(N):
    p = 1 if i in [0, N-1] else 2
    coef1.append(p*(1 if i%2==0 else -1))
    coef2.append(p*(-1 if i%2==0 else 1))

A.sort()
coef1.sort()
coef2.sort()
ans = max(sum(Ai*p for Ai, p in zip(A, coef1)), sum(Ai*p for Ai, p in zip(A, coef2)))
print(ans)

Measured memory_bytes: 83024
#from scipy.special import comb
from math import factorial

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

if N >= 2:
  N1 = factorial(N) / factorial(2) / factorial(N - 2)
else:
  N1 = 0
if M >= 2:
  M1 = factorial(M) / factorial(2) / factorial(M - 2)
else:
  M1 = 0
print(int(N1+M1))

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

using namespace std;

int main() {
    int N;
    string s;
    cin >> N >> s;

    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        int a[] = {i / 100, (i / 10) % 10, i % 10};
        int cnt = 0;
        for (int j = 0; j < N; j++) {
            if (s[j] == ('0' + a[cnt])) {
                cnt++;
                if (cnt == 3) {
                    ans++;
                    break;
                }
            }
        }
    }

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

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

int q;
const int rm = 1e5;
bool prime[rm];
int c[rm];

int main() {
	fill(prime, prime + rm, 1);
	for (int i = 2; i * i <= rm; i++)
		if (prime[i])
			for (int j = i * i; j <= rm; j += i)
				prime[j] = 0;

	for (int i = 3; i < rm; i += 2)
		c[i] = c[i - 2] + (prime[i] && prime[(i + 1) / 2]);

	cin >> q;
	for (int i = 0, l, r; i < q; i++) {
		cin >> l >> r;
		cout << (l == 1 ? c[r] : c[r] - c[l - 2]) << endl;
	}
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<3;i++){
        if(s[i]=='A')cnt++;
    }
    if(cnt==3||cnt==0){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
ll nxt(){ll x;cin>>x;return x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	vector<int> a(n);
	unordered_map<int,ll> cnt;
	for(auto& it:a) cin>>it,cnt[it]++;
	ll ans=0;
	for(auto it:cnt) ans+=it.S*(it.S-1)/2;
	for(auto it:a){
		cout<<ans-cnt[it]+1<<endl;
	}
    return 0;
}



Measured memory_bytes: 8392
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    if x+1-i >= 0:
        a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i)) #赤の間に青を入れるので(x+1)Ci通り
    else:
        a = 0#例外　赤が少ないと実現できない手数が出てくる。
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))#青玉の配分
    print(a * b % (10**9+7))
    print("\n")


Measured memory_bytes: 3700
#include <iostream>
using namespace std;
void bsort(int *n1, int *n2, int *n3)
{
	if(*n1 > *n2) {
	int tmp = *n1;
	*n1 = *n2;
	*n2 = tmp;
	}
	if(*n1 > *n3){
	int tmp = *n1;
	*n1 = *n3;
	*n3 = tmp;
	}
	if(*n2 > *n3){
	int tmp = *n2;
	*n2 = *n3;
	*n3 = tmp;
	}
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bsort(&a, &b, &c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}



Measured memory_bytes: 3108
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,j,k,N,ma,mb,a,b,x,ans=inf;
  cin>>N>>ma>>mb;
  vector<mat> v(N+1,mat(500,vec(500,inf)));
  v[0][0][0]=0;
  rep1(k,N+1){
    cin>>a>>b>>x;
    rep(i,410)rep(j,410){
      chmin(v[k][i+a][j+b],v[k-1][i][j]+x);
      chmin(v[k][i][j],v[k-1][i][j]);
    }
  }
  for(i=1;i*max(ma,mb)<500;i++){
    chmin(ans,v[N][ma*i][mb*i]);
  }
  if(ans!=inf)cout<<ans<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 83072
int n=1<<18;
long dat[1<<19],lazy[1<<19],A[1<<18];
eval(i,l,r)
{
	if(lazy[i])
	{
		dat[i]+=lazy[i];
		if(r-l>1)
		{
			lazy[2*i+1]+=lazy[i];
			lazy[2*i+2]+=lazy[i];
		}
		lazy[i]=0;
	}
}
update(a,b,x,k,l,r)long x;
{
	eval(k,l,r);
	if(b<=l||r<=a)return 0;
	else if(a<=l&&r<=b)
	{
		lazy[k]+=x;
		eval(k,l,r);
	}
	else
	{
		update(a,b,x,2*k+1,l,(l+r)/2);
		update(a,b,x,2*k+2,(l+r)/2,r);
		dat[k]=fmax(dat[2*k+1],dat[2*k+2]);
	}
}
long query(a,b,k,l,r)
{
	eval(k,l,r);
	if(b<=l||r<=a)return 0;
	else if(a<=l&&r<=b)return dat[k];
	else return fmax(
		query(a,b,2*k+1,l,(l+r)/2),
		query(a,b,2*k+2,(l+r)/2,r)
	);
}
N,m;
L[1<<18],p;
first[1<<18],next[1<<18];
main(i)
{
	scanf("%d%d",&N,&m);
	for(;~scanf("%d%d%ld",L+i,&p,A+i);first[p]=i++)next[i]=first[p];
	for(i=1;i<=N;i++)
	{
		update(i,i+1,query(0,i,0,0,n),0,0,n);
		p=first[i];
		for(;p!=0;)
		{
			update(L[p],i+1,A[p],0,0,n);
			p=next[p];
		}
	}
	printf("%ld",query(0,N+1,0,0,n));
}

/*
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
*/

Measured memory_bytes: 12800
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <tuple>
#include <string>

int main() {
  size_t n;
  scanf("%zu", &n);

  int res = 0;
  for (size_t i = 0; i < n; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string s = buf;
    if (s == "E869120") ++res;
  }

  printf("%d\n", res);
}



Measured memory_bytes: 2860
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

#define REP(i,a,b) for(int i=(a); i<(b); ++(i))
#define rep(i,n) REP(i,0,n)

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main(void) {
  int N; cin >> N;
  vector<int> A(N), X(N);

  ll S = 0;
  rep(i, N) {
    cin >> A[i];
    S += A[i];
  }

  X[0] = S;
  for (int i = 1; i < A.size(); i += 2) {
    X[0] -= 2 * A[i];
  }

  for (int i = 1; i < N; i++) {
    X[i] = 2 * A[i - 1] - X[i - 1];
  }

  rep(i, N) {
    if (i) cout << " ";
    cout << X[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
//10:50
int absl(long n){
  if(n>0){
    return n;
  }else if(n<0){
    return -n;
  }else{
    return 0;
  }
}

int main(){
  int n = 0;
  int m = 0;
  long a[100] = {};
  long b[100] = {};
  long c[100] = {};
  long d[100] = {};
  int nearpoint[100] = {};//最後に必ず１を足すこと
  int i = 0;
  int j = 0;
  long mindst = 0;
  int nindex = 0;
  
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%lu %lu",&a[i],&b[i]);
  }
  for(i=0;i<m;i++){
    scanf("%lu %lu",&c[i],&d[i]);
  }
  
  for(i=0;i<n;i++){
    mindst = absl(c[0]-a[i])+absl(d[0]-b[i]);
    nindex = 0;
    for(j=1;j<m;j++){
      if(mindst > absl(c[j]-a[i])+absl(d[j]-b[i])){
        mindst = absl(c[j]-a[i])+absl(d[j]-b[i]);
        nindex = j;
      }
    }
    nearpoint[i] = nindex;
  }
  
  for(i=0;i<n;i++){
    printf("%lu\n",nearpoint[i]+1);
  }
  return 0;
}
 
          
        
    

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

using namespace std;

#define ll long long

int main() {
    vector<ll> vec;
    int t, a;
    ll x;
    cin >> t;
    while (t--) {
        cin >> a;
        if (a == 0) {
            cin >> x;
            vec.push_back(x);
        } else if (a == 1) {
            cin >> x;
            cout << vec[x] << endl;
        } else if (a == 2) {
            vec.pop_back();
        }
    }

    return 0;
}


Measured memory_bytes: 4880
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

output:
1
2
"""

import sys
from math import ceil, log2, isinf


class SegmentTree(object):
    __slots__ = ('dat', 'tree_range')

    def __init__(self):
        """
        Init a SegmentTree with update and find for RMQ.
        """
        self.tree_range = end
        self.dat = [float('inf')] * (2 * self.tree_range - 1)

    # let A[k]=a
    def update(self, k, a):
        k += self.tree_range - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    # get min(A[s] A[s+1] ... A[t])
    def find(self, s, t, k=0, l=0, r=float('inf')):
        if r <= s or t <= l:
            return float('inf')
        elif s <= l <= r <= t:
            return self.dat[k]
        else:
            vl = self.find(s, t, k * 2 + 1, l, (l + r) // 2)
            vr = self.find(s, t, k * 2 + 2, (l + r) // 2, r)
            return min(vl, vr)


def action(cmd_list):
    for query in cmd_list:
        cmd, ele_1, ele_2 = map(int, query)
        if cmd == 0:
            case.update(ele_1, ele_2)
        elif cmd == 1:
            assert ele_1 <= ele_2
            res = case.find(s=ele_1, t=ele_2 + 1, r=end)
            if isinf(res):
                print(INIT_MAX)
            else:
                print(res)

    return case


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n_num, q_num = map(int, _input[0].split())
    q_list = map(lambda x: x.split(), _input[1:])

    end = pow(2, ceil(log2(n_num)))
    INIT_MAX = pow(2, 31) - 1

    case = SegmentTree()

    ans = action(q_list)

Measured memory_bytes: 19648
#include<bits/stdc++.h> 
using namespace std;
int main()
{int a,b,c,d,n;
 cin>>n;
 a=n/1000;b=n/100%10;c=n/10%10;d=n%10;
 if((a==b&&b==c)||(b==c&&c==d))
   cout<<"Yes"<<endl;
 else
   cout<<"No"<<endl;
}

Measured memory_bytes: 256
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

def solve(arr):
    ab = lcm(arr)
    sum = 0
    for a in arr:
        sum += ab // a
    return sum % (10**9+7)

n = int(input())
arr = list(map(int, input().split()))
print(solve(arr))


Measured memory_bytes: 5576