akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var N = line[0];
            var M = line[1];

            var lines = consoleReader.RepeatSplitInt32(N).Select(ia => ia.Skip(1).ToArray()).ToArray();

            IEnumerable<int> r = lines[0];
            foreach (var l in lines.Skip(1))
            {
                r = r.Intersect(l);
            }

            return r.Count();
        }

        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine();
        public int Int32() => int.Parse(String());
        public long Int64() => long.Parse(String());
        public ulong UInt64() => ulong.Parse(String());
        public double Double() => double.Parse(String());
        public string[] Split() => String().Split().ToArray();
        public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray();
        public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray();
        public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray();
        public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray();

        public IEnumerable<string> Repeat(int count)
        {
            for (int i = 0; i < count; i++)
                yield return String();
        }
        public IEnumerable<int> RepeatInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int32();
        }
        public IEnumerable<long> RepeatInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int64();
        }
        public IEnumerable<string[]> RepeatSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
        public IEnumerable<int[]> RepeatSplitInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return SplitInt32();
        }
    }
}


Measured memory_bytes: 13536
#include <iostream>

using namespace std;

int K, S;

int main(void) {

	cin >> K >> S;

	int ans = 0;

	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			int z = S - x - y;

			if (0 <= z && z <= K) { ans++; }
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  long long ans=s.size(),cntS=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='S'){
      cntS++;
    }else if(s[i]=='T'){
      if(cntS>0){
        cntS--;
        ans-=2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	char x, y;
	cin >> x >> y;
	if (x > y) cout << '>' << endl;
	else if (x == y) cout << '=' << endl;
	else cout << '<' << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    BeatMeScanf;
    //freopen("G:/C++/in.txt", "r", stdin);
    //freopen("G:/C++/out.txt", "w", stdout);

    int n, m;
    cin>>n>>m;
    if(m<n)
        puts("No");
    else
        puts("Yes");

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define REP(i, n) for(int i=0;i < (n); ++i)
#define REPA(i, n) for(int i=1;i < (n);++i)
#define DP_SIZE 90010
#define DP_CENT (DP_SIZE / 2)
#define MOD ((long long)998244353)
#define LL long long
using namespace std;
int N;
LL sum;
LL nums[300];
long long ans;
LL dp[DP_SIZE];
LL dp2[DP_SIZE];
int main(){
  cin >> N;
  REP(i, N){
    cin >> nums[i];
    sum += nums[i];
  }
  dp[0] = 1;
  REP(i, N){
    REP(j, DP_SIZE - nums[i]){
      dp2[j + nums[i]] = (dp2[j + nums[i]] + dp[j]) % MOD;
      dp2[j] = (dp2[j] + dp[j]*2) % MOD;
    }
    REP(j, DP_SIZE){
      dp[j] = dp2[j];
      dp2[j] = 0;
    }
  }
  for(int i = (sum+1)/2;i<DP_SIZE;++i){
    ans -= dp[i]*3;
    if(ans < 0){
      ans += MOD;
    }
  }
  REP(i, DP_SIZE){
    dp[i] = dp2[i] = 0;
  }
  dp[DP_CENT] = 1;
  REP(i, N){
    REP(j, DP_SIZE){
      int k = j + nums[i];
      if(k < DP_SIZE){
        dp2[k] = (dp2[k] + dp[j]) % MOD;
      }
      k = j - nums[i];
      if(0 <= k){
        dp2[k] = (dp2[k] + dp[j]) % MOD;
      }
    }
    REP(j, DP_SIZE){
      dp[j] = dp2[j];
      dp2[j] = 0;
    }
  }
  ans += dp[DP_CENT] * 3;
  ans %= MOD;
  LL d = 1;
  REP(i, N){
    d = (d * 3) % MOD;
  }
  ans = (ans + d + MOD) % MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define all(n)      (n).begin(), (n).end()
#define ll long long 

void solve(){
	ll n,k; cin >> n >> k;
	ll ans = n;
	while(1){
		if(ans % k == 0){
			ans = 0;
			break;
		}

		n = abs(n - k);

		if(ans > n){
			ans = n;
		}else{
			break;
		}
		n = n%k;
		
	}
	cout << ans << endl;
	

}


int main (){

	//Write from here.
	
		solve();
	
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int a,b;cin>>a>>b;

  if(a+b>=10)out("error")
  else out(a+b)

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int mood(int a, int b){
    if (a % b == 0) return b;
    else return a % b;
}

struct graph{
    int hi;
    vector<int> to;
};



int main() {
    int n, m; cin >> n >> m;
    vector<graph> ar(n);
    rep(i,n) cin >> ar[i].hi;
    rep(i,m){
        int a, b; cin >> a >> b;
        ar[a-1].to.emplace_back(b-1);
        ar[b-1].to.emplace_back(a-1);
    }
    int ans = 0;
    rep(i,n){
        bool t = true;
        if (ar[i].to.size() == 0) ans++;
        else {
            rep(j,ar[i].to.size()){
                if (ar[ar[i].to[j]].hi >= ar[i].hi){
                    t = false;
                    break;
                }
            }
            if (t) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9068
N = int(input())

list1 = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(list1[N-1])




Measured memory_bytes: 38512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

int n;
bool all_zero(string &s) {
	rep(i, n) {
		if (s[i] == '1')return false;
	}
	return true;
}
int dist(int i, int j) {
	int d = abs(i - j); d %= n;
	return min(d, n - d);
}
void solve() {
	string a, b; cin >> a >> b;
	n = a.length();
	if (all_zero(b)) {
		if (all_zero(a)) {
			cout << 0 << endl;
		}
		else{
			cout << -1 << endl;
		}
		return;
	}
	vector<int> loc;
	rep(i, n) {
		if (b[i] == '1') {
			loc.push_back(i - n);
			loc.push_back(i);
			loc.push_back(i + n);
		}
	}
	sort(loc.begin(), loc.end());
	vector<int> le(n), ri(n);
	rep(i, n) {
		int id = lower_bound(loc.begin(), loc.end(), i) - loc.begin();
		ri[i] = loc[id]-i;
		if (i == loc[id]) {
			le[i] = i - loc[id];
		}
		else {
			le[i] = i - loc[id - 1];
		}
	}
	int ans = mod;
	vector<vector<int>> c(n);
	rep(i, n) {
		rep(j, n) {
			c[j].clear();
		}
		int cnt = 0;
		rep(j, n) {
			int ni = (i + j) % n;
			if (a[ni] != b[j]) {
				c[le[ni]].push_back(ri[ni]);
				cnt++;
			}
		}
		//cout << cnt << endl;
		int ma = 0;
		per(j, n) {
			int sum1 = cnt+2*j+ma + dist(ma, -i);
			int sum2 = cnt+2*ma+j + dist(-j, -i);
			ans = min({ ans,sum1,sum2 });
			rep(k, c[j].size()) {
				ma = max(ma, c[j][k]);
			}
			//cout << i << " " << j << " " << sum1 << " " << sum2 << " "<<ma<<endl;
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

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

int main(){
  int d, g; cin >> d >> g;
  
  vector<pair<int, int>> pc(d);
  for(int i = 0; i < d; i++){
    int p, c; cin >> p >> c;
    pc.at(i) = make_pair(p, c);
  }
  
  int ans = 1e9;
  
  for(int i = 0; i < (1<<d); i++){
    ll a = 0;
    int tmp_ans = 0, rest_max = -1;
    for(int j = 0; j < d; j++){
      if(i&(1<<j)){
        a += (pc.at(j).first * (j+1) * 100 + pc.at(j).second);
        tmp_ans += pc.at(j).first;
      }else rest_max = j;
    }
    if(a < g){
      int a1 = 100 * (rest_max + 1); 
      int need = (g - a + a1 - 1) / a1;
      if(need >= pc.at(rest_max).first) continue;
      tmp_ans += need;
    }
    
    ans = min(ans, tmp_ans);
    
  }
  
  cout << ans << endl;
}

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

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

    int p;
    int pmax = 0;
    int psum = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> p;
        psum += p;
        pmax = std::max(pmax, p);
    }

    std::cout << (psum - (pmax / 2)) << std::endl;

    return 0;
}

Measured memory_bytes: 256
from_user=input()
coordinates_str=from_user.split(' ')
A=int(coordinates_str[0])
B=int(coordinates_str[1])
C=int(coordinates_str[2])

if C > A:
    if C < B:
        print('Yes')
    else:
        print('No')

if C < A:
    if C > B:
        print('Yes')
    else:
        print('No')

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

int main(){
	int n;
	cin >> n;
	int n1 = n / 100;
	int n3 = n % 10;
	if(n1 == n3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
mod = 10 ** 9 + 7
if abs(N - M) >= 2:
  print(0)
else:
  if abs(N - M) == 1:
    ans = 1
    for i in range(1, N+1):
      ans = ans * i % mod
    for i in range(1, M+1):
      ans = ans * i % mod
    print(ans)
  else:
    ans = 2
    for i in range(1, N+1):
      ans = ans * i % mod
    for i in range(1, M+1):
      ans = ans * i % mod
    print(ans)

Measured memory_bytes: 63608
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

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

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    double r; cin >> r;
    cout << fixed << setprecision(10) << 2.0*r*pie << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 3808
extern crate proconio;
use proconio::input;

fn main() {
    input! {
        n: i32,
        mut s: String,
    }
    let s = s.chars().collect::<Vec<_>>();
    let mut i = 0;
    let mut j = n - 1;
    let mut ans = 0;
    while i < j {
        while i < n && s[i as usize] == 'R' {
            i += 1;
        }
        while j >= 0 && s[j as usize] == 'W' {
            j -= 1;
        }
        if i >= j {
            break;
        }
        ans += 1;
        i += 1;
        j -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 3300
package main

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

type Tuple struct {
	cost int
	c    []int
}

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	tuples := make([]Tuple, M)
	for i := 0; i < M; i++ {
		Q := sc.NextIntArray()
		W := sc.NextIntArray()
		tuples[i] = Tuple{
			cost: Q[0],
			c:    W,
		}
	}

	dp := make([]int, 1<<uint(N))
	fill(dp, -1)
	dp[0] = 0
	for i := 0; i < 1<<uint(N); i++ {
		if dp[i] == -1 {
			continue
		}
		for _, v := range tuples {
			bits := 0
			total := v.cost
			for _, b := range v.c {
				bits |= 1 << uint(b-1)
			}
			p := i | bits
			//println(dp[p], dp[i], total)

			if dp[p] == -1 || dp[p] > dp[i]+total {
				dp[p] = dp[i] + total
			}
		}
	}
	fmt.Println(dp[(1<<uint(N))-1])
}

func fill(arr []int, v int) {
	for i := 0; i < len(arr); i++ {
		arr[i] = v
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	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) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

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: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    map<int, int> num2idMap;
    for (int i = 1; i <= N; ++i)
    {
        int Ai;
        cin >> Ai;
        num2idMap[Ai] = i;
    }
    for (const auto &kvp : num2idMap)
    {
        cout << kvp.second << ' ';
    }
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
vector<ll>adj[500001];
ll deg[N];
ll ma=-1,ind;
ll mark[N],n;

map<pa,ll>marks;
void dfs(ll v,ll p,ll col)
{   
    marks[{v,p}]=marks[{p,v}]=col++;
    for(auto s:adj[v]){
        if(s!=p){
            dfs(s,v,col++);
        }
    }
}  
int32_t main() {

    fast();
    cin>>n;
    ll i,x,y;
    vector<pa>p;
    f(i,0,n-1){
        cin>>x>>y;
        x--;
        y--;
        adj[x].pb(y);
        adj[y].pb(x);  
        deg[x]++;
        deg[y]++;
        p.pb({x,y});

    }
    f(i,0,n){
        if(deg[i]>ma){
            ma=deg[i];
            ind=i;
        }
    }
    dfs(0,-1,0);
    cout<<ma<<edl;
    ll c=0;
    for(auto s:p){
        cout<<marks[s]%ma+1<<edl;
    }
   


    cerr << "\nTime taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;


 }

Measured memory_bytes: 30832
#include<iostream>
using namespace std;
typedef long long ll;
ll mod=1e9+7;

ll modpow(ll a, int p){
	if(p==0) return 1;
	if(p%2==0){
		int halfP=p/2;
		ll half=modpow(a,halfP);
		return half*half%mod;
	}else{
		return a*modpow(a,p-1)%mod;
	}
}

ll calcComb(int a,int b){
	if(b>a-b) return calcComb(a,a-b);
	ll ansMul=1;
	ll ansDiv=1;
	for(int i=0;i<b;i++){
		ansMul*=a-i;
		ansDiv*=i+1;
		ansMul%=mod;
		ansDiv%=mod;
	}
	ll ans=ansMul*modpow(ansDiv,mod-2)%mod;
	return ans;
}

int main(){
	int n,m; cin >> n >> m;
	ll ans=1;
	int mrem=m;
	for(int i=2;i*i<=mrem;i++){
		if(mrem%i==0){
			int cnt=0;
			while(mrem%i==0){
				cnt++;
				mrem/=i;
			}
			ans*=calcComb(cnt+n-1,n-1);
			ans%=mod;
		}
	}
	if(mrem!=1){
		ans*=calcComb(1+n-1,n-1);
		ans%=mod;
	}
	cout << ans << endl;
}


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

long long solve(long long n) {
    if (n < 10) {
        return n;
    }
    if (n % 10 == 9) {
        return 9 + solve(n / 10);
    } else {
        return 9 + solve((n / 10) - 1);
    }
}
 
int main() {
    long long  n;
    cin >> n;
    long long ans = solve(n);
    cout << ans << endl;
    return 0;
}
 

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

#define ll long long
using namespace std;

const int N = 105, W = 1e5 + 5;
int n, m, w[N], v[N];
ll dp[N][W];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            dp[i][j] = dp[i - 1][j];
            if(w[i] <= j) {
                dp[i][j] = max(dp[i][j], v[i] + dp[i - 1][j - w[i]]);
            }
        }
    }
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 79360
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let S: Vec<char> = read_line().chars().collect();
    let T: Vec<char> = read_line().chars().collect();
    let mut hashS = std::collections::HashMap::new();
    let mut hashT = std::collections::HashMap::new();
    for i in 0..S.len() {
        let c = hashS.entry(S[i]).or_insert(T[i]);
        if *c != T[i] {
            println!("No");
            return;
        }
        
        let c = hashT.entry(T[i]).or_insert(S[i]);
        if *c != S[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

int main()
{
    int n, l, sum, min = 1e9;
    cin >> n >> l;
    for (int i = 1; i <= n; i++) {
        int a = l + i - 1;
        sum += a;
        if (abs(a) < abs(min)) min = a;
    }
    cout << sum - min << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            B.OrdinaryNumber();
        }
    }

    class B
    {
        public static void OrdinaryNumber()
        {
            int n = Input.getInt();
            int[] p = Input.getIntArray();

            int cnt = 0;
            for(int i=1; i<n-1; i++)
            {
                if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1]) cnt ++;                
            }

            Output.writeInt(cnt);
        }
    }
  
    class Input
    {
        public static int getInt()
        {
            int i = int.Parse(Console.ReadLine());
            return i;
        }

        public static string getString()
        {
            string s = Console.ReadLine();
            return s;
        }
        public static int[] getIntArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = s.Select(x=>int.Parse(x)).ToArray();
            return num;
        }
    }

    class Output
    {
        public static void writeInt(int i)
        {
            Console.WriteLine(i);
        }
    }
}


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

int id = INT_MAX;
int merge(int l, int r) {
	return min(l, r);
}

struct node {
	int val;
	int all;
	node *lch, *rch;
	unsigned int pri;
	int size;
	node(int v, unsigned int p) : val(v), all(v), pri(p), size(1) {
		lch = rch = nullptr;
	}
};

random_device rd;

int count(node *t) { return t == nullptr ? 0 : t->size; }
int que(node *t) { return t == nullptr ? id : t->all; }
node *update(node *t) {
	t->size = count(t->lch) + count(t->rch) + 1;
	t->all = merge(que(t->lch), merge(t->val, que(t->rch)));
	return t;
}
node *merge(node *l, node *r) {
	if (l == nullptr || r == nullptr) return l == nullptr ? r : l;
	if (l->pri > r->pri) {
		l->rch = merge(l->rch, r);
		return update(l);
	}
	else {
		r->lch = merge(l, r->lch);
		return update(r);
	}
}
pair<node*, node*> split(node *t, int k) {
	if (t == nullptr) return make_pair(nullptr, nullptr);
	if (k <= count(t->lch)) {
		pair<node*, node*> s = split(t->lch, k);
		t->lch = s.second;
		return make_pair(s.first, update(t));
	}
	else {
		pair<node*, node*> s = split(t->rch, k - count(t->lch) - 1);
		t->rch = s.first;
		return make_pair(update(t), s.second);
	}
}
node *insert(node *t, int k, int v, unsigned int pri) {
	pair<node*, node*> s = split(t, k);
	node *r = merge(s.first, new node(v, pri));
	r = merge(r, s.second);
	return r;
}
node *erase(node *t, int k) {
	pair<node*, node*> s1 = split(t, k), s2 = split(s1.second, 1);
	if (s2.first != nullptr) delete s2.first;
	return merge(s1.first, s2.second);
}
node *find(node *t, int k) {
	if (t == nullptr) return t;
	int c = count(t->lch);
	return k < c ? find(t->lch, k) : k == c ? t : find(t->rch, k - (c + 1));
}
int find(node *t, int l, int r) {
	if (t == nullptr) return id;
	if (r < 0 || l >= count(t)) return id;
	if (l <= 0 && r >= count(t)) return t->all;
	int c = count(t->lch);
	return merge(t->lch == nullptr ? id : find(t->lch, l, r), merge(l <= c && c < r ? t->val : id, t->rch == nullptr ? id : find(t->rch, l - (c + 1), r - (c + 1))));
}
int cnt(node *t, int v) {
	if (t == nullptr) return 0;
	if (t->val < v) return count(t->lch) + 1 + cnt(t->rch, v);
	if (t->val == v) return count(t->lch);
	return cnt(t->lch, v);
}
node *shift(node *t, int l, int r) {
	pair<node*, node*> s1 = split(t, l), s2 = split(s1.second, r - l), s3 = split(s2.second, 1);
	return merge(s1.first, merge(s3.first, merge(s2.first, s3.second)));
}
node *change(node *t, int k, int v) {
	if (t == nullptr) return nullptr;
	int c = count(t->lch);
	if (k < c) {
		t->lch = change(t->lch, k, v);
		update(t);
	}
	else if (k > c) {
		t->rch = change(t->rch, k - (c + 1), v);
		update(t);
	}
	else {
		t->val = v;
		update(t);
	}
	return t;
}

int main()
{
	cin.sync_with_stdio(false);
	int n, q, x, y, z;
	cin >> n >> q;
	node *root = nullptr;
	for (int i = 0, a; i < n; i++) {
		cin >> a;
		root = insert(root, i, a, rd());
	}
	while (q--) {
		cin >> x >> y >> z;
		if (x == 0) {
			root = shift(root, y, z);
		}
		else if (x == 1) {
			printf("%d\n", find(root, y, z + 1));
		}
		else {
			root = change(root, y, z);
		}
	}
	return 0;
}

Measured memory_bytes: 12712
n, m = map(int, input().split())
shop = []
for i in range(n):
    shop.append(list(map(int, input().split())))
shop.sort()
i = 0
tot_b = 0
while tot_b < m:
    tot_b += shop[i][1]
    i += 1
i -= 1
if tot_b == m:
    cost = 0
    for k in range(i+1):
        cost += shop[k][0]*shop[k][1]
    print(cost)
if tot_b > m:
    cost = 0
    for k in range(i):
        cost+= shop[k][0]*shop[k][1]
    cost += shop[i][0]*(shop[i][1]+m-tot_b)
    print(cost)



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

public class Main {
    public static final long mod = 998244353L;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //programmingOU B
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        long[] d = in.nl(n);
        long[] dist = new long[n];
        long ans = 0;
        if(d[0]==0){
            ans = 1;
            dist[0]++;
            boolean flag = true;
            for (int i = 1; i < n; i++) {
                if(d[i] > 0) dist[(int)d[i]]++;
                else flag = false;
            }
            if(flag){
                for (int i = 0; i < n-1; i++) if (dist[i] == 0 && dist[i + 1] > 0) flag = false;
            }
            if(flag){
                for (int i = 0; i < n-1; i++) {
                    ans *= pow(dist[i], dist[i+1]);
                    ans %= mod;
                }
            }else ans = 0;
        }
        out.println(ans);
    }
    public static long pow(long x, long n){
        long res = 1;
        while(n > 0){
            if ((n & 1) == 1) {
                res *= x;
                res %= mod;
            }
            x *= x;
            x %= mod;
            n >>= 1;
        }
        return res;
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 35740
#include <stdio.h>

int main(void) {
	int h,w;
	do{
		scanf("%d%d",&h,&w);
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if((i * j == 0)||(i ==h-1)||(j==w-1)){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		if(!(h&&w))break;
		printf("\n");
	}while(1);
	return 0;

}



Measured memory_bytes: 2044
#include <stdio.h>
#include <string.h>

int main(void)
{
  char s[100001] = "";
  char *p;
  int f = 0;
  scanf("%s", s);
  
  p = s;
  
  while ( strlen(p) != 0 ) {
    //puts(p);
    if ( strncmp(p, "dreameraser", 11) == 0 ) {
      p += 11;
    } else if ( strncmp(p, "dreamerase", 10) == 0 ) {
      p += 10;
    } else if ( strncmp(p, "eraser", 6) == 0 ) {
      p += 6;
    } else if ( strncmp(p, "dreamer", 7) == 0 ) {
      p += 7;
    } else if ( strncmp(p, "dream", 5) == 0 ) {
      p += 5;
    } else if ( strncmp(p, "erase", 5) == 0 ) {
      p += 5;
    } else {
      f = 1;
      puts("NO");
      break;
    }
  }
  if ( ! f ) {
    puts("YES");
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    public static void Main()
    {
        var str = Console.ReadLine()
            .Split(' ')
            .Select(x => int.Parse(x))
            .ToArray();
        var nn = str[0];
        var m = str[1];
        var ls = new List<Cake>();
        for (int i = 0; i < nn; i++)
        {
            var st = Console.ReadLine()
                .Split(' ')
                .Select(x => long.Parse(x))
                .ToArray();
            var c = new Cake() { Kireisa = st[0], Oishisa = st[1], Ninkido = st[2] };
            ls.Add(c);
        }

        var bits = CreateBits(3);

        var lss = new List<UnkoList<Cake>>();
        foreach (var item in bits)
        {
            long count = 0;
            long num = 0;
            var oti = new UnkoList<Cake>();
            ls.OrderByDescending(x =>
            {
                num = item[0] ? x.Kireisa : -x.Kireisa;
                num += item[1] ? x.Ninkido : -x.Ninkido;
                num += item[2] ? x.Oishisa : -x.Oishisa;
                return num;
            })
            .Take(m)
            .ToList()
            .ForEach(x =>
            {
                oti.Add(x);
            });
            oti.ForEach(x =>
            {
                oti.Num += item[0] ? x.Kireisa : -x.Kireisa;
                oti.Num += item[1] ? x.Ninkido : -x.Ninkido;
                oti.Num += item[2] ? x.Oishisa : -x.Oishisa;
            });
            lss.Add(oti);
        }
        var xx = lss.OrderByDescending(x => x.Num).FirstOrDefault();
        Console.WriteLine(xx.Num);
        Console.ReadLine();
    }

    class Cake
    {
        public long Kireisa;
        public long Oishisa;
        public long Ninkido;
    }

    #region　bit全探索
    /// <summary>
    /// Bit全探索用のライブラリ
    /// </summary>
    /// <param name="len">作る配列の長さ(lenが0以下だと（ｒｙ)</param>
    /// <returns>できた配列</returns>
    public static List<List<bool>> CreateBits(int len)
    {
        return CreateBitsPri(new List<List<bool>>(), len, 0);
    }

    private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count)
    {
        if (count == 0)
        {
            var lss = new List<bool>();
            lss.Add(true);
            bits.Add(lss);
            var lx = new List<bool>();
            lx.Add(false);
            bits.Add(lx);
            count++;
            return CreateBitsPri(bits, len, count);
        }
        if (len - count == 0)
            return bits;
        count++;
        var ls = new List<List<bool>>();
        foreach (var item in bits)
        {
            var x = item.ToList();
            x.Add(true);
            item.Add(false);
            ls.Add(item);
            ls.Add(x);
        }
        return CreateBitsPri(ls, len, count);
    }
    #endregion

    class UnkoList<T> : List<T> 
    {
        public long Num;
    }
}


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

int cnt=0;

void merge(int a[],int l,int m,int r){
	int n1=m-l;
	int n2=r-m;
	vector<int> L;
	vector<int> R;
	int i,j;
	for(i=0;i<n1;i++){L.push_back(a[l+i]);}
	for(i=0;i<n2;i++){R.push_back(a[m+i]);}
	L.push_back(1<<30);
	R.push_back(1<<30);
	i=j=0;
	for(int k=l;k<r;k++){
		if(L[i]<R[j]){
			a[k]=L[i++];
		}else{
			a[k]=R[j++];
		}
		cnt++;
	}
}

void mergeSort(int a[], int l, int r){
	if(l+1<r){
		int mid=l+(r-l)/2;
		mergeSort(a,l,mid);
		mergeSort(a,mid,r);
		merge(a,l,mid,r);
	}
}

void mergeSort(int n, int a[]){
	mergeSort(a,0,n);
}

int main(){
	int n, a[500000];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	mergeSort(n,a);
	cout << a[0];
	for(int i=1;i<n;i++){
		cout << " " << a[i];
	}
	cout << endl;
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 7276
// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let (h, w) = readl!(usize, usize);
    let mut s = Vec::with_capacity(h);
    for _ in 0..h {
        let a = readl!(String);
        s.push(a.into_bytes());
    }

    for i in 0..h {
        for j in 0..w {
            let mut cnt = 0;
            for dx in 0..3 {
                for dy in 0..3 {
                    if dx == 1 && dy == 1 {
                        continue;
                    }
                    let nx = (i+dx) as i32 -1;
                    let ny = (j+dy) as i32 -1;
                    if 0 <= nx && nx < h as i32 && 0 <= ny && ny < w as i32 {
                        if s[nx as usize][ny as usize] == '#' as u8 {
                            cnt += 1;
                        }
                    }
                }
            }
            if s[i][j] == '#' as u8 {
                print!("#");
            } else {
                print!("{}", cnt);
            }
        }
        println!("");
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin>>n;
  vector<int> e(n);
  rep(i,n) cin >> e[i];
  int m = *max_element(all(e));
  int s = 0;
  rep(i,n) s += e[i];
  s -= m;
  cout<<(s>m ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void) {
    int N;
scanf("%d",&N);
int array[N];

for (int i=0;i<N;i++)
scanf("%d",&array[i]);
float sum=0;
for (int i=0;i<N;i++)
sum+=1/(float)array[i];

printf("%.5f",1/sum);

return EXIT_SUCCESS;
}


Measured memory_bytes: 128
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

dp = [[float('inf')]* W for _ in range(H)]

if s[0][0]=='#':
    dp[0][0]=1
else:
    dp[0][0]=0

for c in range(W):
    for r in range(H):
        if r > 0:
            count=0
            if s[r-1][c]=='.' and s[r][c]=='#':
                count = 1
            dp[r][c] = min(dp[r][c], dp[r-1][c]+count)
        if c > 0:
            count=0
            if s[r][c-1]=='.' and s[r][c]=='#':
                count = 1
            dp[r][c] = min(dp[r][c], dp[r][c-1]+count)
print(dp[H-1][W-1])

Measured memory_bytes: 44784
#include<bits/stdc++.h>
#define fi first
#define se second
#define bug cout<<"--------------"<<endl
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=1e9;
const ll llf=1e18;
const int mod=1e9+7;
const int maxn=1e5+10;
int n;
int x[110],y[110],h[110];
int flag;
int solve(int cx,int cy){
	int H;
	if(!flag){
		H=1;
		for(int i=1;i<=n;i++){
			if(H-abs(x[i]-cx)-abs(y[i]-cy)>0) return 0;
		}
		return 1;
	}
	for(int i=1;i<=n;i++){
		if(h[i]){
			H=abs(x[i]-cx)+abs(y[i]-cy)+h[i];
			break;
		}
	}
	for(int i=1;i<=n;i++){
		int p=max(H-abs(x[i]-cx)-abs(y[i]-cy),0);
		if(p!=h[i]) return 0;
	}
	return H;
}
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]){
			flag=1;
		}
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			int k=solve(i,j);
			if(k){
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string color = Console.ReadLine();

            //出力
            Console.WriteLine(N < 3200 ? "red":color);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
from collections import deque

def main():
    input()
    A = list(enumerate(input().split()))
    b = deque()
    (append1, append2) = (b.append, b.appendleft) if len(A) % 2 == 0 else (b.appendleft, b.append)
    for i, a in A:
        if i % 2 == 0:
            append1(a) 
        else:
            append2(a)

    print(" ".join(list(b)))

main()


Measured memory_bytes: 47172
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    string S[50], T[50];

    bool flag;

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

    for(int i=0; i<M; i++){
	cin >> T[i];
    }

    
    for(int x=0; x<N; x++){
	for(int y=0; y<N; y++){
	    flag = true;
	    for(int xM=0; xM<M; xM++){
		for(int yM=0; yM<M; yM++){
		    if(y+yM>=N || x+xM>=N || S[x+xM][y+yM]!=T[xM][yM]){
			flag = false;
			break;
		    }		    
		}
	    }
	    if(flag){
		cout <<"Yes"<<endl;
		return 0;
	    }
	}
    }

    cout <<"No"<<endl;


}


Measured memory_bytes: 256
using System;

namespace ForAizuSol
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = Console.ReadLine().Split(' ');
            var one = int.Parse(list[0]);
            var zero = int.Parse(list[1]);
            var minone = int.Parse(list[2]);
            var maisu = int.Parse(list[3]);


            var onereal = 0;
            var minonereal = 0;

            if (maisu <= one)
            {
                onereal = maisu;
            }
            else
            {
                onereal = one;

                if (maisu > one + zero)
                {
                    minonereal = -(maisu - one - zero);
                }
            }

            Console.WriteLine(onereal + minonereal);
        }
    }
}

Measured memory_bytes: 27544
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D)
    cout << "Left" << endl;
  else if (A + B == C + D)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
N = int(input())
T = list(map(int,input().split()))
M = int(input())
px = [list(map(int,input().split())) for _ in range(M)]


for i in range(M):
    cnt = 0
    for j in range(len(T)):
        if px[i][0] == j+1 :
            cnt += px[i][1]
        else:
            cnt += T[j]
    print(cnt)   
    

Measured memory_bytes: 9136
/**
 * Created by hiramekun at 23:41 on 2020-05-19.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, m;
    cin >> n >> m;
    vl ans(n, -1);
    rep(i, m) {
        ll s, c;
        cin >> s >> c;
        s--;
        if (ans[s] == -1) ans[s] = c;
        else if (ans[s] != c) {
            cout << -1 << '\n';
            return;
        }
    }
    if (ans[0] == -1 && n == 1) ans[0] = 0;
    else {
        if (n != 1 && ans[0] == 0) {
            cout << -1 << '\n';
            return;
        }
        if (ans[0] == -1) ans[0] = 1;
        for (ll i = 1; i < n; ++i) {
            if (ans[i] == -1) ans[i] = 0;
        }
    }
    string str;
    rep(i, n) {
        str += (ans[i] + '0');
    }
    cout << str << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef long long ll;

const int Maxn = 100005;

int n, m;
vector <int> neigh[Maxn];
bool tk[Maxn];
int lft;
int bic, nonbic;
int col[Maxn];
ll res;

int Count(int v)
{
    if (tk[v]) return 0;
    tk[v] = true;
    int cnt = 1;
    for (int i = 0; i < neigh[v].size(); i++)
        cnt += Count(neigh[v][i]);
    return cnt;
}

bool Bic(int v, int c)
{
    if (col[v] != 0) return col[v] == c;
    col[v] = c;
    for (int i = 0; i < neigh[v].size(); i++)
        if (!Bic(neigh[v][i], -c)) return false;
    return true;
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    lft = n;
    for (int i = 1; i <= n; i++) if (!tk[i]) {
        int siz = Count(i);
        if (siz == 1) { lft--; res += 2ll * lft + 1ll; }
        else if (Bic(i, 1)) bic++;
             else nonbic++;
    }
    while (nonbic > 0) {
        nonbic--;
        res += 2 * (bic + nonbic) + 1;
    }
    res += ll(bic) * bic * 2ll;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 10112
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 4 * n] * n

if k >= n:
    ans = abs(h[0] - h[n - 1])
else:
    dp[0] = 0
    for i in range(n - 1):
        j = 1
        while i + j < n:
            if j == k + 1:
                break
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
            j += 1
    ans = dp[n - 1]
print(ans)

Measured memory_bytes: 52592
//1時間経過しました（大嘘）。嘘解法をお伝えします。
//貪欲に「Mの倍数」ペアを作って, 残った数であれする。
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

int n, m;
int x[100000];
int cnt[100001];		//mod Mして値をカウント
int used[100001];		//mod Mして値をカウント -> Mの倍数ペアを作る -> いくつ使ったか？

void input() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		cnt[x[i] % m]++;
	}
}

//usedを使って, 同じ数で作る
int unko() {
	typedef pair<int, int> P;
	
	static int k_cnt[100000] = {0};	//k_cnt[i] = Mで割ってi余る要素のうち, 奇数個のものの個数
	map<int, int> m_cnt;
	
	for (int i = 0; i < n; i++) {
		if (m_cnt.find(x[i]) == m_cnt.end()) {
			m_cnt[x[i]] = 0;
		}
		m_cnt[x[i]]++;
	}
	
	for (map<int, int>::iterator it = m_cnt.begin(); it != m_cnt.end(); it++) {
		int val = (*it).first;
		int cnt = (*it).second;
		if (cnt % 2 == 1) k_cnt[val % m]++;
	}
	
	static int loss[100000] = {0};		//loss[i] = 奇数で残ってしまう整数の個数
	for (int i = 0; i < m; i++) {
		if (k_cnt[i] >= used[i]) {
			loss[i] = k_cnt[i] - used[i];
		}
		else {
			loss[i] = (used[i] - k_cnt[i]) % 2;
		}
	}
	
	int ret = 0;
	for (int i = 0; i < m; i++) {
		ret += (cnt[i] - loss[i]) / 2;
	}
	return ret;
}

signed main() {
	input();
	
	int ans = 0;
	for (int i = 0; i < m; i++) {
		int p = m - i;
		if (i == 0) p = 0;
		
		if (i == 0 || i == p) {
			int plus = cnt[i] / 2;
			ans += plus;
			cnt[i] -= 2 * plus;
			used[i] += 2 * plus;
		}
		else {
			int plus = min(cnt[i], cnt[p]);
			ans += plus;
			cnt[i] -= plus;
			cnt[p] -= plus;
			used[i] += plus;
			used[p] += plus;
		}
	}
	
	ans += unko();
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6912