akhauriyash/Code-Regression huggingface dataset:
def solve():
  n = int(input())
  p = list(int(i) for i in input().split())
  ans = 0
  for i in range(n-2):
   query = [p[i],p[i+1],p[i+2]]
   query.sort()
   if query[1] == p[i+1]:
    ans += 1
  print(ans)
solve()

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

using namespace std;

#define endl "\n"
typedef long long int ll;

inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

ll INF = 1e10;
ll MOD = 1e9+7;

int n;
int a[21][21];

ll done[1<<21];

ll pairs(int state){
    int idx = __builtin_popcount(state);
    if(idx == n) return 1;
    if(done[state] != -1) return done[state];
    ll ans = 0;
    for(int i=0;i<n;++i)
        if(a[idx][i] && !(state&(1<<i)))
            ans = (ans + pairs(state|(1<<i)))%MOD;
    done[state] = ans;
    return ans;
}

int main(){
    fastio();
    cin>>n;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            cin>>a[i][j];
    memset(done, -1, sizeof(done));
    cout<<pairs(0);
    return 0;
}


Measured memory_bytes: 19944
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string ss;
    cin>>ss;
    for(int i=0;i<(int)ss.length();i++)
        if((i%2==0&&ss[i]!='h')||(i%2==1&&ss[i]!='i'))
        {
            puts("No");
            return 0;
        }
    if((int)ss.length()%2==1) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

N, *A = map(int, open(0).read().split())

S = [0] + list(accumulate(A))

memo = [[-1] * N for _ in range(N)]
def dp(L, R):
    if L == R:
        return 0
    if memo[L][R] >= 0:
        return memo[L][R]

    memo[L][R] = min(dp(L, c) + dp(c + 1, R) + S[R + 1] - S[L] for c in range(L, R))
    return memo[L][R]

print(dp(0, N - 1))

Measured memory_bytes: 46652
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

const int N=2e5+10;
int ar[N];
int cnt[N];
int ans=0;
int C2(int x)
{
	return (x*(x-1))/2;
}
int32_t main()
{
	fastio();
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>ar[i];cnt[ar[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		ans+=(cnt[i]*(cnt[i]-1))/2;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<ans-C2(cnt[ar[i]])+C2(cnt[ar[i]]-1)<<endl;
	}
	
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define m_p make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
map<vector<ll>,int> go; 
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> vl;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		vl.push_back(a);
	}
	map<ll,ll> mp;
	ll cnt = 0;
	vector<ll> used;
	ll zhouqi;
	ll left=0;
	for(int i=1;;)
	{
		if(mp[i]>0)
		{
			zhouqi = cnt-mp[i];
			left = mp[i];
			break;
		}
		mp[i] = cnt;
		cnt++;
		used.push_back(i);
		i = vl[i-1];
	}
	//cout<<"period:"<<zhouqi<<",left="<<left<<",k="<<k<<endl;
	//6 5 2 5 3 2
	//1->6->2->5->3->2->5->3->2
	if(zhouqi==0)
	{
		cout<<1<<endl;
		return 0;
	}
	if(k<left)
	{
		cout<<used[k]<<endl;
		return 0;
	}
	ll chu = (k-left)%zhouqi;
	cout<<used[chu+left]<<endl;
	return 0;
}


Measured memory_bytes: 18624
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {

    int K, X;
    cin >> K >> X;
    if (K * 500 >= X) 
        cout << "Yes\n";
    else 
        cout << "No\n";

}


Measured memory_bytes: 256
import std.stdio, std.typecons, std.string, std.conv;

enum D {up, bottom, left, right};

void show(char[][] field, int n) {
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      writef("%c", field[i][j]);
    }
    writeln;
  }
}

