akhauriyash/Code-Regression huggingface dataset:
class BinarySearchTree:

    def __init__(self):
        self.root = None

    def insert(self, z):
        p = None
        x = self.root
        while x != None:
            p = x
            if z.key < x.key : x = x.left
            else             : x = x.right
        z.p = p
        if p == None      : self.root = z
        elif z.key < p.key: p.left  = z
        else              : p.right = z

    def get_inorder_list(self):
        def _get_inorder_list(root):
            l = root.left
            r = root.right
            if l: yield from _get_inorder_list(l)
            yield root.key
            if r: yield from _get_inorder_list(r)
        yield from _get_inorder_list(self.root)

    def get_preorder_list(self):
        def _get_preorder_list(root):
            l = root.left
            r = root.right
            yield root.key
            if l: yield from _get_preorder_list(l)
            if r: yield from _get_preorder_list(r)
        yield from _get_preorder_list(self.root)

    def find(self, k):
        z = self.root
        while z:
            if k == z.key: return z
            if k <  z.key: z = z.left
            else         : z = z.right
        return None

    def delete(self, k):
        def ldelete(z):
            def get_next(x):
                c = x.left if x.left else x.right
                if c: return get_next(c)
                else: return x
            if z.left and z.right:
                next_node = get_next(z.right)
                z_key_n = next_node.key
                ldelete(next_node)
                z.key = z_key_n
            else:
                c = z.left if z.left else z.right
                if   z.p == None    : self.root = c
                elif z.key < z.p.key: z.p.left  = c
                else                : z.p.right = c
                if c: c.p = z.p
        z = self.find(k)
        if z: ldelete(z)
# end class BinarySearchTree:

class Node:
    def __init__(self, k):
        self.key = k
        self.p = None
        self.left = None
        self.right = None
#end class Node:
       

if __name__=='__main__':
    m = int(input())

    T = BinarySearchTree()
    for _ in range(m):        
        op = input().split()
        if   op[0] == 'insert': T.insert( Node(int(op[1])) )
        elif op[0] == 'delete': T.delete( int(op[1]) )
        elif op[0] == 'find'  : print("yes" if T.find(int(op[1])) else "no")
        else:
            print("",*T.get_inorder_list())
            print("",*T.get_preorder_list())

Measured memory_bytes: 130760
/* ***************************************
Author        :Scau.ion
Created Time  :2017/09/23 20:08:27 UTC+8
File Name     :ion.cpp
*************************************** */

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

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

