akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main (){
	int A,B,C;
		scanf("%d",&A);
		scanf("%d",&B);
		scanf("%d",&C);	
		
	if(A == B && B == C && C == A){
		
		printf("No\n");
	}
	else if (A == B || B == C || C == A){
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	
	
return 0;
}


Measured memory_bytes: 1636
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main implements Runnable {

    private void solve() throws IOException {

        int R = nextInt();
        int C = nextInt();
        for(int r = 0; r < R; ++r) {
            String s = reader.readLine();
            writer.println(s);
            writer.println(s);
        }
    }



    public static void main(String[] args) {
        new Main().run();
    }

    BufferedReader reader;
    //    BufferedReader reader2;
    StringTokenizer tokenizer;
    PrintWriter writer;
    //    BufferedWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//            reader = new BufferedReader(new FileReader("trees.in"));
            //            reader2 = new BufferedReader(new FileReader("1.in"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
//            writer = new     PrintWriter("trees.out");
//                                                    writer = new BufferedWriter(System.out);
            //                        writer = new BufferedWriter(new OutputStreamWriter(System.out));
            solve();
            reader.close();
            //            reader2.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    short nextShort() throws IOException {
        return Short.parseShort(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }

}

Measured memory_bytes: 8276
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    int H,W;
    cin >> H >> W;
    vector<vector<bool>> g(W, vector<bool>(H));
    
    rep(y,H){
        string s;
        cin >> s;

        rep(x,W){
            if (s.substr(x,1) == "#") {
                g.at(x).at(y) = false;
            } else {
                g.at(x).at(y) = true;
            }
        }

    }


    vector<vector<int>> cR(W, vector<int>(H));
    vector<vector<int>> cL(W, vector<int>(H));
    vector<vector<int>> cU(W, vector<int>(H));
    vector<vector<int>> cD(W, vector<int>(H));

    //左に伸びる個数
    for(int y = 0; y < H; ++y) {
        for(int x = 0; x < W; ++x) {
            if (!g.at(x).at(y)){
                cL.at(x).at(y) = 0;
            } else if (x == 0) {
                cL.at(x).at(y) = 1;
            } else {
                cL.at(x).at(y) = cL.at(x-1).at(y) + 1;
            }
        }
    }
    //右に伸びる個数
    for(int y = 0; y < H; ++y) {
        for(int x = W-1; x >= 0; --x) {
            if (!g.at(x).at(y)){
                cR.at(x).at(y) = 0;
            } else if (x == W-1) {
                cR.at(x).at(y) = 1;
            } else {
                cR.at(x).at(y) = cR.at(x+1).at(y) + 1;
            }
        }
    }
    //上に伸びる個数
    for(int x = 0; x < W; ++x) {
        for(int y = 0; y < H; ++y) {
            if (!g.at(x).at(y)){
                cU.at(x).at(y) = 0;
            } else if (y == 0) {
                cU.at(x).at(y) = 1;
            } else {
                cU.at(x).at(y) = cU.at(x).at(y-1) + 1;
            }
        }
    }
    //下に伸びる個数
    for(int x = 0; x < W; ++x) {
        for(int y = H-1; y >= 0; --y) {
            if (!g.at(x).at(y)){
                cD.at(x).at(y) = 0;
            } else if (y == H-1) {
                cD.at(x).at(y) = 1;
            } else {
                cD.at(x).at(y) = cD.at(x).at(y+1) + 1;
            }
        }
    }

    //cout << endl;
    //for(int y = 0; y < H; ++y) {
    //    for(int x = 0; x < W; ++x) {
    //        cout << cL.at(x).at(y) << ",";
    //    }cout << endl;
    //}cout << endl;

    ll ret  = 0;
    for(int x = 0; x < W; ++x) {
        for(int y = 0; y < H; ++y) {
            ll score = 0;
            score += cR.at(x).at(y);
            score += cL.at(x).at(y);
            score += cU.at(x).at(y);
            score += cD.at(x).at(y);
            score -= 3;
            ret = max(ret,score);
        }
    }


    cout << ret << endl;
    

    return 0;
}


Measured memory_bytes: 63616
#include<stdio.h>

int abs(int a){return a<0?-a:a;}
int min(int a, int b){return a>b?b:a;}
int max(int a, int b){return a<b?b:a;}

int N, K, H[100000], i, j;
int ans[100000];
int main(){
	scanf("%d%d", &N, &K);
	for(i=0; i<N; i++){
		scanf("%d", H+i);
	}
	ans[0]=0;
	ans[1]=abs(H[0]-H[1]);
	for(i=2; i<N; i++){
		ans[i] = 2147483647;
		for(j=max(0, i-K); j<i; j++){
			ans[i] = min(ans[i], ans[j]+abs(H[i]-H[j]));
		}
	}
	printf("%d\n", ans[N-1]);
}


