akhauriyash/Code-Regression huggingface dataset:
# エクサウィーズ2019C

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


n,q = map(int, input().split())
S = input()
ts = [None] * q
ds = [None] * q
for i in range(q):
    ts[i], ds[i] = input().split()

d2v = {"L": -1, "R": 1}
def sub(i, left=True):
    # i番目が左(右)に落ちるかどうか
    for t,d in zip(ts, ds):
        c = S[i]
        if c==t:
            i += d2v[d]
        if (left and i<0) or (not left and i>=n):
            return True
        if (left and i>=n) or (not left and i<0):
            return False
        
    return False

s = 0
t = n-1
if not sub(s):
    lnum = 0
elif sub(t):
    lnum = n
else:
    while t-s>1:
        m = (s+t)//2
        if sub(m):
            s = m
        else:
            t = m
    lnum = s+1
s = 0
t = n-1
if sub(s, False):
    rnum = n
elif not sub(t, False):
    rnum = 0
else:
    while t-s>1:
        m = (s+t)//2
        if sub(m, False):
            t = m
        else:
            s = m
    rnum = n-(s+1)
print(n-(lnum+rnum))

Measured memory_bytes: 97948
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull =  unsigned long long;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define pii pair<int,int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<"# "<<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))

const int MX = 1e5+5;

std::vector<int>node[MX];
bool vis[MX];
int dp[MX];
int n,m;

void dfs(int s)
{
	//if(!vis[s])return 0;
	vis[s]=1;
	for(auto d:node[s]){
		if(!vis[d]){
			dfs(d);
		}
		dp[s]=max(dp[s],dp[d]+1);
	}
}
int main()
{
	//fast_io
	cin >>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin >>a>>b;
		node[a].pb(b);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,dp[i]);
	}
	cout <<ans<<endl;
	return 0;
}

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

using namespace std;

constexpr int MAXN = 1e5 + 5, MOD = 1e9 + 7;

template <typename T>
inline void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

struct BIT { //Binary Index Trees, 1based
    int lowbit(int x) { return x & (~x + 1); }
    /* O(n) 建树*/
    void build(int x = 2, int sub = 1) {
        while (x <= n) {
            for (int i = x; i <= n; i += x)
                c[i] += c[i - sub];
            x <<= 1, sub <<= 1;      // 2 ^ n
        }
    }
    /*@param x the position to add val*/
    void add(int x, int val) {
        while (x <= n) c[x] += val, x += lowbit(x);
    }
    /*查询 [1, x] 的前缀和*/
    int query(int x, int res = 0) {
        while (x) res += c[x], x -= lowbit(x);
        return res;
    }
    int n;
    array<int, MAXN> c;
};

#define int long long

int tc, n, m;
array<int, MAXN> a;

inline int qpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

signed main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    int res = qpow(10, n);
    int minus = qpow(8, n);
    (minus += 2LL * (qpow(9, n) - qpow(8, n))) %= MOD;
    (res -= minus) %= MOD;
    cout << (res + MOD) % MOD <<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 50 + 5;
ll f[2][maxn];
int main()
{
	int n, p;
	scanf("%d%d", &n, &p);
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		int v;
		scanf("%d", &v);
		v %= 2;
		if(!v)
		{
			f[0][i] = f[0][i - 1] << 1;
			f[1][i] = f[1][i - 1] << 1;
		}
		else
		{
			f[0][i] = f[0][i - 1] + f[1][i - 1];
			f[1][i] = f[1][i - 1] + f[0][i - 1];
		}
	}
	cout << f[p][n] << endl;
	return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1 && b!=1)
        cout<<"Alice"<<endl;
    else if(b==1 && a!=1)
        cout<<"Bob"<<endl;
    else  if(a==b)
    cout<<"Draw"<<endl;
    else if(a>b)
        cout<<"Alice"<<endl;
    else if(b>a)
        cout<<"Bob"<<endl;

    return 0;



}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int MOD = 1000000007;
	static int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int res = 0;
        if (a == 1 && b == 2) res = 3;
        if (a == 1 && b == 3) res = 2;
        if (a == 2 && b == 1) res = 3;
        if (a == 2 && b == 3) res = 1;
        if (a == 3 && b == 1) res = 2;
        if (a == 3 && b == 2) res = 1;
                
        System.out.println(res);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef map<int, bool> mp;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define pr(x) cout<<(x)<<endl

int main(void){
  int n,m,a,b,ok;cin>>n>>m;vector<vi> g(n);vector<vb> l(n,vb(n,0));vb rm(n,0),vs(n,0);
  rep(i,m){cin>>a>>b;g[--a].push_back(--b); if(!l[b][a])l[a][b]=1;else{pr(2);pr(++a);pr(++b);return 0;}}
  auto update=[&](int s,mp& nx,bool r){for(int t:g[s])swap(rm[t],nx[t]),rm[t]=r?rm[t]:1;};
  auto f = [&](auto f, int s, int r) -> bool{
    for(int t:g[s])if(t!=r&&vs[t])return 0;
    if(l[s][r])return vs[s]=1;
    vs[s]=1,ok=0;mp nx;update(s,nx,0);
    for(int t:g[s])if(!nx[t]&&f(f,t,r)){ok=1;break;}
    update(s,nx,1);
    return vs[s]=ok;
  };
  rep(i, n){rm.assign(n,0),vs.assign(n,0);if (f(f,i,i)){pr(count(vs.begin(),vs.end(),1));rep(j,n)if(vs[j])pr(j+1);return 0;}}
  pr(-1);return 0;
}