char[][] draw_spiral(char[][] field, int n) {
  D direction = D.up;
  int[] pos = [n - 1, 0];
  int len = n;
  bool first = true;
  foreach(ref f; field)
    foreach(ref x; f) x = ' ';
  if (n == 1) {field[0][0] = '#'; return field;}
  if (n == 2) {
    field[0][0] = '#';
    field[1][0] = '#';
    field[0][1] = '#';
    return field;
  }
  while(true) {
    switch(direction) {
    case D.up:
      if (len <= 2) goto end;
      for(int i = 0; i < len; i++) field[pos[0] - i][pos[1]] = '#';
      pos = [pos[0] - (len - 1), pos[1]];
      direction = D.right;
      if (!first) len -= 2;
      break;
    case D.right:
      if (len <= 1) goto end;
      for(int i = 0; i < len; i++) field[pos[0]][pos[1] + i] = '#';
      pos = [pos[0], pos[1] + (len - 1)];
      direction = D.bottom;
      break;
    case D.bottom:
      if (len <= 2) goto end;
      for(int i = 0; i < len; i++) field[pos[0] + i][pos[1]] = '#';
      pos = [pos[0] + (len - 1), pos[1]];
      direction = D.left;
      len -= 2;
      break;
    case D.left:
      if (len <= 1) goto end;
      for(int i = 0; i < len; i++) field[pos[0]][pos[1] - i] = '#';
      pos = [pos[0], pos[1] - (len - 1)];
      direction = D.up;
      break;
    default:
      throw new Exception("illegal direction");
      break;
    }
    if (first) first = false;
  }
 end:;
  return field;
}

int read_num() {return readln.chomp.to!(int);}

void main() {
  int n = read_num;
  foreach(i; 0..n) {
    int size = read_num;
    draw_spiral(new char[][](size, size), size).show(size);
    if (i != n - 1) writeln;
  }
}

