akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


public class Main { 
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int m,f,r;
       
       while((m = sc.nextInt())+ (f = sc.nextInt()) + (r = sc.nextInt())!= -3){
           if(m != -1 && f !=-1){
               if (m+ f >=80){
               System.out.println("A");
               }
               else if (m+ f>=65){
               System.out.println("B");}
               else if (m+f >=50){
               System.out.println("C");}
               else if (m+ f>= 30){
                   if(r>= 50){
                   System.out.println("C");}
                   else 
                   System.out.println("D");}
               else System.out.println("F");
           }
           else {System.out.println("F");}
       }   
   }   
}



Measured memory_bytes: 26368
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

int main() {
    string N;
    ll K;
    cin >> N >> K;
    ll dp[10] = {};
    ll cur_nz = 0;
    for (char c : N) {
        ll n = c - '0';
        ll sub[20] = {};
        for (ll i = 0; i < 10; i++) {
            sub[i] += dp[i];
            sub[i + 1] += dp[i] * 9;
        }
        if (n != 0) {
            if (cur_nz < 20) sub[cur_nz]++;
            if (cur_nz + 1 < 20)sub[cur_nz + 1] += n - 1;
            cur_nz++;
        }
        for (ll i = 0; i < 10; i++) dp[i] = sub[i];
    }

    if (cur_nz < 10) dp[cur_nz]++;
    cout << dp[K] << endl << flush;
    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
def ok(string):
    N = len(string)
    for i in range(N//2):
        if string[i] != string[-i-1]:return False
    return True

if ok(s[:n//2]) and ok(s[n//2+1:]) and ok(s):print('Yes')
else:print('No')

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <queue>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
vector <int> adj[(int)2e3+5];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,x,y;
	cin >> n >> x >> y;
	for(int i=1;i<n;i++)
	{
		adj[i].push_back(i+1);
		adj[i+1].push_back(i);
	}
	adj[x].push_back(y);
	adj[y].push_back(x);
	vector <int> m(n+1,0);
	queue <int> q;
	for(int i=1;i<=n;i++)
	{
		vector <int> visited(n+1,0);
		q.push(i);
		visited[i]=1;
		vector <int> d(n+1,0);
		while(!q.empty())
		{	
			int v = q.front();
			q.pop();
			for(int u : adj[v])
			{
				if(!visited[u])
				{
					visited[u]=1;
					q.push(u);
					d[u]=d[v]+1;
					m[d[u]]++;
				}
			}
		}
	}
	for(int i=1;i<n;i++)
	{
		cout <<(m[i]==1?m[i]: m[i]/2) << "\n";
	}
}

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

int main(void){
    long long x; cin >> x;

    long long ans=0;
    ans+=2*(x/11);
    x%=11;
    if(x==0) cout << ans << endl;
    else if(0<x and x<=6) cout << ans+1 << endl;
    else cout << ans+2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int N, M;
  int max_v[101];
  int sum;
  
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0) break;

    for (int& v : max_v) v = 0;

    while (N--) {
      int d, v;
      cin >> d >> v;
      if (v > max_v[d]) max_v[d] = v;
    }

    sum = 0;
    for (int i = 1; i <= M; i++) {
      sum += max_v[i];
    }
    cout << sum << endl;
  }
}
      
    



Measured memory_bytes: 3076
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	ll N,M;
	cin>>N>>M;
	vll X,Y,Z;
	int arr[8][3]={{1,1,1},{1,1,-1},{1,-1,1},{-1,1,1},{1,-1,-1},{-1,1,-1},{-1,-1,1},{-1,-1,-1}};
	for(int i=0;i<N;i++){
		ll x,y,z;
		cin>>x>>y>>z;
		X.pb(x);
		Y.pb(y);
		Z.pb(z);
	}
	ll ans=0;
	for(int i=0;i<8;i++){
		ll temp=0;
		vll V;
		for(int j=0;j<N;j++)
			V.pb(arr[i][0]*X[j]+arr[i][1]*Y[j]+arr[i][2]*Z[j]);
		sort(V.begin(),V.end(),greater<ll>());
		for(int j=0;j<M;j++)
			temp+=V[j];
		ans=max(ans,temp);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin>>n;
    int min=n;
    for(int i=1;i<n;i++){

        int x,y;
        x=i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10+i/100000;
        y=(n-i)%10+((n-i)/10)%10+((n-i)/100)%10+((n-i)/1000)%10+((n-i)/10000)%10+(n-i)/100000;
        if(x+y<min) min=x+y;
    }
    cout<<min<<endl;
}


Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

double a,b;

int main()
{
	cin>>a>>b;
	printf("%.10lf\n",a/b);
	rt0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int K = sc.nextInt();

  	int max = A;

  	if (max < B) {
      max = B;
    }
    if (max < C) {
      max = C;
    }
    System.out.println(A + B + C + max * ((1 << K) - 1));
  }

}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  double a=sc.nextInt(),b=sc.nextInt(),h=sc.nextInt(),m=sc.nextInt();
	  double ah=30*h+m/2,bh=6*m;
	  double res1=Math.abs(ah-bh),res2=360-Math.abs(ah-bh);
	  double res=Math.min(res1, res2);
	  System.out.println(Math.sqrt(a*a+b*b-2*a*b*Math.cos(Math.toRadians(res))));
	  //System.out.println(ah+" "+bh);
  }
}