Measured memory_bytes: 3920
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    long long int n,arr[1005],mul,m,l,r,mx;

    while(scanf("%lld",&n)==1)
    {
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&arr[i]);
        }

        mx=0;

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                mul=arr[i]*arr[j];

                m=mul;

                l=m%10;
                m=m/10;

                int flag=0;

                while(m!=0)
                {
                    r=m%10;

                    if(l!=(r+1))
                    {
                        flag=1;
                        break;
                    }

                    l=r;

                    m=m/10;
                }

                if(flag==0)
                {
                    if(mul>mx)
                        mx=mul;
                }
            }
        }

        if(mx==0)
            printf("-1\n");

        else
            printf("%lld\n",mx);
    }

    return (0);
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;

ll add(ll a, ll b) {
	return ((a%mod) + (b%mod)) % mod;
}


ll sub(ll a, ll b) {
	return ((a%mod) - (b%mod) + mod) % mod;
}


ll mul(ll a, ll b) {
	return ((a%mod)*(b%mod)) % mod;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> X, Y;
	ll totalX = 0, totalY = 0;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		X.push_back(x);
		totalX += x;
	}
	for (int i = 0; i < m; i++) {
		ll y;
		cin >> y;
		Y.push_back(y);
		totalY += y;
	}
	ll ans = 0;
	ll sumX = 0;
	sort(X.rbegin(), X.rend());
	sort(Y.rbegin(), Y.rend());
	for (int i = 0; i < n; i++) {
		sumX = add(sumX, sub(mul(n - i, X[i]), totalX));
		totalX -= X[i];
	}
	for (int i = 0; i < m; i++) {
		ll b = sub(mul(m - i, Y[i]), totalY);
		ans = add(ans, mul(sumX, b));
		totalY -= Y[i];
	}
	cout << ans;




}

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

int main()
{
    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    int count[N + 1] = {};
    for (int i = 2; i <= N; i++)
    {
        if (S[i - 2] == 'A' && S[i - 1] == 'C')
        {
            count[i] = count[i - 1] + 1;
        }
        else
        {
            count[i] = count[i - 1];
        }
    }

    int l, r;
    int ans;
    for (int i = 0; i < Q; i++)
    {
        cin >> l >> r;
        ans = count[r] - count[l];
        cout << ans << endl;
    }
}


Measured memory_bytes: 1408
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

a,b,c,x,y = MI()

min = min(x,y)
ans = 0
if a+b>2*c:
    ans += 2*c*min
    if 2*c < a:
        ans+=2*c*(x-min)
    else:
        ans+=a*(x-min)
    if 2*c < b:
        ans+=2*c*(y-min)
    else:
        ans+=b*(y-min)
else:
    ans += a*x + b*y
print(ans)


Measured memory_bytes: 60012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const ll MAX = 10e16;
vector<ll> pw, sm;
ll n;

string solve(ll num, ll len) {
  if (len == 0) return "";
  return char('a' + num / pw[len - 1]) + solve(num % pw[len - 1], len - 1);
}

int main() {
  pw.push_back(1);
  sm.push_back(0);
  while (pw.back() < MAX) {
    pw.push_back(26 * pw.back());
    sm.push_back(pw.back() + sm.back());
  }
  
  scanf("%lld", &n);
  int len = (int)(lower_bound(sm.begin(), sm.end(), n) - sm.begin());
  printf("%s\n", solve(n - sm[len - 1] - 1, len).data());
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    vector<pair<int, int>> ab;
    ab.push_back(make_pair(A, B));
    ab.push_back(make_pair(C, D));
    sort(ab.begin(), ab.end());
    if(ab[0].second <= ab[1].first) {
        cout << 0 << endl;
        return 0;
    }
    cout << min(-ab[1].first + ab[0].second, min(B - A, D - C)) << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys

dq = deque()
num = int(sys.stdin.readline())
line = sys.stdin.readlines()

for i in range(num):

    order = line[i].split()

    if order[0] == 'insert':
        dq.appendleft(order[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(order[1])

print(' '.join(dq))

Measured memory_bytes: 214268
import kotlin.collections.ArrayDeque as ArrayDeque

@OptIn(ExperimentalStdlibApi::class)
fun main(args: Array<String>) {
    val inf = 1001001001
    val to = Array(100005) { mutableListOf<Int>() }

    var (n, m) = readLine()!!.split(" ").map { it.toInt() }
    repeat(m) {
        var (a, b) = readLine()!!.split(" ").map { it.toInt() }

        // inputが1始まりなので調整
        a--
        b--

        // 経路情報を格納
        to[a].add(b)
        to[b].add(a)
    }

    // キュー
    val q = ArrayDeque<Int>()
    // 距離(深さ)
    val dist = Array(n) { inf }
    // 親ノード
    val prev = Array(n) { -1 }

    dist[0] = 0
    q.addLast(0)

    while (q.isNotEmpty()) {
        // キューの先頭要素取得
        val v = q.first()
        q.removeFirst()

        // vから辿れる経路を評価していく
        for (u in to[v]) {
            if (dist[u] != inf) {
                // 設定済みなのでスキップ
                continue
            }

            // vから辿れる経路はv+1
            dist[u] = dist[v] + 1
            // 親ノードにvをセット
            prev[u] = v
            // キューへ追加
            q.addLast(u)
        }
    }

    // 制約；どの2部屋間も、通路をいくつか通って行き来できる
    // -> Noのケース無し
    println("Yes")
    
    for (i in 0 until n) {
        if (i == 0) {
            // 部屋1は出力対象外
            continue
        }

        // 親ノードが辿るべき部屋(0始まりに調整していたのを+1で戻す)
        val ans = prev[i] + 1
        println(ans)
    }
}

Measured memory_bytes: 79840
import math
a,b,h,m = map(int,input().split())
a_cos = 360 / 12 * h + 30 / 60 *m
b_cos = 360  / 60 * m
x = math.cos(math.radians(a_cos - b_cos))
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(a_cos - b_cos))))

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

