akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine()) - k;
		}
		br.close();

		TreeMap<Long, Integer> map = new TreeMap<>();
		map.put(a[0], 0);
		for (int i = 1; i < n; i++) {
			a[i] += a[i - 1];
			map.put(a[i], 0);
		}

		Long[] arr = map.keySet().toArray(new Long[0]);
		int cnt = 0;
		for (Long i : arr) {
			cnt++;
			map.put(i, cnt);
		}
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = map.get(a[i]);
		}

		long ans = 0;
		BIT bit = new BIT(map.size());
		for (int i = 0; i < n; i++) {
			ans += bit.sum(b[i]);
			if (a[i] >= 0) {
				ans++;
			}
			bit.add(b[i], 1);
		}
		System.out.println(ans);
	}

	static class BIT {
		int n;
		long[] arr;

		public BIT(int n) {
			this.n = n;
			arr = new long[n + 1];
		}

		void add(int idx, long val) {
			for (int i = idx; i <= n; i += i & -i) {
				arr[i] += val;
			}
		}

		long sum(int idx) {
			long sum = 0;
			for (int i = idx; i > 0; i -= i & -i) {
				sum += arr[i];
			}
			return sum;
		}
	}
}


Measured memory_bytes: 62724
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

int main(){
    ll n;
    cin >> n;
    ll sum[n+2];
    ll A[n+2];
    // rep(i,n+2){

    // }
    llRep(i,n){
        cin >> A[i];
    }
    sum[0] = 0;
    // sum[1] = A[1];
    //+,-,+,...
    ll cnt=0;
    for(ll i=1; i<=n; i++){
        sum[i] = sum[i-1] + A[i];
        if (i%2==0){//-
            if(sum[i]>-1){
                ll new_sum = -1;
                cnt += abs(new_sum - sum[i]);
                sum[i] = new_sum;
            }
        }else{//+
            if (sum[i]<1){
                ll new_sum = 1;
                cnt += abs(new_sum - sum[i]);
                sum[i] = new_sum;
            }
        }
    }
    
    //-,+,-,...
    ll cnt2 = 0;
    for(ll i=1; i<=n; i++){
        sum[i] = sum[i-1] + A[i];
        if (i%2==1){//-
            if(sum[i]>-1){
                ll new_sum = -1;
                cnt2 += abs(new_sum - sum[i]);
                sum[i] = new_sum;
            }
        }else{//+
            if (sum[i]<1){
                ll new_sum = 1;
                cnt2 += abs(new_sum - sum[i]);
                sum[i] = new_sum;
            }
        }
    }
    cout << min(cnt,cnt2) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  ll x;
  cin >> x;
  ll a = 0;
  ll b = 0;

  for (int i = -200; i <= 200; i++) {
    for (int j = -200; j <= 200; j++) {
      if ((ll)pow(i, 5) - pow(j, 5) == x) {
        a = i;
        b = j;
        break;
      }
    }
  }
  cout << a << " " << b << endl;
}


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

int n,A,B,C;
int l[10];

int dfs(int i,int a,int b,int c){
	if(i==n){
		if(min({a,b,c})>0) return abs(A-a)+abs(B-b)+abs(C-c)-30;
		else return 1e9;
	}
	int res0=dfs(i+1,a,b,c);
	int res1=dfs(i+1,a+l[i],b,c)+10;
	int res2=dfs(i+1,a,b+l[i],c)+10;
	int res3=dfs(i+1,a,b,c+l[i])+10;
	return min({res0,res1,res2,res3});
}

