akhauriyash/Code-Regression huggingface dataset:
def main():
    from collections import deque

    K = int(input())

    dq = deque()
    for x in range(1, 10):
        dq.append(x)

    idx = 0
    while dq:
        x = dq.popleft()
        idx += 1
        if idx == K:
            print(x)
            return

        r = x % 10
        if r > 0:
            dq.append(x * 10 + r - 1)
        dq.append(x * 10 + r)
        if r < 9:
            dq.append(x * 10 + r + 1)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


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

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

  if(a > b || a == b){
    for(int i=0;i<a;i++){
      cout << b;
    }
  }else if(b > a){
    for(int i=0;i<b;i++){
      cout << a;
    }
  }

  cout << endl;
}


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

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

    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    int D = 0;
    int ans = 0;
    for(int i=0;i<N;i++){
      D = D + L[i];
      if(D > X){
        ans = i+1;
        break;
      }
    }

    cout << (ans == 0 ? N + 1 : ans) << endl;
}

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

int main() {
  int a;
  cin>>a;
  int d=0;
  vector<string> b(a);
  vector<int> c(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i)>>c.at(i);
  }
  string e;
  cin>>e;
  for(int i=a-1;i>=0;i--){
    if(b.at(i)==e){
      break;
    }
    d+=c.at(i);
  }
  cout<<d<<endl;
}

Measured memory_bytes: 256
N = gets.to_i
MOD = 10 ** 9 + 7
dp = Array.new(N + 1) { Hash.new { 0 } }
dp[0][''] = 1

def included_agc(cs)
  return false if cs.size <= 2
  return true if cs[-3..-1].join('') == 'AGC'
  (0..(cs.size - 2)).any? do |i|
    ts = cs.dup
    t = ts[i + 1]
    ts[i + 1] = ts[i]
    ts[i] = t
    ts.join('').include?('AGC')
  end
end

N.times do |i|
  dp[i].keys.each do |s|
    ss = s.chars
    %w[A C G T].each do |ch|
      new_ss = ss + [ch]
      unless included_agc(new_ss)
        new_s = if new_ss.size <= 2
          new_ss.join('')
        else
          new_ss[-3..-1].join('')
        end
        dp[i + 1][new_s] += dp[i][s] % MOD
      end
    end
  end
end
ans = dp[N].values.reduce(0) do |acc, n|
  (acc + n) % MOD
end
puts ans


Measured memory_bytes: 2684
def make_divisors(n):

    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()

    return divisors

def is_remainder(n):
    if n == 1:
        return True

    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    
    return True
        

A, B = [int(i) for i in input().split()]

import fractions
n = fractions.gcd(A, B)
divisors = make_divisors(n)
N = len(divisors)

count = 0
flag = [0] * N
for item in divisors:
    if is_remainder(item):
        count += 1

print(count)

Measured memory_bytes: 5300
import sys

def main():
    n, k = map(int, sys.stdin.buffer.readline().split())
    a = [0] + list(map(int, sys.stdin.buffer.readline().split()))

    visited = [0]*(n+1)
    town = 1
    for i in range(1, k+1):
        town = a[town]
        if visited[town] == 0:
            visited[town] = i
        else:
            cyc = (k - visited[town])%(i - visited[town]) + visited[town]
            print(visited.index(cyc))
            exit()
    print(town)

if __name__ == "__main__":
    main()

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

int N;
int d[110];
int ans,list;