int main(void){
  int n;
  long long l[87] = {2, 1};
  for(int i = 2; i < 87; i++){
    l[i] = l[i-1] + l[i-2];
  }
  cin >> n;
  cout << l[n] << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program{
  static long Get(long n, long x, long result)
  {
    //Console.WriteLine($"{n} {x} {result}");
    if(x == 0) return result;
    if(n < x) return Get(x, n, result);
    return Get(x, n % x, result + n / x * x * 3);
  }
  static void Main()
  {
    string[] inputs = Console.ReadLine().Split();
    long n = long.Parse(inputs[0]);
    long x = long.Parse(inputs[1]);
    Console.WriteLine(Get(n -x, x, 0));
  }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val);


int main(void)
{
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int arr[1000][1000];
    Fill(arr, 0);
    for(int i=0;i<b;i++)
    {
        for(int j=0;j<a;j++)
        {
            arr[i][j] = 1;
        }
    }

    for(int i=b;i<h;i++)
    {
        for(int j=a;j<w;j++)
        {
            arr[i][j] = 1;
        }
    }

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cout << arr[i][j];
        }
        cout << endl;
    }
    return 0;
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
    fill( (T*)array, (T*)(array+N), val );
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, int> PL;
constexpr int mod = 1e9 + 7;
constexpr int INF = 2e9;

int main() {
  ll n, m;
  cin >> n >> m;
  if (n > m) swap(n, m);
  if (n == 1 && m == 1) cout << 1 << endl;
  else if (n == 1) cout << m - 2 << endl;
  else cout << (n - 2) * (m - 2) << endl;
  return 0;
} 

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

ll gcd(ll m, ll n) {
    return n != 0 ? gcd(n, m % n) : m;
}

ll lcm(ll m, ll n) {
    // If both m and n are large numbers, the result is overflow without parentheses.
    return m * (n / gcd(m, n));
}

