akhauriyash/Code-Regression huggingface dataset:
/*
TASK: Trial division (prime factorization of a number)
NAME: Aryan
LANG: c++
*/
#include <bits/stdc++.h>
#define MAX 200005
using namespace std;
using ll=long long int;
ll dp[MAX];

#define FOR(n) for(int i=0;i<n;i++)
bool isPower(ll x, ll y) 
{ 
    // The only power of 1 is 1 itself 
    if (x == 1) 
        return (y == 1); 
  
    // Repeatedly comput power of x 
    ll pow = 1; 
    while (pow < y) 
        pow *= x; 
  
    // Check if power of x becomes y 
    return (pow == y); 
} 
ll calculate(ll x, ll y) 
{ 
    // The only power of 1 is 1 itself 
    if (x == 1) 
        return (y == 1); 
  
    // Repeatedly comput power of x 
    ll pow = 1,k=0; 
    while (pow < y) 
    {
        pow *= x; 
        k++;
    }
  
    // Check if power of x becomes y 
    return k; 
} 
int main()
{
    double n,t,s;
    cin>>n>>t>>s;
    
    if(n/s<=t)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
} 

Measured memory_bytes: 3716
import heapq
from collections import defaultdict

N,M=map(int,input().split())
V=defaultdict(int)
for i in range(M):
  a,b,c=map(int,input().split())
  V[(a-1,b-1)]=-c
d=[float('inf') for x in range(N)]

def Bellman_Ford(s):
  d[s]=0
  for i in range(N-1):
    update=False
    for ft,c in V.items():
      frm,to=ft
      if d[frm]!=float('inf') and d[to]>d[frm]+c:
        d[to]=d[frm]+c
        update=True
    if not(update):
      break
  
def Bellma_Ford_rep(n):
  upd=[False for x in range(N)]
  for i in range(N):
    update=False
    for ft,c in V.items():
      frm,to=ft
      if d[to]>d[frm]+c or upd[frm]:
        update=True
        upd[to]=True
    if not(update):
      break
  return upd[n]

Bellman_Ford(0)
if Bellma_Ford_rep(N-1):
  print("inf")
else:
  print(-d[N-1])

Measured memory_bytes: 3820
n = int(input())
A = list(map(int, input().split()))

pos = 0
P = [0] * n
if A[0] > 0:
    P[0] = A[0]
else:
    P[0] = 1
    pos += 1 - A[0]
for i in range(1, n):
    P[i] = P[i - 1] + A[i]
    if i % 2 == 0 and P[i] <= 0:
        pos += 1 - P[i]
        P[i] = 1
    elif i % 2 == 1 and P[i] >= 0:
        pos += 1 + P[i]
        P[i] = -1

neg = 0
N = [0] * n
if A[0] < 0:
    N[0] = A[0]
else:
    N[0] = -1
    neg += 1 + A[0]
for i in range(1, n):
    N[i] = N[i - 1] + A[i]
    if i % 2 == 0 and N[i] >= 0:
        neg += 1 + N[i]
        N[i] = -1
    elif i % 2 == 1 and N[i] <= 0:
        neg += 1 - N[i]
        N[i] = 1

print(min(pos, neg))


Measured memory_bytes: 14332
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	void dfs(int n, int i, int& ans, const vector<ll>& num , const vector<vector<ll>>& numIndex) {

	}
}

int main() {

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	// O(n^2)行ける
	//vector<ll> num(2001, 0);
	//rep(i, n) {
	//	num[a[i]]++;
	//}
	//cout << "a" << endl;

	//vector<vector<ll>> numIndex(n + 1, vector<ll>(2001, 0));
	//Rep(i, 1, n + 1) {
	//	Rep(j, 1, 2001) {
	//		if (j == a[i])
	//			numIndex[i][j] = numIndex[i - 1][j] + 1;
	//		else {
	//			numIndex[i][j] = numIndex[i - 1][j];
	//		}
	//	}
	//}

	ll ans = 0;
	// 左から見ていく
	// n
	rep(i, n) {
		// 数字a[i]をみて計算する
		// a[i]より小さい数
		ll sum = 0;
		Rep(j, i + 1, n) {
			if (a[i] > a[j])sum++;
		}
		ll sumAll = 0;
		rep(j, n) {
			if (a[i] > a[j])sumAll++;
		}
		ans += sum * k;
		ans %= mod;
		// ここでオーバーフローして層
		//ans += ((k - 1) * k / 2) * sumAll;
		ll add = 0;
		add = k * (k - 1) / 2;
		add %= mod;
		add *= sumAll;
		add %= mod;
		ans += add;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable inf = 10L^^16;
alias Edge = Tuple!(int, "to", long, "flow", long, "cap", int, "rev");

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);
    a = [0] ~ a;

    auto adj = new Edge[][](n + 2, 0);

    void addEdge(int u, int v, long cap) {
        adj[u] ~= Edge(v, 0, cap, adj[v].length.to!int);
        adj[v] ~= Edge(u, 0, 0, adj[u].length.to!int - 1);
    }

    foreach (i ; 1 .. n + 1) {
        foreach (j ; iota(2*i, n + 1, i)) {
            addEdge(i, j, inf);
        }

        if (a[i] >= 0) {
            addEdge(i, n + 1, a[i]);
        }
        else {
            addEdge(0, i, -a[i]);
        }
    }

    long ans = a.filter!"a > 0".sum(0L) - Dinic(adj, 0, n + 1);

    writeln(ans);
}

