akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p,left,right;
};

Node T[MAX];
int n,dep[MAX],h[MAX];

void Depth(int a,int da){
  if(a == NIL){
    return ;
  }
  dep[a] =da;
  Depth(T[a].left,da+1);
  Depth(T[a].right,da+1);
}

int Height(int a){
  int ha1 = 0,ha2 =0;
  if(T[a].left!= NIL){
    ha1 = Height(T[a].left)+1;
  }
  if(T[a].right !=NIL){
    ha2 = Height(T[a].right)+1;
  }
  return h[a]=(ha1 > ha2 ? ha1 : ha2);
}

int getSibling(int sa){
  if(T[sa].p ==NIL){
    return NIL;
  }
  if(T[T[sa].p].left != sa && T[T[sa].p].left != NIL){
    return T[T[sa].p].left;
  }
  if(T[T[sa].p].right != sa && T[T[sa].p].right != NIL){
    return T[T[sa].p].right;
  }
  return NIL;
}

void print(int u){
  printf("node %d: ", u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getSibling(u));
  int deg=0;
  if(T[u].left != NIL){
    deg++;
  }
  if(T[u].right != NIL){
    deg++;
  }
  printf("degree = %d, ",deg);
  printf("depth = %d, ",dep[u]);
  printf("height = %d, ",h[u]);

  if(T[u].p == NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right ==NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int d,l,r,root,i = 0;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p = NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&d,&l,&r);
    T[d].left = l;
    T[d].right = r;
    if(l != NIL){
      T[l].p =d;
    }
    if(r != NIL){
      T[r].p = d;
    }
  }
    for(i=0;i<n;i++){
      if(T[i].p ==NIL){
	root = i;
      }
    }
    Depth(root,0);
    Height(root);

    for(int i=0;i<n;i++){
      print(i);
    }

    return 0;
  }




Measured memory_bytes: 2760
import java.util.*;
public class Main {

    public static void main(String __[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        String arr[] = new String[N];
        for(int i=0; i< arr.length; i++){
            arr[i] = sc.next();
        }
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr).replaceAll("\\[|\\]|\\,|\\s", ""));

    }
}

Measured memory_bytes: 23764
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
P za[100005];
int main()
{
	srand((unsigned int)time(NULL));
	int n,x,y;  scanf("%d",&n);
	int lx=INF,ly=INF,rx=-INF,ry=-INF;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		za[i]=mp(x+y,x-y);
		lx=min(lx,x+y);
		rx=max(rx,x+y);
		ly=min(ly,x-y);
		ry=max(ry,x-y);
	}
	int ret1=0,ret2=0;
	for(int i=0;i<n;i++)
	{
		//(lx,ly)(rx,ry)
		ret1=max(ret1,min(max(za[i].f-lx,za[i].s-ly),max(rx-za[i].f,ry-za[i].s)));
		//(lx,ry)(rx,ly)
		ret2=max(ret2,min(max(za[i].f-lx,ry-za[i].s),max(rx-za[i].f,za[i].s-ly)));
	}
	printf("%d\n",min(ret1,ret2));
}

Measured memory_bytes: 1968
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<long long>
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = 998244353;
const ll INF = (ll)1e9+1;
const ll N = 1e5;

ll ans = 0;
int n;
string str;
map<char, ll> mp;

#define M mp['M']
#define A mp['A']
#define R mp['R']
#define C mp['C']
#define H mp['H']

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
   // freopen("B.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> str;
        mp[str[0]]++;
    }
    ans += M * A * R;
    ans += M * A * C;
    ans += M * A * H;
    ans += M * R * C;
    ans += M * C * H;
    ans += M * R * H;
    ans += A * R * C;
    ans += A * R * H;
    ans += A * C * H;
    ans += R * C * H;
    cout << ans;
}


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

public class Main{
  static char[] s;

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

    s = sc.next().toCharArray();

