akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int H, W, M;

void solve(ll &ans, vector<int> &Hmaxpos, vector<int> &Wmaxpos,
           map<P, int> &bomb) {
    int cnt = 1;
    for (auto x : Hmaxpos) {
        for (auto y : Wmaxpos) {
            P p = make_pair(x, y);
            if (bomb[p] == 0) return;
            if (cnt == M) {
                --ans;
                return;
            }
            ++cnt;
        }
    }
    --ans;
    return;
}

int main() {
    cin >> H >> W >> M;
    vector<int> h(M), w(M);
    rep(i, M) cin >> h[i] >> w[i];

    vector<int> cntH(H + 1, 0), cntW(W + 1, 0);
    map<P, int> bomb;
    rep(i, M) {
        ++cntH[h[i]];
        ++cntW[w[i]];
        P p = make_pair(h[i], w[i]);
        ++bomb[p];
    }
    vector<int> Hmaxpos, Wmaxpos;
    int Hmax = -1;
    int Wmax = -1;
    rep(i, H + 1) {
        if (cntH[i] < Hmax) continue;
        if (cntH[i] > Hmax) Hmaxpos.clear();
        Hmax = cntH[i];
        Hmaxpos.push_back(i);
    }
    rep(i, W + 1) {
        if (cntW[i] < Wmax) continue;
        if (cntW[i] > Wmax) Wmaxpos.clear();
        Wmax = cntW[i];
        Wmaxpos.push_back(i);
    }
    ll ans = Hmax + Wmax;
    solve(ans, Hmaxpos, Wmaxpos, bomb);
    cout << ans << endl;
}

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

using namespace std;

const int INF = 1 << 30;

int S, N, M, X[2000], T[2000];
int sum[2001][2001], dp[2001][2001];

int getcost(int left, int right)
{
  return (sum[left][right - 1]);
}

void rec(int idx, int left, int right, int latte, int malta)
{
  if(left >= right) return;
  int mid = (left + right) >> 1;
  dp[idx][mid] = INF;
  int best = -1;
  for(int k = latte; k < min(mid, malta); k++) {
    int cost = dp[idx - 1][k] + getcost(k, mid); // cost[k, mid)
    if(cost < dp[idx][mid]) {
      dp[idx][mid] = cost;
      best = k;
    }
  }
  rec(idx, left, mid, latte, best + 1);
  rec(idx, mid + 1, right, best, malta);
}


int main()
{
  cin >> S >> N >> M;
  for(int i = 0; i < S; i++) {
    cin >> X[i];
  }
  for(int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    T[i] = a - X[--b];
  }
  sort(T, T + N);

  for(int right = N - 1; right >= 0; right--) {
    for(int left = right - 1; left >= 0; left--) {
      sum[left][right] = sum[left + 1][right] + T[right] - T[left];
    }
  }

  fill_n(*dp, 2001 * 2001, INF);
  dp[0][0] = 0;
  for(int i = 1; i <= M; i++) {
    rec(i, 0, N + 1, 0, N + 1);
    for(int j = 0; j <= N; j++) dp[i][j] = min(dp[i][j], dp[i - 1][j]);
  }

  cout << dp[M][N] << endl;
}

Measured memory_bytes: 32588
def check(num):
    return (1<=int(num) and int(num)<=12)
s=input()
first=check(int(s[0:2]))
second=check(int(s[2:]))
if first and second:
    print("AMBIGUOUS")
elif first and not second:
    print("MMYY")
elif not first and second:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3060
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
A = []
B = []
N.times do |i|
  A[i], B[i] = get_ints
end

xx = A.zip(B).map { |a, b| [a, b] }.sort { |a, b| a[0] <=> b[0] }

count = 0
total = 0
xx.each do |x|
  if count + x[1] > M
    total += x[0] * (M - count)
    count = M
    break
  else
    total += x[0] * x[1]
    count += x[1]
  end
  # p total
  # p count
end

puts total


Measured memory_bytes: 27592
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define MOD 1000000007

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

