akhauriyash/Code-Regression huggingface dataset:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


class SegTree:
    X_unit = 0
    X_f = max

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)


def main():
    n, k = input_int_list()
    segtree = SegTree(500000)
    for _ in range(n):
        a = input_int()

        val = segtree.fold(max(0, a - k), min(500000, a + k + 1))
        segtree.set_val(a, val + 1)

    print(segtree.X[1])

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 78332
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  vector<vector<int>> field(h,vector<int>(w,1));
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if(i<b&&j<a) field[i][j]=0;
      else if(i>=b&&j>=a) field[i][j]=0;
      cout<<field[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<vector<int>> a(2,vector<int>(n));
	rep(i,2) rep(j,n) cin >> a[i][j];
	int ans = 0;
	rep(i,n){
		int sum = 0;
		rep(j,n){
			if(j < i) sum += a[0][j];
			else if(j == i) sum += a[0][j] + a[1][j];
			else sum += a[1][j];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = int(input())
a = list(map(int, input().split()))
num = 1
for i in range(n):
    num = lcm(num, a[i])
ans = 0
for i in range(n):
    ans += num // a[i]
print(ans % (10 ** 9 + 7))


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

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

	string s;
	//int n,k;//,b;

	//cin >> n >> k;
	cin >> s;
	
	string ans="Yes";
	
	//int ans=0;
	//vector<int> h(n);
	
	string s1="";//o
	string s2="";//e
	
	rep(i,s.size()){
		if(i%2){//i:odd->even
			if(s[i]=='R'){
				ans="No";
				break;
			}
				
		}
		else{   //i;even->odd
			if(s[i]=='L'){
				ans="No";
				break;
			}
		}
	}
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
#include <iostream>
 int main() {
  int a, b, c;
   std::cin >> a >> b >> c;

    if (a < b && b < c) {
     std::cout << "Yes" <<std::endl;
    } else {
     std::cout << "No" <<std::endl;
    }





 return 0;



}
    


Measured memory_bytes: 3020
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
int h,w;
int ans;
int d[25][25];
char ch[25][25];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
struct node{
	int x,y;
};
bool check(int x,int y){
	return x>0&&x<=h&&y>0&&y<=w&&d[x][y]==-1&&ch[x][y]=='.';
}
inline int max(int a,int b){
	return a>b?a:b;
}
int bfs(int x,int y){
	int res=0;
	queue<node> q;
	q.push(node{x,y});
	d[x][y]=0;
	while(!q.empty()){
		node now=q.front();
		q.pop();
		int nx=now.x;
		int ny=now.y;
//		printf("%d %d\n",nx,ny);
		if (d[nx][ny]!=-1){
			res=max(res,d[nx][ny]);
		}
		for (int i=0;i<4;i++){
			int xx=nx+dx[i];
			int yy=ny+dy[i];
			if (check(xx,yy)){
				q.push(node{xx,yy});
				d[xx][yy]=d[nx][ny]+1;
			}
		}
	}
	return res;
}
int main(){
	scanf("%d%d",&h,&w);
	for (int i=1;i<=h;i++){
		scanf("%s",ch[i]+1);
	} 
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++){
			if (ch[i][j]=='.'){
				memset(d,-1,sizeof(d));
				int now=bfs(i,j);
//				printf("%d\n",now);
				ans=max(ans,now);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	int cnt = 0;
	for (int i = 1, x; i <= n; ++i) {
		cin >> x;
		if ((i & 1) && (x & 1)) cnt++;
	}
	
	cout << cnt << '\n';
	
	return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
typedef pair<ll, P> E;
struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<ll> weight;
	int size;
	UnionFind(int n, vector<ll> &weight) :size(n), weight(weight) {
		par.resize(size);
		rank.resize(size);
		for (int i = 0; i < size; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			weight[y] += weight[x];
		}
		else {
			par[y] = x;
			weight[x] += weight[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		x = find(x);
		y = find(y);
		return x == y;
	}
};
vector<E> edge;
vector<P> G[100000];
int use[100000];
void dfs(int v, ll d) {
	for (P p : G[v]) {
		if (edge[p.second].first > d || use[p.second] == 1) continue;
		use[p.second] = 1;
		dfs(p.first, d);
	}
}
int main() {
	int N, M;
	cin >> N >> M;
	vector<ll> X;
	for (int i = 0; i < N; i++) {
		ll x;
		cin >> x;
		X.push_back(x);
	}
	for (int i = 0; i < M; i++) {
		int A, B;
		ll Y;
		cin >> A >> B >> Y;
		A--; B--;
		edge.emplace_back(Y, P(A, B));
	}
	sort(edge.begin(), edge.end());
	UnionFind U(N, X);
	for (int i = 0; i < M; i++) {
		G[edge[i].second.first].emplace_back(edge[i].second.second, i);
		G[edge[i].second.second].emplace_back(edge[i].second.first, i);
	}
	for (int i = 0; i < M; i++) {
		E e = edge[i];
		U.unite(e.second.first, e.second.second);
		int v = U.find(e.second.first);
		if (U.weight[v] >= e.first) use[i] = 2;
	}
	for (int i = M - 1; i >= 0; i--) {
		E e = edge[i];
		if (use[i] == 1 || use[i] == 0) continue;
		dfs(e.second.first, e.first);
	}
	int ans = M;
	for (int i = 0; i < M; i++) {
		if (use[i]) ans--;
	}
	cout << ans << endl;
}

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

#define int long long int 

int32_t main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=1;i<=n;i++)
  {
    cin>>a[i-1];
    a[i-1]-=i;
  }
  sort(a,a+n);
  int ans=0;
  for(auto i:a)
  ans+=abs(i-a[n/2]);
  cout<<ans<<endl;
}

Measured memory_bytes: 5100
sub f{my$r=my$s=$v[$_]=1;my$p=$h[my$c=$c[$_-1]-1];$v[$_]or$a[$c]-=-$s*(-$s+($s=($r+=f())-$h[$c]+$p))for@$_;$a[$c]+=($p+$r-$h[$c])*(@a-($h[$c]=$p+$r))+1;$r}$_=@a=(0)x<>;@c=glob<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f;print"@a"

Measured memory_bytes: 506760
import sys
N,M=map(int, raw_input().split())

NG=[ 0 for i in range(N+1) ]
for i in range(M):
	a=int( sys.stdin.readline().strip() )
	NG[a]=1

dp=[ 0 for i in range(N+1) ]
dp[0]=1

mod=10**9+7

for i in range(N):
	if i+1<=N and NG[i+1]==0:
		dp[i+1]+=dp[i]
		dp[i+1]%=mod
	if  i+2<=N and NG[i+2]==0:
		dp[i+2]+=dp[i]
		dp[i+2]%=mod

print dp[N]%mod


Measured memory_bytes: 34284
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


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 = 1000000007



def sieve(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


n = I()
primes = sieve(n)
prime_num = len(primes)
L = prime_num * [0]
for i in range(prime_num):
    ret = primes[i]
    while ret <= n:
        L[i] += n // ret
        ret *= primes[i]


ans = 1
for j in range(prime_num):
    ans = ans * (L[j] + 1) % mod



print(ans)

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vector<string> W(N);
    rep(i, N) cin >> W[i];
    unordered_map<string, int> um;

    bool flg = true;
    rep(i, N){
        if(um[W[i]] == 0) um[W[i]]++;
        else flg = false;
    }
    rep(i, N-1){
        if(W[i][W[i].size()-1] != W[i+1][0]) flg = false;
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" <<endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mk make_pair
#define ll long long



signed main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    //freopen("../in.txt", "r", stdin);
    //freopen("../out.txt", "w", stdout);
    int n;
    cin>>n;
    cout<<n*n*n<<endl;  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    long i = 100000;
    long j,n;
    scanf("%ld",&n);
    for(j = n;j > 0;j--){
        i = i + i * 0.05;
        if(i % 1000 == 0){
        }
        else{
            i = i / 1000;
            i = i * 1000 + 1000;
        }
    }
    printf("%ld\n",i);
    return 0;
}

Measured memory_bytes: 592
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    def dfs(i,k):
        if i == d:
            l.append(k)
        else:
            for j in range(2):
                dfs(i+1,k+[j])
    d,g = LI()
    p = LIR(d)
    ans = float("inf")
    l = []
    dfs(0,[])
    for k in l:
        m = 0
        o = 0
        q = [[p[i][0],p[i][1]] for i in range(d)]
        for i in range(d):
            if k[i]:
                o += q[i][0]
                m += q[i][0]*(i+1)*100+q[i][1]
                q[i][0] = 0
        while m < g:
            for i in range(d)[::-1]:
                for j in range(q[i][0]):
                    m += (i+1)*100
                    o += 1
                    if m >= g:break
                if m >= g:break
        ans = min(ans,o)
    print(ans)
#D
def D():
    s = S()
    n = len(s)
    dp = [[0,0,0,0] for i in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        if s[i] == "?":
            dp[i+1] = [3*dp[i][0]%mod,3*dp[i][1]%mod,3*dp[i][2]%mod,3*dp[i][3]%mod]
        else:
            dp[i+1] = [dp[i][0],dp[i][1],dp[i][2],dp[i][3]]
        if s[i] == "A":
            dp[i+1][1] += dp[i][0]
            dp[i+1][1] %= mod
        elif s[i] == "B":
            dp[i+1][2] += dp[i][1]
            dp[i+1][2] %= mod
        elif s[i] == "C":
            dp[i+1][3] += dp[i][2]
            dp[i+1][3] %= mod
        else:
            dp[i+1][1] += dp[i][0]
            dp[i+1][2] += dp[i][1]
            dp[i+1][3] += dp[i][2]
            dp[i+1][1] %= mod
            dp[i+1][2] %= mod
            dp[i+1][3] %= mod
    print(dp[n][3])
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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


Measured memory_bytes: 63228
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      String s = sc.next();
      if(s.equals("-")){
        break;
      }
      int m = Integer.parseInt(sc.next());
      for(int i = 0; i < m; i++){
        int x = Integer.parseInt(sc.next());
        String s1 = s.substring(0, x);
        String s2 = s.substring(x);
        s = s2 + s1;
      }
      System.out.printf("%s\n", s);
    }
  }
}


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

using ll = long long;

map <string, int> m;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i=1; i<=n; i++) {
		string s;
		cin >> s;
		m[s] ++;
	}
	int ans = 0;
	for (auto i:m) {
		ans ++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 19204
import java.util.Scanner;

class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max = 0;
    int sum = 0;
    while(sc.hasNext()){
      int newone = sc.nextInt();
      if(newone > max){
        max = newone;
      }
      sum = sum + newone;
    }
    sum = sum - max;
    System.out.println(max < sum ? "Yes" : "No");
  }
}


Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		if(S<=W) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 35772
#include<bits/stdc++.h>
using namespace std;
struct monster
{
	int x, h;
}mon[200005];
long long dat[200005 << 2];
long long cov[200005 << 2];
long long int d, a;
long long int n;
void pushup(long long int p)
{
	dat[p] = dat[p << 1] + dat[p << 1 | 1]; 
}
void pushdown(long long int p,long long int l, long long int r)
{
	if(cov[p])
	{
		long long int mid = l + r >> 1;
		dat[p << 1] -= cov[p] * (mid - l + 1);
		dat[p << 1 | 1] -= (r - mid) * cov[p];
		cov[p << 1] += cov[p];
		cov[p << 1 | 1] += cov[p];
		cov[p] = 0;
	}
}
long long int ask(long long int p, long long int l,long long int r, int x)
{
	if(l == r) return dat[p];
	pushdown(p, l, r);
	long long int mid = l + r >> 1;
	if(mid >= x) return ask(p << 1, l, mid, x);
	else return ask(p << 1 | 1, mid + 1, r, x);
}
void change(long long int p,long long int l,long long int r,long long int ql,long long int qr,long long int x)
{
	if(ql <= l && r <= qr)
	{
		dat[p] -= (l - r + 1) * x;
		cov[p] += x;
		return;
	}
	pushdown(p, l, r);
	long long int mid = l + r >> 1;
	if(mid >= ql) change(p << 1, l, mid, ql, qr, x);
	if(mid < qr) change(p << 1 | 1, mid + 1, r, ql, qr, x);
	pushup(p);
}
void build(long long int p ,long long int l,long long int r)
{
	dat[p] = cov[p] = 0;
	if(l == r)
	{
		dat[p] = mon[l].h;
		return;
	}
	long long int mid = l + r >> 1;
	build(p << 1, l, mid);
	build(p << 1 | 1, mid + 1, r);
	pushup(p);
}
bool cmp(monster x, monster y)
{
	return x.x < y.x;
}
int main()
{
	long long int l, r;
	long long int ql, qr;
	long long int ans = 0;
	int j = 1;
	cin >> n >> d >> a;
	for(int i = 1; i <= n; i++)
	{
		cin >> mon[i].x >> mon[i].h;
		if(mon[i].h % a)
			mon[i].h = mon[i].h / a + 1;
		else
			mon[i].h = mon[i].h / a;
	}
	sort(mon + 1, mon + n + 1, cmp); 
	build(1, 1, n);
	for(int i = 1; i <= n; i++)
	{
		long long int tmp = ask(1, 1, n, i);
		if(tmp > 0)
		{
			l = mon[i].x;
			r = mon[i].x + 2 * d;
			ql = i;
			for(j--; j <= n &&mon[j].x <= r ; j++)
				qr = j;
			change(1, 1, n, ql, qr, tmp); 
			ans += tmp;
		}
	}
	cout << ans << endl;
	return 0;
}  

Measured memory_bytes: 14080
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = MI()
A = [0] + LI()

for i in range(K+1,N+1):
    if A[i] > A[i-K]:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 94048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 0; i < s.length(); i++)if (s.at(i) == 'x')ans++;
	if (ans <= 7)cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main(){
  int m,n;
  int s,y;

  cin >> m;
  while(m--){
    cin >> s >> y >> n;
    
    int ans = s;
    for(int i=0;i<n;i++){
      int sisan=s, rishi=0;
      int type, tesu;
      double ratio;

      cin >> type >> ratio >> tesu;

      for(int i=0;i<y;i++){
	int gain = (int)((double)sisan * ratio);
	if(type == 0)rishi += gain;
	else sisan += gain;
	sisan -= tesu;
      }

      ans = max(ans, sisan + rishi);
    }
    cout << ans << endl;
  }
}

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