    int min = s.length - 1;
    for(char ch = 'a'; ch <= 'z'; ch++){
      char[] t = Arrays.copyOf(s, s.length);
      int len = t.length;
      int count = 0;
      while(len > 1){
        boolean check = true;
        for(int i = 0; i + 1 < len; i++){
          if(t[i] != t[i + 1]){
            check = false;
            break;
          }
        }
        if(check){
          break;
        }
        for(int i = 0; i + 1 < len; i++){
          if(t[i + 1] == ch){
            t[i] = ch;
          }
        }
        --len;
        ++count;
      }
      min = Math.min(min, count);
    }

    System.out.println(min);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

void chmin(int &a, int b){
    a = min(a,b);
}

int dp[1<<18][55];

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    for(int i=0;i<(1<<n);i++){
        fill(dp[i], dp[i]+55, IINF);
    }
    dp[0][0] = 0;
    for(int S=0;S<(1<<n);S++){
        for(int j=0;j<=50;j++){
            if(dp[S][j] == IINF) continue;
            int cnt = 0, p = 0;
            for(int i=0;i<n;i++){
                cnt += (S>>i)&1;
            }
            for(int i=0;i<n;i++){
                if((S>>i)&1){
                    cnt--;
                    continue;
                }
                if(((p&1)^(cnt&1))==0){
                    if(j <= a[i]){
                        chmin(dp[S|(1<<i)][a[i]], dp[S][j]+p);
                        // cout << S << " " << j << " " << i << " " << a[i] << " a" << endl;
                    }
                }
                else{
                    if(j <= b[i]){
                        chmin(dp[S|(1<<i)][b[i]], dp[S][j]+p);
                        // cout << S << " " << j << " " << i << " " << b[i] << " b" << endl;
                    }
                }
                p++;
            }
        }
    }
    int ans = IINF;
    for(int i=0;i<=50;i++){
        chmin(ans, dp[(1<<n)-1][i]);
    }
    if(ans < IINF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    // for(int i=0;i<1<<n;i++){
    //     for(int j=0;j<5;j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 56704
#include<bits/stdc++.h>
#define size 100000
#define mod 1000000007
#define ll long long 
#define pb push_back
using namespace std;
vector<vector<int>> v(size+1);
ll dp[size+1][2];
bool vis[size+1][2];
ll solve(int src,int col,int par)
{
	if(dp[src][col]!=-1)
		return dp[src][col];
	ll ans=0;
    ll left=1;
	for(auto it=v[src].begin();it!=v[src].end();it++)
	{
		auto nbr=*it;
		if(nbr!=par)
            left=(left%mod*solve(nbr,0,src)%mod)%mod;	
	}
    ans=(ans+left)%mod;
    if(col==0){
        ll right=1;
	    for(auto it=v[src].begin();it!=v[src].end();it++)
	    {
		    auto nbr=*it;
		    if(nbr!=par)
		    {
			    right=(right*solve(nbr,1,src))%mod;
	    	}	
	    }
        
    ans=(ans+right)%mod;

    }
	return dp[src][col]=ans;
}
int main()
{
	int n;
	cin>>n;
	int degree[n+1]={};
	memset(dp,-1,sizeof(dp));
	memset(vis,false,sizeof(vis));
	
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
		degree[x]++;
		degree[y]++;
	}
	
	cout<<solve(1,0,-1)%mod<<"\n";
    
	return 0;
}

Measured memory_bytes: 17632
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#define MAX_INT 2147483647
#define MAX_DOUBLE 1e9
#define MODULO 1000000007

using namespace std;
long long X,Y;

typedef pair<int, int> P;

int solve() {
	int ans  = 0;
  scanf("%lld %lld", &X, &Y);
  while(X <= Y) {
    X *= 2;
    ans++;
  }
  printf("%d\n", ans);
}

int main(int args, char* argv[]) {
  solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
	chutiyaap;
    int n,m;cin>>n>>m;
    int y,x=((n)*(n-1))/2;
    if(m>1)y=(m*(m-1))/2;
    else y=0;
    cout<<x+y;

}

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

using namespace std;

typedef long long ll;

int main(){
        ll N;
        cin>>N;
        vector <ll> a(N), b(N), c(N);
        for(ll i=0;i<N;i++){
                cin>>a[i];
        }
        for(ll i=0;i<N;i++){
                cin>>b[i];
        }
        for(ll i=0;i<N;i++){
                cin>>c[i];
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        sort(c.begin(), c.end());
        ll res=0;
        for(ll i=0;i<N;i++){
                ll aa=lower_bound(a.begin(), a.end(), b[i])-a.begin();
                ll cc=upper_bound(c.begin(), c.end(), b[i])-c.begin();
                res+=(aa*(N-cc));
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

	public class Main {

		static long mod = 1000000007;

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			String[] t = sc.nextLine().split(" ");
			int n  = Integer.parseInt(t[0]);
			long k = Long.parseLong(t[1].replaceAll("\\.", ""));


			StringBuilder sb = new StringBuilder();

			long x  = k == 100 ? 101 : k;
			sb.append(x);

			switch(n) {
				case 1:{
					sb.append("00");
					break;
				}
				case 2:{
					sb.append("0000");
					break;
				}
			}
			System.out.println(sb.toString());
		}
	}

Measured memory_bytes: 35624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

bool ok(char i) {
    bool ret = 0;
    string a = "MARCH";
    for (char j : a)ret |= (i == j);
    return ret;
}

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

    int n;
    cin >> n;
    string s;
    map<char, int> m;
    FOR(i, 0, n) {
        cin >> s;
        m[s[0]]++;
    }

    ll ans = 0;
    vector<ll> a;
    for (auto i : m)if(ok(i.first))a.push_back(i.second);
    FOR(i, 0, a.size())FOR(j, i + 1, a.size())FOR(k, j + 1, a.size()) {
        ans += a[i] * a[j] * a[k];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

long long gcd(long long x,long long y){
  if(y == 0) return x;
  return gcd(y,x%y);
}

int main(void){
  int N;
  scanf("%d",&N);

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

  int L[N+1],R[N+1];
  L[0] = R[N] = 0;
  for(int i = 0;i < N;i++){
    L[i+1] = gcd(L[i],A[i]);
  }

  for(int i = N;i > 0;i--){
    R[i-1] = gcd(R[i],A[i-1]);
  }

  int ans = 0;
  for(int i = 0;i < N;i++){
    ans = max(ans,gcd(L[i],R[i+1]));
  }


  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 1280
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
int d(int n)
{
    int count=0;
    while(n)
    {
        n=n/10;
        count++;
    }
    return count;
}
int32_t main()
{
    IOS
    
    
    
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
        cin>>a[i];
    if(a[0]!=1)
        a[0]--;
    for(int i=1;i<n;++i)
    {
        if(a[i]>a[i-1])
            a[i]--;
    }
    int check=0;
    for(int i=1;i<n;++i)
    {
        if(a[i]<a[i-1])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

}



Measured memory_bytes: 1024
from operator import add
import sys
input = sys.stdin.buffer.readline

class BIT():

    def __init__(self, length_or_list, func, e):
        self.func = func
        self.e = e
        if isinstance(length_or_list, int):
            self.n = length_or_list + 1
            self.data = [self.e] * self.n
        else:
            self.n = len(length_or_list) + 1
            self.data = [self.e] + length_or_list
            for i in range(1, self.n):
                self.data[i + (i & -i)] = self.func(self.data[i + (i & -i)], self.data[i])        

    def point_append(self, index, delta):
        index += 1
        while index < self.n:
            self.data[index] = self.func(self.data[index], delta)
            index += index & -index
        
    def prefix_folded(self, end):
        res = 0
        while end > 0:
            res = self.func(res, self.data[end])
            end -= end & -end
        return res


N, Q = map(int, input().split())
cs = list(map(int, input().split()))
lrs = [tuple(map(int, input().split())) for _ in range(Q)]

#クエリを終了位置rでソート。
ilrs = sorted(((i, l-1, r-1) for i, (l, r) in enumerate(lrs)), key = lambda t: t[2])

#重複を区間としてし、終了位置でソートされた状態で列挙。
duplicates = []
indices = [-1 for _ in range(N+1)]
for i, c in enumerate(cs):
    if indices[c] != -1:
        duplicates.append((indices[c], i))
    indices[c] = i

#あとは平面走査と呼ばれる探査
ilrs.reverse()
duplicates.reverse()
starts = BIT(N, add, 0)
ans = [-1] * Q
for i in range(N):
    if duplicates and duplicates[-1][1] == i:
        dupstart, _ = duplicates.pop()
        starts.point_append(dupstart, 1)
    while ilrs[-1][2] == i:
        ans_i, l, r = ilrs.pop()
        ans[ans_i] = (r - l + 1) - (starts.prefix_folded(r + 1) - starts.prefix_folded(l))
        if not ilrs:
            break
    else:
        continue
    break

print(*ans, sep = '\n')

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

int main(){
  int N,num,count=0,k=0,ans=1;
  cin >> N;
  for(int i=1;i<=N;i++){
   num = i;
   count = 0; 
   while(num%2 == 0){
     num/=2;
     count++;
   }
   if(k<count) { 
     k = count;
     ans = i;
   }
  }
  cout << ans << endl;
} 


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		final int L = 100000;
		int[][] cnt = new int[2][L];
		for(int i=0; i<N/2; i++) {
			cnt[0][sc.nextInt()-1]++;
			cnt[1][sc.nextInt()-1]++;
		}
		
		int[] maxIndex = new int[2];
		
		for(int i=0; i<2; i++)
			for(int j=0; j<L; j++)
				if(cnt[i][j] > cnt[i][maxIndex[i]])
					maxIndex[i] = j;
		if(maxIndex[0]==maxIndex[1]) {
			Arrays.sort(cnt[0]);
			Arrays.sort(cnt[1]);
			System.out.println(Math.min(N - cnt[0][L-1] - cnt[1][L-2], N - cnt[0][L-2] - cnt[1][L-1]));
		} else {
			System.out.println(N - cnt[0][maxIndex[0]]-cnt[1][maxIndex[1]]);
		}
		
		sc.close();
	}
}


Measured memory_bytes: 63208
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def dfs(graph: list, node: int, start: int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF] * node

    # 始点ノードの距離を0とし、dfsのためのstackを作成
    dist[start] = 0
    stack = [(0, start)]

    while stack:
        cost, cur_node = stack.pop()

        # 未探索のノードをstackに入れる
        for nex_cost, nex_node in graph[cur_node]:
            if dist[nex_node] != INF:
                continue
            else:
                dist[nex_node] = dist[cur_node] + nex_cost
                stack.append((dist[nex_node], nex_node))

    return dist


n, m, p = li()
edges = []
for _ in range(m):
    ai, bi, ci = li()
    ai -= 1
    bi -= 1
    ci -= p
    edges.append((ai, bi, ci))

# グラフ構築
one2n = [[] for _ in range(n)]
n2one = [[] for _ in range(n)]
for ai, bi, _ in edges:
    one2n[ai].append((ci, bi))
    n2one[bi].append((ci, ai))

# 1から到達可能な点を抽出
one2n_dist = dfs(one2n, n, 0)
one2n_reachable = set()
for i, di in enumerate(one2n_dist):
    if di != float('inf'):
        one2n_reachable.add(i)

# Nから到達可能な点を抽出
n2one_dist = dfs(n2one, n, n-1)
n2one_reachable = set()
for i, di in enumerate(n2one_dist):
    if di != float('inf'):
        n2one_reachable.add(i)

one2n_path = one2n_reachable & n2one_reachable


# ベルマンフォード
INF = float('inf')
dist = [-INF]*n
dist[0] = 0

for _ in range(n):
    for ai, bi, ci in edges:
        if ai in one2n_path and bi in one2n_path and dist[ai] + ci > dist[bi]:
            dist[bi] = dist[ai] + ci

aftern = dist[n-1]

modified = False
for _ in range(n):
    for ai, bi, ci in edges:
        if ai in one2n_path and bi in one2n_path and dist[ai] + ci > dist[bi]:
            modified = True

# N回更新と2N回更新を比較
# 2N回で更新されていれば-1
if modified:
    print(-1)
else:
    print(max(0, aftern))

Measured memory_bytes: 49396
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = []
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    ans.append(min(abs(l)+abs(l-r), abs(r)+abs(l-r)))

print(min(ans))

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

int n, ans = 0;
int cnt[100005] = {0};

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if(x > n)
      ++ans;
    else
      ++cnt[x];
  }
  for(int i = 0; i <= n; ++i) {
    if(cnt[i] < i) ans += cnt[i];
    if(cnt[i] > i) ans += cnt[i] - i;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll H, W, k;
  cin >> H >> W >> k;
  mint dp[H + 1][W] = {};
  dp[0][0] = 1;
  rep(h, H) rep(w, W) rep(j, 1 << (W - 1)) {
    vb v(W - 1, false);
    rep(k, W - 1) v[k] = (j >> k & 1);
    bool ok = true;
    rep(k, W - 2) if(v[k] && v[k + 1]) ok = false;
    if(!ok) continue;
    if(w > 0 && v[w - 1])
      dp[h + 1][w - 1] += dp[h][w];
    else if(w < W - 1 && v[w])
      dp[h + 1][w + 1] += dp[h][w];
    else
      dp[h + 1][w] += dp[h][w];
  }
  cout << dp[H][k - 1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll N;
	ll X[200000];
	ll X1[200000];
	ll high = 0;
	ll low = 0;
	cin >> N;
	REP(i, N) {
		cin >> X[i];
		X1[i] = X[i];
	}
	sort(X1, X1 + N);
	high = X1[(N / 2)];
	low = X1[(N / 2)-1];
	REP(i, N) {
		if (X[i] >= high) {
			cout << low << endl;
		}
		else {
			cout << high <<endl;
		}
	}


	return 0;


}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1000111;

const ll MOD = 1000000007LL;

void solve() {

}

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

    int k, x;
    cin >> k >> x;
    for (int i=x-k+1; i<=x+k-1; i++) {
        cout << i << " ";
    }






    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}
int gdc(int a, int b) {
    int r;
    if (a < b)
        swap(&a, &b);
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    int n;
    scanInt(n);
    char s[n+1];
    scanf("%s", s);
    if (n % 2) {
        printNo();
        return 0;
    }
    bool flag = true;
    rep(i, n/2) {
        if (s[i] != s[i+n/2]) {
            flag = false;
            break;
        }
    }
    if (flag) printYes();
    else printNo();
    return 0;
}

Measured memory_bytes: 3684
n,a,b = [int(i) for i in input().split()]
if (b-a)%2==0:
    print((b-a)//2)
else:
    min = n-a
    if b-1<min:
        min = b-1
    if (a+b-1)//2<min:
        min = (a+b-1)//2
    if (n-(a+b-1)//2) <min:
        min = n-(a+b-1)//2
    print(min)
  

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

int main(void) {
	int n, q, tmp;
	vector<int> A;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		A.push_back(tmp);
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d", &tmp);
		printf("%d\n", distance(A.begin(), lower_bound(A.begin(), A.end(), tmp)));
	}
}


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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

struct CustomCompare
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }
};

bool comp(pair<ll, ll>a,pair<ll,ll>b)
{
    return a.fi>b.fi;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n,k; cin>>n>>k;
vi arr(n);
rep(i,0,n)cin>>arr[i];
rep(i,k,n)
{
    if(arr[i]>arr[i-k])cout<<"Yes\n";
    else cout<<"No\n";
}
return 0;
}
/*
23 5
10 3 3
2 1 4 11 8 10 5 6 7 9 12 3 14 13 16 18 21 15 17 19 20 23 22
4 6 3 18 23
*/


Measured memory_bytes: 4780
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

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

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> s(N);
	for (int i = 0; i < N; i++) cin >> s[i];
	sort(s.begin(), s.end());

	int sum = 0;
	for (int i = 0; i < N; i++) sum += s[i];

	if (sum % 10) cout << sum << "\n";
	else {

		int idx = 0;
		while (idx < N - 1 && !(s[idx] % 10)) idx++;

		if (idx == N - 1) cout << 0 << "\n";
		else cout << sum - s[idx] << "\n";

	}


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795

#define fill(x, v)  fillchar(x, v, sizeof(x))
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;


#define MAXN 3010

ll  a[MAXN];
ll  f[MAXN][MAXN];
int n;

int main() {
    scanf("%i", &n);
    for(int i = 0; i < n; ++i) scanf("%lld", &a[i]);
    for(int l = 1; l <= n; ++l)
        for(int i = 0; i + l <= n; ++i) {
            int j = i + l - 1;
            if (l % 2 == n % 2) {
                f[i][j] = max(f[i + 1][j] + a[i], f[i][j - 1] + a[j]);
            } else {
                f[i][j] = min(f[i + 1][j], f[i][j - 1]);
            }
        }

    printf("%lld\n", 2*f[0][n - 1] - accumulate(a, a + n, 0LL));

    return 0;
}

Measured memory_bytes: 70144
s = str(input())

n = len(s)
a = True
odd = ['R','U','D']
even = ['L','U','D']

m = n // 2
if n == 1:
    if s in odd:
        print('Yes')
    else:
        print('No')
else:
    if all((s[2 * i] in odd) for i in range(m)):
        if all(((s[2 * i + 1]) in even) for i in range(m)):
            print('Yes')
        else:
            print('No')
    else:
        print('No')


Measured memory_bytes: 3064
def main():
    N = int(input())
    ans = 0
    for i in range(1, N+1, 2):
        cnt = 0
        for j in range(1, i+1):
            if i % j == 0:
                cnt += 1
        if cnt == 8:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

const int mod = 1e9+7;

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

    int N;
    string S;
    cin >> N >> S;

    int a[26] = {};
    for (char c: S) a[c-'a']++;

    long long res = 1;
    for (char c='a'; c<='z'; ++c) {
        if (a[c-'a'] > 0) {
            res = (res * (a[c-'a']+1)) % mod;
        }
    }
    cout << res-1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;

ll a,b;
vector<ll> k(1,1);

void decompositPrime(ll n,ll m)
{
    ll a = 2;
    while (n >= a * a) {
        if (n % a == 0) {
            n /= a;
            if(m % a == 0 && k[k.size()-1] != a){
                k.push_back(a);
            }
        } else {
            a++;
        }
    }
    if(m % n == 0 && k[k.size()-1] != n){
        k.push_back(n);
    }
}

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    cin >> a >> b;
    ll swap;
    if(a>b){
        swap=a;
        a=b;
        b=swap;
    }
    
    decompositPrime(a,b);

    //rep(i,k.size()) cout << k[i] <<" ";
    cout << k.size();
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc139/tasks/abc139_c
# 整数の入力
n = int(input())
b = list(map(int, input().split()))
a = [b[0], b[0]]
for i in range(1, n-1):
    a.append(b[i])
    if b[i] < b[i-1]:
        a[i] = b[i]
print("{}".format(sum(a)))


Measured memory_bytes: 3060
N = int(input())
Xsize = 1001 # 0-1000
Ysize = 1001 # 0-1000
Data = [[0]*(Xsize) for _ in range (Ysize)]
Tmp  = [[0]*(Xsize) for _ in range (Ysize)]
Ans  = [[0]*(Xsize) for _ in range (Ysize)]

for _ in range(N):
    x1,y1,x2,y2 = map(int,input().split())
    Data[y1][x1] += 1
    Data[y1][x2] -= 1
    Data[y2][x1] -= 1
    Data[y2][x2] += 1

#x方向の累積和 
for y in range(Ysize):
    Tmp[y][0] = Data[y][0]
    for x in range(1,Xsize):
        Tmp[y][x] = Data[y][x] + Tmp[y][x-1]
#y方向の累積和 
for x in range(Xsize):
    Ans[0][x] = Tmp[0][x]
    for y in range(1,Ysize):
        Ans[y][x] = Tmp[y][x] + Ans[y-1][x]
#最大値
ans = 0
for y in range(Ysize):
    ans = max(ans,max(Ans[y]))
print(ans)


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

int main()
{
    std::int64_t X, Y;
    std::cin >> X >> Y;

    const std::int64_t b = Y - 2 * X;
    if(b < 0 || b % 2 != 0 || 2 * X < b)
    {
        std::cout << "No" << std::endl;
    }
    else
    {
        std::cout << "Yes" << std::endl;
    }
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int B[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<=N;i++) {
		cin>>B[i];
		if(B[i]>i) return _P("-1\n");
	}
	
	vector<int> R;
	for(i=N;i>=1;i--) {
		int ma=i;
		for(j=i;j>=1;j--) {
			if(B[j]==j) break;
		}
		if(j==0) return _P("-1\n");
		R.push_back(j);
		for(;j<=101;j++) swap(B[j],B[j+1]);
	}
	
	reverse(ALL(R));
	FORR(r,R) cout<<r<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
#define s second
#define f first
const int MOD = 1e9+7;
using namespace std;

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

ll llmin(ll x, ll y){
	if (x > y) return y;
	return x;
}

bool is_prime(int x){
	for (int i = 2; i*i <= x; i++){
		if (!(x%i)) return false;
	}
	return true;
}

ll gcd(ll x, ll y){
	if (y > x){
		ll temp = x;
		x = y;
		y = temp;
	}
	if (x%y) return gcd(y, x%y);
	return y; 
}


int main(){
	int n, ans = 0;
	cin >> n;
	vector<int> a(n);

	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int now = 1;
	for (int i = 0; i < n; i++){
		if (a[i] == now){
			now++;
		}else{
			ans++;
		}
	}
	if (ans == n) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}




Measured memory_bytes: 1024
fun main(args: Array<String>) = yorukatsu6E()

fun yorukatsu6E() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val xyList = (1..n).map { readLine()!!.split(' ').map { it.toLong() } }
        .map { Xy(it[0], it[1]) }.toTypedArray()

    val xList = xyList.map { it.x }.sorted().toLongArray()
    val yList = xyList.map { it.y }.sorted().toLongArray()

    var answer = Long.MAX_VALUE

    for ((index1, left) in xList.withIndex()) {
        for (right in xList.drop(index1 + 1)) {
            for ((index2, down) in yList.withIndex()) {
                for (up in yList.drop(index2 + 1)) {
                    val inRectangle = xyList.count() { it.y in down..up && it.x in left..right }
                    if (inRectangle >= k) {
                        val area = Math.abs(right - left) * Math.abs(up - down)
                        answer = Math.min(answer, area)
                    }
                }
            }
        }
    }

    println(answer)
}

private data class Xy(val x: Long, val y: Long)


Measured memory_bytes: 54272
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

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

MOD = 10 ** 9 + 7

lcm = 1
answer = 0
for x in A:
  n = x//gcd(lcm,x)
  lcm *= n
  answer *= n
  answer += lcm//x
  
answer %= MOD
print(answer)


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

using namespace std;

typedef long long ll;

const int N = 100000;
int a[N+1], b[N+1];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, x;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if (i%2)
        {
            b[x]++;
        }
        else
        {
            a[x]++;
        }
    }
    int ma = 0, ai = 0;
    int mb = 0, bi = 0;
    for (int i = 0; i <= N; i++)
    {
        if (a[i] > ma)
        {
            ma = a[i];
            ai = i;
        }
        if (b[i] > mb)
        {
            mb = b[i];
            bi = i;
        }
    }
    int s = ma+mb;
    if (ai == bi)
    {
        int m = 0;
        for (int i = 0; i <= N; i++)
        {
            if (i == ai) continue;
            m = max(m, a[i]);
        }
        s = ma+m;
        m = 0;
        for (int i = 0; i <= N; i++)
        {
            if (i == bi) continue;
            m = max(m, b[i]);
        }
        s = max(s, mb+m);
    }
    cout << n - s << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		int[] Ans = new int[totalVertex];
		for(int i = 1; i < totalVertex; i++) {
			Ans[i] = Integer.MAX_VALUE;
		}
		