int main()
{
    IOS;
    int n, m, k;
    cin>>n>>m>>k;
    for (int jn = 0; jn <= n; ++ jn)
    {
        for (int jm = 0; jm <= m; ++ jm)
        {
            int tis = jn * m;
            tis -= jm * jn;
            tis += jm * (n - jn);
            if (k == tis)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()  
{
  int X;
  scanf("%d",&X);
  
  if(X>=-40 && X<=40)
  {
    if(X>=30)
    {
      printf("Yes");
    }
    else
    {
      printf("No");
    }
  }
  return 0;
}

Measured memory_bytes: 1728
elem = input().split('/')
ans = "Heisei"

if int(elem[0], 10) > 2019:
    ans = "TBD"
elif int(elem[1], 10) > 4:
    ans = "TBD"
elif int(elem[2], 10) > 30:
    ans = "TBD"


print(ans)


Measured memory_bytes: 2940
N, M = list(map(int, input().split()))
    
S = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(2**N):
    cnt = 0
    for j in range(M):
        tmp = 0
        for s in S[j]:
            if (i & (1<<(s-1))):
                tmp = 1 - tmp
        if tmp % 2 == P[j]:
            cnt += 1
    if cnt ==  M:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum=0;
	int n,m,c;
	cin>>n>>m>>c;
	int b[m],a[n][m];
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	int f;
	for(int i=0;i<n;i++)
	{
		f=0;
		for(int j=0;j<m;j++)
		{
			f=f+(a[i][j]*b[j]);
		}
		f=f+c;
		if(f>0)
		{
			sum++;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int

	fmt.Scan(&n)

	s := make([]string, n)
	var countS map[string]int = map[string]int{}

	max := 0

	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
		countS[s[i]]++

		if max < countS[s[i]] {
			max = countS[s[i]]
		}
	}

	k := make([]string, 0)
	for key, _ := range countS {
		k = append(k, key)
	}

	sort.Strings(k)

	for _, key := range k {
		if countS[key] == max {
			fmt.Println(key)
		}
	}
}


Measured memory_bytes: 37372
#include<bits/stdc++.h>
int main(){
  std::vector <int>a(100);
  int N,Alice,Bob;
  std::cin>>N;
  Alice=Bob=0;
  for(int i=0;i<N;i++){
    std::cin>>a[i];
  }
  std::sort(a.begin(),a.end());
  std::reverse(a.begin(), a.end());
  for(int i=0;i<N;i++){
    if(i%2==0){
      Alice+=a[i];
    }else{
      Bob+=a[i];
    }
  }
    std::cout<<Alice-Bob<<std::endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;

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

    lli ans = 0;
    for(auto p: b){
        ans += p.second * (p.second -1) /2;
    }

    for(int i=0; i<n; i++){
        cout << ans - b[a[i]] *(b[a[i]]-1) /2 +(b[a[i]]-1) *(b[a[i]]-2)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  string S; cin >> S;
  rep(i, S.size())cout << "x";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int x1,y1,x2,y2;
  scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

  int a = x2-x1;
  int b = y2-y1;
  
  printf("%d %d %d %d\n",x2-b,y2+a,x1-b,y1+a);

  return 0;
}

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

int main(){
    int n;
    string s,t;
    cin>>n>>s>>t;
    for(int i=n; i>=0; --i){
        if(s.substr(n-i,i)==t.substr(0,i)){
            cout<<n*2-i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;

const int inf = numeric_limits<int>::max();


int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int counter = 1;
    while(a>0 && c>0){
        if(counter%2 == 1){
            c-=b;
        }
        else{
            a-=d;
        }
        counter++;
    }
    if(a>0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

















Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	makes(s);
	bool b[26];
	rep(26)b[i] = true;
	for (char x : s)b[x - 'a'] = false;
	if (s.size() != 26) {
		cout << s;
		rep(26) {
			if (b[i]) {
				say((char)('a' + i));
				re;
			}
		}
	}
	else {
		rep(25) {
			if (s[25 - i] > s[24 - i]) {
				For(j, 24 - i) {
					cout << s[j];
				}
				For(j, 26) {
					if (s[24 - i] < s[25 - j]) {
						say(s[25 - j]);
						re;
					}
				}
			}
		}
		say(-1);
	}
}

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

const int MAX = 1e6 + 10;
int to[MAX][26], bad[MAX][26], tot[MAX], sz;
ll ans = 0;

void add(string s) {
    array<int, 26> cnt;
    for(int i = 0; i < 26; i++)
        cnt[i] = 0;
    for(auto &c : s)
        cnt[c - 'a']++;
    int cur = 0;
    for(auto &c : s) {
        tot[cur]++;
        for(int i = 0; i < 26; i++)
            if(!cnt[i]) bad[cur][i]++;
        cnt[c - 'a']--;
        if(!to[cur][c - 'a'])
            to[cur][c - 'a'] = ++sz;
        cur = to[cur][c - 'a'];
    }
    tot[cur]++;
    for(int i = 0; i < 26; i++)
        bad[cur][i]++;
}

ll get(string &s) {
    int cur = 0;
    for(int i = 0; i + 1 < s.size(); i++) {
        //cout << s[i];
        cur = to[cur][s[i] - 'a'];
    }
    //cout << '\n';
    //cout << cur << " " << tot[cur] << '\n';
    return tot[cur] - 1 - bad[cur][s.back() - 'a'];
}

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

    int n;
    cin >> n;
    vector<string> v(n);
    for(auto &s : v) {
        cin >> s;
        reverse(s.begin(), s.end());
        //cout << s << '\n';
        add(s);
        //cout << sz << '\n';
    }
    for(auto &s : v) {
        ans += get(s);
        //cout << ans << '\n';
    }

    //for(int i = 0; i <= sz; i++)
    //    cout << i << " " << tot[i] << '\n';

    cout << ans << '\n';
}

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

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

using namespace std;

int main()
{
  int n, c;
  cin >> n >> c;
  ll grid0[30] = {}, grid1[30] = {}, grid2[30] = {};
  ll d[30][30];
  REP(i, c)
  {
    REP(j, c)
    {
      cin >> d[i][j];
    }
  }

  REP(i, n)
  {
    REP(j, n)
    {
      int c;
      cin >> c;
      c--;
      if ((i + j) % 3 == 0)
      {
        grid0[c]++;
      }
      else if ((i + j) % 3 == 1)
      {
        grid1[c]++;
      }
      else
      {
        grid2[c]++;
      }
    }
  }

  ll result = 1000000000;
  REP(i, c)
  {
    REP(j, c)
    {
      if (i == j)
        continue;
      REP(k, c)
      {
        if (i == k || j == k)
          continue;
        ll tmp = 0;
        REP(l, c)
        {
          tmp += grid0[l] * d[l][i];
          tmp += grid1[l] * d[l][j];
          tmp += grid2[l] * d[l][k];
        }
        result = min(result, tmp);
      }
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int T;
    cin >> T;
    int A,B;
    cin >> A>>B;
    string N;
    cin >> N;
    int YES = 0;
    int YESb= 0;
    for(int i=0;i<T;++i){
        if(N.at(i)=='a' && YES<(A+B)){
            cout << "Yes"<<endl;
            ++YES;
        }
        else if (N.at(i)=='b' && YES<(A+B)&&YESb<B){
            cout << "Yes"<<endl;
            ++YES;
            ++YESb;
        }
        else{
            cout << "No" <<endl;
        }
    }
}

Measured memory_bytes: 896
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def calc(x, isTrans):
    if isTrans:
        y = np.copy(x.T)
    else:
        y = np.copy(x)

    for i in range(len(y)):
        xxx = np.copy(y[i])
        tmp_l = np.arange(len(xxx))
        tmp_l[xxx > 0] = 0
        np.maximum.accumulate(tmp_l, out=tmp_l)
        left = tmp_l

        xxx_reverse = xxx[::-1]
        tmp_r = np.arange(len(xxx_reverse))
        tmp_r[xxx_reverse > 0] = 0
        np.maximum.accumulate(tmp_r, out=tmp_r)
        right = len(xxx)-tmp_r[::-1]-1

        y[i] = right-left-1
        y[i][xxx == 0] = 0

    if isTrans:
        return np.transpose(y)
    else:
        return y


if __name__ == "__main__":
    h, w = map(int, readline().split())
    room = np.zeros((h+2, w+2), dtype=np.int)
    for i in range(1, h+1):
        room[i][1:-1] = [0 if i == "#" else 1 for i in input()]

    a = calc(room, True)
    b = calc(room, False)
    ans = (a + b).max() - 1
    print(ans)


Measured memory_bytes: 137716
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof i);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) (x&-x)
#define siz(v) (long long)v.size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

int main() {
    EmiliaMyWife

    set<char> has;
    for(int i = 0; i < 26; i++) has.insert('a'+i);
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        has.erase(s[i]);
    }
    if(has.size()) cout << *has.begin();
    else cout << "None";

	return 0;
}


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

int n;
string s, ans;
int cnt;

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

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(') {
      cnt++;
      ans += '(';
    }
    else if (s[i] == ')') {
      if (cnt == 0) {
        ans = '(' + ans + ')';
      }
      else {
        ans += ')';
        cnt--;
      }
    }
  }

  for (int i = 0; i < cnt; i++) ans += ')';

  cout << ans << endl;
}


Measured memory_bytes: 256
while True:
    input_value = input()

    height, width = map(int, input_value.split())

    if height == 0 and width == 0:
        break

    odd_row_chars = ['#' if i % 2 == 1 else '.' for i in range(width)]
    even_row_chars = ['#' if i % 2 == 0 else '.' for i in range(width)]

    odd_row_string = ''.join(odd_row_chars)
    even_row_string = ''.join(even_row_chars)

    lines = [even_row_string if i % 2 == 0 else odd_row_string for i in range(height)]

    chess_board = '\n'.join(lines)

    print(chess_board)
    print()






Measured memory_bytes: 5648
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy

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

P=[0 for i in range(N+1)]
P[0]=1
PB=[0 for i in range(N+1)]
PB[0]=1
for i in range(1,N+1):
    P[i]=1+2*P[i-1]
    PB[i]=3+2*PB[i-1]

count=0
idx=N

while X>0:
    A=PB[idx]
    if X>=A:
        X-=A
        count+=P[idx]
        if X>=1:
            count+=1
            X-=1
    else:
        X-=1
        idx-=1
print(count)


Measured memory_bytes: 64108
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	int X[100] = { 0 };
	cin >> a >> b >> c;
	if (a > b && a > c) {
		cout << b * c / 2;
	}
	else if (b > c && b > a) {
		cout << a * c / 2;
	}
	else {
		cout << a * b / 2;
	}
}

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

using namespace std;

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

	int n;
	cin >> n;
	set<string> st;
	string s;
	for(int i = 0; i < n; i++) {
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << '\n';
	
	return 0;
}


Measured memory_bytes: 19184
import java.util.Scanner;

public class Main {

    static Scanner scanner;
    static int a, b, c;

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

        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();

        candy_divide();
    }

    private static void candy_divide() {
        if ( a + b == c || a + c == b || b + c == a){
            System.out.println("Yes");
        }
        else
            System.out.println("No");
    }
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    cin >> n;
    vector<char> c(n);
    rep(i,0,n) cin >> c[i];

    int64_t mod=1e9+7;
    vector<vector<int64_t>> dp(n,vector<int64_t>(n+1));
    if(c[0]=='-') dp[0][1]=1;
    else dp[0][0]=1;
    rep(i,1,n){
        rep(j,0,n+1){
            if(c[i]=='-'){
                if(j-1>=0) dp[i][j]=dp[i-1][j-1];
            }
            if(c[i]=='U'){
                if(j-1>=0) dp[i][j]=dp[i-1][j-1]*(i-j+1);
                dp[i][j]+=dp[i-1][j];
            }
            if(c[i]=='D'){
                if(j-2>=0) dp[i][j]=dp[i-1][j-2]*(i-j+2)*(i-j+2);
                if(j-1>=0) dp[i][j]+=dp[i-1][j-1]*(i-j+1);
            }
            dp[i][j]%=mod;
        }
    }
    cout << dp[n-1][n] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3256
n,m = map(int,input().split())
alist = list(map(int,input().split()))

alist.sort(reverse=True)
allvote = sum(alist)

count = 0
for i in range(n):
    if alist[i] >= allvote/(4*m):
        count+=1

if count >= m:
    print("Yes")
else:
    print("No")

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

ans = 0
neg = 0
zero = False
smallest = abs(a[0])

for i in range(n):
    ans += abs(a[i])

    if abs(a[i]) < smallest:
        smallest = abs(a[i])

    if a[i] == 0:
        zero = True
    elif a[i] < 0:
        neg += 1

if neg % 2 == 1 and not zero:
    print(ans-2*smallest)
else:
    print(ans)

Measured memory_bytes: 20132
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    
    double r,x,y;
    cin >>r;
    
    x = 3.141592653589*r*r;
    y = 3.141592653589*2*r;
    
    printf("%f %f\n",x,y);
}



Measured memory_bytes: 3280
import java.util.Scanner;

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] a = new int[N];
        for(int i = 0; i < N; i++)
            a[i] = sc.nextInt();
        int ans = 0;
        for(int i = 0; i < N; i++)
            ans += cnt2(a[i]);
        System.out.println(ans);
    }

    static int cnt2(int a) {
        int ret = 0;
        while(a % 2 == 0) {
            ret++;
            a >>= 1;
        }
        return ret;
    }
}
public class Main {
    public static void main(String...args) {
        C.main();
    }
}

