akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            if (A + B >= C) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

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

Measured memory_bytes: 23380
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
	get_number(N),
    X is N div 2,
    Y is N - N div 2,
    Z is X * Y,
    writeln(Z).


Measured memory_bytes: 8124
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  ff     first
#define  ss     second
#define  pb     push_back
#define  all(x) (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  deb(x) cout << #x << " - " << x << "\n";
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)  cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; 
#define  D2p(x)	cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << "\n";
#define  ps(x,y) fixed<<setprecision(y)<<x
 
#define PI 3.141592653589793238462643383279502884L
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 1e5 + 2;

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

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long int ll;
const ll mod=1e9+7;
ll f[2006];
int main()
{
	ios;
	f[0]=1;
	for(int i=3;i<=2000;++i)
	for(int j=3;j<=i;++j)
	{
		f[i]=(f[i]+f[i-j])%mod;
	}
	int s;
	cin>>s;
	cout<<f[s]<<'\n';
}

Measured memory_bytes: 3664
private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

fun main(args: Array<String>) {
    val (N, K) = readInts()
    val A = readInts()
    val counts = A.groupBy { it }.mapValues { p -> p.value.size }.values.sorted()
    val toChange = counts.size - K
    println(if (toChange > 0) counts.take(toChange).sum() else 0)
}

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

int main()
{
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  int total = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    total += A[i];
  }
  string result = H <= total ? "Yes" : "No";
  cout << result << endl;
}

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

#define int long long
//typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif



signed main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> cnt(N+1,0);

    // cnt[i+1]: S[i]までの個数
    rep(i,N){
        if(i>0){
            if(S[i-1]=='A' && S[i]=='C')
                cnt[i+1] = cnt[i] + 1;
            else
                cnt[i+1] = cnt[i];
        }else
            cnt[i+1] = 0;
    }
    dump(cnt);
    while(Q--){
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << cnt[r+1] - cnt[l+1] << endl;
    }
}


Measured memory_bytes: 1792
package main

import "fmt"

func btcToYen(btc float64) float64 {
	return 380000.0 * btc
}