Measured memory_bytes: 896
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int x = 0;
		
		for (int i = 0; i < n; i ++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			
			x += b[i] - a[i] + 1;
		}
		
		System.out.println(x);
		
	}
}

Measured memory_bytes: 27752
#include<iostream>
#include<algorithm>
using namespace std;
long ans;
string s;
int n,sum;
long fac[15],prod=1;
long power(long a,long b){return b?power(a*a,b/2)*(b%2?a:1):1;}
int cnt[10];
void dfs(int p,int c)
{
	if(p<10)
	{
		for(int i=0;i<=c;i++)
		{
			cnt[p]=i;
			dfs(p+1,c-i);
		}
		cnt[p]=0;
		return;
	}
	if(c)return;
	int nowsum=0;
	long nowprod=1;
	for(int i=0;i<10;i++)
	{
		nowsum+=i*cnt[i];
		nowprod*=power(i+1,cnt[i]);
	}
	if(nowsum<sum||nowsum==sum&&nowprod<prod)
	{
		long plus=fac[n];
		for(int i=0;i<10;i++)plus/=fac[cnt[i]];
		ans+=plus;
		return;
	}
	else if(!(nowsum==sum&&nowprod==prod))return;
	int sto[10]={};
	for(int i=0;i<10;i++)sto[i]=cnt[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<s[i]-48;j++)
		{
			if(cnt[j]==0)continue;
			long now=fac[n-i-1];
			cnt[j]--;
			for(int k=0;k<10;k++)now/=fac[cnt[k]];
			ans+=now;
			cnt[j]++;
		}
		if(cnt[s[i]-48]==0)break;
		cnt[s[i]-48]--;
	}
	for(int i=0;i<10;i++)cnt[i]=sto[i];
}
main()
{
	cin>>s;
	n=s.size();
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i;
	for(int i=0;i<n;i++)
	{
		sum+=s[i]-48;
		prod*=s[i]-47;
	}
	dfs(0,n);
	cout<<ans<<endl;
}


Measured memory_bytes: 3204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc070.contest.atcoder.jp/tasks/abc070_c>
問題文============================================================
 N 台の時計があり、i(1≦i≦N) 番目の時計の針はちょうど Ti 秒で時計盤を 1 周します。
 最初、全ての時計の針は真っ直ぐ上に向いており、止まっています。
 イルカは、全ての時計の針を同時に動かし始めました。
 再び、全ての時計の針が真っ直ぐ上に向くのは何秒後でしょうか?
=================================================================

解説=============================================================
lcmだね
================================================================
*/

inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll res = 1;
    for(int i = 0; i < N;i++){
        ll x; cin >> x;
        res = lcm(res,x);
    }
    cout << res << endl;
	return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M;
int cnt[100100];

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

    std::cin >> N >> M;

    int prv = -1;
    for(int i=0;i<M;++i){
        int p;
        std::cin >> p;

        if(prv != -1){
            ++cnt[min(prv, p)];
            --cnt[max(prv, p)];
        }
        prv = p;
    }

    for(int i=1;i<N;++i){
        cnt[i+1] += cnt[i];
    }

    ll res = 0ll;
    for(int i=1;i<N;++i){
        int a, b, c;
        std::cin >> a >> b >> c;

        ll x = 1ll * a * cnt[i], y = 1ll * c + 1ll * b * cnt[i];
        res += min(x, y);
    }

    std::cout << res << std::endl;
}



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

int main(){
	string s;
	cin>> s;
	int ans = 700;

	rep(i,3){
		if(s[i] == 'o'){
			ans += 100;
			}
	}
	cout << ans << endl;
	return 0;

}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()

    def solve(S):
        while len(S) > 0:
            if len(S) >= 7:
                if S[-7:] == 'dreamer':
                    S = S[:-7]
                    continue
            if len(S) >= 6:
                if S[-6:] == 'eraser':
                    S = S[:-6]
                    continue
            if len(S) >= 5:
                if S[-5:] == 'erase':
                    S = S[:-5]
                    continue
                elif S[-5:] == 'dream':
                    S = S[:-5]
                    continue
            return False
        return True
    print('YNEOS'[not solve(S)::2])


if __name__ == "__main__":
    main()


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;

LL GCD(LL a,LL b){
    LL t; LL r;
    if(a<b){t=a;a=b;b=t;}
    if(b==0){return a;}
    while(a%b!=0){r=a%b;a=b;b=r;}
    return b;
}

