akhauriyash/Code-Regression huggingface dataset:
N,M,Q=map(int,input().split())
N=550
A=[]
for i in range(M+Q):
    L,R=map(int,input().split())
    A.append([L,R])
#print(A)
B = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
    B[A[i][0]][A[i][1]] +=1
#print(*B,sep='\n')
C = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
    for k in range(N):
        if k==0:
            C[i][k] = B[i][k]
        else:
            C[i][k] += C[i][k-1]+B[i][k]
#print('\n')
#print(*C,sep='\n')
for i in range(M,M+Q):
    total=0
    for k in range(N):
        if A[i][0]<=k<=A[i][1]:
            total+=C[k][A[i][1]]-C[k][A[i][0]-1]
    print(total)

Measured memory_bytes: 116312
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ "; for(auto v : V) os << v << " "; return os << "]";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1<<" | ";
	__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mems(x, y) memset(x, y, sizeof(x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define irep(i, n) for (int i = 1; i <= n; ++i)
#define print(x) cout << x << '\n'
#define err(x) clog << x << '\n'
typedef long long ll;
#define int ll
typedef long double ld;
#define double ld
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 0x3f3f3f3f;
const int M = 1e9+7;
const int N = 3e3+5;

int f[N][N];
int g[N][N];

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

	int n; cin >> n;
	string s; cin >> s;

	f[1][1] = 1; g[1][1] = 1;
	irep(i, n) {
		if (i == 1) continue;
		irep(d, i) {
			if (s[i-2] == '<') {
				f[i][d] = g[i-1][d-1];
			} else {
				f[i][d] = g[i-1][i-1] - g[i-1][d-1];
				f[i][d] += M, f[i][d] %= M;
			}
			g[i][d] = g[i][d-1] + f[i][d], g[i][d] %= M;
		}
	}

	print(g[n][n]);
}


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

#define FIO    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll     long long int

using namespace std;

void solve()
{
	ll n, tot=0 ,d;
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=1;i<n;i++)
	{
		if(a[i]<a[i-1]){
			d=(a[i-1]-a[i]);
			tot+=d;
			a[i]+=d;
		}
	}
	cout<<tot;

	return;
}