int main (){

	cin >> N;
    	
  	for(int i = 0 ; i < N ;i++)cin >> d[i];
  	
  	sort(d,d+N);
  	
  	ans = 1;
  	list = d[0];
  
  	for(int i = 1; i< N;i++){
      
    	if(d[i] != list){
          
        	list = d[i];
          	ans++;
          
        }
      
    }
  	
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

vector<ll> Factorial(ll M, ll MOD){
    vector<ll> result = vector<ll>(M + 1);
    for(int i = 0; i <= M; i++){
        if(i == 0){
            result[i] = 1;
        }else{
            result[i] = result[i-1] * i % MOD;
        }
    }
    return result;
}

vector<ll> InvFact(ll M, ll MOD){
    vector<ll> result = vector<ll>(M + 1);
    vector<ll> inv = vector<ll> (M + 1);
    result[0] = 1;
    result[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < M; i++){
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        result[i] = result[i - 1] * inv[i] % MOD;
    }
    return result;
}

ll Combination(ll n,ll k,vector<ll>& fact, vector<ll>& invFact,ll MOD){
    //nCkを計算する
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
}

int main() {
    ll n,m;
    cin >> n >> m;
    ll x[n];
    ll y[m];
    ll Ex[n-1];
    ll Ey[m-1];

    ll MOD = 1000000007;
    auto fact = Factorial(100000,MOD);
    auto invFact = InvFact(100000,MOD);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < n-1; ++i) {
        Ex[i] = x[i + 1] - x[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> y[i];
    }
    for (int i = 0; i < m-1; ++i) {
        Ey[i] = y[i + 1] - y[i];
    }
    ll sumX = 0;
    ll sumY = 0;
    for (int i = 0; i < n - 1; ++i) {
        sumX += (((Ex[i] * (i + 1)) % MOD) * (n - i - 1)) %MOD;
        sumX %= MOD;
    }
    for (int i = 0; i < m - 1; ++i) {
        sumY += ((Ey[i] * (i + 1))%MOD * (m - i - 1)) % MOD;
        sumY %= MOD;
    }

    cout << (sumX * sumY) % MOD << endl;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	cout << (int)pow(n,3) << endl;
	return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    vi a(n);
    rep(i, n) a[i] = i + 1;
    map<vi, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(all(a)));
    cout << abs(mp[p]-mp[q]) << endl;
    return 0;
}



Measured memory_bytes: 5248
#!/usr/bin/env python3

import sys

input = iter(sys.stdin.read().splitlines()).__next__

sys.setrecursionlimit(10000)

R = int(input())

res = -1
if R <= 599:
   res = 8
elif R <= 799:
   res = 7
elif R <= 999:
   res = 6
elif R <= 1199:
   res = 5
elif R <= 1399:
   res = 4
elif R <= 1599:
   res = 3
elif R <= 1799:
   res = 2
elif R <= 1999:
   res = 1

   
print(res)


Measured memory_bytes: 9212
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADontBeLate solver = new ADontBeLate();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADontBeLate {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int d = Integer.parseInt(in.next());
            int t = Integer.parseInt(in.next());
            int s = Integer.parseInt(in.next());
            boolean ok = true;
            if (d > t * s) ok = false;
            out.println(ok ? "Yes" : "No");

        }

    }
}



Measured memory_bytes: 35660
#include<iostream>
using namespace std;
int main(){
	string s1,s2;
  	cin >> s1 >> s2;
  	if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0]){
    	cout << "YES\n";
    }
  	else{
    	cout << "NO\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll MOD = 1e9 + 7;

class Combination {
    //a^p%mod
    ll powmod(ll a, ll p) {
        ll ans = 1LL;
        ll mul = a;
        // p >>=1 <-> p=(p >> 1)
        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    ll mod;
    vector<ll> fact;
    vector<ll> revFact;

    Combination(int n, ll m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    ll get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

ll powmod(ll a, ll b){
    ll ret = 1;
    ll c = a;
    while(b > 0){
        if(b % 2 == 1){
            ret *= c;
            ret %= MOD;
        }

        c = (c * c) % MOD;
        b /= 2;
    }

    return ret;
}

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

    Combination cm = Combination(K + 5, MOD);

    ll ans = 0;
    for(int i = 1; i < K; i++){
        ll tmp = 1;

        tmp *= cm.get(K, i);
        tmp %= MOD;
        tmp *= powmod(K - i, N);
        tmp %= MOD;

        if(i % 2 == 0){
            ans -= tmp;
            ans += MOD;
            ans %= MOD;
        } else {
            ans += tmp;
            ans %= MOD;
        }
    }

    ans = powmod(K, N) - ans + MOD;
    ans %= MOD;

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



Measured memory_bytes: 3136
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] s = new int[N];

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

			s[i] = sc.nextInt();
		}

		int i = 0;

		int ans = 0;

		while(i<N-1) {

			if(s[i] == s[i+1]) {

				ans++;

				i+=2;

			}else {
				i++;
			}

		}

		System.out.println(ans);
	}

}


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

