akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=16,M=(1<<16);
ll dp[M];
int number[M];
vector<int> yes[N+1];
ll a[N][N];
ll sum[M];
ll calc(int tr)
{
    if(dp[tr]!=-1)
        return dp[tr];
    dp[tr]=LLONG_MIN;
    vector<int> pos;
    for(int i=0;i<N;i++)
    {
        if((1<<i)&tr)
            pos.pb(i);
    }
    int k=number[tr];
    for(int m=1;m<(1<<k);m++)
    {
        int ne=0;
        for(int i=0;i<k;i++)
        {
            if((1<<i)&m)
            {
                ne^=(1<<pos[i]);
            }
        }
        int rem=tr^ne;
        ll cost=sum[ne]+calc(rem);
        dp[tr]=max(dp[tr],cost);
    }
    return dp[tr];
}
int main()
{
    for(int i=0;i<M;i++)
        dp[i]=-1;
    sum[0]=0;
    dp[0]=0;
    int n;
    scanf("%i",&n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            scanf("%lld",&a[i][j]);
    for(int i=0;i<(1<<n);i++)
    {
        int k=__builtin_popcount(i);
        number[i]=k;
        yes[k].pb(i);
    }
    for(int i=1;i<=n;i++)
    {
        for(auto p:yes[i])
        {
            for(int j=0;j<n;j++)
            {
                if((1<<j)&p)
                {
                    sum[p]=sum[(1<<j)^p];
                    for(int l=j+1;l<n;l++)
                    {
                        if((1<<l)&p)
                        {
                            sum[p]+=a[j][l];
                        }
                    }
                    break;
                }
            }
        }
    }
    //printf("Uradio!\n");
    printf("%lld\n",calc((1<<n)-1));
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll n,k;
	cin>>n>>k;
	ll res=0;
	for(ll b=k+1;b<=n;++b){
		ll t=(n-k)/b,total=0;
		for(ll i=1;i<=t+1;++i){
			ll hi=i*b;
			ll lo=k+b*(i-1);
			if(lo==0) lo++;
			if(lo<=hi&&lo<=n) total+=min(n,hi-1)-lo+1;

		}
		//cerr<<b<<' '<<total<<'\n';
		res+=total;
	}
	cout<<res<<'\n';
}




Measured memory_bytes: 3628
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b,k = LI()
    for i in range(k):
        if i % 2 == 0:
            a //= 2
            b += a
        else:
            b //= 2
            a += b

    return '{} {}'.format(a,b)


print(main())


Measured memory_bytes: 5720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
#define mn -
#define pls +
#define mod %
#define E =
#define EE ==
#define le <=
#define ge <=
int mx=9999999;
/**  '' "\n" - ^ **/

    void yes()
    {
        cout<<"Yes\n";
    }

    void no()
    {
        cout<<"No\n";
    }
    void YES()
    {
        cout<<"YES\n";
    }

    void NO()
    {
        cout<<"NO\n";
    }

    void Case(int i,int n)
    {
        cout<<"Case:"<<i<<" "<<n<<endl;
    }
    /**  '' "\n" x ^ **/
    /** printf("\n") */

    bool comp(pair<int,int> a,pair<int,int> b)
    {
        if(a.second != b.second)//return false;
        return a.first<b.first;
        return true;
    }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    if(n mod 1000 EE 0){cout<<0;return 0;
	}
    cout<< 1000 mn (n % 1000)<<endl;

}


Measured memory_bytes: 3656
import sys
k = int(input())
a = dict()
cnt = 0
base = 0
while True:
    cnt += 1
    base = (base*10+7)%k
    if base == 0:
        break
    if base in a:
        cnt = -1
        break
    else:
        a[base] = 1
print(cnt)