int main()
{    
    FIO;

    int t=1;
    // cin>>t;
    while(t--)
    	solve();

    return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;
#define MOD 1000000007LL

int main(){
  ll N;
  cin >> N;
  vll A(N);
  vll count(60, 0);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    int x = 0;
    for(int j = 0; j < 60; j++){
      if((A.at(i)>>j)&1) count.at(j)++;
    }
  }
  ll ans = 0;
  for(int i = 0; i < 60; i++){
    ll n = (1LL << i) % MOD; 
    ans += (count.at(i) * (N - count.at(i))) % MOD * n % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,ans,cnt,a;
    cin >> n;
    vector<ll> sum(n);
    cin >> a;
    sum[0] = a;
    rep1(i, n){
        cin >> a;
        sum[i] = sum[i - 1] + a;
    }
    ans = abs(sum[n - 1] - sum[0] * 2);
    rep1(i, n - 1){
        cnt = abs(sum[n - 1] - sum[i] * 2);
        ans = min(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int isPrime(int x) {
    int i;
    if ( x < 2 ) return 0;
    else if(x == 2 ) return 1;
    if (x % 2 == 0) return 0;
    for (i = 3; i*i <= x; i+= 2) {
        if (x % i == 0) return 0;
    }
    return 1;
}

int main() {
    int n, x, i;
    int cnt = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &x);
        if ( isPrime(x)) cnt++;
    }
    printf("%d\n", cnt);
    
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

long long modFact(long long n, long long mod = MODV){
    if(n == 0) return 1;
    else return n * modFact(n-1) % mod;
}

int main(){
    Init();
    ll n, m; cin >> n >> m;
    if(abs(n-m) >= 2) cout << 0 << endl;
    else{
        if(n == m) cout << (modFact(n, MODV)*modFact(m, MODV))%MODV*2%MODV << endl;
        else cout << (modFact(n, MODV)*modFact(m, MODV))%MODV << endl;
    }
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
long long ans;
int main()
{
	string s;
	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			long long nn=0;
			for(int k=i;k<=j;k++)nn=nn*10+(s[k]-'0');
			for(int k=1;k<i;k++)nn*=2;
			for(int k=j+2;k<n;k++)nn*=2;
			ans+=nn;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    int b = 1;
    int n = s.length();
    rep(i, n) {
        if (s[i] == 'B') {
            ans += n - i - b;
            b++;
        }
    }

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

Measured memory_bytes: 640
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A,B=get_i
P=get_i
group=array(3,0)
P.each do|p|
    if p<=A
        group[0]+=1
    elsif p<=B
        group[1]+=1
    else
        group[2]+=1
    end
end
puts group.min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}
int main(void)
{ 
 double a, b, h, m;
 cin >> a >> b >> h >> m;
 double rad = abs((30*h+30*(m/60))-(360*(m/60)));
 if(rad>180){
   rad = 360 - rad;
 }
 //cout << rad << endl;
 double pi = rad/180*M_PI;
 double ans = sqrt(a*a + b*b -2*a*b*cos(pi));
 cout << setprecision(21) << ans << endl;
 return 0;
}


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

typedef long long int64;
int n, x, a[4005];

int main() {
	scanf("%d%d", &n, &x);

	int64 s = 0;

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

	int64 ans = s;
	for(int k = 0; k < n; k++) {
		int64 res = 1LL * k * x;
		multiset <int> s;

		int j = (n - k) % n;

		for(int l = j; l != 0; l = (l + 1) % n)
			s.insert(a[l]);

		for(int i = 0; i < n; i++) {
			s.insert(a[i]);

			int mn = *s.begin();
			res += mn;

			s.erase(s.find(a[j]));

			j = (j + 1) % n;
		}

		ans = min(ans, res);
	}

	printf("%lld\n", ans);
	return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  std::string s;
  std::cin >> s;

  int64_t c = 0;
  int64_t i = 1;
  char d = s.front();
  bool flag = false;
  while (k != 0 && i != s.size()) {
    if (s[i] != d) {
      if (!flag) {
        k--;
      }
      s[i] = d;
      flag = true;
    } else {
      flag = false;
    }
    i++;
  }
  if (flag) {
    while (i != s.size()) {
      if (s[i] != d) {
        s[i] = d;
      } else {
        break;
      }
      i++;
    }
  }

  for (int64_t i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      c++;
    }
  }

  std::cout << c << std::endl;
  return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

int n,k;
ll a[15],mi=LINF;

void dfs(int idx,ll ma,ll sum,int num) {
	//cout<<idx<<' '<<ma<<' '<<sum<<' '<<num<<endl;
	if(idx==n) {
		if(num>=k) mi=min(mi,sum);
		return;
	}
	dfs(idx+1,max(ma,a[idx]),sum,num);
	if(ma<a[idx]) dfs(idx+1,a[idx],sum,num+1);
	else {
		ll cost=ma-a[idx]+1;
		dfs(idx+1,ma+1,sum+cost,num+1);
	}
}

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

	cin>>n>>k;
	REP(i,n) cin>>a[i];

	dfs(0,0,0,0);
	cout<<mi<<endl;

	return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cout << lcm(2,n) << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <math.h>

using namespace std;
#define ll long long

int main()
{
   // freopen("aa_input.txt", "r", stdin);
    ll n;
    cin>>n;
    ll sum = 0;
    for(int i=1; i<=n; i++){
        if(i%3==0 || i%5==0){
            continue;
        }
        else sum += i;
    }
    cout<<sum<<endl;

    /*
    ll sum = (n*(n-1))/2;
    cout<<sum<<endl;
    ll three = n/3;
    ll five = n/5;
    ll three_five = n/15;
    three_five = three_five/2;
    cout<<((sum-(three+five))-three_five)<<endl;
    */
    
    return 0;
}
/*

riaadmorshed@gmail.com

*/

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

using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  int p[n];
  for(int i=0;i<n;i++) cin>>p[i];

  sort(p,p+n);

  int res = 0;
  for(int i=0;i<k;i++) res+=p[i];

  cout << res << "\n";
}


Measured memory_bytes: 3572
import math
mod = 1000000007
N,M = list(map(int,input().strip().split()))
l = []

ans = 1
cnt = 0
while  M%2 == 0:
  M //= 2
  cnt += 1
l.append(cnt)
cnt = 0

i = 3
while i**2 <= M:
  cnt = 0
  while M%i == 0:
    M //= i
    cnt += 1
  if cnt != 0:
    l.append(cnt)
    cnt = 0
  i += 2
if M != 1:
    l.append(1)

for i in l:
  for j in range(i):
    ans = ans*(N+j)//(j+1)

print(ans%mod)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
/******************************TYPE name************************************/
typedef long long ll;
typedef vector<int> vi;
typedef pair<int ,int > pii;
typedef map<int,int>mii;

/***********************************MACRO*************************/
#define test int ct;cin>>ct;while(ct--)
#define fo(i,n) for( i=0;i<n;i++)
#define el <<"\n"
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define sq(a) (a)*(a)
#define file() freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define zro 1e-9
#define F first
#define S second
#define pb(a) push_back(a)
#define sqsum(n) (((n)*(n+1)*(2*(n)+1))/6) //sum of square number 1 to n
#define mltpls(first,last,ratio) ((last)*(ratio)-(first))/(ratio-1) //multiple series
#define linear_sum(n) (n)*(n+1)/2; //sum of 1 to n
#define arithmetic_progression(first,last,ratio) ((ratio)*(first+last))/2
#define rb rbegin()
#define re rend()
#define bg begin()
#define en end()
#define itr iterator
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
int i;
#define gcd(a,b) __gcd(a,b)
#define gl(s) getline(cin,s)

//code: amr and music :: map of vector

/********************************code***************************/
int main()
{
    int a[3]={0};
    fo(i,2)
    {
        int k;
        cin>>k;
        a[k-1]=1;
    }
    fo(i,3)
    {
        if(a[i]==0)
            cout<<(i+1);
    }
}


Measured memory_bytes: 3544
// Bite Eating

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int N, L;

int Abs(int a, int b) {
    if (a < b) {
        return b - a;
    }
    return a - b;
}

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

    // n個のりんごでつくったときのパイの味
    int pieInAllApple = N * (L - 1) + N * (N + 1) / 2;

    int diff = 999999999;
    int res;

    for (int i = 1; i <= N; i++) {
        int tmpPieTaste = pieInAllApple - (L + i - 1);
        if (Abs(pieInAllApple, tmpPieTaste) < diff) {
            diff = Abs(pieInAllApple, tmpPieTaste);
            res = tmpPieTaste;
        }
    }

    cout << res << endl;

    return 0;
}


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


using namespace std;


// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
  void solve(std::istream& in, std::ostream& out)
  {
    long long n, a, b, c, d;
    in >> n >> a >> b >> c >> d;
    for(int i = 0; i < n; i++) {
      if(a - d * i + c * (n - i - 1) <= b && b <= a - c * i + d * (n - i - 1)) {
        out << "YES\n";
        return;
      }
    }
    out << "NO\n";
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}




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

using namespace std;

const int N=105;
//char str1[N],str2[N];
string s1,s2;
int l1,l2;

int main()
{
   // scanf("%s %s",str1,str2);
    cin>>s1>>s2;
   // if(strlen(str1)!=strlen(str2)||strcmp(str1,str2)==0)
    if(s1==s2)
    {
        printf("Yes\n");
        return 0;
    }
    if(s1.length()!=s2.length())
    {
        printf("No\n");
        return 0;
    }
    char c=s1[0];
    int index=-1;
    while(true)
    {
        index=s2.find(c,index+1);
        if(index==-1)
        {
            printf("No\n");
            return 0;
        }
        int i;
        for(i=0;i<s2.length()-index;i++)
        {
            if(s1[i]!=s2[index+i])
                break;
        }
        int l=s2.length()-index;
        if(index+i==s2.length())
        {
            for(i=0;i<index;i++)
            {
                if(s2[i]!=s1[l+i])
                    break;
            }
            if(i==index)
            {
                printf("Yes\n");
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a-c)/(b+c) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"1"<<endl;}else cout<<"0"<<endl;//条件によってYes、Noを出力する
int main(){
    int x;
    cin>>x;
    bool ans=false;
    for(int i=1;i<=1000;i++){
        if(x>=100*i && x<=105*i){
            ans=true;
            //cout<<100*i<<"<x<"<<105*i<<endl;
            break;
        }
    }
    YN(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void dfs(vector<vector<pair<int, int>>> &tree, vector<int> &ans, int now, int bfn, int bfc){
  int co = 0;
  rep(i, tree.at(now).size()){
    if(tree.at(now).at(i).first == bfn) continue;
    if(co == bfc) co++;
    ans.at(tree.at(now).at(i).second) = co;
    dfs(tree, ans, tree.at(now).at(i).first, now, co);
    co++;
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> tree(n, vector<pair<int, int>>());
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.at(a).push_back({b, i});
    tree.at(b).push_back({a, i});
  }
  int mx = 0, index = -1;
  rep(i, n){
    if(tree.at(i).size() > mx){
      mx = tree.at(i).size();
      index = i;
    }
  }
  cout << tree.at(index).size() << endl;
  vector<int> ans(n-1);
  dfs(tree, ans, index, -1, -1);
  for(int i : ans){
    cout << i+1 << endl;
  }
  return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

vector<int> edge[2000];

int dfs(int curr, int prev, int dist) {
    if (dist == 0) return 1;

    int res = 1;
    rep (i, sz(edge[curr])) {
        if (edge[curr][i] != prev) {
            res += dfs(edge[curr][i], curr, dist - 1);
        }
    }

    return res;
}

int main() {
    int n, k;
    cin >> n >> k;
    rep (i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].eb(b);
        edge[b].eb(a);
    }

    int ans = INF;

    if (k % 2) {
        rep (i, n) rep (j, sz(edge[i])) {
            int tmp = n - dfs(i, edge[i][j], k / 2) - dfs(edge[i][j], i, k / 2);
            ans = min(ans, tmp);
        }
    } else {
        rep (i, n) {
            ans = min(ans, n - dfs(i, -1, k / 2));
        }
    }

    cout << ans << endl;
}


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

int main()
{
	int Hill[10];

	for (int i = 0; i < 10; i++){
		cin >> Hill[i];
	}

	sort(Hill, Hill + 10);

	cout << Hill[9] << endl << Hill[8] << endl << Hill[7] << endl;

	return (0);
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename P, typename Q>
istream& operator >> (istream& is, pair<P, Q>& p)
{
  is >> p.first >> p.second;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v)
{
  each (i, v) is >> i;
  return is;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    const int N = 100000 + 5;
    int dp[N];
    fill(dp, dp + N, 1 << 29);
    dp[0] = 0;

    vector<int> v({1});
    int x = 6;
    int y = 9;
    while (min(x, y) <= N) {
      v.push_back(x);
      v.push_back(y);
      x *= 6;
      y *= 9;
    }

    for (int i = 0; i < N; ++i) {
      each (j, v) {
        if (i + j < N) {
          dp[i + j] = min(dp[i + j], dp[i] + 1);
        }
      }
    }

    cout << dp[n] << endl;
  }
  
  return 0;
}


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

int main(void){

    int N, D, tmp, count=0;
    scanf("%d %d", &N, &D);
    int X[N][D];
    double ans;

    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            scanf("%d", &X[i][j]);
        }
        ans = sqrt(ans);
    }
    
    
    for(int i=0;i<N-1;i++){
        
        for(int j=i+1;j<N;j++){
            //比較
            ans = 0;
            for(int z=0;z<D;z++){
                ans += pow(X[i][z]-X[j][z],2);
            }
            ans = sqrt(ans);
            if(ceil(ans) == floor(ans)){count++;}
        }
    }


    printf("%d\n", count);
}

Measured memory_bytes: 256
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N = int(input())
lisA = list(map(int,input().split()))

ans = lisA[0]
if 0 in lisA:
    print(0)
    exit()

for i in lisA[1:]:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 21644
// Created by arvybhatt

#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

#define ll long long int
using namespace std;


ll power(ll x, ll y) { ll temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else return x*temp*temp; } 

int main()
{
	fast;
	int n;cin>>n;
	int x=ceil((double)n/1000);
	cout<<1000*x-n;

}


Measured memory_bytes: 3652
def main():

    N = int(input())
    num_input = list(map(int,input().split()))

    if(N==1 and num_input[0]==1):
        print(0)
        return
    if(1 in num_input):
        print(numCount(num_input))
    else:
        print(-1)

def numCount(num_input):
    now = 0
    count = 0
    for i in num_input:
        if(now == (i-1)):
            now = i
        else:
            count += 1
    return count

main()

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

int main() {
    int a, b; cin >> a >> b;

    if (a > 9 || b > 9) {
        cout << "-1" << endl;
    }
    else
        cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque


def main():
    K = int(input())
    if K <= 9:
        print(K)
        exit()
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    for _ in range(K - 1):
        n = q.popleft()
        n_left = n % 10
        if n_left == 0:
            q.append(n * 10)
            q.append(n * 10 + 1)
            continue
        if n_left == 9:
            q.append(n * 10 + 8)
            q.append(n * 10 + 9)
            continue
        for i in range(-1, 2):
            q.append(n * 10 + n_left + i)

    print(q.popleft())


if __name__ == '__main__':
    main()


Measured memory_bytes: 46684
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern PATTERN = Pattern.compile("^(dreamer|dream|eraser|erase)+$");
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        sc.close();
                
        boolean canMake = PATTERN.matcher(s).matches();
        System.out.println(canMake ? "YES" : "NO");
    }
    
}

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

int main(){
  int n;
  cin >> n;
  int a,b,c;
  a = n/100;
  b = (n-a*100)/10;
  c = n%10;
  if(a == 7 or b == 7 or c == 7)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3636
S = list(input())
N = len(S)
num0 = 0
for i in range(N):
	if S[i] == '0':
		num0 = num0 + 1

num1 = 0
for i in range(N):
	if S[i] == '1':
		num1 = num1 + 1
print(N - abs(num0 - num1))

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


class Main {
	public static void main(String[] args) throws IOException{

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		StringTokenizer st =
	    		new StringTokenizer(str, " ");

		String str1 = st.nextToken();
		String str2 = st.nextToken();
		String str3 = st.nextToken();

		int num1 = Integer.parseInt(str1);
		int num2 = Integer.parseInt(str2);
		int num3 = Integer.parseInt(str3);

		if(num1<num2) {
			if(num2<num3) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24144
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long

#define INF 1e+9
#define MAX_V 100008


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

int main(){
  long long a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;

  long long ab = abs(a - b);
  long long v_abs = abs(v - w);

  if(v_abs * t >= ab && v >= w){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


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



int main(){
	map<string,vector< int > > data;
	vector<string> words;
	string tmpWord;
	int tmpPage;
	while(cin>>tmpWord>>tmpPage){
		words.push_back(tmpWord);
		data[tmpWord].push_back(tmpPage);
	}
	int s=words.size();
	sort(words.begin(),words.end());
	for(int i=0;i<s;i++){
		if(i!=0)if(words[i]==words[i-1])continue;
		cout<<words[i]<<endl;
		sort(data[words[i]].begin(),data[words[i]].end());
		int si=data[words[i]].size();
		for(int j=0;j<si;j++){
			if(j!=0)cout<<" ";
			cout<<data[words[i]][j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1252
n,m = map(int,input().split())
mod = 10**9+7
p = [0 for _ in range(n+1)]
p_ok = [True for _ in range(n+1)]

for i in range(m):
	p_ok[int(input())] = False

p[0] = 1
for now in range(0,n):
	for next in range(now+1,min(n,now+2)+1):
		if p_ok[next]:
			p[next] += p[now]
			p[next] %= mod


ans = p[n]
print(ans%mod)


Measured memory_bytes: 7864
#include<bits/stdc++.h>
using namespace std;
long long q;
long long v;
int main() {
	cin>>q;
	if(q==1) {cout<<0;return 0;}
	for(v=sqrt(q);v>=1;v--) 
		if(!(q%v)) break;
	cout<<v+(q/v)-2;
	return 0;
}

Measured memory_bytes: 256
import sys


def solve(n):
    a = list(map(int, input().split()))
    ave = sum(a) / n
    count = 0
    for i in a:
        if i <= ave:
            count += 1

    print(count)


def main():
    while(True):
        n = int(input())
        if n == 0:
            sys.exit(0)
        else:
            solve(n)


main()



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

from collections import deque

n = int(input())
word = deque()

for i in range(n):
    command = list(map(int, input().split()))
    if command[0] == 0:
        if command[1] == 0:
            word.insert(0, command[2])
        else:
            word.append(command[2])
    elif command[0] == 1:
        print('{0}'.format(word[command[1]]))
    elif command[0] == 2:
        if command[1] == 1:
            word.pop()
        else:
            word.popleft()



Measured memory_bytes: 21984
p =10**9 +7
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
N,M,K =map(int,input().split())
def keisan(a,b):
    foo = a*(a**2 +3*a +2)//6
    foo *= b**2
    foo = foo%p
    return foo
ans = (keisan(N-1,M) + keisan(M-1,N))%p
foo = comb(N*M-2,K-2,p)
bar =9*17
bar =bar%p
ans = (ans*foo)%p
print(ans)

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    for (int i = 0; i < M; i++)
    {
        cin >> p.at(i) >> S.at(i);
    }
    int gotou = 0;
    int seikai = 0;
    vector<int> gotouans(N);
    set<int> hozon;
    
    for (int i = 0; i < M; i++)
    {
        if (hozon.count(p.at(i)))
        {
            continue;
        }
        
        if (S.at(i) == "WA")
        {
            gotouans.at(p.at(i)-1) ++;
        }

        if (S.at(i) == "AC")
        {
            gotou += gotouans.at(p.at(i)-1);
            seikai++;
            hozon.insert(p.at(i));
        }
        
        if (hozon.size() == N)
        {
            break;
        }
        
    }

    cout << seikai << " " << gotou << endl;
    
}


Measured memory_bytes: 11136
n,x = map(int,input().split())
arr = list(map(int,input().split()))
chk = 0
cnt = 1
for i in range(len(arr)):
    chk = chk + arr[i]

    if chk <= x:
        cnt += 1
    else:
        print(cnt)
        exit()

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define M 1000000000
#define f(i,a,b) for(long long i=a;i<b;i++)
#define tc long long t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define up upper_bound
#define lo lower_bound
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long
#define umap unordered_map

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll n;
    cin>>n;

    string s;
    cin>>s;

    ll a=0,b=0;
    f(i,0,n){
        if(s[i]=='R') a++;
    }
    f(i,0,a){
        if(s[i]=='W') b++;
    }

    cout<<b;

    return 0;


}

Measured memory_bytes: 3704
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
using namespace std;

int N, K, worry;
string S;

int main(){
	cin >> N >> K >> S;
	int S_length = S.length();
	worry = 0;
	for (int i = 1; i < S_length; i++)
		if (S[i] != S[i - 1])
			worry++;
	worry = max(worry - K * 2, 0);
	printf("%d\n", N - 1 - worry);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cmath>
#include<queue>
#include<algorithm>

using namespace std;
using ll=long long;
using db=double;

typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<bool> vbl;

int inf=(1LL<<31)-1;
int MOD=1000000007;

#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define f_i(a,b) for(int i=a;i<=b;i++)
#define f_j(a,b) for(int j=a;j<=b;j++)
#define vvii(c,a,b) vector<vector<ii>> c(a,vector<ii>(b,0))
#define vvll(c,a,b) vector<vector<ll>> c(a,vector<ll>(b,0))
#define vvstr(c,a,b) vector<vectorM<string> c(a,vector<string>(b,0))

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    vector<vector<ll>> school_1(5,vector<ll>(10+10,0));
    vector<vector<ll>> school_2(5,vector<ll>(10+10,0));
    vector<vector<ll>> school_3(5,vector<ll>(10+10,0));
    vector<vector<ll>> school_4(5,vector<ll>(10+10,0));


    int n;
    cin >> n;
    int b=0,f=0,r=0,v=0;
    fi(0,n)
    {
        cin >> b >> f >> r >> v;
        if(b==1)
        {
            school_1.at(f).at(r)+=v;
            if(school_1.at(f).at(r)<=-1)
            {
                school_1.at(f).at(r)=0;
            }
            else if(school_1.at(f).at(r)>=10)
            {
                school_1.at(f).at(r)=0;
            }
        }
        else if(b==2)
        {
            school_2.at(f).at(r)+=v;
            if(school_2.at(f).at(r)<=-1)
            {
                school_2.at(f).at(r)=0;
            }
            else if(school_2.at(f).at(r)>=10)
            {
                school_2.at(f).at(r)=0;
            }
        }
        else if(b==3)
        {
            school_3.at(f).at(r)+=v;
            if(school_3.at(f).at(r)<=-1)
            {
                school_3.at(f).at(r)=0;
            }
            else if(school_3.at(f).at(r)>=10)
            {
                school_3.at(f).at(r)=0;
            }
        }
        else
        {
            school_4.at(f).at(r)+=v;
            if(school_4.at(f).at(r)<=-1)
            {
                school_4.at(f).at(r)=0;
            }
            else if(school_4.at(f).at(r)>=10)
            {
                school_4.at(f).at(r)=0;
            }
        }
    }
    f_i(1,3)
    {
        cout << " ";
        f_j(1,9)
        {
            cout << school_1.at(i).at(j) << " ";
        }
        cout <<school_1.at(i).at(10) << endl; 
    }
    cout << "####################" << endl;
    f_i(1,3)
    {
        cout << " ";
        f_j(1,9)
        {
            cout << school_2.at(i).at(j) << " ";
        }
        cout <<school_2.at(i).at(10) << endl; 
    }
    cout << "####################" << endl;
    f_i(1,3)
    {
        cout << " ";
        f_j(1,9)
        {
            cout << school_3.at(i).at(j) << " ";
        }
        cout <<school_3.at(i).at(10) << endl; 
    }
    cout << "####################" << endl;
    f_i(1,3)
    {
        cout << " ";
        f_j(1,9)
        {
            cout << school_4.at(i).at(j) << " ";
        }
        cout <<school_4.at(i).at(10) << endl; 
    }
    return(0);
}


Measured memory_bytes: 3228
/* ****GT_18**** */

#include<bits/stdc++.h>
void file() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	// file();
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll ans[200004],b[200004],n,w,i,j,k,l,v[100005],wi[100004];
		cin>>n>>w;
		for(i=0;i<n;i++)
		{
			cin>>wi[i]>>v[i];
		}
		for(i=0;i<=100000;i++)
			ans[i]=hell,b[i]=hell;
		for(i=0;i<n;i++)
		{
			b[v[i]]=min(ans[v[i]],wi[i]);
			for(j=1;j<=100000;j++)
			{
				b[j+v[i]]=min(ans[j+v[i]],ans[j]+wi[i]);
			}
			for(j=0;j<=100004;j++)
				ans[j]=b[j];
		}
		for(i=100000;i>=1;i--)
		{
			// if(ans[i]!=hell)
			// 	cout<<i<<" "<<ans[i]<<endl	;
			if(ans[i]<=w)
				break;
		}
		cout<<i;
	}
	return 0;
}

Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	void reverse(){
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a[] = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = s.nextInt();
		}
		for(int i = n-1;i >= 0;i--){
			System.out.print(a[i]);
			if(i > 0){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.reverse();
	}
}

Measured memory_bytes: 26028
//R<3S
#include <bits/stdc++.h>
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);}
#define inset(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);}
#define ll long long
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


using namespace std;

void solve()
  {
    int n;
    cin>>n;
    int last=n%10;n/=10;
    int sl=n%10;n/=10;
    int f=n%10;
    if(f==7||sl==7||last==7)cout<<"Yes\n";
    else cout<<"No";


  }



signed main()
{
   FAST

   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


Measured memory_bytes: 3608
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int H,W;
  cin >> H >> W;
  int h,w;
  cin >> h >> w;
  printf("%d\n", H*W - h*W - w*H + h*w);
  return 0;
}


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

using namespace std;

int main() {
    string s,sub1,sub2;
    cin >> s;
    int len = (int)s.size()/2;
    sub1 = s.substr(0, len);
    sub2 = s.substr(len+1,len);
    if (sub1 == sub2)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> ind, d;
int k;
int solve() {
	int n, x, m;
	cin >> n >> x >> m;
	n--;
	int tacc = 0, tzero = 0;
	for(int i=0; i<k; i++) {
		d[i] = ind[i] % m;
		tacc += d[i]*(n/k);
		if(i%k < n%k)
			tacc += d[i];
		if(!d[i]) {
			//printf("at i=%d, not di, add %d\n", i, n/k);
			tzero += n/k;
			if(i%k < n%k) {
				//printf("additional one\n");
				tzero++;
			}
		}
	}
	int tsub = (x+tacc)/m - x/m;
	//printf("tacc=%d, tsub=%d, zero=%d\n", tacc, tsub, tzero);
	return n - tsub - tzero;
	int acc = accumulate(d.begin(), d.end(), 0ll)*(n/k) + accumulate(d.begin(), d.begin()+(n%k), 0ll);
	int zero = count_if(d.begin(), d.end(), [](int t){return !t;})*(n/k) + count_if(d.begin(), d.begin()+(n%k), [](int t){return !t;});
	int sub = x/m + (x+acc)/m;
	//printf("acc=%lld, sub=%lld, zero = %lld\n", acc, sub, zero);
	return n-sub - zero;
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int q;
	cin >> k >> q;
	ind.resize(k);
	d.resize(k);
	for(int i=0; i<k; i++) {
		cin >> ind[i];
	}
	while(q--)
		cout << solve() << '\n';
}

Measured memory_bytes: 384