int main(){
    int n;
    cin>>n;
    int ans;
    for(int i=9; i>0; i--){
        if(i*100+i*10+i>=n)ans=i*100+i*10+i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
ans_temp = 10**5
ans = 0
for i in range(n):
    temp = t - h[i] * 0.006
    if abs(a - ans_temp) > abs(a - temp):
        ans_temp = temp
        ans = i
print(ans + 1)

Measured memory_bytes: 3064
#include <iostream>
#include <stdlib.h>
#include <string>
#include <math.h>
#include<algorithm>

using namespace std;

int main(void)
{
    string number;
    cin >> number;
    int a,b,c,d;
    a = number[0] - '0';
    b = number[1] - '0';
    c = number[2] - '0';
    d = number[3] - '0';
    //cout << a << b << c << d;
    for (int i = 0; i <=1 ; i++)
     for (int j = 0; j <=1 ; j++)
      for (int k = 0; k <=1 ; k++)
      {
         int sum = 0;
         string answer;
         answer[0] = number[0];
         answer[2] = number[1];
         answer[4] = number[2];
         answer[6] = number[3];
         answer[7] = '=';
         answer[8] = '7';
         sum = sum + a;
         if (i == 0)
         {
         sum = sum + b;
         answer[1] = '+';
         }
         else
         {
         sum = sum - b;
         answer[1] = '-';
         }
         if (j == 0)
         {
         sum = sum + c;
         answer[3] = '+';
         }
         else
         {
         sum = sum - c;
         answer[3] = '-';
         }
         if (k == 0)
         {
         sum = sum + d;
         answer[5] = '+';
         }
         else
         {
         sum = sum - d;
         answer[5] = '-';
         }
         //cout << sum << endl;
         //cout << answer << "____" << endl;
         if (sum == 7)
         {
             for (i = 0; i <= 8; i++)
             cout << answer[i];
             return 0;
         }
      }
    return 0;
}

Measured memory_bytes: 256
void main()
{
    string s = rdStr;

    long n = 2019;
    long len = s.length;
    long[] dp1 = new long[n];
    long[] dp2 = new long[n];
    long result;
    foreach (x; s)
    {
        long m = x - '0';
        ++dp1[m];
        foreach (j; 0 .. n)
        {
            dp1[(10*j+m)%n] += dp2[j];
        }
        result += dp1[0];
        dp2[] = dp1[];
        dp1[] = 0;
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 3076
#include<stdio.h>
int main(void)
{
    int n,a[10],s,j,i,flg;
	while(1){
	    for(i=0;i<10;i++) a[i]=0;
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
		    scanf("%d",&s);
			a[s]++;
		}
		for(i=0;i<10;i++){
		    flg=0;
			for(j=0;j<a[i];j++){
			    printf("*");
				flg=1;
			}
			if(flg==0) printf("-");
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2504
#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

#[fastout]
fn main() {
    input! {
        N: usize,
    }

    let ans = N / 3;
    println!("{}", ans);
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll mod = 1e9 + 7;
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    reps(i, k, n + 2) {
        ll minv = (0 + (i - 1)) * i / 2;
        ll maxv = ((n - i + 1) + n) * i / 2;
        ans = (ans + max(0LL, maxv - minv + 1)) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define ll long long
const int N = 2e6 + 15;
int main(){
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << "\n";
	return 0;
}


Measured memory_bytes: 256
// ABC049_C
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    string str;
    cin >> str;
    
    // calculation
    string five, six, seven;
    unsigned long len = str.length();
    
    if (len < 5) {
        cout << "NO" << "\n";
        return 0;
    } else if (len == 5) {
        if (str == "dream" || str == "erase") {
            cout << "YES" << "\n";
            return 0;
        } else {
            cout << "NO" << "\n";
            return 0;
        }
    } else if (len == 6) {
        if (str == "eraser") {
            cout << "YES" << "\n";
            return 0;
        } else {
            cout << "NO" << "\n";
            return 0;
        }
    } else if (len == 7) {
        if (str == "dreamer") {
            cout << "YES" << "\n";
            return 0;
        } else {
            cout << "NO" << "\n";
            return 0;
        }
    } else {
        while (str.length() != 0) {
            five = str.substr(str.size()-1 -4, 5);
            if (five == "dream" || five == "erase") {
                str.erase(str.end()-5, str.end());
            } else {
                six = str.substr(str.size()-1 -5, 6);
                if (six == "eraser") {
                    str.erase(str.end()-6, str.end());
                } else {
                    seven = str.substr(str.size()-1 -6, 7);
                    if (seven == "dreamer") {
                        str.erase(str.end()-7, str.end());
                    } else {
                        cout << "NO" << "\n";
                        return 0;
                    }
                }
            }
        }
        cout << "YES" << "\n";
        return 0;
    }
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			String S = scan.next();
			String T = scan.next();
			
			String t = T.substring(0, T.length()-1);
			
			
			System.out.println(S.equals(t)?"Yes":"No");
			
		}
		
		
	}
		

}


Measured memory_bytes: 35680
#!/usr/bin/python

import sys

def overlap(source, target):
    n = 0
    for s, t in zip(source, target):
        if s == 1 and s == t:
            n += 1
    return n

def main(argv):
    line = sys.stdin.readline()
    while line:
        n = int(line.rstrip("\n"))
        f = []
        for i in xrange(n):
            f.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))
        p = []
        for i in xrange(n):
            p.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))

        max_profit = -10**7 * n - 1
        for index in xrange(1, 2**10):
            b = map(lambda x: int(x), bin(index)[2:].zfill(10))

            profit = 0
            for i in xrange(n):
                c = overlap(b, f[i])
                profit += p[i][c]

            if profit > max_profit:
                max_profit = profit

        print max_profit

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
long long a[200010];
int main(){
	long long n,s,t=1,ans=0;
	int i;
	scanf("%lld",&n);
	scanf("%lld",&s);
	a[0]=s;
	for (i=1;i<n;i++)
	  scanf("%lld",&a[i]);
	i=1;
	long long k=0;
	ans=1;
	while (i<n)
	{
	  if ((s^a[i])==s+a[i])
	  {
	  	s^=a[i];
	  	i++;
	  	t++;
	  	ans+=t;
	  	k=0;
	  } else
	  {
	  	s-=a[i-t];
	  	t--;
	  	k=1;
	  }
	    
    }
    printf("%lld",ans);
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
 
int main(void){
 int N, M;
 int i, j, k, l;
 int flag;
 char **A, **B;
 char ex;
 scanf("%d%d%c", &N, &M, &ex);
 A = (char **)malloc(sizeof(char *)*N);
 for(i = 0; i < N; i++) A[i] = (char *)malloc(N);
 B = (char **)malloc(sizeof(char *)*M);
 for(i = 0; i < M; i++) B[i] = (char *)malloc(M);
 for(i = 0; i < N; i++){
  for(j = 0; j < N; j++) A[i][j] = getchar();
  getchar();
 }
 for(i = 0; i < M; i++){
  for(j = 0; j < M; j++) B[i][j] = getchar();
  getchar();
 }
 
 for(i = 0; i <= N - M; i++){
  for(j = 0; j <= N - M; j++){
   flag = 1;
   for(k = 0; k < M; k++){
    for(l = 0; l < M; l++){
     if(A[k + i][l + j] != B[k][l]) flag = 0;
    }
   }
   if(flag){
    printf("Yes\n");
    return 0;
   }
  }
 }
 printf("No\n");
 return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3

from functools import lru_cache

NMAX = 50

@lru_cache(maxsize=1)
def get_sizes():
    res = [1]
    for i in range(1, NMAX + 1):
        res.append(res[-1] * 2 + 3)
    return tuple(res)

@lru_cache(maxsize=1000)
def eat_m_layers_of_level_k(k, m, si):
    assert 0 < m <= si[k]
    if k == 0:
        pats = 1
        buns = 0
    else:
        sublev = si[k - 1]
        pp, bb = eat_m_layers_of_level_k(k - 1, si[k - 1], si)
        if m == 1:
            pats = 0
            buns = 1
        elif 1 < m <= 1 + sublev:
            p, b = eat_m_layers_of_level_k(k - 1, m - 1, si)
            pats = p
            buns = b + 1
        elif m == 2 + sublev:
            pats = pp + 1
            buns = bb + 1
        elif 2 + sublev < m <= 2 + 2 * sublev:
            p, b = eat_m_layers_of_level_k(k - 1, m - si[k - 1] - 2, si)
            pats = pp + p + 1
            buns = bb + b + 1
        elif m == si[k]:
            pats = 2 * pp + 1
            buns = 2 * bb + 2
        else:
            raise ValueError
    return pats, buns

def main():
    n, x = map(int, input().split())
    si = get_sizes()
    p, b = eat_m_layers_of_level_k(n, x, si)
    print(p)

main()


Measured memory_bytes: 4068
import collections
N = int(input())

O = []
E = []
A = list(map(lambda a: int(a), input().split(" ")))
for i in range(N):
  if i % 2 == 0:
    E.append(A[i])
  else:
    O.append(A[i])

CE = collections.Counter(E)
CO = collections.Counter(O)
CE2 = CE.most_common(2)
CO2 = CO.most_common(2)
if CE2[0][0] != CO2[0][0]:
  print(len(E) + len(O) - CE2[0][1] - CO2[0][1])
elif CE2[0][0] == CO2[0][0]:
  if len(CE2) == 1 and len(CO2) == 1:
    print(min([CE2[0][1], CO2[0][1]]))
  elif len(CE2) > 1 and len(CO2) == 1:
    print(len(E) + len(O) - CE2[1][1] - CO2[0][1])
  elif len(CE2) == 1 and len(CO2) > 1:
    print(len(E) + len(O) - CE2[0][1] - CO2[1][1])
  elif CE2[0][1] + CO2[1][1] > CO2[0][1] + CE2[1][1]:
    print(len(E) + len(O) - CE2[0][1] - CO2[1][1])
  elif CE2[0][1] + CO2[1][1] <= CO2[0][1] + CE2[1][1]:
    print(len(E) + len(O) - CE2[1][1] - CO2[0][1])
    

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, m; cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  vector<int> c = convolution(a, b);
  for (int i = 0; i < c.size(); i++) cout << c[i] << " ";
  cout << endl;
}


Measured memory_bytes: 19012
#include <iostream>

int main(){
	int w;
	while(std::cin >> w, w+1){
		int p = 1150;
		if(w > 30)p += 2650 + (w-30) * 160;
		else if(w > 20)p += 1250 + (w-20) * 140;
		else if(w > 10)p += (w-10) * 125;
		std::cout << 4280 - p << std::endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, k, r, s, p;
string t;
int main() {
    cin>>n>>k>>r>>s>>p>>t;

    // グー：r、チョキ：s、パー：p
    // rsrpr
    // prrsp
    string player="";
    map<char, char> win;
    win['r']='p';
    win['s']='r';
    win['p']='s';
    REP(i, 0, k){
        player+=win[t[i]];
    }
    REP(i, k, n){
        if(player[i-k]==win[t[i]]){
            player+='*';
        }
        else{
            player+=win[t[i]];
        }
    }

    ll ans=0;
    REP(i, 0, n){
        if(player[i]=='r') ans+=r;
        else if(player[i]=='s') ans+=s;
        else if(player[i]=='p') ans+=p;
    }

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

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

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

	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int pos = 0;
	int ans = 0;
	while (pos < n) {
		if (pos == n - 1) {
			ans++;
			break;
		}
		int x, y;
		for (int i = pos + 1; i < n; i++) {
			if (a[i] <= a[i-1]) {
				x = i;
			} else {
				break;
			}
		}
		for (int i = pos + 1; i < n; i++) {
			if (a[i] >= a[i-1]) {
				y = i;
			} else {
				break;
			}
		}
		pos = max(x, y) + 1;
		ans++;
// printf("ans %d x %d y %d pos %d\n", ans, x, y, pos);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            int r = int.Parse(Console.ReadLine());

            if(r<1200)
            {
                Console.WriteLine("ABC");
            }
            else if(r<2800)
            {
                Console.WriteLine("ARC");
            }else
            {
                Console.WriteLine("AGC");
            }
        }


    }
}


Measured memory_bytes: 13140
def main():
    X = int(input())
    DP = [0 for _ in range(100001)]

    for j in range(100, 106):
        DP[j] = 1

    for i in range(100001):
        for j in range(100, 106):
            idx = i - j
            if idx >= 0 and DP[idx] == 1:
                DP[i] = 1

    print(DP[X])
if __name__ == '__main__':
    main()


Measured memory_bytes: 3864
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

sum_max = sum(p[0:k])
sum_temp = sum_max

for i in range(n-k):
     sum_temp = sum_temp - p[i] + p[i+k]
     if sum_temp > sum_max:
         sum_max = sum_temp

s_max = (sum_max + k) / 2

print(s_max)

Measured memory_bytes: 25188
import java.io.*;
 
public class Main{
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        int n, h;
 
        while(true){
            str = br.readLine();
            if(str.equals("-")){
                break;
            }
            n = Integer.parseInt(br.readLine());
 
            for(int i = 0; i < n; i++){
                h = Integer.parseInt(br.readLine());
                StringBuilder sb = new StringBuilder();
                sb.append(str.substring(h, str.length())).append(str.substring(0, h));
                str = sb.toString();
            }
            System.out.println(str);
        }
    }
}

Measured memory_bytes: 24396
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define bit(n,m)((n>>m)&1)
#define minz(p,q)((p)&&(p<q)?(p):(q))

ll n,m,k;
int dp[65536];
int que[65536],quecnt;
int h[20];
int a[110];
int v[110][110];

void f(int i){
	rep(j,0,k){
		ll s=0;
		rep(kkk,0,m)if(bit(i,kkk)&&a[v[h[kkk]][j]]!=-1)s|=1<<a[v[h[kkk]][j]];
		if(!dp[s]){
			if(s==0){
				printf("%d\n",dp[i]);
				exit(0);
			}
			dp[s]=dp[i]+1;
			que[quecnt++]=s;
		}
	}
}

int main(){
	scanf("%lld%lld%lld",&n,&m,&k);
	rep(i,0,n)a[i]=-1;
	rep(i,0,m){
		scanf("%lld",h+i);
		a[--h[i]]=i;
	}
		
	rep(i,0,n)rep(j,0,k){
		scanf("%lld",&v[i][j]);
		v[i][j]--;
	}

	dp[(1<<m)-1]=1;
	que[quecnt++]=(1<<m)-1;
	rep(i,0,quecnt)f(que[i]);
}


Measured memory_bytes: 2404
#include<bits/stdc++.h>
using namespace std;
#define  mem(a,x) memset(a,x,sizeof(a));
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n;
    int a[n+1],b[n+1],c[n+1];
    mem(c,0);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        c[a[i]]++;
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
        c[b[i]]++;
    }
    for(i=1;i<=n;i++)
    {
        if(c[i]>n)
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    reverse(b,b+n);
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            for(j=0;j<n;j++)
            {
                if(b[j]!=a[i] && b[i]!=a[j])
                {
                    swap(b[i],b[j]);
                    break;
                }
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<b[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 5992
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <string>
#include <iostream>

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

int n;
map<P,int> check;

int func(int fie,int x,int y){
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==x && j==y)continue;
			int cnt=0;
			for(int k=-1;k<=1;k++){
				for(int l=-1;l<=1;l++){
					if(k==0 && l==0)continue;
					int nx=i+k,ny=j+l;
					if(nx>=0 && nx<n && ny>=0 && ny<n){
						if(fie>>(ny*n+nx) & 1 || (nx==x && ny==y))cnt++;
					}
				}
			}
			if(cnt==3 || (cnt==2 && (fie>>(j*n+i) & 1)))res|=(1<<(j*n+i));
		}
	}
	return res;
}

int bfs(int fie,int s){
	queue<P> que;
	que.push(P(fie,s));
	check[P(fie,s)]=0;
	while(que.size()){
		P q=que.front();
		que.pop();
		if(q.first==0)return check[P(q.first,q.second)];
		int x=q.second%n,y=q.second/n;
		for(int i=-1;i<=1;i++){
			for(int j=-1;j<=1;j++){
				if(i==0 && j==0)continue;
				int nx=x+i,ny=y+j;
				if(nx>=0 && nx<n && ny>=0 && ny<n){
					if(q.first>>(ny*n+nx) & 1)continue;
					int nfie=func(q.first,nx,ny);
					if(check.find(P(nfie,ny*n+nx))==check.end()){
						check[P(nfie,ny*n+nx)]=check[P(q.first,y*n+x)]+1;
						que.push(P(nfie,ny*n+nx));
					}
				}
			}
		}
	}
	return -1;
}

int main(void){
	while(1){
		scanf("%d%*c",&n);
		if(n==0)break;
		int fie=0;
		int s=0;
		check.clear();
		for(int i=0;i<n;i++){
			string str;
			cin >> str;
			for(int j=0;j<n;j++){
				if(str[j]=='#')fie|=(1<<(i*n+j));
				if(str[j]=='@')s=i*n+j;
			}
		}
		printf("%d\n",bfs(fie,s));
	}
	return 0;
}

Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll h, w;
char a[101][101];
bool flag[101][101];
bool skip[101];
int main() {
    cin>>h>>w;
    REP(i, 0, h) REP(j, 0, w){
        cin>>a[i][j];
    }

    REP(i, 0, h){
        bool f=false;
        REP(j, 0, w){
            if(a[i][j]=='#') f=true;
        }

        if(!f){
            REP(j, 0, w) flag[i][j]=true;
            skip[i]=true;
        }
    }

    REP(j, 0, w){
        bool f=false;
        REP(i, 0, h){
            if(a[i][j]=='#') f=true;
        }

        if(!f){
            REP(i, 0, h) flag[i][j]=true;
        }
    }

    REP(i, 0, h){
        REP(j, 0, w){
            if(!flag[i][j]) cout<<a[i][j];
        }
        if(!skip[i]) cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 1000005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef map<ll, ll> Map;

int main(void) {
    ll N, K;
    cin >> N >> K;
    ll x, y;
    char c;
    ll i, j;
    ll cnt[4*K+2][4*K+2];
    ll sum[4*K+2][4*K+2];
    memset(cnt, 0, sizeof(cnt));
    memset(sum, 0, sizeof(sum));
    
    for(i=0; i<N; i++) {
        cin >> x >> y >> c;
        if(c=='W') {
            y+=K;
        }
        x%=2*K; y%=2*K;
        x++; y++;
        cnt[x][y]++;
        cnt[x][y+2*K]++;
        cnt[x+2*K][y]++;
        cnt[x+2*K][y+2*K]++;
    }
    
    
    
    
    for(i=1; i<=4*K; i++) {
        for(j=1; j<=4*K; j++) {
            sum[i][j]=cnt[i][j]+sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1];
        }
    }
    
    ll ans=0;
    for(i=1; i<=2*K; i++) {
        for(j=1; j<=2*K; j++) {
            ll sqr1=sum[i+K-1][j+K-1]-sum[i-1][j+K-1]-sum[i+K-1][j-1]+sum[i-1][j-1];
            ll sqr2=sum[i+2*K-1][j+2*K-1]-sum[i+K-1][j+2*K-1]-sum[i+2*K-1][j+K-1]+sum[i+K-1][j+K-1];
            ans=max(ans, sqr1+sqr2);
        }
    }
    
    prin(ans);
}

Measured memory_bytes: 250496
<?php
fscanf(STDIN, '%d %d', $N, $T);
$ans = 1001;
for ($i  = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d %d', $c, $t);
    if ($t <= $T) {
        $ans = min($c, $ans);
    }
}
if ($ans !== 1001) {
    echo $ans;
} else {
    echo 'TLE';
}

Measured memory_bytes: 4728
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,p[100000]={},ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> p[i];
  }
  for(int i=0; i<n; i++) {
    if(p[i]==i+1) {
      ans++,i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define all(L) L.begin(),L.end()
using ll=long long;
#define RO 1
#define SI 2
#define PA 3

int main(){
    int n;cin>>n;
    vector<int> L(n);
    rep(i,0,n) cin>>L[i];

    sort(all(L));
    
    ll count=0;
    rep(i,0,n-1){
        rep(j,i+1,n){
            int ab=L[i]+L[j];
            int h=j+1;
            while(ab>L[h]&&h<n){
                count++;
                h++;
            }
        }
    }

    cout<<count<<endl;
}    



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
  ll N, K;
  cin >> N >> K;
  vi A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  for (ll i = 0; i < N; i++) A[i]--;
  vi B(N + 1);
  for (ll i = 0; i < N; i++) B[i + 1] = B[i] + A[i];
  unordered_map<ll, vi> v;
  for (ll i = 0; i < N + 1; i++) {
    v[B[i] % K].push_back(i);
  }
  ll ans = 0;
  for (auto p: v) {
    queue<ll> q;
    for (auto i : p.second) {
      while (q.size() && i - q.front() >= K) q.pop();
      ans += q.size();
      q.push(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 21064
mark = ('S', 'H', 'C', 'D')
tr = {m:{i for i in range(1, 14)} for m in mark}
n = int(input())
for i in range(n):
    m, p = input().split()
    tr[m].remove(int(p))
for j in mark:
    for q in sorted(tr[j]):
        print(j, q)


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<double> p(n);
  for (int i = 0; i < n; i++) cin >> p.at(i);
  
  vector<vector<double>> dp(n + 1, vector<double>(n + 1));
  dp.at(0).at(0) = 1;
  
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (j == 0) dp.at(i).at(j) = dp.at(i - 1).at(j) * (1 - p.at(i - 1));
      else {
        dp.at(i).at(j) = dp.at(i - 1).at(j) * (1 - p.at(i - 1)) + dp.at(i - 1).at(j - 1) * p.at(i - 1);
      }
    }
  }
  
  double ans = 0;
  for (int j = n / 2 + 1; j <= n; j++) ans += dp.at(n).at(j);
  
  cout << fixed << setprecision(10) << ans << '\n';
}

Measured memory_bytes: 70784
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        //int n = stdIn.nextInt();
        //int p = stdIn.nextInt();
        
        System.out.println(Math.max(a + a - 1, Math.max(b + b - 1, a + b)));
        
        //System.out.println();
        //System.out.print();
    }
}


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

int main() {
	int w,i;
	int sum;
	while(1){
		cin>>w;
		sum=1150;
		if(w==-1) break;
		if(w>30) {
			sum+=(w-30)*160;
			w=30;
		}
		if(w>=20){
			sum+=(w-20)*140;
			w=20;
		}
		if(w>=10){
			sum+=(w-10)*125;
		}
		sum=4280-sum;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

int main() {
  ll n, m, r;
  cin >> n >> m >> r;

  vvP eds(n);
  vll d(n, INF);

  rep(i, m) {
    ll u, v, w;
    cin >> u >> v >> w;
    eds[u].push_back(P(v, w));
  }

  priority_queue<P, vP, greater<P>> q;
  q.push(P(0, r));
  d[r] = 0;
  while (!q.empty()) {
    P du = q.top();
    q.pop();
    ll u = du.second;
    for (P p : eds[u]) {
      ll v, w;
      tie(v, w) = p;
      if (d[u] + w < d[v]) {
        d[v] = d[u] + w;
        q.push(P(d[v], v));
      }
    }
  }

  rep(i, n) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 19348
h,w,d=map(int,input().split())

def dist(start,goal):
    return abs(start[0]-goal[0])+abs(start[1]-goal[1])

D={} 
for i in range(h) :
    tmp=list(map(int,input().split()))
    for j in range(w):
        D[tmp[j]]=[i,j]
q=int(input())
A=[]
for _ in range(q):
    A.append(list(map(int,input().split())))
B=[0 for i in range(h*w)]
for i in range(h*w):
    if i>=d:
        B[i]=B[i-d]+dist(D[i+1],D[i-d+1])
for [l,r] in A:
    ans=B[r-1]-B[l-1]
    print(ans)

Measured memory_bytes: 49696
import java.util.Scanner;

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

}


Measured memory_bytes: 26208
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

typedef double db;
db eps=1e-9;
struct point {
	db x,y;
	point() {}
	point(db x,db y):x(x),y(y) {}
	void input() { scanf("%lf%lf",&x,&y); }
	void output() { printf("%.10f %.10f\n",x,y); }
	db len() { return sqrt(x*x+y*y); }
	db len2() { return x*x+y*y; }
};
point operator + (const point &a,const point &b) { return point(a.x+b.x,a.y+b.y);}
point operator - (const point &a,const point &b) { return point(a.x-b.x,a.y-b.y);}
point operator * (const point &a,const db &b) { return point(a.x*b,a.y*b);}
point operator / (const point &a,const db &b) { return point(a.x/b,a.y/b);}
db dot(const point &a,const point &b) { return a.x*b.x+a.y*b.y; }
db det(const point &a,const point &b) { return a.x*b.y-a.y*b.x; }
struct line {
	point a,b;
	line() {}
	line(point a,point b):a(a),b(b) {}
};
point proj(const line &a,const point &b) {
	return a.a+(a.b-a.a)*dot(a.b-a.a,b-a.a)/(a.b-a.a).len2();
}
point reflect(const line &a,const point &b) {
	return proj(a,b)*2-b;
}
int dblcmp(db x) {
	return fabs(x)<eps?0:(x>0?1:-1);
}
int relation(const line &a,const point &b) {
	int x=dblcmp(det(a.b-a.a,b-a.a));
	if (x==1) return 0; // COUNTER_CLOCKWISE
	else if (x==-1) return 1; // CLOCKWISE
	else {
		x=dblcmp(dot(b-a.a,a.b-a.a));
		if (x<-eps) return 2; // ONLINE_BACK
		else {
			x=dblcmp(dot(b-a.b,a.b-a.a));
			if (x>eps) return 3; // ONLINE_FRONT
			else return 4; // ON_SEGMENT
		}
	}
}

int q;
int main() {
	point a,b;
	a.input(); b.input();
	line p(a,b);
	scanf("%d",&q);
	rep(i,0,q) {
		a.input();
		int x=relation(p,a);
		if (x==0) puts("COUNTER_CLOCKWISE");
		else if (x==1) puts("CLOCKWISE");
		else if (x==2) puts("ONLINE_BACK");
		else if (x==3) puts("ONLINE_FRONT");
		else puts("ON_SEGMENT");
	}
}

Measured memory_bytes: 2752