akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	static ArrayList<Integer> list = new ArrayList<Integer>();

	public static void main(String[] args) throws Exception {
		BufferedReader br;
		if( args.length > 0 && args[0].equals("File") == true ) {
			br = getReader("C:\\Users\\USER\\Downloads\\ALDS1_4_A-in8.txt");
		} else {
			br = getReader();
		}
		int snum = getInt(br);
		int[] snumAry = getIntAry(br);
		int tnum = getInt(br);
		int[] tnumAry = getIntAry(br);
		int count = 0;
		for( int s = 0; s < snumAry.length ; s++ ) {
			for( int t = 0 ; t < tnumAry.length ; t++ ) {
				if ( snumAry[s] == tnumAry[t]) {
					slist(snumAry[s]);
					break;
				}
			}
		}
		count = list.size();
//		System.out.println("");
		System.out.println(count);
	}
	public static void slist(int v) {
		boolean insert = false;
		for( int i = 0 ; i < list.size() ; i++ ) {
			if ( list.get(i) == v) {
				insert = true;
				break;
			} else if ( list.get(i) > v ) {
				list.add(i,v);
				insert = true;
				break;
			}
		}
		if ( insert == false ) {
			list.add(v);
		}
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	}
	public static BufferedReader getReader(String path) throws Exception{
		return( new BufferedReader(new InputStreamReader(
				new FileInputStream(path))));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static String[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	}
	public static int[] getIntAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

}

Measured memory_bytes: 26148
// B - Grid Compression
// https://abc107.contest.atcoder.jp/tasks/abc107_b

import scala.io.StdIn.readLine

object Main extends App {

  val Array(h, w) = readLine.split(" ").map(_.toInt)

  var ass: Array[Array[Char]] = Array.ofDim[Char](h, w)
  for (i <- 0 until h) {
    ass(i) = readLine.toCharArray
  }

  def trim(ass: Array[Array[Char]]) = {
    ass.filter(as => as.exists(_ == '#'))
  }

  val reduce_h = trim(ass)
  val reduce_w = trim(reduce_h.transpose).transpose

  reduce_w.foreach(as => println(as.mkString))

}

Measured memory_bytes: 29056
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

fac = [-1] * (10**6+1)
inv = [-1] * (10**6+1)
finv = [-1] * (10**6+1)

fac[0] = fac[1] = 1
inv[1] = 1
finv[0] = finv[1] = 1

def initNCMMod(limit):
    for i in range(2, limit):
        inv[i] = mod - inv[mod%i] * (mod // i) % mod

initNCMMod(10**6+1)

def integer_factorization(n):
    prime_count = collections.Counter()
    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n //= i
            prime_count[i] += 1
    if n > 1:
        prime_count[n] += 1
    return prime_count

def modpow(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x % mod
        x = x*x % mod
        n = n >> 1
    return ans % mod

def main():
    N = I()
    A = LI()
    kobaisu = collections.defaultdict(int)
    div = [1] * N
    for i, a in enumerate(A):
        d = integer_factorization(a)
        for k, v in d.items():
            kobaisu[k] = max(kobaisu[k], v)
            div[i] *= modpow(k, v)
            div[i] %= mod

    kobai = 1
    for k, v in kobaisu.items():
        kobai *= modpow(k, v)
        kobai %= mod

    ans = 0
    for d in div:
        ans += kobai * inv[d] % mod
        ans %= mod
    print(ans)
main()



Measured memory_bytes: 103384
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

import itertools as it

N= one_int()
P= many_int()
Q= many_int()

temp = list(set(P))
ans_list = list(it.permutations(temp))



first=ans_list.index(tuple([p for p in P]))

after=ans_list.index(tuple([q for q in Q]))

print(abs(after-first))

Measured memory_bytes: 8052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, a=0, b=0;
	vector<int> v;

	cin >> n;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		v.push_back(t);
	}
	
	std::sort(v.begin(), v.end(), greater<int>());

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			a += v[i];
		}
		else {
			b += v[i];
		}
	}

	cout << a-b << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N, K = na()