func main() {
	var n int
	fmt.Scan(&n)

	var x, sum float64
	var u string
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &u)
		if u == "BTC" {
			sum += x * 380000.0
		} else {
			sum += x
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//a^n mod p
ll repsq(ll a, ll n, ll p) {
  ll cnt = 1, b = a;
  while (b < p && cnt < n) {
    b *= a;
    cnt++;
  }
  if (b < p) return b;
  b %= p;
  ll c = pow(a, n % cnt);
  return repsq(b, n / cnt, p) * c % p;
}

//二項係数 mod p
ll modinv(ll n, ll p) {
  ll a = p, u = 1, v = 0;
  while (a) {
    ll t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

ll ncr(ll n, ll r, ll p) {
  r = min(r, n - r);
  ll ans = 1;
  for (ll i = 0; i < r; i++) {
    ans *= (n - i) % p;
    ans %= p;
  }
  for (ll i = 0; i < r; i++) {
    ans *= modinv(i + 1, p);
    ans %= p;
  }
  return ans;
}

int main() {
  ll n, a, b, p = 1000000007;
  cin >> n >> a >> b;

  ll ans = repsq(2, n, p) - 1;
  ll aa = ncr(n, a, p);
  ll bb = ncr(n, b, p);
  ans -= aa;
  if (ans < 0) ans += p;
  ans -= bb;
  if (ans < 0) ans += p;
  cout << ans << endl;
}

Measured memory_bytes: 256
#!python
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10**6)


next_s = ((-1, 1), (0, 1), (1, 1),
          (-1, 0), (1, 0),
          (-1, -1), (0, -1), (1, -1))


def DFS(x, y):
    if not (0 <= x < W and 0 <= y < H):
        return
    if map_[y][x] == 0:
        return

    map_[y][x] = 0

    for dx, dy in next_s:
        DFS(x + dx, y + dy)


while True:
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        break
    map_ = [list(map(int, input().split())) for h in range(H)]
    island_num = 0
    for x in range(W):
        for y in range(H):
            if map_[y][x] == 1:
                DFS(x, y)
                island_num += 1
    print(island_num)



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

int main() {
	int n;
	long long y;
	cin >> n >> y;
	int a,c;
	int b = 0;
	bool flag = 0;
	while (b<9) {
		long long new_y =y- b * 5000;
		int new_n = n - b;
		if ((new_y - 1000 * new_n) % 9000 == 0) {
			a = (new_y - 1000 * new_n )/ 9000;
			c = new_n - a;
			if (a >= 0 && c >= 0) {
				flag = 1;
				break;
			}
		}
		b++;
	}
	if (flag) {
		cout << a << ' ' << b << ' ' << c << endl;
	}
	else { cout << -1 << ' ' << -1 << ' ' << -1 << endl; }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N,i,j,cake=4,donuts=7,a=0,flag=0;
	scanf("%d",&N);
	for(i = 1; i < 26; i++){
		for(j = 1; j < 15; j++){
			a= (cake * i) + (donuts * j);
			if(N % 4 == 0){
				flag = 1;
				if(flag == 1){
					printf("Yes\n");
					return 0;
				}
			}
			else if(N % 7 == 0){
				flag = 1;
				if(flag == 1){
					printf("Yes\n");
					return 0;
				}
			}
			else if(N % a == 0){
				flag = 1;
				if(flag == 1){
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	printf("No\n");
	return 0;
}

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

const int maxN = 2e6 + 10;

int n, len, cnt, root;
int ch[maxN + 1][3], a[maxN + 1];
int rev[maxN + 1], pw[15], ans[maxN + 1];
char s[maxN + 1];

inline void reverse(int x) 
{ 
	if(!x) return;
	swap(ch[x][1], ch[x][2]);
	rev[x] ^= 1;
}

inline void pushdown(int x)
{
	if(!rev[x]) return;
	reverse(ch[x][0]);
	reverse(ch[x][1]);
	reverse(ch[x][2]);
	rev[x] = 0;
}

inline void insert(int &node, int x, int k)
{
	if(!node) node = ++ cnt;
	if(k == n) { a[node] = x; return; }
	int d = x / pw[k] % 3;	
	insert(ch[node][d], x, k + 1);
}

inline void change(int node)
{
	if(!node) return;
	pushdown(node);
	change(ch[node][2]);
	swap(ch[node][1], ch[node][2]); 
	swap(ch[node][0], ch[node][1]);
}

inline void dfs(int node, int k, int x)
{
	if(!node) return;
	if(k == n) { ans[ a[node] ] = x; return; }
	pushdown(node);
	dfs(ch[node][0], k + 1, x);
	dfs(ch[node][1], k + 1, x + pw[k]);
	dfs(ch[node][2], k + 1, x + 2 * pw[k]);
}

int main()
{
	scanf("%d", &n);
	scanf("%s", s + 1);
	len = strlen(s + 1);

	pw[0] = 1;
	for(int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 3;

	for(int i = 0; i < pw[n]; i++) insert(root, i, 0);

	for(int i = 1; i <= len; i++)
		if(s[i] == 'S') reverse(root);
		else change(root);

	dfs(root, 0, 0);
	
	for(int i = 0; i < pw[n]; i++) printf("%d ", ans[i]);
	puts("");
	return 0;
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            decimal iN = decimal.Parse(sS[0]);
            decimal iA = decimal.Parse(sS[1]);
            decimal iB = decimal.Parse(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            decimal iCnt = Math.Truncate(iN / (iA + iB));
            decimal iZan = Math.Truncate(iN % (iA + iB));
            decimal iOut = iCnt * iA;
            if (iZan > iA) { iOut += iA; }
            else { iOut += iZan; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString("0").Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i,j,num;
    int y=0;
    int trump[4][13]={0};
    char c;
    scanf("%d",&num);
    for(i=0;i<2*num;i++){
        scanf("%c %d",&c,&y);
        if(c=='S'){
            trump[0][y-1]=1;
        }else if(c=='H'){
            trump[1][y-1]=1;
        }else if(c=='C'){
            trump[2][y-1]=1;
        }else if(c=='D'){
            trump[3][y-1]=1;
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(trump[i][j]==0){
                switch(i){
                    case 0:
                        printf("S %d\n",j+1);
                        break;
                    case 1:
                        printf("H %d\n",j+1);
                        break;
                    case 2:
                        printf("C %d\n",j+1);
                        break;
                    case 3:
                        printf("D %d\n",j+1);
                        break;
                }
            }
        }
    }
    return 0;
}

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

int main()
{
	
	int a, b, c;
	char op;
		while (1){
			cin >> a >> op >> b;
			if (op == '+') {
				c = a + b;
			}
			
			else if (op == '-'){
				c = a - b;
			}else if (op == '/') {
				c = a / b;
			}else if (op == '*') {
				c = a * b;
			}else{
				break;
			}
			cout << c << endl;
		}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
  Scanner stdIn = new Scanner(System.in);
  while (stdIn.hasNextDouble()) {
   double x1 = stdIn.nextDouble();
   double y1 = stdIn.nextDouble();
   double x2 = stdIn.nextDouble();
   double y2 = stdIn.nextDouble();
   double x3 = stdIn.nextDouble();
   double y3 = stdIn.nextDouble();
   double x4 = (x1 + x2 + x3) / 3.0;
   double y4 = (y1 + y2 + y3) / 3.0;
   double px = stdIn.nextDouble();
   double py = stdIn.nextDouble();
   if (((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4))
     * ((x1 - x2) * (py - y1) + (y1 - y2) * (x1 - px)) > 0
     && ((x2 - x3) * (y4 - y2) + (y2 - y3) * (x2 - x4))
       * ((x2 - x3) * (py - y2) + (y2 - y3) * (x2 - px)) > 0
     && ((x3 - x1) * (y4 - y3) + (y3 - y1) * (x3 - x4))
       * ((x3 - x1) * (py - y3) + (y3 - y1) * (x3 - px)) > 0)
    System.out.println("YES");
   else {
    System.out.println("NO");
   }
  }
 }
}

Measured memory_bytes: 23276
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;
char a[200], b[200],c[200];

int main(){
	int x, a, b;
	while(~scanf("%d %d %d", &x, &a, &b)){
		int c = x - a;
		int d = c % b;
		printf("%d\n", d);
	}
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll a,b,x; cin >> a >> b >> x;
  ll l = (a+x-1)/x;
  ll r = b/x;
  cout << max(0LL,r - l + 1) << endl;
}



Measured memory_bytes: 3656
import sys
import Queue

d_num = int(sys.stdin.readline().strip())

graph_list = []

for _ in range(0, d_num):
    array = sys.stdin.readline().strip().split(" ")
    if len(array) <= 2:
        graph_list.append([])
    else:
        graph_list.append([int(array[i]) - 1 for i in range(2, len(array))])

result = [0 for _ in range(0, d_num)]
searched_list = []
queue = Queue.Queue()

queue.put((0, 0))
searched_list.append(0)
while not queue.empty():
    data = queue.get()
    node = data[0]
    d = data[1]
    children = filter(lambda x: x not in searched_list, graph_list[node])
    for c in children:
        queue.put((c, d + 1))
        searched_list.append(c)
        result[c] = d + 1

for i in range(0, len(result)):
    if (i != 0) and (result[i] == 0):
        print str(i + 1) + " " + str(-1)
    else:
        print str(i + 1) + " " + str(result[i])
            

Measured memory_bytes: 6984
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbg=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int n,cnt;
bool vis[100111],vis2[100111];
vector<int>con[100111];
int q[100111],qsz,deg[100111];
bool del[100111];
void dele(int x)
{
	del[x]=1;
	for(int i=0;i<con[x].size();i++)
	{
		if(!del[con[x][i]])
		{
			if(!vis[con[x][i]]&&(--deg[con[x][i]])==1)
			{
				q[qsz++]=con[x][i];
				vis[con[x][i]]=1;
			}
		}
	}
}
int main()
{
	geti(n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		getii(x,y);
		con[x].PB(y);
		con[y].PB(x);
		deg[x]++;
		deg[y]++;
	}
	cnt=n;
	for(int i=1;i<=n;i++)
	{
		if(con[i].size()==1)
		{
			q[qsz++]=i;
			vis[i]=1;
			cnt--;
		}
	}
	int qb=0;
	for(int i=0;i<qsz;i++)
	{
		int u=q[i];
		if(del[u])continue;
		del[u]=1;
		bool flag=0;
		for(int j=0;j<con[u].size();j++)
		{
			if(!del[con[u][j]])
			{
				flag=1;
				dele(con[u][j]);
			}
		}
		if(!flag)
		{
			puts("First");
			return 0;
		}
	}
	puts("Second");
	return 0;
}

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

#define TOUMAX 4
#define KAIMAX 3
#define ROOMMAX 10

int main(void)
{
	int n,x;
	int i,j,k;
	int cnt;

	while (1) {
		cin >> n;
		cin >> x;

		if ((n+x) == 0) {
			break;
		}
		else {
			cnt = 0;
			for (i=1; i<(n-1); i++) {
				for (j=(i+1); j<n; j++) {
					for (k=(j+1); k<=n; k++) {
						if ((i+j+k) == x) {
							cnt++;
						}
					}
				}
			}
			cout << cnt << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}
int main(){
    string s;
    cin >> s;
    int ans=0;
    rep(i,4){
        if(s[i]=='+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


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

int n, a[10], b[10], fac[10], c[10], id;
int ch;

int main() {
	cin >> n;
	fac[1] = 1;
	for (int i = 2; i <= n; i++) fac[i] = fac[i - 1] * i;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) c[i] = i + 1;
	//cout << fac[n] << '\n';
	for (int i = 0; i <= (fac[n]); i++) {
		//for (int j = 0; j < n; j++) cout << c[j] << ' ';
		//cout << '\n';
		if(ch) {
			if(ch == 1) {
				bool c1 = 1;
				for (int j = 0; j < n; j++) {
					if(c[j] != b[j]) c1 = 0;
				}
				if(c1) {
					cout << i - id;
					return 0;
				}
				next_permutation(c, c + n);
				continue;
			}
			bool c1 = 1;
			for (int j = 0; j < n; j++) {
				if(c[j] != a[j]) c1 = 0;
			}
			if(c1) {
				cout << i - id;
				return 0;
			}
			next_permutation(c, c + n);
			continue;
		}
		bool c1 = 1, c2 = 1;
		for (int j = 0; j < n; j++) {
			if(c[j] != a[j]) c1 = 0;
			if(c[j] != b[j]) c2 = 0;
		}
		if(c1) ch = 1, id = i;
		if(c2) ch = 2, id = i;
		//if(c1 || c2) cout << id << ' ';
		if(c1 && c2) return cout << 0, 0;
		next_permutation(c, c + n);
	}
	return 0;
}





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

#define F first
#define S second
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b){
	if (a == 0) return b;
	return gcd(b%a, a);
}

ll lcm(ll a, ll b){
	return (a/gcd(a, b))*b;
}

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

	string s;

	cin >> s;
	ll ans = 0;
	for(ll i=0;i<s.size();i++)
	{
		ll x = s[i] - '0';
		ans+=x;
	}

	if(ans%9 == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    int n; std::cin >> n;
    bool ans = true;
    for(int i=0; i<n; i++)
    {
        int temp;
        std::cin >> temp;
        if(temp%2==0 && (temp%3!=0 && temp%5!=0)) ans = false;
    }
    std::cout << ((ans)?"APPROVED\n":"DENIED\n");
    return 0;
}

Measured memory_bytes: 256
// abc131_b
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int N, L;
	cin >> N >> L;
	vector<int> vec;
	int min = abs(L), index = 0;
	vec.push_back(L);
	// optimum value
	for (int i = 1; i < N; i++) {
		int num = L	+ i;
		vec.push_back(num);
		if (abs(num) < min) {
			min = abs(num);
			index = i;
		}
	}

	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (i == index) {
			continue;
		}
		sum += vec[i];
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int abc[20];
    int a=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        abc[i]=a;
    }
    int sum=0;
    for(int j=0;j<n-2;j++){
        // a b c 
        // a < b && b < c 
        // c < b && b < a 
        // 
        if(abc[j]< abc[j+1] && abc[j+1]<abc[j+2]){
            sum +=1;
        }else if (abc[j+2]< abc[j+1] && abc[j+1]<abc[j]){
            sum +=1;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
S = input()
d,m = len(S)//2,len(S)%2
A = '01'*d+'0'*m
B = '10'*d+'1'*m
count_a = 0
count_b = 0
for s,a,b in zip(S,A,B):
    if s != a:
        count_a += 1
    if s != b:
        count_b += 1
print(min(count_a, count_b))
    


Measured memory_bytes: 3316
from collections import Counter

n = int(input())
s = [""]*n
for i in range(n):
    s[i] = input()
m = int(input())
t = [""]*m
for i in range(m):
    t[i] = input()
cnt_s = Counter(s)
cnt_t = Counter(t)
ans = [0]
cnt = 0
for i in range(len(cnt_s)):
    s_value = cnt_s.most_common()[i][0]
    s_count = cnt_s.most_common()[i][1]
    for j in range(len(cnt_t)):
        t_value = cnt_t.most_common()[j][0]
        t_count = cnt_t.most_common()[j][1]
        if s_value == t_value:
            ans.append(s_count-t_count)
            cnt = 1
            break
    if cnt == 0:
        ans.append(s_count)
    cnt = 0
print(max(ans))

Measured memory_bytes: 3316
#include<stdio.h>

int main(void) {
        int A, B;

        scanf("%d %d", &A, &B);

        if((int)(A % 3) == 0 || (int)(B % 3) == 0 || (int)((A + B) % 3) == 0)
                printf("Possible");
        else
                printf("Impossible");

        return 0;
}

Measured memory_bytes: 128
h,w=map(int,input().split())

m=[input() for i in range(h)]


cnt=[[1000000 for i in range(w)] for j in range(h)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(h):
    for x in range(w):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[h-1][w-1])

Measured memory_bytes: 3188
n,m = (int(i) for i in input().split())
(n,m) = sorted([n,m])
if n ==2 or m == 2:
  ans = 0
elif n == 1 and m > 2:
  ans = m-2
elif n == 1 and m == 1:
  ans = 1
else:
  ans = (n-2)*(m-2)
print(ans)

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

int main()
{
    ll x, y;
    cin >> x >> y;
    int cnt = 0;
    
    while(x <= y)
    {
        x *= 2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n){
        cin >> A[i];
    }
    vector<int> a(n);
    rep(i, n){
        if((i+1) % 2 == 0 || (i+1) == n){
            a[n-1] += A[i];
        }else{
            a[n-1] -= A[i];
        }
    }
    a[0] = 2*A[n-1] - a[n-1];
    rep(i, n-2){
        a[i+1] = 2*A[i] - a[i];
    }
    rep(i, n){
        cout << a[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <sstream>

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
const int mod = 2019;

int main() {
    int n, d; cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    
    rep (i, n) {
        rep (j, d) cin >> x[i][j];
    }
    
    int ans = 0;
    rep(i,n) rep(j, i) {
        int sq = 0;
        rep (k, d) {
            int s = x[i][k] - x[j][k];
            sq += s*s;
        }
        int s = sqrt(sq) + 0.5;
        if (s * s == sq) ans++;
    }
    cout << ans << endl;
}



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


int main(){
  int N;
  cin >> N;
  vector<int> A(N+1, 0);
  for(int ii=1; ii<=N; ii++){
    cin >> A[ii];
  }

  vector<int> B(N+1, 0);
  for(int ii=N; ii>0; ii--){
    int sum = 0;
    for(int jj=ii+ii; jj<=N; jj+=ii){
      sum += B[jj];
    }
    B[ii] = ((sum%2)==A[ii]) ? 0 : 1;
  }

  int M = 0;
  for(auto& b : B){
    M += b;
  }
  cout << M << endl;
  int add_space = false;
  for(int ii=1; ii<=N; ii++){
    if(B[ii]){
      if(add_space) cout << " ";
      cout << ii;
      add_space = true;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2560
def factors(z):
    ret = []
    for i in range(2, int(z**(1/2))+1):
        if z%i == 0:
            ret.append(i)
            while z%i == 0:
                z //= i
    if z != 1:
        ret.append(z)
    return ret

def eratosthenes(N):
    if N == 0:
        return []
    from collections import deque
    work = [True] * (N+1)
    work[0] = False
    work[1] = False
    ret = []
    for i in range(N+1):
        if work[i]:
            ret.append(i)
            for j in range(2* i, N+1, i):
                work[j] = False
    return ret

N = int( input())
A = [ int( input()) for _ in range(N+1)]
Primes = eratosthenes(N)
ANS = []
F = factors( abs(A[0]))
for f in F:
    if f >= N+1:
        Primes.append(f)
for p in Primes:
    if p >= N+1:
        check = 1
        for i in range(N+1): # f が恒等的に 0 であるかどうかのチェック
            if A[i]%p != 0:
                check = 0
                break
        if check == 1:
            ANS.append(p)
    else:
        poly = [0]*(p-1)
        for i in range(N+1): # フェルマーの小定理
            poly[(N-i)%(p-1)] = (poly[(N-i)%(p-1)] + A[i])%p
        check = 0
        if sum(poly) == 0 and A[N]%p == 0: # a_0 が 0 かつ、g が恒等的に 0 であることをチェックしている
            check = 1
        if check == 1:
            ANS.append(p)
for ans in ANS:
    print(ans)

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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = inputs[0];
        var k = inputs[1];

        // n = k * x + amari
        // n - (k * x) = amari (>0)
        var amari = n % k;

        var result = Math.Min(amari, Math.Abs(amari - k));

        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[200010];
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	ll ans=0,crr=0;
	rep(i,0,n){
		if(s[i]=='A')crr++;
		else if(s[i]=='B'&&s[i+1]=='C'){
			ans+=crr;
			i++;
		}else{
			crr=0;
		}
	}
	printf("%lld",ans);
}

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

int main() {
  ll n, d;
  cin >> n >> d;
  
  ll dd = d * d;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    
    ll di = x * x + y * y;
    if (di <= dd) {
      ans++;
      //cout << i << endl;
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int a[n][n];
  rep(i,n)rep(j,n) a[i][j]=MAX;
  rep(i,n) a[i][i]=0;
  while(m--) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    a[x][y]=1;
    a[y][x]=1;
  }
  ll ans=0;
  rep(x,n) {
    REP(y,x+1,n) {
      if(a[x][y]==MAX) continue;
      ll d[n][n];
      rep(i,n)rep(j,n) {
        if(P(i,j)==P(x,y)||P(j,i)==P(x,y)) d[i][j]=MAX;
        else d[i][j]=a[i][j];
      }
      rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      ll z=0;
      rep(i,n)rep(j,n) z=max(z,d[i][j]);
      if(z==MAX) ans++;
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x,y,z) for(int i=0;i<(n);i++) cin >> x[i]>>y[i]>>z[i];
typedef long long int ll;
using namespace std;

int main(){
	int n;cin >>n;
	int num[4][3][10]={{{}}};
	int a,b,c,d; 
	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				num[i][j][k]=0;
			}
		}
	}
	for(int i=0;i<n;i++){
		cin>>a>>b>>c>>d;
		num[a-1][b-1][c-1]+=d;
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout <<" "<< num[0][i][j];
		}
		cout << endl;
	}
	cout << "####################" << endl;
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout <<" " << num[1][i][j] ;
		}
		cout << endl;
	}
	cout << "####################" << endl;
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout <<" " << num[2][i][j];
		}
		cout << endl; 
	}
	cout << "####################" << endl;
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout <<" "<< num[3][i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
using namespace std;
int main(){
    int AC = 0,WA = 0,TLE = 0,RE = 0,i,N;
    string S;
    cin >> N;
    for(i = 0;i < N;i++){
        cin >> S;
        if(S == "AC") AC++;
        else if(S == "WA") WA++;
        else if(S == "TLE") TLE++;
        else if(S == "RE") RE++;
    }
    cout << "AC x " << AC << endl << "WA x " << WA << endl << "TLE x " << TLE << endl << "RE x " << RE << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    size_t c = 0;
    for (size_t i = 1; i < n; ++i)
        c += i;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    a = A[i]
    b = A[i + 1]
    if b < a:
        ans += (a - b)
        A[i + 1] = a
print(ans)


Measured memory_bytes: 32228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool check(string a)
{
    ll res=0;
    for(int i=0;i<a.size();i++)
    res+=(a[i]-'0');
    if(res%9==0)
    return 1;
    else
    return 0;
}
int main()
{
    string n;
    cin>>n;
    if(check(n))
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
static class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		int[] a=sc.Ia;
		long ans=0;
		long[] h=new long[n+1];
		for(int i=0;i<n;i++) {h[a[i]]=i;}
		St stmax=new St(0,n-1,0);
		St stmin=new St(0,n-1,1);
		for(int i=1;i<=n;i++) {
			long q=stmax.Get(0,(int)h[i]).n;
			long p=stmin.Get((int)h[i],n-1).n;
			p=p==-1?n:p;
			ans+=(h[i]-q)*(p-h[i])*i;
			stmax.Ud((int)h[i],h[i]);
			stmin.Ud((int)h[i],h[i]);
		}
		Console.WriteLine(ans);
	}
}
public class St{
	public class Mo{
		public int n;
		public long d;
		public Mo(long d,int n){this.d=d;this.n=n;}
	}
	public Mo[] dat;
	private int m=1,f,mm;
	private Mo du;
	private Func<Mo,Mo,bool> compare;
	public St(int f,int n,int mm){
		this.f=f;
		n+=f^1;
		this.mm=mm;
		if(mm==0){du=new Mo(long.MinValue,-1);compare=CoMax;}
		else{du=new Mo(long.MaxValue,-1);compare=CoMin;}
		while(m<n){m*=2;}
		dat=new Mo[m+n-1];
		for(int i=0;i<m+n-1;i++){dat[i]=du;}
	}
	private bool CoMax(Mo x,Mo y){return x.d>y.d;}
	private bool CoMin(Mo x,Mo y){return x.d<y.d;}
	public void Ud(int q,long b){
		q+=m-1-f;
		if(dat[q]==du){
			int z=q;
			dat[q]=new Mo(b,q-(m-1-f));
			while(q>0&&compare(dat[z],dat[(q-1)/2])){
				dat[(q-1)/2]=dat[z];
				q=(q-1)/2;
			}
		}
		else{
			//b+=dat[q].d;
			dat[q].d=du.d;
			dat[q]=new Mo(b,q-(m-1-f));
			q=(q-1)/2;
			while(q>=0){
				Mo o=compare(dat[2*q+1],dat[2*q+2])?dat[2*q+1]:dat[2*q+2];
				if(dat[q]==o){break;}
				dat[q]=o;
				q=(q-1)/2;
			}
		}
	}
	private Mo Fdg(int a,int b,int k,int l,int r){
		if(r<a||b<l){return du;}
		if(a<=l&&r<=b){return dat[k];}
		Mo p=Fdg(a,b,k*2+1,l,(l+r)/2);
		Mo q=Fdg(a,b,k*2+2,(l+r+1)/2,r);
		return compare(p,q)?p:q;
	}
	public Mo Get(int a,int b){return Fdg(a,b,0,f,m-(f^1));}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

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

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

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

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

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

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

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

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

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> a_list(N);
    range(i, 0, N) cin >> a_list.at(i);
    lint cur_num = 0;
    range(i, 0, N) {
        lint a = a_list.at(i);
        if (a == cur_num + 1) cur_num = a;
    }
    cout << (cur_num == 0 ? -1: N - cur_num) << "\n";
}

Measured memory_bytes: 1792
## ABC 087
## B. coins
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            sum = i*500+j*100+k*50
            if(sum == x):
                ans += 1
                
print(ans)

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int K;
  in >> K;
  vector<int> cost(K, numeric_limits<int>::max());
  cost[1] = 1;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> Q;
  Q.emplace(cost[1], 1);
  while (!Q.empty()) {
    int n, c;
    tie(c, n) = Q.top();
    Q.pop();
    if (c > cost[n]) continue;
    if (c < cost[10 * n % K]) {
      cost[10 * n % K] = c;
      Q.emplace(c, 10 * n % K);
    }
    if (c + 1 < cost[(n + 1) % K]) {
      cost[(n + 1) % K] = c + 1;
      Q.emplace(c + 1, (n + 1) % K);
    }
  }
  out << cost[0] << '\n';
}

Measured memory_bytes: 4280
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
  int l, f;
  string S;
  stack<int> T;
  while (getline(cin, S), S != ".") {
    l = S.size();
    f = 1;
    for (int i = 0; i < l; ++i) {
      if (S[i] ==  '(' || S[i] == '[') T.push(S[i]);
      else if (S[i] == ')') {
	if (T.empty() || T.top() != '(') {
	  cout << "no" << endl;
	  f = 0;
	  break;
	}
	T.pop();
      }else if (S[i] == ']') {
	if (T.empty() || T.top() != '[') {
	  cout << "no" << endl;
	  f = 0;
	  break;
	}
	T.pop();
      }
    }
    if (f) {
      if (T.empty()) {
	cout << "yes" << endl;
      } else {
	cout << "no" << endl;
      }
    }
    while (!T.empty()) T.pop();
  }
  return 0;
}

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

const int N = 105, INF = 1e9;
string s[N];
int dp[N][N];

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

    int n, m;
    cin >> n >> m;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i + 1 < n) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (s[i][j] != s[i + 1][j]));
            }
            if (j + 1 < m) {
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (s[i][j] != s[i][j + 1]));
            }
        }
    }

    int ans = dp[n - 1][m - 1] + 1;

    if (s[0][0] == '#') {
        ans = (ans + 1) / 2;
    }
    else {
        ans = ans / 2;
    }

    cout << ans;

    return 0;   
}   

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <functional>
using namespace std;

static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

#define int long long

signed main() {
        int n;
        scanf("%lld", &n);
        vector<vector<pair<int, int>>> g(n), dp(n);
        for (int i = 1; i < n; i ++) {
                int a, v;
                scanf("%lld%lld", &a, &v);
                a --;
                g[a].emplace_back(v, i);
        }
        function<void (int, int)> dfs = [&](int u, int x) {
                if (g[u].size() == 0) return;
                pair<int, int> a = g[u][0], b = g[u][1];
                dfs(a.second, x);
                dfs(b.second, x);
                int l = a.first + b.first;
                vector<pair<int, int>> v;
                if (dp[a.second].size() > dp[b.second].size()) swap(a, b);
                for (int i = 0, j = 0; i < dp[a.second].size(); i ++) {
                        while (j < dp[b.second].size() && dp[b.second][j].first + dp[a.second][i].second + l <= x) j ++;
                        if (j != 0) {
                                v.emplace_back(dp[a.second][i].first + a.first, dp[b.second][j - 1].second + b.first);
                        }
                }
                for (int i = 0, j = 0; i < dp[a.second].size(); i ++) {
                        while (j < dp[b.second].size() && dp[b.second][j].second + dp[a.second][i].first + l > x) j ++;
                        if (j != dp[b.second].size()) {
                                v.emplace_back(dp[b.second][j].first + b.first, dp[a.second][i].second + a.first);
                        }
                }
                sort(v.begin(), v.end());
                int now = INFL;
                for (int i = 0; i < v.size(); i ++) {
                        if (i > 0 && v[i].first == v[i - 1].first) continue;
                        if (now > v[i].second) {
                                dp[u].push_back(v[i]);
                                now = v[i].second;
                        }
                }
        };        
        function<bool (int)> check = [&](int x) {
                for (int i = 0; i < n; i ++) if (g[i].size() == 0) dp[i].emplace_back(0, 0);
                dfs(0, x);
                int ok = dp[0].size();
                for (int i = 0; i < n; i ++) dp[i].clear();
                return ok != 0;
        };
        int lb = 0, ub = 1e9, ans = -1;
        while (lb <= ub) {
                int mid = (lb + ub) / 2;
                if (check(mid)) ans = mid, ub = mid - 1;
                else lb = mid + 1;
        }
        printf("%lld\n", ans);
        return 0;
}



Measured memory_bytes: 35376
Bingo = [ list(map(int,input().split())) for i in range(3)]
n = int(input())
num = [int(input()) for i in range(n)]
Bingo.append([Bingo[0][0] , Bingo[1][1],Bingo[2][2] ])
Bingo.append([Bingo[0][2] , Bingo[1][1],Bingo[2][0] ])
for k in range(3):
  Bingo.append([Bingo[0][k] , Bingo[1][k],Bingo[2][k] ])
k=0
re = 'No'
for l in range(len(Bingo)):
  if len(list(set(num) & set(Bingo[l]))) == 3:
    re = 'Yes'
    break
print(re)

Measured memory_bytes: 3064
n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))
dic = {}
for d in D:
  if d in dic:
    dic[d] += 1
  else:
    dic[d] = 1

flg = True
for t in T:
  if t in dic:
    if dic[t] == 0:
      flg = False
      break
    else:
      dic[t] -= 1
  else:
    flg = False
    break
if flg:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 41316