long Dinic(Edge[][] adj, int s, int t) {
    int n = adj.length.to!int;
    int[] level = new int[](n);
    int[] prog = new int[](n);
    auto q = Queue!(int)(n);

    bool bfs() {
        level[] = -1;
        level[s] = 0;
        q.clear();
        q.push(s);

        while (!q.empty) {
            auto u = q.front;
            q.pop;

            foreach (e ; adj[u]) {
                if (level[e.to] == -1 && e.cap - e.flow > 0) {
                    level[e.to] = level[u] + 1;
                    q.push(e.to);
                }
            }
        }

        return level[t] != -1;
    }

    long dfs(int u, long f) {
        if (u == t) return f;

        for (; prog[u] < adj[u].length; prog[u]++) {
            auto e = &adj[u][prog[u]];

            if (level[u] + 1 == level[e.to] && e.flow < e.cap) {
                long d = dfs(e.to, min(f, e.cap - e.flow));

                if (d > 0) {
                    e.flow += d;
                    adj[e.to][e.rev].flow -= d;
                    return d;
                }
            }
        }

        return 0;
    }

    long F;

    while (bfs()) {
        prog[] = 0;

        while (true) {
            auto df = dfs(s, inf);

            if (df) F += df;
            else break;
        }
    }

    return F;
}


struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this (int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head++;
        head %= N;
    }

    void clear() {
        head = tail = 0;
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

const int mod=1000000007;

int N;
int X[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>X[i];

    int ans=1;
    int s=0;
    for(int i=0;i<N;i++){
        if(2*s+1<=X[i]){
            s++;
            continue;
        }
        ans=ans*(s+1)%mod;
    }
    for(int i=1;i<=s;i++)ans=ans*i%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

long long int cost[10][3000];
long long int DP[3000];

int main(){
	
	int N, K;
	
	while(true){
		cin >> N >> K;
		if(cin.eof()){
			break;
		}
		
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 3000; j++){
				cost[i][j] = 0;
			}
		}
		
		vector<int> v_cost[10];
		
		for(int i = 0; i < N; i++){
			int c, g;
			cin >> c >> g;
			g--;
			v_cost[g].push_back(c);
		}
		
		for(int i = 0; i < 10; i++){
			sort(v_cost[i].begin(), v_cost[i].end());
			long long int sum = 0;
			for(int j = v_cost[i].size() - 1; j >= 0; j--){
				int count = v_cost[i].size() - j - 1;
				sum += v_cost[i][j];
				cost[i][count] = sum + count * (count + 1);
			}
		}
		
		for(int i = 0; i < 3000; i++){
			DP[i] = 0;
		}
		
		for(int i = 0; i < 10; i++){
			for(int j = 0; j <= K; j++){
				for(int k = 0; k < K; k++){
					if(j + k + 1 > K){
						break;
					}
					DP[j] = max(DP[j], DP[j + k + 1] + cost[i][k]);
				}
				//cout << DP[j] << " ";
			}
			//cout << endl;
		}
		
		cout << DP[0] << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3388
n = int(input())
A =list(map(int, input().split()))

dp = [[0]*2 for _ in range(n)]
# dp[i][0]:*1
# dp[i][1]:*(-1)
for i in range(n-1):
    if i == 0:
        dp[i+1][0] += A[i]
        dp[i+1][1] += -A[i]
    else:
        dp[i+1][0] = max(dp[i][0]+A[i], dp[i][1]+(-1)*A[i])
        dp[i+1][1] = max(dp[i][0]+(-1)*A[i], dp[i][1]+A[i])
ans = max(dp[n-1][0]+A[n-1], dp[n-1][1]+(-1)*A[n-1])
print(ans)


Measured memory_bytes: 99240
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int x;
  cin >> x;
  int time = 0;
  while (x > 0) {
    ++time;
    x -= time;
  }

  cout << time << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

const int nax = 101;
vi t,v;
int n, totalt;
vector<iii> intervals;
double speed[nax * 200 * 100 * 2];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    cin>>n; t.resize(n); v.resize(n);
    FOR(i, 0, n) {
        cin>>t[i]; t[i] *= 2;
        totalt += t[i];
    }
    FOR(i, 0, totalt + 1) {
        speed[i] = INF;
    }
    FOR(i, 0, n) cin>>v[i];
    intervals.push_back({0, {0, 0}});
    int csum = 0;
    FOR(i, 0, n) {
        intervals.push_back({v[i], {csum, csum + t[i]}});
        csum += t[i];
    }
    intervals.push_back({0, {totalt, totalt}});

    int l,r,sp;
    FOR(i, 0, intervals.size()) {
        sp = intervals[i].first;
        tie(l, r) = intervals[i].second;

        // cerr << l << " " << r << " " << sp << endl;

        FOR(ts, l, r + 1) {
            speed[ts] = min(speed[ts], 1.0 * sp);
        }
        FOR(ts, 0, l + 1) {
            speed[ts] = min(speed[ts], sp + (l - ts)/2.0);
        }
        FOR(ts, r, totalt + 1) {
            speed[ts] = min(speed[ts], sp + (ts - r)/2.0);
        }
    }

    long double res = 0;

    FOR(ts, 0, totalt) {
        res += 0.5 * (speed[ts] + speed[ts + 1]);
    }
    
    res /= 2;
    coud(res, 12);

    return 0;
}

Measured memory_bytes: 4044
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      m: usize,
    }
    let mut m = m;
    let mut ans;
    ans = min(n, m/2);
    m -= ans*2;
    ans += m/4;
    println!("{}", ans);
}