a_array = na()
mod = 10 ** 9 + 7

ans = [[0] * (K+1) for _ in range(N)]
total = [[0] * (K+1) for _ in range(N)]

for i in range(a_array[0]+1):
    ans[0][i] = 1
for i in range(K+1):
    total[0][i] = min(i + 1, a_array[0] + 1)


for i in range(1, N):
    for j in range(K+1):
        if j - a_array[i] > 0:
            ans[i][j] = (total[i-1][j] + mod - total[i-1]
                         [j-a_array[i]-1]) % mod
        else:
            ans[i][j] = total[i-1][j]
        if j == 0:
            total[i][j] = ans[i][j]
        else:
            total[i][j] = (total[i][j-1] + ans[i][j]) % mod


print(ans[-1][-1])


Measured memory_bytes: 221356
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main(){
int n;
cin>>n;
ll a[n];
rep(i,n){
    cin>>a[i];
}
sort(a,a+n);
reverse(a,a+n);
ll b=a[0];
int min_ite=1;
ld min_abs=1000000000000000000;
rep2(i,1,n){
    if(min_abs>abs((ld)b/2-a[i])){
    min_abs=abs((ld)b/2-a[i]);
    min_ite=i;
    }

}
ll c=a[min_ite];
cout<<b<<" "<<c<<endl;
 return 0;
}

Measured memory_bytes: 4396
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int x, y;
  while(scanf("%d %d", &x, &y) != EOF && y != 0){
    int memo[1000000] = {};
    for(int t = 1; ; t++){
      if(memo[x]) {
        printf("%d %d\n", memo[x] - 1, t - memo[x]);
        break;
      }else if(x == 0){
        printf("%d 0\n", t - 1);
        break;
      }
      memo[x] = t;
      x = (x * 10) % y;
    }
  }
  return 0;
}

Measured memory_bytes: 5100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split("");
			int x = Integer.parseInt(chr[0]);
			int y = 0;
			String ans = "Good";
			for(int i =1; i<chr.length; i++) {
				y=Integer.parseInt(chr[i]);
				if(x==y) {
					ans = "Bad";
					break;
				}else {
					x=y;
				}
			}

			 System.out.println(ans);
		}
	}
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    if (n&1) cout << (double)(((n - n%2)/2)+1)/n << '\n';
    else cout << 1.0/2 << '\n';  
}

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

import static java.lang.Integer.parseInt;