P<Vll,Vll> primeFactor(LL n){
    Vll p,e; LL m=n; int c;
    for(LL i=2;i*i<=n;i++){
        if(m%i!=0){continue;}
        c=0;
        while(m%i==0){c++;m/=i;}
        p.pb(i); e.pb(c);
    }
    if(m>1){ p.pb(m); e.pb(1);}
    return mp(p,e);
}

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

    LL gcd_ab = GCD(a,b);

    auto pf_gcd = primeFactor(gcd_ab);

    cout<<pf_gcd.fi.size()+1<<endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A, B = list(input().split())
	A = int(A)
	Bint = int(B[0] + B[2] + B[3])
	# print(Bint)
	print(int(A * Bint // 100))


if __name__ == '__main__':
	main()

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

bool Do(vector<ll>& v, int N){
	int idx = max_element(v.begin(), v.end()) - v.begin();
	if(v[idx] <= N - 1) return false;
	for(int i = 0; i < v.size(); i++) {
		if(i == idx) v[i] -= N;
		else v[i]++;
		//cout << v[i] << " ";
	}
	//cout << endl;
	return true;
}

ll f(vector<ll> v, int N){
	ll sum = 0;
	while(Do(v, N)) {
		sum++;
	}
	return sum;
}

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

	ll K;
	cin >> K;

	int N = 50;
	vector<ll> ans(N);
	ll loop = (K + N - 1) / N;
	ll sum = loop * N;
	for(int i = 0; i < N; i++) {
		ans[i] = N - 1 + loop;
	}

	//cout << f(ans, N) << " " << sum << endl;
	while(sum > K) {
		Do(ans, N);
		sum--;
	}
	//cout << f(ans, N) << endl;

	cout << N << endl;
	for(int i = 0; i < N; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 256
def calc():
    n = int(input())
    a = list(map(int, input().split()))

    if 0 in a :
        print(0)
        return

    ans = 1
    for x in a:
        ans *= x
        if ans > 1000000000000000000:
            print(-1)
            return

    print(ans)


calc()


Measured memory_bytes: 21564
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define repit(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define sortt(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define co(x) cout << (x);
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define mkp make_pair
#define mkt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/******* Variable ***********************************/
const int maxn = 1e6 * 50;
const double inf = 0x3f3f3f3f3f;
/******* Function ***********************************/
void out(const vector<int> A) {
  rep(i, 0, A.size()) {
    cout << A[i] << ((i != A.size() - 1) ? " " : "\n");
  }
}

/******* Main ****************************************/
int main() {
  vector<int> A(3);
  rep(i, 0, 3) {
    cin >> A[i];
  }
  rep(i, 0, 3) {
    int min = A[i];
    int tmp = i;
    rep(j, i + 1, 3) {
      if (A[j] < min) {
        min = A[j];
        tmp = j;
      }
    }
    A[tmp] = A[i];
    A[i] = min;
  }
  out(A);
  return 0;
}


Measured memory_bytes: 3060
#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 <numeric>
#include <iomanip>  //setprecision(桁)
using namespace std;
#define pb push_back
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 1e+9

struct edge {
    int to;
    double cost;
};

// <最短距離, 頂点の番号>
using P = pair<double, int>;

int V;
const int ci = 2e5+ 5;
vector<edge> G[ci];
double d[ci];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) { //cout << "On" << endl;
        P p = que.top();
        que.pop();
        int v = p.second; //cout << "v=" << v << endl;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); i++) {
            edge e = G[v][i]; //cout << "koo" << endl;
            if (d[e.to] > d[v] + e.cost) { //cout << e.cost << endl;
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[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;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modPow(ll a, ll n, ll p) {
    if (n == 0) return 1; // 0乗にも対応する場合
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}


int main(){
    COMinit();
    ll n, m, k; cin >> n >> m >> k;
    ll ans = 0;

    for(ll i = 0; i <= k; i++) {
        ll c = COM(n - 1, i) % MOD;
        ll mP = modPow(m - 1, n - 1 - i, MOD);
        ans += (((c * m) % MOD) * mP) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 20280
#include <iostream>


int main(void){

	int n, m, x;
	std::cin >> n >> m >> x;

	bool* pass = new bool[n];
	for(int i = 0; i < n; i++){
		pass[i] = true;
	}

	int tmp;
	for(int i = 0; i < m; i++){
		std::cin >> tmp;
		pass[tmp] = false;
	}
	int costL = 0;
	int costR = 0;
	for(int i = x; i < n; i++){
		costR += pass[i] ? 0 : 1;
	}
	for(int i = x; i > 0; i--){
		costL += pass[i] ? 0 : 1;
	}
	
	std::cout << ((costL > costR) ? costR : costL) << std::endl;

	delete[] pass;

	return 0;
}

Measured memory_bytes: 384
S = input()
T = input()

l = len(S)
k = len(T)
f = 0


if k > l:
    f = 0
else:
    for i in reversed(range(0,l-k+1)):
        #print(i)
        for j in range(k):
            #print(S[i+j], T[j])
            if S[i + j] != T[j] and S[i + j] != "?":
                #print(i+j)
                break
            if j == k-1:
                f = 1
                s = i
        if f == 1:
            break

if f == 0:
    print("UNRESTORABLE")
else:
    S = S[:s] + T + S[s+k:]
    for i in range(l):
        if S[i] == "?":
            S = S[:i] + "a" + S[i+1:]
    print(S)


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

int main(void)
{
  string n;
  cin>>n;

  for(int i=0;i<3;i++){
    if(n[i]=='1')
      n[i]='9';
    else if(n[i]=='9')
      n[i]='1';
  }
  cout<<n<<endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	static final Scanner	s	=new Scanner(System.in);

	public static void main(String args[]){
		input();
		solve();
	}

	private static void input(){
	}

	private static void solve(){
		int h=s.nextInt();
		s.next();
		for(int i=0;i<h;i++) {
			String in=s.next();
			System.out.println(in);
			System.out.println(in);
		}
	}
}


Measured memory_bytes: 22996
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        if (array[0] <= 8 && array[1] <= 8)
        {
            Console.WriteLine("Yay!");
        }
        else
        {
            Console.WriteLine(":(");
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
int n,k;
mint dp[110][110000];
mint dp_sum[110][110000];
int main(){
    cin >> n >> k;
    vl a(n+1);rrep(i,n) cin >> a[i];
    dp[0][0]=1;
    for(int i=0;i<=k;i++) dp_sum[0][i]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            dp[i][j]=dp_sum[i-1][j];
            if(j-a[i]-1>=0) dp[i][j]-=dp_sum[i-1][j-a[i]-1];
            if(j-1>=0) dp_sum[i][j]=dp_sum[i][j-1]+dp[i][j];
            else dp_sum[i][j]=dp[i][j];
        }
    }
    cout << dp[n][k].x << endl;
    return 0;
}

Measured memory_bytes: 189440
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <iomanip>
#include <climits>
const int MOD = 1000000007;


ll POWER(ll x,ll y)
{
	ll ret=1;
	ll p=x;
	for (ll i=y;i>0;i/=2)
	{
		if (i%2) ret=(ret*p)%MOD;
		p=(p*p)%MOD;
	}
	return ret;
}
ll gcm(ll a, ll b)
{
	if (b>a) {ll c=a; a=b; b=c;}
	while (b>0)
	{
		ll r=a%b;
		a=b;
		b=r;
	}
	return a;
}

ll calc(map<ll,ll> &mp,ll n,ll a,ll b,ll c,ll d)
{
	ll tmp,m;
	ll ret=LLONG_MAX;
	if (ret/d>n) ret=d*n;

	if (n==0) return 0;
	if (n==1) return d;
	if (mp.count(n)) return mp[n];
	//cerr<<n<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

	m=n%2;
	tmp=calc(mp,(n-m)/2,a,b,c,d)+a+d*m;if (tmp<ret)ret=tmp;
	if (m) tmp=calc(mp,(n+2-m)/2,a,b,c,d)+a+d*(2-m);if (tmp<ret)ret=tmp;
	
	m=n%3;
	tmp=calc(mp,(n-m)/3,a,b,c,d)+b+d*m;if (tmp<ret)ret=tmp;
	if (m) tmp=calc(mp,(n+3-m)/3,a,b,c,d)+b+d*(3-m);if (tmp<ret)ret=tmp;

	m=n%5;
	tmp=calc(mp,(n-m)/5,a,b,c,d)+c+d*m;if (tmp<ret)ret=tmp;
	if (m) tmp=calc(mp,(n+5-m)/5,a,b,c,d)+c+d*(5-m);if (tmp<ret)ret=tmp;

	//cerr<<"cacl("<<n<<")="<<ret<<endl;
	mp[n]=ret;
	return ret;
}


int main(int argc, char *argv[])
{
	int t;
	ll n,a,b,c,d;
	cin>>t;
	for (int i=0;i<t;i++)
	{
		map<ll,ll> mp;
		mp.clear();
		cin>>n>>a>>b>>c>>d;
		cout<<calc(mp,n,a,b,c,d)<<endl;
	}
	return 0;
}



Measured memory_bytes: 4376
// 3つの数の整列
#include <iostream>
using namespace std;

int main()
{
    int i, j, tmp, num[3];

    for (i=0; i<3; i++) cin >> num[i];

    for (i = 2; i > 0; i--) {
        for (j = 0; j < i; j++) {
            if (num[j] > num[j+1]){
               tmp = num[j];
               num[j] = num[j+1];
               num[j+1] = tmp;
            }
        }
    }
    cout << num[0] << ' ' << num[1] << ' ' << num[2] << endl;
    return 0;
}



Measured memory_bytes: 3088
n = int(input())
h = list(map(int,input().split()))
dp = [10**9 for i in range(n)]
dp[0]=0
for i in range(1,n):
    if  i-1 >= 0 :
        dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i])
    if i-2 >= 0:
        dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]),dp[i])
print(dp[len(dp)-1])


Measured memory_bytes: 13976
import java.util.*;

public class Main {

    public static void main(String[] args) {

        // Read
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean a[][] = new boolean[h][w];

        // Preproc
        Queue<Coord> queue = new ArrayDeque<>();
        String tmp;

        for (int i=0; i<h; i++) {
            tmp = sc.next();
            for (int j=0; j<w; j++) {

                if (tmp.charAt(j) == '#') {
                    a[i][j] = true;
                    queue.add(new Coord(i,j));
                }

            }
        }

        Coord dummy = new Coord(0,0);
        dummy.isDummy = true;
        queue.add(dummy);

        // Counting
        int result = 0;

        while (!queue.isEmpty()) {
            Coord c = queue.remove();
            if (!c.isDummy) {
                for(Coord n : neighbours(c, h-1, w-1)){
                    if(!a[n.x][n.y]) {
                        a[n.x][n.y] = true;
                        queue.add(n);
                    }
                }
            } else {
                if (queue.isEmpty()) {
                    break;
                }
                queue.add(dummy);
                result++;
            }
        }

        System.out.println(result);


    }

    private static List<Coord> neighbours(Coord c, int uBoundX, int uBoundY) {
        List<Coord> r = new ArrayList<>(4);
        if (c.x-1 >= 0) {r.add(new Coord(c.x-1,c.y));}
        if (c.y-1 >= 0) {r.add(new Coord(c.x,c.y-1));}
        if (c.x+1 <= uBoundX) {r.add(new Coord(c.x+1,c.y));}
        if (c.y+1 <= uBoundY) {r.add(new Coord(c.x,c.y+1));}
        return r;
    }


    static class Coord {
        boolean isDummy = false;
        int x; int y;
        Coord(int x, int y){
            this.x = x;
            this.y = y;
        };
    }

}



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

using namespace std;


int confere[10000000];


vector<vector<pair<int,int>>>v;


void dfs(int i,int j,int peso){

	if(confere[i]!=-1) return;

	if(peso%2==0) confere[i]=j;
	else confere[i]= (j+1)%2;


	for(int s=0;s<v[i].size();s++){

		dfs(v[i][s].first, confere[i],v[i][s].second);
	}

}

int main(){

	int n;
	int u,u2,w;
	cin >> n;

	for(int i=0;i<n+10;i++){
		vector<pair<int,int>>s;
		v.push_back(s);
	}

	for(int i=0;i<n+10;i++){
		confere[i]=-1;
	}
	n--;

	for(int i=0;i<n;i++){
		cin >> u >> u2 >> w;
		v[u].push_back(make_pair(u2,w));
		v[u2].push_back(make_pair(u,w));
	}
	dfs(1,0,0);

	for(int i=1;i<=n+1;i++)
		cout << confere[i] << endl;
	return 0;
}

Measured memory_bytes: 7408
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1000*1000*1000+7;
lli bpow(lli a, lli b) {
	if(b == 0) return 1;
	if(b == 1) return a % MOD;
	lli r = bpow(a, b >> 1);
	r = (r * r) % MOD;
	return (r * (((b&1)?a:1) % MOD)) % MOD;
}
lli multInverse(lli a) {
	return bpow(a, MOD - 2);
}
lli modMult(lli a, lli b) {
	return (a * b) % MOD;
}
lli modSub(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli modAdd(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
string NN;
string num;
int k, n;
lli k3() {
	lli ans = 0;
	for(int i = k-1; i < n-1; i++)
		ans += 9 * 9LL * 9 * ((i * (i-1)) / 2);
	for(char dig1 = '1'; dig1 <= '9'; dig1++) {
		num[0] = dig1;
		for(int ii = 1; ii < n; ii++) {
			for(char dig2 = '1'; dig2 <= '9'; dig2++) {
				num[ii] = dig2;
				for(int jj = ii+1; jj < n; jj++) {
					for(char dig3 = '1'; dig3 <= '9'; dig3++) {
						num[jj] = dig3;
						for(int cccc = 0; cccc < n; cccc++) {
							if(num[cccc] < NN[cccc]) ans++;
							if(num[cccc] != NN[cccc]) break;
						}
					}
					num[jj] = '0';
				}
			}
			num[ii] = '0';
		}
	}
	return ans;
}
lli k2() {
	lli ans = 0;
	for(int i = k; i < n; i++)
		ans += 9 * 9 *(i-1);
	for(int j = 1; j <= 9; j++) {
		num[0] = j + '0';
		for(int kk = 1; kk < n; kk++) {
			for(int ll = 1; ll <= 9; ll++) {
				num[kk] = ll + '0';
				for(int cccc = 0; cccc < n; cccc++) {
					if(num[cccc] < NN[cccc]) ans++;
					if(num[cccc] != NN[cccc]) break;
				}
			}
			num[kk] = '0';
		}
	}
	return ans;
}
lli k1() {
	lli ans = 0;
	for(int i = k; i < n; i++)
		ans += 9;
	for(int j = 1; j <= 9; j++) {
		num[0] = j + '0';
		for(int cccc = 0; cccc < n; cccc++) {
			if(num[cccc] < NN[cccc]) ans++;
			if(num[cccc] != NN[cccc]) break;
		}
	}
	return ans;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	cin >> NN;
	cin >> k;
	n = NN.length();
	num = "";
	for(int i = 1; i <= n; i++)
		num.push_back('0');
	
	lli anss;
	if(k == 1) anss = k1();
	if(k == 2) anss = k2();
	if(k == 3) anss = k3();
	int cnt = 0;
	for(int i = 0; i < n; i++)
		if(NN[i] != '0') 
			cnt++;
	//cout << anss << "\n";
	if(cnt == k) anss++;
	cout << anss << "\n";
	return 0;
}

Measured memory_bytes: 256
import sys
s = raw_input()
K = input()
suffix_array = [s[-i:] for i in range(1, len(s) + 1)]
suffix_array.sort()
cand = set()
for s in suffix_array[:K]:
    for i in range(1, len(s) + 1):
        sub = s[:i]
        cand.add(sub)
        if len(cand) == K:
            print sub
            sys.exit()



Measured memory_bytes: 15236
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

co = 0

n,k = m()

for i in range(1,n+1):
    p = n//i
    q = n%i
    co += p*(max(0,i-k))
    co += max(0,q-k+1)
if k == 0:
    co -= n
print(co)








Measured memory_bytes: 39408
#include <stdio.h>
#include <ctype.h>

int main(void){
    char pile[201]={0}, buffer[201]={0}, cutbuffer[201]={0};
    int num=0, shuffle=0, index=0;
    
    
    for(;scanf("%s", pile) && strcmp("-", pile);){
        for(index=0, scanf("%d", &num); num > index && scanf("%d", &shuffle); index++){
            strncpy(buffer, pile, shuffle);                                     /*bufferの中に山札の前からシャッフル枚コピーされる*/
            strncpy(cutbuffer, &(pile[shuffle]), strlen(pile)-shuffle);    /*詰め用のバッファに山札残りを詰め込む*/
            strncpy(pile, cutbuffer, 201); /*山札を詰め戻す+他をナルで埋める*/
            strncat(pile, buffer, shuffle); /*山札のケツにバッファ分を付ける*/
            
            strncpy(buffer, "\0", 201); /*バッファー系のナル詰め初期化*/
            strncpy(cutbuffer, "\0", 201);
        }
        
        printf("%s\n", pile); /*シャッフル後の山札の表示*/
    }
    
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
using namespace std;
int main(void) {
	string S, T, U;
	int A, B;
	cin >> S >> T >> A >> B >> U;
	if (S == U) {
		cout << A - 1<<" ";
		cout << B;
	}
	else {
		cout << A<< " ";
		cout << B - 1;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define show(x) std::cerr << #x << "=" << x << std::endl
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn = 1e7+5;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int t;
int n,m;
ll f[maxn];
void init()
{
    memset(f,0,sizeof f);
    for(int i=1;i<=10000000;++i)
    {
        for(ll j=i;j<=10000000;j+=i)
        {
            ++f[j];
        }
        //printf("%d %d\n",i,f[i]);
    }
}
int main()
{
    init();
    while(~scanf("%d",&n))
    {
        ll ans = 0;
        for(int i=1;i<=n;++i) ans+=i*f[i];
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 81964
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;
    while(cur != nil &&  cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *) malloc (sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node*)malloc(sizeof(Node));
    x->key = key;
    
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') { insert(key); np++; size++; }
        else if (com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }
    
    printList();
    
    return 0;
}

Measured memory_bytes: 33948
//昇順ソート
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void){
    int i, N, W[220]={0}, MIN, S1, S2, f=0;
    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%d", W+i);
        W[100+i] += W[i];
        W[100+i+1] = W[100+i];
    }//W[100+N]に合計がある
    MIN = W[100+N];
    for(i=0; f==0; i++){
        S1 = W[100+i];
        S2 = W[100+N] - S1;
        f = fabs(S1-S2);
        if(f < MIN) {
            MIN = fabs(S1-S2);
            f=0;
        }
    }
    printf("%d\n", MIN);
    return 0;
}


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

using namespace std;

template <std::uint_fast64_t Modulus> class ModInt {
  using u64 = std::uint_fast64_t;

public:
  u64 x;

  constexpr ModInt(const u64 x = 0) noexcept : x(x % Modulus){};

  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    x += rhs.x;
    if (x >= Modulus) {
      x -= Modulus;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (x < rhs.x) {
      x += Modulus;
    }
    x -= rhs.x;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    x = x * rhs.x % Modulus;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    u64 n = Modulus - 2;
    while (n) {
      if (n & 1) {
        *this *= rhs;
      }
      rhs *= rhs;
      n /= 2;
    }
    return *this;
  }

  friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
    is >> rhs.x;
    return is;
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
    os << rhs.x;
    return os;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, X;
  cin >> N >> X;
  using mint = ModInt<1000000007>;
  vector<int> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  vector<vector<mint>> dp(N + 1, vector<mint>(X + 1, 0));
  for (int i = 0; i < X + 1; i++) {
    dp[0][i] = i;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < X + 1; j++) {
      dp[i + 1][j] = dp[i][j] * i + dp[i][j % S[i]];
    }
  }
  cout << dp[N][X] << '\n';
  return 0;
}


Measured memory_bytes: 158592
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int N = 16;
const int L = 6;
const int MAX_A = 366;
const int MAX_B = 9;
const int MAX_C = 7 * 7 * 7 * 7;

int D;
bool v[MAX_A][4][4], dp[MAX_A][MAX_B][MAX_C];

int vtoi(int *h){
  int res = 0;
  for(int i = 3; i >= 0; --i){
    res *= 7;
    res += h[i];
  }
  return res;
}

void itov(int c, int *h){
  REP(i, 4){
    h[i] = c % 7;
    c /= 7;
  }
}

int check(int d, int y, int x, int c){
  int h[4];
  itov(c, h);
  h[0] = (y == 0 && x == 0 ? 0 : h[0] + 1);
  h[1] = (y == 0 && x == 2 ? 0 : h[1] + 1);
  h[2] = (y == 2 && x == 0 ? 0 : h[2] + 1);
  h[3] = (y == 2 && x == 2 ? 0 : h[3] + 1);
  REP(i, 4) if(h[i] >= 7) return -1;
  REP(i, 2) REP(j, 2) if(v[d][y + i][x + j]) return -1;
  return vtoi(h);
}

int solve(){
  if(v[0][1][1] || v[0][1][2] || v[0][2][1] || v[0][2][2]) return 0;
  memset(dp, 0, sizeof(dp));
  dp[0][4][400] = 1;
  REP(a, D - 1){
    REP(b, MAX_B){
      REP(c, MAX_C){
        if(!dp[a][b][c]) continue;
        int nc;
        if((nc = check(a + 1, b / 3, b % 3, c)) != -1) dp[a + 1][b][nc] = 1;
        for(int i = -1; i <= 1; ++i){
          for(int j = -1; j <= 1; ++j){
            if((i != 0 && j != 0) || (i == 0 && j == 0)) continue;
            int y = b / 3 + i, x = b % 3 + j;
            while(y >= 0 && y <= 2 && x >= 0 && x <= 2){
              if((nc = check(a + 1, y, x, c)) != -1) dp[a + 1][y * 3 + x][nc] = 1;
              y += i; x += j;
            }
          }
        }
      }
    }
  }
  bool res = 0;
  REP(i, MAX_B) REP(j, MAX_C) if(dp[D - 1][i][j]) res = 1;
  return res;
}

int main() {
  while(cin >>D && D){
    REP(i, D) REP(j, 4) REP(k, 4) cin >>v[i][j][k];
    cout <<solve() <<endl;
  }
    return 0;
}

Measured memory_bytes: 8900
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val H = Array.fill(N)(sc.nextInt())

    var max = H.head
    var count = 1
    H.tail.foreach { h =>
      if (h >= max) {
        max = h
        count += 1
      }
    }
    println(count)
  }

}


Measured memory_bytes: 25796
//=========================================c++
/* ===========================================
// 20.04.03 日立製作所 社会システム事業部 プログラミングコンテスト2020 - A. Hitachi String 
// 
// 
=========================================== */
/* ===========================================

content

=========================================== */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int (i)=1;(i)<=(n);i++)
#define rez(i,n) for(int (i)=0;(i)<(n);i++)
#define ET "\n"
#define CLR(arr) memset(&arr, 0, sizeof(arr))
#define PAIR pair<int, int>
#define UQ unique_ptr
#define MQ make_unique
const ll INF = 1LL << 50;
const int MINI = 10e5+5;

static struct GV{
    string input;
} gv;

void build(){
    cin >> gv.input;
}

void solve(){
    int slen = gv.input.length();
    if ((slen &1) == 1) {
        cout << "No" << ET;
        return;
    }
    
    for (int i = 0; i < slen; i+=2) {
        if (gv.input.substr(i,2) == "hi") {
            
        }
        else {
            cout << "No" << ET;
            return;
        }
    }
    
    cout << "Yes" << ET;
    return;
}

int main(){
    build();
    solve();
    
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	char s[5];
	scanf("%s",s);
	
	int i,j,a=0;
	for(i=0;i<4;i++){
		for(j=i+1;j<4;j++){
			if(s[i]==s[j]){
				a++;
				break;
			}
			
		}
	}
	
	if(a==2)
		printf("Yes");
	else
		printf("No");
	return 0;
}

				

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

int main(int argc, char **argv)
{
  char a[4],b[4];
  
  scanf("%s %s", a, b);
  
  int ans = 0;
  for (int i = 0; i < 3; ++i) ans += a[i] == b[i];
  printf("%d\n", ans);
  
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    double r;
    double are,circ;
    
    scanf("%lf",&r);
    are = r * r * 3.141592653589;
    circ = 2 * r * 3.141592653589;
    printf("%f %f\n",are,circ);
    return 0;
}


Measured memory_bytes: 2044
#include<stdio.h>

int main(){
  int arr[3], s, m , l, n;
  for(n=0;n<3;n++){
    scanf("%d",&arr[n]);
  }
  if(arr[0]>arr[1]){
     if(arr[0]<arr[2]){
      printf("%d %d %d\n",arr[1],arr[0],arr[2]);
     }else if(arr[1]>arr[2]){
       printf("%d %d %d\n",arr[2],arr[1],arr[0]);
     }else{
       printf("%d %d %d\n",arr[1],arr[2],arr[0]);
     }
   }else{
     if(arr[0]>arr[2]){
      printf("%d %d %d\n",arr[2],arr[0],arr[1]);
     }else if(arr[1]>arr[2]){
      printf("%d %d %d\n",arr[0],arr[2],arr[1]);
     }else{
      printf("%d %d %d\n",arr[0],arr[1],arr[2]);
     }
  }

  return 0;
}

Measured memory_bytes: 596
// 最大利益

#include <iostream>
using namespace std;

int main()
{
    int n, i, minv, maxv;

    cin >> n;
    cin >> minv;  // 1個目の要素
    cin >> i;     // 2個目の要素

    maxv = i - minv;
    if (minv > i) // これを忘れた
        minv = i;
    for (int j=2; j<n; j++) {
        int k, diff;
        cin >> k;
        diff = k - minv;
        if (diff > maxv)
            maxv = diff;
        if (minv > k)
            minv = k;
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3088
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static long slove(String p,long all){
        char m[]=p.toCharArray();
        for(int k=1;k<=p.length()/2;k++){
            for(int i=0;i<m.length;i++){
                if(i+2*k>=p.length())
                    break;
                else{
                    if(m[i]!=m[i+k]&&m[i+2*k]!=m[i+k]&&m[i]!=m[i+2*k]) {
                        all--;
                    }
                }
            }
        }
        return all;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        int a=sc.nextInt();
        String p=sc.next();
        int countR=0;
        int countG=0;
        int countB=0;
        char m[]=p.toCharArray();
        for(int i=0;i<m.length;i++){
            if(m[i]=='R')
                countR++;
            if(m[i]=='G')
                countG++;
            if(m[i]=='B')
                countB++;
        }
        long all=countB*countG;
        all*=countR;
        System.out.println(Main.slove(p,all));
    }
}


Measured memory_bytes: 35860
N, M, R = map(int, input().split())
towns = list(map(int, input().split()))
allEdges = [[float('inf') for i in range(N)] for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    allEdges[A-1][B-1] = C
    allEdges[B-1][A-1] = C

for k in range(N):
    for i in range(N):
        for j in range(N):
            allEdges[i][j] = min(allEdges[i][j], allEdges[i][k] + allEdges[k][j])

graph = [[float('inf') for i in range(R)] for j in range(R)]

for i in range(R):
    for j in range(R):
        graph[i][j] = allEdges[towns[i] - 1][towns[j] - 1]

dp = [[-1 for i in range(R)] for j in range(1 << R)]

def recurse(seen, cur):
    if seen == (1 << R) - 1:
        return 0
    if dp[seen][cur] != -1:
        return dp[seen][cur]
    
    cost = float('inf')
    for i in range(R):
        if seen & (1 << i) == 0:
            cost = min(cost, recurse(seen | (1 << i), i) + graph[cur][i])
    dp[seen][cur] = cost
    return dp[seen][cur]

cost = float('inf')
for i in range(R):
    cost = min(cost, recurse(1 << i, i))

print(cost)


Measured memory_bytes: 76248
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}

#define ll long long
#define f first
#define s second
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	// 入力
	string S;
	cin >> S;
	
	ll a=0,b=0,c=0;
	ll s=S.size();
	REP(i,s){
		if(S[i]=='a') a++;
		else if(S[i]=='b') b++;
		else c++;
	}

	if((s/3==a || s/3+1==a) && (s/3==b || s/3+1==b) && (s/3==c || s/3+1==c))
		cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    s=list(input())+['T']
    x,y=map(int,input().split())
    x+=16000
    y+=16000
    ud=[]
    lr=[]
    f=0
    f2=0
    c=0
    for t in s:
        if t=='F':
            if not f:
                x-=1
            else:
                c+=1
        else:
            f=1
            if c:
                if f2:
                    ud.append(c)
                else:
                    lr.append(c)
            c=0
            f2=not f2
    for l,z in [(ud,y),(lr,x)]:
        N=len(l)
        dp=[0]*(N+1)
        dp[0]=1<<16000
        for i in range(N):
            dp[i+1]|=dp[i]<<l[i]|dp[i]>>l[i]
        if not (dp[-1]>>z)&1:
            print('No')
            break
    else:
        print('Yes')
        
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 50396