int main()
{
	string s; long long k;
	cin >> s >> k;
	for (int i = 0; i < min((long long)s.size(),k); i++) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << '1' << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

const int MAX_N = 100010;
ll K[MAX_N+1];
ll inv[MAX_N+1];

ll memo[2010][2010];

ll mul(ll _a, ll _b) {
  if (_b == 0) return 1LL;
  if (_b == 1) return _a;
  ll ans = mul(_a, _b/2);
  ans *= ans;
  ans %= MOD;
  if (_b&1) ans *= _a;
  return ans % MOD;
}

ll C(ll _n, ll _k) {
  if (_n == _k) return 1;
  if (_k == 0) return 1;
  return (K[_n] * ((inv[_k] * inv[_n-_k]) % MOD)) % MOD;
}

void init() {
  K[1] = 1;
  inv[1] = 1;
  inv[0] = 1;
  for (ll i = 2; i <= MAX_N; i++) {
    K[i] = K[i-1]*i;
    K[i] %= MOD;
    inv[i] = mul(K[i], MOD-2);
  }
  for (int i = 1; i < 2010; i++) {
    for (int j = 1; j <= i; j++) {
      if (j == 1 || j == i) memo[i][j] = 1;
      else {
        memo[i][j] = memo[i-1][j-1] + memo[i-1][j];
        memo[i][j] %= MOD;
      }
    }
  }
}

void solve() {
  init();
  ll n,k;
  cin >> n >> k;
  ll m = n - k + 1;
  for (ll i = 1; i <= k; i++) {
    if (m < i) {
      cout << 0 << endl;
      continue;
    }
    ll ans = C(m,i);
    ans *= memo[k][i];
    ans %= MOD;
    cout << ans << endl;
  }
  // REP(i,k+1) {
  //   REP(j,k+1) {
  //     cout << pat(i,j) << " ";
  //   }
  //   cout << endl;
  // }
}

int main(int argc, char *argv[]){

  /* Regular */
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }
  
  // /* AOJ */
  // solve();
  return 0;
}

