akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

const int MAXN = 300;

int N;
double dp[MAXN + 1][MAXN + 1][MAXN + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);
    cin >> N;
    int i0 = 0, j0 = 0, k0 = 0, pieces = 0;
    forn(i, N) {
        int a; cin >> a;
        if (a == 1)
            i0++;
        else if (a == 2)
            j0++;
        else
            k0++;
        pieces += a;
    }
    dp[i0][j0][k0] = 1;
    for (int k = k0; k >= 0; k--) {
        for (int j = N - k; j >= 0; j--) {
            for (int i = N - k - j; i >= 0; i--) {
                if (i + j + k < N)
                    dp[i][j][k] += dp[i + 1][j][k] * (i + 1) / (i + j + k + 1);
                if (i > 0)
                    dp[i][j][k] += dp[i - 1][j + 1][k] * (j + 1) / (i + j + k);
                if (j > 0)
                    dp[i][j][k] += dp[i][j - 1][k + 1] * (k + 1) / (i + j + k);
            }
        }
    }
    double useless = 0;
    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= N; j++)
            for (int k = 0; k <= N; k++)
                if (i + j + k > 0)
                    useless += dp[i][j][k] * (N - i - j - k) / (i + j + k);
    cout << pieces + useless << endl;
}


Measured memory_bytes: 213248
#include <iostream>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
  int *num, *hoge, n;
  num = new int[12];
  hoge = new int[12];
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> num[i];

    int time = 0;
    while (true) {
      memset(hoge, 0, sizeof(int) * 12);
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          if (num[i] == num[j])
            hoge[i]++;
      if (memcmp(num, hoge, sizeof(int) * n) == 0)
        break;
      int *tmp = hoge;
      hoge = num;
      num = tmp;
      time++;
    }

    cout << time << endl;
    for (int i = 0; i < n; i++) {
      if (i)
        cout << ' ';
      cout << num[i];
    }
    cout << endl;
  }
  return 0;
}

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

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

int main(){
	int n,m,p;
	while(cin >>n >>m >>p,n!=0){
		int tmp, set;
		int sum=0;
		rep(i,n){
			cin >> tmp;
			sum+=tmp;
			if(i==m-1) set = tmp;
		}
		if(set == 0){
			cout << 0 << endl;
		}else{
			sum = (sum * 100 - (sum * p));
			cout << (sum/set) << endl;
		}
	}
}

Measured memory_bytes: 1160
type
	node=record
				sa,sb,sc:longint;
			end;
var
	a,b,c:array[0..100010] of longint;
	f1,f2:node;
	i,n,ans:longint;
function max(x,y:longint):longint;
begin
	if x>y then exit(x) else exit(y);
end;
begin
	readln(n);
	for i:=1 to n do read(a[i],b[i],c[i]);
	f1.sa:=a[1];
	f1.sb:=b[1];
	f1.sc:=c[1];
	for i:=2 to n do
	begin
		f2.sa:=a[i]+max(f1.sb,f1.sc);
		f2.sb:=b[i]+max(f1.sa,f1.sc);
		f2.sc:=c[i]+max(f1.sa,f1.sb);
		f1:=f2;
	end;
	ans:=max(f1.sa,f1.sb);
	ans:=max(ans,f1.sc);
	writeln(ans);