Measured memory_bytes: 36044
n, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
t = gets.chomp
(n - k).times do |i|
  t[i + k] = 'x' if t[i] == t[i + k]
end
puts t.count('r') * p + t.count('s') * r + t.count('p') * s

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

long long N, Q;
//X, <s-x, t-x>. Xが小さい方が先に当たる
vector<pair<long long, pair<long long, long long> > > XST;
set<pair<long long, long long> > DI;
long long ans[200005];

int main(){
	cin >> N >> Q;
	for(long long i = 0; i < N; i++){
		long long s,t,x;
		cin >> s >> t >> x;
		XST.push_back(make_pair(x, make_pair(s-x, t-x)));
	}
	sort(XST.begin(), XST.end());

	for(long long i = 0; i < Q; i++){
		long long d;
		cin >> d;
		DI.insert(make_pair(d, i));
	}

	for(long long i = 0; i < N; i++){
		long long x = XST[i].first;
		long long start = XST[i].second.first;
		long long end = XST[i].second.second;
		auto it = DI.lower_bound(make_pair(start, -1));
		while(it != DI.end() && (*it).first < end){
			ans[(*it).second] = x;
			DI.erase(it++);
		}
	}

	for(long long i = 0; i < Q; i++){
		if(ans[i] != 0){
		cout << ans[i] << endl;
		}else{
			cout << -1 << endl;
		}
	}
}


Measured memory_bytes: 20588
n = int(input())
l = list(map(int, input().split()))
dp = [0 for i in range(n)]
dp[1] = abs(l[1]-l[0])
for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
print(dp[-1])


Measured memory_bytes: 20636
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int N_MAX = 100000;
const int M_MAX = 200000;


int main(){
    int N,M;
    int visit[N_MAX];
    vector<int> G[M_MAX];
    queue<int> Q;

    for(int i = 0;i < N_MAX;i++){
        visit[i] = -1;
    }

    cin >> N >> M;
    for(int i = 0;i < M;i++){
        int A,B;
        cin >> A >> B;

        G[A-1].push_back(B-1);
        G[B-1].push_back(A-1);
    }

    Q.push(0);

    while(!Q.empty()){
        int x = Q.front();Q.pop();
        for(int i = 0;i < G[x].size();i++){
            if(visit[G[x][i]] == -1){
                visit[G[x][i]] = x;
                Q.push(G[x][i]);
            }
        }
    }

    for(int i = 0;i < N;i++){
        if(visit[i] == -1){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

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

    return 0;
}


Measured memory_bytes: 12464
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int gcd(int m, int n) {
    if (m < n) {
        return gcd(n, m);
    }
    if (n==0) {
        return abs(m);
    } else {
        return gcd(n, m % n);
    }
}

int lcm(int m, int n) {
    return abs(m * n) / gcd(m, n);
}


int main() {
	int N, X;
    vector<int> x;
    cin >> N >> X;

    for (size_t i = 0; i < N; i++) {
        int xi;
        cin >> xi;
		x.push_back(xi);
    }
	x.push_back(X);

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

	int result = x[1] - x[0];
    for (size_t i = 2; i < x.size(); i++) {
		result = gcd(result, x[i] - x[i-1]);
	}

	cout << result << endl;
}


Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

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

    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s;
    String[] sl;

    s = r.readLine();
    long n = Long.parseLong(s);

    int a = 0;
    
    for(int i = 1; ; i++)
    {
      long e = z(i);
      if(z(i) > n)
      {
        break;
      }
      String v = Long.toString(e);
      if(v.contains("3") && v.contains("5") && v.contains("7"))
      {
        a++;
      }
    }
    
    System.out.println(a);

  }
  
  public static long z(long d)
  {
    if(d <= 0)
    {
      return 0;
    }
    d -= 1;
    int g = 0;
    long s = 0;
    long v = 1;
    for(int i = 1; i < 100; i++)
    {
      v *= 3;
      s += v;
      if(s - v <= d && d < s)
      {
        g = i;
        break;
      }
    }
    d -= s - v;
    String str = String.format("%0" + g + "d", Long.parseLong(Long.toString(d, 3)));
    int l = str.length();
    long a = 0;
    for(int i = 0; i < l; i++)
    {
      a *= 10;
      switch(str.charAt(i))
      {
        case '0':
          a += 3;
          break;
        case '1':
          a += 5;
          break;
        case '2':
          a += 7;
          break;
      }
    }
    return a;
  }

}

