akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <stack>
using namespace std;

#define SEC_NUM 8
#define NIL -1

bool fullX[SEC_NUM];
bool fullY[SEC_NUM];
bool fullDiagPos[SEC_NUM * 2 - 1];
bool fullDiagNeg[SEC_NUM * 2 - 1];

stack<pair<int, int>> S;

void init(){
    for(int i = 0; i < SEC_NUM; i++){
        fullX[i] = false;
        fullY[i] = false;
        fullDiagPos[i] = false;
        fullDiagNeg[i] = false;
    }
}

void setQueen(int x, int y){
   fullX[x] = true;
   fullY[y] = true;
   fullDiagPos[x + y] = true;
   fullDiagNeg[x - y + SEC_NUM] = true;
}

void removeQueen(int x, int y){
   fullX[x] = false;
   fullY[y] = false;
   fullDiagPos[x + y] = false;
   fullDiagNeg[x - y + SEC_NUM] = false;
}

bool canPutQueen(int x, int y){
    if(!fullX[x] && !fullY[y] && !fullDiagPos[x + y] && !fullDiagNeg[x - y + SEC_NUM])
        return true;
    return false;
}

int getNextX(int x){
    x++;
    while(x < SEC_NUM){
        if(!fullX[x]){
            return x;
        }
        x++;
    }
    return NIL;
}

int getNextY(int x, int y){
    y++;
    while(y < SEC_NUM){
        if(canPutQueen(x, y)){
            return y;
        }
        y++;
    }
    return NIL;
}

void output(stack<pair<int,int>> S){
    char Queen[SEC_NUM][SEC_NUM];
    for(int i = 0; i < SEC_NUM; i++){
        for(int j = 0; j < SEC_NUM; j++){
            Queen[i][j] = '.';
        }
    }
    
    while(!S.empty()){
        pair<int, int> p = S.top(); S.pop();
        Queen[p.first][p.second] = 'Q';
    }

    for(int i = 0; i < SEC_NUM; i++){
        for(int j = 0; j < SEC_NUM; j++){
            printf("%c", Queen[i][j]);
        }
        printf("\n");
    }
 
}

int main(void){
    init();

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

    for(int i = 0; i < n; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        setQueen(x, y);
        S.push(make_pair(x, y));
    }

    int x = -1;
    int y = -1;
    while((x = getNextX(x)) != -1){
        y = -1;
        while(true){
            y = getNextY(x, y);
            if(y != -1){
                S.push(make_pair(x, y));
                setQueen(x, y);
                break;
            }else{
                pair<int,int> before_pair = S.top(); S.pop();
                x = before_pair.first;
                y = before_pair.second;
                removeQueen(x, y);
                continue;
            }
        }
    }

    output(S);
}




Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

int main()
{
    int N;
    cin >> N;
    cout << N * (N + 1) / 2 << "\n";
}

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

int main() {
  string s, t;
  cin >> s >> t;
  
  int cnt = 0;
  for(int i=0; i<s.size(); i++) if(s[i]!=t[i]) cnt++;
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3840
// Last Change: 06/10/2019 18:56:07.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

const ll MOD = 1e9 + 7;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> dp(N + 1, -1);

  ll ipt;
  for (ll i = 0; i < M; ++i) {
    cin >> ipt;
    dp[ipt] = 0;
  }

  dp[0] = 1;
  if (dp[1] == -1) {
    dp[1] = 1;
  }

  for (ll i = 2; i < N + 1; ++i) {
    if (dp[i] == -1) {
      dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    }
  }

  cout << dp[N] << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	char tmp[10];
	int n;
	int data0[10],data1[10];
	for(int i=0;i<10;i++){
		data0[i]=0;
		data1[i]=0;
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>tmp;
		for(int j=0;j<8;j++){
			data0[ tmp[j] -'0']++;
			data1[ tmp[j] -'0']++;
		}
		int max = 0;
		int min = 0;
		int rate = 10000000;
		for(int j=9;j>=0;j--){
			while(data0[j]) max += rate * j,data0[j]--,rate/=10;
		}
		rate = 10000000;
		for(int j=0;j<10;j++){
			while(data1[j]) min += rate * j,data1[j]--,rate/=10;
		}
		cout<<max-min<<endl;
	}
	return 0;
}

/*
Sample Input
2
65539010
65539010
Output for the Sample Input
96417531
96417531
*/

Measured memory_bytes: 1164
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int x;
	cin >> x;
	if (x >= 30)
		cout << "Yes";
	else
		cout << "No";
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
#define PI  3.14159265358979323846264338327950
 