/**
 * Invest Master
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		StringTokenizer st;
		st = new StringTokenizer(br.readLine());

		int n, d, x;
		n = parseInt(st.nextToken());
		d = parseInt(st.nextToken());
		x = parseInt(st.nextToken());

		int[][] price = new int[d][n];

		for (int i = 0; i < d; i++) {
			st = new StringTokenizer(br.readLine());
			for (int j = 0; j < n; j++) {
				price[i][j] = parseInt(st.nextToken());
			}
		}

		for (int i = 0; i < d - 1; i++) {
			int[] dp = new int[x + 1];
			for (int j = 0; j <= x; j++) {
				dp[j] = j;
			}
			for (int j = 0; j < n; j++) {
				for (int k = 0; k <= x; k++) {
					if (k >= price[i][j]) {
						dp[k] = Math.max(dp[k], dp[k - price[i][j]] + price[i + 1][j]);
					}
				}
			}
			x = dp[x];
		}

		System.out.println(x);
	}
}

Measured memory_bytes: 24976
N = int(input())
a = list(map(int, input().split()))

from functools import reduce
from fractions import gcd

def lcm(x,y):
    return x*y//gcd(x,y)
def lcmm(l):
    return reduce(lcm,l)

ans = 0
x = lcmm(a)-1
for i in range(len(a)):
    ans += x % a[i]

print(ans)

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

int main(){
  int n,m; cin>>n>>m;
  vector<int> a(n);
  int all=0;
  for(int &i:a){
    cin>>i;
    all+=i;
  }
  sort(a.rbegin(),a.rend());
  for(int i=0;i<m;i++){
    if(4*m*a[i]<all){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

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

int main(){
    int N, K = 0;
    int t = 0;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d.at(i);
    }

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

    K = d.at(N/2) - d.at(N/2-1);

    cout << K << endl;
}

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

int main(){
    int N, K;
    std::cin >> N >> K;
    std::vector<int> L(N);
    for(int i = 0; i < N; i++) std::cin >> L[i];
    std::sort(L.begin(), L.end(), std::greater<int>());
    int maxLen = 0;
    for(int i = 0; i < K; i++) maxLen += L[i];
    std::cout << maxLen << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100
#define INFTY 1000000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim(){

  int i,v,u,min,sum=0;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    min=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i] && color[i]!=BLACK){
	u=i;
	min=d[i];
      }
    }

    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  
  for(i=0;i<n;i++){
    if(p[i]!=-1) sum+=M[i][p[i]];
  }

  return sum;
}

int main(){
  int i,j,e;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1)M[i][j]=INFTY;
      else M[i][j]=e;
    }
  }
  printf("%d\n",prim());

  return 0;
}
	    



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define ff first
#define sc second
typedef unsigned long long ll;
using namespace std;
int main()
{
//    ios::sync_with_stdio(false);
//    cin.tie(NULL),cout.tie(NULL);
    int n,i,j,ans=0;
    cin>>n;
    vector<int>a(n+1),b(n+1),c(n);
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;i++)
    {
        cin>>b[i];
    }
    for(i=1;i<n;i++)
    {
        cin>>c[i];
    }
    int prv=-1;
    for(i=1;i<=n;i++)
    {
        j=a[i];
        ans+=b[j];
        if(prv+1==j)
        ans+=c[prv];
        prv=j;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = A * (N / (A + B));
    ans += min(A, N % (A + B));
    cout << ans << endl;
    


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<int> d(3);
  rep(i,3) { cin >> d[i]; }
  vector<P> q;
  rep(i,n) {
    string s;
    cin >> s;
    int a, b;
    if (s == "AB") { a = 0, b = 1; } // (0,1)
    if (s == "AC") { a = 0, b = 2; } // (0,2)
    if (s == "BC") { a = 1, b = 2; } // (1,2)
    q.emplace_back(a,b);
  }
  string ans;
  auto add = [&](int a, int b) { // b->a.
    ++d[a];
    --d[b];
    ans += 'A'+a;
  };
  q.emplace_back(0,1); // sentinel.

  rep(i,n) {
    int a = q[i].first;
    int b = q[i].second;
    if (!d[a] && !d[b]) { // invalid. both is 0.
      cout << "No" << endl;
      return 0;
    }
    if (!d[a]) {
      add(a,b);
    } else if (!d[b]) {
      add(b,a);
    } else {
      int na = q[i+1].first;
      int nb = q[i+1].second;
      if (a == na || a == nb) { // a is used in next tern.
        add(a,b);
      } else {
        add(b,a);
      }
    }
  }
  cout << "Yes" << endl;
  rep(i,n) {
    cout << ans[i] << endl;
  }
}


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

long long N;
char alpha[27] = {',','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main(void){

    cin >> N; 

    int twsix[100];
    bool calc = true;
    int i = 0;

    while (calc){
//        cout << N % 26 << endl;
        int modN = N % 26;
        if (modN == 0){
            twsix[i] = 26;
            N = N - 26;
        } else {
            twsix[i] = modN;
        }
//        cout << N / 26 << endl;
        if (N / 26 == 0){
            calc = false;
            break;
        } else {
            N = N / 26;
        }
        i++;
    }

    string ans;

    for (int j = i;j >= 0;j--) ans += alpha[twsix[j]];

    cout << ans << endl;

    return 0;
}

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

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

if(a>b){
    string x = "a > b";
    cout << x << endl;
}

else if(a<b){
    string x = "a < b";
    cout << x << endl;
}

else{
    string x = "a == b";
    cout << x << endl;
}
return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>

int main(void)
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12)
	{
		if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12)
			printf("Yes");
		else printf("No");
	}
	else if(x==4 || x==6 || x==9 || x==11)
	{
		if(y==4 || y==6 || y==9 || y==11)
			printf("Yes");
		else printf("No");
	}	
	else if(x==2)
	{
		if(y==2) printf("Yes");
		else printf("No");
	}	

   	return 0;
}

Measured memory_bytes: 2144
N = int(input())
V = [i for i in map(int,input().split())]
C = [i for i in map(int,input().split())]
ans = 0
XY = []
for i in range(N):
    XY.append(V[i] - C[i])
XY.sort(reverse=True)
for xy in XY:
    if xy > 0:
        ans += xy
    else:
        break
print(ans)

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

using namespace std;

typedef long long ll;

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

	ll res = 0, n, k;
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++)
	{
		res = (res / (k - 1)) + 1 + res;
	}
	cout << res << endl;
}



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

int main()
{
  int H , W ;
  while (true) {
      cin >> H >> W;
      if (H == 0 && W == 0) {
          break;
      }
      
        for(int j= 0; j<W; j++){
          cout << '#';
      }      
      cout << endl;
      for(int i = 1;  i< H-1 ; i++){
          cout << '#';
          for(int j= 1; j< W-1; j++){
              cout << '.' ;
          }
          cout << '#' << endl;
      }
      for(int j = 0; j <W; j++){
          cout << '#';
      }
      cout << endl << endl ;
  }
}


Measured memory_bytes: 3088
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val t = (1..n).map { sc.nextInt() }
    println(Math.ceil((n - 1).toDouble() / (k - 1)).toInt())
}

Measured memory_bytes: 55952
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

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

using namespace std;

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

/*==================================================*/
/*variable*/
int Q, l[100010], r[100010];
set<int> prList;
int imos[100010];