Measured memory_bytes: 68808
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

A,B,C = MI()
K = I()

ans = False

def check(a,b,c):
    return a < b and b < c

for i in range(K):
    if A >= B:
        B = B * 2
    elif B >= C:
        C = C * 2
    if check(A,B,C):
        print("Yes")
        exit() 

print("No")

Measured memory_bytes: 27040
#include<bits/stdc++.h>
using namespace std;
//chmin,maxは小さい、大きい方をaにぶっこむやつ
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
static const int mod = 1e+7;
int main(){
    int N;
    cin >> N;
    vector<ll> h(N);
    rep(i,N) cin >> h[i];
    ll dp[100010];
    const ll INF = 1LL << 60;
    rep(i,100010){
        dp[i] = INF;
    }
    dp[0] = 0;
    for(int i = 1; i < N; i++){ //dp[i]はINFで初期化されているからできること
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 1){
            chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
        }
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  while(cin>>n,n){
    n=1000-n;
    int a[]={500,100,50,10,5,1};
    int ans=0;
    for(int i=0;i<6;i++){
      while(n>=a[i]) n-=a[i],ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e12;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 998244353;

vector<int> graph[N];
int visited[N];
int t, l, a, b;

int dfs(int u, int dis)
{
    if(u == t)
    {
        l = dis;
        if(dis == (l-1)/2)
            a = u;
        if(dis == (l-1)/2 + 1)
            b = u;
        return 1;
    }
    visited[u] = 1;
    for(int i = 0; i < graph[u].size(); i++)
    {
        int v = graph[u][i];
        if(visited[v])
            continue;
        if(dfs(v, dis+1))
        {
            if(dis == (l-1)/2)
                a = u;
            if(dis == (l-1)/2 + 1)
                b = u;
            return 1;
        }
    }
    return 0;
}

int find(int u, int dis)
{
    visited[u] = 1;
    int ans = dis;
    for(int i = 0; i < graph[u].size(); i++)
    {
        int v = graph[u][i];
        if(visited[v] || v == b)
            continue;
        ans = max(ans, find(v, dis+1));
    }
    return ans;
}

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, u, v;
    cin >> n >> u >> v;
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    t = v;
    dfs(u, 0);
    int ans = l - (l-1)/2;
    memset(visited, 0, sizeof(visited));
    ans += find(a, 0) - 1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 37888
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	long l = Integer.parseInt(sc.next());
	long r = Integer.parseInt(sc.next());
	long min = 2019;
	if((r - l) >= 673){
		System.out.println(0);
	}else{
		for(long i = l; i < r; i++){
			for(long j = i+1; j <= r; j++){
				if((j*i)%2019 < min){
					min = ((j*i)%2019);
				}
			}
		}
	System.out.println(min);
	}
}
}


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

#define rep(i, N) for (int i = 0; i < N; i++)

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, N)
    {
        cin >> P[i];
        P[i]--;
    }

    vector<int> P2i(N);
    rep(i, N)
    {
        P2i[P[i]] = i;
    }

    vector<bool> is_checked(N, false);
    is_checked[P2i[N - 1]] = true;
    set<int> s;
    s.insert(P2i[N - 1]);
    ll sum = 0;
    for (int p = N - 2; p >= 0; p--)
    {
        int i_p = P2i[p];
        int i_ll, i_l, i_r, i_rr;

        auto it = s.insert(i_p).first;
        auto it_first = s.begin();
        auto it_last = s.end();
        it_last--;
        if (it != it_first)
        {
            auto it_l = it;
            it_l--;
            i_l = *it_l;
            if (it_l != it_first)
            {
                it_l--;
                i_ll = *it_l;
            }
            else
                i_ll = -1;
        }
        else
            i_l = i_ll = -1;

        if (it != it_last)
        {
            auto it_r = it;
            it_r++;
            i_r = *it_r;
            if (it_r != it_last)
            {
                it_r++;
                i_rr = *it_r;
            }
            else
                i_rr = N;
        }
        else
            i_r = i_rr = N;

        ll dll = i_l - i_ll;
        ll dl = i_p - i_l;
        ll dr = i_r - i_p;
        ll drr = i_rr - i_r;
        sum += (dll * dr + dl * drr) * (p + 1);
    }
    cout << sum << endl;
}

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main(){
	int n, square;
	cin >> n;
	for (int i = 0; i < n + 1; i++){
		if (i*i <= n){
			square = i*i;
		}
		else if (i*i > n){
			break;
		}
	}
	cout << square << endl;
	return 0;
}

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i=0; i<M; i++) {
    cin >> B.at(i);
  }
  vector<vector<int>> A(N, vector<int>(M));
  for (int i=0; i<N; i++) {
    for (int j=0; j<M; j++) {
      cin >> A.at(i).at(j);
      A.at(i).at(j) *= B.at(j);
    }
  }
  vector<int> sum(N, 0);
  for (int i=0; i<N; i++) {
    for (int j=0; j<M; j++) {
      sum.at(i) += A.at(i).at(j);
    }
  }
  int answer = 0;
  for (int i=0; i<N; i++) {
    if (sum.at(i)+C > 0) {
      answer++;
    }
  }
  cout << answer << endl;
}

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

