akhauriyash/Code-Regression huggingface dataset:
import queue
import copy
 
H,W= map(int,input().split())
 
dy = [1,0,-1,0]
dx = [0,1,0,-1]

MAX_N = 0


L = [list(input()) for _ in range(H)]

for k in range(1,H+1):
    for l in range(1,W+1): 
        sy = k
        sx = l
        A = copy.deepcopy(L)
        # ↓だと、id(A)とid(L)は異なるが、id(A[0])とid(L[0])は同じになってしまう
        # A = copy.copy(L)
        # print(L)
        # print(id(A[0]),id(L[0]))

        if A[sy-1][sx-1] == '.':

            # FIFOキューの作成
            q = queue.Queue()
            q.put([sy-1,sx-1])
            
            # スタートを　0 にする
            A[sy-1][sx-1] = 0
            
            while not q.empty():
                # キューの先頭を取り出す
                tem = q.get()

                for i in range(4):
                    # 移動した後の座標をny,nxとおく
                    ny = tem[0] + dy[i]
                    nx = tem[1] + dx[i]
            
                    if (0<= ny < H) and (0<= nx < W) and A[ny][nx] == '.':
                        A[ny][nx] = A[tem[0]][tem[1]] + 1
                        if A[ny][nx] > MAX_N:
                            MAX_N = A[ny][nx]
                        q.put([ny,nx])