Measured memory_bytes: 31872
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

string amida[40];

int main() {
	int n,m,s,d;
	while(n=in()){
		cin>>m>>s>>d;
		int i;
		m--;s--;
		for(i=0;i<d;i++)cin>>amida[i];
		for(i=d-1;i>=0;i--){
//cout<<"i "<<i<<endl;
//cout<<"s "<<s<<endl;
//cout<<endl;
			if(amida[i][s]=='1'){
				s++;
			}else if(0<s&&amida[i][s-1]=='1'){
				s--;
			}
		}
		if(m==s){
			cout<<0<<endl;
			continue;
		}
		for(i=0;i<d;i++){
//cout<<"i "<<i<<endl;
//cout<<"s "<<s<<endl;
//cout<<"m "<<m<<endl;
//cout<<endl;
			if(amida[i][s]=='1'){
				s++;
			}else if(0<s&&amida[i][s-1]=='1'){
				s--;
			}
			if(amida[i][m]=='1'){
				m++;
			}else if(0<m&&amida[i][m-1]=='1'){
				m--;
			}
			if(s==m-1){
				if((s==0||amida[i][s-1]=='0')&&(s>=n-1||amida[i][s]=='0')&&(s>=n-2||amida[i][s+1]=='0')){
					cout<<i+1<<" "<<s+1<<endl;
					break;
				}
			}
			if(s==m+1){
				if((m==0||amida[i][m-1]=='0')&&(m>=n-1||amida[i][m]=='0')&&(m>=n-2||amida[i][m+1]=='0')){
					cout<<i+1<<" "<<m+1<<endl;
					break;
				}
			}
		}
		if(i==d)cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }

  vector<long long> count(N,0);
  for(auto i : A){
    count.at(i-1)++;
  }

  long long tmp_ans=0;
  vector<long long> pat(N,0);
  for(int i=0;i<N;i++){
    pat.at(i)=count.at(i)*(count.at(i)-1)/2;
    tmp_ans+=pat.at(i);
  }

  long long cp_ans;
  long long tmp;
  for(int i=0;i<N;i++){
    cp_ans=tmp_ans-(count.at(A.at(i)-1)-1);
    cout << cp_ans << endl;
  }
  
  return 0;
}


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