Measured memory_bytes: 92404
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=100000+10;
const int maxm=100000+10;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const ll LINF=(1LL<<62);
const double eps=1e-8;
const double PI=acos(-1.0);
#define mst(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<b;i++)
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define lowbit(x) x&(-x)
#define X first
#define Y second
int main(){
#ifdef local
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
    //ios::sync_with_stdio(false); cin.tie(0);
    char s[10]={0};
    scanf("%s",s);
    int ans=0;
    for (int i=0;i<3;i++)
        if (s[i]=='1') ans++;
    printf("%d\n",ans);
    return 0;
}


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

int main() {
	string S;
	cin >> S;

	int ans = 0;
	if (S[0] == 'R' && S[0] == S[1] && S[0] == S[2]) {
		cout << 3 << endl;
		return 0;
	}
	else if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R') {
			ans++;
			if (S[0] == 'R' && S[0] == S[1] || S[1] == 'R' && S[1] == S[2])ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3656
N = int(input())
A = list(map(int, input().split()))
B = sum(list(map(int, input().split())))
C = list(map(int, input().split()))
for i in range(N - 1):
    if A[i + 1] == A[i] + 1:
        B += C[A[i] - 1]
print(B)

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

struct UnionFind{
    vector<int> p; // p[i]: 頂点iの親の番号

    // 初期化 -> 自分の親は自分自身
    UnionFind(int n){
        rep(i,n) p.push_back(i);
    }

    // 頂点xに対応する木の根を見つける
    int root(int x){
        if (p[x] == x) return x;
        else return p[x] = root(p[x]);
    }

    // 頂点xの木と頂点yの木を統合
    void unite(int x, int y){
        x = root(x); y = root(y);
        if (x != y) p[x] = y;
    }

    bool same(int x, int y){
        return (root(x) == root(y));
    }
};

int main(){
    int N, M; cin >> N >> M;
    vector<int> position(N);
    rep(i, N){
        int P; cin >> P; P--;
        position[P] = i;
    }

    UnionFind UF(N);
    rep(i, M) {
        int x, y; cin >> x >> y; x--; y--;
        UF.unite(x,y);
    }

    int ans = 0;
    rep(i,N){
        if(UF.root(position[i]) == UF.root(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1276
n,k=map(int,input().split())
td=[list(map(int,input().split()))[::-1]for _ in range(n)]
td.sort(reverse=1)
s=set()
ss=set()
a=[]
b=[]
c=[]
for i in range(n):
  if i<k:
    d,t=td[i]
    if t in s:
      b.append(d)
    else:
      a.append(d)
      s.add(t)
      ss.add(t)
  else:
    d,t=td[i]
    if t not in ss:
      c.append(d)
      ss.add(t)
c=c[::-1]
ls=len(s)
su=sum(a)+sum(b)
ans=ls*ls+su
for i in range(min(len(b),len(c))):
  ls+=1
  su-=b.pop()
  su+=c.pop()
  ans=max(ans,ls*ls+su)
print(ans)

Measured memory_bytes: 28916
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def generate_inv(n,mod):
    """
    逆元行列
    n >= 2
    Note: mod must bwe a prime number
    """
    ret = [0, 1]
    for i in range(2,n+1):
        next = -ret[mod%i] * (mod // i)
        next %= mod
        ret.append(next)
    return ret

def comb_mod2(n, a, mod, inv):
    """
    return: [n, a] % mod
    Note: mod must be a prime number
    """
    if a == 0:
        return 1 % mod
    ret = 1
    for i in range(1, a + 1):
        ret *= n - i + 1
        ret %= mod
        ret *= inv[i]
        ret %= mod
    return ret

def run():
    S = int(input())
    inv = generate_inv(S, mod)

    ans = 0
    for k in range(1, S//3+1):
        v = comb_mod2(S-3 * k + k -1, k-1, mod, inv)
        ans += v
        ans %= mod

    print(ans)

if __name__ == "__main__":
    run()


Measured memory_bytes: 9252
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    if(n<10) cout << n << endl;
    else if(n<100) cout << 9 << endl;
    else if(n<1000) cout << n - 90 << endl;
    else if(n<10000) cout << 909 << endl;
    else if(n<100000) cout << n - 9090 << endl;
    else if(n==100000) cout << 90909 << endl;

    return 0;
}



Measured memory_bytes: 256
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

int main() {
	int h1, m1, h2, m2, k;
	cin>>h1>>m1>>h2>>m2>>k;
	
	int t1 = h1*60+m1;
	int t2 = h2*60+m2;
	
	cout<<(t2-t1-k)<<endl;

    return 0;
}



Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
int a[3];

int main(){
	cin >> n;
	REP(i, n)cin >> a[i];
	sort(a, a + n);
	FOR(i, 1, a[n - 1] + 1){
		if (n == 2){
			if (a[0] % i == 0 && a[1] % i == 0)cout << i << endl;
		}
		else{
			if (a[0] % i == 0 && a[1] % i == 0 && a[2] % i == 0)cout << i << endl;
		}
	}
}

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

int main(){
    int l;
    cin>>l;
    
    double L=(double)l;
    /*
    double max = 0.0;
    for(double i=0.01 ;i<=L;i=i+0.01){
        for(double j=0.01;j<=L-i;j=j+0.01){
            for(double k=0.01;k<=L-i-j;k=k+0.01){
                if(max<i*j*k){
                    max=i*j*k;
                }
            }
        }
    }
    cout<<max<<endl;
    */
   cout<<setprecision(14)<<(L/3.0)*(L/3.0)*(L/3.0)<<endl;

    return 0;
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> weight(N);
    vector<ll> value(N);
    for(int i = 0; i < N; i++) cin >> weight[i] >> value[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
    for(int sum_w = 0; sum_w <= W; sum_w++) dp[0][sum_w] = 0;

    for(int i = 0; i < N; i++){
        for(int sum_w = 0; sum_w <= W; sum_w++){
            if(sum_w >= weight[i]){
                dp[i + 1][sum_w] = max(dp[i][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }else dp[i + 1][sum_w] = dp[i][sum_w];
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 80256
#88c
c_array = []
for i in range(3):
    c_list = [int(e) for e in input().split()]
    c_array.append(c_list)
    
#整数 a1,a2,a3,b1,b2,b3 の値が決まっており, マス (i,j) には数 ai+bj が書かれているらしいです.
#ci,j (1≤i≤3,1≤j≤3) は 0 以上 100 以下の整数

#a1+b1 a1+b2 a1+b3
#a2+b1 a2+b2 a2+b3
#a3+b1 a3+b2 a3+b3

#a1+b1 = c11　…(1)
#a1+b2 = c12　…(2)
#a1+b3 = c13　…(3)
#a2+b1 = c21　…(4)
#a2+b2 = c22　…(5)
#a2+b3 = c23　…(6)
#a3+b1 = c31　…(7)
#a3+b2 = c32　…(8)
#a3+b3 = c33　…(9)

#(1)-(2)
#b1 - b2 = c11 - c12
#(4)-(5)
#b1 - b2 = c21 - c22  
#(7)-(8)
#b1 - b2 = c31 - c32　∴c11 - c12 = c21 - c22 = c31 - c32

#(2)-(3)
#b2 - b3 = c12 - c13
#(5)-(6)
#b2 - b3 = c22 - c23  
#(8)-(9)
#b2 - b3 = c32 - c33　∴c12 - c13 = c22 - c23 = c32 - c33

#(1)-(3)
#b1 - b3 = c11 - c13
#(4)-(6)
#b1 - b3 = c21 - c23  
#(7)-(9)
#b1 - b3 = c31 - c33　∴c11 - c13 = c21 - c23 = c31 - c33

#c11 - c12 = c21 - c22 = c31 - c32
#c12 - c13 = c22 - c23 = c32 - c33
#c11 - c13 = c21 - c23 = c31 - c33

c11 = c_array[0][0]
c12 = c_array[0][1]
c13 = c_array[0][2]
c21 = c_array[1][0]
c22 = c_array[1][1]
c23 = c_array[1][2]
c31 = c_array[2][0]
c32 = c_array[2][1]
c33 = c_array[2][2]

if (c11 - c12 == c21 - c22 and
    c21 - c22 == c31 - c32 and
    c11 - c12 == c31 - c32 and 
    c12 - c13 == c22 - c23 and
    c22 - c23 == c32 - c33 and
    c12 - c13 == c32 - c33 and
    c11 - c13 == c21 - c23 and
    c21 - c23 == c31 - c33 and
    c11 - c13 == c31 - c33):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0050
{
	class Program
	{
		static void Main(string[] args)
		{
			var	s1	= Console.ReadLine(); 
			var	s2	= s1.Replace( "apple", "xxxxx" );
			var	s3	= s2.Replace( "peach", "apple" );
			var	s4	= s3.Replace( "xxxxx", "peach" );
			Console.WriteLine( s4 );
		}
	}
}

Measured memory_bytes: 5276
N,W = map(int,input().split())
value,weight = [0],[0]
for i in range(N):
  w,v = map(int,input().split())
  value.append(v)
  weight.append(w)
V = sum(value)
dp = [[0]+[10**12]*V for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(1,V+1):
    dp[i][j] = min(dp[i-1][j], dp[i-1][max(0, j-value[i])]+weight[i] )
for i in range(V,0,-1):
  if dp[N][i] <= W:
    print(i)
    quit()

Measured memory_bytes: 137628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    long long int x,c,a;
    cin>>n>>m>>x;
    std::vector<vector<long long int>> vec(n,vector<long long int>(m+1));
    for (int i=0;i<n;i++) {
        cin>>c;
        vec[i][0]=c;
        for (int j=1;j<m+1;j++) {
            cin>>a;
            vec[i][j]=a;
        }
    }
    std::deque<long long int> deq(m,0);
    std::deque<int> tmp;
    long long int sum=0,min_sum=10000000;
    for (int bit=0;bit<(1<<n);bit++) {
        for (int k=0;k<n;k++) {
            if (bit&(1<<k)) {
                tmp.emplace_back(k);
            }
        }
        for (int pp=0;pp<tmp.size();pp++) {
            for (int l=0;l<m+1;l++) {
                if (l==0) {
                    sum+=vec[tmp[pp]][l];
                } else {
                    deq[l-1]+=vec[tmp[pp]][l];
                }
            }
        }
        int flag=0;
        for (int o=0;o<m;o++) {
            if (deq[o]<x) {
                flag=1;
                break;
            }
        }
        if (flag==0) {
            if (sum<min_sum) {
                min_sum=sum;
            }
        }
        sum=0;
        for (int hoge=0;hoge<m;hoge++) {
            deq[hoge]=0;
        }
        tmp.clear();
    }
    if (min_sum==10000000) {
        cout<<-1<<endl;
    } else {
        cout<<min_sum<<endl;
    }
}

Measured memory_bytes: 3600
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<char,char> pcc;
typedef tuple<ll,ll,ll> t3;

int main(void) {
    ll n,k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    const vector<char> tokens = {'r', 's', 'p'};
    ll m[3][3];
    for(int i = 0;i<3;i++){
        for(int j = 0;j < 3;j++){
            m[i][j]= 0;
        }
    }
    m[0][2] = p;
    m[1][0] = r;
    m[2][1] = s;
    unordered_map<char,int> mToI;
    mToI['r']= 0;
    mToI['s']= 1;
    mToI['p']= 2;
    vector<vector<ll>> dp(n+1, vector<ll>(3,0));
    for(int i = 0;i < k;i++){
        auto c = mToI[t[i]];
        for(int j = 0;j < 3;j++){
            dp[i][j] = max(dp[i][j], m[c][j]);
        }
    }
    for(ll i = k;i < n;i++){
        auto c = mToI[t[i]];
        for(int a = 0; a < 3;a++){
            for(int b = 0;b < 3;b++){
                if(a == b){
                    continue;
                }
                ll score = m[c][b];
                ll prev =dp[i-k][a];
                dp[i][b] = max(dp[i][b], score + prev);
            }
        }
    }
    ll sum = 0;
    for(ll i = n-k;i < n;i++){
        ll mm = 0;
        for(int j = 0;j < 3;j++){
            mm = max(mm, dp[i][j]);
        }
        //cout << i << " " << mm << endl;
        sum += mm;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 5760
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int N;
	float x[20];
	string u[20];
	int i, j;
	float sum = 0;
	cin >> N;

	for (i = 0; i < N; ++i) {
		cin >> x[i] >> u[i];
	}


	for (i = 0; i < N; ++i) {
		if (u[i] == "BTC") {
			x[i] *= 380000;
		}
	}


	for (i = 0; i < N; ++i) {
		sum += x[i];
	}

	cout << sum << endl;




}



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

int main() {
  int X,A,B;
  cin >> X >> A >> B;
  if(-A+B<=0){
    cout << "delicious" << endl;
  }
  else if(-A+B<=X){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
}

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

using namespace std;

int main(){
  long long A, B;
  assert(cin >> A >> B);
  long long ans = 0;
  while(A--){
    ans += max(A, (long long) 0);
  }
  while(B--){
    ans += max(B, (long long) 0);
  }
  cout << ans;
  return 0;
}


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


int main() {
  string s;
  cin >> s;
  string ans = "ABC";
  if(s == ans) ans = "ARC";
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3628
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

void solve(long long n, long long m, string s, string t){
	LL ans=n*m/__gcd(n,m);			
	LL l1=ans/n,l2=ans/m;
	int p1=0,p2=0;
	while(p1<n && p2<m) {
		if (1+p1*l1==1+p2*l2) {
			if (s[p1]!=t[p2]) {
				puts("-1");
				return;
			} else {
				p1++;
				p2++;
			}
		} else if (1+p1*l1<1+p2*l2) {
			++p1;
		} else {
			++p2;
		}
	}
	cout<<ans<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long M;
	string T;
	string S;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&M);
	cin >> S;
	cin >> T;
	solve(N, M, S, T);
	return 0;
}



Measured memory_bytes: 640
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

temp = [0]*(10**5+1)
ans = 0

for i in A:
    temp[i] += 1
    ans += i
for i in range(Q):
    B, C = map(int,input().split()) 
    ans += temp[B]*(C-B)
    temp[C] += temp[B]
    temp[B] = 0

    print(ans)
    


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N; string S, T;
  cin >> N >> S >> T;

  for (int i = 0; i < N; i++){
    string ans = "";
    for (int j = 0; j < i; j++) ans += S[j];
    for (int j = 0; j < N; j++) ans += T[j];

    bool flag = true;
    for (int j = 0; j < N; j++){
      if (ans[j] != S[j]) flag = false;
    }
    if (flag){
      cout << ans.length() << endl;
      return 0;
    }
  }
  cout << N * 2 << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        b.at(i)=a.at(i);
    }
    sort(all(a));
    for (int i = 0; i < n; i++)
    {
        if (b.at(i) == a.at(n - 1))
        {
            cout << a.at(n - 2) << endl;
        }
        else
        {
            cout << a.at(n - 1) << endl;
        }
    }
}

Measured memory_bytes: 3200
a, b, k = map(int, input().split())

for i in range(a, min(b, a + k - 1) + 1):
    print(i)
for i in range(max(a + k, b - k + 1), b + 1):
    print(i)

exit()
l = list(range(a, b + 1))
ans = []
ans.extend(l[:min(k,len(l))])
ans.extend(l[max(0,len(l) - k):])

ans = sorted(list(set(ans)))
for a in ans:
   print(a)

Measured memory_bytes: 3064
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    num = len(set(a))
    aset=set(a)

    if sum(a) == 0:
        print('Yes')
        return
    # if n % 3 != 0:
        # print('No')
        # return
    if len(cnt.most_common()) == 3:
        a1, a2, a3 = aset
        if cnt.most_common()[0][1] == cnt.most_common()[1][1] == cnt.most_common()[2][1]  and a1 ^ a2 == a3:
            # print(cnt.most_common())
            print('Yes')
            return

    if len(cnt.most_common()) == 2:

        tmp_min = cnt.most_common()[1][1]
        tmp_max = cnt.most_common()[0][1]
        if 3 * tmp_min == n and int(cnt.most_common()[1][0]) == 0:
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 18076
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long a,b,c,k, ans=0;
    cin >> a >> b >> c >> k;
    if(k<=a){
        for(int i=0; i<k; i++){
            ans++;
        }
        cout << ans;
        return 0;
    }else if(a<=k && k<=a+b){
        for(int i=0; i<a; i++){
            ans++;
        }
        cout << ans;
        return 0;
    }else if(a+b<k){
        for(int i=0; i<a; i++){
            ans++;
        }
        for(int i=0; i<k-a-b; i++){
            ans--;
        }
        cout << ans;
        return 0;
    }
}

Measured memory_bytes: 3632
//Chat in a Circle

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    nvarep(n,a);
    sort(range(a),greater<int>());
    int ans=0;
    rep(i,1,n){
        int t = i/2;
        ans+=a[t];
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
#include <ctime>
#include <cassert>
#include <memory.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define mp(x, y) make_pair(x, y)
#define fst first
#define snd second

using namespace std;

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

#define FILE_NAME ""

ll q, h, s, d, n;
const ll inf = (ll)1e18;

bool read() {
  if (!(cin >> q >> h >> s >> d >> n)) {
    return 0;
  }
  return 1;
}

void solve() {
  n *= 4;
  ll cost = min({d, 2 * s, 4 * h, 8 * q});
  
  ll ans = (n / 8) * cost;
  n %= 8;

  vll dp(n + 1, inf);
  dp[0] = 0;
  vi add = {1, 2, 4, 8};
  vll cst = {q, h, s, d};
  
  forn (i, n) {
    forn (j, 4) if (i + add[j] <= n) {
      dp[i + add[j]] = min(dp[i + add[j]], dp[i] + cst[j]);  
    }
  }

  cout << dp[n] + ans << endl;
}

int main() {
#ifdef LOCAL
  freopen(FILE_NAME ".in", "r", stdin);
  freopen(FILE_NAME ".out", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);

  while (read()) {
    solve();
  }

#ifdef LOCAL
  cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<set>
using namespace std;
#define R for(i=0;i<n;++i)
#define L(l,m,n) l=max(l,min(max(a[i]-e,m),max(f-a[i],n)));
int a[1<<17],b[1<<17],e=1e7,f=-1e7,g=1e7,h=-1e7,n,c,d,j=-1e7,k=-1e7,i;int main(){scanf("%d",&n);R{scanf("%d%d",&c,&d);a[i]=c+d;b[i]=c-d;e=min(e,a[i]);f=max(f,a[i]);g=min(g,b[i]);h=max(h,b[i]);}R{L(j,b[i]-g,h-b[i])L(k,h-b[i],b[i]-g)}printf("%d\n",min(j,k));}

Measured memory_bytes: 1816
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

vector<int> G[201010];
int c[201010];
ll ans[201010];
ll sub[201010];
unordered_map<int, vector<int>> dic[201010];
void dfs(int v, int pv) {
    for (auto nv : G[v]) {
        if (nv==pv) continue;
        dfs(nv,v);
        sub[v] += sub[nv];
        if (dic[nv].find(c[v])==dic[nv].end()) ans[c[v]] += (sub[nv])*(sub[nv]+1)/2;
        else {
            ll val = 0;
            for (auto j : dic[nv][c[v]]) {
                val += sub[j];
            }
            ans[c[v]] += (sub[nv]-val)*(sub[nv]-val+1)/2;
        }
        if (dic[v].size() < dic[nv].size()) {
            swap(dic[v],dic[nv]);
        }
        for (auto A : dic[nv]) {
            for (auto j : A.second) {
                dic[v][A.first].emplace_back(j);
            }
        }
    }
    dic[v][c[v]].clear();
    dic[v][c[v]].emplace_back(v);
    sub[v]++;
    return;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    set<int> zzz;
    rep(i,N) {
        cin >> c[i];
        --c[i];
        zzz.emplace(c[i]);
    }
    rep(i,N-1) {
        int u,v; cin >> u >>  v;
        --u; --v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    dfs(0,-1);
    //rep(i,N) cout << ans[i] << ln;
    for (auto i : dic[0]) {
        ll val = 0;
        for (auto j : i.second) {
            val += sub[j];
        }
        ans[i.first] += (sub[0]-val)*(sub[0]-val+1)/2;
    }
    rep(i,N) {
        if (!zzz.count(i)) cout << 0 << ln;
        else cout << (N+1)*N/2 - ans[i] << ln;
    }

    
}




Measured memory_bytes: 112700
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;


int main(void) {
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    vector<int>C(N-1);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for(int i = 0; i < N-1; i++) {
        cin >> C[i];
    }
    int ans = B[A[0]-1];
    int before = A[0];
    for(int i = 1; i < N; i++) {
        int after = A[i];
        ans += B[A[i]-1];
        if(after-before == 1) {
            ans += C[before-1];
        }
        before = A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var s string
    fmt.Scan(&s)
    ans := 0
    for i:=len(s)-2;i>=0;i-=2{
        flg := true
        for j:=0;j<i/2;j++{
            if s[j]!=s[i/2+j]{
                flg = false
            }
        }
        if flg{
            ans = i
            break
        }
    }
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int W = in.nextInt();
		int[] w = new int[n];
		int[] v = new int[n];
		for (int i = 0; i < n; ++i) {
			w[i] = in.nextInt();
			v[i] = in.nextInt();

		}
		long r = solve(n, W, w, v);
		System.out.println(r);
		in.close();
	}

	private static long solve(int n, int W, int[] w, int[] v) {
		int maxValue = 0;
		for (int i = 0; i < v.length; i++) {
			maxValue += v[i];
		}
		long[] state = new long[maxValue + 1];
		Arrays.fill(state, Long.MAX_VALUE);
		state[0] = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = maxValue; j >= v[i - 1]; j--) {
				if (state[j - v[i - 1]] != Long.MAX_VALUE) {
					state[j] = Math.min(state[j], state[j - v[i - 1]] + w[i - 1]);
				}

			}
		}
		for (int i = state.length - 1; i >= 0; i--) {
			if (state[i] <= W) {
				return i;
			}
		}
		return -1;
	}

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v[505];

int main(){
  ll n;
  cin >> n;
  map<string, ll> ma;
  for (int i=0;i<n;i++){
    string tmp;
    cin >> tmp;
    if (ma.count(tmp)) ma[tmp] += 1;
    else ma[tmp] = 1;
  }
  
  ll m;
  cin >> m;
  for (int i=0;i<m;i++){
    string tmp;
    cin >> tmp;
    if (ma.count(tmp)) ma[tmp] -= 1;
    else ma[tmp] = -1;
  }
  
  ll ans = 0;
  for (auto it=ma.begin();it!=ma.end();++it){
    pair<string, ll> p = *it;
    if (p.second > ans) ans = p.second;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
package main
import (
    "fmt"
    "strings"
)

func main(){
    var s string
    fmt.Scan(&s)
    for i, char := range strings.Split(s, "") {
        if i%2 == 0 { // 奇数
            if char == "L" {
                fmt.Println("No")
                return
            }
        } else {
            if char == "R" {
                fmt.Println("No")
                return
            }
        }
    }
    fmt.Println("Yes")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  scanf("%d %d %d",&n,&a,&b);
  if(abs(b-a-1)&1){
    puts("Alice");
  } else {
    puts("Borys");
  }
  return 0;
}

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

using namespace std;
#define INF (1e9)

int main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];

  int ans = INF;

  for (int i = 0; i < 3; i++) {
    int tmp =
        min(abs(a[(i + 1) % 3] - a[i]) + abs(a[(i + 2) % 3] - a[(i + 1) % 3]),
            abs(a[(i + 2) % 3] - a[i]) + abs(a[(i + 1) % 3] - a[(i + 2) % 3]));
    ans = min(ans, tmp);
  }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
  int n,i;
  char s;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%c",&s);
    if(s=='Y') {
      printf("Four");
      return 0;
    }
  }
  printf("Three");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int a;
  cin >> a;
  long long int b = a / 11;
  long long int ans = 0;
  if(a%11==0) ans = 2*b;
  else if(a%11<=6) ans = 2*b+1;
  else ans = 2*b + 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      int n;
      cin>>n;
      set<string> s;
    REP(i,n)
    {
        string r;
        cin>>r;
        s.insert(r);
    }
    cout<<s.size();
  }  
  return 0;
}

Measured memory_bytes: 19216
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = LS()
    if a[1][0] == "+":
        print(int("".join(a[0])) + int("".join(a[2])))
    else:
        print(int("".join(a[0])) - int("".join(a[2])))
    return

#B
def B():
    _ = II()
    t = LI()
    tsum = sum(t)
    for _ in range(II()):
        p, x = LI()
        print(tsum - t[p - 1] + x)
    return

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    ans = 1
    if n & 1:
        for i in a:
            if i & 1:
                print(0)
                return
            d[i] += 1
        for a, b in d.items():
            if a:
                if b == 2:
                    ans *= 2
                    ans %= mod
                    continue
                print(0)
                return
            if b == 1:
                continue
            print(0)
            return
    else:
        for i in a:
            if i & 1:
                d[i] += 1
                continue
            print(0)
            return
        for a, b in d.items():
            if b == 2:
                ans *= 2
                ans %= mod
                continue
            print(0)
            return
    print(ans)
            
        
    return

#D
def D():
    n = II()
    binmax = len(bin(n)) - 1
    dp = [[0] * 3 for i in range(binmax)]
    dp[0][0] = 1
    for i in range(binmax - 1):
        if n & (1 << (binmax - 2 - i)):
            dp[i + 1][0] = dp[i][0] % mod
            dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod
            dp[i + 1][2] = (2 * dp[i][1] + 3 * dp[i][2]) % mod
        else:
            dp[i + 1][0] = (dp[i][0] + dp[i][1]) % mod
            dp[i + 1][1] = dp[i][1] % mod
            dp[i + 1][2] = (dp[i][1] + 3 * dp[i][2]) % mod
    print(sum(dp[binmax - 1]) % mod)

    return


#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 41456
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn get_seen(s: &[usize]) -> Vec<bool> {
    let mut seen = vec![false; 26 + 1];
    seen[0] = true;
    for i in 0..s.len() {
        if s[i] == 0 { return seen; }
        seen[s[i]] = true;
    }
    seen
}

fn print_str(s: &[usize]) {
    for i in 0..s.len() {
        if s[i] == 0 { break; }
        print!("{}", (s[i] as u8 -1 + 'a' as u8) as char);
    }
    println!();
}

fn main() {
    input!{
        ss: chars
    }
    let mut s = vec![0; 26];
    for i in 0..ss.len() {
        let c = ss[i];
        // 1-26
        let c = c as usize - 'a' as usize + 1;
        s[i] = c;
    }

    // 1
    if ss.len() < 26 {
        let idx = s.iter().position(|&v|v==0).unwrap();
        let value = get_seen(&s).iter().position(|&v|v==false).unwrap();
        s[idx] = value;
        print_str(&s);
    } else {
        let mut pool = vec![];
        let mut idx = (s.len() - 2) as isize;
        pool.push(s[s.len()-1]);

        'outer: while idx >= 0 {
            for &v in &pool {
                if s[idx as usize] < v {
                    s[idx as usize] = v;
                    break 'outer;
                }
            }
            pool.push(s[idx as usize]);
            idx -= 1;
        }
        if idx == -1 {
            println!("{}", -1);
            return;
        }

        let idx = idx as usize;
        for i in idx+1..26 {
            s[i] = 0;
        }
        print_str(&s);
    }
}


Measured memory_bytes: 4352