end.

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  ll ans=INF;
  ll suml=0;
  rep(i,n){
    suml+=a[i];
    ll sumr=sum-suml;
    chmin(ans,abs(suml-sumr));
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1920
import sys

# 立方体で数字が自由なさいころ
class Dice:
    def __init__(self, top, bottom, front, rear, right, left):
        self.top = top
        self.front = front
        self.right = right
        self.bottom = bottom
        self.rear = rear
        self.left = left

    def rotate_front(self):
        t, b, f, r = self.top, self.bottom, self.front, self.rear
        self.top = r
        self.bottom = f
        self.front = t
        self.rear = b

    def rotate_rear(self):
        t, b, f, r = self.top, self.bottom, self.front, self.rear
        self.top = f
        self.bottom = r
        self.front = b
        self.rear = t

    def rotate_right(self):
        t, b, r, l = self.top, self.bottom, self.right, self.left
        self.top = l
        self.bottom = r
        self.right = t
        self.left = b

    def rotate_left(self):
        t, b, r, l = self.top, self.bottom, self.right, self.left
        self.top = r
        self.bottom = l
        self.right = b
        self.left = t

    def get_tfr(self):
        return [self.top, self.front, self.right]

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    top, front, right, left, rear, bottom = map(int, input().split())
    d = Dice(top, bottom, front, rear, right, left)
    tftor = {}

    t, f, r = d.get_tfr()
    tftor[(t, f)] = r
    for _ in range(3):
        d.rotate_right()
        t, f, r = d.get_tfr()
        tftor[(t, f)] = r
    d.rotate_front()
    d.rotate_front()
    t, f, r = d.get_tfr()
    tftor[(t, f)] = r
    for _ in range(3):
        d.rotate_right()
        t, f, r = d.get_tfr()
        tftor[(t, f)] = r

    d.rotate_front()
    t, f, r = d.get_tfr()
    tftor[(t, f)] = r
    for _ in range(3):
        d.rotate_right()
        t, f, r = d.get_tfr()
        tftor[(t, f)] = r
    d.rotate_front()
    d.rotate_front()
    t, f, r = d.get_tfr()
    tftor[(t, f)] = r
    for _ in range(3):
        d.rotate_right()
        t, f, r = d.get_tfr()
        tftor[(t, f)] = r

    d.rotate_right()
    d.rotate_front()
    t, f, r = d.get_tfr()
    tftor[(t, f)] = r
    for _ in range(3):
        d.rotate_right()
        t, f, r = d.get_tfr()
        tftor[(t, f)] = r
    d.rotate_front()
    d.rotate_front()
    t, f, r = d.get_tfr()
    tftor[(t, f)] = r
    for _ in range(3):
        d.rotate_right()
        t, f, r = d.get_tfr()
        tftor[(t, f)] = r
    # print(tftor)

    q = int(input())
    for _ in range(q):
        t, f = map(int, input().split())
        print(tftor[(t, f)])

main()



Measured memory_bytes: 5640
n = int(input())
l = []
m = []
ans = -10**9

for i in range(n):
    f = "".join(input().split())
    f = int(f, 2)
    l.append(f)

for i in range(n):
    p = list(map(int, input().split()))
    m.append(p)

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & l[j]).count("1")
        ref += m[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Measured memory_bytes: 9168
/*=======================
Author    : Shounak Dey
=======================	*/

#include<bits/stdc++.h>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;

#define PB push_back
#define MK make_pair
#define SZ(a) (int)(sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define read(n) scanf("%d",&n)
#define readl(n) scanf("%lld",&n)
#define readul(n) scanf("%llu",&n);


#define SORTV(a) sort(a.begin(),a.end())
#define TEST int Test;cin >> Test;while(Test--)
#define gcd(a,b) __gcd(a,b)
#define ffs(a) __builtin_ffs(a) // find first set
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)


#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

int main()
{
	fast_io;
	double t,x;
	cin >> t >> x;
	cout << setprecision(10) << fixed;
	cout << t/x << endl;
	return 0;
}



Measured memory_bytes: 256
def solve(N, a):
    mod = 10**9 + 7
    dp = [0] * (N+1)
    step = [0] * (N+1)
    for aa in a:
        step[aa] = 1

    dp[0] = 1
    if step[1] == 0:
        dp[1] = 1

    for i in range(2, N+1):
        if step[i] == 0:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= mod

    return dp[N]


if __name__ == "__main__":
    N, M = map(int, input().split())
    a = [int(input()) for _ in range(M)]

    print(solve(N, a))