Measured memory_bytes: 36332
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int N, M; 
int X[100010]; 
int Y[100010];
int Z[100010]; 
int par[114514] = {}; 
int depth[114514] = {}; 
int find(int x){
	if(par[x] == x){
		return x;
	}
	else{
		return par[x] = find(par[x]); 
	}
}
void unite(int x, int y){
	x = find(x); 
	y = find(y); 
	if(x == y) return;
	else if(depth[x] < depth[y]){
		par[x] = y; 
	}else{
		par[y] = x; 
		if(depth[x] == depth[y]) depth[x] ++; 
	}
}
bool same(int x, int y){
	return find(x) == find(y); 
}
int main(){
	cin >> N >> M; 
  	for(int i = 1; i <= N; i++){
		par[i] = i, depth[i] = 0; 
	}
	for(int i = 1; i <= M; i++){
		cin >> X[i] >> Y[i] >> Z[i]; 
		unite(X[i], Y[i]); 
	}
	bool count[100010] = {};
	for(int i = 1; i <= N; i++){
		int a = find(i); count[a] = true; 
	}
	int ans = 0; 
	for(int i = 1; i <= N; i++){
		if(count[i]) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    string s,t;
    cin>>s>>t;
    int ans = t.size();

    for(int i =0 ; i < s.size() ; i++)
    {
        int temp = 0;
        for(int j = i ; j < i + t.size() ; j++)
        {
            if(j>=s.size())
            {
                temp = INF;
                break;
            }
            if(s[j]!=t[j-i])
                temp++;
        }

        ans = min(ans,temp);
    }
    cout<<ans;

    printclock;
    return 0;
}


Measured memory_bytes: 3848
Imports System
Imports System.IO

Module Module1

    Sub Main(ByVal args As String())

        Dim s As String() = Console.ReadLine().Split(" ")
        Dim ans As String

        Dim ta As Decimal = Math.Ceiling(CLng(s(2)) / CLng(s(1)))
        Dim ao As Decimal = Math.Ceiling(CLng(s(0)) / CLng(s(3)))

        If ta <= ao Then
            ans = "Yes"
        Else
            ans = "No"
        End If

        Console.Write(ans)

    End Sub

End Module

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

int cnt[110];
void prime_factorize(int n){
    for(int p = 2; p <= n; p++){
        if(n % p != 0) continue;
        while(n % p == 0){cnt[p]++; n /= p;}
    }
    if(n != 1) cnt[n] = 1;
    return;
}

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) prime_factorize(i);
    int sum = 0;
    for(int i = 0; i <= n; i++){
        if(cnt[i] >= 74) sum++;
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(i == j) continue;
            if(cnt[i] >= 24 && cnt[j] >= 2) sum++;
            if(cnt[i] >= 14 && cnt[j] >= 4) sum++;
        }
    }
    for(int i = 0; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            for(int k = j + 1; k <= n; k++){
                if(cnt[i] >= 4 && cnt[j] >= 4 && cnt[k] >= 2) sum++;
                if(cnt[i] >= 4 && cnt[j] >= 2 && cnt[k] >= 4) sum++;
                if(cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4) sum++;
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, A;

  std::cin >> N >> A;

  std::cout << N * N - A << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
int main() {
    int a, b; cin >> a >> b;
    int sum = 0;
    rep(i, b - a + 1) {
        sum += i;
    }
    cout << sum - b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

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

    cout << min(a,b) << " ";
  	if(a+b > n) cout << a + b - n << endl;
  	else cout << 0 << endl;
  	return 0;
  	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;
 
#define forl(i,a,b) for (int i = a; i <= b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin>>a>>b;
    cout<<(ll)a*b;
    return 0;    
}

Measured memory_bytes: 3652
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var input, height, width, area, outer;
  input = chunk.split(' ').map(Number);
  height = input[0];
  width = input[1];
  area = height * width;
  outer = (height * 2) + (width * 2);
  console.log(area.toString() + ' ' + outer.toString());
});