using namespace std;
#define int long long int
const int N = 1e2 + 4 , M = 200005 , MOD = 1e9 + 7;
int n , k;
int arr[M] , mem[N][M];
//int dp(int pos, int val)
//{
//     if (val > k)
//          return 0;
//     if (pos == n)
//          return val == k;
//
//     int &ans = cache[pos][val];
//     if (ans != -1)
//          return ans;
//
//     ans = dp(pos, val + 1) + dp(pos + 1, val) - dp(pos + 1, val + arr[pos] + 1) + 2 * MOD;
//     ans %= MOD;
//     return ans;
//}
int solve(int idx , int candies){
    if(candies < 0)
        return 0;
     if(idx == n){
        return (candies == 0);
     }
     int &ret = mem[idx][candies];
     if(~ret)
        return ret;
    ret = solve(idx , candies -1) + solve(idx + 1 , candies) - solve(idx + 1 , candies - arr[idx] -1 ) + 2 * MOD;
    ret%= MOD;
    return ret;
}
 main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem , -1 , sizeof mem);
    cin >> n >> k;
    for(int i = 0 ; i < n ; ++i){
        cin >> arr[i];
    }
    cout << solve(0 , k) % MOD;



}


Measured memory_bytes: 168832
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s[ohara];
bool fl;
struct edge{int to,cost;};
double ans,a[ohara];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n;
    rep(i,n)cin>>a[i]>>s[i];
    rep(i,n){
        if(s[i]=="JPY")ans+=(double)a[i];
        else ans+=(double)(a[i]*380000.0);
    }
    doublecout(ans);
    return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 2e5+5;

int n;
int m;
int s , t;
vector < int > adj[N];

bool vis[N][3];

struct state{
    int u;
    int dist;
};

int main(){
    scanf("%d%d " , &n , &m);
    for(int i = 1; i <= m; i++){
        int u , v;
        scanf(" %d%d" , &u , &v);
        adj[u].push_back(v);
    }
    scanf(" %d%d" , &s , &t);
    queue < state > q;
    q.push({s , 0});
    while(!q.empty()){
        int u = q.front().u;
        int dist = q.front().dist;
        q.pop();
        if(u == t && dist % 3 == 0){
            printf("%d\n" , dist / 3);
            return 0;
        }
        vis[u][dist % 3] = 1;
        for(auto v : adj[u]){
            if(!vis[v][ (dist + 1)%3 ]){
                vis[v][ (dist + 1)%3 ] = 1;
                q.push({v , dist + 1});
            }
        }
    }
    puts("-1");
}


Measured memory_bytes: 11900
import itertools

n,m,x = map(int,input().split())
li = []
mn = 10**20
for i in range(n):
    buf = [int(x) for x in input().split()]
    li.append(buf)