print(MAX_N)

Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
 
	int i,j,n,k;
 
	cin>>n>>k;
	int h[n];
	long long dp[n];
	for(i=0;i<n;i++)
	{
	    cin>>h[i];
 
	}
	for(i=0;i<n;i++)
	{
	    dp[i]=1000000010;
	}
	dp[0]=0;
	for(i=1;i<n;i++)
	{
	    for(j=max(0,i-k);j<i;j++)
	    {
	        dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
	    }
 
	   if(i==(n-1))
	   {
	       cout<<dp[n-1];
	   }
	}
 
	return 0;
}


Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int x,y; cin >> x >> y;
	rep(t, x+1){
		int k = x-t;
		if(t*2 + k*4 == y){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}


Measured memory_bytes: 3672
s = input()
k = int(input())
smallests = []


def ins(x):
    if len(smallests) == k and x > smallests[-1]:
        return
    if x in smallests:
        return
    smallests.append(x)
    smallests.sort()
    while len(smallests) > k:
        smallests.pop()


def solve():
    for i in range(len(s)):
        for size in range(1, k + 1):
            if i + size > len(s):
                break
            ins(s[i : i + size])
    return smallests[-1]


print(solve())


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

int main(){
  int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;

  vector<char> pre(k,'x');
  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    char hand = t[i];
    if(hand=='r'){
      if(pre[i%k]=='p') pre[i%k] = 'x';
      else{
        sum+=p;
        pre[i%k] = 'p';
      }
    }
    if(hand=='s'){
      if(pre[i%k]=='r') pre[i%k] = 'x';
      else{
        sum+=r;
        pre[i%k] = 'r';
      }
    }
    if(hand=='p'){
      if(pre[i%k]=='s') pre[i%k] = 'x';
      else{
        sum+=s;
        pre[i%k] = 's';
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 512
import sys
import time
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

K = int(input())

cnt = [0]*(K+1)
ans = 0
for k in range(1,K+1):
  i = 1
  while k*i <= K:
    cnt[k*i] += 1
    ans += k*i
    i += 1

print(ans)

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

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

    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    ll ans = 0;
    while(true){
        sort(all(a), greater<>());

        if(a[0] <= N - 1) break;

        ll num = a[0] / N;
        a[0] -= num * N;

        REP(i, N - 1) a[i + 1] += num;

        ans += num;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
results = ''
for A in range(N + 1):
    if A == 0:
        continue

    BBB = []
    AAA = []

    B = N - A
    if B >= 1:
        for b in range(len(str(B))):
            BBB.append(int(str(B)[b]))

        for a in range(len(str(A))):
            AAA.append(int(str(A)[a]))
        sums = sum(BBB) + sum(AAA)
        if sums == 1:
            print(A)
            print(B)
            print(AAA)
            print(BBB)

        if not results:
            results = sums
        else:
            if results > sums:
                results = sums
print(results)

Measured memory_bytes: 3064
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

using namespace std;

int main(void) {
  string s,t;
  cin >> s >> t;
  cout << t << s << endl;
  
  
  return 0;
}


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

typedef long long ll;
int main()
{
    ll n,m;
    vector<ll>v;
    cin>>n>>m;
    ll sum=0;
    while(n--)
    {
        ll a;
        cin>>a;
        sum+=a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    ll cnt=0;
    double id=(1.0*sum/(1.0*m))*(1/4.0);
    for(ll i=0;i<v.size();i++)
    {
        if(v[i]>=(id))
        {
            cnt++;
        }
    }
    if(cnt>=m)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using static MyMath;
public static class MyMath
{
    public static long gcd(long a, long b)
    {
        while (a != 0 && b != 0)
        {
            if (a > b)
                a %= b;
            else
                b %= a;
        }
        return a == 0 ? b : a;
    }
    public static long lcm(long a, long b)
    {
        return (a * b) / gcd(a, b);
    }

    public static IEnumerable<long> Divisors(long n)
    {
        var x = 2L;
        yield return 1;
        while (true)
        {
            if ((x * x) > n)
                break;
            if (n % x == 0)
            {
                yield return x;
                if ((n / x) != x)
                {
                    yield return n / x;
                }
            }
            x += 1;
        }
        if (n != 1)
            yield return n;
    }
}

namespace q3
{

    class Program
    {

        static void Main(string[] args)
        {
            var K = Convert.ToInt32(Console.ReadLine());
            long r = 0;
            for (var a = 1; a <= K; a++)
            {
                for (var b = 1; b <= K; b++)
                {
                    var ab = gcd(a, b);
                    for (var c = 1; c <= K; c++)
                    {
                        r += gcd(ab, c);
                    }
                }
            }
            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 27560
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string S;

int main(){
    cin>>S;

    ll ans=0;
    char prev='0';
    ll l=0, r=0;    // l:< , r:>
    rep(i,S.size()){
        if(prev=='>' && S[i]=='<'){
            ll maxi=max(l,r), mini=min(l,r);
            ans+=maxi*(maxi+1)/2;
            ans+=(mini-1)*mini/2;
            l=r=0;
        }
        if(S[i]=='<') l++;
        if(S[i]=='>') r++;
        prev=S[i];
    }
    ll maxi=max(l,r), mini=min(l,r);
    ans+=maxi*(maxi+1)/2;
    ans+=(mini-1)*mini/2;

    cout<<ans<<endl;
}

Measured memory_bytes: 900
def solve():
    from collections import Counter
    import sys
    input = sys.stdin.readline

    N, M, K = map(int, input().split())
    ABs = [tuple(map(int, input().split())) for _ in range(M)]
    CDs = [tuple(map(int, input().split())) for _ in range(K)]

    # Union-Findデータ構造
    class UnionFind:
        def __init__(self, numV):
            self.pars = list(range(numV))
            self.ranks = [0] * numV
        def find(self, x):
            if self.pars[x] == x: return x
            else:
                self.pars[x] = self.find(self.pars[x])
                return self.pars[x]
        def union(self, x, y):
            x, y = self.find(x), self.find(y)
            if x == y: return
            if self.ranks[x] < self.ranks[y]:
                self.pars[x] = y
            else:
                self.pars[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1
        def same(self, x, y):
            return self.find(x) == self.find(y)

    UF = UnionFind(N)
    for A, B in ABs:
        A, B = A-1, B-1
        UF.union(A, B)

    for i in range(N):
        UF.find(i)

    cnt = Counter(UF.pars)
#    print('cnt:', cnt)

    anss = [cnt[UF.pars[i]]-1 for i in range(N)]
#    print('anss:', anss)

    for A, B in ABs:
        A, B = A-1, B-1
        if UF.same(A, B):
            anss[A] -= 1
            anss[B] -= 1
    for C, D in CDs:
        C, D = C-1, D-1
        if UF.same(C, D):
            anss[C] -= 1
            anss[D] -= 1

    print(' '.join(map(str, anss)))


solve()


Measured memory_bytes: 114908
#!/usr/bin/env python3
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
            #return self.find(self.parents[x])

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
n,m,k = map(int,input().split())
uf = UnionFind(n)
#初期化したら友達関係を受け取ってufを形成していく union
friend = [0]*n
# 友達が何人いるかも必要
for i in range(m):
    a,b = map(int,input().split())
    friend[a-1] += 1
    friend[b-1] += 1
    uf.union(a-1,b-1)
# uf が完成したら,c,d を受け取り、parentの値が同じならblock[c],bloc[d]+=1をする
block = [0]*n
for j in range(k):
    c,d = map(int,input().split())
    if uf.find(c-1) == uf.find(d-1):
        block[c-1]+=1
        block[d-1]+=1
"""
print(uf.parents)
print(block)
print(friend)"""
for i in range(n):
    #print(abs(uf.parents[uf.find(i)]),":",i)
    print(abs(uf.parents[uf.find(i)]) - 1 - friend[i] - block[i],end=" ")

Measured memory_bytes: 93528
#include <bits/stdc++.h>
using namespace std;
int dp[1<<16][16];
int main() {
  int n;
  while(cin >> n && n) {
    string s,s2;
    cin >> s >> s2;
    int r=0;
    for(int t=0;t<(1<<n);t++)for(int i=0;i<n;i++)dp[t][i]=1<<29;
    for(int i=0;i<n;i++)if(s[i]==s2[i]) r|=1<<i;
    for(int i=0;i<n;i++)dp[r][i]=0;
    for(int t=0;t<(1<<n);t++) {
      for(int i=0;i<n;i++) {
        if(dp[t][i]==1<<29) continue;
        string e="";
        for(int j=0; j<n;j++) {
          if(t&(1<<j)) e+='1';
          else e+='0';
        }
        for(int j=0;j<n;j++) {
          if(t&(1<<j)) continue;
          for(int k=j+1;k<n;k++) {
            if(t&(1<<k)||s[j]==s[k]) continue;
            dp[t|(1<<j)|(1<<k)][j]=min(dp[t|(1<<j)|(1<<k)][j],dp[t][i]+abs(i-k)+abs(k-j));
            dp[t|(1<<j)|(1<<k)][k]=min(dp[t|(1<<j)|(1<<k)][k],dp[t][i]+abs(i-j)+abs(j-k));
          }
        }
      }
    }
    int ans=1<<29;
    for(int i=0;i<n;i++)ans=min(ans,dp[(1<<n)-1][i]);
    cout << ans << endl;
  }
  return 0;
}

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

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

    int res = 0;

    vector<vector<int> > s(m);
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;

        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            --x;
            s[i].push_back(x);
        }
    }

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

    for (int bit = 0; bit < (1<<n); bit++) {
        vector<bool> switchOn(n);
        for (int i = 0; i < n; i++) {
            if (bit & (1<<i)) {
                switchOn[i] = true;
            }
        }

        // 追加の処理
        // それぞの電球が繋がっているスイッチがONになっているものの個数が欲しい
        bool judge = true;
        for (int i = 0; i < m; i++) {
            int counter = 0;
            for (const auto& element : s[i]) {
                if (switchOn[element]) counter++;
            }
            // ONの個数が２で割れるかどうかをちぇっくしてp_iと照合をする。
            if (counter % 2 != p[i]) judge = false;
        }
        if (judge) ++res;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;
#define MAXN 100010
int n;
vector<int> adj[MAXN];
int dist[2][MAXN];

void calcd(int w, int k){
	vector<bool> visited(n+1, false);
	queue<pair<int, int>> q;
	q.push({w, 0});
	visited[w] = true;
	while(not q.empty()){
		int u = q.front().ff;
	       	int d = q.front().ss; q.pop();
		dist[k][u] = d;
		for(auto v:adj[u]){
			if(visited[v]) continue;
			visited[v] = true;
			q.push({v, d+1});
		}
	}
}


int32_t main(){
	ios::sync_with_stdio(0);
	int t, a;
	cin >> n >> t >> a;
	for(int i=0; i<n-1; ++i){
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	calcd(t, 0);
	calcd(a, 1);
	int ans = 0;
	for(int i=1; i<=n; ++i)
		if(dist[1][i]>=dist[0][i]) ans = max(ans, dist[1][i]);
	cout << ans-1 << endl;
}


Measured memory_bytes: 8288
// template version 1.10
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings {{{
#define infile "../test/sample-4.in"
#define int long long
const int INF=1e18;
const int MOD=1e9+7;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
//}}}

// dump macro {{{
#if defined(PCM) || defined(LOCAL)
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
// }}}

int solve(){
  int M,K;cin>>M>>K;
  dump(M,K);

  if (M==1 && K==1){
    cout << -1 << endl;
    return 0;
  }

  if (M==1 && K==0){
    cout << "0 0 1 1" << endl;
    return 0;
  }

  if (K>(pow(2, M)-1)){
    cout << -1 << endl;
    return 0;
  }

  vi res;
  int L = pow(2, M);
  rrep(i, L){
    if (i!=K) res.pb(i);
  }
  res.pb(K);
  rep(i, L){
    if (i!=K) res.pb(i);
  }
  res.pb(K);

  rep(i, sz(res)) cout << res[i] << (i!=sz(res)-1 ? " " : "\n");
  dump(sz(res));

  vi val(2*L,0);
  val[0] = res[0];
  rep(i, 1, 2*L) val[i] = val[i-1]^res[i];
  dump(res);
  dump(val);

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 6128
r,g,b,n = (int(i) for i in input().split())
ans = 0
for i in range(n//r+1):
    for j in range((n-(i*r))//g+1):
        k = (n-r*i-j*g)//b
        if r*i+j*g+abs(k*b) == n:
            ans += 1
print(ans)


Measured memory_bytes: 40556
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        int Q = scan.nextInt();
        int[][] map = new int[N][N];
        for (int i = 0; i < M; i++) {
            int L = scan.nextInt() - 1;
            int R = scan.nextInt() - 1;
            map[L][R] += 1;
        }
        int[][] sum = new int[N][N+1];
        for (int i = 0; i < N; i++) {
            for (int j = 1; j <= N; j++) {
                sum[i][j] = sum[i][j-1]+map[i][j-1];
            }
        }
        for (int i = 0; i < Q; i++) {
            int p = scan.nextInt()-1;
            int q = scan.nextInt()-1;
            int ans = 0;
            for (int j = p; j <= q; j++) {
                ans += sum[j][q+1]-sum[j][p];
            }
            System.out.println(ans);
        }
    }
    private int findL(int[] x, int key) {
        int l = 0;
        int r = x.length - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (key <= x[mid]) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }

    private int findR(int[] x, int key) {
        int l = 0;
        int r = x.length - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (x[mid] <= key) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return r;
    }
}


Measured memory_bytes: 155580
#include <cstdio>
#include <algorithm>
int a[1001],b[510001],*p;main(){
	int n,m,i,j,k,r;
	for(;scanf("%d%d",&n,&m)>1&&n;printf("%d\n",r)){
		for(i=1;i<=n;i++)scanf("%d",a+i);
		for(k=i=0;i<=n;i++)for(j=i;j<=n;j++)b[k++]=a[i]+a[j];
		std::sort(b,b+k);
		for(r=i=0;b[i]<=m&&i<k;i++){
			p=std::upper_bound(b,b+k,m-b[i]);
			if(p>b&&r<b[i]+*(p-1))r=b[i]+*(p-1);
		}
	}
}

Measured memory_bytes: 3008
import numpy as np
from itertools import product
from collections import  defaultdict as dd
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
wi = wv[0][0]
vi = wv[0][1]
dic = dd(list)
dic_cumsum = dd(list)
for w,v in wv:
    dic[w].append(v)

for k,v in dic.items():
    tmp = sorted(v, reverse=True)
    dic_cumsum[k] = [0] + list(np.zeros((N + 1), dtype=np.int64))
    dic_cumsum[k][1:] = list(np.cumsum(tmp, dtype=np.int64))
for i in range(1,4):
    if wi+i not in dic_cumsum.keys():
        dic_cumsum[wi+i] = [0]
        
n = [len(dic_cumsum[wi]), len(dic_cumsum[wi+1]), len(dic_cumsum[wi+2]), len(dic_cumsum[wi+3])]
m = [list(range(val)) for val in n]
res = 0

for ls in product(m[0], m[1], m[2]):
    if sum(ls)*wi > W:
        continue
    tmp_value = 0
    tmp_weight = 0
    for i,k in enumerate(ls):
        tmp_value += dic_cumsum[wi + i][k]
        tmp_weight += k*(wi+i)
    if tmp_weight > W:
        continue
    # wi, wi+1, wi+2の個数が決まっているので、wi+3を何個取れるかはO(1)で求められる
    max_m3 = (W - tmp_weight) // (wi+3)
    m3 = min(max_m3, n[3]-1)
    tmp_value += dic_cumsum[wi+3][m3]
    if tmp_value > res:
        res = tmp_value
print(res)




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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
   int n; cin >> n;
   V<int> a(n);
   for(int i = 0; i < n; i++) cin >> a[i];

   int p = 1, cnt = 0;;
   for(int i = 0; i < n; i++){
       if(a[i] != p) cnt++;
       else p++;
   }
   if(cnt == n) cout << -1 << endl;
   else cout << cnt << endl;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

ab.sort(key=lambda x: x[1])
ans = 0
x = -9999999999
for a, b in ab:
    if x <= a:
        x = b
        ans += 1

print(ans)

Measured memory_bytes: 29568
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
    
    int i;
    int n;
    char *x;
  	x= (char *)malloc(200000);
    int w=0;
    int ans=0;
    scanf("%d",&n);
    scanf("%s",x);
 
  	char *y;
  	y = x;
    for ( i=0;i<n;i++)
    {
        if (strncmp(y,"R",1) == 0)
        {
            w++;
        }
      	++y;
    }
  	y=x;
    for (i=0;i<w;i++)
    {
        if (strncmp(y,"W",1)==0)
        {
            ans++;
        }
      	++y;
    }
 
    printf("%d",ans);
free(x);
    return 0;
}

Measured memory_bytes: 1780
//#pragma GCC optimize("O2")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pi>;
const int maxn = 2e2 + 55;
const int mod = 1e9 + 7;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, cnt = 1, ans = 0;
	cin >> n;
	while(n) {
		ans += cnt;
		n>>=1;
		cnt<<=1;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
    cin>>a>>b>>c>>d;
    if (abs (a-c)<=d||(abs (a-b)<=d&&abs (b-c)<=d))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int hi, hy;
	int ki, ky;
	int a, b, c, d;

	int hpoint = 0, kpoint = 0;

	scanf("%d %d", &hi, &hy);
	scanf("%d %d", &ki, &ky);
	scanf("%d %d %d %d", &a, &b, &c, &d);

	hpoint = (hi * a) + (hy * b);
	kpoint = (ki * a) + (ky * b);


	while (hi >= 10) {
		hpoint += c;
		hi -= 10;
	}
	while (hy >= 20) {
		hpoint += d;
		hy -= 20;
	}
	while (ki >= 10) {
		kpoint += c;
		ki -= 10;
	}
	while (ky >= 20) {
		kpoint += d;
		ky -= 20;
	}

	if (hpoint > kpoint) {
		printf("hiroshi\n");
	}
	else if (hpoint < kpoint) {
		printf("kenjiro\n");
	}
	else if (hpoint == kpoint) {
		printf("even\n");
	}

	return 0;
}


Measured memory_bytes: 2684
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#define PI acos(-1.0)
#define LL long long
#define MAX 0x3fffffff
using namespace std;

LL n, ans = 1;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	while (n) {
		ans *= 2;
		n /= 2;
	}
	cout << ans - 1 << endl;
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long int64;
int64 n;
vector<int> meth[2];
int m;
int main()
{
    scanf("%lld", &n), ++n;
    for(int i = 1; n > 1; ++i) meth[n&1].push_back(i), n = n&1?(n-1):(n>>1);
    m = meth[0].size()+meth[1].size(); printf("%d\n", m<<1);    
    for(int i = 0; i < meth[1].size(); ++i) printf("%d ", meth[1][i]);
    for(int i = meth[0].size()-1; ~i; --i) printf("%d ", meth[0][i]);
    for(int i = m; i; --i) printf("%d ", i);
    return 0;
}

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


using namespace std;

int main(void){
  int n,a,b;
  cin >> n >> a >> b;
  int asum = 0;
for (int i1 = 0; i1 < n+1; i1++){
  int s = 0;
  int i = i1;
  if(i == 10000){
    s = 1;
  }else{
     if(i / 1000 != 0){
       s += i / 1000;
       i = i%1000;
     }
     if(i / 100 != 0){
       s+=i/100;
       i = i%100;
     }
     if(i / 10!=0){
       s+=i/10;
       i = i%10;
     }
     s += i;
  }
  if (s>= a&&s<=b){
    asum += i1;
  }
}

cout << asum << endl;

return 0;

}


Measured memory_bytes: 256
import heapq

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

table = [list(map(int, input().split())) for _ in range(n)]
table.sort(reverse=True)

ans = 0
pay = []

for day in range(1, m+1):
    while table and table[-1][0] <= day:
        tmp = table.pop()
        heapq.heappush(pay, -tmp[1])
   
    if pay:
        ans -= heapq.heappop(pay)

print(ans)

Measured memory_bytes: 28080
#include<stdio.h>

/*??????????????¢??°*/
long int diff(long int x,long int y) {
	return y - x;
}

int main(void) {
	long int a, b, n, i, d;
	scanf("%d", &n);/*n???????????\???*/
	scanf("%d", &a);/*R1?????\???*/
	for (i = 0; i < n-1; i++) {
		scanf("%d", &b);/*R2??\????????\???*/
		if(i==0)
			d = diff(a, b);
		if (diff(a,b) > d)/*R1??¨Rt??????????????§???*/
			d = diff(a, b);
		if (a > b)/*R1???????????????*/
			a = b;
	}
	printf("%d\n", d);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
using M=Mint<int>;
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int &p:v)cin>>p;
  map<int,int> m;
  for(int p:v){
    int tmp=p;
    for(int j=2;j*j<=tmp;j++){
      int cnt=0;
      while(tmp%j==0)tmp/=j,cnt++;
      chmax(m[j],cnt);
    }
    chmax(m[tmp],1);
  }
  M lcm{1};
  for(auto p:m)lcm*=M(p.first).pow(p.second);
  M ans{0};
  for(int p:v)ans+=lcm/p;
  cout<<ans<<endl;
}


Measured memory_bytes: 768
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353
#define meme(x) memset((x), 0, sizeof((x)))
#define memo(x) memset((x),-1, sizeof((x)))
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

// #define int ll

ll egcd(ll a, ll b, ll &x, ll &y){
    if (a == 0LL){  
        x = 0LL;  
        y = 1LL;  
        return b;  
    }
    ll xx, yy;
    ll val = egcd(b % a, a, xx, yy);  
    x = yy - (b / a) * xx;  
    y = xx;  
    return val;
}

ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

//  ==========     //\\       //||     ||====//||
//      ||        //  \\        ||     ||   // ||
//      ||       //====\\       ||     ||  //  ||
//      ||      //      \\      ||     || //   ||
//  ========== //        \\  ========  ||//====|| 
//  code

void solve(){
    ll n,i,j,k,l,p,w;
    cin >> n >> w;
    vector< vector<ll> > dp(n + 1, vector<ll>(100001, INT_MAX));
    vector<ll> weights(n), values(n);
    for(i = 0; i < n; i++){
        cin >> weights[i] >> values[i];
    }

    dp[0][0] = 0LL;
    for(i = 0; i < n; i++){
        for(j = 0; j < 100001; j++){
            dp[i + 1][j] = dp[i][j];
            if(j >= values[i]){
                if(dp[i][j - values[i]] + weights[i] <= w){
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - values[i]] + weights[i]);
                }
            }
        }
    }

    p = 0;
    for(i = 0; i < 100001; i++){
        if(dp[n][i] <= w){
            p = i;
        }
    }
    cout << p << endc;
}

int32_t main(){
    init;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 83168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

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

    vector<bool> isprime(100005, true);
    isprime[0] = isprime[1] = false;
    for (int i = 2; i * i <= 100000; ++i)
        for (int j = 2; i * j <= 100000; ++j)
            if (isprime[i * j])
                isprime[i * j] = false;

    vector<int> cnt(100005);
    for (int i = 3; i <= 100000; i += 2)
        if (isprime[i] && isprime[(i + 1) / 2])
            cnt[i]++;
    for (int i = 1; i <= 100000; ++i)
        cnt[i] += cnt[i - 1];

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        l--;
        cout << cnt[r] - cnt[l] << '\n';
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	long long h, w, ans = 1LL << 62, smax, smin;
	cin >> h >> w;

	for (int k = 0; k < 2; ++k) {
		for (int i = 1; i <= h - 2; ++i) {
			smax = smin = w * i;
			if ((h - i) % 2 == 0) {
				smax = max(smax, (h - i) / 2 * w);
				smin = min(smin, (h - i) / 2 * w);
			}
			else {
				smax = max(smax, (h - i + 1) / 2 * w);
				smin = min(smin, (h - i - 1) / 2 * w);
			}
			ans = min(ans, smax - smin);
		}

		for (int i = 1; i <= h - 1; ++i) {
			smax = smin = w * i;
			if (w % 2 == 0) {
				smax = max(smax, (h - i) * w / 2);
				smin = min(smin, (h - i) * w / 2);
			}
			else {
				smax = max(smax, (h - i) * (w + 1) / 2);
				smin = min(smin, (h - i) * (w - 1) / 2);
			}
			ans = min(ans, smax - smin);
		}

		swap(h, w);
	}

	cout << ans << endl;

	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

unsigned GetDigit(unsigned num) {
	unsigned digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

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

	int cnt = 0;
	int tmp = 0;

	for (int i = 1; i <= n; i++)
	{
		int num = i;
		int dig;
		int sum = 0;

		

		if (GetDigit(num) % 2 == 1) cnt++;

	}

	ANS(cnt);
}

Measured memory_bytes: 256
use std::collections::VecDeque;

fn main() {
    let (n, q): (usize, usize) = {
        let v = read_vec::<usize>();
        (v[0], v[1])
    };

    // 双方向パスのリストを作る
    let mut to: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..n-1 {
        let v = read_vec::<usize>();
        // 双方向パスの記録(0オリジンに直す)
        to[v[0] - 1].push(v[1] - 1);
        to[v[1] - 1].push(v[0] - 1);
    }

    // 答え
    let mut counter = vec![0; n];
    for _ in 0..q {
        let v = read_vec::<usize>();
        counter[v[0] - 1] += v[1];
    }

    // dfs
    let mut queue = VecDeque::new();
    queue.push_back((0, 0));
    
    while let Some((parent, value)) = queue.pop_front() {
        // valueの子要素にvalueの値を加える
        for &next in to[value].iter() {
            // valueから伸びるパスの先が親でない場合のみ処理
            if next != parent {
                counter[next] += counter[value];
                queue.push_back((value, next));
            }
        }
    }


    // 表示
    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", counter[i]);
    }
    println!();
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T  {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap())
    .collect()
}

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

#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define rep(i , j , k) for(int i = j ; i <= k ; i ++)
#define Rep(i , j , k) for(int i = j ; i >= k ; i --)

using namespace std ;
using ll = long long ;
using pii = pair <int , int> ;
using vii = vector <int> ;

auto ot = [&]() { cerr << "ATS TXDY" << '\n' ; int ATS_nantf_txdy = true ; } ;
auto _ios = [&]() { ios :: sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr) ; } ;

namespace stO_ATS_Orz {
  template < class T > void cmax(T & x , T y) { if(x > y) x = y ; }
  template < class T > void cmin(T & x , T y) { if(x < y) x = y ; }
  template < class T > void abs(T x) { if(x < 0) x = -x ; }
  void main() {
    int a , b ;
    int c , d ;
    cin >> a >> b >> c >> d ;
    if(a < c) cout << 1 << '\n' ;
    else cout << 0 << '\n' ;
  }
}
signed main() {
  _ios() ; ot() ;
  return stO_ATS_Orz :: main() , 0 ;
}

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

char tmp;
int len;

int main()
{
    int tmpp=1e9;
    printf("? %d\n",tmpp);
    fflush(stdout);
    scanf("\n");
    scanf("%c",&tmp);
    if(tmp=='Y')
    {
        int ask_num=1e9-1;
        int ans=1e9;
        len=9;
        while(1)
        {
            printf("? %d\n",ask_num);
            fflush(stdout);
            scanf("\n");
            scanf("%c",&tmp);
            if(tmp=='N')break;
            len--;
            ask_num/=10;
            ans/=10;
            if(ans==1)break;
        }
        printf("! %d",ans);
    }
    else
    {
        int ask_num=1e8;
        len=9;
        while(1)
        {
            printf("? %d\n",ask_num);
            fflush(stdout);
            scanf("\n");
            scanf("%c",&tmp);
            if(tmp=='Y')break;
            len--;
            ask_num/=10;
        }
        int l=1,r,mid;
        for(int i=1;i<len;i++)l*=10;
        r=l*10;r--;l+=1;
        while(l<r)
        {
            mid=(l+r)/2;
            long long cao=mid;
            cao*=10;
            printf("? %lld\n",cao);
            fflush(stdout);
            scanf("\n");
            scanf("%c",&tmp);
            if(tmp=='Y')r=mid;
            else l=mid+1;
        }
        printf("! %d",l);
    }
    return 0;
}


Measured memory_bytes: 596
N=int(input())
S_dict={}
 
for s_idx in range(N):
    s = input()
    
    if s not in S_dict:
        S_dict.update({s:1})
    else:
        S_dict.update({s:S_dict[s]+1})
        
s_max=max(S_dict.values())
 
ans = []    
 
for a,b in S_dict.items():
    if b == s_max:
        ans.append(a)
    
ans.sort()
 
for i in ans:
    print(i)

Measured memory_bytes: 92248
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());
#define OUT(d) cout << (d);
#define OUT_L(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define CEIL(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  int a,b,c; cin >> a>>b>>c;
  OUT_L(a*b/2)
}


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

int main()
{
	int N = 0, ans = 0;
	std::cin >> N;

	std::vector<int> H(N);
	for (int i = 0; i < N; i++){
		std::cin >> H[i];
	}

	int cnt = 0;
	for (int i = N-1; i > 0; i--){
		if (H[i] <= H[i - 1]){
			cnt++;
		}
		else{
			cnt = 0;
		}
		ans = std::max(ans, cnt);
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<string> s;
    string temp;
    int ans = 0;

    for (int i = 0; i < n; i++) {
        cin >> temp;
        s.push_back(temp);
    }

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

    for (int i = 0; i < n-1; i++) {
        if (s[i] == s[i + 1]) {
            ans++;
        }
    }

    cout << n - ans;



    return 0;
}

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

int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    rep(i, l, r+1){
        if(i%d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
s = input()
d = ["dream","dreamer","erase","eraser"]

while s:
    if s[-5:] == d[0] or s[-5:] == d[2]:
        s = s[0:-5]
    elif s[-6:] == d[3]:
        s = s[0:-6]
    elif s[-7:] == d[1]:
        s = s[0:-7]
    else:
        break

if len(s) == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 133916
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(60)]

for i in range(N):
    n=A[i]
    #print(n)
    for j in range(60):
        L[j]+=n//(2**(59-j))
        n%=(2**(59-j))
        #print(n)
#print(L)
ans=0
for i in range(60):
    ans+=(N-L[i])*(L[i])*2**(59-i)
    ans%=(10**9+7)
print(ans)

Measured memory_bytes: 122808
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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



signed main () {
    int n,k;cin >>n>>k;
    vector<int> a(n);
    rep(i,n)cin >>a[i];
    rep(i,n-k){
        if(a[i]<a[i+k])cout <<"Yes"<<endl;
        else cout <<"No"<<endl;
    }

}





Measured memory_bytes: 4840
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#define LL long long
#define PP std::pair<int,int>
#define TT std::tuple<int,int,int>
std::vector<TT> res;
int rank[200010];
int par[200010];
int ans[200010];
int N, K, L;
void init(int n) {
	for (int i = 1; i <= N; i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}

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]++;
	}
	return;
}

int memo[200010];
bool same(int x, int y) {
	return find(x) == find(y);
}

int main() {
	std::cin >> N >> K >> L;
	init(N);
	for (int i = 0; i < K; i++) {
		int a, b;
		std::cin >> a >> b;
		unite(a, b);
	}
	for (int i = 1; i <= N; i++) {
		memo[i] = find(i);
	}
	init(N);
	for (int i = 1; i <= L; i++) {
		int a, b;
		std::cin >> a >> b;
		unite(a, b);
	}
	for (int i = 1; i <= N; i++) {
		res.push_back(TT{ memo[i],find(i),i });
	}
	std::sort(res.begin(), res.end());
	std::vector<int> S;
	int a, b, c;
	TT t = res[0];
	std::tie(a, b, c) = t;
	S.push_back(c);
	int befa, befb;
	befa = a;
	befb = b;
	for (int i = 1; i < (int)res.size(); i++) {
		t = res[i];
		std::tie(a, b, c) = t;
		if (a == befa&&b == befb) {
			S.push_back(c);
		}
		else {
			for (auto u : S) {
				ans[u] += S.size();
			}
			S.clear();
			befa = a;
			befb = b;
			S.push_back(c);
		}
	}
	for (auto u : S) {
		ans[u] += S.size();
	}
	for (int i = 1; i <= N; i++) {
		std::cout << ans[i];
		if (i != N)std::cout << " ";
	}
	std::cout << std::endl;
	return 0;
}

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

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

Measured memory_bytes: 256
#include <cstdio>
#include <limits.h>
using namespace std;

const int N = 25;
int a[N], b[N], c[N], n;
long long tot;

int main() {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
	 	scanf ("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
	 	scanf ("%d", &b[i]), tot += b[i];
	for (int i = 1; i <= n - 1; ++i)
	 	scanf ("%d", &c[i]);
	for (int i = 2; i <= n; ++i) {
		if (a[i] == a[i - 1] + 1) {
			tot += c[ a[i - 1] ];
		}
	}
	printf ("%lld\n", tot);
	return 0;
}

Measured memory_bytes: 128
class UnionFindTree
	#0→連結成分のサイズ 1→parent 2→rank 3→連結成分に含まれる人
	attr_accessor :nodes
	def initialize(size)
		@nodes = Array.new(size)
		size.times do |i|
			@nodes[i] = -1
		end
		nodes = @nodes
	end

	# x番目の値の親を探す
	def findParent(x)
		if @nodes[x] < 0 then 
			return x
		else
			return findParent(@nodes[x])
		end
	end

	# 合併
	def unite(x, y)
		xx = findParent(x)
		yy = findParent(y)
		return if xx == yy

		xx, yy = yy, xx if @nodes[xx] > @nodes[yy]

		@nodes[xx] += @nodes[yy]
		@nodes[yy] = xx
		#@nodes[xx][2] += 1 if @nodes[xx][2] == @nodes[y][2]
		#@nodes[xx][3] += @nodes[yy][3]

		# if @nodes[xx][2] < @nodes[yy][2] then
		# 	@nodes[xx][1] = yy
		# 	@nodes[xx][0] += @nodes[yy][0]
		# 	@nodes[yy][0] = @nodes[xx][0]
		# else
		# 	@nodes[yy][1] = xx
		# 	@nodes[yy][0] += @nodes[xx][0]
		# 	@nodes[xx][0] = @nodes[yy][0]
		# 	@nodes[xx][2] += 1 if @nodes[xx][2] == @nodes[yy][2]
		# end
	end

	def same(x, y)
		return findParent(x) == findParent(y)
	end
end

n, m, k = gets.chomp.split(" ").map(&:to_i)
group = UnionFindTree.new(n)
kankei = Array.new(n).map{Array.new}

# p group.nodes
m.times do 
	a, b = gets.chomp.split(" ").map{|ngo| ngo.to_i - 1}
	group.unite(a,b)
	#p group.nodes.map{|ma| ma[1]}
	# p group.nodes
 	kankei[a] << b
	kankei[b] << a
end

k.times do
	a, b = gets.chomp.split(" ").map{|ngo| ngo.to_i - 1}
	kankei[a] << b
	kankei[b] << a
end

# puts "group"; p group.nodes ;puts 
# puts "kankei"; p kankei; puts
n.times do |i|
	par = group.findParent(i)
	num = group.nodes[par] * -1
	unchi = kankei[i].count{|hotti| group.findParent(hotti) == par}
	#yaju << num - unchi - 1
	print (num - unchi - 1).to_s + " "
	#puts "par:#{par} num:#{num} unchi:#{unchi} yaju:#{yaju}"
	#puts "i:#{i} par:#{par} num:#{group.nodes[par][0]} group:#{group.nodes[i][3]}"
	# list = group.nodes[par][3]
	# ngo = list - hash[i]
	#print ((group.nodes[par][3] - hash[i]).length - 1).to_s + " "
end
puts 


Measured memory_bytes: 21116
import math

n, X, D = map(int, input().split())

if D == 0:
	if X == 0:
		print(1)
	else:
		print(n + 1)
	exit()

Y = dict()

for i in range(n + 1):
	b = -2 * i * X
	r = (n - 1 + n - i) * i // 2
	l = (0 + i - 1) * i // 2
	off = b % (-2 * D)
	l += (b - off) // (-2 * D)
	r += (b - off) // (-2 * D)
	if off in Y:
		Y[off].append((l, r))
	else:
		Y[off] = [(l, r)]

def calc(u):
	pt = dict()
	for l, r in u:
		if l in pt:
			pt[l] += 1
		else:
			pt[l] = 1
		if r + 1 in pt:
			pt[r + 1] -= 1
		else:
			pt[r + 1] = -1
	cur, v = -10 ** 100, 0
	ans = 0
	for k in sorted(pt.keys()):
		if v:
			ans += k - cur
		v += pt[k]
		cur = k
	return ans

print(sum(map(calc, Y.values())))


Measured memory_bytes: 98756