Measured memory_bytes: 4352
n=input()
k=int(input())
m=len(n)
dp=[[[0]*(k+1) for _ in range(2)] for _ in range(m+1)]
dp[0][0][0]=1
for i in range(1,m+1):
    l = int(n[i-1])
    for j in range(k+1):
        dp[i][1][j]+=dp[i-1][1][j] 
        if l!=0:
            dp[i][1][j]+=dp[i-1][0][j]  
        else:
            dp[i][0][j]+=dp[i-1][0][j]      
        if j-1>=0:
            dp[i][1][j]+=9*dp[i-1][1][j-1]
            if l!=0:
                dp[i][0][j]+=dp[i-1][0][j-1]
                dp[i][1][j]+=(l-1)*dp[i-1][0][j-1]
print(dp[m][0][k]+dp[m][1][k])

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, h; cin >> n >> h;
    int amax = 0; vector<int> b(n);
    rep (i, n) {
        int a; cin >> a >> b[i];
        chmax(amax, a);
    }
    sort(all(b)); reverse(all(b));
    ll now = 0, ans = 0;
    rep (i, n) {
        if (b[i] < amax) break;
        ans++;
        if ((now += b[i]) >= h) {
            cout << ans << "\n";
            return 0;
        }
    }
    cout << ((h - now - 1) / amax + 1) + ans << "\n";
    return 0;
}

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