Measured memory_bytes: 7648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(void)
{
    int N;
    cin >> N;
    int price_max = 0;
    int price_total = 0;
    rep(i,N){
        int price; cin >> price;
        price_total += price;
        price_max = max(price, price_max);
    }
    price_total -= (price_max / 2);
    cout << price_total << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){//float?????????double???
int a,n,i,min,max,t,ok;
long s;
s=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&a);
if(i==1) min=a;
if(i==1) max=a;
s=a+s;
if(min>a) min=a;
if(max<a) max=a;
}

printf("%d %d %ld\n",min,max,s);
return 0;
}

Measured memory_bytes: 1860
import numpy as np

h,w,m = map(int,input().split())
bomb_list = []
for i in range(m):
    th,tw = map(int,input().split()) 
    bomb_list.append([th,tw])

bomb_list = np.array(bomb_list)

row_dict = [0]*h
column_dict = [0]*w

for i in range(m):
    th,tw = bomb_list[i]
    row_dict[th-1] += 1 
    column_dict[tw-1] += 1 

max_row = max(row_dict)
max_column = max(column_dict)

total = row_dict.count(max_row) * column_dict.count(max_column)

dup = 0
for i in range(m):
    th,tw = bomb_list[i]
    if row_dict[th-1] == max_row and column_dict[tw-1] == max_column:
        dup += 1