int keta (long long num){
    int a = 0;
    while(num>0){
        num /=10;
        a +=1;
    }
    return a;
}

int main () {

    long long N;
    cin >> N;

    int ans = keta(N);
  
    for(int i=1; i <= sqrt( N); i++){
        if( N%i != 0)continue;

        int F = max(keta(i),keta(N/i));
        ans = min(ans,F);
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7


def bingo(c):
    for i in range(3):
        flag = [False for _ in range(3)]
        for j in range(3):
            if c[i][j]:
                flag[j] = True
        if flag[0] and flag[1] and flag[2]:
            return True
    for i in range(3):
        flag = [False for _ in range(3)]
        for j in range(3):
            if c[j][i]:
                flag[j] = True
        if flag[0] and flag[1] and flag[2]:
            return True
    flag = [False for _ in range(3)]
    for i in range(3):
        if c[i][i]:
            flag[i] = True
    if flag[0] and flag[1] and flag[2]:
        return True
    flag = [False for _ in range(3)]
    for i in range(3):
        if c[i][2-i]:
            flag[i] = True
    if flag[0] and flag[1] and flag[2]:
        return True
    return False


a = [LIST() for _ in range(3)]
c = [[0 for _ in range(3)] for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    d = -1
    e = -1
    for i in range(3):
        if b in a[i]:
            d = i
            e = a[i].index(b)
    if d != -1:
        c[d][e] = 1
    if bingo(c):
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 60012
#include<bits/stdc++.h>
#include <sstream>
#define pi 3.1416
using namespace std;
/*double Convert(double radian)
{
    return(radian*(180/pi));
}*/
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b;
}






Measured memory_bytes: 256
#include <stdio.h>
 

int main(void) {
    long long a,b,c;
    
    scanf("%lld%lld%lld", &a, &b, &c);

    if(a+b < c && 4*a*b < (c-a-b)*(c-a-b)){
        printf("Yes\n");
    }
    else printf("No\n");
    
    
    return 0;
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
   ll n;cin >>n;
   if(n%2==1){
       cout <<0<<endl;
   }
   if(n%2==0){
       ll ans=0;
       while(n>=10){
           n/=5;
           ans+=n/2;
       }
       cout <<ans <<endl;
   }
    return 0;
}

Measured memory_bytes: 256
import bisect
import random
import sys

input = sys.stdin.readline


class score:
    def __init__(self, t):
        self.t = t

    def first_score(self):
        last = [0]*26
        score = 0
        for i,ti in enumerate(self.t):
            score += S[i][ti - 1]
            last[ti-1] = i + 1
            for j in range(26):
                score -= C[j] * ((i+1) - last[j])
        self.score = score
        return score


D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]

#T = [int(input()) for i in range(D)]
T = []
for i in range(D):
    T.append(int(input()))
    s = score(T)
    print(s.first_score())

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

#define M 1046527

int charToValue(char c) {
    if (c == 'A') return 1;
    else if (c == 'C') return 2;
    else if (c == 'G') return 3;
    else if (c == 'T') return 4;
    else return 0;
}

long long getKey(string target) {
    long long sum = 0;
    long long p = 1;
    for (int i = 0; i < target.length(); i++) {
        sum += p * charToValue(target[i]);
        p *= 4;
    }

    return sum;
}

int h1(long long key) {
    return key % M;
}

int h2(long long key) {
    return 1 + key % (M - 1);
}

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

    string dict[M];
    for (int i = 0; i < M; i++) {
        dict[i] = "";
    }

    string command;
    string target;
    long long keySeed;
    int key;
    for (int i = 0; i < n; i++) {
        cin >> command;
        cin >> target;

        keySeed = getKey(target);
        key = h1(keySeed);
        if (command == "insert") {
            int j = 1;
            while (dict[key] != "") {
                key = (h1(keySeed) + (j * h2(keySeed))) % M;
                j++;
            }
            dict[key] = target;
        } else {
            int j = 1;
            bool find = false;
            while (dict[key] != "") {
                if (dict[key] == target) {
                    find = true;
                    break;
                }
                key = (h1(keySeed) + (j * h2(keySeed))) % M;
                j++;
            }

            if(find) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 42908
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//以下、素集合と木は同じものを表す
class UnionFind{
public:
    vector<ll> parent; //parent[i]はiの親
    vector<ll> siz; //素集合のサイズを表す配列(1で初期化)
    map<ll,vector<ll>> group; //集合ごとに管理する(key:集合の代表元、value:集合の要素の配列)
    ll n; //要素数

    //コンストラクタ
    UnionFind(ll n_):n(n_),parent(n_),siz(n_,1){ 
        //全ての要素の根が自身であるとして初期化
        for(ll i=0;i<n;i++){parent[i]=i;}
    }

    //データxの属する木の根を取得(経路圧縮も行う)
    ll root(ll x){
        if(parent[x]==x) return x;
        return parent[x]=root(parent[x]);//代入式の値は代入した変数の値なので、経路圧縮できる
    }

    //xとyの木を併合
    void unite(ll x,ll y){
        ll rx=root(x);//xの根
        ll ry=root(y);//yの根
        if(rx==ry) return;//同じ木にある時
        //小さい集合を大きい集合へと併合(ry→rxへ併合)
        if(siz[rx]<siz[ry]) swap(rx,ry);
        siz[rx]+=siz[ry];
        parent[ry]=rx;//xとyが同じ木にない時はyの根ryをxの根rxにつける
    }

    //xとyが属する木が同じかを判定
    bool same(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        return rx==ry;
    }

    //xの素集合のサイズを取得
    ll size(ll x){
        return siz[root(x)];
    }

    //素集合をそれぞれグループ化
    void grouping(){
        //経路圧縮を先に行う
        REP(i,n)root(i);
        //mapで管理する(デフォルト構築を利用)
        REP(i,n)group[parent[i]].PB(i);
    }

    //素集合系を削除して初期化
    void clear(){
        REP(i,n){parent[i]=i;}
        siz=vector<ll>(n,1);
        group.clear();
    }
};

signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n,m;cin>>n>>m;
    UnionFind uf(n);
    REP(i,m){
        ll a,b;cin>>a>>b;
        uf.unite(a-1,b-1);
    }
    uf.grouping();
    cout<<SIZE(uf.group)-1<<endl;

}

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

int main()
{
  int N;
  cin >> N;
  int k = 2;
  while (1)
  {
    int now = k * (k - 1) / 2;
    if (now == N)
    {
      break;
    }
    if (now < N)
    {
      k++;
    }
    else
    {
      k = 0;
      break;
    }
  }
  if (!k)
  {
    cout << "No" << endl;
    return 0;
  }
  vector<vector<bool>> table(N + 1, vector<bool>(k + 1, false));
  int index = 1;
  for (int i = 1; i <= k; i++)
  {
    for (int j = i + 1; j <= k; j++)
    {
      table.at(index).at(i) = true;
      table.at(index).at(j) = true;
      index++;
    }
  }
  cout << "Yes" << endl;
  cout << k << endl;
  for (int i = 1; i <= k; i++)
  {
    vector<int> tmp;
    for (int index = 1; index <= N; index++)
    {
      if (table.at(index).at(i))
      {
        tmp.push_back(index);
      }
    }
    cout << tmp.size();
    for (int j = 0; j < tmp.size(); j++)
    {
      cout << " " << tmp.at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 11520
#include<iostream>
using namespace std;
 
int main(){
    int time, h, m, s;

    cin >> time;
    h = time / 3600;
    m = time % 3600 / 60;
    s = time % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;		 
}



Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = Cin<int>();
        int a = Cin<int>();
        int b = Cin<int>();
        
        Console.WriteLine(Math.Min(a,b) +" " + Math.Max(0,(a+b)-N));
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)(-1);
    }
    public static T Line<T>()
    {
        if (typeof(T) == typeof(int[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        else if (typeof(T) == typeof(long[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        else if (typeof(T) == typeof(string[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').ToArray();
        }
        else if (typeof(T) == typeof(double[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
        else return (T)(object)(-1);
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;


public class Main {

	private static Scanner sc = new Scanner(System.in);

	
	public static void main(String[] argv){
		new Main().cal();
	}
	
	private void cal(){
		
		
		for(;;){
		int w=sc.nextInt();
		int h=sc.nextInt();
		
		if(w==0 && h==0)
				break;	
		
		int[][] map=new int[h][w];
		boolean[][] checked=new boolean[h][w];
		int count=0;
		
		for(int i=0;i<map.length;i++) 
			for(int j=0;j<map[0].length;j++)
				map[i][j]=sc.nextInt();
		
		for(int i=0;i<map.length;i++)
			for(int j=0;j<map[0].length;j++){
				if(checked[i][j])
					continue;
				else{
					count+=add(map,checked,i,j);
				}
					
			}
		
			System.out.println(count);
		
		}
		
	}
	
	private int add(int[][] map,boolean[][] checked,int i, int j){
	    if(i>=0 && i<map.length && j>=0 && j<map[0].length && map[i][j]==1 && !checked[i][j]){
		
			checked[i][j]=true;
			add(map,checked,i+1,j);
			add(map,checked,i,j+1);
			add(map,checked,i-1,j);
			add(map,checked,i,j-1);
			add(map,checked,i+1,j+1);
			add(map,checked,i+1,j-1);
			add(map,checked,i-1,j+1);
			add(map,checked,i-1,j-1);
			return 1;
		}
		return 0;
		
			
			
	}
	
}

Measured memory_bytes: 13000
import math

n = int(input())
index=1
minS=10**5
while index < n//2+1:
    a = str(index)
    b = str(n-index)
    listA= list(a)
    listB= list(b)
    sum =0
    index2 =0
    while index2 < len(listA):
        sum+=int(listA[index2])
        index2+=1
    index3 =0
    while index3 < len(listB):
        sum+=int(listB[index3])
        index3+=1
    if sum < minS:
        minS = sum
    index+=1
print(minS)

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

T = [int(x) for x in input().split()]

total = sum(T)

M = int(input())

PX = []
for i in range(M):
  p,x = map(int,input().split())
  PX.append((p,x))
  
for j in PX:
  print(total-T[j[0]-1]+j[1])

Measured memory_bytes: 3064
n, k = map(int, input().split())
mod = pow(10, 9) + 7
c1, c2 = 1, 1
n1, n2 = n, n - 1
ans = 1
for r in range(1, min(k + 1, n)):
    c1 = (c1 * n1 * pow(r, mod - 2, mod)) % mod
    c2 = (c2 * n2 * pow(r, mod - 2, mod)) % mod
    n1 -= 1
    n2 -= 1
    ans += (c1 * c2) % mod
    ans %= mod
print(ans)

Measured memory_bytes: 73324
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve2(sc: => Scanner, x: Int, y: Int, n: Int): Boolean = {
    if (n == 0) (true) else {
      val x_, y_ = sc.nextInt
      if ((x_ <= x && x < y_) || (x_ < y && y <= y_) || (x <= x_ && x_ < y) || (x < y_ && y_ <= y)) {
        false
      } else (solve2(sc, x, y, n - 1))
    }
  }

  def solve(sc: => Scanner) = {
    val x, y, n = sc.nextInt
    if (solve2(sc, x, y, n)) (println(0)) else (println(1))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}




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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> abc(n, vector<int>(3));
  rep(i, n) {
    cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
  }
  vector<vector<int>> dp(n+1, vector<int>(3));

  rep(i, n) {
    rep(j, 3) {
      rep(k, 3) {
        if(j == k) continue;
        dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abc[i][k]);
      }
    }
  }
  int ans = max({dp[n][0], dp[n][1], dp[n][2]});
  cout << ans << endl;
  return 0;
}


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

int main(void){
    int N;
    cin >> N;
    long last = 10000000001;
    int count = -1;
    int max_count = 0;
    for(int i=0; i<N; i++) {
        long x;
        cin >> x;
        if(last>=x) {
            count += 1;
        }else {
            //途切れた
            max_count = max(max_count, count);
            count = 0;
        }
        last = x;
    }
    if(max_count < count) max_count = count;
    cout << max_count << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

def solve(n, a, b, c, q, k, x, y):
    E = {}
    G = {}
    for u, v, d in zip(a, b, c):
        if not u in E:
            E[u] = []
        if not v in E:
            E[v] = []
        E[u].append(v)
        E[v].append(u)
        G[u, v] = d
        G[v, u] = d
    dist = {}
    dist[k] = 0
    que = deque([k])
    while que:
        v = que.pop()
        for u in E[v]:
            if not u in dist:
                dist[u] = dist[v] + G[u,v]
                que.append(u)
    for i in range(q):
        print(dist[x[i]] + dist[y[i]])

n = int(input())
a = [0] * (n-1)
b = [0] * (n-1)
c = [0] * (n-1)
for i in range(n-1):
    a[i], b[i], c[i] = map(int, input().split())
q, k = map(int, input().split())
x = [0] * q
y = [0] * q
for i in range(q):
    x[i], y[i] = map(int, input().split())
solve(n, a, b, c, q, k, x, y)

Measured memory_bytes: 83028
import sys,os
import math
from fractions import Fraction 
from collections import defaultdict
from random import randint

# sys.stderr=open('err.txt','w')
# sys.stdout=open('output.txt','w')
# sys.stdin=open('input.txt','r')

def linput():
    return list(minput())

def minput():
    return map(int, sys.stdin.readline().strip().split())

###############################################################

n=int(input())
a=linput()

ans,s=0,0
mod=10**9+7
for i in a:
    s=(s+i)%mod
now=0
for i in a:
    now+=i
    cur=(s-now)%mod
    ans=(ans+(i*(cur))%mod)%mod
print(ans)


Measured memory_bytes: 33740
N,K=map(int,input().split())
d=[] 
A=[] 
A_union=[]
U=[i for i in range(1,N+1)]

for i in range(K): 
    d.append(int(input())) 
    A.append(list(map(int,input().split()))) 
for j in range(K): 
    A_union+=A[j] 
print(len(set(U)-set(A_union)))

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	string s;
	cin>>s;
	cout<<s.substr(0,5) << " "<<s.substr(6,7)<<" "<<s.substr(14,5)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll a[10000005];
int main()
{
    ll r=1,n,i,sum=0,ma=0,flag=0,ans=1,x,b,flag2=0;
    scanf("%lld",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]==0)
        {
            flag=1;
        }
    }
    ll nu3=0;
    for(i=1; i<=n; i++)
    {
        ll y1=a[i],nu1=-1,y2=ans,nu2=-1;
        while(y1)
        {
            y1/=10;
            nu1++;
        }
        while(y2)
        {
            y2/=10;
            nu2++;
        }
        if(flag==1)
        {
            ans=0;
            break;
        }
        nu3+=nu1+nu2;
        if(nu3>18&&flag==0)
        {
            ans=-1;//printf("*%lld %lld\n",nu1,nu2);
            break;
        }
    }
    if(ans>0)
    {
        if(nu3<18)
        {
            for(i=1; i<=n; i++)
            {
                ans*=a[i];
                if(ans>1000000000000000000&&flag==0)
                {
                    ans=-1;
                    break;
                }
            }
        }
        if(nu3==18&&flag==0)
        {
            for(i=1; i<=n; i++)
            {
                ans*=a[i];
            }
            if(ans!=1000000000000000000)
            {
                ans=-1;
            }
        }
    }

    printf("%lld\n",ans);
}


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

using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void chmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  ll a, b;
  ll v, w, t;
  cin >> a >> v >> b >> w >> t;
  
  bool c;
  
  if(a < b){
    if(a+v*t >= b+w*t)
      c = true;
    else
      c = false;
  }
  else{
    if(a-v*t <= b-w*t)
      c = true;
    else
      c = false;
  }
  
  if(c)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
  
}

Measured memory_bytes: 3636
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

long n, m;
bool pos[100005];
long num[100005];

int main(){
	scanf("%ld%ld", &n, &m);
	pos[1] = true;
	for(int i = 1; i <= n; i++){
		num[i] = 1;
	}
	/*
	printf("  ");
	for(int i = 1; i <= n; i++){
		printf("%d ", pos[i]);
	}
	printf("\n  ");
	for(int i = 1; i <= n; i++){
		printf("%d ", num[i]);
	}
	printf("\n");
	//*/
	for(int i = 0; i < m; i++){
		long x, y;
		scanf("%ld%ld", &x, &y);
		num[x]--;
		num[y]++;
		if(pos[x] == true){
			if(num[x] == 0){
				pos[y] = true;
				pos[x] = false;
			}else{
				pos[y] = true;
			}
		}
		/*
		printf("  ");
		for(int i = 1; i <= n; i++){
			printf("%d ", pos[i]);
		}
		printf("\n  ");
		for(int i = 1; i <= n; i++){
			printf("%d ", num[i]);
		}
		printf("\n");
		//+*/
	}
	long ans = 0;
	for(int i = 1; i <= n; i++){
		if(pos[i]){
			ans++;
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 1152
N, M = map(int, input().split())
 
if M == 0:
    print(0)
    exit()
    
es = [[] for i in range(M+1)]
for i in range(M):
    a, b = map(int, input().split())
    a,b = a-1, b-1
    es[a].append(b)
    es[b].append(a)

def dfs(v, visited, es, cnt):
 
    #print("--------------")
    #print((v, visited, cnt))
 
    if cnt == N-1:
        return 1
    ret = 0
    for i in es[v]:
        if visited[i] == True:
            continue
 
        visited[i] = True
        ret += dfs(i, visited, es, cnt+1)
        visited[i] = False
 
    return ret
 
visited = [False] * N
visited[0] = True
 
ans = dfs(0,visited,es,0)
print(ans)

Measured memory_bytes: 41564
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,d,e;
	cin>>a>>b;
	vector<int> c(b,0);
for(int i=0;i<a;i++){
   cin>>d;
   for(int j=0;j<d;j++){
      cin>>e;
      c.at(e-1)++;
   }
}
int count;
for(int i=0;i<b;i++){
   if(c.at(i)==a)
   	count++;
}
cout<<count<<endl;
}

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

const int N = 1e5 + 5;

long long dp[N];
int n, k;
int arr[N];

void read() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
}

long long work() {
  dp[n] = 0;
  for (int i = n - 1; i >= 1; i--) {
    dp[i] = 4e18;
    for (int j = 1; j <= k && i + j <= n; j++)
      dp[i] = min(dp[i], dp[i + j] + abs(arr[i] - arr[i + j]));
  }
  return dp[1];
}

int main() {
  read();
  cout << work() << endl;
  return 0;
}

Measured memory_bytes: 1408
def solve():
  s = input()
  n  = len(s)
  mod = 10**9+7
  reverses = s[::-1]
  
  query = [0 for i in range(13)]
  if reverses[0] != "?":
    tmp = int(reverses[0])
    query = [0 for i in range(13)]
    query[tmp] += 1
  else:
    for i in range(10):
      query[i] += 1
  digit = 1
  
  for i in range(1,n):
    digit *= 10
    digit %= 13
    tmp = [0 for _ in range(13)]
    
    if reverses[i] =="?":
      for k in range(10):
        for j in range(13):
          num = k*digit
          num += j
          num %= 13
          tmp[num] += query[j]
      
    else:
      for j in range(13):
        num = digit*int(reverses[i])
        num += j
        num %= 13
        tmp[num] += query[j]

    for i in range(13):
      tmp[i] %= mod
    query = tmp 
      
  print(query[5])
solve()

Measured memory_bytes: 43244
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	string S;
	int num[26];
	cin >> S;
	fill(num, num + 26, 0);
	for(int i = 0; i < S.length(); i++){
		num[S[i] - 'a']++;
	}
	bool flag = true;
	for(int i = 0; i < 26; i++){
		if(num[i] == 0) flag = false;
	}
	if(S == "zyxwvutsrqponmlkjihgfedcba"){
		cout << -1 << endl;
		return 0;
	}
	else if(flag){
		for(int i = S.length() - 1; i >= 0; i--){
			bool flag2 = false;
			char ch = S[i];
			for(int j = i + 1; j < S.length(); j++){
				if(S[j] > S[i]){
					flag2 = true;
					if(flag2 && ch > S[j]) ch = S[j];
					else ch = S[j];
				}
			}
			if(flag2){
				S[i] = ch;
				cout << S.substr(0, i + 1) << endl;
				return 0;
			}
		}
	}else{
		for(int i = 0; i < 26; i++){
			if(num[i] == 0){
				S += 'a' + i;
				cout << S << endl;
				return 0;
			}
		}
	}
	return 0;
}

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

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

int main(int argc, char const *argv[])
{
	string s; cin >> s;
	s[3] = '8';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
# Aizu Problem ITP_1_5_C: Print a Chessboard
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


pattern = '#.' * 150

while True:
    H, W = [int(_) for _ in input().split()]
    if H == W == 0:
        break
    for row in range(H):
        print(pattern[:W] if row % 2 == 0 else pattern[1:W+1])
    print()

Measured memory_bytes: 7712
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
	int n,s=0;
	vector<int>v;
	cin>>n;
	r(i,n){
		int x;
		cin>>x;
		if(x%2)v.push_back(x);
		s+=x;
	}
	sort(v.begin(),v.end());
	if(v.size()%2)s-=v[0];
	cout<<s/2<<endl;
}


Measured memory_bytes: 3156
n = gets.to_i
ans = 0;
for i in 1..n do
	if(i % 2 != 0)then
		cnt = 0;
		for j in 1..i do
			if(i % j == 0)then
				cnt += 1;
			end
		end
		if(cnt == 8)then
			ans += 1;
		end
	end
end
puts ans


Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, Z, W;
  cin >> N >> Z >> W;
  vl A(N, 0);
  REP(i, N) cin >> A[i];
  ll kouho1 = abs(A[N - 1] - W);
  ll kouho2 = -llINF;
  if (N >= 2) {
    kouho2 = abs(A[N - 2] - A[N - 1]);
  }
  cout << max(kouho1, kouho2) << endl;

  return 0;
}


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

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

string s;
int K;
int len;

LL dp[101][2][4];

LL solve(int i, int res, int k) {
	if(i == len - 1) {
		if(k >= 2) {
			return 0;
		}
		else if(k == 1) {
			int maxD = res == 1? s[i]-'0' : 9;
			if(res == 1) {
				if(maxD == 0) {
					return 0;
				} else {
					return maxD;
				}
			} else {
				return 9;
			}
		}
		else {
			return 1;
		}
	}
	if(k == 0) {
		return 1;
	}

	LL &ret = dp[i][res][k];
	if(ret != -1) {
		return ret;
	}
	
	ret = 0;
	int maxD = res == 1? s[i]-'0' : 9;
	for(int d=0;d<=maxD;d++) {
		if(res == 0) {
			if(d == 0) {
				ret = ret + solve(i+1, 0, k);
			} else {
				ret = ret + solve(i+1, 0, k-1);
			}
		} else {
			if(maxD == 0) {
				ret = ret + solve(i+1, 1, k);
			} else {
				if(d == 0) {
					ret = ret + solve(i+1, 0, k);
				}
				else if(d == maxD) {
					ret = ret + solve(i+1, 1, k-1);
				}
				else {
					ret = ret + solve(i+1, 0, k-1);
				}
			}
		}
		// trace(i, res, k, maxD, d, ret);
	}
	return ret;
}

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

	memset(dp, -1, sizeof(dp));
	LL ans = solve(0, 1, K);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3580
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
    
def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B, C, D = map(int, input().split())
target = B - A + 1

hoge1 = B // C - (A - 1) // C
hoge2 = B // D - (A - 1) // D
hoge3 = B // (C * D) - (A - 1) // (C * D)

saisho = lcm(C, D)
hoge4 = B // saisho - (A - 1) // saisho

print(target - hoge1 - hoge2 + hoge4)

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


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


def main():
    N, M = map(int, input().split())
    E = []
    for i in range(M):
        a, b = map(int, input().split())
        E.append((a-1, b-1))

    ans = 0
    # i 番目の辺を取り除いても、全ての頂点が連結しているか？
    # Union-Find で連結グラフか判定する
    for i in range(M):
        uf = UnionFind(N) # 最初、全ての頂点が非連結の状態
        for j in range(M):
            if i == j:
                pass # i 番目の辺を無視する
            else:
                # 要素が同じ集合にある＝頂点が連結している
                uf.union(E[j][0], E[j][1])
        # グラフ全体が連結なら、任意の頂点を含む集合のサイズが N のはず
        if uf.size(0) != N:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define long long int
signed main()
{
	string s;
	while(cin>>s)
	{
		map<char,int> m;
		for(int i=0;i<3;i++) m[s[i]]++;
		if(m.size()==1) cout<<"No\n";
		else cout<<"Yes\n";
	}
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N;
    cin>>N;
    int64 sum=0;
    int64 tmp1,tmp2;

    vector<int64> W(N);

    for(int64 i=0;i<N;i++){
        cin>>W[i];
        sum+=W[i];
    }


    for(int64 i=0;i<N;i++){
        sum-=W[i]*2;
        if(sum<=0){
            tmp2=sum;
            break;
        }
        tmp1=sum;
    }

    cout<<min(tmp1,(-1)*tmp2)<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <limits>
#include <thread>
#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <list>
#include <functional>
#include <bitset>
#include <complex>
#include <tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;
typedef complex<D> P;
const ll E = 1e18 + 7;
const ll MOD = 1000000007;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fill(x, y) memset(x, y, sizeof(x))
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
template <class... A>
void prints() { cout << endl; }
template <class... A>
void prints_rest() { cout << endl; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

template <class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

    int N, M, S, T;
    cin >> N >> M;
    vector<vector<int>> E;
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        vector<int> e;
        e.push_back(u-1);
        e.push_back(v-1);
        E.push_back(e);
    }
    cin >> S >> T;
    S--;T--;

    vector<int> cost_ken1(N, __INT_MAX__ - 2), cost_ken2(N, __INT_MAX__ -2 ), cost_pa(N, __INT_MAX__-2);
    cost_pa[S] = 0;

    rep (_, 100) {
        rep(i, M) {
            vector<int> e = E[i];
            cost_ken1[e[1]] = min(cost_ken1[e[1]], cost_pa[e[0]]+1);
            cost_ken2[e[1]] = min(cost_ken2[e[1]], cost_ken1[e[0]]+1);
            cost_pa[e[1]] = min(cost_pa[e[1]], cost_ken2[e[0]]+1);
        }
    }

    if (cost_pa[T] == __INT_MAX__-2) {
        prints(-1);
    } else {
        prints(cost_pa[T] / 3);
    }

    return 0;
}



Measured memory_bytes: 8624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String s = sc.next();
    if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 20944
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi d(n);
  rep(i,n)cin>>d[i];
  int m=1000000;
  vector<bool> v(m,false);
  rep(i,n){
    ll tmp=0;
    for(j=i;j<n;j++){
      tmp*=10;
      tmp+=d[j];
      if(tmp>=m)break;
      v[tmp]=true;
    }
  }
  rep(i,m)if(v[i]==0){
    cout<<i<<endl;
    return 0;
  }
}

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

using Graph = vector< vector<int> >;

vector<int> length_min;
vector<bool> seen;

void bfs(Graph& graph) {
    queue<int> que;
    que.push(0);

    while(!que.empty()) {
        int s = que.front();
        que.pop();
        if(seen[s]) continue;

        for(auto v: graph[s]) {
            if(length_min[v] > length_min[s] + 1) {
                length_min[v] = length_min[s] + 1;
            }
            que.push(v);
        }

        seen[s] = true;
    }
}

int main() {
    int n, m;
    cin >> n >> m;

    Graph g(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    length_min.assign(n, n);
    length_min[0] = 0;
    seen.assign(n, false);

    bfs(g);

    vector<int> ans(n);
    for(int i = 1; i < n; i++) {
        bool ok = false;
        for(auto v : g[i]) {
            if(length_min[i] == length_min[v] + 1) {
                ans[i] = v + 1;
                ok = true;
                break;
            }
        }
        if(!ok) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for(int i = 1; i < n; i++) cout << ans[i] << endl;

    // for(auto v : length_min) cout << v << endl;

    return 0;
}


Measured memory_bytes: 10924
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf INT_MAX
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}

int main(void){
	long long n=llin(),m=llin(),ans=1,t;
	if(abs(n-m)>1){
		puts("0");
	}
	else{
		t=(n+m)%2;
		while(n){
			ans=ans*n%mod;
			n--;
		}
		while(m){
			ans=ans*m%mod;
			m--;
		}
		if(!t){
			ans=ans*2%mod;
		}
		llprint(ans);
	}
	return 0;
}


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

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

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  vector<int> edges(n);
  REP(i,n) {
    cin >> edges[i];
  }
  ll ans = 0;
  SORT(edges);
  REPRS(a, 2, n-1) {
    REPRS(b, 1, a-1) {
      int thre = edges[a] - edges[b];
      int index = upper_bound(ALL(edges), thre) - edges.begin();
      ans += max(0,b-index);
    }
  }
  cout << ans;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void) {
	int iguti_yuka;
	int sakurai_takahiro[26] = {0};
	while ((iguti_yuka = getchar()) != EOF) {
		int kosimizu_ami = (tolower(iguti_yuka) - 'a');
		if (0 <= kosimizu_ami && kosimizu_ami < 26) sakurai_takahiro[kosimizu_ami]++;
	}
	for (iguti_yuka = 0; iguti_yuka < 26; iguti_yuka++) {
		printf("%c : %d\n", iguti_yuka + 'a', sakurai_takahiro[iguti_yuka]);
	}
	return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  string o,e;
  cin >> o >> e;
  string ans;
  rep(i,o.size()+e.size()+1){
    ans += '#';
  }
  rep(i,o.size()){
    ans[i * 2] = o[i];
  }
  rep(i,e.size()){
    ans[i * 2 + 1] = e[i];
  }
  rep(i,ans.size()){
    if(ans[i]=='#')return 0;
    cout << ans[i];
  }
}

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

int main() {
  int H1, H2, M1, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  cout << (H2*60 + M2 - H1*60-M1-K) << endl;
  
}


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

// #include<cstdio>

int main(){
  int a, b;
  char op;
  while(1){
    cin >> a >> op >> b;
    if (op=='?') break;
    if (op=='+') cout << a+b << "\n";
    if (op=='-') cout << a-b << "\n";
    if (op=='*') cout << a*b << "\n";
    if (op=='/') cout << a/b << "\n";
  }

  return 0;
}

Measured memory_bytes: 3112