akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
typedef long long ll;

int y[50];
ll dp[51][5001];
int N,A,X=0;
ll solve(int j,int t){
	if(dp[j][t]>=0)return dp[j][t];
	if(j==0 && t==N*X)return dp[j][t]=1;
	else if(j>0 && (t-y[j]<0 || t-y[j]>2*N*X))return dp[j][t]=solve(j-1,t);
	else if(j>0)return dp[j][t]=solve(j-1,t)+solve(j-1,t-y[j]);
	else return dp[j][t]=0;
}

int main(void){
    cin>>N>>A;
    rep1(i,N){
    	cin>>y[i];
    	y[i]-=A;
    	X=max(y[i],X);
    }
    rep(i,N+1)rep(j,2*N*X+1)dp[i][j]=-1;
    cout<<solve(N,N*X)-1<<endl;
    return 0;
}


Measured memory_bytes: 2176
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    S = list(input())

    ai = ord('A')
    zi = ord('Z')
    for i in range(len(S)):
        code = ord(S[i]) + N
        if code > zi:
            code -= 26
        S[i] = chr(code)

    print(''.join(S))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

l = list(set(s))
a = max (s.count(l[i]) - t.count(l[i]) for i in range(len(l)))

print(a if a > 0 else 0)




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

int main()
{
   int n;
   cin>>n;
   int y=n%10;
   if (y==2 || y==4||y==5||y==7||y==9)
{
cout<<"hon";
}
if(y==3)
{
cout<<"bon";
}
if(y==0||y==1||y==6||y==8)
{
cout<<"pon";
}    

}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		if (x < y) {
			System.out.println("a < b");
		}else if(x > y){
			System.out.println("a > b");
		}else {
				System.out.println("a == b");
			}
		}
	}

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

using namespace std;

bool valid(const vector<string>& vs){
	const int w = vs[0].size();
	const int h = vs.size();
	vector<int> used(w, 0);
	bool usePal = false;
	for(int i=0;i<w;i++){
		if(used[i]) continue;
		for(int j=w-1;j>=i;j--){
			if(used[j]) continue;
			if(j==i && (w%2 == 0 || usePal)) continue;
			bool ok = true;
			for(int k=0;k<h;k++){
				if(vs[k][i] != vs[h-1-k][j]) ok = false;
			}
			if(ok){
				used[i] = used[j] = 1;
				if(i == j) usePal = true;
				break;
			}
		}
		if(!used[i]) return false;
	}
	return true;
}

bool search(vector<string>& vs, int idx){
	int n = vs.size();
	if(idx >= n-1-idx) return valid(vs);
	bool ok = false;
	for(int i=idx+1;i<n-idx;i++){
		if(vs.size()%2 == 1 && i == vs.size()/2) continue;
		swap(vs[i], vs[n-1-idx]);
		if(search(vs, idx+1)) ok = true;
		swap(vs[i], vs[n-1-idx]);
	}
	return ok;
}

bool searchRoot(vector<string>& vs){
	if(vs.size()%2 == 0) return search(vs, 0);
	bool ok = false;
	for(int i=0;i<vs.size();i++){
		swap(vs[i], vs[vs.size()/2]);
		if(search(vs, 0)) ok = true;
		swap(vs[i], vs[vs.size()/2]);
	}
	return ok;
}