		int curr = getUnsettledNearest(Ans);
		
		while (curr != -1) {
			ifSettled[curr] = true;
			LinkedList<Integer> r = getUnsettledNeighbors(curr);
			for(Integer neighbor:r) {
				int e = getWeight(curr, neighbor);
				if(e+Ans[curr] < Ans[neighbor]) {
					Ans[neighbor] = e + Ans[curr];
				}
			}
			
			curr = getUnsettledNearest(Ans);
			
		}
		
		return Ans;
		

	}
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}



Measured memory_bytes: 39976
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

map<int,int> mp;

void prime_factorization(int n){
    if(n==1) return;
    int i=2;
    while(n>1){
        if(n%i==0){
            n/=i;
            mp[i]++;
        }else{
            i++;
        }
    }
    return;
}

const long long MAX=510000;

//階乗,逆元,逆元の階乗
long long fac[MAX],finv[MAX],inv[MAX];

//テーブルを作る前処理
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

//二項係数計算
long long COM(long long n,long long k){
    if (n<k) return 0;
    if (n<0||k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
    COMinit();
    int n,m; cin>>n>>m;
    prime_factorization(m);
    long long ans=1;
    for(auto i:mp){
        int j=i.second;
        ans*=COM(n+j-1,j);
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12160
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#define EPS 1e-10
using namespace std;
typedef long long llong;
llong dp[20001];
int main() {
	int n;
	dp[0] = 0;
	for (int i = 1; i < 20001; i++) {
		dp[i] = dp[i - 1];
		if (i % 5 == 0) {
			int r = i;
			while (r % 5 == 0) {
				dp[i]++;
				r /= 5;
			}
		}
	}
	while (cin >> n&&n) {
		cout << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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 main(){
    ll n,k; cin>>n>>k;
    double res=0;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    vector<double> q(n+1,0);
    rep(i,n) q[i+1]=q[i]+p[i];
    for(ll i=k; i<=n; i++){
        chmax(res, q[i]-q[i-k]+(double)k);
    }
    cout<<fixed<<setprecision(10)<<res/2<<endl;
    return 0;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    string S; cin >> S;
    int k(S.length()), win(0);
    REP(i, k) if(S[i] == 'o') ++win;
    cout << (((15-k)+win >= 8) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        int u = scan.nextInt();
        int n = t + 1;
        int m = u + 1;
        int[][] a = new int[n][m];
        int b[] = new int[m];
        int c[] = new int[n];
        int i,r;
        for(i = 0; i < n - 1; ++i){
            for(r = 0; r < m - 1; ++r){
                a[i][r] = scan.nextInt();
                a[i][m - 1] += a[i][r];
                a[n - 1][r] += a[i][r];
                a[n - 1][m - 1] += a[i][r];
            }
        }
        for(i = 0; i < n; ++i){
            for(r = 0; r < m; ++r){
                if(r == m - 1){
                    System.out.println(a[i][r]);
                }
                else
                System.out.print(a[i][r]+" ");
                 
            }
        }
    }
}
        

Measured memory_bytes: 41756
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println((sc.nextInt()-sc.nextInt())%sc.nextInt());
	}
}

Measured memory_bytes: 22740