for i in range(1,n+1):
    for v in itertools.combinations(li,i):
        sm = 0
        flag = False
        ans_li = [0] * m
        count = 0
        for j in range(len(v)):
            sm += v[j][0]
            tmp = v[j][1:len(v[j])]
            for k in range(len(tmp)):
                ans_li[k] += tmp[k]
        for l in range(m):
            if ans_li[l] >= x:
                count += 1
        if count == m:
            if sm < mn:
                mn = sm

if mn == 10**20:
    print(-1)
else:
    print(mn)


Measured memory_bytes: 9240
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
int main(){
    int a,b,c;
    int x;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    int i,j,k;
    int cnt = 0;
    for(i = 0; i <= a; i++){
        for(j = 0; j <= b; j++){
            for(k = 0; k <= c; k++){
                if(i*500+j*100+k*50==x)
                    cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    a = [list(map(int, input().split())) for e in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    c = 'No'
    for i in range(len(a)):
        for j in range(len(a)):
            if a[i][j] in b:
                a[i][j] = 0

    for i in range(len(a)):
         if {a[i][j] for j in range(len(a))} == {0}:
             c = 'Yes'
         if {a[j][i] for j in range(len(a))} == {0}:
            c = 'Yes'
    if {a[j][j] for j in range(len(a))} == {0}:
        c = 'Yes'
    if {a[-(j+1)][j] for j in range(len(a))} == {0}:
        c = 'Yes'
    print(c)

Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()

int main() {
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());

  vector<int> d;
  rep(i, x) d.push_back(p[i]);
  rep(i, y) d.push_back(q[i]);
  rep(i, c) d.push_back(r[i]);
  ll ans = 0;
  sort(d.rbegin(), d.rend());
  rep(i, x + y) ans += d[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>

long *tree[100001];

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long tree_s[n+1];
  for (long i = 0; i <= n; i++) {
    tree_s[i] = 0;
  }
  long x,y,z;
  for (long i = 0; i < m; i++) {
    scanf("%ld %ld %ld", &x, &y, &z);
    tree[x] = realloc(tree[x], sizeof(long)*(tree_s[x]+1));
    tree[x][tree_s[x]] = y;
    tree_s[x]++;
    tree[y] = realloc(tree[y], sizeof(long)*(tree_s[y]+1));
    tree[y][tree_s[y]] = x;
    tree_s[y]++;
  }
  long visited[n+1],queue[n+1];
  for (long i = 0; i <= n; i++) {
    visited[i] = 0;
    queue[i] = 0;
  }
  visited[1] = 1;
  queue[1] = 1;
  long group = 1;
  long start = 1, end = 1, tail = 1;
  long cur,next;
  int flag;
  long count = 1;
  while (tail < n) {
    flag = 0;
    for (long i = start; i <= end; i++) {
      cur = queue[i];
      for (long j = 0; j < tree_s[cur]; j++) {
        next = tree[cur][j];
        if (visited[next] == 1) {
          continue;
        }
        visited[next] = 1;
        tail++;
        queue[tail] = next;
        flag = 1;
      }
    }
    if (flag == 1) {
      start = end+1;
      end = tail;
    } else {
      for (long i = group+1; i <= n; i++) {
        if (visited[i] == 0) {
          visited[i] = 1;
          tail++;
          queue[tail] = i;
          group = i;
          start = tail;
          end = tail;
          count++;
          break;
        }
      }
    }
  }
  printf("%ld\n", count);

  return 0;
}

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

int main()
{
	for(;;)
	{
		std::vector<int> a(4);

		std::vector<int> b(4);

		for(size_t i=0; i<4; ++i)
		{
			std::cin >> a[i];
		}

		if(std::cin.eof())
		{
			break;
		}

		for(size_t i=0; i<4; ++i)
		{
			std::cin >> b[i];
		}

		int countHit=0, countBlow=0;

		
		for(size_t i=0; i<4; ++i)
		{
			if(a[i]==b[i])
			{
				++countHit;
			}
		}

		for(size_t i=0; i<4; ++i)
		{
			for(size_t j=0; j<4; ++j)
			{
				if(a[i]==b[j])
				{
					++countBlow;
				}
			}
		}

		countBlow -= countHit;

		std::cout << countHit << ' ' << countBlow << '\n';
	}
}

Measured memory_bytes: 1192
// :) 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	if (s.find('9') != string::npos)
		cout << "Yes\n";
	else
		cout << "No\n";
}

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

namespace ConsoleApp22 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            int[] P = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] Q = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            //これまでに出現した数値を保管するリスト
            var already_p = new List<int>();
            var already_q = new List<int>();

            int ans_p = 1;
            int ans_q = 1;

            for (int i = 0; i < N - 1; i++) {
                ans_p += Factorial(N - i - 1) * (P[i] - 1 - already_p.Where(value => value < P[i]).Count());

                //Console.WriteLine(ans_p);

                ans_q += Factorial(N - i - 1) * (Q[i] - 1 - already_q.Where(value => value < Q[i]).Count());


                already_p.Add(P[i]);
                already_q.Add(Q[i]);
            }

            //Console.WriteLine(ans_p);
            //Console.WriteLine(ans_q);

            Console.WriteLine(Math.Abs(ans_p - ans_q));
        }

        static int Factorial(int N) {
            if (N == 1) {
                return 1;
            }
            if (N == 0) {
                return 1;
            }
            return N * Factorial(N - 1);
        }
    }
}


