akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
//        String str = sc.nextLine();
        int count = sc.nextInt();
        boolean flag = true;
        ArrayList<Integer> data = new ArrayList<>();
        ArrayList<Integer> nullData = new ArrayList<>();
        for (int i = 1; i <= count; i++) {
            data.add(sc.nextInt());
        }
        int index = -1;
        int posit = 0;

        while (data.isEmpty() == false) {
            posit = 1;
            for (Integer s : data) {
                if (s == posit) {
                    index = posit-1;
                }
                posit++;
            }
            if(data.size() == 1 && data.get(0)==1){
                index=0;
            }else if (data.size() == 1) {
                index=-1;
            }
            
            if (index == -1) {
                System.out.println("-1");
                flag = false;
                break;
            }
            nullData.add(0, data.get(index));
            data.remove(index);
            index=-1;
        }
        if (flag == true) {
            for (Integer s : nullData) {
                System.out.println(s);
            }
        }
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)



ll n,k;vector<ll> v;
ll dp[100099];
void fun(){
	dp[0] = -1;
	for(ll i=1;i<=k;++i){
		for(ll j=0;j<n && v[j]<=i;++j){
			if(dp[i-v[j]]==-1){
				dp[i] = 1;
				break;
			}
		}
		if(dp[i]==0){
			dp[i] = -1;
		}
	}
}
int main(){
	fast;
	cin>>n>>k;
	//memset(d,0,sizeof(d));
	ll sum=0;
	for(ll i=0;i<n;++i){
		ll c;cin>>c;v.push_back(c);	
		sum +=c;
	}
	
	fun();
	if(dp[k]==1)
		cout<<"First";
	else
		cout<<"Second";
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <chrono>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    if (n < 0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    n--;
    ll ans = 0;
    for (int i = 1; i < n + 1; i++) {
        ans += n / i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if( (a==b&&a!=c) || (a==c&&a!=b) || (b==c&&a!=b) ) cout<<"Yes";
	else cout<<"No"; 
	return 0;
}

Measured memory_bytes: 3556
// 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;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll k,a,b;
    cin >> k;
    cin >> a >> b;

    bool flg = false;
    for(ll i=a; i<=b; i++){
        if( (i%k) == 0){
            flg = true;
            break;
        }
    }
    if(flg){
        cout << "OK" << endl;
    }else{
        cout <<"NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		Map<String, Integer> map = new HashMap<String, Integer>();
		try {
			sc = new Scanner(System.in);
			String maxFrequencyWord = "";
			String maxLengthWord = "";

			String[] sentence = sc.nextLine().split(" ");

			for (String s : sentence) {
				map.put(s, map.containsKey(s) ? map.get(s) + 1 : 1);
			}

			int maxFrequency = Collections.max(map.values());
			int maxLength = 0;

			for (Map.Entry<String, Integer> entry : map.entrySet()) {
				if (maxFrequency == entry.getValue()) {
					maxFrequencyWord = entry.getKey();
				}
				if (maxLength < entry.getKey().length()) {
					maxLength = entry.getKey().length();
					maxLengthWord = entry.getKey();
				}
			}
			System.out.println(maxFrequencyWord + " " + maxLengthWord);

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26076
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long n = sc.nextLong();
			
			List<String> initials = new ArrayList<>();
			
			long current = n;
			
			while(current > 0) {
				
				current--;
				
				long residual = current % 26;
				current = (current - residual) / 26;
				
				char initial = (char) ('a' + residual);				
				String initStr = String.valueOf(initial);
				
				initials.add(initStr);
				
			}
			
			Collections.reverse(initials);
			StringBuilder sb = new StringBuilder();
			for(String s : initials) {
				sb.append(s);
			}
			
			System.out.println(sb.toString());
		}
	}

}

Measured memory_bytes: 35564
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

bool tsort(const vector<vector<int>> &graph, vector<int> &ret){
  int n = graph.size();
  vector<int> indeg(n);
  REP(i,n){
    for(auto j : graph[i]){
      ++indeg[j];
    }
  }

  queue<int> q;
  REV(i,n-1,0){
    if(indeg[i] == 0) q.push(i);
  }

  while(!q.empty()){
    int cur = q.front(); q.pop();
    ret.push_back(cur);
    for(auto next : graph[cur]){
      --indeg[next];
      if(indeg[next]==0){
        q.push(next);
      }
    }
  }
  
  return (int)ret.size() == n;
}


int main(){
  int N;
  while(cin >> N){
    vector<vector<int>> A(N, vector<int>(N-1)); cin >> A;
    REP(i,N) for(auto &x : A[i]) --x;
    
    vector<vector<int>> m(N, vector<int>(N));
    {
      int k = 0;
      REP(i,N){
        FOR(j,i+1,N){
          m[i][j] = m[j][i] = k;
          ++k;
        }
      }
    }

    int sz = N*(N-1)/2;
    vector<vector<int>> g(sz);
    vector<int> deg(sz);
    
    REP(i,N){
      REP(j,A[i].size()-1){
        int x = i;
        int y = A[i][j];
        int z = A[i][j+1];

        int k = m[x][y];
        int l = m[x][z];
        g[k].push_back(l);

        deg[l]++;
      }
    }

    vector<int> ret;
    if(not tsort(g,ret)){
      cout << -1 << endl;
    }else{
      int ans = 0;

      vector<int> dp(sz, 1);

      REP(i,sz){
        int cur = ret[i];
        for(auto nxt : g[cur]){
          chmax(dp[nxt], dp[cur]+1);
        }
      }

      ans = *max_element(ALL(dp));

      cout << ans << endl;
    }
    
  }


  return 0;
}


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

int a[100005];
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int cur = 1, c = 0;
    for (int i = 0; i < n; i++) {
        if (cur == 2) {
            cout << c << endl;
            return 0;
        }
        c++;
        cur = a[cur];
    }
    cout << -1 << endl;
    return 0;
}

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

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

	long long n;
	int x, m;
	cin >> n >> x >> m;
	int prv = x;
	vector<bool> vis(m);
	vector<int> rep; rep.reserve((int) 1e6);
	while (!vis[prv]) {
		vis[prv] = 1;
		rep.push_back(prv);
		prv = (long long) prv * prv % m;
	}
	int i = 0;
	long long ans = 0;
	for (; i < (int) rep.size() && n; ++i) {
		if (rep[i] == prv) break;
		ans += rep[i];
		--n;
	}
	int period = (int) rep.size() - i;
	long long divs = n / period;
	int left = n % period;
	ans += ((long long) divs * accumulate(rep.begin() + i, rep.end(), (long long) 0) +
		accumulate(rep.begin() + i, rep.begin() + i + left, (long long) 0));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.size()<4){
    puts("No");
    return 0;
  }else if(s.substr(0,4)=="YAKI"){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
struct st{long double x,y,z;};
st v[101];
long double a1,a2,a3,sx,sy,sz,gx,gy,gz;
long double a4,a5,t[101],p[101];
long double ch(int q){
  long double px=v[q].x,py=v[q].y,pz=v[q].z;
  long double t1=sqrt((sx-gx)*(sx-gx)+(sy-gy)*(sy-gy)+(sz-gz)*(sz-gz));
  long double t2=sqrt((px-gx)*(px-gx)+(py-gy)*(py-gy)+(pz-gz)*(pz-gz));
  long double t3=sqrt((sx-px)*(sx-px)+(sy-py)*(sy-py)+(sz-pz)*(sz-pz));
  long double s=(t1+t2+t3)/2;
  long double h=sqrt(s*(s-t1)*(s-t2)*(s-t3))*2/t1;
  if(abs(sqrt(t2*t2-h*h)+sqrt(t3*t3-h*h)-t1)>0.1)return 100000000;
  return h;
}
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a1>>a2>>a3>>a4>>a5;
    v[i].x=a1;v[i].y=a2;v[i].z=a3;
    t[i]=a4;p[i]=a5;
  }
  while(m--){
    long long sum=0;
    cin>>sx>>sy>>sz>>gx>>gy>>gz;
    for(int i=0;i<n;i++){
      long double h=ch(i);
      if(h-0.000001<=(long double)(t[i]))sum+=p[i];
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 3400
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 111, K = 111;
int pos[N];
int n, k;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    cin >> n >> k;
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        cin >> pos[i];
        ans += 2 * min(pos[i], k - pos[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x,p=2019;
    long long int i,j;
    cin>>a>>b;

    if( a%2019==0 || b%2019==0 || (b-a)>=2019 || (a<2019 && b>2019) ) p=0;

    else{

        for(i=a;i<b;i++)
        {
            for(j=(i+1);j<=b;j++)
            {
                x=(i*j)%2019;

                if(x<p) p=x;
            }
        }
    }
    printf("%d\n",p);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int n,k,y,x;
int main(){
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>y>>x;
        cout<<min( min(y-1,x-1),min(n-x,n-y) )%3+1<<endl;
    }
}

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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int x[n + 1], y[n + 1], t[n + 1];
  t[0] = x[0] = y[0] = 0;

  for(int i = 1;i <= n;i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  for(int i = 1;i <= n;i++){
    if(t[i] - t[i - 1] >= abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])
    && (t[i] - t[i - 1]) % 2 == (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2){

    }else{
    cout << "No";
    return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int arr[16][16];
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  int ans = 0;
  negative(arr);
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  // fi(0, n)
  //   fj(0, n)
  //     cout << arr[i][j];
  int cnt, a, b;
  fi(0, n) {
    cin >> cnt;
    fj(0, cnt) {
      cin >> a >> b;
      arr[i][a - 1] = b;
    }
  }

  fi(0, (1 << n)) {
    int ng = 0;
    fj(0, n) {
      int ho = (i >> j) & 1;
      if(!ho) continue;
      fk(0, n) {
        if(arr[j][k] < 0) continue;
        // int val = ho == arr[j][k];
        // cout << val << "," << ((i >> k) & 1) << endl;
        if(((i >> k) & 1) != arr[j][k]) {
          ng = 1;
          break;
        }
      }
      if(ng) break;
    }
    if(!ng) {
      chmax(ans, __builtin_popcount(i));
    }
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair


int main(){
    int N,M; cin>>N>>M;
    int ballIn[N+1]; FILL(ballIn,N+1,1);
    int redIn[N+1] = {0};
    redIn[1] = 1;
    
    REP(count,M){
        int x,y; cin>>x>>y;
        
        ++ballIn[y];
        if(redIn[x]){
            redIn[y] = 1;
        }
        
        --ballIn[x];
        if(ballIn[x]==0){
            redIn[x] = 0;
        }
    }

    cout << accumulate(redIn,redIn+N+1,0) << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

//ty beet BellmanFord
template<typename T>
struct BellmanFord{
  struct edge{
    int u,v;
    T w;
    edge(){}
    edge(int u,int v,T w):u(u),v(v),w(w){}
  };

  int n;
  vector< vector<int> > G;
  vector<int> used,reach;
  BellmanFord(int n):n(n),G(n),used(n,0),reach(n,0){}

  vector<edge> es;
  void add_edge(int u,int v,T c){
    es.emplace_back(u,v,c);
    G[u].emplace_back(v);
  }
  //vから各点に到達できるか
  void dfs(int v){
    if(used[v]) return;
    used[v]=1;
    for(int u:G[v]) dfs(u);
  }

  /* bulidを呼び出すときは最初にnegLとか適当に変数定義して、
  int 最短経路コスト=G.build(s,g,negL)とかって使う
  negLの値に応じて場合分け等々*/
  T build(int from,int to,int &neg_loop){
    for(int i=0;i<n;i++){
      //iからtoへと到達できるか->reach配列に格納
      //これのおかげでゴールに到達しない負の閉路には反応しない
      fill(used.begin(),used.end(),0);
      dfs(i);
      reach[i]=used[to];
    }
    const T INFINF = numeric_limits<T>::max();
    vector<T> ds(n,INFINF);
    ds[from]=0;
    for(int j=0;j<n;j++){
      bool update=0;
      for(auto e:es){
        //reachが0->もうやる必要ない
        if(!reach[e.u]||!reach[e.v]||ds[e.u]==INFINF) continue;
        if(ds[e.v]>ds[e.u]+e.w){
          ds[e.v]=ds[e.u]+e.w;
          update=1;
        }
      }
      if(!update) break;
      if(j==n-1){
        //負のループがなければn回以上の更新は起きない
        neg_loop=1;
        return INFINF;
      }
    }
    neg_loop=0;
    return ds[to];
  }
};

int main(){
    int n,m;
    cin>>n>>m;
    BellmanFord<ll> B(n);
    rep(i,m){
        int a,b;ll c;
        cin>>a>>b>>c;
        a--;b--;
        B.add_edge(a,b,-c);
    }
    int neg_loop=0;
    ll ans=B.build(0,n-1,neg_loop);
    if(neg_loop){
        cout<<"inf"<<endl;
    }
    else{
        cout<<-ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 384
defmodule Main do
def main do
  n = IO.gets("") |> String.trim() |> String.to_integer()
  IO.stream(:stdio, :line) 
  |> Enum.take(n)
  |> Enum.map(&String.trim(&1)) 
  |> Enum.frequencies()
  |> solve()
  end
  
  def solve(ans) do
    "AC x " <> (Map.get(ans, "AC", 0) |> Integer.to_string()) |> IO.puts()
    "WA x " <> (Map.get(ans, "WA", 0) |> Integer.to_string()) |> IO.puts()
    "TLE x " <> (Map.get(ans, "TLE", 0) |> Integer.to_string()) |> IO.puts()
    "RE x " <> (Map.get(ans, "RE", 0) |> Integer.to_string()) |> IO.puts()
  end
end

Measured memory_bytes: 76008
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;


#define VMAX (100000)
vector<int> G[VMAX];
bool visited[VMAX] = { false };
int prenum[VMAX];	/*	各頂点のDFSによる訪問の順番 */
int parent[VMAX];	/*	DFSによって生成される木Tにおける親 */
int lowest[VMAX];	/*	以下の内の最小値
						1. prenum[u]
						2. Backedge(u, v)が存在する場合、prenum[v]
							※ Backedge(u, v): 頂点uからvに向かうTに属さないGのエッジ
						3. Tに属するすべての子xに対するlowest[x] */
int timer = 1;

void dfs(int current, int prev)
{
	int next;

	prenum[current] = timer;
	lowest[current] = timer;
	timer++;

	visited[current] = true;

	rep(i, G[current].size()) {
		next = G[current][i];

		if (!visited[next]) {
			parent[next] = current;
			dfs(next, current);
			lowest[current] = min(lowest[current], lowest[next]);
		}
		else if (next != prev) {
			/* Backedgeのパターン */
			lowest[current] = min(lowest[current], prenum[next]);
		}
	}
}

/* ================================================================================ */
/* [1] Tのルートrが2つ以上の子供をもつとき、rは関節点								*/
/* [2] 各頂点uにおいて、uの親をpとすると、prenum[p] <= lowest[u] ならば、pは関節点	*/
/*     ※ uの子孫からpへのエッジがない												*/
/* ================================================================================ */
void art_points(int N)
{
	set<int> ap;
	set<int>::iterator it;
	int np = 0;
	int p;

	dfs(0, -1);

	repc(i, 1, N - 1) {
		p = parent[i];
		if (p == 0) np++;
		else if (prenum[p] <= lowest[i]) ap.insert(p);
	}

	if (np > 1) ap.insert(0);
	for (it = ap.begin(); it != ap.end(); it++) cout << *it << endl;
}

int main()
{
	int V, E;
	int s, t;

	cin >> V >> E;
	rep(i, E) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	art_points(V);

	return 0;
}


Measured memory_bytes: 6832
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	static final long MOD = 1000000007;
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		char[] vals = sc.next().toCharArray();
		long[] cant = new long[26];
		for (int i = 0; i < vals.length; i++) {
			cant[vals[i] - 'a']++;
		}
		long ans = 1;
		for (int i = 0; i < cant.length; i++) {
			ans *= 1 + cant[i];
			ans %= MOD;
		}
		ans += MOD - 1;
		ans %= MOD;
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 24532
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int n,m,inde[100005],tot;
struct p{
	int c[4];
	bool operator < (const p & a)const{
		if(c[0]!=a.c[0]) return c[0]<a.c[0];
		if(c[1]!=a.c[1]) return c[1]<a.c[1];
		if(c[2]!=a.c[2]) return c[2]<a.c[2];
		return c[3]<a.c[3];
	}
}col[405];
map<p,int> mp;
void add(p x,int val){
	p now=x,nxt;
	mp[now]+=val;
	for(int j=1;j<=3;j++){
		for(int i=0;i<=3;i++) nxt.c[i]=now.c[(i+1)%4];
		now=nxt;
		mp[now]+=val;
	}
}
int main(){
	int i,j,u,v,e,w;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);
	n=read();
	for(i=1;i<=n;i++)
		col[i].c[0]=read(),col[i].c[1]=read(),col[i].c[2]=read(),col[i].c[3]=read();
	for(i=1;i<=n;i++) 
		add(col[i],1);
	ll ans=0,S;
	for(i=1;i<=n-5;i++){
		add(col[i],-1);
		for(j=i+1;j<=n;j++){
			add(col[j],-1);
			p now,nxt=col[j],pj;
			for(e=1;e<=4;e++){
				now=nxt;
				S=1;
				for(w=0;w<=3;w++) nxt.c[w]=now.c[(w+1)%4];
				for(w=0;w<=3;w++){
					pj=(p){col[i].c[(w+1)%4],col[i].c[w],now.c[3-w],now.c[3-(w+1)%4]};
					S*=mp[pj];
					if(!mp[pj]) break;
					else add(pj,-1);
				}
				w--;
				for(;w>=0;w--){
					pj=(p){col[i].c[(w+1)%4],col[i].c[w],now.c[3-w],now.c[3-(w+1)%4]};
					add(pj,1);
				}
				ans+=S;
			}
			add(col[j],1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
8
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
*/

Measured memory_bytes: 23676
/* ***********************************************************************************************************
									Created By - TANISHQ GUPTA (tanishq_code_c)								
**************************************************************************************************************/

#include <bits/stdc++.h>



using namespace std;
#define int             long long
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl             "\n"
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}


void stringsplitter(string s, string delim,string arr[]){
	char *ptr = strtok((char *)s.c_str(), (char *)delim.c_str());
	int i=0;
	while(ptr!=NULL){
		arr[i]=((string)ptr);
		ptr = strtok(NULL,(char *)delim.c_str());
		i++;
	}
}

int string_to_int(string s){
	int ans = 0;
	int p=1;
	for(int i=s.size()-1;i>=0;i--){
		ans += (s[i]-'0')*p;
		 p *= 10;
	}
	return ans;
}

void t_c_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	int n;
	for(int i=1;i<6;i++){
		cin >> n;
		if(n==0){
			cout << i << endl;
			break;
		}
	}

}

int32_t main()
{
	t_c_c();
	return 0;
}


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

int main() {
 string S;
 cin >> S;
 if ( S == "SAT" ){
 	cout << 1 << endl;
 }
 else if ( S == "SUN" ){
 	cout << 7 << endl;
 }
 else if ( S == "MON" ){
 	cout << 6 << endl;
 }
 else if ( S == "TUE" ){
 	cout << 5 << endl;
 }
 else if ( S == "WED"){
   cout << 4 << endl;
 }
 else if ( S == "THU"){
   cout << 3 << endl;
 } 
 else if ( S == "FRI"){
   cout << 2 << endl;
 }
  }




Measured memory_bytes: 256
import sys, string

H, W = map(int, input().split())

alpha = [0 for i in range(26)]

for _ in range(H):
    a = input()
    for i, char in enumerate(string.ascii_lowercase):
        alpha[i] += a.count(char)

for i in range(H//2):
    for j in range(W//2):
        f = False
        for k in range(26):
            if alpha[k] >= 4:
                f = True
                alpha[k] -= 4
                break

        if not f:
            print('No')
            exit()

print(alpha, file=sys.stderr)

if H % 2 == 1:
    for j in range(W // 2):
        f = False
        for k in range(26):
            if alpha[k] >= 2:
                f = True
                alpha[k] -= 2
                break

        if not f:
            print('No')
            exit()

print(alpha, file=sys.stderr)

if W % 2 == 1:
    for i in range(H // 2):
        f = False
        for k in range(26):
            if alpha[k] >= 2:
                f = True
                alpha[k] -= 2
                break

        if not f:
            print('No')
            exit()

print(alpha, file=sys.stderr)
print('Yes')

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

using namespace std;

int main() {
    int N;

    scanf("%d", &N);
    vector<int> hs(N), dp(N);

    for (int i = 0; i < N; i++)
        scanf("%d", &hs[i]);

    dp[0]= 0;
    for (int i = 1; i < N; i++) {
        int mn = 1e9 + 5;
        if (i > 1)
            mn = min(mn, dp[i - 2] + abs(hs[i] - hs[i - 2]));
        mn = min(mn, dp[i - 1] + abs(hs[i] - hs[i - 1]));
        dp[i] = mn;
    }

    printf("%d\n", dp[N - 1]);

    return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int[] A = readArray(sc, N);
        int[] B = readArray(sc, N);
        int[] C = readArray(sc, N);

        System.out.println(solve(A, B, C));

        sc.close();
    }

    static int[] readArray(Scanner sc, int size) {
        int[] result = new int[size];
        for (int i = 0; i < result.length; ++i) {
            result[i] = sc.nextInt();
        }

        return result;
    }

    static long solve(int[] A, int[] B, int[] C) {
        A = Arrays.stream(A).boxed().sorted().mapToInt(x -> x).toArray();
        C = Arrays.stream(C).boxed().sorted().mapToInt(x -> x).toArray();

        int[] A_ = A;
        int[] C_ = C;
        return Arrays.stream(B).mapToLong(b -> (long) computeLessNum(A_, b) * computeGreaterNum(C_, b)).sum();
    }

    static int computeLessNum(int[] values, int target) {
        int index = -1;
        int lower = 0;
        int upper = values.length - 1;
        while (lower <= upper) {
            int middle = (lower + upper) / 2;
            if (values[middle] < target) {
                index = middle;
                lower = middle + 1;
            } else {
                upper = middle - 1;
            }
        }

        return index + 1;
    }

    static int computeGreaterNum(int[] values, int target) {
        int index = values.length;
        int lower = 0;
        int upper = values.length - 1;
        while (lower <= upper) {
            int middle = (lower + upper) / 2;
            if (values[middle] > target) {
                index = middle;
                upper = middle - 1;
            } else {
                lower = middle + 1;
            }
        }

        return values.length - index;
    }
}

Measured memory_bytes: 93324
N = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0
for i in range(N):
    name = input()
    if name[0] == "M":
        M += 1
    if name[0] == "A":
        A += 1
    if name[0] == "R":
        R += 1
    if name[0] == "C":
        C += 1
    if name[0] == "H":
        H += 1


totalM = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H
totalA = A*R*C + A*R*H + A*C*H
totalR = R*C*H
total = totalM + totalA + totalR
print(total)

Measured memory_bytes: 3064
/*
       ()       ()()()()     ()        ()       ()        ()        ()
      ()()      ()     ()    ()()      ()      ()()       ()()      ()
     ()  ()     ()      ()   ()  ()    ()     ()  ()      ()  ()    ()
    ()()()()    ()      ()   ()    ()  ()    ()()()()     ()    ()  ()
   ()      ()   ()     ()    ()      ()()   ()      ()    ()      ()()
  ()        ()  ()()()()     ()        ()  ()        ()   ()        ()

*/
#include <bits/stdc++.h>
#define MOD 1e9+7
#define SIZE (int)1e5+5
#define all(x) x.begin(),x.end()

#define si(i)  scanf("%d",&i)
#define sf(f)  scanf("%f",&f)
#define pi(i)  printf("%d",i)
#define pd(d)  printf("%lf",d)
#define deb(x) cout<<#x<<" is "<<x<<"\n";
#define lb     lower_bound
#define ub     upper_bound
#define pb     push_back

#define IOfast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

int64_t exponentiation(int64_t base,int exp)
{
    if (exp == 0)
        return 1;

    if (exp == 1)
        return base;

    int64_t t = exponentiation(base, exp / 2);

    t = (t * t);

    if (exp % 2 == 0)
        return t;
    else
        return base * t;
}

int dp[3002][3003];

void solve(int i,int j,string s1,string s2)
{
  if(i==0 || j==0)
    return;
  if(s1[i-1] == s2[j-1] )
  {
    solve(i-1,j-1,s1,s2);
    cout<<s1[i-1];
    return ;
  }
  
  if(dp[i][j] == dp[i-1][j])
  {
    solve(i-1,j,s1,s2);
    return ; 
  }
  else
  {
    solve(i,j-1,s1,s2);
    return ; 
  }  

}

int main()
{
  IOfast;
  

  int q=1;
  //cin>>q;
  //memset(dp,-1,sizeof(dp));
  while(q--)
  {
    string s1,s2;
    cin>>s1>>s2;
    
    for(int i=1;i<=s1.size();i++)
    {
      for(int j=1;j<=s2.size();j++)
      {
        if(s1[i-1] == s2[j-1])
          dp[i][j] = dp[i-1][j-1]+1;
        else
          dp[i][j] = max( dp[i-1][j],dp[i][j-1]);  
      }
    }
    
    solve(s1.size(),s2.size(),s1,s2);

  }
  
  return 0;
}


Measured memory_bytes: 65664
// finish date: 2018/05/05
#include <bits/stdc++.h>


using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    vi a(N);
    int n = 0;
    int temp = 55555;
    while (n < N) {
        if (temp % 5 != 1) goto outer;
        FOR(i, 2, sqrt(temp + 1)) {
            if (temp % i == 0) goto outer;
        }
        a[n] = temp;
        n++;
        outer:;
        temp--;
    }
    rep(i, N) cout << a[i] << " ";
    cout << endl;

    return 0;
}

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

struct record{
 int a;
 int b;
};

int check;

int main(void){
  
  int i,n;
  struct record r[n];
  if(scanf("%d",&n)==1) for(i=0;i<n;i++) {
    if( scanf("%d",&r[i].a)==1 ) ;
    if( scanf("%d",&r[i].b)==1 ) ;
  }
  
  for(i=0;i<n;i++){
    if(r[i].a==r[i].b) check++;
    else check=0;
    if(check >= 3) break;
  }
  
  if(check >= 3) printf("Yes\n");
  else  printf("No\n");
  
  return 0;
}

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

struct card{
	char suit;
	int num;
};

int out_card(vector<card> &A,int n){
	int i;
	for (i=0;i<=n-2;i++){
		cout << A[i].suit << A[i].num <<" ";
	}
	cout << A[n-1].suit << A[n-1].num <<endl;
}

void BubbleSort(vector<card> &A, int n){
	int i,j;
	for (i=0;i<n;i++){
		for (j=n-1;j>i;j--){
			if (A[j].num < A[j-1].num){
				swap(A[j],A[j-1]);
			}
		}
	}
}

void SelectSort(vector<card> &A, int n){
	int i,j,minj;
	for(i=0;i<n;i++){
		minj=i;
		for (j=i;j<n;j++){
			if (A[j].num<A[minj].num){
				minj=j;
			}
		}
		swap(A[i],A[minj]);
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,i;
	cin >> n;
	
	vector<card> C(n),D(n);
	for (i=0;i<n;i++){
		cin >> C[i].suit >> C[i].num;
		D[i].suit=C[i].suit;
		D[i].num=C[i].num;
	}
	
	SelectSort(C,n);
	BubbleSort(D,n);
	
	out_card(D,n);
	cout << "Stable" <<endl;
	
	out_card(C,n);
	int flag=0;
	for(i=0;i<n;i++){
		if((C[i].suit != D[i].suit)||(C[i].num != D[i].num)){
			flag=1;
		}
	}
	if (!flag){
		cout <<"Stable" <<endl;
	}else{
		cout <<"Not stable" <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	
	for(int i=0;i<=x;i++)
	{
		int v=2*(x-i)+4*i;
		if(v==y)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int64_t X;
  cin >> X;
  int N = 0;
  int64_t S = 100;
  
  while (S < X) {
    N += 1;
    S = floor(S * 1.01);
    //cout << S << endl;
  }
  
  cout << N << endl;
}

Measured memory_bytes: 3740
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.endl(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 998244353  // prime;
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);
}
// int size = 200001;  // e6 + 1
vector<ll> fac;   // n!(mod M)
vector<ll> ifac;  // k!^{M-2} (mod M)
vector<ll> inv;   // k!^{M-2} (mod M)
////////////////////////////////////////////////
void fac_mod(int size) {
  // fac[i] = i! (mod M)
  fac.resize(size);
  fac[0] = 1;
  fac[1] = 1;
  int n = fac.size();
  for (int i = 0; i < n - 1; i++) {
    fac[i + 1] = fac[i] * (i + 1) % MOD;
  }
}
////////////////////////////////////////////////
void ifac_mod(int size) {
  // ifac[i] = 1/i! (mod M)
  ifac.resize(size);
  inv.resize(size);
  ifac[0] = 1;
  ifac[1] = 1;
  inv[1] = 1;
  int n = ifac.size();
  for (int i = 2; i < n - 1; i++) {
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }
}
////////////////////////////////////////////////
void nCk_init(int m) {
  if (m <= 0) {
    cout << "error! invalid m val: m = " << m << endl;
  }
  fac_mod(m + 1);
  ifac_mod(m + 1);
}
////////////////////////////////////////////////
ll nCk_mod(ll n, ll k) {
  // nCk (mod M)
  if (n == 0 && k == 0) return 1;
  if (n < k || k < 0) return 0;
  return fac[n] * (ifac[n - k] * ifac[k] % MOD) % MOD;
}
////////////////////////////////////////////////
ll pow_mod(ll x, int n) {
  // x^n (mod M)
  ll pow = 1;
  while (n != 0) {
    if (n & 1) pow = pow * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return pow;
}
////////////////////////////////////////////////
int main() {
  init();
  ll n, m, k;
  cin >> n >> m >> k;
  nCk_init(n);
  vector<ll> mpow(n, 0);
  vector<ll> ncj(n, 0);
  REP(i, n) {
    mpow[i] = pow_mod((ll)(m - 1), i);
    ncj[i] = nCk_mod((n - 1), i);
  }
  ll ans = 0;
  REP(i, k + 1) {
    // cout << mpow[n - 1 - i] << " " << ncj[i] << " "
    //  << ((m * mpow[n - 1 - i]) % MOD * ncj[i]) % MOD << endl;
    ans += ((m * mpow[n - 1 - i]) % MOD * ncj[i]) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
main(){
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++){
		if(!(i%3==0 or i%5==0)) sum+=i;
	}
	cout<<sum;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename Ostream,typename Container>
Ostream& operator<<(Ostream& os,const Container& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

struct UnionFind{
	vi data;
	UnionFind(int n):data(n,-1){}
	int Find(int i){
		return data[i]<0?i:(data[i]=Find(data[i]));
	}
	bool Unite(int a,int b){
		tie(a,b)=mt(Find(a),Find(b));
		if(a==b) return false;
		if(-data[a]<-data[b]) swap(a,b);
		tie(data[a],data[b])=mt(data[a]+data[b],a);
		return true;
	}
};

int ModPow(int a,int r,int m)
{
	ll x=1;
	per(i,32){
		x=x*x%m;
		if(r>>i&1)
			x=x*a%m;
	}
	return x;
}

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		UnionFind uf(n);
		int cc=n;
		rep(i,m){
			int a,b; cin>>a>>b; a--,b--;
			cc-=uf.Unite(a,b);
		}
		ll res=ModPow(2,cc,MOD);
		if(cc<n) res=(res+1)%MOD;
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1584
import java.util.Scanner;

public class Main {

    public static int aa = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < s.length() - 2; i ++) {
//            System.out.println(s.substring(i, i+3));
            min = Math.min(min, Math.abs(Math.min(min, Integer.valueOf(s.substring(i, i+3))-753)));
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 22996
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer x = Integer.parseInt(scanner.next());
        Integer y = Integer.parseInt(scanner.next());

        List<Integer> total = new ArrayList<Integer>();
        int count =0;
        int warizan = x;
        for(;;) {
            if (warizan < y) {
                count++;
                break;
            }
            int zyouyo = x % y;
            warizan = warizan / y;
            count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int h,n;
    cin>>h>>n;
    int a[n];
    
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    
    int d = accumulate(a, a+n, 0);
    bool r = (h<=d ? true : false);
    
    cout << (r ? "Yes" : "No") << "\n";
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
long long n;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    long long cur=1,ans=0;
    while(n){
        n/=2;
        ans+=cur;
        cur*=2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <iostream>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int Max = 1e6 + 5;
int k, n, a[Max];

int main() {
    scanf("%d %d", &k, &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    int ans = inf;
    for (int i = 1; i <= n; i++) {
        int p1 = inf, p2 = inf;
        if(i == 1) {
            p1 = a[n] - a[1];
            p2 = a[1] + (k - a[2]);
        }
        else if(i == n) {
            p1 = (k - a[n]) + a[n - 1];
            p2 = a[n] - a[1];
        }
        else {
            p1 = (k - a[i]) + a[i - 1];
            p2 = a[i] + (k - a[i + 1]);
        }
        ans = min(ans, min(p1, p2));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
a,b,c,x,y = gets.split.map(&:to_i)
ans = a*x + b*y
n = [x,y].max
(n+1).times do |z|
  tmp = a*[0,x-z].max + b*[0,y-z].max + c*z*2
  ans = tmp if tmp < ans
end
p ans


Measured memory_bytes: 1788
#include <bits/stdtr1c++.h>

using namespace std;
set<char> st;

int main() {
    string s;
    cin >> s;
    int len = s.length();
    for (int i = 0; i < len; i++) st.insert(s[i]);
    if (len != 26) {
        cout << s;
        for (char i = 'a'; i <= 'z'; i++) {
            if (st.count(i)) continue;
            cout << i << endl;
            return 0;
        }
    }
    string s2 = s;
    if (!next_permutation(s2.begin(), s2.end())) return !printf("-1\n");
    for (int i = 0; i < len; i++) {
        printf("%c", s2[i]);
        if (s2[i] != s[i]) break;
    }
    puts("");
}



Measured memory_bytes: 256