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

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());
        Integer[] A = new Integer[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(scanner.next());
        }

        Combination comb = new Combination(100_000, MOD);

        long total = 0;
        Arrays.sort(A, (x, y) -> y - x);
        for (int i = 0; N - i >= K; i++) {
            long n = A[i];
            long c = comb.kFromN(K - 1, N - i - 1);
            total += ((n * c) % MOD);
            total %= MOD;
        }

        Arrays.sort(A);
        for (int i = 0; N - i >= K; i++) {
            long n = A[i];
            long c = comb.kFromN(K - 1, N - i - 1);
            total -= ((n * c) % MOD);
            total += MOD;
            total %= MOD;
        }

        System.out.println(total);
    }
}

class Combination {

    private final int MOD;
    private final int MAX;

    private final long[] fac, facInv, inv;

    public Combination(int max, int mod) {
        this.MAX = max + 1;
        this.MOD = mod;
        fac = new long[MAX];
        facInv = new long[MAX];
        inv = new long[MAX];

        fac[0] = fac[1] = 1;
        facInv[0] = facInv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            facInv[i] = facInv[i - 1] * inv[i] % MOD;
        }
    }

    public long kFromN(int k, int n) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (facInv[k] * facInv[n - k] % MOD) % MOD;
    }
}



Measured memory_bytes: 47704
/*
* @author:  codancer
* @createTime:  2020-02-22, 20:05:28
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
int main(){
	int n;
	cin>>n;
	vector<int> x(n+1);
	for(int i=1;i<=n;i++){
		cin>>x[i];
	}
	int ans=1e9;
	for(int i=1;i<=100;i++){
		int now=0;
		for(int j=1;j<=n;j++){
			now+=(x[j]-i)*(x[j]-i);
		}
		ans=min(ans,now);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A, B = map(int, input().split(" "))
P = list(map(int, input().split(" ")))

x = [a for a in P if a <= A]
y = [a for a in P if (a > A)and(a <= B)]
z = [a for a in P if (a > B)]

r = min(len(x), len(y), len(z))

print(r)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;
struct custom_hash 
{
    static unsigned long long splitmix64(unsigned long long x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const 
    {
        static const unsigned long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
mt19937 random_generator(chrono::steady_clock::now().time_since_epoch().count());

int n, m, x; 
int t[15][15];
int c[15];
void read()
{
	cin >> n >> m >> x;
	for (int i = 1; i <= n; i++)
	{
		cin >> c[i];
		
		for (int j = 1; j <= m; j++)
	    cin >> t[i][j];
	}  
}

void solve()
{
	int min_cost = INT_MAX; 
	for (int i = 0; i < (1 << n); i++)
	{
		int o[15];
		memset(o, 0, sizeof(o));
		
		int curr_cost = 0; 
		for (int j = 1; j <= n; j++)
		if (i & (1 << (j - 1)))
		{
			curr_cost += c[j];
			
			for (int p = 1; p <= m; p++)
			o[p] += t[j][p];
		} 
		
		bool can = true;
		for (int j = 1; j <= m; j++)
		if (o[j] < x)
		{
			can = false;
			break;
	    }
	    
	    if (can)
	    min_cost = min(min_cost, curr_cost);
	}
	
	if (min_cost == INT_MAX)
	cout << -1 << endl;
	
	else 
	cout << min_cost << endl; 
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	read();
	solve();
}


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

//Nは桁数が大きい場合があるので文字列として受け取る
string N;
int K;
vector<int> n;  //Nの各桁の数字を格納するベクター
int dp[200][2][200];

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

    //ベクターnを構成
    for(auto a : N){
        n.push_back(a-'0');
    }
    int l = N.size();  //nの長さ

    dp[0][0][0] = 1;  //初期条件。他は0で初期化されている
    for(int i = 0; i < l; i++){
        for(int smaller = 0; smaller < 2; smaller++){
            for(int j = 0; j <= 3; j++){
                for(int x = 0; x <= (smaller ? 9 : n[i]); x++){
                    if(x != 0){
                        dp[i + 1][smaller || x < n[i]][j+1] += dp[i][smaller][j];     
                    }
                    else{
                        dp[i + 1][smaller || x < n[i]][j] += dp[i][smaller][j];          
                    }
                    
                }
            }
        }
    }
    ll ans = dp[l][0][K] + dp[l][1][K];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

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

int main() {
	int K;
	cin >> K;
	ll ans = 0;
	FOR(i, 1, K + 1) FOR(j, 1, K + 1) FOR(k, 1, K + 1) ans += gcd(i, gcd(j, k));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
int a[2][maxn],x[maxn];
int main(){
    #ifdef DanDan
    freopen("in.txt","r",stdin);
    #endif // DanDan
    int n;scanf("%d",&n);
    int odd=0,even=0,ox,ex;
    for(int i=1;i<=n;i++){
        scanf("%d",&x[i]);
        if(i%2){
            if(odd<++a[0][x[i]]){
                odd=a[0][x[i]];
                ox=x[i];
            }
        }
        else {
            if(even<++a[1][x[i]]){
                even=a[1][x[i]];
                ex=x[i];
            }
        }
    }
    int co=0,ce=0,ans=0;
    for(int i=0;i<maxn;i++){
        if(i!=ox)co=max(co,a[0][i]);
        if(i!=ex)ce=max(ce,a[1][i]);
    }
//    cout<<"ox="<<ox<<" ex="<<ex<<" co="<<co<<" ce="<<ce<<" odd="<<odd<<" even="<<even<<endl;
    if(ox!=ex)ans=n-odd-even;
    else ans=min(n-odd-ce,n-co-even);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, x, y = MI()

    ans = [0] * (n-1)
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            # print(i, j)
            d = min(j - i, abs(i - x) + 1 + abs(y - j))
            ans[d-1] += 1
    # print(ans)
    for a in ans:
        print(a)


if __name__ == '__main__':
    solve()


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

using namespace std;

#define LL long long
#define N 300000
#define INF 0x3f3f3f3f3f3f3f3fLL

LL n,m,tot,x[N],y[N],z[N],f[N][2],g[N][2],mn,mx,head[N];
struct edge{LL v,l,nxt;}e[N];

void add(LL x,LL y,LL z){
	e[++tot].v=y; e[tot].l=z; e[tot].nxt=head[x]; head[x]=tot;
}

void dfs(LL u){
	for (LL i=head[u],v;i;i=e[i].nxt){
		v=e[i].v;
		if (f[u][0]){
			if (!g[v][0]){g[v][0]=1; g[v][1]=e[i].l-f[u][1]; dfs(v);}
			else if (g[v][1]!=e[i].l-f[u][1]){puts("0"); exit(0);}
		}
		if (g[u][0]){
			if (!f[v][0]){f[v][0]=1; f[v][1]=e[i].l-g[u][1]; dfs(v);}
			else if (f[v][1]!=e[i].l-g[u][1]){puts("0"); exit(0);}
		}
	}
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=m;++i){
		scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);
		add(x[i],y[i],z[i]); add(y[i],x[i],z[i]);
	}
	f[1][0]=1; f[1][1]=0;
	dfs(1);
	if (f[1][0]&&g[1][0]){
		LL t=g[1][1]-f[1][1];
		if (t&1){puts("0"); return 0;}
		for (LL i=1;i<=n;++i)
			if (f[i][1]+t/2<=0||g[i][1]-t/2<=0||f[i][1]+t/2!=g[i][1]-t/2){puts("0"); return 0;}
		for (LL i=1;i<=m;++i)
			if (f[x[i]][1]+f[y[i]][1]+t!=z[i]){puts("0"); return 0;}
		puts("1"); return 0;
	}
	mn=1; mx=INF;
	for (LL i=1;i<=n;++i)
		if (f[i][0]) mn=max(mn,1-f[i][1]);
		else mx=min(mx,g[i][1]-1);
	printf("%lld\n",mx>=mn?mx-mn+1:0);
	
	return 0;
}
			

Measured memory_bytes: 28672
s = input()[::-1]
n = len(s)
amari = [0]*2019
amari[0] = 1

temp = 0
d = 1
for char in s:
    temp += int(char)*d
    temp %= 2019
    d *= 10
    d %= 2019  
    amari[temp] += 1

ans = 0
for i in amari:
    ans += i*(i-1)/2

print(int(ans))



Measured memory_bytes: 9208
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    int n;cin >> n;
    vector<int>a(n);
    for(int i = 0;i<n;i++) cin >> a[i];
    multiset<int>s;
    int ans = 1;s.insert(a[0]);
    for(int i = 1;i<n;i++){
        auto it = s.lower_bound(a[i]);
        if(it==s.begin()) s.insert(a[i]);
        else{
            it = prev(it);
            s.erase(it);
            s.insert(a[i]);
        }
    }
    cout << s.size();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 8276
#include <stdio.h>
#include <algorithm>
int x, y, a, b, c;
int aa, bb, cc;
int fa, fb, fc;
long long ans;
long long p[100001];
long long q[100001];
long long r[100001];
int main() {
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	for (int i = 0; i < a; i++) {
		scanf("%lld", p + i + 1);
	}
	for (int i = 0; i < b; i++) {
		scanf("%lld", q + i + 1);
	}
	for (int i = 0; i < c; i++) {
		scanf("%lld", r + i + 1);
	}
	p[0] = -1;
	q[0] = -1;
	r[0] = -1;
	std::sort(p, p + a + 1);
	std::sort(q, q + b + 1);
	std::sort(r, r + c + 1);
	aa = a; bb = b; cc = c;
	while (1) {
		if (x + y == fa + fb + fc)break;
		if (p[aa] >= q[bb] && p[aa] > r[cc]) {
			if (fa < x) {
				fa++;
				ans += p[aa];
				aa--;
			}
			else aa--;
			continue;
		}
		if (q[bb] > p[aa] && q[bb] > r[cc]) {
			if (fb < y) {
				fb++;
				ans += q[bb];
				bb--;
			}
			else bb--;
			continue;
		}
		if (r[cc] >= p[aa] && r[cc] >= q[bb]) {
			fc++;
			ans += r[cc];
			cc--;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(){
	int a[4];
	while(1){
    	for(int i = 0; i < 4; ++i){
        	scanf("%d", &a[i]);
    	}
        if(a[0] == 0){ break; }
        
		for(int i = 0; i < 110000; ++i) putchar('(');
		printf("%d+%d+%d+%d", a[0], a[1], a[2], a[3]);
		for(int i = 0; i < 110000; ++i) putchar(')');
		putchar('\n');
	}
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using ld = long double;
using namespace std;

int dp[10010][100][2];

int main(){
	string k; cin >> k;
	int n = k.l_ength();
	int d; cin >> d;
	dp[0][0][0] = 1;
	for( int i = 0; i < n; ++i ){
		for( int r = 0; r < d; ++r ){
			for( int m = 0; m <= 9; ++m ){
				dp[i+1][(r+m)%d][1] += dp[i][r][1];
				dp[i+1][(r+m)%d][1] %= mod;
			}
		}
		for( int r = 0; r < d; ++r ){
			for( int m = 0; m <= k[i]-'0'; ++m ){
				dp[i+1][(r+m)%d][(int)(m<k[i]-'0')] += dp[i][r][0];
				dp[i+1][(r+m)%d][(int)(m<k[i]-'0')] %= mod;
			}
		}
	}
	cout << ( dp[n][0][0] + dp[n][0][1] + (mod-1) ) % mod << endl;
}

Measured memory_bytes: 8064
#include <iomanip>
#include <iostream>
#include <string.h>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

using namespace std;

typedef double dbl;

const int MAX = 300;

void init();
double rec(int i, int j, int k);

double dp[301][301][301];
int n, c[4];

int main()
{
	init();

	cout << setprecision(15) << rec(c[1], c[2], c[3]) << endl;
}

void init()
{
	memset(dp, -1, sizeof dp);
	memset(c, 0, sizeof c);

	cin >> n;
	REP(_i, n)
	{
		int x; cin >> x;
		c[x]++;
	}
}

double rec(int i, int j, int k)
{
	if (dp[i][j][k] >= 0)
		return dp[i][j][k];

	int s = i + j + k;
	if (!s)
		return dp[i][j][k] = 0.0;

	double ret = 0.0;
	
	if (i > 0) ret += rec(i - 1, j, k) * ((dbl)i / s);
	if (j > 0) ret += rec(i + 1, j - 1, k) * ((dbl)j / s);
	if (k > 0) ret += rec(i, j + 1, k - 1) * ((dbl)k / s);

	ret += ((dbl)n / s);

	return dp[i][j][k] = ret;

}

Measured memory_bytes: 213376
import sys
from itertools import accumulate

def resolve():
        input = sys.stdin.readline
        N=int(input().rstrip())
        #S=input()
        #a=len(S)
        S=list(input().rstrip().replace("W","1").replace("E","0"))

        csum=["0"]+S
        csum=list(map(int,csum))
        csum=list(accumulate(csum))#Wの数
        ans=N
        for i in range(1,N+1,1):
            numWleft=csum[i-1]-csum[0]
            numEright=(N-i)-(csum[N]-csum[i])
            ans=min(ans,numWleft+numEright)
        print(ans)

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
WEEWW"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """12
WEWEWEEEWWWE"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """8
WWWWWEEE"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 24364
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int L;
    cin  >> L;
    
    int N=0,M=0;
    int u[100],v[100],w[100];
    N=1ll+(int)log2(L);
    REP(i,N-1){
        u[M]=i+1;v[M]=i+2;w[M]=0;
        M++;
        u[M]=i+1;v[M]=i+2;w[M]=(int)pow(2,i);
        M++;
    }
    int Tapris=L-(int)pow(2,(N-1));
    //cout << Tapris << endl;
    int En=(int)pow(2,(N-1));
    int q=(int)pow(2,(N-2));
    
    for(int i=N-1;i>=1;i--){
        if((Tapris/q)%2==1){
            u[M]=i;v[M]=N;w[M]=En;
            M++;
            En+=(int)pow(2,i-1);
        }
        q/=2;
    }
    
    cout << N << " "<< M << endl;
    REP(i,M){
        cout << u[i] << " " << v[i] << " " << w[i] << Endl;
    }
    return 0;
}   


Measured memory_bytes: 256
if __name__ == "__main__":
    n = int(input())
    a = map(int, input().split())
    a = list(a)
    zerop = any(map(lambda x: x == 0, a))
    evenp = sum(map(lambda x: 1 if x < 0 else 0, a)) % 2 == 0
    abss = list(map(abs, a))
    ans = 0
    if zerop or evenp:
        ans = sum(abss)
    else:
        m = min(abss)
        i = abss.index(m)
        for j, elm in enumerate(a):
            if j == i:
                ans += -abs(elm)
            else:
                ans += abs(elm)
    print(ans)


Measured memory_bytes: 14412
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int N;
long long K;
cin>>N>>K;
long long s[N+1];
s[0]=0;
long long A[N];
rep(i,N){
    cin>>A[i];
    s[i+1]=s[i]+A[i];
}

queue<int>q;
map<int,int>mp;
long long ans=0;
for(int i=0;i<=N;i++){
    int now=(s[i]-i)%K;
    ans+=mp[now];
    mp[now]++;
    q.push(now);
    if(q.size()==K){
        mp[q.front()]--;
        q.pop(); 
    }
}

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

first 11m38s 2019 11 27

5 4
1 4 2 3 5

4


8 4
4 2 4 2 4 2 4 2

7

10 7
14 15 92 65 35 89 79 32 38 46


8
*/

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