int main(){
	int H, W;
	while(cin >> H >> W){
		vector<string> vs(H);
		for(auto& s : vs) cin >> s;
		cout << (searchRoot(vs) ? "YES" : "NO") << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    int N,A,B;
    cin >> N >> A >> B;
    char S[N];
    for(int i=0;i<N;i++){
        cin >> S[i];
    }
    string ans[N];
    int count=0;
    int countB=0;
    for(int i=0;i<N;i++){
        if(S[i]=='c'){
            ans[i]="No";
        }else if(S[i]=='a'){
            if(count<A+B){
                count++;
                ans[i]="Yes";
            }else{
                ans[i]="No";
            }
        }else if(S[i]=='b'){
            countB++;
            if(count<A+B){
                if(countB<=B){
                    count++;
                    ans[i]="Yes";
                }else{
                    ans[i]="No";   
                }
            }else{
                ans[i]="No";
            }
        }else{
            ans[i]="No";
        }
    }

    for(int i=0;i<N;i++){
        cout << ans[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 6144
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[200005], arr1[200005];

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
		arr1[i] = arr[i];
	}

	sort(arr, arr + N);
	ll val1 = arr[N - 1];
	ll val2 = arr[N - 2];
	for(int i = 0; i < N; i++) {
		if(arr1[i] == val1) {
			printf("%lld\n", val2);
		}
		else {
			printf("%lld\n", val1);
		}
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 4736
# coding : utf-8

import numpy as np
import math

N = int(input())

loc = []
for _ in range(N):
    line = input().split(" ")
    loc.append([ int(line[0]), int(line[1]) ])

loc = np.array(loc)

if(N==2):
    print(np.linalg.norm(loc[0]-loc[1]))
else: 
    # 街間の距離
    mat = np.zeros((N,N))
    for i in range(N):
        for j in range(i, N):
            mat[i][j] = np.linalg.norm(loc[i]-loc[j])
            
    for i in range(N):
        for j in range(0, i):
            mat[i][j] = mat[j][i]
      
    mat = mat * (N-1) * math.factorial(N-2)
    print(np.sum(mat) / math.factorial(N))

Measured memory_bytes: 22024
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>

using namespace std;

#define MAX_N 200000

#define max(a,b) a > b ? a : b

int main()
{
    int K, N;
    int A[MAX_N];

    cin >> K >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    int len = 0;
    for (int i = 0; i < N; i++)
    {
        if (i == N-1)
        {
            len = max(len, K - (A[N - 1] - A[0]));
        }
        else
        {
            len = max(len,(A[i+ 1] - A[i]));
        }
    }

    cout << K - len << endl;

    return 0;
}

Measured memory_bytes: 1024
<?php

fscanf(STDIN, '%d %d', $n, $m);

$matrix = array();
$vector = array();
$i = 0;

while (($line = trim(fgets(STDIN))) !== '') {
    if ($i++ < $n) {
        $matrix[] = explode(' ', $line);
    } else {
        sscanf($line, '%d', $b);
        $vector[] = $b;
    }
}

foreach ($matrix as $row) {
    $result = 0;
    foreach ($row as $i => $col) {
        $result += $col * $vector[$i];
    }
    echo $result, PHP_EOL;
}

Measured memory_bytes: 8416
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
map<long,long> prime_decomp(long n){
  map<long,long> m;
  for(long i=2;i*i<=n;i++){
    while(n%i==0){
      m[i]++;
      n/=i;
    }
  }
  if(n>1)m[n]++;
  return m;
}
inline void solve(void){
  long N,P;
  in(N,P);
  long ans=1;
  for(auto e:prime_decomp(P)){
    ans*=pow(e.ft,e.sd/N);
  }
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

int main() {
	 int N;
	 string S;
	 cin >> N >> S;
	 int score=0, max_score=0;
	 for (int i=0; i<N; i++){
	     if (S.at(i)=='I') score++;
	     if (S.at(i)=='D') score--;
	     max_score=max(max_score, score);
	 }
	 cout << max_score << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int> P(N);
    rep(n,0,N) cin>>P.at(n);

    vector<int> Dist(N);
    rep(n,0,N) Dist.at(n)=n-P.at(n)+1;

    int ans=0;
    rep(n,0,N){
        if(Dist.at(n)==0){
            int swapIdx=n+1;
            if(n==N-1) swapIdx=n-1;
            int tmp=P.at(n);
            P.at(n)=P.at(swapIdx);
            P.at(swapIdx)=tmp;

            Dist.at(n)=n-P.at(n)+1;
            Dist.at(swapIdx)=n+1-P.at(swapIdx)+1;
            ans++;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int INF=0x7f7f7f7f;
const int MAXN=100000+10;
int rock[MAXN];
int dp[MAXN];
int n,k;
int main(){
	memset(dp,INF,sizeof(dp));
	cin>>n>>k;
	for(int i=0;i<n;++i){
		cin>>rock[i];
	}
	dp[0]=0;
	for(int i=1;i<k;++i){
		for(int j=0;j<i;++j){
			dp[i]=min(dp[i],dp[j]+abs(rock[j]-rock[i]));
		}
	}
//	dp[1]=abs(rock[1]-rock[0]);
	for(int i=k;i<n;++i){
		for(int j=i-k;j<i;++j){
			dp[i]=min(dp[i],dp[j]+abs(rock[j]-rock[i]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int A, B; cin >> A >> B;
	priority_queue<int, vector<int> > que;
	que.push(A);
	que.push(B);

	int res = 0;
	rep (i, 2){
		int curr = que.top(); que.pop();
		res += curr;
		--curr;
		if (curr > 0){
			que.push(curr);
		} // end if
	} // end rep
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;



int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MAX = 100010;

int par[MAX];//親
int Rank[MAX];//木の深さ

			  //n要素で初期化
void init(int n) {
	REP(i, n) {
		par[i] = i;
		Rank[i] = 0;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);//経路圧縮(根に直接つなぎなおす)もしつつ
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	//低いほうを高いほうにつなげる(効率化)
	if (Rank[x] < Rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}

struct edge { int u, v, cost; };
bool comp(const edge& e1, const edge&e2) {
	return e1.cost < e2.cost;
}

edge es[MAX];
int V, E;


int kruskal() {
	sort(es, es + E, comp);
	init(V);
	int res = 0;
	REP(i, E) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}




int main() {
	cin >> V >> E;

	REP(i, E) {
		int s, t, w;
		cin >> s >> t >> w;
		es[i] = { s,t,w };
	}

	int ans = kruskal();
	cout << ans << endl;
}



Measured memory_bytes: 4340
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    Q = int(input())

    reverse = False
    header = [''] * Q
    footer = [''] * Q
    for i in range(Q):
        query = input()
        if query[0] == '1':
            reverse = not reverse
        else:
            _, f, c = query.split()
            if reverse:
                if f == '1':
                    footer[i] = c
                else:
                    header[i] = c
            else:
                if f == '1':
                    header[i] = c
                else:
                    footer[i] = c
    if reverse:
        print("".join(footer[::-1] + list(S)[::-1] + header))
    else:
        print("".join(header[::-1]) + S + "".join(footer))

if __name__ == '__main__':
    main()


Measured memory_bytes: 12600
#include <stdio.h>
#define MAX 2000005

int heap[MAX], heapsize=0;

int heapExtractMax();
void heapIncraseKey(int,int);
void MaxheapInsert(int);
void maxHeapify(int);

int main(){
  int a, key;
  char command[10];

  while(1){
    scanf("%s",command);
    switch(command[0]){
      case 'i':
	scanf("%d",&key);
	MaxheapInsert(key);
	break;
      case 'e':
	if(command[1] == 'x') printf("%d\n",heapExtractMax());
	else return 0;
	break;
    }
  }
}

int heapExtractMax(){
  int max=heap[1];
  heap[1] = heap[heapsize];
  heapsize--;
  maxHeapify(1);
  return max;
}

void heapIncreaseKey(int a, int key){
  int temp;
  heap[a] = key;
  while(a > 1 && heap[a/2] < heap[a]){
    temp = heap[a];
    heap[a] = heap[a/2];
    heap[a/2] = temp;
    a = a/2;
  }
}

void MaxheapInsert(int key){
  heapsize++;
  heapIncreaseKey(heapsize,key);
}

void maxHeapify(int a){
  int l=2*a, r=2*a+1, largest, temp;

  if(l <= heapsize && heap[l] > heap[a]) largest = l;
  else largest = a;
  if(r <= heapsize && heap[r] > heap[largest]) largest = r;
  if(largest != a){
    temp = heap[a];
    heap[a] = heap[largest];
    heap[largest] = temp;
    maxHeapify(largest);
  }
}



Measured memory_bytes: 5692
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    String ans = "";
    if(n == 0) ans = "0";
    if(n != 0) {
      while(n != 0) {
        int n1 = (int)Math.abs(n);
        if((n1 % 2) == 0) {
          ans = "0" + ans;
        } else {
          ans = "1" + ans;
        }
        n -= (n1 % 2);
        n /= (-2);
      }
    }
    System.out.println(ans);
  }
}

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

int main()
{
  while(1)
    {
      int h,w;
      cin >> h >> w;

      if ( h == 0 && w == 0)
	{break;}

      for(int i = 1; i <= h; i++)
	{
	  for(int j = 1;  j <= w; j++){cout << "#" ;}  
	  cout << endl;
	}
      cout << endl;
    }

  return 0;
}



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

const int R = 5;

int G[R][R];

bool isRect(int a, int b, int c, int d) {
  for(int i = a; i <= c; ++i) {
    for(int j = b; j <= d; ++j) {
      if(!G[i][j]) return false;
    }
  }
  return true;
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < R; ++j) {
        cin >> G[i][j];
      }
    }
    int res = 0;
    for(int a = 0; a < R; ++a) {
      for(int b = 0; b < R; ++b) {
        for(int c = a; c < R; ++c) {
          for(int d = b; d < R; ++d) {
            if(isRect(a,b,c,d)) {
              res = max(res, (c-a+1)*(d-b+1));
            }
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner( System.in);
		int N,A,B;
		int a=0,b=0,c=0;
            N=stdin.nextInt() ;
            A=stdin.nextInt() ;
            B=stdin.nextInt() ;
            
            for(int i=1;i<=N;i++) {
            	int P=stdin.nextInt() ;
            	if(P<=A) {
            		a++;
            	}else if(P<=B){
            		b++;
            	}else {
            		c++;
            	}
            }
            
           
        System.out.println(Math.min(a,Math.min(b, c)));
	}
}


Measured memory_bytes: 23124
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

using namespace std;
#define int long long

int dp[3001][3001], a[3001];

int dfs(int i, int j) {
    if (i > j)return 0;
    if (dp[i][j])return dp[i][j];
    if (i == j)return dp[i][j] = a[i];
    if (i == j + 1)return dp[i][j] = max(a[i], a[j]);
    return dp[i][j] = max(a[i] + min(dfs(i + 1, j - 1), dfs(i + 2, j)), a[j] + min(dfs(i + 1, j - 1), dfs(i, j - 2)));
}

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

    int n, sum = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i];
    cout << dfs(0, n - 1) * 2 - sum << endl;
}

Measured memory_bytes: 70144
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, 0, n)

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

bool conv(int num) {
	int a, b, c;
	a = num / 100;
	num %= 100;
	b = num / 10;
	num %= 10;
	c = num;
	if (a == b && b == c) return true;
	else return false;
}

int main() {
	cin.tie(0);
	int n;
	cin >> n;
	while (1) {
		bool check = conv(n);
		if (check) break;
		else n++;
	}

	cout << n;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    int m;
    cin >> n >> m;
    vector<int> h(100010);
    vector<int> num(100010);
    for(int i = 1; i < n + 1; i++){
        cin >> h[i];
        num[i] = 0;
    }
    vector<int> a(m);
    vector<int> b(m);
    for(int i = 0; i < m; i++){
        cin >> a[i];
        cin >> b[i];
        num[a[i]] = max(num[a[i]], h[b[i]]);
        num[b[i]] = max(num[b[i]], h[a[i]]);
    }
    int result = 0;
    for(int i = 1; i < n + 1; i++){
        result += h[i] > num[i];
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4804
#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>
#include <numeric>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count())

#define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__)
#define rc(...) char __VA_ARGS__; rx(__VA_ARGS__)
#define rs(...) string __VA_ARGS__; rx(__VA_ARGS__)
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__)
#else
#define dbg(...) ;;
#endif

#define fa(i, v) for (auto &i : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(i) ri(_i); fi(i, _i)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

typedef uint32_t u32;
typedef int32_t i32;
typedef uint64_t u64;
typedef int64_t i64;
#ifdef __SIZEOF_INT128__
typedef __uint128_t u128;
typedef __int128_t i128;
#endif
typedef vector<i64> vi;
typedef vector<vi> vvi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) out << x << ' ';
    return out;
}

template<typename T>
inline void rx(T &x) {
    cin >> x;
}

template<typename T, typename... R>
inline void rx(T &x, R &... l) {
    cin >> x;
    rx(l...);
}

template<typename T>
inline void dbg_log(const T &x) {
    cerr << x << '\n';
}

template<typename T, typename... R>
inline void dbg_log(const T &x, const R &... l) {
    cerr << x << ", ";
    dbg_log(l...);
}

template<typename T>
inline void wl(const T &x) {
    cout << x << '\n';
}

template<typename T, typename... R>
inline void wl(const T &x, const R &... l) {
    cout << x << ' ';
    wl<R...>(l...);
}

int main() {
    fio;

    ri(n, m, k);
    vi a(n + 1);
    fi(i, n) {
        ri(x);
        a[i + 1] = a[i] + x;
    }
    vi b(m + 1);
    fi(i, m) {
        ri(x);
        b[i + 1] = b[i] + x;
    }

    i32 res = 0;
    fi(i, n + 1) {
        if (a[i] > k) break;
        i32 j = upper_bound(all(b), k - a[i]) - b.begin();
        res = max(res, i + j - 1);
    }
    wl(res);

    return 0;
}


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

typedef long long ll;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	vector<int> dp_arr(n+1,0);
	dp_arr[0] = 0;
	for(int i = 1; i < n; i++)
	{
		int res = INT_MAX;
		for(int j = 1; i-j >= 0 && j <= k; j++)
		{
			res = min(res, dp_arr[i-j]+abs(arr[i]-arr[i-j]));
		}
		dp_arr[i] = res;
	}
	cout << dp_arr[n-1] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int map[110][110];
	int n,m,i,j,num,x,y,t,flag;
	while(~scanf("%d %d",&n,&m))
	{
		scanf("%d",&t);
		x=1;y=1;flag=1;
		for(i=1;i<=t;i++)
		{
			scanf("%d",&num);
			for(j=1;j<=num;j++)
			{
				map[x][y]=i;
				if(flag)
				{
					y++;
					if(y>m)
					{
						flag=0;
						x++;y--;
					}
				}
				else
				{
					y--;
					if(y<=0)
					{
						flag=1;
						x++;y++;
					}
				}
			}
		}
		for(i=1;i<=n;i++)
		{
			for(j=1;j<m;j++)
			{
				printf("%d ",map[i][j]);
			}
			printf("%d\n",map[i][j]);
		}
	}
	return 0;
}

Measured memory_bytes: 384
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
from itertools import groupby
for k, v in groupby(A):
    c = 0
    for i in v:
        c += 1
    if k > c:
        ans += c
    elif k < c:
        ans += c-k
print(ans)

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

using namespace std;

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

#define pb push_back
#define mp make_pair

int n;
map<int, int> cnt;
vector<ll> vec2, vec4;

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        cnt[t]++;
        if(cnt[t] == 2) vec2.pb(t);
        if(cnt[t] == 4) vec4.pb(t);
    }
    sort(vec2.begin(), vec2.end(), greater<int>());
    sort(vec4.begin(), vec4.end(), greater<int>());
    ll mx = 0;
    if(vec2.size() > 1) mx = vec2.front() * vec2[1];
    if(vec4.size()) mx = max(mx, vec4.front() * vec4.front());
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 4992
#include "stdio.h"
#include "string.h"
#include "math.h"

int main(int argc, char const *argv[]) {
  char S[1000000];
  scanf("%s", S);
  int N=strlen(S);

  int i;
  int w=0;
  long long int ans=0;
  for (i = 0; i < N; i++) {
    if (S[i]=='W') {
      ans=ans+i-w;
      w++;
    }
  }
  if (w==N||w==0) {
    ans=0;
  }
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    int MAX = 0;
    vector<int> score(10001, 0);

    score[0] = 1;
    for (int i = 0; i < N; i++) {
        int s;
        cin >> s;
        for (int j = MAX; j >= 0; j--) {
            if (score[j] > 0) {
                score[j+s] = 1;
            }
        }
        MAX += s;
    }

    int ans = 0;
    for (int i = MAX; i >= 0; i--) {
        if ( score[i] > 0 && i % 10 != 0 ) {
            ans = i;
            break;
        }
    }


    cout << ans << "\n";
    return 0;
}

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

int main() {
	int m[100][100]={};
	int n,k,v,d;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>d>>k;d--;
		for(int j=0;j<k;j++)
		{
			cin>>v;
			m[d][--v]=1;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
	{
		if(j)cout<<" ";cout<<m[i][j];
	}cout<<endl;
	}
	return 0;
}

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




int N, M;
vector<int> E[101010];
//-----------------------------------------------------------------------------------
vector<int> ans;
int vis[101010];
void dfs(int cu) {
    vis[cu] = 1;
    ans.push_back(cu + 1);
    for (int to : E[cu]) if (!vis[to]) {
        dfs(to);
        return;
    }
}
bool chk(int cu) {
    for (int to : E[cu]) if (!vis[to]) return false;
    return true;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N >> M;
    rep(i, 0, M) {
        int a, b; scanf("%d%d", &a, &b);
        a--; b--;
        E[a].push_back(b); E[b].push_back(a);
    }

    vector<int> v;
    rep(i, 0, N) v.push_back(i);
    sort(v.begin(), v.end(), [&](int a, int b) { return E[a].size() < E[b].size(); });

    for (int s : v) {
        ans.clear();
        rep(i, 0, N) vis[i] = 0;
        dfs(s);
        if (chk(s)) {
            cout << ans.size() << endl;
            rep(i, 0, ans.size()) {
                printf("%d", ans[i]);
                if (i != ans.size() - 1) printf(" ");
                else printf("\n");
            }
            return 0;
        }
    }
}

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

int main() {
  int A,B,H,M;
  cin>>A>>B>>H>>M;
  double Ans;
  Ans=sqrt(A*A+B*B-2*A*B*cos(M_PI*(5.5*M-30*H)/180));
  cout << fixed << setprecision(16);
  cout<<Ans<<endl;
}

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

using namespace std;

int main() {
	int a = -1,z = -1;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (a == -1 && s[i] == 'A')a = i;
		if (s[i] == 'Z')z = i;
	}
	cout << (z-a+1) << endl;
}

Measured memory_bytes: 640
#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)

double dp[3009][3009];
ll n;vector<double> p;

void fun(){
	dp[1][1] = p[1];
	dp[1][0] = 1-p[1];
	for(ll i=2;i<=n;++i){
		for(ll j=0;j<=i-1;++j){
			dp[i][j+1] += p[i]*dp[i-1][j];
			dp[i][j] += (1-p[i])*dp[i-1][j];
			//cout<<dp[i][j+1]<<" "<<dp[i][j]<<"\n";
		}
	}
}
int main(){
	fast;
	cin>>n;
	p.push_back(0.0);
	for(ll i=0;i<n;++i){
		double a;cin>>a;p.push_back(a);
	}
	memset(dp,0,sizeof(dp));
	fun();
	double ans = 0.0;
	/*for(ll i=1;i<=n;++i){
		for(ll j=0;j<=i;++j){
			cout<<dp[i][j+1]<<" "<<dp[i][j]<<"\n";
		}
	}*/
	for(ll i=n/2+1;i<=n;++i)
		ans+=dp[n][i];
	cout<<fixed<<setprecision(10)<<ans;
	//printf("%f",ans);
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d;
    UnionFind(int N) : d(N, -1){}

    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false; 
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    int size(int x) {
        return -d[root(x)];
    }
};

void Main(){
    int n, m; cin >> n >> m;
    UnionFind UF(n);
    rep(i, m){
        int a, b; cin >> a >> b; a--; b--;
        UF.unite(a, b);
    }
    map<int, int> mp;
    rep(i, n){
        mp[UF.root(i)]++;
    }
    cout << mp.size() - 1 << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 7508
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <cstdio>
#include <utility>
#include <bitset>

using namespace std;
typedef long long ll;

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> x(N);
	for(int i=0;i<N;i++)
		cin >> x[i];
	sort(x.begin(),x.end());
	vector<ll> m(M,0);
	vector<ll> s(M,0);
	for(int i=0;i<N;){
		ll num = upper_bound(x.begin(),x.end(),x[i])-lower_bound(x.begin(),x.end(),x[i]);
		s[x[i]%M]+=num/2;
		m[x[i]%M]+=num;
		i+=num;
	}
	ll ans=0;
	for(int i=0;i<=M/2;i++){
		if(i==(M-i)%M){
			ans+=m[i]/2;
		}else{
			ll use = min(m[i],m[(M-i)%M]);
			ans+=use;
			s[i]=min(s[i],(m[i]-use)/2);
			s[(M-i)%M]=min(s[(M-i)%M],(m[(M-i)%M]-use)/2);
			ans+=max((ll)0,s[i]);
			ans+=max((ll)0,s[(M-i)%M]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
x=[]
y=[]

for i in range(4):
    X = int(input())
    x.append(X)
    
for i in range (2):
    Y = int(input())
    y.append(Y)
    
list.sort(x)
    
list.sort(y)
    
print(x[1]+x[2]+x[3]+y[1])


Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
#include <vector>

using pii = std::pair<int, int>;
using vpii = std::vector<pii>;

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

    int n; int64_t k; std::cin >> n >> k;
    vpii v(n);
    for (auto &p : v) std::cin >> p.first >> p.second;
    sort(v.begin(), v.end());
    int64_t s = 0;
    for (auto &p : v) {
        s+=p.second;
        if (s >= k) {
            std::cout << p.first << std::endl;
            break;
        }
    }

}


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

using namespace std;
const int maxn=305;
typedef long long ll;
ll mp[305][305];
ll dis[305][305];
ll dp[maxn][maxn];
const ll inf=1e17+5;
int main()
{
    int n,m,l;
    int a,b,c;
    cin>>n>>m>>l;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i==j)
            {
                mp[i][j]=0;
                dp[i][j]=0;
            }

            else
            {
                mp[i][j]=inf;
                dp[i][j]=inf;
            }

        }
    }
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        mp[a][b]=c;
        mp[b][a]=c;
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
                //                if(mp[i][k]<=l&&mp[i][k]>0&&mp[k][j]<=l&&mp[k][j]>0)
                //                {
                //                    dp[i][j]=min(2LL,dp[i][j]);
                //                }
                if(mp[i][k]<=l&&mp[i][k]>0)
                {
                    dp[i][j]=min(dp[k][j]+1,dp[i][j]);
                }
                if(mp[k][j]<=l&&mp[k][j]>0)
                {
                    dp[i][j]=min(dp[i][k]+1,dp[i][j]);
                }
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);

            }
        }
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
                //                if(mp[i][k]<=l&&mp[i][k]>0&&mp[k][j]<=l&&mp[k][j]>0)
                //                {
                //                    dp[i][j]=min(2LL,dp[i][j]);
                //                }
                if(mp[i][k]<=l&&mp[i][k]>0)
                {
                    dp[i][j]=min(dp[k][j]+1,dp[i][j]);
                }
                if(mp[k][j]<=l&&mp[k][j]>0)
                {
                    dp[i][j]=min(dp[i][k]+1,dp[i][j]);
                }
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    
    int q;
    cin>>q;
    while(q--)
    {
        scanf("%d%d",&a,&b);
        if(dp[a][b]>=inf-2)
            printf("-1\n");
        else
        {
            ll ans=0;
            ans=max(ans,dp[a][b]-1);
            printf("%lld\n",ans);
        }

    }
    return 0;
}

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

#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int modi(int a, int m) {
    return power(a, m - 2, m);
}
int32_t main() {
    nitin;
    int n,m;
    cin>>n>>m;
    char a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    int i=0;
    int j=0;
    a[0][0]='v';
    while(true)
    {
        if(i==n-1 && j==m-1)
        {
            a[i][j]='v';
            break;
        }
        if(i==n-1)
        {
            if(a[i][j+1]=='#')
            {
                a[i][j+1]='v';
                j++;
            }
            else{
                break;
            }
        }
        else if(j==m-1)
        {
            if(a[i+1][j]=='#')
            {
                a[i+1][j]='v';
                i++;
            }
            else{
                break;
            }
        }
        else
        {
            if(a[i][j+1]=='#')
            {
                a[i][j+1]='v';
                j++;
            }
            else if(a[i+1][j]=='#')
            {
                a[i+1][j]='v';
                i++;
            }
            else{
                break;
            }
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
        {
            if(a[i][j]=='#')
                cnt++;
        }
    }
    if(cnt==0)
        cout<<"Possible";
    else
        cout<<"Impossible";
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N,C;
vector<pii> v[31];
int cum[200010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> C;
  REP(i,N) {
    int s,t,c;
    cin >> s >> t >> c;
    c--;
    v[c].emplace_back(s,t);
  }
  REP(i,C) {
    SORT(v[i]);
    int l = 0, r = 0;
    while (l < v[i].size()) {
      while (r+1 < v[i].size() && v[i][r].second == v[i][r+1].first) r++;
      cum[2*v[i][l].first-1]++;
      cum[2*v[i][r].second]--;
      l = ++r;
    }
  }
  int ans = 0;
  REP(i,200005) {
    cum[i+1] += cum[i];
    CHMAX(ans,cum[i+1]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main() {
    long long n, x;
    cin >> n >> x;
    long long ans = 0;
    ans = x;
    long long a = x, b = n - x;
    while (true) {
        a %= b;
        if (a == 0) break;
        long long cnt = b / a;
        ans += cnt * a;
        b -= cnt * a;
        if (b == 0) {
            ans -= a;
           break;
       }
    }
    cout << ans * 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b,c;
	cin >> a >> b >> c;
	a[0]=toupper(a[0]);
	b[0]=toupper(b[0]);
	c[0]=toupper(c[0]);
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cstdlib>
#include <iostream>
#include <string>
#include <typeinfo>

using namespace std;

int min(int a,int b){
  return a < b ? a : b;
}
int abs(int a){
  return a < 0 ? -a : a;
}

int main()
{
  // 整数の入力                                                                                                                                                                                                  
  int N;
  cin >> N;
  int K;
  cin >> K;

  int b;

  int minsum = 0;

  for(int i = 0;i < N;i++){
    cin >> b;
    cerr << i << ":" << b << ":" << min(abs(b),abs(b - K)) << "\n";
    minsum += 2*min(abs(b),abs(b - K));
  }

  cout << minsum << "\n";

  // // スペース区切りの整数の入力                                                                                                                                                                               
  // int b,c;                                                                                                                                                                                                    
  // cin >> b >> c;                                                                                                                                                                                              
  // // 文字列の入力                                                                                                                                                                                             
  // string s;                                                                                                                                                                                                   
  // cin >> s;                                                                                                                                                                                                   
  // // 出力                                                                                                                                                                                                     
  // cout << (a+b+c) << " " << s << endl;                                                                                                                                                                        
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;

typedef long long LL;
#define X first
#define Y second
typedef pair<LL, LL> pii;
const int N = 220;

int dp[N][N][2];
char s[N][N];
int main() {
	int n, m;
	cin >> n >> m;
	for(int i = 1 ; i <= n; i ++)
		scanf("%s", s[i] + 1);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][1][0] = dp[0][1][1] = dp[1][0][0] = dp[1][0][1] = 0;
	for(int i = 1; i <= n; i ++) 
		for(int j = 1; j <= m; j ++) {
			if(s[i][j] == '#') {
				dp[i][j][1] = min(min(dp[i - 1][j][0], dp[i][j - 1][0]) + 1, min(dp[i - 1][j][1], dp[i][j - 1][1]));
				dp[i][j][0] = 1 + min(min(dp[i - 1][j][0] - (s[i - 1][j] == '#'), dp[i][j - 1][0] - (s[i][j - 1] == '#')), min(dp[i - 1][j][1], dp[i][j - 1][1]));
			} else {
				dp[i][j][0] = min(min(dp[i - 1][j][0], dp[i][j - 1][0]), 1 + min(dp[i - 1][j][1], dp[i][j - 1][1]));
				dp[i][j][1] = 1 + min(min(dp[i - 1][j][0], dp[i][j - 1][0]), min(dp[i - 1][j][1] - (s[i - 1][j] == '.'), dp[i][j - 1][1] - (s[i][j - 1] == '.')));
			}
		}
	printf("%d\n", min(dp[n][m][0], dp[n][m][1] + 1));
}



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

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

    int total = 0;
    rep (i, k) {
        if (i < a) total += 1;
        else if (i < a + b) total += 0;
        else total -= 1;
    }
    cout << total << endl;

}


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

#define MAX 100
#define Q_MAX 50
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY -1

// d[i]は始点sから各頂点iまでの最短距離
int M[MAX][MAX], color[MAX], d[MAX], Q[Q_MAX], head, tail;

void enqueue(int x){
  //if(x == 18) cout << "head: " << head << ", tail: " << tail << endl;
  Q[tail] = x;
  if(tail + 1 == Q_MAX) tail = 0;
  else tail++;
}

int dequeue(){
  int x = Q[head];
  if(head + 1 == Q_MAX) head = 0;
  else head++;
  return x;
}

// 頂点番号は0-オリジン
void bfs(int n, int s){
  // 初期化
  head = 0;
  tail = 0;
  for(int i=0; i<n; i++){
    color[i] = WHITE;
    d[i] = INFTY;
  }

  color[s] = GRAY;
  d[s] = 0;
  enqueue(s);

  int u;
  while(head != tail){
    u = dequeue();
    //cout << "u: " << u+1 << endl;
    for(int v=0; v<n; v++){
      if(M[u][v] && color[v] == WHITE){
        color[v] = GRAY;
        d[v] = d[u] + 1;
        //cout << "v: " << v+1 << endl;
        enqueue(v);
      } 
    }
    color[u] = BLACK;
  }
}

int main(void){
  int n, u, k, v;
  cin >> n;

  // M[][]の初期化
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(int i=0; i<n; i++){
    cin >> u >> k;
    u--; // 頂点番号を0-オリジンにする。
    for(int j =0; j<k; j++){
      cin >> v;
      M[u][--v] = 1; // 頂点番号を0-オリジンにする。
    } 
  }

  bfs(n, 0);
  for(int i=0; i<n; i++){
    cout << i+1 << " " << d[i] << endl;
  }
  return 0;
}



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

int main() {
	int n;cin>>n;
	string a[n];
	int time[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i]>>time[i];
	}
	string x;cin>>x;
	int start;
	for(int i=0;i<n;i++)
	{
	    if(a[i]==x){
	        start=i+1;
	        break;
	    }
	}
	int ans=0;
	for(int i=start;i<n;i++)
	    ans=ans+time[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/*====================================
Auther:    Shyam Makwana
Problem:   abc179_c.cpp
====================================*/

#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define add(a,b) ((a%mod)+(b%mod))%mod
#define mul(a,b) ((a%mod)*(b%mod))%mod
#define __lcm(a,b) ((a*b)/__gcd(a,b))
#define endl "\n"
#define MAX 1000005


int PrimeNum[1000001];
void sieve()
{
	int maxN=1000000;
	for(int i=1;i<=maxN;i++)
		PrimeNum[i]=0;

	// PrimeNum[0]=PrimeNum[1]=1;

	for(int i=1;i<=maxN;i++)
	{
		// if(PrimeNum[i]==2)
		// {
			for(int j=i;j<=maxN;j+=i)
				PrimeNum[j]++;
		// }
	}

	for(int i=2;i<=maxN;i++)
		PrimeNum[i]+=PrimeNum[i-1];

}

int32_t main()
{
	int n,m,a,b,c,d,n1;	
	int max1=INT_MIN,min1=INT_MAX;
	bool flag=true,flag1=true;
	fastio;	
	string str;

	sieve();

	cin>>n;

	cout<<PrimeNum[n-1];
}


Measured memory_bytes: 11456
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int n, m;
vector<int> vec[15];
int p[15];

int main(void)
{
	cin >> n >> m;
	int k, x;
	for(int i = 1; i <= m; i++){
		cin >> k;
		for(int j = 0; j < k; j++){
			cin >> x;
			x--;
			vec[i].push_back(x);
		}
	}
	for(int i = 1; i <= m; i++) cin >> p[i];
	
	int N = 1<<n, ans = 0;
	for(int i = 0; i < N; i++){
		bool flag = true;
		for(int j = 1; j <= m; j++){
			int cnt = 0;
			for(int k = 0; k < vec[j].size(); k++){
				if(i & (1<<vec[j][k]))cnt++;
			}
			if(cnt%2 != p[j]) flag = false;
		}
		if(flag) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 998244353;

int main() {
  ll N,L,T;cin >> N >> L >> T;
  vll X(N);
  vll Y(N);
  vint W(N);
  map<ll,int> mp;
  repeat(i,N){
    cin >> X[i] >> W[i];
    W[i] = 3-2*W[i];
    Y[i] = (X[i]+W[i]*(T%L)+L)%L;
    mp[Y[i]]++;
  }
  ll j=0;
  repeat(i,N){
    if(mp[Y[i]]==1){
      j=i;
      break;
    }
  }
  ll y0=Y[j];
  ll j0=j;
  for(int i=0;i<N;i++){
    if(W[j0]==W[i])continue;
    ll l = (L+W[j0]*(X[i]-X[j0]))%L;
    debug(l);
    if(2*T<l)continue;
    j = (j+W[j0]+N)%N;
    j = (j+W[j0]*(((2*T-l)/L)%N)+N)%N;
  }
  debug(j);
  vll ans(N);
  sort(Y.begin(),Y.end());
  int idx = lower_bound(Y.begin(),Y.end(),y0)-Y.begin();
  repeat(i,N){
    ans[(i+j)%N] = Y[(i+idx)%N];
  }
  repeat(i,N){
    cout << ans[i] << endl;
  }
  return 0;
}


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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
   int n; cin >> n;
   double ans = 0;
   rep{
           int ai;cin >> ai;
           ans += 1.0/ai;
   }
   printf("%.6f\n", 1.0/ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
   int a,b,c,k,h; cin>>a>>b>>c;
   h=0;
   for(k=a;k<=b;k++){
      if(c%k==0){
         h++;};};
   cout<<h<<endl;
      
      
      
      
      
   
}



Measured memory_bytes: 3116