int main(){
    int A,B,C;cin>>A>>B>>C;
    
    if(A==B&&A!=C)cout<<"Yes"<<endl;
    else if(A==C&&A!=B)cout<<"Yes"<<endl;
    else if(B==C&&A!=B)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;

void solve() {
	string n; cin >> n;
	int f = 0;
	for (unsigned int i = 0; i < n.length(); ++i) {
		f += (n[i] - '0');	
	}
	string ans = ((stoi(n) % f) == 0) ? "Yes" : "No";
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
import math


class Solution:

    def solve(self, N: int, M: int) -> int:

        mod = 10**9+7
        INT_MAX = 10**9

        # calculate {m+n}C{n}

        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

        def combination(n: int, r: int, mod: int = 10**9+7) -> int:
            r = min(r, n-r)
            res = 1
            for i in range(r):
                res = res * (n-i) * modinv(i+1, mod) % mod
            return res

        # solve

        m = M
        answer = 1
        factors = {}
        for i in range(2, int(math.sqrt(M))+1):
            factor = 0
            while m % i == 0:
                m //= i
                factor += 1

            if factor > 0:
                answer *= combination(N + factor - 1, N - 1, mod=mod)
                answer %= mod

        if m > 1:
            answer *= N
            answer %= mod

        return answer


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    print(solution.solve(N, M))


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

int main() {
    int64_t N, X, D;
    cin >> N >> X >> D;

    if (D == 0) {
        cout << (X == 0 ? 1 : N + 1) << endl;
        return 0;
    }

    map<int64_t, map<int64_t, int64_t>> mp;
    for (int64_t i = 0; i <= N; i++) {
        //N個からi個選ぶ
        //i * X + j * Dという形になる
        //これをa * D + bとして見る(0 <= b < D)
        int64_t mod = i * X % D;

        int64_t beta = (i - 1) * i / 2;
        int64_t t_max = i * (N - 1) - beta + i * X / D;
        int64_t t_min = beta + i * X / D;

        mp[mod][t_min] += 1;
        mp[mod][t_max + 1] -= 1;
    }

    int64_t ans = 0;
    for (const auto& mp1 : mp) {
        int64_t value = 0, start = -1;
        for (const auto& p : mp1.second) {
            if (value == 0 && p.second > 0) {
                start = p.first;
            }
            value += p.second;

            if (value == 0) {
                ans += p.first - start;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 44032
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int n, q; cin >> n >> q;
	string s; cin >> s;
	s = "*" + s + "*";
	vector<char> t(q), d(q);
	REP(i, q) cin >> t[i] >> d[i];
	int fr = n+1, fl = 0;
	for(int i = q-1; i >= 0; i--){
		if(d[i] == 'R' && s[fr-1] == t[i]) fr--;
		if(d[i] == 'R' && s[fl] == t[i]) fl--;
		if(d[i] == 'L' && s[fl+1] == t[i]) fl++;
		if(d[i] == 'L' && s[fr] == t[i]) fr++;
	}
	cout << max(fr - fl - 1, 0) << endl;
}

Measured memory_bytes: 4036
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#ifdef ConanYu
#include "local.hpp"
#else
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

int a[55];

void Main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      ans += (a[i] * a[j]);
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)


warp = [[dy, dx] for dy in range(-2, 3) for dx in range(-2, 3) if abs(dy) + abs(dx) > 1]

def main():
    H, W = LI()
    CH, CW = LI1()
    DH, DW = LI1()
    S = SR(H)
    dist = make_list(H, W, default=-1)

    q = deque()
    dist[CH][CW] = 0
    q.append((0, CH, CW))

    while q:
        d, y, x = q.popleft()

        for dy, dx in dire:
            newx, newy = x + dx, y + dy
            if 0 <= newx < W and 0 <= newy < H and S[newy][newx] == ".":
                if dist[newy][newx] == -1 or dist[newy][newx] > d:
                    dist[newy][newx] = d
                    q.appendleft((d, newy, newx))

        for dy, dx in warp:
            newx, newy = x + dx, y + dy
            if 0 <= newx < W and 0 <= newy < H and S[newy][newx] == ".":
                if dist[newy][newx] == -1 or dist[newy][newx] > d + 1:
                    dist[newy][newx] = d + 1
                    q.append((d + 1, newy, newx))

    print(dist[DH][DW])







if __name__ == '__main__':
    main()

Measured memory_bytes: 174252
#include <iostream>
#include <vector>

struct union_find {
	int N, M;
	std::vector<int> parent, sz;

	union_find(int n) : N(n), M(n) {
		parent.resize(N);
		for (int i = 0; i < N; i++) parent[i] = i;
		sz.resize(N, 1);
	}

	int root(int i) {
		if (parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}

	bool is_united(int i, int j) {return (root(i) == root(j));}

	int size(int i) {return sz[root(i)];}

	bool unite(int i, int j) {
		if (is_united(i, j)) return false;
		if (size(i) < size(j)) std::swap(i, j);
		i = root(i); j = root(j);
		parent[j] = i;
		sz[i] += sz[j];
		M--;
		return false;
	}
};

int main() {
	int n, m;
	std::cin >> n >> m;
	union_find uf(n);
	while (m--) {
		int a, b;
		std::cin >> a >> b;
		uf.unite(a - 1, b - 1);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) ans = std::max(ans, uf.size(i));
	std::cout << ans << '\n';

	return 0;
}

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

int main() {
  long long n; cin >>n;
  vector<long long>a(n),b(n);
  for(long long i=0;i<n;i++)cin>>a[i]>>b[i];
  long long kazu=0;
  for(long long i=n-1;i>=0;--i){
    long long tmp=b[i]-(a[i]+kazu)%b[i];
    if((a[i]+kazu)%b[i]!=0)kazu+=tmp;
    tmp=kazu;
  }
  cout<<kazu<<endl;
  return 0;
}

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

int j,y;
void dfs(int a,int b,string game){
  if(a==j && b==y){
    cout<< game<< endl;
    return;
  }
  else if(a>j || b>y) return;
  else if((a<=3 && b==5) || (a==5 && b<=3) || (a==6 || b==6)) return;
  else{
    dfs(a+1,b,game+'A'); 
    dfs(a,b+1,game+'B');
  }
}

main(){
  cin>> j>> y;
  dfs(0,0,"");
} 

Measured memory_bytes: 1200
#include <stdio.h>

int main(void){
	int i, a, sum=0, x=0;

	for(i=0; i<4; i++){
		scanf(" %d", &a);
		sum+=a;
	}
	
	while(sum>=60){
		sum-=60;
		x++;
	}

	printf("%d\n%d\n", x, sum);

	return 0;
}

Measured memory_bytes: 596
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　	  int a,b,sa,gokei;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
          	
          	sa = b-a;
          	gokei = 0;
          	while(sa>0){
              gokei = gokei+sa;
              sa--;
            }
          
          	Console.WriteLine(gokei-b);
        }
 }

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 440

int n, m, ans;
int s[AC], top, tmp;
bool f[AC][AC];

inline int read()
{
	int x = 0;char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

void pre(){
	n = read(), m = read();	
}

void work()
{
	for(R i = 1; i <= m; i ++)
	{
		int x = read(), y = read();
		if(f[y][y] || f[x][x]) //这一切的前提都是自己要活着。。。。
		{
			f[x][x] = f[y][y] = true;
			continue;
		}
		top = 0;
		for(R j = 1; j <= n; j ++) if(f[x][j])	s[++ top] = j;//找到y需要连哪些边
		for(R j = 1; j <= top; j ++) f[y][s[j]] = f[s[j]][y] = true;
		
		top = 0;
		for(R j = 1; j <= n; j ++) if(f[y][j]) s[++ top] = j;
		for(R j = 1; j <= top; j ++) f[x][s[j]] = f[s[j]][x] = true; 
		f[x][y] = f[y][x] = true;
	}
	
	for(R i = 1; i <= n; i ++)
		for(R j = i + 1; j <= n; j ++) 
			if(!f[i][j] && !f[j][j] && !f[i][i]) ++ ans;//需要两者都不是必须死的，而且没有不能共存的限制
	printf("%d\n", ans);
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work();
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;
	
	const ll mod = 1e9 + 7;
	vector<ll> dp(K + 1);
	dp[0] = 1;

	rep(i, N) {
		int a;
		cin >> a;

		//rep1(j, K) dp[j] += dp[j - 1];
		partial_sum(dp.begin(), dp.end(), dp.begin());

		auto are = dp.begin() - a - 1;
		for (int j = K; j > a; j--) {
			dp[j] -= are[j];
		}

		rep1(j, K) dp[j] %= mod;
	}

	co((dp[K] + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
		string s = Console.ReadLine();
		string[] answers = new string[n];
    bool answer = false;

    for(int i = 0; i < 4; i++)
    {
      if(i % 2 == 0) answers[0] = "S";
      else answers[0] = "W";
      if(i <= 1) answers[1] = "S";
      else answers[1] = "W";

      for(int j = 2; j < n; j++)//2匹だけ決まると残りは1通り
      {
        if(s[j-1] == 'o' && answers[j-1] == "S" ||
          s[j-1] == 'x' && answers[j-1] == "W")
        {
          if(answers[j-2] == "S") answers[j] = "S";
          else answers[j] = "W";
        }
        if(s[j-1] == 'x' && answers[j-1] == "S" ||
          s[j-1] == 'o' && answers[j-1] == "W")
        {
          if(answers[j-2] == "S") answers[j] = "W";
          else answers[j] = "S";
        }
      }

      if(s[n-1] == 'o' && answers[n-1] == "S" ||
        s[n-1] == 'x' && answers[n-1] == "W")
      {
        if(answers[0] != answers[n-2]) continue;
      }else 
      {
        if(answers[0] == answers[n-2]) continue;
      }

      if(s[0] == 'o' && answers[0] == "S" ||
        s[0] == 'x' && answers[0] == "W")
      {
        if(answers[1] != answers[n-1]) continue;
      }else 
      {
        if(answers[1] == answers[n-1]) continue;
      }

      answer = true;
      break;
    }

  	if(answer) Console.WriteLine(string.Join("", answers));
    else Console.WriteLine(-1);
	}
}

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

int a[30];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)scanf("%d", &a[i]);
		int cnt = 32;
		for (int i = 0; cnt; i++) {
			if (i & 1) {
				if (cnt < a[(i / 2) % n])cnt = 0;
				else cnt -= a[(i / 2) % n];
			}
			else {
				if (cnt == 1)cnt = 0;
				else cnt -= (cnt - 1) % 5;
			}
			printf("%d\n", cnt);
		}
	}
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
/*long f(long x,long y){
    long A = 1;
    for(int i=2;i<x+1;i++){
        A *= i;
    }
    long B = 1;
    for(int i=2;i<y+1;i++){
        B *= i;
    }
    long C = 1;
    for(int i=2;i<x-y+1;i++){
        C *= i;
    }
    long D = A/(B*C);
    return D;
}*/
    typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main()
{
    //ll n,k;
   // cin >> n >> k;

    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }


   long B; cin >> B;
   long ans = 0;
    //long M = pow(10,9)+7;
   for(int i=1;i<10000;i++){
       long a = B-3*i;
       if(a < 0)break;
       ans += comb(a+i-1,a)%M;
       ans %= M;
   }
   cout << ans << endl;
}


Measured memory_bytes: 7900
#include <iostream>
#include <vector>
#include <bitset>
#include <set>
#include <algorithm>
#include <queue>
#include <map>
#include <assert.h>
 
 
using namespace std;
 
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 2e18 + 7;
const int maxN = 2e6 + 5;
const ll MOD = 1e9 + 7;
 
int n, h[maxN], dp[maxN];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	REP(i, n) cin >> h[i];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	FOR(i, 2, n - 1) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
		//cout << dp[i] << " ";
	}
	cout << dp[n - 1];
	return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
lol u[111111];
lol ii[121111];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0,can;
  string s;
  lol M=0,A=0,R=0,C=0,H=0;
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>s;
    if(s[0]=='M') M++;
    else{
      if(s[0]=='A') A++;
      else{
	if(s[0]=='R') R++;
	else{
	  if(s[0]=='C') C++;
	  else{
	    if(s[0]=='H') H++;
	  }
	}
      }
    }
  }
  d=M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H;
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5,INF = 0x3f3f3f3f;
int n,m,k,ans = INF,cnt[15][N];
char mp[15][N];
vector<int> cut;
int res[15];
#define pb push_back 
inline int cont(int a,int b,int c) {
	return cnt[c][b] - cnt[a-1][b];
}
inline int calc() {
	int ans0 = 0;
	for(int i = 1;i <= m;++i)
		for(int j = 0;j < cut.size()-1;++j)
			if(cont(cut[j],i,cut[j+1]-1) > k) return INF;
	memset(res,0,sizeof res);
	for(int i = 1;i <= m;++i) {
		int ok = 0;
		for(int j = 0;j < cut.size()-1;++j)
			res[j] += cont(cut[j],i,cut[j+1]-1);
		for(int j = 0;j < cut.size()-1;++j)
			if(res[j] > k) ok = 1;
		if(ok) {
			++ans0;
			for(int j = 0;j < cut.size()-1;++j)
				res[j] = cont(cut[j],i,cut[j+1]-1);
		}
	}
	return ans0;
}
inline void dfs(int u) {
	if(u == n) {
		cut.pb(n+1);
		ans = min(ans,calc() + (int)cut.size() - 2);
		cut.pop_back();
		return;
	}
	dfs(u+1);
	cut.pb(u+1);
	dfs(u+1);
	cut.pop_back();
}
int main() {
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i <= n;++i)
		scanf("%s",&mp[i][1]);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j)
			cnt[i][j] = cnt[i-1][j] + (mp[i][j] == '1');
	cut.pb(1);
	dfs(1);
	cout << ans << endl;
	return 0;
}


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