/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>Q;
    REP(i,0,Q){
        cin>>l[i]>>r[i];
    }

    REP(i,2,100001){
        bool flag = true;
        for(int j = 2; j*j <= i; j++){
            if(i % j == 0) {
                flag = false;
                break;
            }
        }
        if(flag) prList.insert(i);
    }
    REP(i,1,100001){
        if(prList.find(i) != prList.end() && prList.find((i+1)/2) != prList.end()) imos[i]++;
    }
    REP(i,2,100001) imos[i] += imos[i-1];


    REP(i,0,Q){
        cout<<imos[r[i]]-imos[l[i]-1]<<endl;
    }


    return 0;
}


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

int main()
{
	int a,b,c;
	
	cin>>a>>b>>c;
	
	if(a+b>=c)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections

N = input()

hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
if (int(N[-1]) in hon):
    print('hon')
elif(int(N[-1]) in bon):
    print('bon')
else:
    print('pon')


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

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

    int cnt = 0;
    REP(i, s.size()) {
        if(s[i] == 'x') cnt++;
    }

    if(cnt > 7) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;

const int N = 3e5 + 5;

ll n, q;
ll a[N], sum[N];
ll dpL[N], dpR[N];
ll take[N];

struct line {
	ll a, b;
	line(ll _a = 0, ll _b = 0) {
		a = _a;
		b = _b;
	}
	ll f(ll x) {
		return a * x + b;
	}
};

struct CHT {
	vector<line> s;
	void reset() {
		s.clear();
	}
	bool bad(line l1, line l2, line l3) {
		return (double)(l3.b - l1.b) / (double)(l1.a - l3.a) <= (double)(l2.b - l1.b) / (double)(l1.a - l2.a);
	}
	void add(line l) {
		while (s.size() > 1 && bad(s[s.size() - 2], s.back(), l)) {
			s.pop_back();
		}
		s.push_back(l);
	}
	ll get(ll x) {
		if (s.empty()) return 0;
		int L = 0, R = s.size() - 1;
		while (L < R) {
			int mid = (L + R) >> 1;
			if (s[mid].f(x) <= s[mid + 1].f(x)) {
				L = mid + 1;
			} else {
				R = mid;
			}
		}
		return s[L].f(x);
	}
} cht;

void solve(int l, int r) {
	int mid = (l + r) >> 1;
	
	cht.reset();
	for (ll i = l; i <= mid; i++) {
		cht.add(line(i, 2 * dpL[i - 1] + 2 * sum[i - 1] + i * i));
	}
	ll mx = -1e18;
	for (ll i = r; i >= mid; i--) {
		mx = max(mx, 2 * dpR[i + 1] - 2 * sum[i] + (i + 1) * (i + 2) + cht.get(-2 * i - 3));
		take[i] = max(take[i], mx/2);
	}
	
	cht.reset();
	for (ll i = mid; i <= r; i++) {
		cht.add(line(2 * i + 3, 2 * dpR[i + 1] - 2 * sum[i] + (i + 1) * (i + 2)));
	}
	mx = -1e18;
	for (ll i = l; i <= mid; i++) {
		mx = max(mx, 2 * dpL[i - 1] + 2 * sum[i - 1] + i * i + cht.get(-i));
		take[i] = max(take[i], mx/2);
	}
	
	if (l == r) return;
	solve(l, mid);
	solve(mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
		take[i] = -1e18;
	}
	
	cht.reset();
	cht.add(line(0, 0));
	for (ll i = 1; i <= n + 1; i++) {
		dpL[i] = -2 * sum[i - 1] + (i - 1) * i + cht.get(-2 * i + 1);
		dpL[i] /= 2;
		cht.add(line(i, 2 * dpL[i] + 2 * sum[i] + i * i));
	}
	
	cht.reset();
	cht.add(line(-2 * n - 1, n * (n + 1) - 2 * sum[n]));
	for (ll i = n; i >= 0; i--) {
		dpR[i] = 2 * sum[i] + i * i + cht.get(i);
		dpR[i] /= 2;
		cht.add(line(-2 * i + 1, (i - 1) * i + 2 * dpR[i] - 2 * sum[i - 1]));
	}
	
	solve(1, n);
	
	cin >> q;
	while (q--) {
		ll p, x;
		cin >> p >> x;
		cout << max(dpL[p] + dpR[p], take[p] + a[p] - x) << "\n";
	}
}


Measured memory_bytes: 15384
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    int n,m;
    cin>>n>>m;
    int h[n+1];
    vector<int> a[n+1];
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=1;i<=m;i++)
    {
        int l,r;
        cin>>l>>r;
        a[l].pb(r);
        a[r].pb(l);
    }
    int count=0;
    for(int i=1;i<=n;i++){
        int c=1;
        for(int j=0;j<a[i].size();j++)
            if(h[a[i][j]]>=h[i]){
                c=0;
                break;
            }
        count+=c;
    }
    cout<<count;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