// fact_num[i] = i! % MOD
// fact_denpow[i] = (i**(MOD-2)) % MOD
// fact_den[i] = fact_denpow[i]! % MOD
// nCm = fact_num[n] * fact_den[m] * fact_den[n-m]
// で計算できる（MODを適切に取る）
// O(NlogN)
void set_table(int N, vector<long long> &fact_num, vector<long long> &fact_den){
    fact_num.resize(N+1, 0);
    fact_den.resize(N+1, 0);
    vector<long long> fact_denpow(N+1, 0);

    fact_num[0] = 1;
    for(int i=1; i<=N; i++) fact_num[i] = (fact_num[i-1] * i) % MOD;

    for(int i=0; i<=N; i++) fact_denpow[i] = bipow(i, MOD-2);
    fact_den[0] = 1;
    for(int i=1; i<=N; i++) fact_den[i] = (fact_den[i-1] * fact_denpow[i]) % MOD;
}

// mCn
long long comb(const vector<long long> &fact_num, const vector<long long> &fact_den, int m, int n){
    return ((fact_num[m] * fact_den[n]) % MOD * fact_den[m-n]) % MOD;
}

long long fac[123456];

int main(){
    long long N;
    cin >> N;
    if(N == 2){
        cout << 1 << endl;
        return 0;
    }
    vector<long long> fact_num, fact_den;
    set_table(N, fact_num, fact_den);

    vector<long long> v(N);
    for(int i=2; i<N; i++){
        if(i-1 < N-i-1) continue;
        long long tmp = (fact_num[i] * fact_num[N-1-i]) % MOD;
        tmp *= comb(fact_num, fact_den, i-1, N-1-i);
        tmp %= MOD;
        v[i] = tmp;
    }

    long long ans = 0;
    for(int i=2; i<N; i++){
        long long tmp = v[i];
        if(i != 2) tmp = (tmp - v[i-1] + MOD) % MOD;
        tmp = (tmp * i) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    x -= a[i];
    if (x < 0) break;
    cnt++;
  }
  dump(x > 0 ? cnt-1 : cnt);
  return 0;
}


Measured memory_bytes: 256
import math
#数値ひとつ
#I = int(input())
#数値欲しいとき
N, M = map(int, input().split())
#文字欲しいとき
#N = input()
#それをListにしたいとき
#listA = list(N)
#受け取る数が未定かつリストにしたいとき
#list = list(map(int, input().split()))

if N>M:
    print('safe')
else:
    print('unsafe')

Measured memory_bytes: 9036
#include <stdio.h>

int main(void) {
	int A, B, C;
	int tomatuharuka;
	if (scanf("%d%d%d", &A, &B, &C) != 3) return 1;
	tomatuharuka = C - (A - B);
	if (tomatuharuka < 0) tomatuharuka = 0;
	printf("%d\n", tomatuharuka);
	return 0;
}


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

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 

//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;
ll t=1;

void solve()
{ll cnt=1;
    cin>>n;
    if(n%2==0 or n%5==0)
    {
        cout<<-1;return;
    }
   ll num=0;
    while(1)
    {
        num=(10*num)+7;
        num%=n;
        if(num%n==0)
        {
            cout<<cnt;return;
        }
        cnt++;
    }
   // cout<<cnt-1;
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>


int main(){
	int n;
	int a=0;
	int	b=0;
	int apoint=0;
	int bpoint=0;
	int i;

	scanf("%d",&n);

	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%d %d",&a,&b);
			if(a<b){
				bpoint = bpoint + a + b;
			}if(a>b){
				apoint = apoint + a + b;
			}if(a==b){
				apoint= apoint + a;
				bpoint= bpoint + b;
			}
		}		
		printf("%d %d\n",apoint,bpoint);
		apoint=0;
		bpoint=0;
		scanf("%d",&n);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
string s,t,ss;
set<string>st;
int lens,lent;
void check(int l,int r)
{
    if(l>r) return;
    for(int i=l,j=0;i<=r&&j<lent;i++,j++)
    {
        if(ss[i]==t[j]) continue;
        if(ss[i]=='?') ss[i]=t[j];
        else return;
    }
    for(int i=0;i<lens;i++) if(ss[i]=='?') ss[i]='a';
    st.insert(ss);
}
int main()
{
    cin>>s;
    cin>>t;
    lens=s.size(),lent=t.size();
    for(int i=lens-1;i>=0;i--)
    {
        ss=s;
        check(i-lent+1,i);
    }
    if(st.empty()) printf("UNRESTORABLE\n");
    else cout<<*st.begin()<<endl;
}


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

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

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long a = Long.parseLong(in.next());
            long b = Long.parseLong(in.next());
            long n = Long.parseLong(in.next());
            long ans = -1;
            long cnt = b;

            if (n < b) cnt = n;
            if (n >= b) {
                ans = f(a, b, b - 1);
            } else {
                ans = f(a, b, n);

            }

            // 出力
            out.println(ans);

        }

        public static long f(long a, long b, long x) {
            long res = 0;
            res = (long) (Math.floor(a * x / b) - a * Math.floor(x / b));
            return res;
        }

    }
}