int main() {
	cin >> n >> A >> B >> C;
	for(int i=0;i<n;i++) cin >> l[i];
	cout << dfs(0,0,0,0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);cerr<<fixed<<setprecision(5);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
/* VARIABLE DECLARATION START */
int globe[int(1e6)];
/*  FUCNTION TEMPLATE STARTS  HERE */
double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
inline int maxm(const int &a,const int &b)
{
  if(a>b)return a;
  else return b;
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
/*  FUCNTION TEMPLATE ENDS HERE */

int main()
{
   VALHALLA
   string s;cin>>s;
   reverse(all(s));
   string s1="maerd";
   string s2="remaerd";
   string s3="esare";
   string s4="resare";
   int index=0;
   while(index<sz(s))
   {
     string to_check1=s.substr(index,5);
     string to_check2=s.substr(index,6);
     string to_check3=s.substr(index,7);
     if(to_check1==s1||to_check1==s3)
      index+=5; 
     else if(to_check2==s4)
      index+=6;
     else if(to_check3==s2)
      index+=7;
     else
      {cout<<"NO"<<endl;return 0;}

   }
   cout<<"YES"<<endl;
}




Measured memory_bytes: 512
<?php

fscanf(STDIN, "%d %d", $n, $k);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = 0; $i < $n; ++$i) {
    --$A[$i];
}

const K_MAX = 61;

$to = [];
$to[0] = $A;

for ($i = 1; $i < K_MAX; ++$i) {
    for ($j = 0; $j < $n; ++$j) {
        $to[$i][$j] = $to[$i - 1][$to[$i - 1][$j]];
    }
}

$x = 0;
for ($i = 0; $i < K_MAX; ++$i) {
    if ($k & 1<<$i) {
        $x = $to[$i][$x];
    }
}

echo $x + 1;

/* foreach ($to as $key => $arr) { */
/*     echo "$key: [" . implode(', ', $arr) . "]", PHP_EOL; */
/* } */


Measured memory_bytes: 406936
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    if(s=="Cloudy") cout<<"Rainy"<<endl;
    if(s=="Rainy") cout<<"Sunny"<<endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b, c;
    cin >> a >> b >> c;
    int i = 1, j = 0, k = 0;
    char ch = a[0];
    while (1) {
      if (ch == 'a') {
        if (i == a.size()) {
          cout << "A" << endl;
          return 0;
        }
        ch = a[i];
        i++;
      } else if (ch == 'b') {
        if (j == b.size()) {
          cout << "B" << endl;
          return 0;
        }
        ch = b[j];
        j++;
      } else {
        if (k == c.size()) {
          cout << "C" << endl;
          return 0;
        }
        ch = c[k];
        k++;
      }
    }

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	string s, t;
	cin >> s >> t;

	int ans = BIG_NUM;
	for (int i = 0; i <= s.length() - t.length(); i++) {
		string t1 = s.substr(i, t.length());
		int cnt = 0;
		

		for (int j = 0; j < t.length(); j++) {
			if (t1[j] != t[j]) {
				cnt++;
			}
		}
		
		ans = min(ans, cnt);

	}

	cout << ans << endl;
}

Measured memory_bytes: 3568
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main { 
	static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) { 

    	int n = scan.nextInt();
    	String str = "";
    	
    	for(int i=0; i<n; i++) {
    		str += scan.nextInt();	//WARNING
    		if (i != n-1) str += " ";
    	}
    	
    	String str2 = "";
    	List<String> list = new ArrayList<String>();
    	for(int i=1; i<n+1; i++) {
    		str2 += i;
    	}
    	list =permutation(list, str2, "");
    	
    	int a = -1;
    	for(int i=0; i<list.size(); i++) {
    		if(list.get(i).equals(str)) {
    			a = i;
    			break;
    		}
    	}
    	if(a != 0) {
    		System.out.println(list.get(a - 1));
    	}
    	System.out.println(list.get(a));
    	if(a != list.size()-1) System.out.println(list.get(a + 1));
    }
	
    public static List<String> permutation(List<String> list, String q, String ans){
    	if(q.length() <= 1) {
    		list.add(ans + q);
    	}else {
    		for (int i = 0; i < q.length(); i++) {
    			permutation(list, q.substring(0, i) + q.substring(i + 1), ans + q.charAt(i) + " ");
    		}
    	}
    	return list;
    }    	
}