class union_find{
  private:
    ll N;
    vll par; // iの親
    vll rank; // 木の深さ
    vll siz; // iの属する集合の要素数
    vll weig;
  public:

    // 要素の初期化
    union_find(ll n){
      N = n;
      for(ll i=0;i<N;i++){
        par.push_back(i);
        rank.push_back(0);
        siz.push_back(1);
        weig.push_back(0);
      }
    }

    // 木の根を求める
    ll root(ll x){
      if(par[x] == x) return x;
      else{
        ll r = root(par[x]);
        weig[x] += weig[par[x]];
        return par[x] = r;
      }
    }

    ll weight(ll x){
      root(x);
      return weig[x];
    }

    // 木の併合(rank基準)
    void unite(ll x, ll y, ll w = 0){
      w += (weight(x) - weight(y));
      x = root(x);
      y = root(y);
      if(x == y) return;

      if(rank[x] < rank[y]){
        par[x] = y;
        siz[y] += siz[x];
        w *= -1;
        weig[x] = w;
      }
      else{
        par[y] = x;
        siz[x] += siz[y];
        weig[y] = w;
        if(rank[x] == rank[y]) rank[x]++;
      }
    }
    
    ll diff(ll x, ll y){
      if(same(x,y)) return weight(y) - weight(x);
      else return -LINF;
    }

    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y){
      return root(x) == root(y);
    }

    // xが木の根であるかどうか
    bool is_root(ll x){
      return x == root(x);
    }

    // xの属する集合の要素数
    ll size(ll x){
      return siz[root(x)];
    }

    // 全体でいくつ集合があるか
    ll cnt(ll x){
      ll res = 0;
      for(ll i=0;i<N;i++) if(i == root(i)) res++;
      return res;
    }
};

 
//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, q;
  cin >> n >> q;
  union_find tree(n);
  REP(i,q){
    ll com, x, y;
    cin >> com >> x >> y;
    if(com) cout << tree.same(x,y) <<endl;
    else tree.unite(x,y);
  }

  return 0;
}



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

