akhauriyash/Code-Regression huggingface dataset:
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int n, m;
  fscanf(stdin, "%d%d ", &n, &m);
  fprintf(stdout, "%d\n", n*(n-1)/2 + m*(m-1)/2);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }

    return 0;
}


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

int main()
{
	string S;
	cin >> S;
	if (S == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;
int main()
{
	int N,K;
	long long ans=0;
	long long cnt=0;
	cin >> N >> K;
	
	for(int i=1; i<=N; i++){
		if(K % 2 == 0){
			if(i % K ==0)
				ans++;
			else if(i % (K/2) == 0)
				cnt++;
		}
		else{
			if(i % K ==0)
				ans++;
		}
	}
	
	cout << ans * ans * ans + cnt * cnt * cnt << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<algorithm>
// #include<bits/stdc++.h>
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.141592653589793//23846264338327950254
#define ft first
#define sd second
#define pb push_back
#define ll long long
#define vec vector<ll>
#define mat vector<vector<ll>>
//cout<<fixed<<setprecision(6)<<
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//ifstream f1("/Users/wangzichao/Documents/wzc.in");
//ofstream f2("/Users/wangzichao/Documents/wzc.out");
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
using namespace std;
#define local
#ifdef local
#endif
const ll maxn=6e5+7;
const double eps=1e-10;
// const ll mod=1e9+7;
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);
#define int ll
const int N = 1e5 + 10;

const int mod = 1e9+7;
ll dp[N];
int qmi(int m, int k, int p)
{
    int res = 1 %p, t = m;
    while (k)
    {
        if (k&1) res = res * t%p ;
        t = t * t%p;
        k >>= 1;
    }
    return res;
}
signed main()
{
	//STDIN;
	Quick
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; i++)
	{
		dp[i] = qmi(k/i, n, mod);
	}
	for (int i = k/2; i >= 1; i--)
	{
		for (int j = i + i; j <= k; j+=i)
		{
			dp[i]-=dp[j];
		}
	}
	ll ans = 0;
	for (int i = 1; i <= k; i++)
	{
		dp[i] = i*dp[i] %mod;
		ans = (ans + dp[i]) %mod;
	}
	cout << ans << endl;

}

Measured memory_bytes: 3924
N, K = map(int, input().split())
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * N
dp[0] = 0
for i in range(1,N):
    H = h[i]
    dp[i] = min( [dp[j] + abs(h[j] - H) for j in range(max(0, i-K),i)])
print(dp[-1])


Measured memory_bytes: 13928
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=200005;
int n;
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
		if(s[i]=='?') s[i]='D';
	printf("%s",s+1);
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 55, M = 3e3, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    string s;
    while(cin >> s)
        cout << s[0];
}


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

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            Console.WriteLine(Math.Min(Math.Min(input[0] + input[1], input[1] + input[2]), input[2] + input[0]));
        }
    }
}

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