Measured memory_bytes: 175544
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+7,p=1e9+7;
int n,k,f[N][N];
int main(){
	cin>>n>>k,f[0][n]=1;
	if(n==1&&k==1) {cout<<1<<endl; return 0;}
	for(int i=1;i<k;i++){
		for(int j=1;j<=n-i+1;j++) f[i][j]=(f[i-1][n]-f[i-1][j-1]+p)%p;
		for(int j=1;j<=n;j++) f[i][j]=(f[i][j]+f[i][j-1])%p;
	}
	int ans=(f[k-1][n]-f[k-1][1]+p)%p,c=n-k-1; while(c>0) ans=ans*2%p,c--; cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
typedef long long ll;
using namespace std;

ll mod=1000000007;
ll dp[1000010], sum[1000010];

int main() {
	ll N;
	cin >> N;
	ll ans=0, m=((N-1)*(N-1))%mod;
	dp[0]=sum[0]=1;
	for(ll i=0; i<N-1; ++i){
		(ans += (dp[i]*m)%mod) %= mod;
		if(i<N-2){
			(ans += dp[i]*(i+2)) %= mod;
		}else{
			(ans += dp[i]*(i+1)) %= mod;
		}
		if(i>0){
			dp[i+1]=(sum[i]-dp[i-1]+mod)%mod;
		}else{
			dp[i+1]=1;
		}
		sum[i+1]=(sum[i]+dp[i+1])%mod;
	}
	(ans += dp[N-1]*N) %= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15872
K, N = map(int, input().split())
A = [int(x) for x in input().split()]

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

Measured memory_bytes: 26420
#include <iostream>
#include <vector>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  int n;
  cin >> n;
  vector<int> v;
  rep(i, n){
    int a;
    cin >> a;
    if(a % 2 == 0){
      v.push_back(2);
    }else{
      v.push_back(1);
    }
  }
  ll res = 1;
  ll res2 = 1;
  rep(i, n){
    res *= 3;
    res2 *= v[i];
  }
  cout << res - res2 << endl;
}


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

using namespace std;

#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())

typedef long long ll;typedef vector<int> vi;
typedef pair<int,int> ii;typedef vector<ii> vii;
typedef vector<vi> vvi;

int dp[10004],dp_new[10004];
signed main(){
	IOS
	int n;cin>>n;
	dp[0]=1;
	forn(i,n){
		int x;cin>>x;
		forn(i,10004){
			dp_new[i]=dp[i]|(i-x>=0?dp[i-x]:0);
		}
		swap(dp,dp_new);
	}
	for(int i=10003;i>=0;i--){
		if(dp[i] && i%10){
			cout<<i;
			return 0;
		}
	}
	cout<<0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

void darts();

void longest_dis();

void sum_of_three_integers();

void otoshidama();

int main()
{
  //darts();
  //longest_dis();
  //sum_of_three_integers();
  otoshidama();
}


void darts()
{
  while (true)
  {
    int n, m;
    cin >> n >> m;

    // stop cond
    if (n == 0) break;

    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];

    // 2 darts combination
    // p = q, 0, p + q
    vector<int> q = p;
    q.push_back(0);
    for (int i = 0; i < n; ++i)
    {
      for (int j = 0; j <= i; ++j)
      {
        q.push_back(p[i] + p[j]);
      }
    }

    sort(q.begin(), q.end());

    // q's size = 1 + n + n(n + 1) / 2
    //cout << q.size() << "\n";
    //for (auto x : q) cout << x << " ";

    int ret = 0;
    int j = q.size() - 1;
    //i:q linear scan
    for (int i = 0; i < q.size(); ++i)
    {
      if (q[i] > m) break;
      while (q[i] + q[j] > m) --j;
      ret = max(ret, q[i] + q[j]);
    }

    cout << ret << "\n";
  }
}

void longest_dis()
{
  int n;
  cin >> n;

  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;

  double v_max = 0.0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      if ((p[i].first - p[j].first) * (p[i].first - p[j].first)
        + (p[i].second - p[j].second) * (p[i].second - p[j].second)
        >  v_max * v_max)
      {
        v_max = sqrt((p[i].first - p[j].first) * (p[i].first - p[j].first)
          + (p[i].second - p[j].second) * (p[i].second - p[j].second));
      }
    }
  }

  cout << v_max << "\n";
}

void sum_of_three_integers()
{
  int k, s;
  cin >> k >> s;

  int cnt = 0;
  //for (int i = 0; i <= k; ++i)
  //{
  //  for (int j = 0; j <= k; ++j)
  //  {
  //    for (int m = 0; m <= k; ++m)
  //    {
  //      if (i + j + m == s) ++cnt;
  //    }
  //  }
  //}
  for (int i = 0; i <= k; ++i)
  {
    for (int j = 0; j <= k; ++j)
    {
      int m = s - i - j;
      if (0 <= m && m <= k) ++cnt;
    }
  }

  cout << cnt << "\n";
}

void otoshidama()
{
  int n, Y;
  cin >> n >> Y;

  for (int x = 0; x <= n; ++x)
  {
    for (int y = 0; x + y <= n; ++y)
    {
      int z = n - x - y;
      if (x * 10000 + y * 5000 + z * 1000 == Y)
      {
        cout << x << " "<< y << " " << z << "\n";
        return;
      }
    }
  }

  cout << "-1 -1 -1\n";
}

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