int func(int a){
    if(a%2==0) return a/2;
    else return a*3+1;
}

int main()
{
    set<int> v;
    int s; cin>>s;
    v.insert(s);
    int a=func(s);
    auto itr=v.find(a);
    if(itr!=v.end()){
        cout<<2<<endl;
        return 0;
    }
    v.insert(a);
    for(int i=3;i<1000000;i++){
        a=func(a);
        auto itr=v.find(a);
        if(itr!=v.end()){
            cout<<i<<endl;
            return 0;
        }
        v.insert(a);
    }
    return 0;
}

Measured memory_bytes: 256
let arr_of_str s = Array.init (String.length s) (fun i -> s.[i])
let _ = print_endline @@ Scanf.scanf "%s" @@ fun d ->
  let n,w,s,e =
    arr_of_str d |> Array.fold_left (fun (n,w,s,e) c ->
    (n||c='N', w||c='W', s||c='S', e||c='E')) (0=1,0=1,0=1,0=1)
  in if n = s && w = e then "Yes" else "No"


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

int main() {
    int N;
    cin >> N;
    vector<int> cnt(100010, 0);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        if(a != 0) cnt[a-1]++;
        cnt[a]++;
        cnt[a+1]++;
    }

    cout << *max_element(cnt.begin(), cnt.end()) << endl;
}