Measured memory_bytes: 14448
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define trav(var, container) for(auto& var: container)
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)x.size()
using namespace std;
using namespace __gnu_pbds;
using ld = long double; 
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
struct chash { // large odd number for C
    const uint64_t C = ll(4e18 * acos(0)) | 71;
    ll operator()(ll x) const { return __builtin_bswap64(x*C); }
};
const int MOD = (int)1e9 + 7;
const int MAXN = 100;
bitset<MAXN + 1> is_prime;
vector<int> primes;
void gen_primes() {
	is_prime.set();
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= MAXN; ++i) {
		if(is_prime[i]) {
			primes.emplace_back(i);
			for(int j = 2 * i; j <= MAXN; j += i) {
				is_prime[j] = false;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	gen_primes();
	int n;
	cin >> n;	
	map<int, int> prcnt;
	for(int& prime: primes) {
		for(int i = prime; i <= n; i += prime) {
			int x = i;
			while(x % prime == 0) {
				x /= prime;
				++prcnt[prime];
			}
		}

	}
	map<int, int> cnt;
	for(auto& p: prcnt) {
		for(int i = 0; i <= 74; ++i) 
			if(p.second >= i) ++cnt[i];
		// cout << p.first << " " << p.second << "\n";
	}
	// for(int i = 0; i <= 74; ++i) cout << cnt[i] << "\n";
	ll ans = cnt[74];
	ans += cnt[24] * (cnt[2] - 1);
	ans += cnt[14] * (cnt[4] - 1);
	// cout << cnt[4] << " " << cnt[2];
	ans += (cnt[4] * (cnt[4] - 1)) / 2 * (cnt[2] - 2);
	cout << ans;
	return 0;
}

// 75 * 1
// 25 * 3
// 15 * 1




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000;

int dsu[N];
int kk[N], kkf[N], kkb[N];

int find(int i) {
	return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (dsu[i] > dsu[j])
		dsu[i] = j;
	else {
		if (dsu[i] == dsu[j])
			dsu[i]--;
		dsu[j] = i;
	}
}

int main() {
	int n, m, k; cin >> n >> m >> k;
	fill_n(dsu, n, -1);
	while (m--) {
		int i, j; cin >> i >> j, i--, j--;
		join(i, j);
		kkf[i]++, kkf[j]++;
	}
	while (k--) {
		int i, j; cin >> i >> j, i--, j--;
		if (find(i) == find(j))
			kkb[i]++, kkb[j]++;
	}
	for (int i = 0; i < n; i++)
		kk[find(i)]++;
	for (int i = 0; i < n; i++)
		kk[i] = kk[find(i)];
	for (int i = 0; i < n; i++)
		cout << kk[i] - 1 - kkf[i] - kkb[i] << ' ';
	cout << '\n';
	return 0;
}


Measured memory_bytes: 2432
package main

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

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e13
var mod = 1000000007

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	n := next.Int()

	fmt.Printf("ABC%d", n)
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a ...int) int {
	r := a[0]
	if len(a) > 1 {
		for i := 1; i < len(a); i++ {
			r += a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

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

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

template<class T>
inline bool chmin(T &a, const T b) { return a > b && (a = b, true); }

int main() {

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

	int H, W;
	cin >> H >> W;

	vector<vector<int>> A(H, vector<int>(W));
	vector<vector<int>> B(H, vector<int>(W));
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> A[i][j];
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> B[i][j];

	const int offset = 6500;
	vector<bitset<offset * 2 + 1>> dp(W + 1);
	dp[0][offset] = 1;
	for (int i = 0; i < H; i++) {

		for (int j = 0; j < W; j++) {
int shift = abs(A[i][j] - B[i][j]);
dp[j + 1] |= (dp[j] << shift) | (dp[j] >> shift);

		}
		DMP(dp);
dp[0][offset]=0;
		if (i == H - 1) break;
		for (int j = 1; j <= W; j++) {
int shift = abs(A[i + 1][j - 1] - B[i + 1][j - 1]);
          DMP(shift);
dp[j] = (dp[j] << shift) | (dp[j] >> shift);
		}
		DMP(dp);

	}

	int ans = INF;
	for (int i = 0; i <= 2 * offset; i++) {
		if (dp[W][i]) chmin(ans, abs(i - offset));
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;

int main()
{
	string s;
	cin >> s;
	int len = (int) s.size();

	LL res = 0;
	for (int i = 0; i < (1 << (len-1)); i++)
	{
		LL x = 0;
		for (int j = 0; j < len-1; j++)
		{
			x += s[j] - '0';
			if (((1 << j) & i) != 0)
			{
				res += x;
				x = 0;
			}
			x *= 10;
		}
		x += s[len-1] - '0';
		res += x;
	}
	cout << res << endl;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 2005;
const int MAX_S = 100005;

int N, M;
int S[MAX_N], T[MAX_N];
int dp[MAX_N][MAX_N];

int SUM_S[MAX_N];

signed main()
{
  cin >> N >> M;
  REP(n,N) {
    cin >> S[n];
  }
  REP(m,M) {
    cin >> T[m];
  }

  REP(n,N+1) {
    dp[n][0] = 1;
  }

  REP(n,N+1) {
    REP(m,M) {
      dp[n][m+1] += dp[n][m]; // 採用しない
      dp[n][m] %= MOD;
      // 採用する
      dp[n][m+1] += SUM_S[m];
      dp[n][m+1] %= MOD;
    }
    if(n < N) {
      REP(m,M) {
        if(S[n] == T[m]) {
          SUM_S[m] += dp[n][m];
          SUM_S[m] %= MOD;
        }
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    int N;
    cin >> N;
    vector<long long> A(N + 1, 0);
    vector<long long> B(N, 0);

    for (int i = 0; i < N + 1; ++i) 
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) 
    {
        cin >> B[i];
    }

    long long ans = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        long long diff2 = A[i+1] - B[i];
        if (diff2 < 0)
        {
            B[i] -= A[i+1];
            ans += A[i+1];
        }
        if (diff2 >= 0)
        {
            A[i+1] -= B[i];
            ans += B[i];
            B[i] = 0;
        }

        long long diff1 = A[i] - B[i];
        if (diff1 < 0)
        {
            B[i] -= A[i];
            ans += A[i];
            A[i] = 0;
        }
        if (diff1 >= 0)
        {
            A[i] -= B[i];
            ans += B[i];
            B[i] = 0;
        }
    }

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

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

// using ll = long long;
#define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  string s;
  cin >> s;
  int n = s.length();
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }
  map<char, int> mp;
  REP(i,n) {
    ++mp[s[i]];
  }
  int ans = n * (n-1) / 2;
  for(char c = 'a'; c <= 'z'; ++c) {
    int count = mp[c];
    if(count < 2) continue;
    ans -= count * (count-1) / 2;
  }
  cout << ans+1;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
	ll x;
	cin >> x;
	ll p = (x + 10) / 11;
	if (11 * (p - 1) + 6 >= x)
		cout << 2 * p - 1 << endl;
	else
		cout << 2 * p << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
M = (n+1)*(1/2)*(n+1)*(n+2)-(n+1)*(n+2)*(n*2+3)*(1/6)+n+1
m = (n+1)*(1/2)*(k-1)*k-(k-1)*k*(2*k-1)*(1/6)+k-1
ans = M-m
print(int(ans%(1000000007)))

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, r, p;
string s, t;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n>>s;
	ll maxi = 0,x = 0;

	for(auto ch : s) {
		if(ch == 'I') x++;
		else x--;
		maxi = max(maxi,x);
	}

	cout<<maxi;
}

int main() {
	fastio; randomINT;
	//cin>>t;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 238028
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

S = input()

print("Yes" if S[2] == S[3] and S[4] == S[5] else "No")


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

def main():
    n=int(input())

    b=list(map(int,input().split()))
    a=[0]*n
    a[0]=b[0]

    a[n-1]=b[n-2]

    for i in range(1,n-1):
        a[i]=min(b[i],b[i-1])
    print(sum(a))

if __name__ == "__main__":
    main()



Measured memory_bytes: 3060
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
lis.sort()
factmod=[0 for i in range(n)]
factmod[0]=1
for i in range(n-1):
    factmod[i+1]=(factmod[i]*(i+1))%mod
#print(factmod)
combmod=[0 for i in range(n)]
for i in range(n):
    if i>=k-1:
        combmod[i]=(factmod[i]*(pow(factmod[k-1]*factmod[i-k+1]%mod,mod-2,mod)))%mod
ans=0
#print(combmod)
for i in range(n):
    if n-i-1>=k-1:
        ans=(ans-lis[i]*combmod[n-i-1])%mod
for i in range(n):
    if i>=k-1:
        ans=(ans+lis[i]*combmod[i])%mod
print(ans%mod)
        
        

Measured memory_bytes: 99788
N = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(N):
    if a[i] == b[i] == c[i]:
        pass
    elif a[i] == b[i] or a[i] == c[i] or b[i] == c[i]:
        ans += 1
    else:
        ans += 2
print(ans)

Measured memory_bytes: 38256
//https://atcoder.jp/contests/keyence2020/tasks/keyence2020_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
    ll N; cin>>N;
    vector<pair<ll,ll>> xln(N);
    for(auto& xl:xln){
        ll x,l; cin>>x>>l;
        ll st=x-l;
        ll ed=x+l;
        xl.first=ed;
        xl.second=st;
    }
    sort(xln.begin(),xln.end());
    ll ans=0;
    ll pt=INT64_MIN;
    for(auto& xl:xln){
        if(pt<=xl.second){
            ++ans;
            pt=xl.first;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    for (int i = 1; i <= 5; i++) {
      int x = sc.nextInt();
      if (x == 0) {
        System.out.println(i);
        break;
      }
    }
  }
}


Measured memory_bytes: 26968
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
//cout << std::fixed << std::setprecision(15) << y << endl;


#define MOD 1000000007

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

    ll A[N + 1];
    ll sum = 0;
    ll sumA[N + 1];
    REP(i, N){
        cin >> A[i];
        sum += A[i];
        sum %= MOD;
    }
    sumA[0] = sum;
    ll ans = 0;
    REP(i, N){
        sumA[i] = sumA[i - 1] - A[i];
        if(sumA[i] < 0){
            sumA[i] += MOD;
        }
        ans += A[i] * sumA[i];
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6672
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;

class Nodes(T) {

  class Node {
    public int id;
    public Node[] friends;

    public T content;
    alias content this;

    this(int id) {
      this.id = id;
    }
  }

  public int origin;
  public Node[int] nodes;

  this(int size, int origin = 1) {
    this.origin = origin;
    size.iota.each!((i) {
      auto id = origin + i;
      this.nodes[id] = new Node(id);
    });
  }

  void setPath(int a, int b) {
    this.nodes[a].friends ~= this.nodes[b];
    this.nodes[b].friends ~= this.nodes[a];
  }

  Node root() {
    return this.nodes[origin];
  }

  void apply(int id, void delegate(Node) d) {
    d(this.nodes[id]);
  }

  void applyAllFromRoot(void delegate(Node) d) {
    auto cursors = [this.root()];
    bool[int] checked;
    while(!cursors.empty) {
      foreach(node; cursors) {
        d(node);
        checked[node.id] = true;
      }
      cursors = cursors.map!(node => node.friends)
        .joiner.filter!(node => node !is null && node.id !in checked).array;
    }
  }
}

struct Counter {
  int count;
}

void main() {
  int N, Q; readf("%d %d\n", &N, &Q);

  auto nodes = new Nodes!(Counter)(N);
  foreach(i; 1..N) {
    int from, to; readf("%d %d\n", &from, &to);
    nodes.setPath(from, to);
  }
  
  foreach(i; 0..Q) {
    int nodeId, increments; readf("%d %d\n", &nodeId, &increments);
    nodes.apply(nodeId, (node){ node.count += increments; });
  }

  int[] totals = new int[N+1];
  nodes.applyAllFromRoot((node) {
    totals[node.id] += node.count;
    node.friends.each!(n => totals[node.id] += totals[n.id]);
  });

  totals.popFront();
  totals.to!(string[]).join(" ").writeln;
}


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

using namespace std;

int main(){
	int r,c;
	cin >> r >> c;
	
	vector<vector<int> > table(r+1,vector<int>(c+1));
	
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin >> table.at(i).at(j);
			table.at(i).at(c) += table.at(i).at(j);
			table.at(r).at(j) += table.at(i).at(j);
			table.at(r).at(c) += table.at(i).at(j);
		}
	}
	
	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			cout << table.at(i).at(j);
			if(j != c) cout << " ";
		}
		cout << endl;
	}
}



Measured memory_bytes: 3132
def lower_bound(array, value)
  array.bsearch_index do |x|
    x >= value
  end
end

def upper_bound(array, value)
  i = array.bsearch_index do |x|
    x >= value
  end
  if i.nil?
    array.empty? ? nil : array.size - 1
  elsif i >= 1
    i - 1
  else
    nil
  end
end

def former(array, value)
  array.bsearch do |x|
    x >= value
  end
end

def latter(array, value)
  i = array.bsearch_index do |x|
    x >= value
  end
  if i.nil?
    array.empty? ? nil : array[-1]
  elsif i >= 1
    array[i - 1]
  else
    nil
  end
end

N, M = gets.split.map(&:to_i)
a_list = gets.split.map(&:to_i).sort
bc_list = M.times.map { gets.split.map(&:to_i) }.sort_by { |(_, c)| -c }

memo = []
bc_list.each do |(b, c)|
  ub = upper_bound(a_list, c)
  if ub
    memo.push([b, c, ub])
  end
end
base_i = memo.size > 0 ? memo[0][2] : nil
unless base_i
  sum = a_list.reduce(&:+)
  puts sum
  exit 0
end

sum = 0
max = memo.size > 0 ? memo[0][2] + 1 : 0
used = 0
memo.each do |(b, c, ub)|
  break if used >= max
  next if ub + 1 - used <= 0
  count = [(ub + 1 - used), b].min
  next if count < 0
  sum += count * c
  used += count
end
a_list = a_list[(base_i - (max - used) + 1)..(a_list.size)].compact
if a_list && a_list.size > 0
  sum += a_list.reduce(&:+)
  puts sum
else
  puts sum
end

# bc_list.each do |(b, c)|
#   ub = upper_bound(a_list, c)
#   if ub
#     i = 0
#     while true
#       break if i >= b || i > ub
#       a_list[i] = c
#       i = i + 1
#     end
#     a_list.sort!
#   end
# end
# ans = a_list.reduce(&:+)
# puts ans


# bc_list.each do |(b, c)|
#   ub = upper_bound(a_list, c)
#   if ub
#     i = 0
#     while true
#       break if i >= b || i > ub
#       a_list[i] = c
#       i = i + 1
#     end
#     a_list.sort!
#   end
# end
# ans = a_list.reduce(&:+)
# puts ans


Measured memory_bytes: 21040
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
int n,m;
int fa[2000003],vis[2000003],D[2000003],C[2000003];
inline int find(int x){
	if(fa[x]==x){
		return fa[x];
	}else{
		return fa[x]=find(fa[x]);
	}
}
int main(){
	cin>>n>>m;
    for(int i=1;i<=1000;i++){
    	fa[i]=i;
	}
    for(int i=1;i<=n;i++){
        int x,y,a,b,c,d;
        cin>>a>>b>>c>>d;
        x=!c?a+500:-c+500;
        y=!d?-b+500:d+500;
        fa[find(x)]=find(y);
        D[x]++,D[y]--;
		vis[x]=1;
    }
    int flag=1;
    for(int i=1;i<500;i++){
    	if(D[i]>0){
			puts("NO");
    		return 0;
		}
	}
    for(int i=501;i<=1000;i++){
    	if(D[i]<0){
    		puts("NO");
    		return 0;
		}
	}
    for(int i=1;i<=1000;i++){
    	vis[find(i)]|=vis[i];
	}
    for(int i=1;i<=1000;i++){
		if(D[i]){
			C[find(i)]=1;
		}
	}
    for(int i=1;i<=1000;i++){
    	if(fa[i]==i&&!C[i]&&vis[i]){
    		puts("NO");
    		return 0;
		}
	}
	cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main (void)
{
  int n; cin >> n;
  for (int i = 0; i < 100; i++) {
    int m = n - 4 * i;
    if (m >= 0 && m % 7 == 0) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}

typedef struct{
    int x;
    int y;
} pair;

pair nums[90005];

int dist[90005] = {0};
int l[100005];
int r[100005];
int ans[100005];

int main(void){
    int h, w, d;
    int num;
    scanf("%d %d %d", &h, &w, &d);
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            scanf("%d", &num);
            nums[num].x = j;
            nums[num].y = i;
        }
    }

    for (int i = 1; i <= d; i++){
        int j = i+d;
        int nx, ny;
        nx = nums[i].x;
        ny = nums[i].y; 
        while (j <= h*w){
            dist[i] += abs(nums[j].x - nx)+abs(nums[j].y - ny);
            dist[j] -= dist[i];
            nx = nums[j].x;
            ny = nums[j].y;
            j+= d;
        }
        for (int k = i+d; k <= h*w; k+= d){
            dist[k] += dist[i];
        }
    }

    int q;
    scanf("%d", &q);


    for (int i = 0; i < q; i++){
        scanf("%d %d", &l[i], &r[i]);
    }
    for (int i = 0; i < q; i++){
        printf("%d\n", dist[l[i]] - dist[r[i]]);
    }

}


Measured memory_bytes: 2944
#include <iostream>

using namespace std;

#define pow5(x) x*x*x*x*x

int main()
{
    int x; cin>>x;
    long long a,b;
    while(true){
        for(a=0;a<140;a++){
            if(pow5(a)-x<0){
                for(b=0;b>-100;b--){
                    if(pow5(a)==x+pow5(b)){
                        cout << a << " " << b << endl;
                        return 0;
                    }
                }
            }else{
                for(b=0;b<a;b++){
                    if(pow5(a)==x+pow5(b)){
                        cout << a << " " << b << endl;
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

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

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

template <typename T>
T gcd(T a, T b) {
  if(b == 0) return a;
  else return gcd(b,a%b);
}



int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

// struct UnionFind {
//   vector<int> par;

//   UnionFind(int n) {
//     par.resize(n,-1); 
//   }

//   int root(int x) {
//     if(par[x] < 0) return x;
//     else return par[x] = root(par[x]);
//   }

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

//   bool merge(int x, int y) {
//     x = root(x); y = root(y);
//     if(x == y) return false;
//     if(par[x] > par[y]) swap(x,y);
//     par[x] += par[y];
//     par[y] = x;
//     return true;
//   }
  
//   int size(int x) {
//     return -par[root(x)];
//   }
// };
  
int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a + b >= k) cout << min(a,k) << endl;
  else {
    ll rem = a + b - k;
    cout << a + rem << endl;
  }

    
}














Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3fLL
#define rep(i,a,b) for(register ll i=(a);i<=(b);i++)
#define dep(i,a,b) for(register ll i=(a);i>=(b);i--)
using namespace std;
const int maxn=2e5+5;
//const double pi=acos(-1.0);
//const double eps=1e-9;
//const ll mo=1e9+7;
ll n,m,k;
ll a[maxn];
ll c[maxn],cc[maxn];
ll ans,tmp,cnt;
ll p;
int main()
{
    int T,cas=1;
    //scanf("%d",&T);
    while(scanf("%lld%",&n)!=EOF)
    {
        rep(i,1,n) scanf("%lld",&a[i]);
        ll ans=inf,tmp=0;
        rep(i,-100,100)
        {
            tmp=0;
            rep(j,1,n)
            {
                tmp+=(a[j]-i)*(a[j]-i);
            }
            ans=min(ans,tmp);
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 2304
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,t = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    bs = []
    mi = a[0]
    for i in a[1::]:
        if mi < i:
            bs.append(i-mi)
        else:
            mi = i
    ma = max(bs)
    cnt = 0
    for i in bs:
        if i == ma:
            cnt += 1

    print(cnt)
    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 92304
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            String temp = scanner.next();
            Integer index = map.get(temp);
            map.put(temp, index == null ? 1 : index + 1);
        }

        scanner.close();

        System.out.println(map.size());

    }
}

Measured memory_bytes: 76960
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
const int MAXN = 100000 + 3;
int a[10], n, m, p, d;

int main() {

  	for(int i=0;i<10;i++)a[i] = -1;
    cin>>n>>m;
    int flag = 0;
  	for(int i=0;i<m;i++) {
    	cin>>p>>d;
        if(a[p] != -1 && a[p] != d) {
            flag = 1;
        }
        a[p] = d;
    }
    if(a[1] == 0 && n > 1) {
        flag = 1;
    }

    if(flag) {
        printf("-1\n");
        return 0;
    }

    if(a[1] == -1) {
    	if(n>1)a[1] = 1;
        else a[1] =0;
    }
    int ans = 0;
    for(int i=1;i<=n;i++) {
        if(a[i] == -1) a[i] = 0;
        ans = ans * 10 + a[i];
    }
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

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

    int n,k;
    cin>>n>>k;
    if(k==1)cout<<"0\n";
    else cout<<n-k<<"\n";
    return 0;
}


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

int main() {
	int H, W;
	while(1){
		
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for ( int i = 1; i <= H; i++){
			for( int j = 1; j <= W; j++){
			cout << "#";
			}
			cout << "\n";
			}
			cout << endl;
	}

	
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
     
     
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
   
  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
     
  cout << (f?"Yes":"No") << endl;
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(rng(ret));
  return (ret);
}

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  ll n;
  cin >> n;
  map<ll,int> M;
  int cnt = 0;
  while(1){
    auto tmp = divisor(n);
    ll x = -1;
    for(auto u: tmp){
      auto r = prime_factor(u);
      if(M[u] == 0 && u!=1 && n%u == 0 && sz(r) == 1){
        M[u] = 1;
        x = u;
        break;
      }
    }
    if(x == -1) break;
    cnt++;
    n/=x;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <queue>
#include <math.h>
using namespace std;
typedef long long int ll;

constexpr ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

struct perm{
private:
	int sz;
	vector<ll> p,invp;
public:
	perm(int n){
		sz=n+1;
		p.resize(sz),invp.resize(sz);
		p[0]=1;
		for(int i=1;i<=sz-1;i++){
			p[i]=p[i-1]*i%mod;
		}
		invp[sz-1]=mod_pow(p[sz-1],mod-2);
		for(int i=sz-2;i>=0;i--){
			invp[i]=invp[i+1]*(i+1)%mod;
		}
	}
	ll comb(ll x,ll y){
		if(x<y||y<0)return 0;
		return (p[x]*invp[x-y]%mod)*invp[y]%mod;
	}
};
perm p(1<<20);

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll n,k; cin >> n >> k;
	ll res=0;
	for(ll i=k;i<=n+1;i++){
		(res+=(2*n-i+1)*i/2-i*(i-1)/2+1)%=mod;
	}
	printf("%lld\n",res );
}

Measured memory_bytes: 19408
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

int w, h, k, ssum[3][1111][1111];
char mas[1111][1111];
map <int, int> enc;


int main(){
  
  enc['J'] = 0, enc['O'] = 1, enc['I'] = 2;
  enc[0] = 'J', enc[1] = 'O', enc[2] = 'I';

  cin >> h >> w >> k;
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++){ 
      cin >> mas[i][j];
      ssum[enc[mas[i][j]]][i+1][j+1] = 1;
    }           
  
  for(int l = 0; l < 3; l++){

    for(int i = 0; i < h; i++){
      for(int j = 1; j < w; j++){
        ssum[l][i+1][j+1] += ssum[l][i+1][j];
      }
    }

    for(int i = 1; i < h; i++){
      for(int j = 0; j < w; j++){
        ssum[l][i+1][j+1] += ssum[l][i][j+1];
      }
    }
  }
   
  while(k--){
    int a, b, c, d; 
    cin >> a >> b >> c >> d;
    for(int l = 0; l < 3; l++){
      cout << ssum[l][c][d] + ssum[l][a-1][b-1] - ssum[l][c][b-1] - ssum[l][a-1][d] << (l != 2 ? ' ' : '\n');
    }
  }
                                           

}

Measured memory_bytes: 16220