Measured memory_bytes: 13396
loop do
    n = gets.to_i
    break if n == 0
    c = n.times.map{gets.split.map(&:to_i) + [true]}
    m = gets.to_i
    move = m.times.map{gets.split}
    cur = [10,10]
    move.each do |dir, dis|
        case dir
        when "N"
            suc = [cur[0], cur[1] + dis.to_i]
        when "E"
            suc = [cur[0] + dis.to_i, cur[1]]
        when "S"
            suc = [cur[0], cur[1] - dis.to_i]
        when "W"
            suc = [cur[0] - dis.to_i, cur[1]]
        end
        c.each_with_index do |(x, y, b), i|
            if x.between?(cur[0], suc[0]) && y.between?(cur[1], suc[1])
                c[i][2] = false
            end
            if x.between?(suc[0], cur[0]) && y.between?(suc[1], cur[1])
                c[i][2] = false
            end
        end
        cur = suc
    end
    puts c.all?{|x,y,b| !b} ? "Yes" : "No"
end

Measured memory_bytes: 6132
from collections import Counter
from operator import itemgetter

input()
An = Counter(map(int, input().split()))


def main():
    l = [[k, v] for k, v in An.items() if 2 <= v]
    l.sort(key=itemgetter(0), reverse=True)

    if len(l) == 0:
        print(0)
    elif 4 <= l[0][1]:
        print(l[0][0] * l[0][0])
    elif len(l) < 2:
        print(0)
    else:
        print(l[0][0] * l[1][0])

    return


main()


Measured memory_bytes: 24224
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=1000050;
//int arr[SIZE]={};
//ここまでテンプレ