int main(){
    int N;
    cin>>N;
    int first=N/100, second=N%100;
    string ans;

    if(1<=first && first<=12) {
        if(1<=second && second<=12) ans="AMBIGUOUS";
        else ans="MMYY"; 
    }

    else{
        if(1<=second && second<=12) ans="YYMM";
        else ans="NA";
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    ll n,k,r,s,p,ans;
    ans=0;
    cin>>n>>k;
    cin>>r>>s>>p;
    int i;
    string str;
    cin>>str;
    rep(i,n){
        if(i<k){
            if(str[i]=='r'){
                ans+=p;
            }else if(str[i]=='s'){
                ans+=r;
            }else{
                ans+=s;
            }
        }else{
            if(str[i-k]==str[i]){
                str[i]='a';
            }else{
                if(str[i]=='r'){
                    ans+=p;
                }else if(str[i]=='s'){
                    ans+=r;
                }else{
                    ans+=s;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int a = sc.nextInt();
			
			int x = n / 500;
			if (a >= n - x * 500) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}

	}

}

Measured memory_bytes: 23892
using System;
using static System.Console;

namespace AtCorder
{
	public class Program
	{
		public static void Main()
		{
			var input = Array.ConvertAll(ReadLine().Split(), int.Parse);
			var n = input[0];
			var k = input[1];
			WriteLine(n % k == 0 ? 0 : 1);
		}
	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

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

  vector < pair<int, int> > A(N);
  for (int i = 0; i < N; i++){
    int a; cin >> a;
    A[i] = make_pair(a, i + 1);
  }
  sort(A.begin(), A.end());

  for (int i = 0; i < N; i++){
    cout << A[i].second;
    if (i != N - 1){
      cout << " ";
    }else{
      cout << endl;
    }
    
  }
  
  
  
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char s;
  cin>>s;
  if(s=='a'||s=='i'){
  cout<<"vowel"<<endl;
  }else if(s=='u'||s=='e'){
  cout<<"vowel"<<endl;
  }else if(s=='o'){
  cout<<"vowel"<<endl;
  }else{
  cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
import heapq


change = []
n, m = map(int, input().split())
a = [-1 * int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([-c, b])

l = []
heapq.heapify(change)
heapq.heapify(a)
flg = False
cnt = 0
while cnt < n:
    if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                l.append(b)
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            l.append(aa)
            cnt += 1
    else:
        aa = heapq.heappop(a)
        l.append(aa)
        cnt += 1
        
print(-1 * sum(l))

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

M = []
for _ in range(N):
  t, x, y = map(int, input().split())
  M.append([t, x, y])

current = [0, 0, 0]
can = True
for m in M:
  dt = m[0] - current[0]
  dist = abs(m[1] - current[1]) + abs(m[2] - current[2])
  if (dist > dt):
    can = False
    break
  else:
    if (dist % 2 != dt % 2):
      can = False
      break
  current = m

result = "Yes" if (can == True) else "No"
print(result)


Measured memory_bytes: 19572
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string w;
    int c[27];

    cin >> w;

    int n = w.length();

    for (int i = 0; i < 26; i++)
    {
        c[i] = 0;
    }

    for (int i = 0; i < n; i++)
    {
        c[w[i]-'a']++;
    }

    bool ans = true;

    for (int i = 0; i < 26 && ans; i++)
    {
        if (c[i] % 2)
        {
            ans = false;
        }
    }

    if (ans)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    cout << endl;

    return 0;
}

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

int N;
int A[22];
/*
double dp[2][2*100000+1];

double solve(int id,int dv){
  fill(dp[0],dp[2],1e15);
  double res = 1e15;
  for(int i=0;i<20;i++){
    int id = i&1;
    int nd = (i+1)&1;
    for(int j=0;j<=(1<<20);j++) dp[nd][j]=1e15;
    for(int dv=1;dv<=(1<<20);dv++){
      if( dp[id][dv] < -1e-9 ) continue;
      if( dp[id][dv] > res ) continue;
      printf("dp[%d][%d] = %.9lf\n",i,dv,dp[id][dv]);
      if( id == N ) return dp[id][dv] = 0.0f;
      for(int j=dv;j<=(1<<20);j+=dv){
	dp[nd][j] = min( dp[nd][j], max( dp[id][dv],
					 abs(A[i]-j)/(double)A[i]) );
	res = min(dp[nd][j],res);
      }
    }
  }
  return res;
  double ret = 1e15;
  for(int i=0;i<=(1<<20);i++) ret = min( ret, dp[N&1][i] );
  return ret;
}

*/
double dp[21][200001];
double solve(int id,int dv){
  if( dp[id][dv] > -1e-9 ) return dp[id][dv];
  if( id == N ) return dp[id][dv] = 0.0;
  double ret = 1e15;
  for(int i=dv;i<A[id]*2;i+=dv){
    ret = min( ret,
	       max( solve(id+1,i), abs(A[id]-i)/(double)A[id]) );
  }
  return dp[id][dv] = ret;
}


int main(){
  scanf("%d",&N);
  for(int i=0;i<N;i++) scanf("%d",&A[i]);
  fill(dp[0],dp[N],-1.0);
  printf("%.10lf\n",solve(0,1));  
}

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

int main(){
  string S;
  cin>>S;
  if(S=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  else if(S=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  else{
    cout<<"Sunny"<<endl;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include<vector>
#include<stdlib.h>
#include<math.h>

using namespace std;

int main() {
    long long n, x, t;
    vector<long long> ara;
    long long arr[100007];
    cin >> n;
    t = n;
    while(n--){
        cin >> x;
        ara.push_back(x);
    }
    arr[0] = 0;
    for (int i = 1; i < t; i++){
        i==1? arr[i] = abs(ara[i]-ara[i-1]) : arr[i] = min(arr[i-2]+abs(ara[i]-ara[i-2]), arr[i-1]+abs(ara[i]-ara[i-1]));
    }
    //for(int j = 0; j<t; j++) printf("%lld %lld\n", ara[j], arr[j]);
    cout << arr[t-1] << endl;
    return 0;
}

Measured memory_bytes: 1908
import heapq
n,m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)
 
for i in range(m):
	target = heapq.heappop(a)
	heapq.heappush(a, (-1)*(-target//2))
	
print(-sum(a))	

Measured memory_bytes: 14180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int m, k;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> m >> k;
	if (m == 0) {
		if (k == 0) {
			cout << "0 0";
		}	else {
			cout << -1;
		}
		return 0;
	}
	if (m == 1) {
		if (k == 0) {
			cout << "0 0 1 1";
		}	else {
			cout << -1;
		}
		return 0;
	}
	if (k >= (1 << m)) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < (1 << m); i++) {
		if (i != k) {
			cout << i << ' ';
		}
	}
	cout << k << ' ';
	for (int i = (1 << m) - 1; i >= 0; i--) {
		if (i != k) {
			cout << i << ' ';
		}
	}
	cout << k;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < (int)(n);i++)
int main() {
  int n, k, q, a;
  cin >> n >> k >> q;
  vector<int> v(n, 0);
  rep(i, q) {
    cin >> a;
    v[a-1]++;
  }
  rep(i, n) cout << ((k + v[i] - q > 0) ? "Yes" : "No") << endl;
}

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

int main(){
  int n;
  cin >> n;
  for(int i=1;i<=9;i++){
    if(n%i==0 && n/i<=9 && n/i>=1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

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
#include<stdio.h>
int main(){
  int n,i,time,min=1001;
  scanf("%d%d",&n,&time);
  int route[n+1][2];
  for(i=0;i<n;i++){
    scanf("%d%d",&route[i][0],&route[i][1]);
    if(route[i][1]<=time && route[i][0]<min)
      min=route[i][0];
  }
  if(min==1001){
    printf("TLE\n");
    return 0;
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
 
//Aのn乗modM

long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}
 
//O(K)でnCkを求める
int comb( int N, int K ){
  int X = 1; //分子
  int Y = 1; //分母
  for( int i = N; i > N-K; i-- ){
    X = (X*i)%MOD;
  }
  for( int i = 1; i <= K; i++ ){
    Y = (Y*i)%MOD;
  }
  return X * modpow(Y, MOD-2, MOD)%MOD;   //Aの逆元を取る場合、modpow(A, MOD-2, MOD)
}
 
signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int ans = modpow(2, N, MOD);
  cout << (ans-1+MOD+MOD- comb(N, A) - comb(N, B))%MOD << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const double EPS = 1e-8;

struct Vector {
    double x, y;
    Vector(double x, double y) : x(x), y(y) {
    }
};

typedef Vector Point;

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

Vector operator+(const Vector& a, const Vector& b) {
    return Vector(a.x + b.x, a.y + b.y);
}

Vector operator*(const Vector& a, const double p) {
    return Vector(a.x * p, a.y * p);
}

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

Vector project(Point a, Point b, Point p) {
    Vector v = b - a;
    double t = dot(p - a, v)/dot(v, v);
    return a + v * t;
    
}

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Point a(x1, y1);
    Point b(x2, y2);
    
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        double x, y;
        cin >> x >> y;
        Vector ans = project(a, b, Point(x, y));
        cout << setprecision(8) <<fixed << ans.x << " " << ans.y << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3276
// 4 12 20
// 2 6 10
// 16 12 8
// 8 6 4
// 10 12 14
// 5
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if a%2 == 0 && a == b && b == c && c == a {
		fmt.Println(-1)
		return
	}

	ans := 0
	for {
		if a%2 == 1 || b%2 == 1 || c%2 == 1 {
			break
		}

		a2 := a / 2
		b2 := b / 2
		c2 := c / 2
		a = b2 + c2
		b = a2 + c2
		c = a2 + b2
		ans++
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int r = (n - 1) * (n - 2) / 2;
	if (k > r) {
		cout << -1 << endl;
		return 0;
	}
	vector<P> ans;
	rep(i, n - 1) ans.emplace_back(i + 1, n);
	vector<P> edge;
	rep(i, n - 1)rep(j, i) edge.emplace_back(i + 1, j + 1);
	rep(i, r -  k) ans.emplace_back(edge[i]);
	cout << ans.size() << endl;
	rep(i, ans.size()) cout << ans[i].first << ' '<< ans[i].second << endl;
	return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    A = Scanner.map_int()
    A.sort(reverse = True)
    h,w = 0,0
    i = 0
    while i < N - 1:
        if A[i] == A[i + 1]:
            if h == 0:
                h = A[i]
                i +=1
            else:
                w = A[i]
                break
        i += 1
    print(h * w)
    return

if __name__ == "__main__":
    main()


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

using ll = long long;
using P = pair<int,int>;

struct Edge {
  int next;
  int cost;
  int time;
  Edge(){}
  Edge(int next, int cost, int time): next(next), cost(cost), time(time) {}
};

struct Status {
  int city;
  int money;
  ll time;
  Status (int city, int money, ll time): city(city), money(money), time(time) {}

  bool operator < (const Status& status) const {
    return this->time > status.time;
  }
};

int main() {
  const int s_max = 2500;
  const ll inf = 1e18;

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

  vector<vector<Edge>> edges(n);
  rep(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--; v--;
    edges[u].emplace_back(v, a, b);
    edges[v].emplace_back(u, a, b);
  }

  vector<P> ex(n);
  rep(i, n) {
    int c, d;
    cin >> c >> d;
    ex[i] = P(c, d);
  };

  vector<vector<ll>> memo(n, vector<ll>(s_max+1, inf));
  priority_queue<Status> que;
  auto push = [&](int city, int money, ll time) {
    if(money < 0 || money >= s_max) return;
    if(memo[city][money] <= time) return;
    que.emplace(city, money, time);
  };

  s = min(s, s_max);
  que.emplace(0, s, 0);
  while(!que.empty()) {
    Status now = que.top(); que.pop();
    if(memo[now.city][now.money] <= now.time) continue;
    memo[now.city][now.money] = now.time;

    {
      int c = ex[now.city].F;
      int d = ex[now.city].S;

      int next_money = now.money + c;
      ll next_time = now.time + d;
      push(now.city, next_money, next_time);
    }

    for(Edge e: edges[now.city]) {
      int next_money = now.money - e.cost;
      ll next_time = now.time + e.time;
      push(e.next, next_money, next_time);
    }
  }

  for(int i = 1; i < n; i++) {
    cout << *min_element(memo[i].begin(), memo[i].end()) << endl;
  }

  return 0;
}


Measured memory_bytes: 8436
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    vector<ll> div;
    auto divisor = [&](long long a) -> void {
        for (long long i = 1; i*i <= n; i++) {
            if (a%i == 0) {
                div.push_back(i);
            }
        }
        sort(div.begin(), div.end());
    };

    divisor(n);
    ll ans = 1e18;
    for (auto v : div) {
        chmin(ans, v+n/v);
    }
    cout << ans-2 << endl;
    return 0;
}

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

int main(){
  long long N;
  cin >> N;
  long long ans = 1;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++){
    cin >> A.at(i);
	if (A.at(i) == 0){
      ans = 0;
      break;
    }
  }
  if (ans >= 1){
    for (long long i = 0; i < N; i++){
      if (A.at(i) <= (long long) 1e18 / ans){
        ans *= A.at(i);
      } else {
        ans = -1;
        break;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 4000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner (System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a<=b){
			System.out.println(a);
		}else{
			System.out.println(a-1);
		}
		
	}
}


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

using namespace std;

typedef long long LL;

const int nmax = 100007; const LL inf = 1e18;

int N;
char a[105],b[105];

int main(){
//   #ifndef GLOBAL_JUDGE
//      freopen("txt.in","r",stdin);
//      freopen("txt.out","w",stdout);
//   #endif // GLOBAL_JUDGE

     int i,j,q;
     cin >> N >> a >> b;
     int sol = 2*N;
     int best = 0;
     for(i = 0; i < N; ++i){
        q = 0;
        j = i;
        while(a[j] == b[q] && q < N)++j,++q;
        best = max(best,q);
     }
     cout << sol - best << '\n';
  return 0;
}


Measured memory_bytes: 256
ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if [h, w].eql? [0, 0]
  1.upto(h) { |i|
    case i
    when 1, h
      puts '#' * w
    else
      print "#", ("." * (w - 2)), "#\n"
    end
  }
  puts
end

Measured memory_bytes: 6100
import sys
from collections import deque
read = sys.stdin.read

N, *A = map(int, read().split())

A.sort()
A = deque(A)
a = deque()
side = True
a.append(A.popleft())

while A:
    if side:
        a.append(A.pop())
        if A:
            a.appendleft(A.pop())
        side = False
    else:
        a.append(A.popleft())
        if A:
            a.appendleft(A.popleft())
        side = True

if side:
    tmp = a.popleft()
else:
    tmp = a.pop()

if abs(tmp - a[0]) <= abs(tmp - a[-1]):
    a.append(tmp)
else:
    a.appendleft(tmp)

if not side:
    tmp = a.popleft()
else:
    tmp = a.pop()

if abs(tmp - a[0]) <= abs(tmp - a[-1]):
    a.append(tmp)
else:
    a.appendleft(tmp)

answer = 0
a = list(a)
for i, j in zip(a, a[1:]):
    answer += abs(i - j)

print(answer)

Measured memory_bytes: 14380
#include<iostream>

int main()
{
	int n;
	while( 1 ){
		std::cin >> n;
		if( !n ) break;
		
		int ans = 0;
		while( n >= 5 ){
			ans += n / 5;
			n /= 5;
		}
		
		std::cout << ans << std::endl;
	}
	

 	return 0;	
}

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

int gcd(int a, int b) {
  if (b == 0) return a;

  if (a < b) return gcd(b, a);

  return gcd(b, a % b);
}

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

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

  cout << gcd(a, b) << endl;

  return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; 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()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    string s; cin >> s;
    int n = s.length();
    bool ans = false;
    REP(i,n-1) {
        if(s[i]=='A' && s[i+1]=='C') {
            ans = true;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
    int h, n, x = 0;
    scanf("%d%d", &h, &n);
    
    int A[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
        x = x+A[i];
}

    if(x >= h)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 2000
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;

public class Playground
{
    private static int[] item1;
    private static int[] item2;

    public static void Main(string[] args)
    {
        Input();
        Method();
        System.Console.ReadLine();
    }

    private static void Input()
    {
        Console.ReadLine();
        item1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Console.ReadLine();
        item2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    }

    private static void Method()
    {
        int sum = item2.Aggregate(0, (cnt, elem) =>
            cnt + (item1.Contains(elem) ? 1 : 0)
            );

        System.Console.WriteLine(sum);
    }
}

Measured memory_bytes: 9840
from collections import deque
H,W = map(int,input().split())
A = [input() for i in range(H)]
dxy = [(0,1),(1,0),(0,-1),(-1,0)]

INF = 99999
dp = [[INF]*W for i in range(H)]
q = deque()
for y,row in enumerate(A):
    for x,c in enumerate(row):
        if c=='#':
            dp[y][x] = 0
            q.append((x,y))

while q:
    x,y = q.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if dp[ny][nx] <= d+1: continue
        dp[ny][nx] = d+1
        q.append((nx,ny))
print(max(max(row) for row in dp))

Measured memory_bytes: 89180
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

struct TopologicalSort {
    int n;
    vector <set<int>> G;
    vector<bool> used;
    vector<int> indeg, p;

    TopologicalSort() {}
    TopologicalSort(int sz) : n(sz), G(n), used(n), indeg(n), p(0) {}

    void add_edge(int s, int t) {
        G[s].insert(t);
    }

    void bfs(int s) {
        queue<int> q;
        q.push(s);
        used[s] = 1;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            p.push_back(v);
            for (int u:G[v]) {
                indeg[u]--;
                if (indeg[u] == 0 && !used[u]) {
                    used[u] = 1;
                    q.push(u);
                }
            }
        }
    }

    vector<int> build() {
        fill(used.begin(), used.end(), 0);
        fill(indeg.begin(), indeg.end(), 0);

        for (int i = 0; i < n; i++) {
            for (int v:G[i]) {
                indeg[v]++;
            }
        }

        for (int i = 0; i < n; i++) {
            if (indeg[i] == 0 && !used[i]) {
                bfs(i);
            }
        }

        return p;
    }
};

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

    int N, M;
    cin >> N >> M;

    int x[M],y[M];

    TopologicalSort ts(N);
    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        x[i]=s;
        y[i]=t;
        ts.add_edge(s, t);
    }

    auto p = ts.build();

    /*for (int node : p) {
        cout << node << "->";
    }*/

    vector<vector<int> > parent(N,vector<int>(0));
    for(int i=0;i<M;i++){
      parent[y[i]].push_back(x[i]);
    }

    /*for(int i=0;i<N;i++){
      printf("%d's parent is ",i);
      for(auto itr=parent[i].begin();itr!=parent[i].end();itr++){
        printf("%d",*itr);
      }
      cout << endl;
    }*/

    int dp[N];//dp[i]:iまでの最長パス
    fill(dp,dp+N,0);
    for(int i=1;i<N;i++){
      for(auto itr=parent[p[i]].begin();itr!=parent[p[i]].end();itr++){
        dp[p[i]]=max(dp[p[i]],dp[*itr]+1);
      }
    }

    //for(int i=0;i<N;i++) printf("dp[%d]=%d\n",i,dp[i]);

    cout << *max_element(dp,dp+N) << endl;
    return 0;
}


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

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

using namespace std;

int main(){
  int n,m;cin>>n>>m;
  map<int, int> mm;
  rep(i,n)mm[i+1]=1;
  set<int>s;
  s.insert(1);

  rep(i,m){
    int f,t;cin>>f>>t;
    if(s.count(f)>0)s.insert(t);
    mm[f]--;
    mm[t]++;
    if(mm[f]==0)s.erase(f);
  }

  cout<<s.size()<<endl;

  return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    int tail_a = 0, head_b = 0, both = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < s.size() - 1; j++) {
            if (s[j] == 'A' && s[j + 1] == 'B') {
                ans++;
            }
        }
        if (s[0] == 'B' && s[s.size() - 1] == 'A') {
            both++;
        } else if (s[0] == 'B') {
            head_b++;
        } else if (s[s.size() - 1] == 'A') {
            tail_a++;
        }
    }
    if (both > 0) {
        ans += both - 1;
        if (tail_a > 0) {
            ans++;
            tail_a--;
        }
        if (head_b > 0) {
            ans++;
            head_b--;
        }
    }
    cout << ans + min(tail_a, head_b) << endl;
    
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int w,h,n;

  cin >> w >> h >> n;

  int m[w][h] = {0};

  rep(i,n)
  {
    int x,y,a;

    cin >> x >> y >> a;

    switch(a)
    {
      case 1:
        for(int j = 0;j < x;j++)
        {
          rep(k,h)
          {
            m[j][k] = 1;
          }
        }
        break;
      case 2:
        for(int j = x; j < w;j++)
        {
          rep(k,h)
          {
            m[j][k] = 1;
          }
        }
        break;
      case 3:
        rep(j,w)
        {
          for(int k = 0; k < y;k++)
          {
            m[j][k] = 1;
          }
        }
        break;
      case 4:
        rep(j,w)
        {
          for(int k = y; k < h; k++)
          {
            m[j][k] = 1;
          }
        }
        break;
      default:
        break;
    }
  }

  int cnt = 0;

  rep(i,w)
  {
    rep(j,h)
    {
      if ( m[i][j] == 0)
        cnt++;
    }
  }

  cout << cnt;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

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

int sumOfDigits(int n) {
  int sum = 0;
  while(n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  const int INF = 1000;
  int N, res = INF;
  cin >> N;
  for(int a = 1; a < N; a++) {
    int b = N - a;
    res = min(res, sumOfDigits(a) + sumOfDigits(b));
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2*1e5+100;
int n,a[N],dp[N],sum[N];
signed main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	for (int i=1;i<=n;i+=2) sum[i]=sum[i-2]+a[i];
	for (int i=2;i<=n;i++)
	{
		if (i&1) dp[i]=max(dp[i-2]+a[i],dp[i-1]);
		else dp[i]=max(dp[i-2]+a[i],sum[i-1]);
	}
	printf("%lld\n",dp[n]);
}

Measured memory_bytes: 8504
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N=nextInt();
		int K=nextInt();
		int Q=nextInt();
		int[] A = new int[Q];
		int[] x = new int[N];
		Arrays.fill(x, 0);
		for(int i=0;i<Q;i++){
			A[i] = nextInt();
			x[A[i]-1]++;
		}
		for(int i=0;i<x.length;i++){
			if(K-Q+x[i]<=0){
				System.out.println("No");
			}else{
				System.out.println("Yes");

			}

		}

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 61524