Measured memory_bytes: 1064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        List<Tuple<long, long, long>> list = new List<Tuple<long, long, long>>();

        long maxH = 0;
        long maxX = 0;
        long maxY = 0;

        for (int i = 0; i < n; i++)
        {
            long x = sc.NextLong();
            long y = sc.NextLong();
            long h = sc.NextLong();
            if (h >= maxH)
            {
                maxH = h;
                maxX = x;
                maxY = y;
            }
            list.Add(Tuple.Create(x, y, h));
        }

        for (long x = 0; x <= 100; x++)
        {
            for (long y = 0; y <= 100; y++)
            {
                long h = maxH + Math.Abs(x - maxX) + +Math.Abs(y - maxY);
                bool ok = true;
                foreach (var item in list)
                {
                    if (item.Item3 != Math.Max(h - Math.Abs(x - item.Item1) - Math.Abs(y - item.Item2), 0))
                    {
                        ok = false;
                        break;
                    }
                }
                if (ok)
                {
                    Console.WriteLine(x + " " + y + " " + h);
                    return;
                }
            }
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27872
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class ModTools:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        # 階乗テーブル
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        # 階乗の逆元テーブル
        inverse = [1] * MAX
        # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, 0, -1):
            # 最後から戻っていくこのループならMAX回powするより処理が速い
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """

        if n < r: return 0
        # 10C7 = 10C3
        r = min(r, n-r)
        # 分子の計算
        numerator = self.fact[n]
        # 分母の計算
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

N, K = MAP()
A = LIST()

mt = ModTools(N, MOD)
A.sort()
# 各要素が最小・最大として何回使われるか数える
mncnt = [0] * N
for i in range(N):
    mncnt[i] = mt.nCr(N-i-1, K-1)
mxcnt = mncnt[::-1]

mnsm = 0
mxsm = 0
for i in range(N):
    mnsm += A[i] * mncnt[i]
    mxsm += A[i] * mxcnt[i]
    mnsm %= MOD
    mxsm %= MOD
ans = mxsm - mnsm
ans %= MOD
print(ans)


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

using namespace std;

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

    vector<int> arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];

    int q;
    cin>>q;

    while(q--)
    {
        int l,step,r;
        cin>>l>>step>>r;

        rotate(arr.begin()+l,arr.begin()+step,arr.begin()+r);
    }

    for(int i=0;i<n;i++) cout<<arr[i]<<(i==n-1?'\n':' ');

    return 0;
}



Measured memory_bytes: 3172
#include <iostream>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int n;
int w[400];
int dp[400][400];

// the maximum number of block can be removed
int cnt(int b, int t) {
    if (dp[b][t] >= 0) return dp[b][t];

    if (abs(w[t]-w[b])<=1 && cnt(b+1, t-1) == t-(b-1)-2) {
        return dp[b][t] = t-(b-1);
    }

    int output = 0;
    for(int i=b; i<=t-1; i++) {
        output = max(output, cnt(b, i)+cnt(i+1, t));
    }
    return dp[b][t] = output;
}

int main() {
    while(true) {
        cin >> n;
        if (n==0) break;

        REP(i, n) {
            cin >> w[i];
        }

        REP(i, n) {
            REP(j, n) {
                if (i==j) {
                    dp[i][j] = 0;
                } else if (j-i == 1){
                    if (abs(w[i] - w[j]) <= 1) {
                        dp[i][j] = 2;
                    } else {
                        dp[i][j] = 0;
                    }
                } else {
                    dp[i][j] = -1;
                }
            }
        }

        cout << cnt(0, n-1) << endl;
    }
}



Measured memory_bytes: 3584
#include <stdio.h>

int main() {
    int K, S;
    scanf("%d %d", &K, &S);

    if(S<K) {
        K = S;
    }

    int x=K, y, z;
    if(S>2*K) {
        y = K;
    } else {
        y = S - x;
    }

    z = S - x - y;

    int i, j, k, count=0;
    for(i=x; i>=0; i--) {
        k = z;
        for(j=y; j>=0; j--) {
            if((i<=K)&&(j<=K)&&(k<=K)) {
                count += 1;
            }
            k += 1;
        }
        y += 1;
    }

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


    return 0;

}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>

using namespace std;

const int MAXN=100010;
char s[MAXN];

int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	int ans=0;
	int start=1,end=len;
	while (start<end)
	{
		if (s[start]==s[end])
		{
			start++;
			end--;
		}
		else if (s[start]=='x')
		{
			ans++;
			start++;
		}
		else if (s[end]=='x')
		{
			ans++;
			end--;
		}
		else 
		{
			cout<<-1;
			return 0;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
	int i, mt[11];
	
	for(i=0; i<10; i++)	scanf("%d",&mt[i]);
	
	for(i=0; i<100; i++)
	{
		if(mt[i%10] < mt[(i%10)+1])
		{
			mt[10]=mt[i%10];
			mt[i%10]=mt[(i%10)+1];
			mt[(i%10)+1]=mt[10];
		}
	}
	
	for(i=0; i<3; i++)	printf("%d\n",mt[i]);
	
    return 0;
}

Measured memory_bytes: 600
import java.io.*;
import java.util.*;
import java.math.BigDecimal;
 
public class Main {
    public static long combination(int n, int r) {
        r = Math.min(r, n - r);
        if (r == 1) {
            return n;
        }
    
        long sum = 1;
        for (int i = 1; i <= r; i++) {
            sum = sum * (n - i + 1) / i;
        }
        return sum;
    }
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        ArrayList<Long> values = new ArrayList<Long>(n);
        
        for (int i = 0; i < n; i++) values.add(sc.nextLong());
        Collections.sort(values, Comparator.reverseOrder());
 
        //sum
        long ave = 0;
        for (int i = 0; i < a; i++){
            ave += values.get(i);
        } 
        System.out.println(BigDecimal.valueOf(ave / (double)a).toPlainString());
 
        //
        long border = values.get(a - 1);
        int num_border = values.lastIndexOf(border) - values.indexOf(border) + 1;
        
        long ans = 0;
        if (!values.get(0).equals(values.get(a - 1))){
            ans = combination(num_border, a - values.indexOf(border));
        }else{
            for (int i = a; i <= Math.min(b, num_border); i++){
                ans += combination(num_border, i);
            } 
        }
        System.out.println(ans);
    }
    
}

Measured memory_bytes: 25300
#include <stdio.h>

int n;
char s[120];
int abc1[30], abc2[30];

int contar(int mitad){
    int coin = 0;
    //printf("%d: ", mitad);
    for(int i=0; i<=mitad; i++)
        abc1[s[i]-'a'] += 1;

    for(int i=mitad+1; i<n; i++)
        abc2[s[i]-'a'] += 1;

    for(int i=0; i<30; i++){
        if(abc1[i] > 0 && abc2[i] > 0){
            coin += 1;
        }
        abc1[i] = 0;
        abc2[i] = 0;
    }
    //printf("%d\n", coin);
    return coin;
}

int main(){
    scanf("%d", &n);
    scanf("%s", s);
    int mx = 0, idx=0;

    for(int i=0; i<n; i++){
        int coinci = contar(i);
        if(coinci > mx)
            mx = coinci;
    }
    printf("%d\n", mx);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
	static int[][][] dp;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = Integer.MAX_VALUE;
		for (int i = 1; i <= n / 2; i++) {
			int a = n - i;
			int b = i;
			int sum = 0;
			while (a > 0) {
				sum += a % 10;
				a /= 10;
			}
			while (b > 0) {
				sum += b % 10;
				b /= 10;
			}
			if (min > sum) {
				min = sum;
			}
		}
		System.out.print(min);
	}
}


Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc086/submissions/2279952 にも参照
 */
public class Main {

	/** 白の定数 */
	private static final String WHITE = "W";

	/** 四角の差分を計算用 */
	private static final int[] X_DIFFS = { 0, 0, 1, 1, 1, 1, 2, 2 };
	private static final int[] Y_DIFFS = { 0, 1, 0, 1, 1, 2, 1, 2 };
	private static final int[] COUNT_DIFFS = { 1, -1, -1, 1, 1, -1, -1, 1 };

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int w = 4 * k + 1, k2 = 2 * k;
			int[][] count = new int[w][w];
			IntStream.range(0, w).forEach(i -> Arrays.fill(count[i], 0));
			IntStream.range(0, n).forEach(i -> {
				int x = scanner.nextInt(), y = scanner.nextInt();
				if (WHITE.equals(scanner.next())) {
					// 黒へ変換
					y += k;
				}
				x %= k2;
				y %= k2;
				for (int j = 0; j < X_DIFFS.length; j++) {
					count[x + X_DIFFS[j] * k][y + Y_DIFFS[j] * k] += COUNT_DIFFS[j];
				}
			});
			// 横方向への累積和
			IntStream.range(0, w).forEach(i -> IntStream.range(1, w).forEach(j -> count[i][j] += count[i][j - 1]));
			// 縦方向への累積和
			IntStream.range(1, w).forEach(i -> IntStream.range(0, w).forEach(j -> count[i][j] += count[i - 1][j]));
			// 2k x 2k 範囲を超えたcountを2k x 2k範囲に加算
			IntStream.range(0, w).forEach(i -> IntStream.range(0, w).filter(j -> (i >= k2) || (j >= k2))
					.forEach(j -> count[i % k2][j % k2] += count[i][j]));
			// 2k x 2k 範囲の最大値を出力
			System.out.println(IntStream.range(0, k2)
					.map(i -> IntStream.range(0, k2).map(j -> count[i][j]).max().getAsInt()).max().getAsInt());
		}
	}
}


Measured memory_bytes: 133712
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
	string s,t;
	cin>>s>>t;
	ll n=sz(s);
	ll f=1;
	rep(i,0,n) if(s[i]!=t[i]) f=0;
	if(f)cout<<"Yes\n";
	else cout<<"No\n";;
}	
signed main()
{
	
		/***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
		
	}
	TIME
	return 0;
}

Measured memory_bytes: 3840
#!/usr/bin/python3
from collections import defaultdict
from heapq import heappush, heappop

inf = float('inf')

def inf_matrix(n):
    return [[inf for i in range(n)] for j in range(n)]

def dijkstra(r, w, V):
    result = [inf] * V
    q = []
    heappush(q, (0, r))
    result[r] = 0
    while len(q) > 0:
        min_w, min_next = heappop(q)
        for weight, nxt in w[min_next]:
            if result[nxt] > min_w + weight:
                result[nxt] = min_w + weight
                heappush(q, (min_w + weight, nxt))

    return result


def main():
    V, E, r = map(int, input().split())
    w = defaultdict(list)
    for e in range(E):
        s, t, d = map(int, input().split())
        w[s].append((d, t))

    result = dijkstra(r, w, V)
    for i in range(V):
        if result[i] == inf:
            print('INF')
        else:
            print(result[i])

main()

Measured memory_bytes: 102476
def main():

    N = input()
    D = list(map(int,input().split()))
    M = max(D)
    countlist=[0] * (M + 1)
    ans=1

    for i in D:
        countlist[i]+=1

    if countlist[0]!=1 :
        ans = 0
    else :
        if D[0]!=0 :
            ans = 0
        else:
            for i in range(2,M+1):
                ans = ans * (countlist[i-1]**countlist[i]) % 998244353

    print(ans) 

if __name__ == "__main__":
    main()

Measured memory_bytes: 13908
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami,mado[100];
	bool gg = false;
	int manji, nk[26] = {false};
	cin >> a;
	if (a >= 2) {
		if (a >= 4) {
			if (a >= 8 ) {
				if (a >=16) {
					if (a >= 32  ) {
						if (a >= 64) {
							cout << "64" << endl;
							return 0;
						}
						cout << "32" << endl;
						return 0;
					}
					cout << "16" << endl;
					return 0;
				}
				cout << "8" << endl;
				return 0;
			}
			cout << "4" << endl;
			return 0;
		}
		cout << "2" << endl;
		return 0;
	}
	cout << "1" << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
X = sorted(list(map(int, input().split())))

dist = []
for i in range(m-1):
    dist.append(X[i+1]-X[i])
dist = sorted(dist, reverse=True)
if n >= m:
    print(0)
else:
    print(sum(dist[n-1:]))


Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define FRU                                  freopen("out.txt","w",stdout);
#define FRO                                  freopen("in.txt","r",stdin);
#define pb                                   push_back
#define pf                                   push_front
#define ppb                                  pop_back()
#define ppf                                  pop_front()
#define mp                                   make_pair
#define ff                                   first
#define ss                                   second
#define flash                                ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mem(ara,n)                           memset(ara,n,sizeof ara)
#define fr(i,j,n)                            for(i=j;i<n;i++)
#define rf(i,j,n)                            for(i=n;i>=j;i--)
#define inf                                  2147483647
#define ll                                   long long
#define ull                                  unsigned long long
#define pii                                  pair<int,int>
#define vi                                   vector<int>
#define vll                                  vector <long long>
#define vch                                  vector <char>
#define itr                                  ::iterator
#define msi                                  map<string,int>
#define psi                                  pair <string,int>
#define vii                                  vector <pair<int,int> >
#define all(n)                               n.begin(),n.end()
#define INF                                  10000000000000000LL
#define pi                                   3.1415926535897932384626434
#define sii                                  set <int>
#define max3(a,b,c)                          max(a,max(b,c))
#define min3(a,b,c)                          min(a,min(b,c))
#define mid3(a,b,c)                          min(max(a,b),max(b,c),max(a,b))
#define max4(a,b,c,d)                        max(max(a,b),max(c,d))
#define min4(a,b,c,d)                        min(min(a,b),min(c,d))
#define endl                                 '\n'
#define endll                                cout<<"\n";
#define spc                                  ' '
#define ld                                   long double

using namespace std;



int main()
{
    flash
    string s,st;
    ll n,t,T,i,j,J,I,k,m;
    char ch;
    cin>>n;
    m=0;
    fr(i,1,n+1)
    {
        if(i%3==0||i%5==0)  continue;
        m+=i;
    }
    cout<<m;
    return 0;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n;
	cin >> n;
	int a[n];
	set<int> st;
	rep(i, n) {
		cin >> a[i];
		st.insert(a[i]);
	}
	int k = st.size();
	if(k % 2 == 0) cout << k - 1 << endl;
	else cout << k << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
ll n,m,ans=0;

int main(int argc,char const* argv[])
{
  cin >> n >> m;
  ans=n*m;
  if(n>=2)
    {
      ans-=2*m;
    }
  if(m>=2)
    {
      ans-=2*n;
    }
  if(n!=1 && m!=1)
    {
      ans+=4;
    }
  cout << ans <<  endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		String s = fs.next();
		
		System.out.println(s.replaceAll("2017", "2018"));
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32908
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) a[i] = scanner.nextInt();

        for (int i = 1; i <= n; i++) {
            int parent = calcParentIndex(i);
            int left = calcLeftIndex(i);
            int right = calcRightIndex(i);
            StringBuilder sb = new StringBuilder();
            sb.append("node " + (i) + ": " );
            sb.append("key = " + a[i] + ", ");
            if (parent >= 1) sb.append("parent key = " + a[parent] + ", ");
            if (left <= n) sb.append("left key = " + a[left] + ", ");
            if (right <= n) sb.append("right key = " + a[right] + ", ");
            System.out.println(sb.toString());
        }

    }

    private static int calcParentIndex(int i) {
        return i / 2 ;
    }

    private static int calcLeftIndex(int i) {
        return 2 * i;
    }

    private static int calcRightIndex(int i) {
        return 2 * i + 1;
    }
}



Measured memory_bytes: 27868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

vector<int> divisor(int x)
{
    vector<int> ret;
    for(int i=1; i*i<=x; ++i)
    {
        if(x%i==0)
        {
            ret.pb(i);
            if(i!=x/i) ret.pb(x/i);
        }
    }
    sort(all(ret));
    return ret;
}

int solve()
{
    int n;
    cin >>n;
    vector<int> s(n);
    rep(i,n) cin >>s[i];

    for(int cycle:divisor(n))
    {
        bool ok = true;
        rep(i,cycle)
        {
            for(int j=i; j<n; j+=cycle) ok &= (s[i]==s[j]);
        }
        if(ok) return n/cycle;
    }

    return 1;
}

int main()
{
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

bool prime(ll n)
{
	if(n<=1)return false;
	if(n<=3)return true;
	if(n%2==0||n%3==0)return false;
	for(ll i=5;i*i<=n;i+=6)
	{
		if(n%i==0||n%(i+2)==0)return false;
	}
	return true;
}

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)r=(r*a)%m;
		b = b>>1;
		a=(a*a)%m;
	}
	return r%m;
}

ll addmod(ll a,ll b)
{
    if(a+b<mod)return a+b;
    else return a+b-mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll modinv(ll a)
{
    return modexp(a,mod-2,mod);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n; cin>>n;
	ll x,y; cin>>x>>y;
	vi ans(n);
	ans[1] = n;
	for(ll len = 2;len<=n-1;len++)
    {
        for(ll i =1;i+len<=n;i++)
        {
            if(i+len<=x)ans[len]++;
            else if(i+len>x&&i+len<y)
            {
                ll pos = y-i-len+1+fabs(x-i);
                pos = min(pos,len);
                if(pos==1)continue;
                ans[pos]++;
            }
            else
            {
                ll pos = fabs(i-x)+1+fabs(len+i-y);
                pos= min(pos,len);
                if(pos==1)continue;
                ans[pos]++;
            }
        }
        //for(ll i =1;i<=n-1;i++)cout<<ans[i]<<" ";
        //cout<<endl;
    }
    for(ll i =1;i<=n-1;i++)cout<<ans[i]<<endl;
	return 0;
}
/*
6
1 2 3 4 5 -6
*/


Measured memory_bytes: 256
import java.io.{BufferedReader, IOException, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{min, max, abs}

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val K = sc.nextInt()

    val x = Array.ofDim[Long](N)
    val y = Array.ofDim[Long](N)
    (0 until N) foreach { i =>
      x(i) = sc.nextLong()
      y(i) = sc.nextLong()
    }

    var ans = Long.MaxValue
    for {
      x0 <- x.indices
      x1 <- x.indices
      y0 <- y.indices
      y1 <- y.indices
    } {
      val min_x = min(x(x0), x(x1))
      val max_x = max(x(x0), x(x1))
      val min_y = min(y(y0), y(y1))
      val max_y = max(y(y0), y(y1))
      val k = (0 until N) count { i =>
        min_x <= x(i) && x(i) <= max_x && min_y <= y(i) && y(i) <= max_y
      }
      if (k >= K) ans = min(ans, (max_x - min_x) * (max_y - min_y))
    }

    println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
  }

  class InputReader(val stream: InputStream) {
    val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}


Measured memory_bytes: 117984
include Math
while 1 do
  line = gets
  a,other = line.split.map(&:to_i)
  line = gets
  b,other = line.split.map(&:to_i)
  if(a == 0 && b == 0)
    break
  end

  x = a
  h = b
  bottom_s = x * x
  slanting_s = sqrt((x / 2.0)**2 + h**2) * x / 2
  s = bottom_s + slanting_s * 4
  puts s
end

Measured memory_bytes: 6148
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
#define NOW         chrono::system_clock::now()
#define ELP(s,e)    chrono::duration_cast<chrono::milliseconds>(e-s).count()
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

vector<ll>jun;
void add(ll foo, ll depth = 0)
{
	if (depth == 9) {
		return;
	}
	jun.push_back(foo);
	++depth;
	add(foo * 10 + 3, depth);
	add(foo * 10 + 5, depth);
	add(foo * 10 + 7, depth);
}
bool is_shichigosan(ll num)
{
	int bi = 0;
	while (num > 0) {
		switch (num % 10) {
		case 3:
			bi |= 1;
			break;
		case 5:
			bi |= 2;
			break;
		case 7:
			bi |= 4;
			break;
		}
		num /= 10;
	}
	return bi == 7;
}
signed main()
{
	jun.reserve(30000);
	add(3);
	add(5);
	add(7);
	sort(ALL(jun));

	ll n = in();
	ll ans = 0;
	REPC(i, jun) {
		if (i > n) {
			break;
		}
		if (is_shichigosan(i)) {
			++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main()
{
	int height[10];
	int i,j;
	int maxh,maxn;
	for(i = 0;i < 10;i++)
		scanf("%d",&height[i]);
	for(i = 0;i < 3;i++)
	{
		maxh = 0;
		for(j = 0;j < 10;j++)
		{
			if(height[j] > maxh)
			{
				maxh = height[j];
				maxn = j;
			}
		}
		printf("%d\n",maxh);
		height[maxn] = 0;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,i,a[1000],s=0,c=0;
    cin>>n>>x;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=1;i<=n+1;i++)
    {
        if(s<=x)
            c++;
        s+=a[i-1];
    }
    cout<<c<<endl;
}


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

int main() {
    char *s;
    int alphabet[26];
    int len, i;

    memset(alphabet, 0, (26 * sizeof(int)));
    s = (char *)malloc(100*sizeof(char));
    scanf("%s", s);
    len = strlen(s);

    for (int i = 0; i < len; i++) {
        if (s[i] == 'a') {
            alphabet[0]++;
        } else if (s[i] == 'b') {
            alphabet[1]++;
        } else if (s[i] == 'c') {
            alphabet[2]++;
        } else if (s[i] == 'd') {
            alphabet[3]++;
        } else if (s[i] == 'e') {
            alphabet[4]++;
        } else if (s[i] == 'f') {
            alphabet[5]++;
        } else if (s[i] == 'g') {
            alphabet[6]++;
        } else if (s[i] == 'h') {
            alphabet[7]++;
        } else if (s[i] == 'i') {
            alphabet[8]++;
        } else if (s[i] == 'j') {
            alphabet[9]++;
        } else if (s[i] == 'k') {
            alphabet[10]++;
        } else if (s[i] == 'l') {
            alphabet[11]++;
        } else if (s[i] == 'm') {
            alphabet[12]++;
        } else if (s[i] == 'n') {
            alphabet[13]++;
        } else if (s[i] == 'o') {
            alphabet[14]++;
        } else if (s[i] == 'p') {
            alphabet[15]++;
        } else if (s[i] == 'q') {
            alphabet[16]++;
        } else if (s[i] == 'r') {
            alphabet[17]++;
        } else if (s[i] == 's') {
            alphabet[18]++;
        } else if (s[i] == 't') {
            alphabet[19]++;
        } else if (s[i] == 'u') {
            alphabet[20]++;
        } else if (s[i] == 'v') {
            alphabet[21]++;
        } else if (s[i] == 'w') {
            alphabet[22]++;
        } else if (s[i] == 'x') {
            alphabet[23]++;
        } else if (s[i] == 'y') {
            alphabet[24]++;
        } else if (s[i] == 'z') {
            alphabet[25]++;
        }
    }
    i = 0;
    while (i < 26) {
        if (alphabet[i] % 2 == 1) break;
        i++;
    }
    if (i <= 25) {
        printf("No");
    } else {
        printf("Yes");
    }
    return 0;
}

Measured memory_bytes: 128
x, y = map(int, input().split())
A = [1, 3, 5, 7, 8, 10, 12]
B = [2]
C = [4, 6, 9, 11]
if x in A and y in A:
  print('Yes')
elif x in C and y in C:
  print('Yes')
else:
  print('No')

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

int main() {
  int N,a,b,c,d;
  cin >> N;
  a = N / 1000;
  b = (N % 1000)/100;
  c = (N % 100)/10;
  d = N % 10;
//  cout << a << b << c << d << endl;
  if (((a == b)&&(b == c))||((b == c)&&(c == d))){
    cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int dp[3003][3003];
string s,t;
int f(int curr_a,int curr_b){
	if(curr_a>=n || curr_b>=m) return 0;
	int&ret = dp[curr_a][curr_b];
	if(~ret) return ret;
	if(s[curr_a]==t[curr_b]){
		return ret = 1+f(curr_a+1,curr_b+1);
	}
	else{
		return ret = max(f(curr_a+1,curr_b),f(curr_a,curr_b+1));
	}
}
void backtracking(int mx,int curr_a,int curr_b){
	if(curr_a>=n || curr_b>=m) return;
	if(mx == 0) return;
	
	if(s[curr_a]==t[curr_b]){
		cout<<s[curr_a];
		backtracking(mx-1,curr_a+1,curr_b+1);
	}
	else{
		if(f(curr_a+1,curr_b)==mx) backtracking(mx,curr_a+1,curr_b);
		else backtracking(mx,curr_a,curr_b+1);
	}
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>s>>t;
	n = s.length();
	m = t.length();
	backtracking(f(0,0),0,0);
}

Measured memory_bytes: 39088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    long long A,B,K;
    cin >> A >> B >> K;
    A=A-K;
    if(A>=0) cout << A << " " << B << endl;
    else{
        B=A+B;
        if(B>=0) cout << "0 " << B << endl;
        else cout << "0 0" << endl;
    }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    ll n,d,a; cin >> n >> d >> a;
    vector<pair<ll,ll>> p(n);
    rep(i,n) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());
    d*=2;
    ll ans=0;
    ll tot=0;
    queue<pair<ll,ll>> q; //どの座標まで有効か、ダメージがいくつか
    rep(i,n){
        ll x = p[i].first;
        ll h = p[i].second;
        while(q.size() && q.front().first < x){
            tot -= q.front().second;
            q.pop();
        }
        h-=tot;
        if (h<=0) continue;
        ll times = (h+a-1)/a;
        ans+=times;
        ll dmg = times*a;
        tot += dmg;
        q.emplace(x+d,dmg);
    }

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

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

bool Judge_Prime_Number( int x )
{
    for( int i = 2; i <= sqrt(x); i++ )
    {
        if( x % i == 0 )
            return false;
    }
    return true;
}

int main()
{
    int n;

    while( cin >> n )                               //データセットであることを忘れていた。
    {
        if( n == 0 )
            break;

        int i = 0;

        int sum = 0, p = 2;
        while( i != n )
        {
            if( Judge_Prime_Number(p) == true )
            {
                sum += p;
                i++;
            }
            p++;
        }
       cout << sum << endl;
    }

    return 0;
}


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

int main() {
    int H, W, m;
    cin >> H >> W >> m;
    map<int, int> tate, yoko;
    set<pair<int, int>> st;
    rep(i, m) {
        int h, w;
        cin >> h >> w;
        yoko[w]++;
        tate[h]++;
        st.insert({h, w});
    }

    int mah = 0, maw = 0;
    for (auto p : tate)
        mah = max(mah, p.second);

    for (auto p : yoko)
        maw = max(maw, p.second);

    set<int> sth;
    for (auto p : tate) {
        if (mah == p.second)
            sth.insert(p.first);
    }

    set<int> stw;
    for (auto p : yoko) {
        if (maw == p.second)
            stw.insert(p.first);
    }

    int ans = mah + maw - 1;
    for (auto h : sth) {
        for (auto w : stw) {
            if (st.find({h, w}) == st.end()) {
                ans = mah + maw;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 73804
#include <stdio.h>
#include<string.h>

int main()
{
int a[101][101];
int b[101];
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
		scanf("%d",&a[i][j]);
	}
}
for(int i=0;i<m;i++){
	scanf("%d",&b[i]);
}
for(int i=0;i<n;i++){
	int ans=0;
	for(int j=0;j<m;j++){
		ans+=a[i][j]*b[j];
	}
	printf("%d\n",ans);
}
}


Measured memory_bytes: 2096
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<vector<int>> vecs;
    int N; cin >> N;
    int Q; cin >> Q;
    
    vecs.resize(N);
    
    for(int i = 0; i < Q; ++i)
    {
        int Command; cin >> Command;
        int t; cin >> t;
        if(Command == 0)
        {
            int val; cin >> val;
            vecs[t].push_back(val);
            
        }
        else if(Command == 1)
        {
            for(int k = 0; k < vecs[t].size(); ++k)
              cout << (k == 0 ? "" : " ") << vecs[t][k];
            cout << endl;
        }
        else if(Command == 2)
        {
            vecs[t].clear();
        }
    }

    return 0;
}


Measured memory_bytes: 5868
#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
int dp1[100001][3];
int a[100000][3];
int dp(int i,int n,int k){
	if(i==n)return 0;
	if(dp1[i][k]!=-1)return dp1[i][k];
	int x=0;
	for(int j=0;j<3;j++){
		if(j==k)continue;
		x=max(x,a[i][j]+dp(i+1,n,j));
	}
	dp1[i][k]=x;
	return x;
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	memset(dp1,-1,sizeof(dp1));
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	int x=0;
	for(int i=0;i<3;i++){
		x=max(x,a[0][i]+dp(1,n,i));
	}
	cout<<x;
    return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
	string s;
	cin >> s;

	set<int> alpha;
	for (auto c : s) {
		alpha.insert(c);
	}

	cout << (s.size() == alpha.size() ? "yes" : "no") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <bitset>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    
    long long ans=0;
    bitset<20> bit(0);
    for(int mask=0; mask < (1 << (n-1) ); mask++){
        bit = mask;
        string str="";
        long long sum=0;

        str=s[0];
        for(int i=0; i < n-1; i++){
            if(bit[i]==1) {
                sum+=stol(str);
                str=s[i+1];
            }
            else
                str+=s[i+1];
        }
        sum+=stol(str);
        ans+=sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int a, b, c, d; cin >> a >> b >> c >> d;
  cout << ((c+b-1)/b<=(d+a-1)/d? "Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3600