int main(){
	char s[101];
	cin>>s;
	bool flag=0;
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='C')
			flag=1;
		if(flag && s[i]=='F'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
  int n;
  scanf("%d",&n);
  vector<int> h(n);
  for(int& x : h) {
    scanf("%d",&x);
  }
  vector<int> dp(n,INF);
  dp[0]=0;
  for(int i=0;i<n;++i){
    for(int j : {i+1,i+2}){
      if(j < n) {
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
      }
    }
  }
  printf("%d\n",dp[n-1]);
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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 Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	rep(i, n-1)
	{
		if (a[i] == a[i + 1])
		{
			cout << "NO" << endl;
			ret;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1792
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int K, X;

void solve()
{
    cout << (500*K >= X ? "Yes" : "No") << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> K >> X;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
//╔╗───────────╔╗────────────────────╔╗─
//║║──────────╔╝╚╗──────────────────╔╝╚╗
//║╚═╗╔══╗╔══╗╚╗╔╝╔══╗╔═╗╔╗╔╗╔══╗ ╔╗╚╗╔╝
//║╔╗║║╔╗║║╔╗║─║║─║║═╣║╔╝║╚╝║║╔╗║─╣║─║║─
//║╚╝║║╔╗║║║║║─║╚╗║║═╣║║─║║║║║╚╝║─║║─║╚╗
//╚══╝╚╝╚╝╚╝╚╝─╚═╝╚══╝╚╝─╚╩╩╝╚══╝─╚╝─╚═╝ 

#include <bits/stdc++.h>

#define pb push_back
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
    IO;
    int n,k;
    cin>>n>>k;
	vector <int> v;
	forn(i,n){
		int l;
		cin >> l;
		v.pb(l);
	}    
	sort(allr(v));
	int sum = 0;
	forn(i,k){
		sum += v[i];
	}
	cout << sum;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1000100;//1LL << 60;

int main() {
  int n;
  vector<int>dp(31);
  dp[0]=1;
  dp[1]=1;
  dp[2]=2;

  for(int i=3;i<=30;i++){
    dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
  }
  
  while(cin>>n){
    if(n>0){cout<<(dp[n]+3649)/3650<<endl;}
  }
  return 0;}


Measured memory_bytes: 3072
#include<iostream>
#define ll long long
#define re register
using namespace std;
ll n,f[101];
int main()
{
	f[0]=2;
	f[1]=1;
	cin>>n;
	for(re int i=2;i<=n;i++)
	f[i]=f[i-1]+f[i-2];
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,k;
   cin>>a>>b;

   k=(a+b)/2;
   if(a%2==0 && b%2==0 || a%2!=0 && b%2!=0)
        cout<<k<<endl;
   else
        cout<<"IMPOSSIBLE"<<endl;


}


Measured memory_bytes: 256
n=int(input())
l=[[i+1] for i in range(n)]
for i in range(n):
    l[i]+=list(input().split(' '))
    l[i][2]=int(l[i][2])
#print(l)
l.sort(key=lambda x:x[2],reverse=True)
l.sort(key=lambda x:x[1])
for i in range(n):
    print(l[i][0])

Measured memory_bytes: 3064
#include <stdio.h>

int main (void) {
    int n ;
    scanf ( "%d", &n);
    int R[n];
    
    for ( int i = 0; i < n; i++ ) {
        scanf ( "%d", &R[i]);
    }
    int maxv = -2000000000;
    int minv = R[0];
    
    for ( int i = 1; i < n; i++){
        maxv = maxv < (R[i] - minv) ? R[i] - minv : maxv;
        minv = minv > R[i] ? R[i] : minv;
        
    }
    printf ( "%d\n", maxv);
    return 0;
}



Measured memory_bytes: 2576
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def split_list(a):
    ret = []
    tmp = []
    l = len(a)
    for i in range(l):
        tmp.append(a[i])
        if i < l - 1 and a[i] < a[i+1] or i == l - 1:
            ret.append(tmp)
            tmp = []
    return ret

def resolve():
    N = I()
    H = LI()

    l = split_list(H)
    ans = max([len(i) for i in l]) - 1
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 23756
#include <bits/stdc++.h>
using namespace std;
#define M 20
#define LL long long
#define MOD 1000000007
#define rep(i, x, y) for(int i = (x); i <= (y); ++ i)
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
int a[M];
int f[M][(1 << M + 1)];
int fac[(1 << M + 1)];
int inv[(1 << M + 1)]; 
inline int C(int n, int m) {
	return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int main() {
	//freopen("in.txt", "r", stdin);
	int n = read(), m = read();
	rep(i, 1, m) a[i] = read();
	fac[0] = 1;
	rep(i, 1, 1 << n) fac[i] = 1ll * fac[i - 1] * i % MOD;
	inv[0] = inv[1] = 1;
	rep(i, 2, 1 << n) inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;
	rep(i, 1, 1 << n) inv[i] = 1ll * inv[i - 1] * inv[i] % MOD; 
	f[m + 1][0] = (1 << n);
	sort(a + 1, a + m + 1);
	for(int i = m; i >= 1; -- i) {
		rep(s, 0, (1 << n) - 1) {
			int lst = (1 << n) - s - a[i];
			(f[i][s] += f[i + 1][s]) %= MOD;
			if(lst < 0) continue;
			rep(p, 1, n) if(!((1 << p - 1) & s)){
				if((1 << p - 1) - 1 > lst) continue;
				(f[i][s | (1 << p - 1)] += 1ll * f[i + 1][s] * C(lst, (1 << p - 1) - 1) % MOD * fac[1 << (p - 1)] % MOD) %= MOD;
			}
		}
	}
	int ans = 0;
	rep(s, 0, (1 << n) - 1) {
		//printf("%d %d\n", f[1][s], fac[(1 << n) - s - 1]);
		(ans += (__builtin_popcount(s) % 2 == 0 ? 1ll : -1ll) * f[1][s] * fac[(1 << n) - s - 1] % MOD) %= MOD;
		(ans += MOD) %= MOD;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 37376
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

const ll V = 1e5;
vector<ll> g[2 * V];
ll used[2 * V] = {};
ll cnt[2];

void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	cnt[i / V]++;
	int m = g[i].size();
	for (int j = 0; j < m; j++) {
		dfs(g[i][j]);
	}
}

int main() {
	IOS();
	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		b += V;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	ll ans = 0;
	for (int i = 0; i < 1e5; i++) {
		cnt[0] = cnt[1] = 0;
		dfs(i);
		ans += cnt[0] * cnt[1];
	}
	ans -= n;
	dump(ans);
	return 0;
}


Measured memory_bytes: 11648
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP (i,m,n) for(int i=( int)m ; i < (int ) n ; ++i )
#define rep (i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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



int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	for(int i = 0; i < n; i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
  ll n, m; cin >> n >> m;
  vector<Pii> x(n + m);
  REP(i, n){
    ll a; cin >> a;
    x[i] = mp(a, 1);
  }
  REP(j, m){
    ll b, c; cin >> b >> c;
    x[j + n] = mp(c, b);
  }
  RSORT(x);
  ll temp = 0, ans = 0;
  for(ll i = 0; i < n + m; i++){
    if(temp >= n) break;
    ll diff = min(x[i].second, n - temp);
    ans += x[i].first * diff;
    temp += diff;
  }
  cout << ans << endl;
}


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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if( (e - a) > k ){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=100100100;
const int mod=(int)1e9+7;

int main(){
    int n;
    cin>>n;
    vector<ll>a(n+1);
    vector<vector<int>>s(2*10*10*10*10*10+1,vector<int>(2));
    rep(i,1,n+1){
        cin>>a.at(i);
        //if(a.at(i)>2*10*10*10*10*10)continue;
        //else{
            //if(i+a.at(i)<2*10*10*10*10*10 or i-a.at(i)>1){
                if(i+a.at(i)<2*10*10*10*10*10){
                    s.at(i+a.at(i)).at(0)++;
                    //cout<<i+a.at(i);
                }
                if(i-a.at(i)>1){
                    s.at(i-a.at(i)).at(1)++;
                    //cout<<' '<<i-a.at(i)<<endl;;
                }
            //}
        //}
    }
    ll ans=0;
    rep(i,1,2*10*10*10*10*10+1){
        ans=ans+(ll)s.at(i).at(0)*s.at(i).at(1);
    }
    cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 15676
#include <iostream>
#include <set>
#include <numeric>
#include <map>
using namespace std;

long long a[100000];
long long b[100000];

long long ans[10];
map <long long, set<long long> > point_map;
set <pair <long long, long long> > checked;
int main(void){
    // Your code here!
    long long H;
    long long W;
    int N;
    cin >> H >> W >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
        if(point_map.find(a[i]) == point_map.end()){
            set <long long> tmp = {b[i]};
            point_map[a[i]] = tmp;
        } else {
            point_map[a[i]].insert(b[i]);
        }
    }
    
    for(int i = 0; i < N; i++){
        for(int j = -2; j <= 0; j++){
            for(int k = -2; k <= 0; k++){
                int upper_left_h = a[i] + j;
                int upper_left_w = b[i] + k;
                if(checked.find(make_pair(upper_left_h, upper_left_w)) != checked.end() 
                    || upper_left_h < 1 || upper_left_w < 1 || upper_left_h > H - 2 || upper_left_w > W - 2){
                    continue;    
                }
                int filled_no = 0;
                for(int l = 0; l < 3; l++){
                    for(int m = 0; m < 3; m++){
                        int cur_h = upper_left_h + l;
                        int cur_w = upper_left_w + m;
                        if(point_map.find(cur_h) != point_map.end() && point_map[cur_h].find(cur_w) != point_map[cur_h].end()){
                            filled_no++;
                        }
                    }
                }
                ans[filled_no] ++;
                checked.insert(make_pair(upper_left_h, upper_left_w));
            }
        }
    }
    ans[0] = (H - 2) * (W - 2) - accumulate(ans + 1, ans + 10, (long long) 0);
    for(int i = 0; i < 10; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  int N=S.length();
  int temp=0;
  int pnt=0;
  for(int i=0;i<N;i++){
    if(temp){
      if(S.at(i)=='g'){
        pnt++;
        temp--;
      }
      else{
        temp--;
      }
    }
    else{
      if(S.at(i)=='p'){
        pnt--;
        temp++;
      }
      else{
        temp++;
      }
    }
  }
  cout<<pnt<<endl;
  return 0;
}


Measured memory_bytes: 512