Measured memory_bytes: 35808
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
	int N, cnt=0,Min=1987654321;
	long long sum=0;
	bool wildcard=false;
	scanf("%d",&N);
	while(N--){
		int tmp;
		scanf("%d",&tmp);
		if(tmp==0) wildcard=true;
		sum+=abs(tmp);
		Min=min(Min,abs(tmp));
		cnt+=tmp<0;
	}
	printf("%lld",sum-((wildcard||(cnt%2==0))?0:Min*2));
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void) {
	
	int G[100][100] = { 0 };
	int n, v, k, num, i, j;

	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		scanf("%d", &v);
		scanf("%d", &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &num);
			G[v-1][num-1] = 1;
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n-1; j++) {
			printf("%d ", G[i][j]);
		}
        printf("%d", G[i][j]);
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2072
def main():
    import sys
    input = sys.stdin.readline

    n = int(input().rstrip('\n'))
    s = input().rstrip('\n')
    q = int(input().rstrip('\n'))
    Q = []

    for _ in range(q):
        Q.append(input().rstrip().split())

    class SegTree():
        def __init__(self, n_):
            self.n = 1
            while self.n < n_:
                self.n *= 2
            self.tree = []
            for _ in range(2 * self.n - 1):
                self.tree.append(2)
        def update(self, k, a):
            k += self.n - 1
            self.tree[k] = a
            while k > 0:
                k = (k - 1) // 2
                self.tree[k] = min(self.tree[k * 2 + 1], self.tree[k * 2 + 2])
        def query(self, l, r):
            l += self.n - 1
            r += self.n - 2
            res = 2
            while r-l>1:
                if l&1 == 0:
                    res = min(res,self.tree[l])
                if r&1 == 1:
                    res = min(res,self.tree[r])
                    r -= 1
                l = l//2
                r = (r-1)//2
            if l == r:
                res = min(res,self.tree[l])
            else:
                res = min(min(res,self.tree[l]),self.tree[r])
            return res

    d = { c: SegTree(n) for c in "abcdefghijklmnopqrstuvwxyz"}
    l = []

    for i, c in enumerate(s):
        d[c].update(i, 1)
        l.append(c)

    for a, b, c in Q:
        if a == "1":
            b = int(b) - 1
            d[l[b]].update(b, 2)
            d[c].update(b, 1)
            l[b] = c
        else:
            res = 0
            b, c = int(b), int(c)
            for key in d:
                if d[key].query(b-1, c) == 1:
                    res += 1
            print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 397088
#include <stdio.h>
#include <iostream>

#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>


using namespace std;

struct player{
	string card;
	int now;
	char now_card(){
		if(card.length() < now) return '#';
		return card[now++];
	}
};

int turn_convert(char ca){
	switch(ca){
		case 'a': return 0;
		case 'b': return 1;
		case 'c': return 2;
	}
}

string player_convert(int turn){
	switch(turn){
		case 0: return "A";
		case 1: return "B";
		case 2: return "C";
	}
}

void check( int val ){
	
	cout << val << endl;
}