int main(void){
    int N,M;
    cin>>N;
    multiset<int> d;
    rep(i,N){
        int x;
        cin>>x;
        d.insert(x);
    }
    cin>>M;
    vector<int> t(M);
    rep(i,M)cin>>t[i];
    rep(i,M){
        auto itr = d.find(t[i]);
        if(itr == d.end()){
            cout<<"NO"<<endl;
            return 0;
        }
        d.erase(itr);
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 10368
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, m, max;
    int[][] ichiro, jiro, mat;
    int[] dp;

    void run(){
	while(true){
	    n = sc.nextInt();
	    if(n==0) break;
	    ichiro = new int[n][2];
	    for(int i=0; i<n; i++){
		ichiro[i][0] = sc.nextInt();
		ichiro[i][1] = sc.nextInt();
	    }
	    m = sc.nextInt();
	    jiro = new int[m][2];
	    for(int i=0; i<m; i++){
		jiro[i][0] = sc.nextInt();
		jiro[i][1] = sc.nextInt();
	    }

	    mat = new int[n+m][2];
	    int x=0;
	    for(int i=0; i<n; i++){
		mat[x][0] = ichiro[i][0];
		mat[x][1] = ichiro[i][1];
		x++;
	    }
	    for(int i=0; i<m; i++){
		mat[x][0] = jiro[i][0];
		mat[x][1] = jiro[i][1];
		x++;
	    }

	    Arrays.sort(mat, new Comparator<int[]>(){
		    public int compare(int[] m1, int[] m2){
			if(m1[0]!=m2[0]) return m1[0]-m2[0];
			return m1[1]-m2[1];
		    }
		}
		);

	    dp = new int[n+m];
	    Arrays.fill(dp, 1);
	    max = 1;

	    for(int i=0; i<mat.length; i++){
		for(int k=i; k>=0; k--){
		    if(mat[i][0]>mat[k][0] && mat[i][1]>mat[k][1])
			dp[i] = Math.max(dp[i], dp[k]+1);
		    max = Math.max(max, dp[i]);
		}
	    }

	    System.out.println(max);
	}
    }
}

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

using namespace std;
using ll = long long;

int main() {
    cout.precision(20);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> r, g, b;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            r.push_back(i);
        } else if (s[i] == 'G') {
            g.push_back(i);
        } else {
            b.push_back(i);
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int ri = 0, gi = 0, bi = 0;
        for (int j = i + 1; j < n; j++) {
            if (s[i] != s[j]) {
                if (s[i] != 'R' && s[j] != 'R') {
                    while (ri < r.size() && r[ri] <= j) ri++;
                    ans += r.size() - ri;
                    if (2 * j - i < s.size() && s[2 * j - i] == 'R') ans--;
                }
                if (s[i] != 'G' && s[j] != 'G') {
                    while (gi < g.size() && g[gi] <= j) gi++;
                    ans += g.size() - gi;
                    if (2 * j - i < s.size() && s[2 * j - i] == 'G') ans--;
                }
                if (s[i] != 'B' && s[j] != 'B') {
                    while (bi < b.size() && b[bi] <= j) bi++;
                    ans += b.size() - bi;
                    if (2 * j - i < s.size() && s[2 * j - i] == 'B') ans--;
                }
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3652
import sys
n=1
while n>0:

    n,x= map(int,input().split())


    if n==x==0:
        sys.exit()

    ans=0


    for i in  range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    ans+=1
    print(ans)
        


Measured memory_bytes: 5600
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
int main()
{
    int n;
    cin >> n;
    vi v(3 * n);
    rep(i, 3 * n)
    {
        cin >> v[i];
    }
    sort(all(v));
    lint ans = 0;
    for (int i = n; i < 3*n; i+=2)
    {
        ans += v[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(l[K-1])


Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

vi a;
int k;

int main() {
	a.resize(5);
	rep(i, 5) cin >> a[i];
	cin >> k;

	bool ans = true;
	rep(i, 4) {
		rep(j, i + 1, 5) {
			if (abs(a[i] - a[j]) > k) ans = false;
		}
	}

	write(ans ? "Yay!" : ":(");
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int h=sc.nextInt();//縦
  	int w=sc.nextInt();//横
    String[] a=new String[h];
    
    for(int i=0;i<h;i++){
      a[i]=sc.next();
    }
    
    boolean[] row=new boolean[h];
    Arrays.fill(row,false);
    boolean[] col=new boolean[w];
    Arrays.fill(col,false);
    
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(a[i].charAt(j)=='#'){
          row[i]=true;
          col[j]=true;
        }
      }
    }
    
    for(int i=0;i<h;i++){
      if(row[i]){
        for(int j=0;j<w;j++){
          if(col[j]){
            System.out.print(a[i].charAt(j));
          }
        }
      }
      System.out.println();
    }
  
  }
}

Measured memory_bytes: 27016
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<unistd.h>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Buffer{
    int idx;
    char buf[1025];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, 1024); }
    void check(){ if(idx == 1024){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    Buffer buf;
    int h = buf.next(), w = buf.next();
    // vector<vector<short>> cs(10, vector<short>(10));
    int cs[10][10];
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cs[i][j] = buf.next();
        }
    }
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                cs[j][k] = min((int)cs[j][k], cs[j][i] + cs[i][k]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int a = buf.next();
            prints(a);
            if(a != -1){
                ans += cs[a][1];
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int main() {
  int H, W;
  // char '#';
  cin >> H >> W; // >> '#';
 
  while (true)
  {
    if ( H == 0 && W == 0 ) break;
    for ( int i = 0; i < H; i++ ) {
      for ( int j = 0; j < W; j++ ) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
    cin >> H >> W;
  }
       
 /*
  while('#' <= H) {
    while ('#' <= W) {
      cout << '#';
    }
  cout << endl;
  }
*/
  return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP2_7_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            HashSet<int> hs = new HashSet<int>();
            for (int i = 0 ; i < n ; i++)
            {
                int[] line = ReadIntAr();
                switch (line[0])
                {
                    case 0:
                        hs.Add(line[1]);
                        Console.WriteLine(hs.Count());
                        break;
                    case 1:
                        Console.WriteLine(hs.Contains(line[1])?1:0);
                        break;
                }

            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 30636
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

ll Count[int(1e5 + 5)];

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A * A % inf, N / 2) % inf;
  return A * Pow(A * A % inf, N / 2) % inf;
}

int main(){
  ll N, K; cin >> N >> K;
  ll ans = 0;
  for (ll i = K; i >= 1; i--){
    ll num = Pow(K / i, N) - Count[i];
    ans += i * num; ans %= inf;
    if (ans < 0) ans += inf;
    for (ll j = 1; j * j <= i; j++){
      if (i % j == 0){
        if (j * j == i){
          Count[j] += num; Count[j] %= inf;
        }else{
          Count[j] += num; Count[j] %= inf;
          Count[i / j] += num; Count[i / j] %= inf;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4416
import 'dart:io';

void main() {
  int n = int.parse(stdin.readLineSync());
  int sum;
  sum = 1;
  for (int i = 1; i <= n; i++) {
    sum = sum * i;
    if (sum > 10000) {
      sum = sum % (1000000000 + 7);
    }
  }
  print(sum % (1000000000 + 7));
}


Measured memory_bytes: 13156
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long a,b,c;
int main(){
	scanf("%lld%lld%lld",&a,&b,&c);
	if(c<=a-b){
		puts("0");
	}else{
		printf("%lld\n",c-(a-b));
	}
	return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 1e5 + 20;
const ll inf = 1e17 + 7;

int n, m, k;
int c[N], v[N];
ll dp[110][N];
int w;

int main() {
	cin >> n >> w;
	for (int i = 0; i < n; i++)
		scanf("%d%d", v + i, c + i);
	for (int i = 0; i <= n; i++)
		for (int j = 0; j < N; j++)
			dp[i][j] = inf;
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < N; j++) {
		    dp[i][j] = min(dp[i][j], dp[i - 1][j]);
		    if (j - c[i - 1] >= 0)
		    	dp[i][j] = min(dp[i][j], dp[i - 1][j - c[i - 1]] + v[i - 1]);
		}			
	int ans = 0;
	for (int i = 0; i < N; i++)
		if (dp[n][i] <= w)
			ans = max(i, ans);
	cout << ans;
	return 0;
}


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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
pair< pair<string, int>, int> r[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> r[i].first.first >> r[i].first.second, r[i].second = i + 1;

    return true;
}

void solve() {
    sort(r, r + n, [](pair< pair<string, int>, int> a, pair< pair<string, int>, int> b) {
        return a.first.first < b.first.first || (a.first.first == b.first.first && a.first.second > b.first.second);
    });

    for (int i = 0; i < n; ++i)
        cout << r[i].second << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cout<<v[i][j]<<" ";}cout<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair
#define vd vector<double>
#define vdd vector<vd>


int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep (i, n) {
    cin >> a[i];
  }
  int m = 41;
  vll dp(m + 1, vl(2, -INF));
  dp[m][1] = 0;
  for (int i = m; i > 0; i--) {
    rep (giri, 2) {
      if (dp[i][giri] < 0) continue;
      int ok = 0, ng = 0;
      ll mask = 1LL << (i - 1);
      //DEBUG(mask);
      rep (j, n) {
        if (mask & a[j]) ok++;
        else ng++;
      }
      //DEBUG(pii(ok, ng));
      if (!giri) {
        if (ok >= ng) {
          chmax(dp[i - 1][0], dp[i][0] + mask * ok);
        }
        else {
          chmax(dp[i - 1][0], dp[i][0] + mask * ng);
        }
      }
      else {
        if (mask & k) {
          chmax(dp[i - 1][1], dp[i][1] + mask * ng);
          chmax(dp[i - 1][0], dp[i][1] + mask * ok);
        }
        else {
          chmax(dp[i - 1][1], dp[i][1] + mask * ok);
        }
      }
    }
  }
  //DEBUG_MAT(dp);
  cout << max(dp[0][0], dp[0][1]) << endl;
}
          
          
          
  


Measured memory_bytes: 1024
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let (r, w, e) = (stdin(), stdout(), stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    // =============================================== //
    let (h, w): (usize, usize) = (io.read(), io.read());
    let mut a: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let k = io.chars();
        a.push(k);
    }

    let mut dp = vec![vec![1; w]; h];
    let MOD = 1e9 as isize + 7;

    for i in 0..h {
        for j in 0..w {
            if a[i][j] == '#' {
                dp[i][j] = 0;
            } else {
                if i == 0 && j == 0 {
                    dp[i][j] = 1;
                } else {
                    let m1 = if i > 0 { dp[i - 1][j] } else { 0 };
                    let m2 = if j > 0 { dp[i][j - 1] } else { 0 };
                    dp[i][j] = m1 + m2;
                }
            }
            dp[i][j] %= MOD;
        }
    }
    io.writeln(dp[h - 1][w - 1]);
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug ) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
}


Measured memory_bytes: 16636
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    ll T1, T2;
    ll A1, A2;
    ll B1, B2;
    cin >> T1 >> T2;
    cin >> A1 >> A2;
    cin >> B1 >> B2;
    ll P = (A1 - B1) * T1;
    ll Q = (A2 - B2) * T2;
    if(P > 0) {
        P = -P;
        Q = -Q;
    }
    if(P + Q < 0) {
        cout << 0 << endl;
        return 0;
    }
    if(P + Q == 0) {
        cout << "infinity" << endl;
        return 0;
    }
    ll S = (-P) / (P + Q);
    ll T = (-P) % (P + Q);
    if(T == 0) {
        cout << S * 2 << endl;
        return 0;
    } else {
        cout << S * 2 + 1 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
S = list(input())

E = [s for i, s in enumerate(S) if i % 2 == 0]
O = [s for i, s in enumerate(S) if i % 2 == 1]

E_1 = [e for e in E if e == '1']
O_1 = [o for o in O if o == '1']

diffs_e1_o0 = len(E) - len(E_1) + len(O_1)
diffs_e0_o1 = len(O) - len(O_1) + len(E_1)

print(min(diffs_e0_o1, diffs_e1_o0))


Measured memory_bytes: 5412
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

MOD = 10**9 + 7

x = n()

c = x / 11 * 2
r = x % 11

if r > 6:
    c += 2
elif r >= 1:
    c += 1

print c


Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d,n;
  cin >> d >> n;
  int mul;
  if(d==0){
    mul=1;
  }
  else if(d==1){
    mul=100;
  }
  else{
    mul=10000;
  }
  int ans=n*pow(100,d);
  if(n==100){
    cout << ans+mul;
    return(0);
  }
  cout << ans;
  return(0);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,c=0;
  scanf("%d %d",&a,&b);
  if(a>b){
    c=c+a;
    a--;
  }else{
    c=c+b;
    b--;
  }
    if(a>b){
    c=c+a;
    a--;
  }else{
    c=c+b;
    b--;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 128
S = list(input())
N = len(S) 
ans1 = 0
for i in range(N):
	if i % 2 == 0:
		if S[i] == "1":
			ans1 += 1
	else:
		if S[i] == "0":
			ans1 += 1

ans2 = 0
for i in range(N):
	if i % 2 == 0:
		if S[i] == "0":
			ans2 += 1
	else:
		if S[i] == "1":
			ans2 += 1

print(min(ans1, ans2))

Measured memory_bytes: 3956
#include <iostream> 
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
    int s,ans = 0;
    cin >> s;
    while(1){
       if (s == 4 || s == 2 || s == 1) {
           ans += 4;
           break;
       }
       if (s%2) {
           s = 3 * s + 1;
       } else {
           s /= 2;
       }
       ans++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
open System

[<EntryPoint>]
let main argv =
    let str = Console.ReadLine()
    let ss = str.Split [| ' ' |]
    let nums = Array.map int ss
    let prod = (nums.[0]) * (nums.[1])
    let sum = Array.sum nums
    let diff = (nums.[0]) - (nums.[1])
    let ans = List.max [prod; sum; diff]
    printfn "%i" ans
    0

Measured memory_bytes: 14044
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = input()
T = input()


for i in range(len(s)-len(T), -1, -1):
	for j in range(len(T)):
		if s[i+j] != T[j] and s[i+j] != "?":
			break
	else:
		p = s[:i] + T +  s[i+len(T):]
		ans = ""
		for i in range(len(p)):
			if p[i] == "?":
				ans += "a"
			else:
				ans += p[i]
		print(ans)
		break
else:
	print("UNRESTORABLE")






Measured memory_bytes: 5204
package main

import (
	"fmt"
	"io"
	"os"
)

func answer(r io.Reader, w io.Writer) {
	var numPeople int
	var numKinds int
	fmt.Fscan(r, &numPeople)
	fmt.Fscan(r, &numKinds)
	var s [30]int

	for i := 0; i < numPeople; i++ {
		var numFavorites int
		fmt.Fscan(r, &numFavorites)
		for j := 0; j < numFavorites; j++ {
			var index int
			fmt.Fscan(r, &index)
			s[index-1]++
		}
	}

	sum := 0
	for i := 0; i < numKinds; i++ {
		if s[i] == numPeople {
			sum++
		}
	}

	fmt.Fprintf(w, "%d", sum)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long lucas(long long n) {
    long long l[n + 1];
    l[0] = 2;
    l[1] = 1;
    for (long long i = 2; i <= n; i++) l[i] = l[i - 1] + l[i - 2];
    return l[n];
}
int main() {
    long long n;
    cin >> n;
    cout << lucas(n);
}

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

int main(){
    int M,N,K,i,j,k,output,man_like,all_men_like;
    output=0;
    cin>>N>>M;
    int list[N][M];
    for (i=0;i<N;i++){
        for (j=0;j<M;j++){
            list[i][j]=0;
        }
    }
    for (i=0;i<N;i++){
        cin>>K;
        for (j=0;j<K;j++){
            cin>>list[i][j];
        }
    }
    
    for (i=1;i<=M;i++){
        all_men_like = 1;
        for (j=0;j<N;j++){
            man_like=0;
            for (k=0;k<M;k++){
                if (i == list[j][k]){
                    man_like=1;
                }
            }
            if (man_like==0){
                all_men_like=0;
            }
        }
        output+=all_men_like;
    }
    cout<<output<<endl;
}

Measured memory_bytes: 3644
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=200005;
//Code begin....

map<int,int>vis;

int main ()
{
    int n, m, x;
    scanf("%d",&n);
    FOR(i,1,n) scanf("%d",&x), ++vis[x];
    scanf("%d",&m);
    bool flag=true;
    FOR(i,1,m) {
        scanf("%d",&x);
        if (vis.find(x)==vis.end() || vis[x]==0) flag=false;
        else --vis[x];
    }
    puts(flag?"YES":"NO");
    return 0;
}


Measured memory_bytes: 11648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    char[][] s = new char[H][W];
    for (int i = 0; i < H; i++) {
      String line = sc.next();
      for (int j = 0; j < W; j++) {
        s[i][j] = line.charAt(j);
      }
    }
    
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        // BFS
        if (s[i][j] == '#' && !bfs(s, i, j)) {
          System.out.println("No");
          return;
        }
      }
    }
    
    System.out.println("Yes");
  }
  
  private static boolean bfs(char[][] s, int i, int j) {
    
    boolean hasNext = false;
    LinkedList<List<Integer>> queue = new LinkedList<>();
    queue.push(Arrays.asList(i, j));
    while (!queue.isEmpty()) {
      List<Integer> entry = queue.poll();
      int ii = entry.get(0);
      int jj = entry.get(1);
      s[ii][jj] = '.';
      if (jj > 0 && s[ii][jj-1] == '#') {
        // left
        queue.push(Arrays.asList(ii, jj-1));
        hasNext = true;
      }
      if (jj < s[ii].length - 1 && s[ii][jj+1] == '#') {
        // right
        queue.push(Arrays.asList(ii, jj+1));
        hasNext = true;
      }
      if (ii > 0 && s[ii-1][jj] == '#') {
        // up
        queue.push(Arrays.asList(ii-1, jj));
        hasNext = true;
      }
      if (ii < s.length - 1 && s[ii+1][jj] == '#') {
        // down
        queue.push(Arrays.asList(ii+1, jj));
        hasNext = true;
      }
    }
    return hasNext;
  }
}

Measured memory_bytes: 23764
N = int(input())
town = {}

for i in range(N):  # 地名をキーとした辞書に、[店番号、点数]を付加する
    place, score = input().split()
    tmp = [i+1, int(score)]
    if place in town:
        town[place].append(tmp)
    else:
        town[place] = [tmp]

index = list(town.keys())
index.sort()

for _ in index:
    tmp = town[_]
    tmp = sorted(tmp, reverse=True, key=lambda x: x[1])
    for num in tmp:
        print(num[0])


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

const int NIL=-1;
const int MAX=100000;

int n, color[MAX];
vector<int> G[MAX];

void dfs(int v, int id){
    color[v]=id;

    for(int i=0; i<G[v].size(); i++){
        if(color[G[v][i]]==NIL){
            dfs(G[v][i], id);
        }
    }
}

void assignColor(){
    int id=1;

    for(int i=0; i<n; i++) color[i]=NIL;
    for(int i=0; i<n; i++){
        if(color[i]==NIL){
            dfs(i,id); id++;
        }
    }
}

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

    for(int i=0; i<m; i++){
        int s,t; scanf("%d %d", &s, &t);
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    int q; cin >> q;
    for(int i=0; i<q; i++){
        int s,t; scanf("%d %d", &s, &t);
        if(color[s]==color[t]) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 13676
#include<cstdio>
#include<cmath>
int m=99,n,w[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
void dfs(int p,int s,int c,int i)
{
	if(s==n)m=m<c?m:c;
	else if(p--)for(;i<6&&s+w[p]*i<=n;i++)dfs(p,s+w[p]*i,c+i,0);
}
int main()
{
	scanf("%d",&n);
	dfs(12,0,0,0);
	printf("%d",m);
}

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

int main(){
  int m,d,d1,d2;
  int cnt = 0;
  cin >> m >> d;

  for(int i=4;i<=m;i++){
    for(int j=22;j<=d;j++){
      d2 = j/10;
      d1 = j-d2*10;
      if(d1<2 || d2<2)continue;
      if(d1*d2==i)cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        a: i128,
        v: i128,
        mut b: i128,
        w: i128,
        t: i128,
    }
    b -= a;
    b = b.abs();

    if b - (v - w) * t <= 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2164
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

int main() {
	ll a;
	cin >> a;
	cout << a + a * a + a * a*a << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
struct edge{int to,cost;};
typedef pair<int,int>P;
int V=300000;
vector<edge>G[300000];
int d[300000];
void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P>>que;
	fill(d,d+V,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first)
			continue;
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}
void add_edge(int from,int to){
	G[from].push_back((edge){to+V/3,0});
	G[from+V/3].push_back((edge){to+V/3*2,0});
	G[from+V/3*2].push_back((edge){to,1});
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		add_edge(u,v);
	}
	int s,t;
	cin>>s>>t;
	dijkstra(s);
	cout<<(d[t]==INF?-1:d[t])<<endl;
}


Measured memory_bytes: 17792
using System;

class F
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
		long l = h[0], a = h[1], b = h[2];
		M = h[3];

		long r = 0, n_min = 0;
		var d_max = (a + (l - 1) * b).ToString().Length;
		for (int d = a.ToString().Length; d <= d_max; d++)
		{
			var d10 = 1L;
			for (int i = 0; i < d; i++) d10 *= 10;
			var n_max = Math.Min(l - 1, (d10 - 1 - a) / b);

			long c = a + n_min * b, n = n_max - n_min + 1;
			n_min = ++n_max;

			var q = new long[,] { { d10 % M, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 } };
			q = MPow3(q, n);
			r = (q[0, 0] * r + q[0, 1] * (c % M) + q[0, 2] * (b % M)) % M;
		}
		Console.WriteLine(r);
	}

	static long M;

	static long[,] MPow3(long[,] b, long i)
	{
		var r = new long[,] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
		for (; ; b = MProduct3(b, b))
		{
			if (i % 2 > 0) r = MProduct3(r, b);
			if ((i /= 2) < 1) return r;
		}
	}

	static long[,] MProduct3(long[,] a, long[,] b)
	{
		var r = new long[3, 3];
		for (var i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
			{
				for (var k = 0; k < 3; k++) r[i, j] += a[i, k] * b[k, j];
				r[i, j] %= M;
			}
		return r;
	}
}


Measured memory_bytes: 13268
n, a, b = [int(w) for w in input().split()]
s = input()

n_li = [False] * n
pass_num = 0
b_rank = 0

for i, c in enumerate(s):
    if c == "a":
        if pass_num < a + b:
            n_li[i] = True
            pass_num += 1
    elif c == "b":
        b_rank += 1
        if pass_num < a + b and b_rank <= b:
            n_li[i] = True
            pass_num += 1


for t in n_li:
    print("Yes" if t else "No")


Measured memory_bytes: 9848
import java.util.*;
 
class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int fiveHandredYenCoins = sc.nextInt();
        int oneHandredYenCoins = sc.nextInt();
        int fiftyYenCoins = sc.nextInt();
        int sumYen = sc.nextInt();
 
        int count = 0;
 
        for(int a=0;a<=fiveHandredYenCoins;a++) {
            for(int b=0;b<=oneHandredYenCoins;b++) {
                for(int c=0;c<=fiftyYenCoins;c++) {
                    if((500 * a) + (100 * b) + (50 * c) == sumYen) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define do(i,j,k) for(register int i=j;i>=k;i--) 
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
int n; 
ll sum;
int main()
{
	cin>>n;
	fo(i,1,n)
	{
		if(i>2&&(i%3==0||i%5==0)) continue;
		else sum+=i;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
x = list(map(int, input().split()))

dis = []
if m <= n:
    print(0)
else:
    x.sort()
    for i in range(m - 1):
        dis.append(abs(x[i] - x[i + 1]))
    dis.sort()
    print(sum(dis[:m - n]))

Measured memory_bytes: 20536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,k,a[52],ans=-INF;;
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}		
	for(ll i=0;i<=k;i++){
		//i はとるかず
		for(ll l=0;l<=min(i,n);l++){
			ll r=min(i,n)-l;
			vector<ll>cnt;
			for(ll j=0;j<l;j++){
				cnt.push_back(a[j]);
			}
			for(ll j=0;j<r;j++){
				cnt.push_back(a[n-1-j]);
			}

			sort(cnt.begin(),cnt.end());
			reverse(cnt.begin(),cnt.end());
			for(ll j=0;j<k-i;j++){
				if(cnt.size()==0){
					continue;
				}
				if(cnt[cnt.size()-1]<0){
					cnt.pop_back();
				}
			}
			ll cnt2=0;
			for(ll j=0;j<cnt.size();j++){
				cnt2+=cnt[j];
			}
			ans=max(ans,cnt2);
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3620
A, B, K = map(int, input().split())

if A >= B:
    L, S = A, B
if A < B:
    L, S = B, A

while L%S != 0:
    tmp = L;
    L = S;
    S = tmp%S;

gcd = int(S)

if gcd == 1:
    print(1)
    exit()

com_div = []
com_div.append(gcd)
for i in range(1,gcd):
    if gcd % i == 0:
        com_div.append(i)

com_div.sort(reverse=True)
print(com_div[K-1])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,ans=0;
    scanf("%lld",&n);
    if(n==1)
    {
        printf("0\n");
        return 0;
    }
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(n/(i-1)==n%(i-1)) ans+=i-1;
            if(n/i!=i&&n/(n/i-1)==n%(n/i-1)) ans+=n/i-1;
        }
    }
    if(n/(n-1)==n%(n-1)) ans+=n-1;
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
long long n, q, l[N], r[N], x[N], d[N], ans[N];
vector <pair<long long, long long> > v, res;

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

	cin >> n >> q;
	for(long long i = 1; i <= n ;i++) {
		cin >> l[i] >> r[i] >> x[i];
		v.push_back({l[i] - x[i], x[i]});
		v.push_back({r[i] - x[i], -x[i]});
	}

	for(long long i = 1; i <= q; i++) {
		cin >> d[i];
		res.push_back({d[i], i});
	}

	sort(res.begin(), res.end());
	sort(v.begin(), v.end());
	multiset<long long> blocked;
	blocked.insert(1e9 + 1);

	// dbg(v);
	// dbg(res);

	long long i = 0;
	for(auto e : res) {
		while(i < v.size() && v[i].st <= e.st) {
			// dbg(v[i].nd);
			if(v[i].nd < 0)
				blocked.erase(blocked.find(-v[i].nd));
			else
				blocked.insert(v[i].nd);
			i++;
		}
		// dbg(e, i);
		ans[e.nd] = *blocked.begin();

	}
	for(long long i = 1; i <= q; i++)  {
		if(ans[i] > 1e9) ans[i] = -1;
		cout << ans[i] << '\n';
	}
}	


Measured memory_bytes: 29160