int x;

int main() {
  cin >> x;
  if (x >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3616
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define sz(a)  int((a).size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define CLR(a) memset((a), 0, sizeof(a))
#define INF (1 << 31) - 1
const int dh[8] = {-1, 1, 0, 0,1,1,-1,-1};
const int dw[8] = {0, 0, 1, -1,1,-1,1,-1};
typedef long long ll;
typedef pair<int, int> p;
typedef vector <int> VI;
typedef vector <string> VS;

int table[41][401][401];

int main(){

	int n,ma,mb;
	cin >> n;
	cin >> ma;
	cin >> mb;

	for(int a = 0; a < 401; a++){
		for(int b = 0; b < 401; b++){
			table[0][a][b] = -1;
		}
	}
	table[0][0][0] = 0;
	
	for(int ni = 1; ni <= n; ni++){
		int tempa,tempb,tempc;
		cin >> tempa;
		cin >> tempb;		
		cin >> tempc;
				
		for(int a = 0; a < 401; a++){
			for(int b = 0; b < 401; b++){
				if(a < tempa || b < tempb){
					table[ni][a][b] = table[ni - 1][a][b];
				}else if(table[ni - 1][a - tempa][b - tempb] == -1){
					if(table[ni - 1][a][b] != -1) {
						table[ni][a][b] = table[ni - 1][a][b];
					}else{
						table[ni][a][b] = -1;
					}					
				}else if(table[ni - 1][a][b] == -1){
					table[ni][a][b] = table[ni - 1][a - tempa][b - tempb] + tempc;			
				}else{
					table[ni][a][b] = min(table[ni-1][a][b], 
					table[ni - 1][a - tempa][b - tempb] + tempc);					
				}
			}
		}		
	}

	int r = 1;
	int ans = 5000;
	while(1){
		int ra = r * ma;
		int rb = r * mb;
		
		if(ra > 400 || rb > 400) break;		
		if(table[n][ra][rb] != -1){
			ans = min(ans, table[n][ra][rb]);
		}
		r++;
	}

	if(ans == 5000) cout << "-1" << endl;
	else cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 25984
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    int x,n;
    cin >> x >> n;
    vector<bool> p(102, false);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        p[a] = true;
    }
    int minnum=101, maxnum=-1;
    for(int i=x; i<=100; i++){
        if(!p[i]){
            maxnum = i;
            break;
        }
    }
    for(int i=x; i>=0; i--){
        if(!p[i]){
            minnum = i;
            break;
        }
    }
    if(maxnum == -1) maxnum=101;
    if(minnum == 101) minnum=-1;
    if(x-minnum <= maxnum-x){
        cout << minnum << endl;
    }else{
        cout << maxnum << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
map<ll, int> prime_factor(ll n)
{
    map<ll, int> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] = 1;
    }
    return res;
}

int main()
{
    int X;
    cin >> X;
    if(X<4)
    {
        cout<<1;
        return 0;
    }
    int ans = 0;
    for (size_t b = X; b >= 2; b--)
    {
        for (size_t p = 2; pow(b, p) <= X; p++)
        {
            chmax(ans, (int)pow(b, p));
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    R = int(input())
    G = int(input())
    print(2 * G - R)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
// 0117
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#define  N    10000000
using namespace std;

struct road{
	int v;
	int cost;
};

int com_min(int x, int y, vector<vector<road> > town){
	vector<int> c;

	for(int i=0;i<=town.size();i++)
		if(i == x)
			c.push_back(0);
		else
			c.push_back(N);

	queue<int> ver;
	ver.push(x);

	while(!ver.empty()){
		int f = ver.front();
		for(int i=0;i<town[f].size();i++)
			if(c[town[f][i].v] > c[f] + town[f][i].cost){
				c[town[f][i].v] = c[f] + town[f][i].cost;
				ver.push(town[f][i].v);
			}
		ver.pop();
	}

	return c[y];
}

int main(){
	int n, m, a, b, c, d;
	vector<vector<road> > town;
	road r;

	cin>>n;
	town.resize(n+1);

	cin>>m;
	for(int i=0;i<m;i++){
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);

		r.v = b;
		r.cost = c;
		town[a].push_back(r);
		r.v = a;
		r.cost = d;
		town[b].push_back(r);
	}

	int x1, x2, y1, y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);

	cout<<y1-y2-com_min(x1, x2, town)-com_min(x2, x1, town)<<endl;

	return 0;
}

Measured memory_bytes: 1276
n=int(input())
t1,a1=map(int,input().split())
for i in range(1,n):
  t,a=map(int,input().split())
  if t1%t==0:
    kt=t1//t
  else:
    kt=t1//t+1
  if a1%a==0:
    ka=a1//a
  else:
    ka=a1//a+1
  k=max(kt,ka)
  t1=k*t
  a1=k*a
print(t1+a1)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>
#include<string>

using namespace std;

queue<pair<string, int>> tasks;

int main()
{
	int taskam, q;
	cin >> taskam >> q;
	for (int i = 0; i < taskam; ++i) {
		string name;
		int thistask;
		cin >> name >> thistask;
		tasks.push(make_pair(name, thistask));
	}
	int time = 0;
	while (!tasks.empty()) {
		int tmpt = tasks.front().second;
		string tmpname = tasks.front().first;
		tasks.pop();
		int n = tmpt - q;
		if (n > 0) {
			tasks.push(make_pair(tmpname, n));
			time += q;
		}
		else {
			time += tmpt;
			cout << tmpname << " " << time << endl;
		}
	}
}

Measured memory_bytes: 4408
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author yousack
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();

        for (int i = 0; i < N; i++) {
            System.out.println(solve(in.next()));
        }
    }
    
    public static String solve(String s) {
        char[][] table = new char[][] {
                {},
                {'.', ',', '!', '?', ' '},
                {'a', 'b', 'c'},
                {'d', 'e', 'f'},
                {'g', 'h', 'i'},
                {'j', 'k', 'l'},
                {'m', 'n', 'o'},
                {'p', 'q', 'r', 's'},
                {'t', 'u', 'v'},
                {'w', 'x', 'y', 'z'}
        };
        
        String result = "";
        List<Character> feed = new ArrayList<Character>();
        
        for (char c : s.toCharArray()) {
            if (c != '0') {
                feed.add(c);
            } else {
                if (!feed.isEmpty()) {
                    int num = Integer.parseInt(feed.get(0).toString());
                    result += table[num][(feed.size() - 1) % table[num].length];
                }
                
                feed.clear();
            }
        }
        
        return result;
    }
}

Measured memory_bytes: 27996
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()


int main(){
    int n,k; cin>>n>>k;
    vector<int> h; rep(i,n){ int hh; cin>>hh; h.push_back(hh); }
    sort(all(h)); int ans = INT_MAX;
    rep(i, n-k+1) ans = min(ans, h[i+k-1] - h[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 892
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
n = int(input())
XY = [tuple(map(int, input().split())) for _ in range(n)]
X, Y = zip(*XY)
L_to_R = sorted([(x, i) for i, x in enumerate(X)])
D_to_U = sorted([(y, i) for i, y in enumerate(Y)])
dist = []
for i in range(n-1):
  x1, num1 = L_to_R[i]
  x2, num2 = L_to_R[i+1]
  d = x2-x1
  dist.append((d, num1, num2))
for i in range(n-1):
  y1, num1 = D_to_U[i]
  y2, num2 = D_to_U[i+1]
  d = y2-y1
  dist.append((d, num1, num2))
dist.sort(reverse=True)  
  
uf = UnionFind(n)
count = 0
ans = 0
while count < n-1:
  d, num1, num2 = dist.pop()
  if uf.same(num1, num2):
    continue
  count += 1
  ans += d
  uf.unite(num1, num2)
print(ans)

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

int main(){
  ll n,m;  cin >> n >> m;
  priority_queue<int> a;
  int b;
  rep(i,n){
      cin >> b;
      a.push(b);
      }

  for(int i=0;i<m;i++){
     
     b=a.top()/2;
     a.push(b);
     a.pop();
  }
  ll all = 0;

  while(!a.empty()){
     all += a.top();
     a.pop();
  }
  cout << all << endl;
}



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

using namespace std;

int main()
{
    int N,sum=0;
    long long x,y,len,D;
    cin>>N>>D;
    while(N--)
    {
        scanf("%lld %lld",&x,&y);
        len=x*x+y*y;
        if(len<=D*D)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>


int main() {
    int n ;
    scanf("%d", &n);
    switch (n%10)
    {
    case 3:
        puts("bon");
        break;
    case 0:
    case 1:
    case 6:
    case 8: 
        puts("pon");
        break;      
    
    default:
        puts("hon");
        break;
    }
     
    
}

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

int main() {
  
  string S;
  cin >> S;
  if((S.at(2)==S.at(3))&&(S.at(4)==S.at(5))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
N,M = (int(i) for i in input().split())
A = [[int(i) for i in input().split()] for j in range(N)]

ans_List = [1 for i in range(M)]
for i in range(N):
    for j in range(M):
        if j+1 not in A[i][1:]:
            ans_List[j] = 0
ans = 0
for i in ans_List:
    ans += i

print(ans)


Measured memory_bytes: 3064
n = int(input())
an = [input() for _ in range(n)]
a =[]
for c in "SHCD":
    for i in range(1, 14):
        card = "{} {}".format(c, i)
        if card not in an:
            a.append(card)

if n != 52:
    print("\n".join(a))


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  int c=abs(x-a);
  int d = abs(x-b);
  if(c<d)
     cout<<"A"<<endl;
  else if(c>d)
     cout<<"B"<<endl;
}

Measured memory_bytes: 3488
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
 
#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define rrep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

 
int main(void){
  
  //vector<vector<char>> maze(h, vector<char>(w));
  //vector<vector<ll>> warp(h, vector<ll>(w, INF));
  
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll res=0;
  ll su = 0;
  
  rep(i,n){
    ll e;
    cin >> e;
    a.at(i) = e;
    su += e;
  }
  
  rep(i,n-1){
    ll k = a.at(i);
    su -= k;
    res += (su%MOD*k%MOD)%MOD;
  }
  
  cout << res%MOD << endl;
}


Measured memory_bytes: 4792
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

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

	ll ans[2];	
	for(ll i=-1000;i<=1000;i++){
		for(ll j=i; j<=1000; j++){
			if(j*j*j*j*j - i*i*i*i*i==x){
				ans[0] = j;
				ans[1] = i;
				break;
			}
		}
	}
	cout << ans[0] << " " << ans[1] << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3620
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int memo[100050];


void dp() {
	memo[1] = 1;
	for (int i = 2; i < 100001; i++) {
		if (memo[i] > memo[i-1] + 1) {
			memo[i] = memo[i-1] + 1;
		}
		for (int j = 6; j <= i; j *= 6) {
			if (memo[i] > memo[i-j] + 1) {
				memo[i] = memo[i-j] + 1;
			}
		}
		for (int j = 9; j <= i; j *= 9) {
			if (memo[i] > memo[i-j] + 1) {
				memo[i] = memo[i-j] + 1;
			}
		}
	}
}

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	for (int i = 0; i < 100050; i++) {
		memo[i] = 100000;
	}

	memo[0] = 0;
	dp();
	cout << memo[n] << endl;

	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if S[2] == S[3] and S[4] == S[5]:
        print(YES)
    else: print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str

    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N = gets.to_i
S = gets.chomp.split("")

slimes = Array.new()
S.each.with_index do |slime, i|
  if i == 0
    next
  end

  if S[i] == S[i - 1]
    next
  else
    slimes << S[i - 1]
  end
end
slimes << S.pop
answer = slimes.length
puts answer


Measured memory_bytes: 7804
n,m=map(int,input().split())
s=str(input())
s=list(s)
t=str(input())
t=list(t)
ans=-1
if s[0]==t[0]:
  import fractions
  temp=len(s)*len(t)//fractions.gcd(len(s),len(t))
  k=fractions.gcd(len(s),len(t))
  count=1
  for i in range(1,k):
    if s[i*int(len(s)/k)]==t[i*int(len(t)/k)]:
      count=count+1
  if count==k:
    ans=temp
print(ans)


Measured memory_bytes: 6428
#include<stdio.h>

int main(){
    int a[3][3];
    for (int i=0; i<3; ++i){
        for (int j=0; j<3; ++j){
            scanf("%d", &a[i][j]);
        }
    }
    int n;
    scanf("%d", &n);
    int l0=0, l1=0, l2=0, c0=0, c1=0, c2=0, d0=0, d1=0;
    int b;
    for (int k=0; k<n; ++k){
        scanf("%d", &b);
        if (a[0][0]==b){
            ++l0;
            ++c0;
            ++d0;
        }if (a[0][1]==b){
            ++l0;
            ++c1;
        }if(a[0][2]==b){
            ++l0;
            ++c2;
            ++d1;
        }if (a[1][0]==b){
            ++l1;
            ++c0;
        }if (a[1][1]==b){
            ++l1;
            ++c1;
            ++d0;
            ++d1;
        }if (a[1][2]==b){
            ++l1;
            ++c2;
        }if (a[2][0]==b){
            ++l2;
            ++c0;
            ++d1;
        }if (a[2][1]==b){
            ++l2;
            ++c1;
        }if (a[2][2]==b){
            ++l2;
            ++c2;
            ++d0;
        }
    }
    if (l0>=3 || l1>=3 || l2>=3 || c0>=3 || c1>=3 || c2>=3 || d0>=3 || d1>=3){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll unsigned long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
#define int long long
vector<int>g[2005];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, y, a, b,c;
    cin >> x >> y >> a >> b >> c;
    vector<pair<int,int>>v;
    f(a) {
        int x;
        cin >> x;
        v.pb({x,0});
    }
    f(b) {
        int x;
        cin >> x;
        v.pb({x,1});
    }
    f(c) {
        int x;
        cin >> x;
        v.pb({x,2});
    }
    ll sum = 0;
    sort(v.rbegin(),v.rend());
    ll rem = x + y;
    ll res = 0;
    for (auto i:v) {
        if (i.S == 0) {
            if (x) {
                x--;
                sum += i.F;
                rem--;
            }
        }
        else if(i.S == 1) {
            if (y) {
                y--;
                sum += i.F;
                rem--;
            }
        }
        else {
            sum += i.F;
            res++;
        }
        if (rem == res) {
            break;
        }
    }
    cout << sum << '\n';
}


Measured memory_bytes: 10604
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(long long X) {
  ANS((X / 500) * 1000 + (((X % 500) / 5) * 5));
}

// clang-format off
int main() {
  long long X;
  scanf("%lld",&X);
  solve(X);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <iostream>

using namespace std;
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
typedef long long ll;
const int maxn=100200,P=1000000007;
int n;
int a[maxn];

int main() {
	//freopen("a.in","r",stdin);
	scanf("%d\n",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	ll ans=1,cnt=1;
	rep(i,1,n) {
		if (a[i]>=2*cnt-1) {
			ans=(ans*cnt)%P;
			cnt++;
		} else {
			ans=(ans*cnt)%P;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640