int main( int argc , char ** argv ){
	
	player ABC[3];
	for(int i=0 ; i< 3 ; i++){
		cin >> ABC[i].card;
		ABC[i].now = 0;
	}

	int turn = 0;
	while(1){
		char now = ABC[turn].now_card();
		if(now == '#') break;
		turn = turn_convert(now);
	}

	cout << player_convert(turn) << endl;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint H, N; cin >> H >> N;
    vec<lint> A_list(N);
    range(i, 0, N) cin >> A_list.at(i);
    lint sum = 0;
    range(i, 0, N) sum += A_list.at(i);
    cout << (sum >= H ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    int N , gu = 0 , ki = 0;
    cin >> N;
    vector <int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
        if(A.at(i) % 2 == 0){
            gu++;
        }
        else{
            ki++;
        }
    }
    if(ki % 2 == 1){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
int main() {
	int a,i;
	bool f = true;
	stack<int> c;
	cin >> a;
	vector<int>b(a);
	vector<bool>d(1001,true);
	for (i = 0;i < a;i++) {
		cin >> b[i];
		if (b[i] > 0) {
			c.push(b[i]);
			if (d[b[i]]) d[b[i]] = false;
			else {
				f = false;
				break;
			}
		}
		else {
			if (d[b[i]*-1]) {
				f = false;
				break;
			}
			else if (c.top() != b[i] * -1) {
				f = false;
				break;
			}
			else {	
				c.pop();
				d[b[i] * -1] = true;
			}
		}
	}
	if (f)cout << "OK" << endl;
	else cout << i + 1 << endl;
}



Measured memory_bytes: 3100
"""
(x+y+z)^2 = (x^2+y^2+z^2) + 2(xy+yz+zx)
"""
def func(x, y, z): return (x + y + z) ** 2 - x * y - y * z - z * x


def main():
    num = int(input())
    counter = [0] * (num + 1)
    # func(41, 41, 41) = 10086
    # func(99, 1, 1) = 10002
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 123 - x - y + 1):
                if (tmp := func(x, y, z)) <= num:
                    counter[tmp] += 1
    for count in counter[1:]:
        print(count)


if __name__ == '__main__':
    main()


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

int64_t univMod=1000000007;
vector<int64_t> modfact(100000);
vector<int64_t> modinvfact(100000);

void setmodfact(){
  for(int i=0;i<100000;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

void setinvfact(){
  for(int i=0;i<100000;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
      
int main(){
  setmodfact();
  setinvfact();
  int64_t n,k;
  cin >> n >> k;
  vector<int64_t> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  int64_t sum = 0;
  rep(i,n){
    if(i >= k-1){
      sum = (sum + a.at(i)*calcmodcomb(i,k-1))%univMod;
      //cout << sum;
    }
  }
  rep(i,n){
    if(n-1-i>=k-1){
      sum = (sum + calcmodpositive(-a.at(i)*calcmodcomb(n-1-i,k-1)))%univMod;
      //cout << sum;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	vector<int> t(2);
	for (int i = 0; i < 2; i++) {
		cin >> t[i];
	}
	vector<ll> a(2);
	for (int i = 0; i < 2; i++) {
		cin >> a[i];
	}
	vector<ll> b(2);
	for (int i = 0; i < 2; i++) {
		cin >> b[i];
	}


	vector<ll> d(2);
	for (int i = 0; i < 2; i++) {
		d[i] = a[i] - b[i];
	}

	if (d[0] < 0) {
		d[0] *= -1;
		d[1] *= -1;
	}

	ll dis = d[0] * t[0];
	ll c = dis + d[1] * t[1];
	if (c == 0) {
		cout << "infinity" << endl;
		return 0;
	}

	if (c > 0) {
		cout << 0 << endl;
	}
	else {
		ll ans = 2 * (dis / abs(c));

		if (dis % abs(c) != 0) {
			ans++;
		}

		cout << ans << endl;


	}
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    while (1) {
        int a, b; cin >> a >> b;
        if (a + b == 0) {
            break;
        }
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                if ((i + j) % 2)
                    cout << '.';
                else 
                    cout << '#';
            }
                cout << '\n';
        }
        cout << '\n';
    }
}



Measured memory_bytes: 3084
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int l[m],r[m];
  rep(i,m){
    cin>>l[i]>>r[i];
  }
  sort(l,l+m);
  sort(r,r+m);
  int ans=r[0]-l[m-1]+1;
  if(ans>0) cout<<ans;
  else cout<<0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;


void ABC110C()
{
	string S, T;
	cin >> S >> T;
	int N = S.size();

	map<char, char> charMap;
	map<char, char> charMap2;

	for (int i = 0; i < N; ++i)
	{
		auto p = charMap.find(S[i]);
		if (p == charMap.cend())
		{
			charMap[S[i]] = T[i];
		}
		else if (p->second != T[i])
		{
			cout << "No" << endl;
			return;
		}

		auto q = charMap2.find(T[i]);
		if (q == charMap2.cend())
		{
			charMap2[T[i]] = S[i];
		}
		else if (q->second != S[i])
		{
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

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


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 300
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<int>> Matrix;
typedef unordered_set<int> us;

int n;
Matrix s;

inline void input() {
    cin >> n;
    s = Matrix(n, vector<int>(n, INF));
    rep(i, n) {
        string x;
        cin >> x;
        s[i][i] = 0;
        rep(j, n) if (x[j] == '1') s[i][j] = 1;;
    }
}

inline bool not_bin_graph() {
    us g1, g2, now, next, visit;
    g1.insert(0);
    now.insert(0);
    visit.insert(0);
    while (true) {
        for (int i : now) visit.insert(i);
        for (int i : now) {
            for (int j = 0; j < n; j++) {
                if (s[i][j] == 1) {
                    g2.insert(j);
                    if (!visit.count(j)) next.insert(j);
                }
            }
        }
        if (next.size() == 0) break; 
        now = next;
        next.clear();
        swap(g1, g2);
    }
    if (g1.size() > g2.size()) swap(g1, g2);
    for (int x : g1) if (g2.count(x)) return true;
    return false;
}

inline void warshall_floyd() {
    rep(k, n)rep(i, n)rep(j, n) s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
}

int main() {
    input();
    if (not_bin_graph()) {
        cout << -1 << endl;
        return 0;
    }
    warshall_floyd();
    int ans = 0;
    rep(i, n)rep(j, n) {
        if (s[i][j] == INF) continue;
        ans = max(ans, s[i][j]);
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
int64 a, b, c;
int main()
{
    a = read(), b = read(), c = read();
    if((a&1)&&(b&1)&&(c&1)) printf("%lld\n", min(a*b, min(a*c, b*c)));
    else printf("%d\n", 0);
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

int A, B;

ll solve() {
    REP (i, 1e4) {
        if (i * 8 / 100 == A && i * 10 / 100== B) {
            return i;
        }
    }
    return -1;
}

int main() {
    cin >> A >> B;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream> 
#include <numeric>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std; 
int main(){
#define int long long
	int a, b, r, x, temp;
	while(cin >> a >> b){
	x = a*b;
	if (a<b)
	{
	temp = a;
	a = b;
	b = temp;
	}
	r = a%b;
	while (r!=0)
	{
	a = b;
	b = r;
	r = a%b;
	}
	cout << b << " " << x/b << endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    long long n, x, q;
    long long sum = 0;

    cin >> n;
    long long cnt[100002] = {0};

    for(int i = 0; i < n; i++)
        cin >> x, sum += x, cnt[x]++;

    cin >> q;
    while(q--) {
        long long b, c;
        cin >> b >> c;
        sum -= cnt[b] * b;
        sum += cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << '\n';
    }

    return 0;
}


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

using namespace std;
int main() {
  int a, b;
  int ans = -1;
  cin >> a >> b;
  
  for(int i = 0; i < 10100; i++)
  {
    if( ((int)(i *  0.08) == a) && ((int)(i * 0.1) == b) ){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

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

class UnionFind {
public:
  vector<int> rank, p, num_of_nodes;
  //rank : 各ノードxを根としたときの木の高さをrank[x]とする
  //p : 各ノードxの親をp[x]とする

  UnionFind() {} // Default constructor

  UnionFind(int size = 0) {
    rank.resize(size, 0);
    p.resize(size, 0);
    num_of_nodes.resize(size, 1);
    for (int i = 0; i < size; i++) makeSet(i);
  }

  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    if (root(x) == root(y)) return; //すでに同じ根に属している場合は何もしない
    link(root(x), root(y));
  }

  void link(int x, int y) {
    //低い木を高い木に結合する
    if (rank[x] > rank[y]) { // xのほうが高い木 : xにyを統合
      p[y] = x;
      num_of_nodes[x] += num_of_nodes[y];
    }
    else if (rank[y] > rank[x]){ // yのほうが高い木 : yにxを統合
      p[x] = y;
      num_of_nodes[y] += num_of_nodes[x];
    }
    else {
      p[x] = y;
      rank[y]++;
      num_of_nodes[y] += num_of_nodes[x];
    }
  }

  int root(int x) {
    if (x != p[x]) { // if x is not root
      p[x] = root(p[x]);
    }
    return p[x];
  }

  int size(int x) {
    return num_of_nodes[root(x)];
  }

private:

};

int deg[MAX]; // 各ノードの出次数
vector<int> brock_to[MAX]; //各ノードへのブロック

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf = UnionFind(n);

  //create united groups
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
    deg[a]++; deg[b]++;
  }

  //create map for brock-brocked persons relation
  for (int j = 0; j < k; j++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    brock_to[a].push_back(b);
    brock_to[b].push_back(a);
  }

  for (int i = 0; i < n; i++) {
    int result = uf.size(i) - 1 - deg[i];
    for (int brocker : brock_to[i]) {
      if (uf.same(brocker, i) == true) result--;
    }
    if (i > 0) cout << " ";
    cout << result;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 7552
N, K = map(int, input().split())
X = [input().split() for _ in range(N)]

grid = [[0] * (2 * K + 1) for _ in range(2 * K + 1)]
for x, y, c in X:
    x, y = map(int, [x, y])
    if c == "W":
        y += K
    grid[x % (2 * K) + 1][y % (2 * K) + 1] += 1
        
for i in range(2 * K):
    for j in range(2 * K):
        grid[i + 1][j + 1] += grid[i][j + 1]

for i in range(2 * K):
    for j in range(2 * K):
        grid[i + 1][j + 1] += grid[i + 1][j]

def count(x, y, i, j):
    return grid[x][y] + grid[i][j] - grid[x][j] - grid[i][y]

ans = 0
for i in range(K + 1):
    for j in range(K + 1):
        tmp = 0
        tmp += count(i + K, j + K, i, j)
        tmp += count(i, j, 0, 0)
        tmp += count(i, 2 * K, 0, j + K)
        tmp += count(2 * K, j, i + K, 0)
        tmp += count(2 * K, 2 * K, i + K, j + K)
        ans = max(ans, tmp, N - tmp)

print(ans)


Measured memory_bytes: 110424
import java.util.*
 
fun main(args: Array<String>) {
  var num = readLine()!!.split(" ").map{ it -> it.toInt() }
  var a = num[0]
  var b = num[1]
  var c = num[2]
  
  if ( b + c < a ) {
    println(0)
  } else {
    println(b+c-a)
  }
}

Measured memory_bytes: 37828
#include <bits/stdc++.h>
using namespace std;
long long a[55], b[55];
int main() {
  long long n, x;
  cin >> n >> x;
  a[0] = 1;
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] * 2 + 1;
  }
  b[0] = 1;
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1] * 2 + 3;
  }
  long long  ans = 0;
  while (x > 0) {
    if (x == b[n]) {
      ans += a[n];
      x = 0;
    } else if (x >= b[n] / 2 + 1) {
      ans += a[n - 1] + 1;
      x -= b[n] / 2 + 1;
    } else {
      x--;
    }
    n--;
  }
  cout << ans << endl;
  return 0;
  
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
	int a;
	cin>>a;
	if(a<1200){
		cout<<"ABC"<<endl;
	}else if(a<2800){
		cout<<"ARC"<<endl;
	}else{
		cout<<"AGC"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
int main(){
	int n,i,x,sum=0;
	cin>>n>>x;
	int L[n];
	for(i=1;i<=n;i++){
		cin>>L[i];
	}
	int count=0;
	for(i=1;i<=n+1;i++){
		if(i==1){
			sum=0;
		}else{
			sum+=L[i-1];		
		}
		if(sum<=x) count++;
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
 
using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
 
  int N = input();
  map<string, int> S;

  int maxCount = 0;
  for(int i=0;i<N;i++){
    string s = input<string>();
    S[s]++;
    maxCount = max(maxCount, S[s]);
  }

  vector<string> answer;
  for(auto iter:S){
    if(iter.second == maxCount)answer.push_back(iter.first);
  }
  std::sort(answer.begin(), answer.end());
  for(auto iter:answer){
    output(iter);
  }

 
  return 0;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    for(char c : s){
        if(c=='?'){
            cout<<'D';
        }else{
            cout<<c;
        }
    }
    cout<<endl;
}

Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int ans = 0;
		for(var i=1;i<N;i++){
			ans += (N-1)/i;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17640
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
	return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
	mem(isprime,true);
	for(ll p=2;p*p<=n;p++)
	{
		if(isprime[p]==true)
		{
			for(ll i=p*p;i<=n;i+=p)
				isprime[i]=false;
		}
	}
}
ll lcm(ll a,ll b)
{
	return (a/__gcd(a,b))*b;
}
ll dp[101][100001];
ll w[101],v[101];
ll knapsack(ll i,ll W)
{
	if(dp[i][W]!=0)
		return dp[i][W];
	if(i==0)
	{
		if(w[i]<=W)
		{
			dp[i][W]=v[i];
			return v[i];
		}
		else
		{
			dp[i][W]=0;
			return 0;
		}
	}
	if(w[i]>W)
		dp[i][W]=knapsack(i-1,W);
	else
		dp[i][W]=max(v[i]+knapsack(i-1,W-w[i]),knapsack(i-1,W));
	return dp[i][W];
}
void solve()
{
	ll n,W;
	cin>>n>>W;
	mem(dp,0);
	for(ll i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
	}
	cout<<knapsack(n-1,W);
}
int main()
{
	IOS
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 79232
#include <iostream>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
vector<int>distan(90001, 0);
int main(void)
{
	vector<long long>arr(5);
	long long N; cin >> N;
	for (int i = 0; i < N; i++)
	{
		string a; cin >> a;
		if (a[0] == 'M')
		{
			arr[0]++;
		}
		if (a[0] == 'A')
		{
			arr[1]++;
		}
		if (a[0] == 'R')
		{
			arr[2]++;
		}
		if (a[0] == 'C')
		{
			arr[3]++;
		}
		if (a[0] == 'H')
		{
			arr[4]++;
		}
	}
	long long count = 0;
	for (int i = 0; i < 5; i++)
	{
		for (int j = i + 1; j < 5; j++)
		{
			for (int l = j + 1; l < 5; l++)
			{
				count += arr[i] * arr[j] * arr[l];
			}
		}
	}
	cout << count << "\n";
}

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

d = [0 for i in range(n+1)]
ans = 1
for i in range(n):
    if a[i] == 0:
        ans *= 3-d[0]
        d[0] += 1
    else:
        d[a[i]] += 1
        ans *= d[a[i]-1] - d[a[i]] + 1
        ans %= 10**9+7

print(ans)


Measured memory_bytes: 56556
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
//#define MOD 998244353
#define MOD 1000000007
#define PI 3.14159265358979
using ll = long long;
using namespace std;

int main(){
    int n,m;
    bool stair[100005]={};//false:not broken, true:broken
    cin>>n>>m;
    rep(i,m){
        int t;
        cin>>t;
        stair[t]=true;
    }
    ll ans[100005]={};
    ans[0]=1;
    if(stair[1]==false) ans[1]=1;
    for(int i=2;i<=n;i++){
        if(stair[i-1]==false) ans[i]+=ans[i-1];
        ans[i]%=MOD;
        if(stair[i-2]==false) ans[i]+=ans[i-2];
        ans[i]%=MOD;
    }
    cout<<ans[n]<<endl;
    return 0;
}


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

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

    int a,z;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='Z'){
            z=i;
            break;
        }
    }

    cout << (z-a+1) << endl;

    return 0;
}

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

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		int x = in.nextInt();
		System.out.println(x == 1? 0 : 1);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readarr(int abc) {
			int[] temp = new int[abc];
			for (int i = 0; i < abc; i++)
				temp[i] = nextInt();
			return temp;
		}
	}
}


Measured memory_bytes: 25368
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int ans=0;
int k=0;
int a;
int mx=0;
for(int i=0;i<5;i++)
{
cin>>a;
ans+=a;
int h=a%10;
if(h==0)
{
h=10;
}
k+=10-h;
mx=max(mx,10-h);
}
cout<<ans+k-mx<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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

//rang min, get point
struct SegmentTree{
private:
  int N;
  vector<long long> node;
  long long identity=1e18;
public:
  SegmentTree(vector<long long> v){
    int SZ=(int)v.size();
    N=1;
    while(N<SZ) N*=2;
    node.resize(2*N-1,identity);

    for(int i=0;i<SZ;i++) node.at(i+N-1)=v.at(i);
    for(int i=N-2;i>=0;i--) node.at(i)=min(node.at(2*i+1),node.at(2*i+2));
  }

  void rangmin(int a,int b,long long x,int k=0,int l=0,int r=-1){
    if(r==-1) r=N;
    if(r<=a || b<=l)  return;
    if(a<=l && r<=b){
      node.at(k)=min(node.at(k),x);
      return;
    }
    rangmin(a,b,x,2*k+1,l,(l+r)/2);
    rangmin(a,b,x,2*k+2,(l+r)/2,r);
    return;
  }

  long long getpoint(int i){
    i+=N-1;
    long long ans=node.at(i);
    while(i>0){
      i=(i-1)/2;
      ans=min(ans,node.at(i));
    }
    return ans;
  }
};

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N,Q;
  cin >> N >> Q;

  ll ans = (N-2)*(N-2);
  SegmentTree seg1(vector<ll>(N-2,N-2));
  SegmentTree seg2(vector<ll>(N-2,N-2));

  rep(_,Q){
    int q,x;
    cin >> q >> x;
    x-=2;
    if(q==1){
      int tmp = seg1.getpoint(x);
      ans -= tmp;
      seg2.rangmin(0,tmp+1,x);
    }
    else if(q==2){
      int tmp = seg2.getpoint(x);
      ans -= tmp;
      seg1.rangmin(0,tmp+1,x);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12964
#include<bits/stdc++.h>
#define M 200005
using namespace std;
const int mod=1e9+7;
int n,c[M];
int dp[M],val[M];
void Add(int &x,int y){
	x+=y;
	if(x>=mod)x-=mod;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	dp[0]=1;c[0]=-1;
	for(int i=1;i<=n;i++){
		if(c[i]!=c[i-1])Add(val[c[i]],dp[i-1]);
		Add(dp[i],val[c[i]]);
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void) {
  int m, d;
  cin >> m >> d;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= d; j++) {
      int a = j % 10;
      int b = j / 10;
      if (a < 2 || b < 2)
        continue;
      if (i == a * b)
        ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int check(llong p, int n, int k, llong w[]) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        llong s = 0;
        while (s + w[i] <= p) {
            s += w[i];
            i++;
            if (i == n) {
                return n;
            }
        }
    }
    return i;
}

int solve(int n, int k, llong w[]) {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid, n, k, w);
        if (v >= n) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return right;
}

int main() {
    int n, k;
    llong w[MAX];
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    cout << solve(n, k, w) << endl;
}



Measured memory_bytes: 3872
N, M = map(int, input().split())
pS = []
for _ in range(M):
    pS.append(input().split())

current = 0
penaltyList = [0] * (N+1)
penalty = 0
state = [False] * (N+1)
for i in pS:
    if i[1] == "WA" and (not state[int(i[0])]):
        penaltyList[int(i[0])] += 1
    elif i[1] == "AC" and (not state[int(i[0])]):
        current += 1
        penalty += penaltyList[int(i[0])]
        state[int(i[0])] = True
print(current, penalty)


Measured memory_bytes: 33696
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  std::map<int, int> b,c;
  for (int i = 0; i < n; ++i)
  {
    cin>>b[i+1];
  }
  for (int i = 0; i < n-1; ++i)
  {
    cin>>c[i+1];
  }
  int sum=0;
  for (int i = 0; i < n; ++i)
  {
    sum+=b[a[i]];
    if(i!=n-1 && a[i]+1==a[i+1]){
      sum+=c[a[i]];
    }
  }
  cout<<sum;
}

Measured memory_bytes: 256
md = 10 ** 9 + 7
n = int(input())
s = input()
dp = [1] * n
for i in range(n - 1):
    if s[i] == "<":
        for dpi in range(1, n - i - 1):
            dp[dpi] = (dp[dpi] + dp[dpi - 1]) % md
        dp = dp[:-1]
    else:
        for dpi in range(n - i - 2, 0, -1):
            dp[dpi] = (dp[dpi] + dp[dpi + 1]) % md
        dp = dp[1:]
print(dp[0])


Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <queue>

int main(){
	std::stack<int> in;
	std::queue<int> out;
	int num;
	
	while(std::cin >> num){
		if(num == 0){
			out.push(in.top());
			in.pop();
		}else
			in.push(num);
		
		//output
		if(in.empty()){
			while(!out.empty()){
				std::cout << out.front() << std::endl;
				out.pop();
			}
		}
	}
	
    return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) puts("No");
	else if (a == b || b == c || c == a) puts("Yes");
	else puts("No");
	return 0;
}



Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 9000000000000000000 //9e18:極めて大きい値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

int main(){
  string S;
  cin >> S;
  ll mod = 2019;
  ll dp[mod], tmp_dp[mod];
  REP(m, mod) dp[m] = 0;
  ll ret = 0;
  for(auto& c : S){
    ll n = (ll) c - 48;
    //cout << n << endl;
    REP(m, mod) tmp_dp[(m * 10) % mod] = dp[m];
    REP(m, mod) dp[(m + n) % mod] = tmp_dp[m];
    dp[n] += 1;
    ret += dp[0];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3380
import math
def isPrime(num):
    if num < 2: return False
    elif num == 2: return True
    for i in range(2,math.floor(math.sqrt(num))+1):
        if num % i == 0:
            return False
    return True

n=int(input())
if n==1:print(1);exit()
l=[i for i in range(1,n+1) if isPrime(i)==True]
ans=1
INF=10**9+7
for i in l:
    tmp=0
    tmpi=i
    while n//i>0:
        tmp+=n//i
        i*=tmpi
    ans=(ans*(tmp+1))%INF
print(ans)

Measured memory_bytes: 3064