void solve() {
    int a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
int main(){
    ll n1,n2;cin>>n1>>n2;
    ll num;cin>>num;
    ll cnt=0;
    ll ans;
    rrep(i,1,min(n1,n2)){
        if(n1%i==0&&n2%i==0){
            cnt++;
            if(cnt==num){
                ans=i;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# include <algorithm>
# include <iostream>
# include <map>
# include <queue>
# include <string>
# include <vector>

using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<string, int> d;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        if (d.find(s) != d.end()) {
            int c = d.at(s);
            d.erase(s);
            c++;
            d.insert(make_pair(s, c));
        } else {
            d.insert(make_pair(s, 1));
        }
    }
    int m; cin >> m;
    for (int i = 0; i < m; i++) {
        string t; cin >> t;
        if (d.find(t) != d.end()) {
            int c = d.at(t);
            d.erase(t);
            c--;
            d.insert(make_pair(t, c));
        }
    }
    int y = 0;
    for (auto& x : d) {
        y = max(y, x.second);
    }
    cout << y << "\n";
    return 0;
}


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

using namespace std;

int main(){
    int k,s;
    cin>>k;
    string str;
    cin>>str;
    s=str.length();
    if(s>k){
        string tmp="";
        for(int i=0;i<k;i++)tmp+=str[i];
        tmp+="...";
        str=tmp;
    }
    cout<<str<<"\n";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, s, n) for(int i = s; i < n; i++)
#define rrep(i, s, n) for(int i = s; i > (s)-(n); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  string a, b;
  cin >> a >> b;

  int n = stoi(a+b);
  int i = 0;
  while (i*i <= n) {
    if (i*i == n) {
      pr("Yes");
      return 0;
    }
    i++;
  }
  pr("No");


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string a,b,c; cin>>a>>b>>c;
	if (a.back()==b.front()&&b.back()==c.front()) cout<<"YES";
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#include <math.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

int brute(int n, int k) {
  int ans = 0;
  for (int i=1;i<=n;++i)
    for (int j=1;j<=n;++j)
      for (int l=1;l<=n;++l)
        if ( (i + j) % k == 0 && (i + l) % k == 0 && (j + l) % k == 0 ) {
          ++ans;
        }
  return ans;
}

int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);

  long long p = n / k;
  long long ans = p * p * p;

  if (k == 2) {
    long long p2 = (n + 1) / k;
    ans += (p2 * p2 * p2);

    printf("%lld", ans);

    return 0;
  }
  

  
  if (k % 2 == 0) {
    int c = 1;
    if (n % k < k / 2)
      --c;

    ans += (p + c) * (p + c) * (p + c);
  }


  printf("%lld", ans);


  return 0;
}


Measured memory_bytes: 128
N = int(input())
List = input()
import re

Shift = re.split(" ",List)
Ctr = 1
Wlist = []


for Ctr in range(1,N+1):
    Xn = 1
    DW = int(Shift[Ctr-1])
    while True:
        if DW % (2**Xn) != 0:
            break
        else:
            Xn += 1
    Wlist.append(Xn-1)
    Ctr += 1

print(sum(Wlist))

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
const int INF=10010010;
int main(){
  int N;
  cin>>N;
  vector<int>W(N);
  int sum=0;
  rep(i,N){
    cin>>W[i];
    sum+=W[i];
  }
  int tmp=0;
  int res=INF;
  int ans=INF;
  int ans2=INF;
  rep(i,N){
    tmp+=W[i];
    res=sum-tmp;
    ans2=abs(res-tmp);
    ans=min(ans,ans2);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
a=input()
b=input()
c=input()
m=len(a)
n=len(b)
o=len(c)
i=0
j=0
k=0
curr=a
while(1):
    if(curr==a):
        if(i==m):
            print("A")
            break
        if(curr[i]=='b'):
            curr=b
        elif(curr[i]=='c'):
            curr=c
        i+=1
    elif(curr==b):
        if(j==n):
            print("B")
            break
        if(curr[j]=='a'):
            curr=a
        elif(curr[j]=='c'):
            curr=c
        j+=1
    elif(curr==c):
        if(k==o):
            print("C")
            break
        if(curr[k]=='a'):
            curr=a
        elif(curr[k]=='b'):
            curr=b
        k+=1

Measured memory_bytes: 38384
a, b, c = [int(x) for x in input().split()]
k = int(input())

max_n = max(a, b, c)
if max_n == c:
    rem = [a, b]
elif max_n == b:
    rem = [a, c]
else:
    rem = [b, c]
for _ in range(k):
    max_n *= 2
print(sum(rem) + max_n)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;

int dp[100010];

int main(){
    int n;cin>>n;
    vi co;
    co.push_back(1);
    for(int i=6;i<=100000;i*=6)co.push_back(i);
    for(int i=9;i<=100000;i*=9)co.push_back(i);
    sort(co.begin(),co.end());
    rep(i,0,n+1)dp[i]=20;
    dp[0]=0;
    rep(i,0,co.size()){
        for(int j=0; j+co[i]<=n;j++){
            dp[j+co[i]]=min(dp[j+co[i]],dp[j]+1);
        }
    }
    cout<<dp[n]<<endl;
	return 0;
}



Measured memory_bytes: 640
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(args){
    var N = parseInt(args.split('\n')[0], 10);
    var tmp = N;
    var fx = 0;

    while(tmp>0){
        fx += tmp%10;
        tmp = Math.floor(tmp/10);
    }

    console.log( N%fx==0 ? 'Yes' : 'No' );
}

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

int main()
{
    

    int s,t,count,i,k,m=0;
    char S[1000],T[1000];
    cin>>S>>T;
    s=strlen(S);
    t=strlen(T);

    for(i=0;i<s-t+1;++i)
    {   count=0;
    	for(k=0;k<t;++k)
    	{
    		if(S[i+k]==T[k])
    			++count;
    	}
    	if (m<count)
    	    m=count;
    	    
    	
    }
    cout<<t-m;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define all(v) (v.begin(),v.end())
#define ll long long
const int N=35;
const int inf=2e9;

int main(){
    ios::sync_with_stdio(0);
    string s;
    cin>>s;
    int n=s.length();
    vector<int>vis(26,0);
    if(n<26){
        for(int i=0;i<n;++i){
            int t=s[i]-'a';
            vis[t]=1;
        }
        char ch;
        for(int i=0;i<26;++i){
            if(!vis[i]){
                ch='a'+i;
                break;
            }
        }
        cout<<s<<ch<<endl;
        return 0;
    }
    int flag=0;
    for(int i=n-1;i>=0;--i){
        char c=s[i];
        int f1;
        while(c<'z'){
            ++c;
            f1=1;
            for(int j=0;j<i;++j){
                if(c==s[j]){
                    f1=0;
                    break;
                }
            }
            if(f1) break;
        }
        if(f1){
            s[i]=c;
            s=s.substr(0,i+1);
            flag=1;
            break;
        }
    }
    if(flag) cout<<s;
    else cout<<-1;
    return 0;
}


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

int main()
{
	auto dist = [](pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) -> long double {
		return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
	};

	auto fact = [](int64_t n) {
		int64_t r = 1;
		for (int64_t i = 1; i <= n; i++)
		{
			r *= i;
		}
		return r;
	};

	int64_t n;
	cin >> n;
	vector<int64_t> xs(n), ys(n);
	for (int64_t i = 0; i < n; i++)
	{
		cin >> xs[i] >> ys[i];
	}

	long double ans = 0;

	for (int64_t i = 0; i < n; i++)
	{
		for (int64_t j = i + 1; j < n; j++)
		{
			ans += 2 * dist({xs[i], ys[i]}, {xs[j], ys[j]}) * fact(n - 1);
		}
	}

	ans /= fact(n);

	cout << fixed << setprecision(20) << ans << endl;

	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  vpll ab(m);
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    ab[i]={a,b};
  }
  
  UnionFind uf(n);
  vll ans(m);
  ans[m-1]=n*(n-1)/2;
  
  rrep(i,m-1){
    ll a,b; tie(a,b)=ab[i+1];
    if(!uf.isSame(a,b)){
      ans[i]=ans[i+1]-(uf.size(a)*uf.size(b));
      uf.connect(a,b);
    }else{
      ans[i]=ans[i+1];
    }
  }
  
  rep(i,m){
    cout<<ans[i]<<endl;
  }
  
}

Measured memory_bytes: 4480
function main(arg) {
	arg = arg.split("\n")
	var N = Number(arg[0])
	var tmp = arg[1].split(" ")
	var A = tmp[0]
	var B = tmp[1]
	var P = arg[2].split(" ").map(e => Number(e))

	var count = 0;
	for (;;) {
		// 1
		var flg1 = false;
		for (var i = 0; i < P.length; i++) {
			if (P[i] <= A) {
				flg1 = true
				P[i] = null
				break
			}
		}

		P = P.filter(n => n !== null);

		if (!flg1) {
			break
		} 

		// 2
		var flg2 = false;
		for (var i = 0; i < P.length; i++) {
			if (A < P[i] && P[i] <= B) {
				flg2 = true
				P[i] = null
				break
			}
		}

		P = P.filter(n => n !== null);

		if (!flg2) {
			break
		} 

		// 3
		var flg3 = false;
		for (var i = 0; i < P.length; i++) {
			if (B < P[i] ) {
				flg3 = true
				P[i] = null
				break
			}
		}

		P = P.filter(n => n !== null);

		if (!flg3) {
			break
		}
		
		count++;
	}

	console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <iostream>
using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;

ll fact(ll a){
  ll ans = 1;
  for(int i = 2; i <= a; i++) ans = (ans * i) % mod;  
  return ans;
}

ll exp(ll a, ll b){
  ll ans = 1;
  a %= mod;
  while (b){
    if ((b & 1) == 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

ll solve(ll k, ll n){
  ll x = max(n - k, k);
  ll ans = 1;
  for(ll i = x + 1; i <= n; i++) ans = (ans * i) % mod;
  ans = (ans * exp(fact(n - x), mod - 2)) % mod;
  return ans;
}

int main(){
  ll n, a, b;
  cin>>n>>a>>b;
  ll ans = (exp(2,n) + mod - 1) % mod;
  ll x = solve(a, n);
  ll y = solve(b, n);
  ans = (ans - x - y + mod + mod) % mod;
  cout<<ans<<endl;
}

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

namespace otameshi
{
    class Program
    {
        static void Main(string[] args)
        {
            int k, x;
            var word = Console.ReadLine().Split(' ');
            k = int.Parse(word[0]);
            x = int.Parse(word[1]);
            if (500 * k >= x)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 

operations = T[:]
v_limits = V[:]

v = 0
limits_x = [0]
for i in range(N):
    for _ in range(operations[i]*2):
        v += 0.5
        limit = min(v, v_limits[i])
        limits_x.append(limit)
        v = limit
        
        
v = 0
limits_y = [0]
for i in reversed(range(N)):
    for _ in range(operations[i]*2):
        v += 0.5
        limit = min(v, v_limits[i])
        limits_y.append(limit)
        v = limit
limits_y = list(reversed(limits_y))
#print(limits_x)
#print(limits_y)

limits_z = [min(x,y) for x, y in zip(limits_x, limits_y)]
#print(limits_z)

ans = 0
for _z, z in zip(limits_z[:-1],limits_z[1:]):
    ans += (_z+z)*0.5/2
print(ans)



Measured memory_bytes: 47216
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class E
{
	static void Main()
	{
		var k = int.Parse(ReadLine());
		var a = ReadLine().Split(' ').Select(int.Parse).ToArray();
		var q = new V(a[0], a[1]);

		if (k % 2 == 0 && q.Norm % 2 == 1)
		{
			WriteLine(-1);
			return;
		}
		var ps = new List<V> { new V() };
		var l = q.Norm % k == 0 ? 2 : q.Norm % 2 == 1 && q.Norm < k ? 4 : 3;
		if (l == 4) ps.Add(q.NextShot4(k));
		if (l >= 3) ps.Add(ps.Last() + (q - ps.Last()).NextShot3(k));
		while ((q - ps.Last()).Norm != 0) ps.Add(ps.Last() + (q - ps.Last()).NextShot2(k));
		WriteLine(ps.Count - 1);
		foreach (var p in ps.Skip(1)) WriteLine("{0} {1}", p.X, p.Y);
	}
}

struct V
{
	public int X;
	public int Y;
	public int Norm;

	public V(int x, int y)
	{
		X = x;
		Y = y;
		Norm = Abs(x) + Abs(y);
	}
	public static V operator +(V v, V w) => new V(v.X + w.X, v.Y + w.Y);
	public static V operator -(V v, V w) => new V(v.X - w.X, v.Y - w.Y);

	public V NextShot4(int k) => Abs(X) >= Abs(Y) ? new V(-Sign(X) * (k - Norm), (Y > 0 ? -1 : 1) * Norm) : new V((X > 0 ? -1 : 1) * Norm, -Sign(Y) * (k - Norm));
	public V NextShot3(int k)
	{
		var w2 = k - Norm % k;
		if (w2 % 2 == 1) w2 += k;
		var w = Norm < k ? k - Norm / 2 : w2 / 2;
		return Abs(X) >= Abs(Y) ? new V(Sign(X) * (k - w), (Y > 0 ? -1 : 1) * w) : new V((X > 0 ? -1 : 1) * w, Sign(Y) * (k - w));
	}
	public V NextShot2(int k)
	{
		var d = Min(Abs(X), k);
		return new V(Sign(X) * d, Sign(Y) * (k - d));
	}
}


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

public class Main {
	public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
    	String items[]=reader.readLine().split(" ");
    	int a=Integer.parseInt(items[0]);
    	int b=Integer.parseInt(items[1]);
    	int c=Integer.parseInt(items[2]);
    	int counter=0;
        for(int i=a;i<=b;i++){
        	if(c%i==0){
        		counter++;
        	}
        }
        System.out.println(counter);
	}
}

Measured memory_bytes: 24452
H, W = map(int, input().split())
grid = []
for _ in range(H):
    line = list(map(int, input().split()))
    grid.append(line)
# print(grid)
q = []
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            q.append([i, j])
    else:
        for j in range(W - 1, -1, -1):
            q.append([i, j])
# print(q)
cnt = 0
op_list = []
for i in range(len(q) - 1):
    if grid[q[i][0]][q[i][1]] % 2 == 0:
        pass
    else:
        grid[q[i][0]][q[i][1]] -= 1
        grid[q[i + 1][0]][q[i + 1][1]] += 1
        cnt += 1
        op_list.append([q[i][0], q[i][1], q[i + 1][0], q[i + 1][1]])
print(cnt)
for op in op_list:
    print(op[0] + 1, op[1] + 1, op[2] + 1, op[3] + 1)


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

using namespace std;

#define inf (ll)1e15
#define ll long long
#define all(x) x.begin(), x.end()
#define x first
#define y second

typedef pair<int, int> Point;

const int mod = (int) 1e9 + 7;
const int mod2 = 998244353;
const int MAX_NODES = 1000;

struct Trie{

	int sz;
	int t[MAX_NODES][26], cnt[MAX_NODES][26];

	Trie(){
		memset(t, 0xff, sizeof t);
		memset(cnt, 0, sizeof cnt);
		sz = 0;
	}

	void insert(string s){
		int node = 0;
		for(int i = 0; i < s.size(); ++i){
			if(t[node][s[i] - 'a'] == -1)
				t[node][s[i] - 'a'] = ++sz;
			++cnt[node][s[i] - 'a'];
			node = t[node][s[i] - 'a'];
		}
	}

	int find(string s){
		int node = 0;
		int res = 0;
		for(int i = 0; i < s.size(); ++i){
			res = cnt[node][s[i] - 'a'];
			node = t[node][s[i] - 'a'];
		}
		return res;	
	}

}trie;


int main(){

    cin.tie(0);
    cin.sync_with_stdio(0);

    #ifdef Cyborg101
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

  	// int n;
  	// cin >> n;

  	// std::vector<int> prime(1e6 + 1, true);
  	// prime[1] = false;

  	// for(int i = 2; i <= 5e5; ++i){
  	// 	if(prime[i])
  	// 		for(int j = 2 * i; j <= 1e6; j += i){
  	// 			prime[j] = false;
  	// 		}
  	// }

  	// for(int i = 0; i < n; ++i){
  	// 	ll x;
  	// 	cin >> x;
  	// 	ll sq = sqrtl(x);

  	// 	if(sq * sq == x && prime[sq])
  	// 		cout << "YES" << endl;
  	// 	else
  	// 		cout << "NO" << endl;
  	// }

    int n;
    cin >> n;

    int All = 1;
    int odds = 1;
    for(int i = 0, x; i < n; ++i){
    	cin >> x;
    	All *= 3;
    	odds *= (x & 1 ? 1 : 2);
    }
    cout << All - odds << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>                                                                               
using namespace std;
#define FOR(v1, v2) for (v1 = 0; v1 < v2; ++v1)

const uint64_t kNumBits = 60; 
constexpr uint64_t kMod = 1'000'000'007;
uint64_t cnt[kNumBits][2];;

int main () {
  uint64_t N, i, j;
  cin >> N;
  uint64_t b = 0;
  uint64_t a;
  FOR(i, N) {
    cin >> a;
    FOR(j, kNumBits) {
      b = 1 & (a >> j); 
      cnt[j][b] += 1;
      if (b != 0 && b!= 1) return 0;
    }   
  }

  uint64_t ans = 0;
  FOR(j, kNumBits) {
    uint64_t val =  (1ULL << j); 
    //cout << j << ":" <<  val << ":" << kMod;
    val %= kMod;
    val *= cnt[j][0];
    val %= kMod;
    val *= cnt[j][1];
    val %= kMod;
    ans += val;
    //cout << ":" << ans << endl;
  }
    ans %= kMod;
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) (int)s.size()
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
const int MOD=1e9+7;
void solve()
{
fastio
int x;
cin>>x;
if(x)
cout<<0;
else
cout<<1;
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    
    int cnt = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == T[i]) cnt++;
    }
    
    cout << cnt;
    
    return 0;
}


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

int main(){
  string a,b;
  cin >>a >>b;
  int A = a.size(), B = b.size();
  int ans = 0;
  if(A>B) ans = 1;
  else if(A<B) ans = -1;
  else{
    rep(i,A){
      if(a[i]>b[i]){
        ans = 1;
        break;
      }
      else if(a[i]<b[i]){
        ans = -1;
        break;
      }
    }
  }
  if(ans==1) cout << "GREATER" << endl;
  else if(ans==-1) cout << "LESS" << endl;
  else cout << "EQUAL" << endl;
  return 0;
}

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

#define MOD 1000000007

int A[102];
int dp[2][100005], fp[2][100005];

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int N, K;
    cin >> N >> K;
    
    for(int i=1; i<=N; i++)
        cin >> A[i];
    
    int prev = 0, curr = 1;
    dp[0][0] = fp[0][0] = 1;
    
    for(int i=1; i<=K; i++)
        fp[0][i] = 1;
    
    for(int i=1; i<=N; i++, swap(prev, curr))
    {
        for(int j=0; j<=K; j++)
        {
            dp[curr][j] = fp[prev][j] - (j - A[i] - 1 >= 0 ? fp[prev][ j - A[i] - 1 ] : 0);
            
            if(dp[curr][j] < 0)
                dp[curr][j] += MOD;
            
            fp[curr][j] = fp[curr][j-1] + dp[curr][j];
            
            if(fp[curr][j] >= MOD)
                fp[curr][j] -= MOD;
        }
    }
    
    cout << dp[prev][K] << "\n";
    return 0;
}

Measured memory_bytes: 1792
/*
  Task: I. Kevin and Grid
  Link: http://codeforces.com/contest/1392/problem/I
  Lang: cpp17
*/
#include <bits/stdc++.h>
using namespace std;

#define eb emplace_back
#define pb push_back
#define INF LLONG_MAX
#define FLT_INF pow(10.0, 16)


using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<ll, ll>;
using int3 = tuple<ll, ll, ll>;

template <typename A> string to_string(const A& v);
string to_string(const string& s) { return '"'+ s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C> string to_string(const tuple<A, B, C>& p) {
  return "(" + to_string(std::get<0>(p)) + ", " + to_string(std::get<1>(p)) +  ", " + to_string(std::get<2>(p)) + ")";
}

template <typename A> string to_string(const A& v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T>
void sort(vector<T>& val) {
  sort(val.begin(), val.end());
}

template <typename T>
void reverse(vector<T>& val) {
  reverse(val.begin(), val.end());
}

template <typename T>
void sort_b(vector<T>& val) {
  sort(val.begin(), val.end(), greater<T>());
}

template <typename T>
T pair_sum(pair<T, T>& val) {
  return val.first + val.second;
}


template <typename T>
T min(T a, T b, T c) {
  return min(min(a, b), c);
}

template <typename T>
T max(T a, T b, T c) {
  return max(max(a, b), c);
}


template <typename T>
T mul_mod(T a, T b, T mod) {
  T res = 0;
  a %= mod;
  while (b) {
    if (b & 1) {
      res = (res + a) % mod;
    }
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...);
#endif

#define COMMON_MOD pow(10, 9) + 7
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;
/* printf("%lld %lld \n", cur_n, m / 2 + 1);
sort(a.begin(), a.end(), [ ](ll& lhs, ll& rhs) {return abs(lhs) < abs(rhs);});
*/


class mytask {
public:

  mytask() { }

  
  int solve() {

    ll n;
    cin >> n;
    vll a(n);
    for (ll i = 0; i < n; i++) {
      cin >> a[i];
    }

    ll res = 0;
    ll mod7 = 1e9 + 7;
    vll sums(n);
    //sums[n-1] = a[n-1];
    for (ll i = n-2; i >= 0; i--) {
      sums[i] = sums[i + 1] + a[i+1];
    }
    debug(sums);
    for (ll i = 0; i < n; i++) {
      
      res = res + mul_mod(a[i], sums[i], mod7);
      res = res % mod7;
      
    }

    cout << res;
    
    return 0;
  }

   

};


int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  auto task = mytask();
  task.solve();


  //cout << endl;

  return 0;
}


Measured memory_bytes: 6340
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
L  = sorted(LI())
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        ret += bisect_left(L, L[i] + L[j]) - j - 1

print(ret)

Measured memory_bytes: 43612
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
ll len, A, B, L, R;
int mod, n;
struct matrix
{
	ll mat[3][3];
}a;
matrix operator * (matrix a, matrix b) 
{
	matrix res;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
		{
			res.mat[i][j] = 0;
			for(int k=0; k<n; k++)
				res.mat[i][j] = (res.mat[i][j]+a.mat[i][k]*b.mat[k][j]%mod)%mod;
		}
	return res;
}
void one(matrix& E) 
{
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			E.mat[i][j] = (i==j);
}
matrix operator ^ (matrix a, ll x) 
{
	matrix res;
	one(res);
	while(x)
	{
		if(x&1) res = res * a;
		a = a * a;
		x >>= 1;
	}
	return res;
}
bool find(ll x, ll y)
{
	ll l = 0, r = len-1;
	L = -1;
	while(l<=r)
	{
		ll mid = (l+r)>>1;
		ll cur = A + mid*B;
		if(cur<x) l = mid + 1;
		else L = mid, r = mid - 1;
	}
	l = 0, r = len-1;
	R = -1;
	while(l<=r)
	{
		ll mid = (l+r)>>1;
		ll cur = A + mid*B;
		if(cur>=y) r = mid - 1;
		else R = mid, l = mid + 1;
	}
	if(R==len-1) return 0;
	return 1;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> len >> A >> B >> mod;
 	const ll up = 1e18;
 	ll ans = 0, s = 0;
 	bool ok = 1;
 	n = 3;
 	for(ll d=10; d<=up&&ok; d*=10)
 	{
 		ok = find(d/10, d);
 		if(R-L+1<=0) continue;
 		a.mat[0][0] = d%mod;
 		a.mat[0][1] = a.mat[0][2] = a.mat[1][2] = a.mat[2][0] = 0;
 		a.mat[1][0] = a.mat[1][1] = a.mat[2][2] = 1;
 		a.mat[2][1] = B%mod;
 		a = a ^ (R-L+1);
 		(s = A + L*B) %= mod;
 		(ans = ans*a.mat[0][0]%mod + s*a.mat[1][0]%mod + a.mat[2][0]) %= mod;
 	}
 	ans = (ans + mod)%mod;
 	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
	char a[100],b[100],c[100];
	scanf("%s %s %s",a,b,c);
	int x=0,y=0,z=0,d=strlen(a),e=strlen(b),f=strlen(c),flag=0;
	while(1){
		if(flag==0){
			if(x==d){
				printf("A");
				return 0;
			}
			if(a[x]=='a'){x++;flag=0;}
			else if(a[x]=='b'){x++;flag=1;}
			else if(a[x]=='c'){x++;flag=2;}
		}else if(flag==1){
			if(y==e){
				printf("B");
				return 0;
			}
			if(b[y]=='a'){y++;flag=0;}
			else if(b[y]=='b'){y++;flag=1;}
			else if(b[y]=='c'){y++;flag=2;}
		}else{
			if(z==f){
				printf("C");
				return 0;
			}
			if(c[z]=='a'){z++;flag=0;}
			else if(c[z]=='b'){z++;flag=1;}
			else if(c[z]=='c'){z++;flag=2;}
		}
	}
}

Measured memory_bytes: 128
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	long[] as = readln.split.map!(to!long).array;
	
	int count = 0;
	int trend = 0;
	bool hasOld = 0;
	long old = 0;
	for(int i = 0; i < n; i ++){
		debug writeln(i, " ", as[i], " ", old, " ", trend, " ", count);
		if(!hasOld){
			count += 1;
			debug "a".writeln;
			}
		else{
			if(trend != 0){
				if(trend > 0 && old <= as[i] || trend < 0 && old >= as[i]){
					debug "b".writeln;
					}
				else{
					trend = 0;
					count += 1;
					debug "c".writeln;
					}
				}
			else{
				if(old < as[i]) trend = 1;
				else if(old > as[i]) trend = -1;
				debug "d".writeln;
				}
			}
		old = as[i];
		hasOld = 1;
		debug writeln(i, " ", as[i], " ", old, " ", trend, " ", count);
		debug "-".writeln;
		}
	
	count.writeln;
	}

Measured memory_bytes: 4392
# solution

data=int(input())
array=[list(map(int,input().split())) for _ in range(data)]
array.sort(key=lambda x:x[1])
count=0
for i in range(data):
    count+=array[i][0]
    if count>array[i][1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 53600