if dup < total:
    print(max_row+max_column)
else:
    print(max_row+max_column-1)


Measured memory_bytes: 76880
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long double a, b, ans;
	cin >> a >> b;
	ans = floor(a * b);

	long long aa = ans;
	cout << aa << "\n";


	return 0;
}


Measured memory_bytes: 3748
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    l = list(map(int, input().split()))
    l.sort()
    total = l[2]*2 - l[0] - l[1]
    if total % 2:
        print((total-1)//2+2)
    else:
        print(total//2)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import math

def cal_edge(cosA, b, c):
    return math.sqrt(b*b + c*c - 2 * b * c * cosA)

A, B, H, M = map(int, input().split())
minute = 60 * H + M

b_angle = (360 * M) / 60
a_angle = (360 * minute) / (60*12)

degree = math.fabs(a_angle - b_angle)

if degree > 180:
    degree = 360 - degree

cos = math.cos(math.radians(degree))

print(cal_edge(cos, A, B))

Measured memory_bytes: 9520
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int gx=-1e5;
    
    int ly = 1e6;
    for (int i = 0; i < n; i++)
    {
        int num;
        cin >> num;
        gx = max(gx, num);
    }//cout<<gx<<'\n';
    for (int i = 0; i < m; i++)
    {
        int num;
        cin >> num;
        ly = min(ly, num);
    }
    
    string ans = "War";
    if (gx < ly and (ly > x and gx < y) and x < y)
    {
        ans = "No War";
    }

    cout << ans << '\n';
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    int test;
    test = 1;
    while (test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3584
class Union():
  def __init__(me,N):
    me.N = N
    me.up = [-1]*N
    me.down = [ [] for i in range(N) ]
  def union(me,a,b):
    ua = me.up[a] if me.up[a]!=-1 else a
    ub = me.up[b] if me.up[b]!=-1 else b
    if (ua == ub):
      return
    if ( len(me.down[ua]) < len(me.down[ub]) ):
      ub,ua = ua,ub
    for v in me.down[ub]:
      me.up[v] = ua
    me.down[ua].extend( me.down[ub] )
    me.down[ub] = []
    me.up[ub] = ua
    me.down[ua].append( ub )
  def count(me,a):
    ua = me.up[a] if me.up[a]!=-1 else a
    return len(me.down[ua])+1
  
N = int(input())
li = [ [int(it) for it in input().split()] for i in range(N) ]

for i in range(N):
  li[i].append(i)

lx = sorted(li,lambda x:x[0])
ly = sorted(li,lambda x:x[1])

uni = Union(N)
for i in range(N-1):
  if ( lx[i][0] == lx[i+1][0] ):
    uni.union(lx[i][2],lx[i+1][2])
for i in range(N-1):
  if ( ly[i][1] == ly[i+1][1] ):
    uni.union(ly[i][2],ly[i+1][2])

s = 0
for i in range(N):
  if ( uni.up[i] != -1 ):
    continue
  px = set()
  py = set()
  px.add( li[i][0] )
  py.add( li[i][1] )
  for it in uni.down[i]:
      px.add( li[it][0] )
      py.add( li[it][1] )
  #print ( uni.count(i), len(px), len(py) )
  s += len(px)*len(py) - uni.count(i)
print ( s )

    

Measured memory_bytes: 99288
#include <stdio.h> 
int main(void) {
  int N, K, bt[100], vam[100][100], i, j, sum, flag;
  while(scanf("%d%d",&N,&K),N+K) {
    for(i = 0; i < K; i++ ) {
      scanf("%d",&bt[i]);
    }
    for(i = 0; i < N; i++ ) {
      for(j = 0; j < K; j++ ) {
	scanf("%d",&vam[i][j]);
      }
    }
    flag = 0;
    for(j = 0; j < K; j++ ) {
      sum = 0;
      for(i = 0; i < N; i++ ) {
	sum += vam[i][j];
      }
      if(sum > bt[j]) {
	flag = 1;
	break;
      }
    }
    if(flag) {
      puts("No");
    } else {
      puts("Yes");
    }
  }
  return 0;
}
	

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

const int maxN=101000;

int Mt[500][500];

int main(){
	int n,d;scanf("%d",&n);
	for (d=1;d*(d-1)<n+n;d++);
	if (d*(d-1)!=n+n){
		printf("No\n");return 0;
	}
	printf("Yes\n");
	for (int i=1,now=0,lst=0;i<=d+1;i++){
		for (int j=1;j<i;j++) Mt[i][j]=Mt[j][i-1];
		for (int j=i;j<d;j++) Mt[i][j]=++now;
	}
	printf("%d\n",d);
	for (int i=1;i<=d;i++){
		printf("%d ",d-1);
		for (int j=1;j<d;j++) printf("%d ",Mt[i][j]);
		printf("\n");
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
ll T[MAX_N];
ll A[MAX_N];
ll Mount[MAX_N];   // 高さの確定した山

signed main()
{
    cin >> N;
    REP(i, N) { cin >> T[i]; }
    REP(i, N) { cin >> A[i]; }

    // 記録の正当性チェック
    MINUS(Mount);
    Mount[0] = T[0];
    for(int i = 1; i < N; ++i) {
        if(T[i] > T[i-1]) {
            // 最高値が更新された = その山の高さがわかる
            Mount[i] = T[i];
        }
    }
    for(int i = N-1; i >= 0; --i) {
        if( (i == N-1) || (i < N-1 && A[i] > A[i+1]) ) {
            if(Mount[i] != -1 && Mount[i] != A[i]) {
                printf("0\n");
                return 0;
            }
            Mount[i] = A[i];
        }
        if(Mount[i] != -1 && Mount[i] > A[i]) {
            printf("0\n");
            return 0;
        }
    }

    ll ans = 1;
    REP(i, N) {
        //DBG("i: %lld Mount[i]: %lld\n", i, Mount[i]);
        if(Mount[i] == -1) {
            ans *= min(T[i], A[i]);
            ans %= MOD;
            //DBG("ans *= %lld -> ans = %lld\n", min(T[i], A[i]), ans);
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2560
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn get_point() -> (f64, f64) {
    let x = get();
    let y = get();
    (x, y)
}

type Pt = (f64, f64);
fn dist(a: Pt, b: Pt) -> f64 {
    ((a.0 - b.0).powi(2) + (a.1 - b.1).powi(2)).sqrt()
}

fn maxf(a: f64, b: f64) -> f64 {
    if a > b { a } else { b }
}

// I wrote this solution after I read the editorial.
fn solve() {
    let p1 = get_point();
    let p2 = get_point();
    let p3 = get_point();
    let two_s = (p2.0 - p1.0) * (p3.1 - p1.1) - (p3.0 - p1.0) * (p2.1 - p1.1);
    let two_s = two_s.abs();
    let a = dist(p1, p2);
    let b = dist(p3, p2);
    let c = dist(p1, p3);
    let r = two_s / (a + b + c);
    // Find x s.t. max(a, b, c) * (1 - x / r) >= 2 * x
    let abc = maxf(a, maxf(b, c));
    println!("{}", abc / (2.0 + abc / r));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
a, b, c = map(int, input().split())

if a % b == 0:
    if c == 0:
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"
    for i in range(1, b+1):
        if (a*i) % b == c:
            ans = "YES"
            break

print(ans)


Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------



int main(){
  char s[4];
  cin >> s;
  int i = 0;
  for(int a=0;a<4;++a){
    if(s[a]=='+'){
      ++i;
    }else{
      --i;
    }
  }
  cout << i;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    int n,p,i;
    cin>>n;
    string s;
    cin>>s;
    p=s.size();
    if(p>n)
    {
        for(int i=0;i<n;i++)
        cout<<s[i];
        cout<<"...";
    }
    else
        cout<<s<<endl;
    return 0;
}


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

int main() {
  int a,b,c,d,e;
  cin >> e ;
  a=e/1000 ;
  b=(e-1000*a)/100;
  c=(e-1000*a-100*b)/10;
  d=e-1000*a-100*b-10*c;
  if (a==b&&b==c||b==c&&c==d) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<string> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vector<int> ans(n,-1) ;
	for(int i=0;i<m;i++){
		ll s,c ;
		cin >> s >> c ;
		s-- ;
		if(s==0&&n!=1&&c==0){
			cout << -1 << endl ;
			return 0 ;
		}
		if(ans.at(s)!=-1&&ans.at(s)!=c){
			cout << -1 << endl ;
			return 0 ;
		}
		ans.at(s) = c ;
	}
	for(int i=0;i<n;i++){
		if(ans.at(i)==-1){
			if(i==0&&n!=1) cout << 1 ;
			else cout << 0 ;
		}else cout << ans.at(i) ;
	}
	cout << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    vector<ll> d(100);
    d[0] = 2;
    d[1] = 1;
    REP(i, 2, n + 1) {
        d[i] = d[i - 1] + d[i - 2];
    }
    
    cout << d[n] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll visited[200005];

int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+5],freq[n+5];
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        freq[i]=-1;
    }
    visited[1]=1;
    freq[1]=0;
    ll now=1,cnt=1;

    //cycle
    while(1)
    {
        if(visited[a[now]])
            break;
        now=a[now];
        visited[now]=1;
        freq[now]=cnt;
        cnt++;
    }

    if(k>=cnt)
    {
        ll diff=cnt-freq[a[now]];
        k-=freq[a[now]];
        k%=diff;
        k+=freq[a[now]];
    }
    for(int i=1; i<=n; i++)
    {
        if(freq[i]==k)
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 8304
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <stdlib.h>
#include <deque>
#include <cstdint>
using namespace std;

int main () {
  string a;
  cin >> a;
  int max = 0;
  int n = (int) a.length();
  for (int i = 0; i < n; i++){
    int t = 0;
    if (a[i] == 'A' || a[i] == 'C' || a[i]=='G' || a[i]=='T'){
      t++;
      for (int j = i+1; j < n; j++){
        if (a[j] != 'A' && a[j] != 'C' && a[j]!='G' && a[j]!='T'){
          break;  
        }else{
          t++;
        }
      }
    }
    if (t >= max){
      max = t;
    }
  }

  cout << max;
  return 0;
}

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

typedef long long ll;
ll a, b, c;
int main()
{
	scanf("%lld%lld%lld", &a, &b, &c);
	if(a + b >= c) puts("No");
	else if(4 * a * b < (c - a - b) * (c - a - b)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
from collections import defaultdict
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())

s = [0] * N

patterns = defaultdict(int)

for i in range(N):
    s[i] = input()

    list_string = list(s[i])
    list_string.sort()

    list_string = "".join(list_string)
    patterns[list_string] += 1

ans = 0
for p in patterns.values():
    if p >= 2:
        ans += comb(p, 2)

print(ans)


Measured memory_bytes: 111408
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define SUP INT_MAX
#define INF INT_MIN
#define SSUP LLONG_MAX
#define IINF LLONG_MIN
#define W while
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define all(v) v.begin(),v.end()
#define in insert
//#define For(i,n) for(ll i=0;i<n;i++)
//#define FOR(i,a,b) for(ll i=a;i<b;i++)
//#define Rev(i,n) for(ll i=n-1;i>=0;i--)
using namespace std;
const ll M = 1e9+7;
int main()
{
	/*#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif*/
	FIO
	ll k,n; cin>>k>>n;
	ll ar[n];
	ll dist[n];
	cin>>ar[0];
	for(ll i=1;i<n;i++){
	    cin>>ar[i];
	    dist[i]=abs(ar[i]-ar[i-1]);
	}
	dist[0]=ar[0]+k-ar[n-1];
	sort(dist,dist+n);
	ll sum = 0;
	for(ll i=0;i<n-1;i++){
	    sum+=dist[i];
	}
	cout<<sum<<"\n";
	return 0;
}

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

using namespace std;

#define int long long

bool cmp(pair <int, int> a, pair <int, int> b) {
    return a.first / (a.second + 1.0) > b.first / (b.second + 1.0);
}

int lul = 50;

void solve() {
    int n, t;
    cin >> n >> t;
    pair <int, int> a[n];
    for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
    sort(a, a + n, cmp);
    //for (int i = 0; i < n; ++i) cout << a[i].first << ' ' << a[i].second << '\n';
    int dp[n][lul];
    for (int i = 0; i < n; ++i) for (int j = 0; j < lul; ++j) dp[i][j] = t + 1;
    for (int i = 0; i < n; ++i) dp[i][0] = 0;
    dp[0][1] = min(dp[0][1], 1 + a[0].first + a[0].second);
    int id = n;
    for (int i = 1; i < n; ++i) {
        if (a[i].first == 0) {
            id = i;
            break;
        }
        for (int j = 0; j < lul; ++j) dp[i][j] = dp[i - 1][j];
        for (int j = 0; j < lul - 1; ++j) {
            if (dp[i - 1][j] <= t) dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + 1 + a[i].first * (dp[i - 1][j] + 1) + a[i].second);
        }
    }
    vector <int> lol;
    for (int i = id; i < n; ++i) lol.push_back(a[i].second);
    sort(lol.begin(), lol.end());
    int ans = 0;
    for (int i = 0; i < lul; ++i) {
        if (dp[id - 1][i] <= t) {
            int val = i, tt = dp[id - 1][i];
            //cout << val << ' ' << tt << ' ' << i << '\n';
            for (int j = 0; j < lol.size(); ++j) {
                if (1 + lol[j] + tt > t) break;
                ++val;
                tt += lol[j] + 1;
            }
            //cout << val << '\n';
            ans = max(ans, val);
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 83700