using namespace std;

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

    vector<int> d(N);
    for(int i=0; i<N; i++) cin >> d[i];

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

    int tmp_b = -1;
    int count = 0;
    for(auto & x : d){
        if(tmp_b != x){
            count++;
        }

        tmp_b = x;
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n,k;
  cin >> n>>k;
  vector<int> a(n);
  REP(i, n) { cin >> a[i]; }
  sort(ALL(a));
  ll ans = 0;
  REP(i, k) { ans += a[i]; }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3628
*a,=map(int,open(0).read().split());print('NYoe s'[any(t<=set(a.index(b)for b in a[10:])for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])

Measured memory_bytes: 38296
import sys
n = int(input())

if n == 1:
  print(1)
  sys.exit()
l, r = 0, n*2
while r-l > 1:
  key = (r+l)//2
  if (key)*(key+1)//2 >= n:
    r = key
  else:
    l = key

print(r)

Measured memory_bytes: 2940
#include <stdio.h>

int parentkey(int);
int leftkey(int);
int rightkey(int);

int a[250];

int main(){

  int h;
  int i, j;

  scanf("%d", &h);

  for(i=1; i<=h; i++){
    scanf("%d", &a[i]);
  }
  //print
  for(i=1; i<=h; i++){
    printf("node %d: key = %d, ", i, a[i]);

    if(parentkey(i)>=1){ //rootじゃない時
      printf("parent key = %d, ", a[parentkey(i)]);
    }//rootの時はスルー

    if(leftkey(i)<= h){//leftが個数の最大であるhを越えない、つまり子が存在している時
      printf("left key = %d, ", a[leftkey(i)]);
    }

    if(rightkey(i)<= h){
      printf("right key = %d, ", a[rightkey(i)]);
    }
    printf("\n");
  }

  return 0;
}

int parentkey(int i){

  return i/2;
}
int leftkey(int i){
  return i*2;
}
int rightkey(int i){
  return (i*2+1);
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

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

    if(L < 0){
        if(L+N-1 < 0){
            cout << N*(N-1)/2 + L*N - (L+N-1) << endl;
        }else{
            cout << N*(N-1)/2 + L*N << endl;
        }
    }else{
        cout << N*(N-1)/2 + L*(N-1) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
   ll n,xr=0;
   cin>>n;
   vector<ll>v;
   for(int i=0;i<n;i++)
   {
     ll x;
     cin>>x;
     xr^=x;
     v.push_back(x);
   }
   for(int i=0;i<v.size();i++)
   {
     cout<<(xr^v[i])<<" ";
   }
   cout<<endl;
   return 0;
}




Measured memory_bytes: 5300
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
def inv(n):
	n %= mod
	return pow(n,mod-2,mod)
	
H = [0]*(N+1)
for n in range(1,N+1):
	H[n] = (inv(n)+H[n-1])%mod

N_f = 1
for n in range(1,N+1):
	N_f = N_f*n%mod

ans = 0
for n in range(1,N+1):
	ans += A[n-1]*(H[N-n+1]+H[n]-1)
	ans %= mod

ans *= N_f
ans %= mod
print(ans)

Measured memory_bytes: 62576
s,k = input().split()
K = int(k)
if s[-1] == "1":
  s += "0"
n = len(s)
ls = []
cnt = 0
for i in range(n):
  if s[i] == "0":
    ls.append(cnt)
    cnt = 0
  else:
    cnt += 1
l = len(ls)
sm = sum(ls)
mod = 998244353
dp = [[[0 for i in range(sm+1)] for j in range(sm+1)] for k in range(l+1)]
dp[0][0][0] = 1
smprv = 0
for i in range(1,l+1):
  num = ls[i-1]
  for j in range(smprv+num,sm+1):
    if j == smprv+num:
      dp[i][j][0] = 1
    for k in range(1,j+1):
      x = 0
      for m in range(j+1):
        if num >= m:
          x += dp[i-1][j-m][k]
        else:
          x += dp[i-1][j-m][k-(m-num)]
      dp[i][j][k] = x%mod
  smprv += num
ans = 0
for i in range(sm+1):
  if i <= K:
    ans += dp[-1][-1][i]
    ans %= mod
print(ans)

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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			long n = cin.Long();
			var a = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = cin.Long();
			}

			long[] t = new long[n];
			for (int i = 1; i < n; i++) {
				long v = (a[i - 1] - t[i - 1]);
				t[i - 1] += v;
				t[i] = v;
			}

			long s = 0;
			if (t[n - 1] != a[n - 1]) {
				long v = a[n - 1] - t[n - 1];
				s = v;
			}

			long[] ans = new long[n];
			long[] t2 = new long[n];
			ans[0] = s;
			t2[0] = s / 2;
			t2[n - 1] = s / 2;
			for (int i = 1; i < n; i++) {
				long v = (a[i - 1] - t2[i - 1]);
				ans[i] = v * 2;
				t2[i - 1] += v;
				t2[i] = v;
			}

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < n; i++) {
				sb.Append($"{ans[i]} ");
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 33432
from operator import itemgetter


def solve():
    N = int(input())
    SP = [['', 0, 0] for _ in range(N)]
    for i in range(N):
        S, P = map(str, input().split())
        P = -int(P)
        SP[i] = [S, P, i+1]
    
    SP.sort(key=itemgetter(0, 1))
    for i in range(N):
        print(SP[i][2])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

type Score struct {
	s     string
	p     int
	index int
	ans   int
}

func solve(in io.Reader, out io.Writer) {
	var n, x int
	fmt.Fscanf(in, "%d%d", &n, &x)

	l := make([]int, n)
	for i := range l {
		fmt.Fscanf(in, "%d", &l[i])
	}

	d := 0
	ans := 1
	for i := range l {
		d += l[i]
		if d > x {
			break
		}
		ans++
	}
	fmt.Fprintln(out, ans)
}


Measured memory_bytes: 512
import sys
S=input()
Skai=list(S)
Skai.reverse()
S=list(S)
num=len(S)
i=0
Slist =[]
Skailist =[]
for j in range (num):
	if S[j]!=Skai[j]:
		i+=1
		Skailist.append(Skai[j])
		Slist.append(S[j])
		if Slist==Skailist:
			print(len(Skailist))
			sys.exit()			
print(int(i/2))
                


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int a,b,c,tmp;

	scanf("%d %d %d",&a,&b,&c);

	if(a<b){
		if(b<c){}else{tmp=b;b=c;c=tmp;}	
	} else{	tmp=a; a=b;b=tmp;
	
	if(b<c){}else{tmp=b;b=c;c=tmp;}	}

	if(a>b){ tmp=a; a=b; b=tmp; }

	printf("%d %d %d\n",a,b,c);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>

#define N 15
using namespace std;

int n, m;
vector<int> v[N];
bool p[N], p2[N];
int pa(){
  
	long int n,k,p,i,j,l;
	cin>>n>>k;
	long int arr[n];
	long int min,c,sum;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(i=0;i<n;i++)
	{
	c=arr[i],sum=0;
		for(l=0;l<n;l++)
		{
		if(l!=i)
		{
			long int temp=arr[l];
			cout<<temp<<endl;
			if(temp+k<=c)
			{
				sum+=c-temp-k;
			}
			if(temp-k>=c)
			{
				sum+=temp-k-c;
			}
			if(temp+k>c && temp<c)
			{
				if(k-(c-temp)%2==0)
				sum+=0;
				else
				sum-=1;
			}
			if(temp-k<c && temp>c)
			{
				if(k-(temp-c)%2==0)
				sum+=0;
				else
				sum-=1;
			}
			if(i==0)
			{ min=sum;
			  p=i+1;
			}
		}
		}
		if(sum<min)
		{
			p=i+1;
			min=sum;
			cout<<sum<<endl;
		}
	}
	cout<<p<<" "<<min;
	return 0;
}

int main() {
    cin >> n >> m;

    int tmp, a;
    for (int i = 1; i <= m; ++i) {
        cin >> tmp;
        while (tmp--) {
            cin >> a;
            v[a].push_back(i);
        }
    }
    for (int i = 1; i <= m; ++i) {
        cin >> tmp;
        if (tmp == 1)
            p[i] = true;
        else
            p[i] = false;
    }

    int statue, ans = 0;
    for (statue = 0; statue < pow(2, n); ++statue) {
        for (int i = 1; i <= m; ++i)
            p2[i] = 0;
        tmp = statue;
        for (int i = 1; i <= n; ++i) {
            if (tmp % 2 == 1) {
                for (int j = 0; j < v[i].size(); ++j)
                    p2[v[i][j]] = !p2[v[i][j]];
            }
            tmp>>=1;
        }
        bool flag = true;
        for (int i = 1; i <= m; ++i) {
            if (p2[i] != p[i]){
            	flag = false;
            	break;
            }
        }
        if (flag){
        	ans++;
        //	cout << statue << endl;
        }
            
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[200000];

//check, add関数で使用
typedef pair<int, int> P;	//(ruiseki_count, moji(0～x-1))
P stk[1000010];
int sp;

//stkのインクリメント
bool add(int x) {
	if (stk[sp - 1].second != x - 1) {
		if ((sp >= 2 && stk[sp - 1].first - 1 == stk[sp - 2].first) || (sp == 1 && stk[0].first == 1)) {
			stk[sp - 1].second++;
			if (sp >= 2 && stk[sp - 2].second == stk[sp - 1].second) {
				stk[sp - 2] = stk[sp - 1];
				sp--;
			}
		}
		else {
			P a = P(stk[sp - 1].first - 1, stk[sp - 1].second);
			P b = P(stk[sp - 1].first, stk[sp - 1].second + 1);
			stk[sp - 1] = a;
			stk[sp] = b;
			sp++;
		}
		return true;
	}
	
	if (sp == 1) return false;
	
	if ((sp >= 3 && stk[sp - 2].first - stk[sp - 3].first == 1) || (sp == 2 && stk[sp - 2].first == 1)) {
		stk[sp - 2].second++;
		stk[sp - 1].second = 0;
		if (sp >= 3 && stk[sp - 2].second == stk[sp - 3].second) {
			stk[sp - 3] = stk[sp - 2];
			stk[sp - 2] = stk[sp - 1];
			sp--;
		}
	}
	else {
		P a = P(stk[sp - 2].first - 1, stk[sp - 2].second);
		P b = P(stk[sp - 2].first, stk[sp - 2].second + 1);
		//cout << "a = " << a.first << ", " << a.second << endl;
		//cout << "b = " << b.first << ", " << b.second << endl;
		int tmp = stk[sp - 1].first;
		stk[sp - 2] = a;
		stk[sp - 1] = b;
		stk[sp] = P(tmp, 0);
		sp++;
	}
	return true;
}

//x種類で足りるか？(x >= 2)
bool check(int x) {
	int i, j;
	
	//cout << "check(" << x << ")" << endl;
	
	sp = 0;
	stk[sp++] = P(a[0], 0);
	for (i = 1; i < n; i++) {
		
		//cout << endl;
		//for (j = 0; j < sp; j++) { cout << stk[j].first << ", " << stk[j].second << endl; }
		
		if (a[i] > a[i - 1]) {
			if (stk[sp - 1].second == 0) {
				stk[sp - 1].first = a[i];
			}
			else {
				stk[sp] = P(a[i], 0);
				sp++;
			}
		}
		else if (a[i] == a[i - 1]) {
			if (!add(x)) return false;
		}
		else {
			sp = lower_bound(stk, stk + sp, P(a[i] + 1, -1)) - stk;
			stk[sp].first = a[i];
			if (sp > 0 && stk[sp].first == stk[sp - 1].first) {
				sp--;
			}
			sp++;
			if (!add(x)) return false;
		}
	}
	
	//cout << endl;
	//for (j = 0; j < sp; j++) { cout << stk[j].first << ", " << stk[j].second << endl; }
		
	return true;
}

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	int st = 0, ed = n, mid;	//xxxooo, (st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) ed = mid;
		else st = mid;
	}
	cout << ed << endl;
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#include <map>
#include <cmath>
#include <string>
#define SIZE 100000

using namespace std;
typedef long long ll;
typedef pair <int,int> P;

#define abs(x) ((x>0)?x:(-(x)))

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, D;
  int X[500000], Y[5000000];
  int Q;
  int S[500*500];

  cin >> H >> W >> D;
  for (int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      int A;
      cin >> A;
      X[A] = j;
      Y[A] = i;
    }
  }

  for(int i = 1; i <= H * W; i++) {
    if(i <= D) {
      S[i] = 0;
    }
    else{
      S[i] = S[i - D] + abs(X[i] - X[i - D]) + abs(Y[i] - Y[i - D]);
    }
  }

  cin >> Q;
  for(int i=1; i<=Q;i++) {
    int L, R;
    cin >> L >> R;
    cout << (S[R] - S[L]) << endl;
  }
  return 0;
}


Measured memory_bytes: 5632
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    n, x = map(int, input().split())
    aaa = list(map(int, input().split()))
    aaa.sort()
    ans = 0
    for a in aaa:
        if x < a:
            break
        ans += 1
        x -= a
    else:
        if x > 0:
            ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,s;
  	cin>>a>>s;
  	long long sum=0;
    long long x=1;
    for(int i=a.size()-1;i>=0;i--){
        sum+=(a[i]-'0')*x;
        x*=10;
    }
  	//cout<<sum;
    if(sum<3200)
    {
      cout<<"red";
    }
    else
        cout<<s;
    return 0;
  	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(a, n) rep(hoge, n) printf("%d%c", a[hoge], hoge == n - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define ln(a) cout << (a) << endl

using namespace std;
using P = pair<int, int>;
using ll = long long;

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

signed main() {
    ll n;
    cin >> n;
    if(n % 2) {
        ln(0);
        return 0;
    }
    n /= 2;
    ll ans = 0;
    while(n) {
        n /= 5;
        ans += n;
    }
    ln(ans);
}


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

using namespace std;

int main()
{
    int arr[101];
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    /*for(int i = 0; i < n; i++) {
        cout << arr[i] << " ";
    }
    cout << endl; */
    // 1 
    int alice = 0;
    int bob = 0; 
    for(int i = n-1; i >= 0; i = i-2) {
        alice += arr[i];
    }
    for(int i = n-2; i >= 0; i = i-2) {
        bob += arr[i];
    }

    cout << (alice-bob);

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import combinations
def run():
    n,a,b = map(int, input().split())
    mod = 10 ** 9 + 7
    S = 0
    S += pow_mod(2, n, mod)
    S += (-1) % mod

    sub = 0
    for _a in (a,b):
        up = -1
        down = 1
        for i in range(_a):
            up *= n - i
            up %= mod
            down *= i + 1
            down %= mod
        down = pow_mod(down, mod - 2, mod)
        sub += (up * down) % mod

    S += sub % mod
    print(S % mod)
def pow_mod(n, k, mod):
    res = 1
    nk = n
    while True:
        if k // 2 >= 1:
            if k % 2 == 1:
                res = (res * nk) % mod
            nk = (nk ** 2) % mod
            k = k // 2
        else:
            break
    return (nk * res) % mod


if __name__ == "__main__":
    run()

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
  int a,b,c,t;
  cin>>a>>b>>c;
  t=a;
  a=b;
  b=t;
  t=a;
  a=c;
  c=t;
  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 1000

void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int S[MAX];
int top=0;

int main(){
  int i, j, n, x, y;
  char c[MAX], c2[MAX];

  initialize();

  for(i = 0; i < MAX; i++){
    scanf("%c", &c[i]);
    if(c[i] == '\n'){
      n = i;
      break;
    }
  }

  for(i = 0; i < n; i++){
    if(c[i] == ' ')
      continue;
    else if(c[i] == '+' || c[i] == '-' || c[i] == '*'){
      y = pop();
      x = pop();
      //printf("x = %d, y = %d\n", x, y);
      switch(c[i]){
      case '+':
	push(x + y);
	break;
      case '-':
	push(x - y);
	break;
      case '*':
	push(x * y);
	break;
      }
      //printf("top= %d\n", top);
      //printf("S[top] = %d\n", S[top]);
      //printf("S[top-1] = %d\n", S[top-1]);
    }
    else{
      memset(c2, '\0', strlen(c2));
      for(j = 0; c[i+j] != ' '; j++)
	c2[j] = c[i+j];
      i += j;
      //printf("%c\n", c2);
      push(atoi(c2));
    }
  }

  printf("%d\n", pop());

  return 0;
}

void initialize(void){
  top = 0;
}

int isEmpty(void){
  if(top == 0)
    return 0;
  else
    return 1;
}

int isFull(void){
  if(top >= MAX - 1)
    return 0;
  else
    return 1;
}

void push(int x){
  if(isFull() == 0){
    printf("Error (OverFlow)\n");
    exit(1);
  }
  top++;
  S[top] = x;
}

int pop(void){
  if(isEmpty() == 0){
    printf("Error (UnderFlow)\n");
    exit(2);
  }
  top--;
  return S[top+1];
}

Measured memory_bytes: 560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int n, a;
bool flag = true;

int main()
{
    cin>>n;
    REP(i,n) {
        cin>>a;
        if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0))
            flag = false;
    }
    cout<<(flag ? "APPROVED" : "DENIED")<<endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S,T = input().split()
result = ''
for i in range(N):
    result += S[i] + T[i]
# X1_list = [int(input()) for i in range(N)]
# X2_list = [list(map(int,input().split())) for i in range(N)]
#print(S,T)
print(result)

Measured memory_bytes: 2940
n = gets.to_i
xs = gets.split(" ").map(&:to_i)
sorted = xs.sort

index1 = xs.size / 2
index2 = index1 - 1
median1 = sorted[index2]
median2 = sorted[index1]

xs.each do |x|
  if x <= median1
    puts median2
  else
    puts median1
  end
end

Measured memory_bytes: 23396
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int input[NUM],table[NUM],pre_index[NUM],LOC[NUM];

int main(){

	int N;
	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d",&input[i]);
	}

	table[0] = input[N-1];

	int index = 0;
	pre_index[N-1] = -1;
	LOC[0] =  N-1;

	int left,right,m,replace_index;

	for(int i = N-2; i >= 0; i--){

		if(input[i] < table[index]){ //最長減少部分列が伸びる

			index++;
			pre_index[i] = LOC[index-1]; //後方にしか張らない
			table[index] = input[i];
			LOC[index] = i;
			continue;
		}

		left = 0,right = index,m = (left+right)/2;

		//最も左にある、自分より小さい数を探す
		while(left <= right){
			if(table[m] == input[i]){
				replace_index = m;
				break;
			}else if(table[m] < input[i]){
				replace_index = m;
				right = m-1;
			}else{
				left = m+1;
			}
			m = (left+right)/2;
		}

		if(replace_index == 0){
			pre_index[i] = -1;
		}else{
			pre_index[i] = LOC[replace_index-1];
		}
		table[replace_index] = input[i];
		LOC[replace_index] = i;

	}

	ll ans = table[index]; //table上のindex
	index = pre_index[LOC[index]];

	while(index != -1){

		ans += input[index];
		index = pre_index[index];
	}

	printf("%lld\n",ans);

	return 0;
}




Measured memory_bytes: 4748
#include<cstdio>
#define ll long long
#define fo(i, x, y) for(int i = x; i <= y; i ++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
using namespace std;

const int N = 2e5 + 5;

int n;

ll a[N], as, mx, mi;

int main() {
	scanf("%d", &n);
	fo(i, 1, n) scanf("%lld", &a[i]), a[i] += a[i - 1];
	as = 1e18;
	fo(k, 2, n - 2) {
		int ans = 1;
		for(int l = 1, r = k - 1; l <= r; ) {
			int m = l + r >> 1;
			if(a[m] <= a[k] - a[m]) {
				ans = m; l = m + 1;
			} else r = m - 1;
		}
		int ans2 = k + 1;
		for(int l = k + 1, r = n - 1; l <= r; ) {
			int m = l + r >> 1;
			if(a[m] - a[k] <= a[n] - a[m]) {
				ans2 = m; l = m + 1;
			} else r = m - 1;
		}
		fo(i, ans, ans + 1) {
			if(i == k) continue;
			fo(j, ans2, ans2 + 1) {
				if(j == n) continue;
				
				mx = -1e18; mi = 1e18;
				
				mx = max(mx, a[i]);
				mx = max(mx, a[k] - a[i]);
				mx = max(mx, a[j] - a[k]);
				mx = max(mx, a[n] - a[j]);
				
				
				mi = min(mi, a[i]);
				mi = min(mi, a[k] - a[i]);
				mi = min(mi, a[j] - a[k]);
				mi = min(mi, a[n] - a[j]);
				
				
				as = min(as, mx - mi);
			}
		}
	}
	printf("%lld", as);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,i,p=0,u;
	cin >> a >> b;
   for(i=0;i<a;i++)
   {
   	cin >> u;
   	if(u>=b)
   	{
   		p++;
	   }
   }
   cout << p;
	
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final int n = scanner.nextInt();
    final int k = scanner.nextInt();
    scanner.nextLine();
    final int[] p = Arrays.stream(scanner.nextLine().split(" "))
        .mapToInt(Integer::parseInt)
        .toArray();
    Arrays.sort(p);

    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += p[i];
    }

    System.out.println(sum);
  }
}


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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  string S, T;
  cin >> S >> T;
  string odd, even;
  odd = even = "";
  rep(i, S.size()) (i%2 ? odd : even) += S[i];
  int idx = 0;
  rep(i, T.size()) {
    if(idx == (int)odd.size()) break;    
    if(T[i] == odd[idx]) idx++;
  }
  if(idx == (int)odd.size()) {
    cout << "Yes" << endl;
    return 0;
  }
  idx = 0;
  rep(i, T.size()) {
    if(idx == (int)even.size()) break;
    if(T[i] == even[idx]) idx++;
  }
  if(idx == (int)even.size()) {
    cout << "Yes" << endl;
    return 0;
  } 
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >

int f(int a) {
    int res[] = {a, 1, a+1, 0};
    return res[a % 4];
}

int getXor(int a, int b) {
    return f(b) ^ f(a);
}
int32_t main()
{
    fast;
    int a,b,ans;
    cin>>a>>b;
    if(a!=0)
        ans=getXor(a-1,b);
    else
        ans=f(b);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
N = gets.to_i
t = []
x = []
y = []
t[0] = 0
x[0] = 0
y[0] = 0
for i in 1..N
    t[i],x[i],y[i] = gets.split.map(&:to_i)
end

a = 0

for i in 0..N-1

    if (x[i+1]-x[i]).abs + (y[i+1]-y[i]).abs > t[i+1]-t[i] || ((x[i+1]-x[i]).abs + (y[i+1]-y[i]).abs) % 2 != (t[i+1]-t[i]).abs % 2

        a += 1

    end

end

if a == 0

    puts 'Yes'

else

    puts 'No'

end

Measured memory_bytes: 4328
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

using ll = long long;

int main() {
    ll N;
    cin >> N;
    ll A[N], sum = 0;
    for (ll i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
    }

    if (sum % (N * (N + 1) / 2) > 0) {
        cout << "NO" << endl;
        return 0;
    }

    ll total = sum / (N * (N + 1) / 2);
    ll ope = 0;

    for (ll i = 0; i < N; ++i) {
        ll diff = A[(i + 1) % N] - A[i];
        if ((total - diff) >= 0 && (total - diff) % N == 0) {
            ope += abs((diff - total) / N);
            continue;
        }
        cout << "NO" << endl;
        return 0;
    }

    if (ope == total) {
        cout << "YES" << endl;
    } else {
        terminate();
    }
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
int n,q;
int a[30];

bool dfs(int idx,int sum,int m) {
    if(sum==m) return true;
    if(idx == n) return false;
    return dfs(idx+1,sum+a[idx],m) || dfs(idx+1,sum,m);
}

int main() {
    cin>>n;
    rep(i,n) cin>>a[i];
    cin>>q;
    while(q--) {
        int m;
        cin>>m;
        if(dfs(0,0,m)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

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

int main(){
	int a, v, b, w, t;
	scanf("%d%d%d%d%d", &a, &v, &b, &w, &t);
	int d = abs(a - b), sp = v - w;
	printf("%s\n", (ll)t * sp >= d ? "YES" : "NO");
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(string str)
{
    string temp = str;
    reverse(str.begin(),str.end());
    return str==temp;
}
int main()
{
    string str;
    cin >> str;
    int n=(int)str.size();
    int left = ((n-1)>>1);
    int right = ((n+3)>>1);
    if(isPalindrome(str) and isPalindrome(str.substr(0,left)) and isPalindrome(str.substr(left+1,right)))
       printf("%s\n","Yes");
    else
       printf("%s\n","No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll N, S, mod = 998244353;
    cin >> N >> S;
    vector<ll> A(N+1);
    REP(i, N) cin >> A[i+1];
    vector< vector<ll> > dp(N + 1, vector<ll>(S+1, 0));
    dp[0][0] = 1;
    FOR(i, 1, N) {
        REP(j, S+1) {
            if(j - A[i] >= 0)   
                dp[i][j] += 2 * dp[i-1][j] + dp[i-1][j-A[i]];
            else
                dp[i][j] += 2 * dp[i-1][j];
            dp[i][j] %= mod;
        }
    }

    // FOR(i, 0, N) {
    //     REP(j, S+1) cerr << dp[i][j] << " ";
    //     cerr << endl;
    // }
    cout << dp[N][S] << endl;
    return 0;
}

Measured memory_bytes: 73680