int main() {
  long long N,K;
  //a = 3.0;
  //b = 2.0;
  long long ans1=0,ans2=0;
  cin >> N >> K;
  int ia;
  int mod = pow(10,9)+7;
  vector<int> via(0);//初期の配列のサイズを0にセット
  for(int i=0;i<N;i++){
    cin >> ia;   
    via.push_back(ia);
  }
  for(int i=1;i<N;i++){
    for(int j=0;j<N-i;j++){
      if(via[j]>via[j+i]){
        ans1++;
      }
    }
  }
  for(int i=0;i<N;i++){
    via.push_back(via[i]);
  }
  for(int i=1;i<N*2;i++){
    for(int j=0;j<N*2-i;j++){
      if(via[j]>via[j+i]){
        ans2++;
      }
    }
  }
  long long ans=0;
  if(K%2==0){
    ans = (((ans1%mod)*K)%mod + ((((ans2-(ans1*2)%mod)%mod * (K/2)%mod)%mod)*(K-1))%mod)%mod;
  }else{
    ans = (((ans1%mod)*K)%mod + ((((ans2-(ans1*2)%mod)%mod * ((K-1)/2)%mod)%mod)*(K))%mod)%mod;
  }


  cout << ans << endl;
  //cout << "test" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    cin >> l;
    int ans = lim<int>::max();
    for(int s = 0; s < 1 << (2 * n); s++) {
        int aa = 0, bb = 0, cc = 0, comb_a = -1, comb_b = -1, comb_c = -1;
        for(int i = 0; i < n; i++) {
            int x = (s >> 2 * i) & 0b11;
            if(x == 1) {
                aa += l[i];
                comb_a++;
            } else if(x == 2) {
                bb += l[i];
                comb_b++;
            } else if(x == 3) {
                cc += l[i];
                comb_c++;
            }
        }
        if(aa and bb and cc) {
            ans = min(ans, abs(a - aa) + abs(b - bb) + abs(c - cc) + 10 * comb_a + 10 * comb_b + 10 * comb_c);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split(" "))
A *= 100
B *= 100

water = []
for a in range(F//A+1):
    for b in range(F//B+1):
        if a + b == 0 or a * A + b * B > F:
            continue
        if not((a * A + b * B) in water):
            water.append(a * A + b * B)

water.sort()

suger = []
for c in range(F//C+1):
    for d in range(F//D+1):
        if c * C + d * D > F:
            continue
        if not((c * C + d * D) in suger):
            suger.append(c * C + d * D)

suger.sort()

max_dense = 0
log = [water[0],0]
for w in water:
    for s in suger:
        dense = 100 * s / w
        if w + s > F or dense > E:
            break
        elif dense == E:
            print(" ".join(map(str,[w+s,s])))
            exit()
        elif dense > max_dense:
            max_dense = dense
            log = [w+s,s]

print(" ".join(map(str,log)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;	


int n,x,t;

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

	
	
	cin >> n >> x >> t;
	cout << ((n+x-1)/x)*t << "\n";
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
int main(void)
{
 int N,M;
 int g = 0;
 int s = 0;
 int b = 0;
 int i,j;
 int tmp1 =0 ;
 int tmp10 =0 ;
 int tmp100 =0 ;

 int A[M];
 int B[M];

 scanf("%d %d\n",&N,&M);
	if (M == 0){
               if (N == 1){
			printf("0");
			return 0;
		}else if(N == 2){
			printf("10");
			return 0;
		}else{
			printf("100");
			return 0; 
		}
	}

 for(i=0;i<M;i++)
  {
  scanf("%d %d\n",&A[i],&B[i]);
  if((A[i] > N)||(A[i]==1&&B[i]==0&&N>=2))
    {
      printf("-1\n");
      return 0;
    }
  }

  for(i=0;i<M;i++)
   for(j=0;j<M;j++)
    {
     if(A[i]==A[j] && B[i]!=B[j])
       {printf("-1\n");
      goto L_Break;}
    }


 if(N==1)
  {
   for(i=0;i<M;i++)
    if(A[i] == 1) tmp1 = B[i];

  for(i=0;i<M;i++) 
    if(A[i] == 1 && B[i] <= tmp1) tmp1 = B[i];
  if(tmp1 != 0 )  printf("%d\n",tmp1);
  else printf("0\n");
 }
 else if (N==2)
  {
    int xx=1,x=0;

   for(i=0;i<M;i++)
    {
     if(A[i] == 1) xx = B[i];
     else if(A[i] == 2) x = B[i];
    }
   printf("%d%d\n",xx,x);

   }

 else if (N==3)
  {
  int xxx=1,xx=0,x=0;

   for(i=0;i<M;i++)
    {
     if(A[i] == 1) xxx = B[i];
     else if(A[i] == 2) xx = B[i];
     else if(A[i] == 3) x = B[i];
    }
  printf("%d%d%d\n",xxx,xx,x);
   }

 L_Break:

 return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  rep(i,n)a[i]--;
  vector<int>idx(n);
  rep(i,n) idx[a[i]]=i;
  set<int>s;
  ll ans=0;
  for (int x=n-1;x>=0;--x){
    int i = idx[x];
    ll c=0;
    { //calc c
      s.insert(i);
      vector<int> l(2,-1);
      vector<int> r(2,n);
      {//calc l
        auto it=s.find(i);
        rep(j,2){
          if (it==s.begin()) break;
          --it;
          l[j]=*it;
        }
      }
      {//calc r
        auto it=s.find(i);
        rep(j,2){
          ++it;
          if (it==s.end()) break;          
          r[j]=*it;
        }
      }
      vector<int> ls(2);
      ls[0]=i-l[0]; ls[1]=l[0]-l[1];
      vector<int> rs(2);
      rs[0]=r[0]-i; rs[1]=r[1]-r[0]; 
      c=(ll)ls[0]*rs[1]+(ll)ls[1]*rs[0];
    }
    ans+=c*(x+1);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
int main(){
  int n;
  cin >> n;
  int d[n];
  for (int i = 0; i < n;i++)
  {
    cin >> d[i];
  }
  sort(d,d+n);
  if(n%2){
    cout << 0 << endl;
  } else if(d[n/2]==d[n/2-1]){
    cout << 0 << endl;
  } else {
    cout << d[n/2]-d[n/2-1] << endl;
  }
}


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

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
#define MOD 1000000007
typedef long long ll;

/* 2017/01/25 問題 ----- ABC042 C/Link http://abc042.contest.atcoder.jp/tasks/arc058_a */
/* -----解説等-----
問題: いろはちゃんはこだわりもので、嫌いな数字が K 個あり、それぞれ D1,D2,…,DK です。

いろはちゃんはお店でお買い物をしていて、 N 円の品物を買おうとしています。
もちろん、この品物は N 円以上のお金を支払えば買うことができます。
しかし、先ほど述べたようにいろはちゃんは強いこだわりがあるので、
自分がお店に支払う金額の 10 進表記にいろはちゃんの嫌いな数字が出現しないような最も少ない金額を支払おうとします。

いろはちゃんが支払う金額を求めてください。




*/

int N, K;
bool d[10];
int ans = 0;

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

    cin >> N >> K;
    FOR(i, 0, K) {
        int s;
        cin >> s;
        d[s] = true;
    }
    int x = N;
    for (;;) {
        bool flag = true;
        int t = x;
        while (t) {
            if (d[t % 10])flag = false;
            t /= 10;
        }
        if (flag) {
            cout << x << endl;
            return 0;
        }
            x++;
    }


    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Applicative
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt

for = flip map

main :: IO ()
main = do
  n <- readLn :: IO Int
  list <- map (fromIntegral . readIntBS) . BS.words <$> BS.getLine :: IO [Integer]
  let
    (as,bs) = splitAt n list
    (cs,ds) = splitAt n (reverse list)

    func1 _ s 0 = return [s]
    func1 (x:xs) s i = do
      ((m,_),set) <- Set.deleteFindMin . Set.insert (x,n+i) <$> get
      put set
      (s:) <$> func1 xs (s-m+x) (i-1)

    func2 _ s 0 = return [s]
    func2 (x:xs) s i = do
      ((m,_),set) <- Set.deleteFindMax . Set.insert (x,n+i) <$> get
      put set
      (s:) <$> func2 xs (s-m+x) (i-1)

  print $ maximum $ zipWith (\a b -> a - b)
    (evalState (func1 bs (sum as) n) (Set.fromList $ zip as [1..]))
    (reverse $ evalState (func2 ds (sum cs) n) (Set.fromList $ zip cs [1..]))



Measured memory_bytes: 119164
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n;
int main()
{
	FAST
	ll m,t;
	cin>>n>>m>>t;
	cout << (t / n)*m << '\n';
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double t = sc.nextDouble();
        double a = sc.nextDouble();
        double rem = Integer.MAX_VALUE;
        int ans = 0;
        for(int i = 1; i <= n; i++){
            double h = sc.nextDouble();
            if(rem > Math.abs(t-h*0.006-a)){
                ans = i;
                rem = Math.abs(t-h*0.006-a);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27092
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;


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

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

    int pAlice = 0, pBob = 0;

    for(int i=n-1;i>=0;i-=2){
        if(n % 2 == 1 && i == 0){
            pAlice += a[i];
        }
        else {
            pAlice += a[i];
            pBob += a[i-1];
        }
        
    }

    cout << pAlice - pBob << endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
a.sort()
m = a[-1]
s = [0]*(m+1)
ans = 0
for i in a:
    if s[i] <= 1:
        for j in range(i, m+1, i):
            s[j] += 1
for k in a:
    if s[k] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 33212
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int table[26];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,L;cin >> N >> L;
    vector<string> s(N);
    REP(i,N) cin >> s[i];
    sort(s.begin(),s.end());
    string ans = "";
    REP(i,N) ans+=s[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256