Measured memory_bytes: 640
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: usize = scan(tokens);
    let s: String = scan(tokens);
    if a >= 3200 {
        println!("{}", s);
    } else {
        println!("red");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int n; cin >>n;
  vector<int> l(2*n); rep(i, 2*n) cin >>l[i];
  sort(all(l));
  int res = 0;
  rep(i, n){
    res += l[2*i];
  }
  cout <<res <<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
	#include<string.h>
	#include<unistd.h>
	#include<stdlib.h>
	#include<time.h>
	int main()
	{
		int a,b[100001],c[10000],d,e,f=0,g=0,i,cnt=0;
		scanf("%d",&a);
		for(i=0;i<a;i++)
		{
			scanf("%d",&b[i]);
		}
		for(i=a-2;0<=i;i--)
		{
			
			if(b[i]>b[i+1])
			{
				e=b[i]-b[i+1];
				if(e>1)
				{
					cnt+=1;
				}
				if(e==1||e==0)
				{
					b[i]-=1;
				}
			}
		}
		if(cnt>0)
		{
			printf("No\n");
		}
		if(cnt==0)
		{
			printf("Yes\n");
		}
	return 0;
	}
	

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m;
    cin>>n>>m;
    vector<pll> ba(m);
    rep(i,m)cin>>ba[i].second>>ba[i].first;
    sort(all(ba));
    ll r=0;//いけない島の右端
    ll res=0;
    rep(i,m){
        if(ba[i].second<=r)continue;
        else{
            r=ba[i].first-1;
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,k,a[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>k;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=k+1;i<=n;i++){
    if(a[i-k]<a[i])cout<<"Yes\n";
    else cout<<"No\n";
  }
  return 0;
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

// BinaryIndexedTree(Fenwick-Tree); フェニック木
// ：BIT<long long> bit(xx)で初期化、bit.sum(n)で0~n番目までの累積和を計算
template<typename T> class BIT {
private:
    const long long n; vector<T> bit;
public:
    BIT(long long size) : n(size+1), bit(n, 0){}
    BIT(const vector<T>& v) : n((long long)v.size()+1), bit(n, 0){ for(long long i = 0; i < n-1; i++) add(i,v[i]); }
    T sum(long long i){ i++; T s = 0; while(i > 0){ s += bit[i], i -= i & -i; } return s; }
    void add(long long i, T x){ i++; while(i < n) bit[i] += x, i += i & -i; }
    void print(){ for(long long i = 0; i < n-1; i++) cout << sum(i)-sum(i-1) << (i != n-2 ? " " : "\n"); }
    void print_sum(){ for(long long i = 0; i < n; i++) cout << sum(i-1) << (i != n-1 ? " " : "\n"); }
};

int main(){
    Init();
    // n;monster, d;range, a;damage
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> monster(n);
    rep(i, n) cin >> monster[i].first >> monster[i].second;
    sort(all(monster));
    BIT<long long> bit(n+10);

    // 左端のモンスターから処理していく。
    ll ans = 0;
    rep(i, n){
        ll leftHP = monster[i].second - bit.sum(i);
        if(leftHP <= 0) continue;
        // 左端のモンスターの座標+2*dの範囲まで爆弾が届く
        ll pos = monster[i].first;
        ll range = pos + 2*d;
        // 範囲ギリギリのモンスターを求める
        auto it = upper_bound(all(monster), make_pair(range, INFLL));
        ll range_i = it-monster.begin();
        // 爆弾を投げる回数
        ll bomb = (ll)ceil(1.0*leftHP/a);
        ans += bomb;
        bit.add(i, bomb*a);
        bit.add(range_i, -bomb*a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7952
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def main():
    s = list(input())

    left, right = 0, len(s) - 1
    ans = 0
    while 1:
        if left >= right:
            break
        if s[left] == s[right]:
            left += 1
            right -= 1
        else:
            if s[left] == 'x':
                ans += 1
                left += 1
            elif s[right] == 'x':
                ans += 1
                right -= 1
            else:
                print(-1)
                sys.exit()
    print(ans)





if __name__ == '__main__':
    main()
    # test()



Measured memory_bytes: 50028
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

ans = 0
total = 0
r_cnt = 0
while n > 0:
    for i in range(m):
        total += b[i]*a[r_cnt][i]
    if total + c > 0:
        ans += 1
    total = 0
    r_cnt += 1
    n -= 1
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
typedef long long int64;
static const int MAXL = 12;

int n, s[MAXL];

inline int64 get(int l, int r)
{
    int64 ret = 0;
    for (; l <= r; ++l) ret = ret * 10 + s[l];
    return ret;
}

int main()
{
    for (n = 0; (s[n] = getchar()) != '\n'; s[n] -= '0', ++n) ;

    int64 ans = 0;
    for (int i = 0; i < n; ++i)
        for (int j = i; j < n; ++j) {
            ans += get(i, j) << (std::max(0, i - 1) + std::max(0, n - j - 2));
        }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
import scala.io.StdIn.{readInt, readLine}

object Main {

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

    val SEP = " "
    val Array(n, m) = readLine().split(SEP).map(_.toInt)
    val matrix = Array.fill(n, m)(0)
    0 until n foreach {
      matrix(_) = readLine().split(SEP).map(_.toInt)
    }

    val b = Array.ofDim[Int](m)
    0 until m foreach {
      b(_) = readInt()
    }

    matrix.foreach { arr => {
      var sum = 0
      arr.zip(b).foreach { case (a, b) => sum += (a * b)}
      println(sum)
    }}

  }
}



Measured memory_bytes: 47580
n, k = map(int, input().split())
ans = 0
if k == 0:
    ans = n * n
else:
    for i in range(1, n + 1):
        ans += n // i * max(i - k, 0)
        if i >= k and n % i != 0:
            ans += max(0, (n % i + 1) - k)
print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<string> vs;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

char c[9][6] = {
	{'.', ',', '!', '?', ' '},
	{'a', 'b', 'c'},
	{'d', 'e', 'f'},
	{'g', 'h', 'i'},
	{'j', 'k', 'l'},
	{'m', 'n', 'o'},
	{'p', 'q', 'r', 's'},
	{'t', 'u', 'v'},
	{'w', 'x', 'y', 'z'}
};

int main() {
	int n;
	cin >> n;
	rep(i,0,n) {
		string s;
		cin >> s;
		int num = 0;
		string ans = "";
		rep(j,0,s.size()) {
			if(s[j] != '0') num++;
			else {
				if(num == 0) continue;
				char tmp = s[j-1];
				int b = atoi(&tmp)-1;
				if(b == 0) ans += c[b][(num-1)%5];
				else if(b == 6 || b == 8) ans += c[b][(num-1)%4];
				else ans += c[b][(num-1)%3];
				num = 0;
			}
		}
		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
    while (x->left != NIL){
        x = x->left;
        return x;
    }
}
 
Node treeMaximum(Node x){
    while (x->right != NIL){
        x = x->right;
        return x;
    }
}
 
Node treeSearch(Node x, int k){
    if(x == NIL||k == x->key) return x;
    if(k < x->key) return treeSearch(x->left, k);
    else return treeSearch(x->right, k);
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}
 
void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}


Measured memory_bytes: 25296
#include<stdio.h>


int main(void){


  char m[8][9];
  int i, j;
  int key;

  while(scanf("%s", m[0])!=EOF){
    for(i=1; i<8; i++){
      scanf("%s", m[i]);
    }

    key=0;
    for(i=0; i<8; i++){
      for(j=0; j<8; j++){
	if(m[i][j]=='1'){
	  key=1;
	  break;
	}
      }
      if(key==1) break;
    }


    if(i+1<8 && j+1<8){
      if(m[i][j+1]=='1' && m[i+1][j]=='1' && m[i+1][j+1]=='1'){
	printf("A\n");
      }
    }
    
    if(i+3<8){
      if(m[i+1][j]=='1' && m[i+2][j]=='1' && m[i+3][j]=='1'){
	printf("B\n");
      }
    }
    
    if(j+3<8){
      if(m[i][j+1]=='1' && m[i][j+2]=='1' && m[i][j+3]=='1'){
	printf("C\n");
      }
    }
    
    if(j-1>=0 && i+2<8){
      if(m[i+1][j]=='1' && m[i+1][j-1]=='1' && m[i+2][j-1]=='1'){
	printf("D\n");
      }
    }
    
    if(i+1<8 && j+2<8){
      if(m[i][j+1]=='1' && m[i+1][j+1]=='1' && m[i+1][j+2]=='1'){
	printf("E\n");
      }
    }
    
    if(i+2<8 && j+1<8){
      if(m[i+1][j]=='1' && m[i+1][j+1]=='1' && m[i+2][j+1]=='1'){
	printf("F\n");
      }
    }
    
    if(i+1<8 && j+1<8 && j-1>=0){
      if(m[i][j+1]=='1' && m[i+1][j]=='1' && m[i+1][j-1]=='1'){
	printf("G\n");
      }
    }

  }


  return(0);
}



Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int x,y;
    x=read(), y=read();
    int res=0;
    while(x<=y)
    {
        res++;
        x*=2;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int N;
    cin >> N;
    int X[N], Y[N];
    for (int i=0; i<N; i++){
        cin >> X[i];
        Y[i] = X[i];
    }
    
    int A, B;
    sort(Y, Y+N);
    A = Y[N/2-1];
    B = Y[N/2];

    for (int i=0; i<N; i++){
        if (X[i] <= A) cout << B << endl;
        else cout << A << endl;
    }


}


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

namespace ABC170
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            int[] xy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int x = xy[0], y = xy[1];
            if( x * 4 < y)
            {
                Console.WriteLine("No");
                return;
            }
            if(x * 2 > y)
            {
                Console.WriteLine("No");
                return;
            }
            int q = Math.Abs((x * 4) - y);
            if(q % 2 != 0 )
            {
                Console.WriteLine("No");
                return;
            }
            q /= 2;
            x -= q;
            if(x >= 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 28300