akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-13;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
char in[20];
int main(){
	int a;scanf("%d",&a);
	while(a--){
		scanf("%s",in);
		if(in[0]=='Y'){
			printf("Four\n");return 0;
		}
	}printf("Three\n");
}

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

int main()
{
	//def
	long long n,i,min,max,sum,a;
	cin >> n;
	for (i = 0; i < n; i++)
		if (i == 0)
		{
			cin >> a;
			min = max = sum = a;
		}
		else
		{
			cin >> a;
			sum = sum + a;
			if (min > a)
			{
				min = a;
			}
			else if (max < a)
			{
				max = a;
			}

		}
	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3088
<?php
$max = 150;

fscanf(STDIN, "%d", $in_n);

for($i = 0; $i < $max; $i++){
    $gojo[$i] = $i * $i * $i * $i * $i;
}

//var_dump($gojo);

$flag = false;
for($i = 0; $i < $max; $i++) {
    for ($j = 0; $j < $max; $j++) {
        if(($gojo[$i] - $gojo[$j]) == $in_n){
            print "$i $j";
            $flag = true;
            break;
        }elseif (($gojo[$i] + $gojo[$j]) == $in_n){
            print "$i -$j";
            $flag = true;
            break;
        }elseif ((-$gojo[$i] + $gojo[$j]) == $in_n){
            print "-$i -$j";
            $flag = true;
            break;
        }
    }
    if($flag == true){
        break;
    }
}

Measured memory_bytes: 16260
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

W = s()

from collections import defaultdict
counts = defaultdict(int)

for c in W:
    counts[c] += 1

if all([v % 2 == 0 for v in counts.values()]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3316
import sys
input = sys.stdin.buffer.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
  
def make_tree(graph, root) -> (list, list, list):
    INF = 10 ** 15
    dist = [INF] * len(graph)
    parent = [-1] * len(graph)
    stack = [root]
    dist[root] = 0
    order = []
    parent[root] = root
    while stack:
        s = stack.pop()
        order.append(s)
        for g in graph[s]:
            if dist[g] > dist[s] + 1:
                dist[g] = dist[s] + 1
                parent[g] = s
                stack.append(g)
    return dist, parent, order
    
dist, parent, order = make_tree(graph, 1)

color = [-1] * (N + 1)
for s in order:
    ng = color[s]
    c = 1
    for g in graph[s]:
        if parent[s] == g:
            continue
        if c == ng:
            c += 1
        color[g] = c
        c += 1

answer = []
for a, b in AB:
    if parent[a] == b:
        answer.append(color[a])
    else:
        answer.append(color[b])

print(max(answer))
for a in answer:
    print(a)

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

int main() {
  string s;
  cin >> s;
  int pos_a;
  int pos_z;
  int s_length = s.length();

  for (int i=0; i < s_length; ++i) {
    if (s[i] == 'A') {
      pos_a = i + 1;
      break;
    }
  }

  reverse(s.begin(), s.end());

  for (int i=0; i < s_length; ++i) {
    if (s[i] == 'Z') {
      pos_z = s.length() - i;
      break;
    }
  }

  cout << pos_z + 1 - pos_a << endl;
}

Measured memory_bytes: 640
N, M, C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
A = N.times.map { gets.split.map(&:to_i) }
outcomes = A.map { |a| [a, B].transpose.inject(0) {|sum, a_| sum + a_[0] * a_[1] } + C }
puts outcomes.count{ |o| o > 0 }


Measured memory_bytes: 1788
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
    /*static class Fast
    {
        BufferedReader br;
        StringTokenizer st;
 
        public Fast()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }*/
    public static void main(String args[] ) throws Exception {
        //Fast in=new Fast();
        Scanner in=new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out); 
	    int a=in.nextInt(),b=in.nextInt(),c=in.nextInt();
	    out.println(a==b?c:a==c?b:a);
	
        out.close();
    }
}



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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    string S;
    cin >> S;

    bool flag = true;

    rep(i, S.size()) {
        int n = 0;
        rep(j, S.size()) {
            if (S[i] == S[j]) {
                n++;
            }
        }
        if (n != 2) {
            flag = false;
            break;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  string str[2];
  for(int i=0;i<2;i++)
    cin>>str[i];
  ll ans=1;
  ll po=1;
  bool flag=false;
  for(int i=0;i<n;i++){
    if(str[0][i]==str[1][i]){
      if(i==0)
	ans=(ans*3)%1000000007;
      else if(flag==false)
	ans=(ans*2)%1000000007;
      flag=false;
    }else{
      if(i==0)
	ans=(ans*6)%100000007;
      else if(flag==true)
	ans=(ans*3)%1000000007;
      else
	ans=(ans*2)%1000000007;
      i++;
      flag=true;
    }
  }
  //a bb,cc aa,cc aa,bb 
  //a cc,bb bb,aa bb,cc
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  int a[n];
  int maxnum=0;
  for(int i=0;i<n;i++){
    cin >>a[i];
    for(int j=i-1;j>=0;j--){
      if(abs(a[j]-a[i])>maxnum){maxnum=abs(a[j]-a[i]);}
    }
  }
  cout << maxnum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll x;
  cin >> x;
  ll mon = 100;
  int ans = 1;
  while(true){
    mon += mon/100;
    if(mon>=x){
      cout << ans << '\n';
      break;
    }
    ans++;
  }

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define fast_io {cin.sync_with_stdio(0); cout.sync_with_stdio(0);}
#define out(x,y) {cout<<x<<y;}
using ll = long long int;
using pa = pair<ll,ll>;

int main(){
	fast_io;
	ll n;
	cin>>n;
	ll x = 100;
	ll y = 0;
	while(true){
		if(x>=n)break;
		x = x+(x/100);
		y++;
	}
	cout<<y<<endl;
}

Measured memory_bytes: 3668
import java.util.*;
public class Main {
static long A= 0;
static long B =0;
static long C=0;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		A = sc.nextInt();
		B=  sc.nextInt();
		C=0;
		
		for(int i=1;i<Math.max(A,B);i++) {
			if(Math.abs(i-A)==Math.abs(i-B)) {
				C=i;
				break;
			}
		}
		if(C==0) {
			System.out.println("IMPOSSIBLE");
		}else {
			System.out.println(C);
		}
		

	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using ll = long long;
ll gcd(ll a, ll b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int main() {
  ll x, y;
  scanf("%lld%lld", &x, &y);
  if (x % y == 0) puts("-1");
  else {
    ll lcm = x * y / gcd(x, y);
    printf("%lld\n", lcm + x);
  }
}
  


Measured memory_bytes: 256
N, x = map(int,input().split())
count = 0
arr = sorted(list(map(int,input().split())))
for i in range(N):
  x -= arr[i]
  if x > 0:
    count += 1
  elif x == 0:
    count += 1
    break
  else:
    break
if x > 0:
  print(count-1)
else:
  print(count)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var aopb = ReadStringArray();
            var a = int.Parse(aopb[0]);
            var op = aopb[1];
            var b = int.Parse(aopb[2]);
            var ans = op == "+" ? a + b : a - b;
            Console.WriteLine(ans);
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13140
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0 for _ in range(N)]
    for i in range(0,2*N-2,2):
        X[(i+2)%N] = X[i%N] + 2*(A[(i+1)%N] - A[i%N]) 
    x0 = (sum(A)-sum(X))//N
    return ' '.join([str(x0+x) for x in X])



if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 19096
s=input()
k=int(input())

l=list(s)

import collections
c=collections.Counter(l)
li=c.most_common()
from operator import itemgetter
li.sort(key=itemgetter(0))

co=0
p=[]
for i in range(min(5,len(li))):
    for j in range(len(s)):
        if l[j]==li[i][0]:
            for e in range(min(len(s)-j,k)):
                co+=1
                p.append(s[j:j+e+1])

q=collections.Counter(p)
ans=q.most_common()
ans.sort(key=itemgetter(0))   

print(ans[k-1][0])      
            
            
            
            




Measured memory_bytes: 4824
#include <cstdio>
#include <cstdint>
#include <vector>

constexpr intmax_t mod = 1e9+7;

template <typename Tp>
Tp gcd(Tp a, Tp b, Tp& x, Tp& y) {
  x = Tp(0);
  y = Tp(1);
  for (Tp u = y, v = x; a;) {
    Tp q = b/a;
    std::swap(x -= q*u, u);
    std::swap(y -= q*v, v);
    std::swap(b -= q*a, a);
  }
  return b;
}

template <typename Tp>
Tp modinv(Tp a, Tp mod) {
  Tp x, y;
  gcd(a, mod, x, y);
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

template <typename Tp>
Tp modadd(Tp a, Tp b, Tp mod) {
  a += b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <typename Tp>
Tp modadd(std::initializer_list<Tp> const& adds, Tp mod) {
  Tp res = 0;
  for (auto const& add: adds) {
    res += add % mod;
    if (res < 0) res += mod;
    if (res >= mod) res -= mod;
  }
  return res;
}

template <typename Tp>
Tp modsub(Tp a, Tp b, Tp mod) {
  a -= b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <typename Tp>
Tp modmul(std::initializer_list<Tp> const& muls, Tp mod) {
  Tp res = 1;
  for (auto const& mul: muls) (res *= mul) %= mod;
  return res;
}

template <typename Tp>
Tp modpow(Tp base, intmax_t iexp, Tp mod) {
  Tp res = 1;
  for (Tp dbl = base; iexp; iexp >>= 1) {
    if (iexp & 1) res = res * dbl % mod;
    dbl = dbl * dbl % mod;
  }
  return res;
}

class modchoose {
  std::vector<intmax_t> fact, fact_inv;
  const intmax_t mod;

public:
  modchoose(intmax_t N, intmax_t mod): mod(mod) {
    fact.resize(N+1);
    fact_inv.resize(N+1);
    fact[0] = 1;
    for (intmax_t i = 1; i <= N; ++i)
      fact[i] = fact[i-1] * i % mod;

    fact_inv[N] = modinv(fact[N], mod);
    for (intmax_t i = N; i--;)
      fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
  }

  intmax_t operator ()(intmax_t n, intmax_t r) const {
    intmax_t res = fact[n] * fact_inv[r] % mod;
    (res *= fact_inv[n-r]) %= mod;
    return res;
  }
};

int main() {
  intmax_t n, k;
  scanf("%jd %jd", &n, &k);

  modchoose mc(k, mod);
  intmax_t res = 0;
  for (intmax_t i = 1; i <= k; ++i) {
    intmax_t cur = mc(k, i);
    if ((i-1) % 2) cur = (mod-cur) % mod;
    (cur *= modpow(k-i, n, mod)) %= mod;
    (res += cur) %= mod;
  }
  res = modsub(modpow(k, n, mod), res, mod);
  printf("%jd\n", res);
}



Measured memory_bytes: 2756
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;




#define Seg_Max_N (1<<18) 

using Value = long long int ;
const Value ini = (1ll<<31)-1;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return min(l, r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};


int main() {
	int N, Q; cin >> N >> Q;
	segtree seg(N);
	while (Q--) {
		int a, b, c; cin >> a >> b >> c;
		if (a == 0) {
			seg.update(b, c);
		}
		else {
			int ans = seg.query(b, c + 1);
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 101;
ll cnt[N];

int main(){
	int n;
	cin >> n;
	fu(i,1,n){
		int t = i;
		fu(j,2,t){
			while(t % j == 0){++cnt[j];t/=j;}
		}
	}
	ll ans = 0;
	fu(i,1,n){
		fu(j,1,n){
			fu(k,j+1,n){
				if(i == j || i == k)continue;	
				ans += (cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4);
			}
		}
	}
	fu(i,1,n){
		fu(j,1,n){
			if(i == j)continue;
			ans += (cnt[i] >= 2 && cnt[j] >= 24);
		}
	}
	fu(i,1,n){
		fu(j,1,n){
			if(i == j)continue;
			ans += (cnt[i] >= 4 && cnt[j] >= 14);
		}
	}
	fu(i,1,n){
		ans += cnt[i] >= 74;	
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
n,m=map(int,input().split())
sc=[]
for i in range(m):
    ss,cc=map(int,input().split())
    sc.append((ss,cc))

ans=-1

for i in range(1000):
    S=str(i)
    l=len(S)
    ok=True
    for s,c in sc:
        if 0<=s-1<l:
            if S[s-1]!=str(c):
                ok=False
                continue
        else:
            ok=False
            continue
    if l!=n:
        ok=False
    if ok:
        ans=i
        print(ans)
        exit(0)
print(ans)



Measured memory_bytes: 3064
(function() {
    'use strict';
    var lines = [];
    require('readline').createInterface({
        input: process.stdin,
        output: process.stdout
    })
        .on('line', function(line) {
            lines.push(line);
        });

    process.stdin.on('end', function() {
        main(lines);
    });
})();

function main(lines) {
    var numRabbits = +lines[0], count = 0;
    var likes = lines[1].split(' ');
    // for (var i=0; i<numRabbits; i++) {
    //     rabbits.push(likes);
    // }
    for (var i=0; i<likes.length; i++) {
        var myLike = likes[i];
        var myLikesLike = likes[myLike-1];
        if (myLikesLike == i+1)
            count++
    }
    console.log(count/2);
}


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

int main(void){
    int x,n,oc,f;
    std::cin >> x >> n;
    
  	if(n==1){
		std::cin >> f;
      	std::cout << f-1;
      	exit(0);
    }
  
  	if(n==100){
      if(x<=50){
        std::cout << "0";
      }else{
        std::cout << "101";
      }
      exit(0);
    }
    
  	std::vector<int> p(n);
    for(int i=0; i<n; i++){
        std::cin >> oc;
		p.push_back(oc);
    }
    
    auto itr = p.begin();
    for(int i=0;i<=2*n;i++){
        itr = std::find(p.begin(),p.end(),x-i);
        if(itr==p.end()){
            std::cout << x-i;
            exit(0);
        }
        itr = std::find(p.begin(),p.end(),x+i);
        if(itr==p.end()){
            std::cout << x+i;
            exit(0);
        }
    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int n, m;
const int N = 2e5 + 5;
int link[N], si[N];

int find(int u) {
    if(link[u] == u)return u;
    return link[u] = find(link[u]);
}

void unite(int u, int v) {
    int a = find(u);
    int b = find(v);
    if(si[a] < si[b])swap(a, b);
    si[a] += si[b];
    si[b] = 0;
    link[b] = a;
}

int32_t main() {

    fast
    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        link[i] = i;
        si[i] = 1;
    }
    int a, b;
    while(m--) {
        cin >> a >> b;
        if(find(a - 1) != find(b - 1))
            unite(a - 1, b - 1);
    }
    int maxi = 0;
    // for(int i = 0; i < n; i++) {
    //     cout << si[i] << " ";
    // }
    // cout << endl;
    for(int i = 0; i < n; i++) {
        maxi = max(maxi, si[find(i)]);
    }
    cout << maxi;


    return 0;
}



Measured memory_bytes: 6704
import sys
from pprint import pprint

from collections import deque

h, w = map(int, sys.stdin.readline().strip().split(" "))

field = []
for _ in range(h):
    field.append(list(sys.stdin.readline().strip()))

black = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            black += 1

def bfs(field, h, w, sy, sx, gy, gx):
    q = deque()
    q.append((0, sy, sx))
    visited = set()
    while q:
        count, y, x = q.popleft()
        for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
            if 0 <= y+dy < h and 0 <= x+dx < w:
                if field[y+dy][x+dx] == "#":
                    continue
                elif (y+dy, x+dx) in visited:
                    continue
                elif (y+dy, x+dx) == (h-1, w-1):
                    return count+1

                visited.add((y+dy, x+dx))
                q.append((count+1, y+dy, x+dx))
    return -1

shortest = bfs(field, h, w, 0, 0, h-1, w-1)
# print(shortest)
if shortest == -1:
    print(-1)
else:
    print(h*w - black - (shortest+1))

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

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define For(i,a,n) for(i=a;i<n;i++)
#define all(ar) ar.begin(),ar.end() 
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;
const ll mod = 1000000007;



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    /*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    //*/
    ll l,r;
    cin>>l>>r;
    ll rem1 = l + (2019 - (l%2019)), rem2 = r - (r%2019) ;
    if(rem1 < r || rem2 > l) cout<<0;
    else{
        r %= 2019; l %= 2019;
        ll i,j, mn = 2019;
        For(i,l,r){
            For(j,i+1,r+1){
                ll tem = (i * j) % 2019;
                mn = min(mn,tem);
            }
        }
        cout<<mn;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<long long> B(N + 1, 0); //累積和テーブル
	int mod = 1000000007;
 
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		B[i + 1] = B[i] + A[i];
	}
 
	long ans = 0;
 
	//i について全探索する
	for (int i = 0; i < N; i++)
	{
		//累積和を使ってA[i+1] + ... + A[N] を求める
		long long sum = (B[N] - B[i + 1]) % mod;
 
		ans += A[i] * sum;
		ans %= mod;
	}
 
	cout << ans << endl;
}

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

int main()
{
    int A, B;
    cin >> A >> B;

    if(A >= 13)
    {
        cout << B << endl;
    }

    else if(A >= 6)
    {
        cout << B / 2 << endl;
    }

    else
    {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def ATCoder(s,can):
    n = len(s)
    count = 0
    #print(s)
    for i in range(n):
        if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
            count += 1
        else:
            if count > can:
                can = count
                count = 0
            can = ATCoder(s[i+1:],can)
            break
    else:
        if count > can:
            can = count
            count = 0

    return can
if __name__ == "__main__":
    s = input()
    print(ATCoder(s,0))


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  string S;
  cin >> S;
  cout << S.substr(0, 3) << "\n";
}


Measured memory_bytes: 3652
//MISHON69
//DATE:6/22/2020
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  stack<char>s;
  int n;
  cin>>n;
  getchar();
  FOR(i,n){
     char temp;
     cin>>temp;
     s.push(temp);
  }
  char temp1=s.top();
  s.pop();
  int sum=1;
  while(!s.empty()){
    char temp2=s.top();
    s.pop();
    if(temp2!=temp1){
       temp1=temp2;
       sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3676
act (a,b,c) "A,B" = (b,a,c)
act (a,b,c) "A,C" = (c,b,a)
act (a,b,c) "B,A" = (b,a,c)
act (a,b,c) "B,C" = (a,c,b)
act (a,b,c) "C,A" = (c,b,a)
act (a,b,c) "C,B" = (a,c,b)

chk (1,0,0) = "A"
chk (0,1,0) = "B"
chk (0,0,1) = "C"

main = do
  c <- getContents
  let i = lines c
      o = chk $ foldl (\s i -> act s i) (1,0,0) i
  putStrLn o

Measured memory_bytes: 3424
#include<iostream>
#include<stack>
using namespace std;
int main()
{
	int n, p, t, x, o;
	cin >> n;
	stack<int> cpp[n];
	cin >> p;
	while (p--)
	{
		cin >> o >> t;
		if (o > 0)
		{
			if ((o == 1)&&(!cpp[t].empty()))			
					cout << cpp[t].top() << endl; 

			if (o == 2 && !cpp[t].empty())
					cpp[t].pop(); 				
		}
		else 
		{
			cin >> x;
			cpp[t].push(x);
		}
	}
	return 0;
}


Measured memory_bytes: 4448
import java.util.Scanner;

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

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

	}
}

Measured memory_bytes: 51672
#include<stdio.h>
#include<vector>
#include<map>
using namespace std;

typedef pair<int, int> P;
vector<P> edge[100000];
int c[100000];

void dfs(int v, int color,int pr) {
    c[v] = color;
    for(int i = 0; i < edge[v].size(); i++) {
        P p = edge[v][i];
        int u = p.first;
        int w = p.second;
        if(u == pr) continue;
        
        if(w%2 == 0) dfs(u, color, v);
        else dfs(u, 1 - color, v);
    }
}

int main() {
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n - 1; i++) {
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        u--; v--;

        edge[u].push_back(P(v, w));
        edge[v].push_back(P(u, w));
    }

    dfs(0, 0, -1);
    for(int i = 0;i < n; i++) printf("%d ", c[i]);
    puts("");
    return 0;
}

Measured memory_bytes: 9984
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            string s;
            cin>>s;
            for(int i=0;i<s.length();++i)
                cout<<"x";
            cout<<endl;
        }
        return 0;
    }


Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

class unionFind{
  constructor(n){this.a=Array(n+1).fill(-1);}
  root(i){
    return this.a[i]<0?i:this.a[i]=this.root(this.a[i]);
  }
  same(x,y){return this.root(x)===this.root(y);}
  unite(x,y){
    const a=this.a;
    x=this.root(x),y=this.root(y);
    if(x===y)return false;
    if(a[y]<a[x])a[y]+=a[x],a[x]=y;
    else a[x]+=a[y],a[y]=x;
    return true;
  }
  size(i){return -this.a[this.root(i)];}
}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next(), m = next();
  var uf = new unionFind(n);
  for(var i = 0; i < m; i++){
    var [a,b] = nexts(2);
    uf.unite(a,b);
  }
  var ans = 0;
  for(var i = 0; i < n; i++){
    ans = Math.max(uf.size(i+1),ans);
  }
  return ans;
}

Measured memory_bytes: 90536
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	q := scanInt()
	s := scanString()

	sum := make([]int, n+1)
	for i := 0; i < n-1; i++ {
		sum[i+2] = sum[i+1]
		if s[i:i+2] == "AC" {
			sum[i+2]++
		}
	}

	for i := 0; i < q; i++ {
		l := scanInt()
		r := scanInt()
		fmt.Fprintln(wr, sum[r]-sum[l])
	}

}


Measured memory_bytes: 4864
import fractions
# fraction
from functools import reduce


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def main():
    result = sub()
    print(result)


def sub():
    N = int(input())
    As = [int(i) for i in input().split()]

    lh_gcds = [0] * N
    for i in range(N):
        if i == 0:
            lh_gcds[i] = As[i]
        else:
            lh_gcds[i] = fractions.gcd(lh_gcds[i-1], As[i])

    rh_gcds = [0] * N
    for i in range(N-1, -1, -1):
        if i == N-1:
            rh_gcds[i] = As[i]
        else:
            rh_gcds[i] = fractions.gcd(rh_gcds[i+1], As[i])

    max_gcd = 1
    for i in range(N):
        if i == 0:
            max_gcd = max(max_gcd, rh_gcds[1])
        if i == N-1:
            max_gcd = max(max_gcd, lh_gcds[-2])
        else:
            max_gcd = max(max_gcd, fractions.gcd(lh_gcds[i-1], rh_gcds[i+1]))
    return max_gcd


if __name__ == '__main__':
    main()


Measured memory_bytes: 16148
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main (void){
	int n,x;
	cin >> n >> x;
	vector<int> a;
	a.resize(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	int count = 0;
	for(int i = 0; i < n-1; ++i){
		if(x - a[i] >= 0){
			count++;
			x -= a[i];
		}
	}
	if(x-a[n-1]==0){
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 888
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(dead_code)]
use proconio::{input, fastout};
use proconio::marker::{Chars, Bytes, Usize1};

#[fastout]
fn main() {
    input!{
        n: usize, q:usize,
        c: [Usize1; n],
        query: [(Usize1, usize); q]
    }
    fn f(x: usize, y:usize) -> usize {
        let mut ret = x / 700 * 600000;
        if x / 700 % 2 > 0 {
            ret += 600000 - y;
        } else {
            ret += y;
        }
        ret
    }
    let mut g = query.iter().enumerate().collect::<Vec<_>>();
    g.sort_by_cached_key(|(_, &(x, y))| f(x, y));
    let mut idxl = 0;
    let mut idxr = 0;
    let mut ans = vec![0; q];
    let mut cur = vec![0; n];
    let mut scr = 0;
    for &(i, &(l, r)) in &g {
        while idxr < r {
            if cur[c[idxr]] == 0 {
                scr += 1;
            }
            cur[c[idxr]] += 1;
            idxr += 1;
        }
        while idxl > l {
            idxl -= 1;
            if cur[c[idxl]] == 0 {
                scr += 1;
            }
            cur[c[idxl]] += 1;
        }
        while idxr > r {
            idxr -= 1;
            if cur[c[idxr]] == 1 {
                scr -= 1;
            }
            cur[c[idxr]] -= 1;
        }
        while idxl < l {
            if cur[c[idxl]] == 1 {
                scr -= 1;
            }
            cur[c[idxl]] -= 1;
            idxl += 1;
        }
        ans[i] = scr;
    }
    println!("{}", ans.iter().map(|x| x.to_string()).collect::<Vec<_>>().join("\n"));
}


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

class Moziretsu {
public:
    string str;
    virtual ~Moziretsu() {

    }
};

class Count {
public:
    int count;
    virtual ~Count() {

    }
};

class Check_Rain
    :
    public Moziretsu,
    public Count
{
public:
    Check_Rain() {
        count = 0;
        cin >> str;
        bool Allready = false;
        for (size_t i = 0; i < str.size(); i++) {
            if (str[i] == 'R') {
                if (Allready) {
                    count++;
                }
                else {
                    count = 1;
                    Allready = true;
                }
            }
            else {
                Allready = false;
            }
        }
    }
    int GetCount() {
        return count;
    }
};

int main() {
    Check_Rain c;

    cout << c.GetCount() << endl;

}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;

    vector<ll> pri(n+1, 1);
    ll ans=1;

    for(ll i=2;i<=n;i++){
        for(ll j=i;j<=n;j+=i){
            pri[j]++;
        }
        ans += i*pri[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 81340
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N = int(input())

def F(A: int, B: int) -> int:
    return max(len(str(A)), len(str(B)))

# 求解処理
ans = len(str(N))
for a in range(1, int(math.sqrt(N)) + 1):
    if N % a != 0:
        continue
    b = int(N / a)
    ans = min(ans, F(a, b))
    
# 結果出力
print(ans)

Measured memory_bytes: 9192
#include <stdio.h>

int main(void){
	int t,i,a[5],b,h[5],l;
	
	while(1){
		scanf("%d",&a[0]);
		if(a[0]==0){
			return 0;
		}
		scanf("%d",&b);
		a[0]+=b;
		h[0]=0;
		for(t=1;t<5;t++){
			scanf("%d %d",&a[t],&b);
			a[t]+=b;h[t]=t;
		}
		for(t=0;t<5;t++){
			for(i=1;i<5;i++){
				if(a[i-1]<a[i]){
					l=a[i];
					a[i]=a[i-1];
					a[i-1]=l;
					l=h[i];
					h[i]=h[i-1];
					h[i-1]=l;
				}
			}
		}
		if(h[0]==0){
			printf("A");
		}
		if(h[0]==1){
			printf("B");
		}
		if(h[0]==2){
			printf("C");
		}
		if(h[0]==3){
			printf("D");
		}
		if(h[0]==4){
			printf("E");
		}
		printf(" %d\n",a[0]);
	}
}

Measured memory_bytes: 604
# ライブラリのインポート
#import re #正規表現
import sys
#import heapq
#import collections
#import math

def main():
    n, w = map(int, input().split())
    goods = [(0,0)]*n
    for i, inp in enumerate(sys.stdin):
        v, wtmp = map(int, inp.strip("\n").split())
        goods[i] = (v,wtmp)
    dp = [[0 for i in range(w+1)] for j in range(n)]
    for i in range(n):
        for c in range(w+1):
            if i < 0 or c <= 0: dp[0][0] = 0
            elif c - goods[i][1] < 0: dp[i][c] = dp[i-1][c]
            else: dp[i][c] = max(goods[i][0] + dp[i-1][c-goods[i][1]], dp[i-1][c])
    print(dp[n-1][w])



    
if __name__ == '__main__':
    main()



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

ll N, xors = 0;
vector<ll> v;
void input() {
  cin >> N;
  v.resize(N);
  for (auto &e : v) {
    cin >> e;
    xors ^= e;
  }
}

void solve() {
  rep(i, 0, N) {
    ll x = 0;
    cout << (xors ^ v[i]);
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

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

Measured memory_bytes: 4764
#include <stdio.h>
int uruu(int year) {
    if(year % 400 == 0)return 1;
    if(year % 4 == 0 && year % 100 != 0)return 1;
    return 0;
}

int main(void) {
    int a,b;
    int cnt=0;
    while(1) {
        scanf("%d %d",&a,&b);
        if(a == 0 && b == 0)break;
        if(cnt)puts("");
        cnt=0;
        for(;a <= b;a++) {
            if(uruu(a)) {
                printf("%d\n",a);
                cnt = 1;
            }
        }
        if(cnt == 0){
            printf("NA\n");
        }
        cnt = 1;
    }
    return 0;
}

Measured memory_bytes: 612
n,k,s=map(int,input().split())
a=[0]*n
if s==10**9:
    for i in range(n):
        if i<k:
            a[i]=s
        else:
            a[i]=(10**9)-1
    print(*a)
    exit()
    
for i in range(n):
    if i<k:
        a[i]=s
    else:
        a[i]=10**9
print(*a)

Measured memory_bytes: 6684
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    string S;
	cin >> S;

	cout << (S == "ABC" ? "ARC" : "ABC") << endl;

	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int dice[7], temp;
    rep(i,6){
        cin >> dice[i + 1];
    }
    char order;
    while(cin >> order){
        if(order == 'E'){
            temp = dice[1];
            dice[1] = dice[4];
            dice[4] = dice[6];
            dice[6] = dice[3];
            dice[3] = temp;
        }else if(order == 'N'){
            temp = dice[1];
            dice[1] = dice[2];
            dice[2] = dice[6];
            dice[6] = dice[5];
            dice[5] = temp;
        }else if(order == 'W'){
            temp = dice[3];
            dice[3] = dice[6];
            dice[6] = dice[4];
            dice[4] = dice[1];
            dice[1] = temp;
        }else{
            temp = dice[5];
            dice[5] = dice[6];
            dice[6] = dice[2];
            dice[2] = dice[1];
            dice[1] = temp;
        }
    }
    cout << dice[1] << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
vector<int> G[500];
bool vis[500];
int n,m,ans;
void dfs(int v){
	vis[v]=1;
	n++;
	for(int u:G[v]){
		m++;
		if(!vis[u]) dfs(u);
	}
}
int main(){
	int N,M,ans=0;
	cin>>N>>M;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		G[a-1].pb(b-1);
	}
	rep(i,N) if(!vis[i]){
		n=m=0;
		dfs(i);
		ans+=m-(n-1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1260
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	int i, j, k;
	int N, M, K;

	cin >> N;
	vecI L(N);
	rep(i, 0, N)
		cin >> L[i];
	ll ans = 0;
	rep(i, 0, N) {
		int a = L[i];
		rep(j, i+1, N) {
			int b = L[j];
			rep(k, j + 1, N) {
				int c = L[k];
				if (a == b || b == c || c == a)
					continue;
				bool ok = false;
				ok = (abs(a - b) < c && c < a + b);
				//ok |= (abs(a - c) < b && c < a + c);
				//ok |= (abs(c - b) < a && a < c + b);
				if (ok) {
					ans++;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3632
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

K=int(input())
ans=0
for a in range(1, K+1):
  for b in range(1, K+1):
    tmp=gcd(a, b)
    for c in range(1, K+1):
      ans+=gcd(tmp, c)
print(ans)

Measured memory_bytes: 9196
using System;

class B {
    public static void Main() {
        Console.ReadLine();
        var x = 0;
        var answer = 0;
        foreach (var i in Console.ReadLine()) {
            switch (i) {
                case 'I': ++x; break;
                case 'D': --x; break;
            }
            if (answer < x) answer = x;
        }
        Console.WriteLine(answer);
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};


template<class T>
T fastpower(T a, long long n) {  // n must be >= 1
  if (n==0) {return 1;}
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2);
      return (halfpower*halfpower) % modd;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2);
          return (((halfpower*halfpower)%modd)*a)%modd;
      }
  }
};


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        int sum = 0;
        forr(i,0,12) {
            sum=i*1000;
            if (sum>=n) {
                cout << sum-n << endl; break;
            }
        }
    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 3656
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: u64 = lines.next().unwrap().unwrap().parse().unwrap();
  if n % 2 != 0 {
    println!("0");
    return;
  }
  let mut count: u64 = 0;
  let mut i: u64 = 10;
  while i <= n {
    count += n / i;
    i *= 5;
  }
  println!("{}", count);
}

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

int main() {
  int N,T;
  cin >> N >> T;
  vector<vector <int>> A(N,vector<int>(2));
  for(int i = 0; i < N; i++){
    cin >> A.at(i).at(0);
    cin >> A.at(i).at(1);
  }
  int ans = 1001;
  for(int i = 0; i < N; i++){
    if(A.at(i).at(1) <= T){
      ans = min(ans,A.at(i).at(0));
    }
  }
  if(ans == 1001){
    cout << "TLE";
  }else{
    cout << ans;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>

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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

vector< vector < vector< __int128 > > >memo;
vi x;

lli dp(int j, int k, int s) {
	if (memo[j][k][s] != -1) {
		return memo[j][k][s];
	}
	else if (j == 0 && k == 0 && s == 0) {
		return memo[j][k][s] = 1;
	}
	else if (j >= 1 && s < x[j - 1]) {
		return memo[j][k][s] = dp(j - 1, k, s);
	}
	else if (j >= 1 && k >= 1 && s >= x[j-1]) {
		return memo[j][k][s] = dp(j - 1, k, s) + dp(j - 1, k - 1, s - x[j - 1]);
	}
	else return  memo[j][k][s] = 0;
}

int main() {
	int n, a, i, j, m, l;
	lli ans;

	cin >> n >> a;

	memo.resize(n + 1);
	rep(i, n+1) {
		memo[i].resize(n + 1);
	}

	ans = 0;
	m = 0;
	rep(i, n) {
		cin >> j;
		x.push_back(j);
		m = m < j ? j : m;
	}

	rep(i, n+1) {
		rep(j, n+1) {
			rep(l, m*n + 1) {
				memo[i][j].push_back(-1);
			}
		}
	}

	x.push_back(a);

	for (i = 1; i <= n; i++) {
		ans += dp(n, i, i*a);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 112512