akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()


int main(){
    ll n; cin >> n;
    map<ll,ll> mp;
    ll input = n;
    for(ll i=2;i*i<=input;i++){
        if(input % i == 0){
            while(input % i == 0){
                input /= i;
                mp[i]++;
            }
        }
    }
    if(input != 1) mp[input]++;

    ll ans = 0;
    map<ll,ll>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        ans += (sqrt(1+8*it->second)-1)/2;
    }

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



Measured memory_bytes: 3724
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

use std::collections::HashMap;
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.input();
    let arr: Vec<i64> = sc.vec(n);
    let mut map = HashMap::new();

    for i in 0..(n as i64) {
        let a = arr[i as usize];
        let diff = i - a + 1;
        map.entry(diff).and_modify(|x| *x += 1).or_insert(1);
    }
    let mut ans: i64 = 0;
    for i in 0..(n as i64) {
        let x = arr[i as usize] + i + 1;
        let diff = i - arr[i as usize]  + 1;
        if let Some(cnt) = map.get(&x) {
            ans += cnt;
        }
        map.entry(diff).and_modify(|x| *x -= 1);
    }
    println!("{}", ans);
}


Measured memory_bytes: 10176
#include<stdio.h>
int main()
{
    int i,c,r[100];
    int n,d,k,t,z=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&r[i]);
    }
    for(c=0;c<n-1;c++)
    {
        k=c;
        for(d=c+1;d<n;d++)
        {
            if(r[d]<r[k])
            {
                k=d;
            }
        }
        if(k!=c)
        {
            t=r[k];
            r[k]=r[c];
            r[c]=t;
            z++;
        }

    }
    for(c=0;c<n-1;c++)
    {
        printf("%d ",r[c]);
    }
    printf("%d\n",r[c]);
    printf("%d\n",z);
    return 0;
}




Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  int Y, X;
  vector<vector<int>> s(H, vector<int>(W, 0));
  REP(y, H) {
    REP(x, W) {
      if (y < B && x < A || y >= B && x >= A) {
        s[y][x] = 1;
      }
    }
  }
  REP(y, H) {
    REP(x, W) {
      cout << s[y][x];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9 + 7;
const int inf = 1e8;

int main() {
	int N,M;
	cin>>N>>M;
	vector<string> A(N),B(M);
	rep(i,N)cin>>A[i];
	rep(j,M)cin>>B[j];
	string ans = "No";
	rep(i,N)rep(j,N){
		int cnt = 0;
		rep(dx,M)rep(dy,M){
			int nx = i+dx,ny=j+dy;
			if(nx>=0&&nx<N&&ny>=0&&ny<N)
			if(A[nx][ny]==B[dx][dy])cnt++;
		}
		if(cnt == M*M)ans = "Yes";
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}


int main(){
  int n;
  cin >> n;
  int a[1000000];
  FOR(i,n){
    cin >> a[i];
  }
  int l[1000000],r[1000000];
  l[0]=a[0];
  r[n-1]=a[n-1];
  for(int i=1;i<n;i++){
    l[i]=gcd(l[i-1],a[i]);
    r[n-i-1]=gcd(r[n-i],a[n-i-1]);
  }
  int ans=0;
  FOR(i,n){
    if(i==0){
      chmax(ans,r[1]);
    }else if(i==n-1){
      chmax(ans,l[n-2]);
    }else{
      chmax(ans,gcd(l[i-1],r[i+1]));
    }
  }

  cout << ans << endl;
  
}

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

using namespace std;

const int maxn = 1e5 + 5;

int n, L, Q, x[maxn], go[maxn][20];

inline int read(){
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)){if(ch == '-')f = -1; ch = getchar();}
	while(isdigit(ch)){u = u * 10 + ch - 48; ch = getchar();} return u * f;
}
void PreGo(int n,int L,int *x){
    int pos=1;
    for(register int i=1;i<=n;++i){
        while(pos<=n && x[pos]-x[i]<=L)
            pos++;
        go[i][0]=pos-1;
    }
    for(register int j=1;j<=19;++j)
        for(register int i=1;i<=n;++i)
            go[i][j]=go[go[i][j-1]][j-1];
}
int main(){
    n=read();
    for(register int i=1;i<=n;++i)
        x[i]=read();
    L=read();
    Q=read();
    PreGo(n,L,x);
    for(register int i = 1; i <= Q; i++){
		int a = read(), b = read(), now, ans = 0;
		if(a > b)swap(a, b);
		now = a;
		for(register int k = 19; ~k; k--)
			if(go[now][k] < b){
				now = go[now][k];
				ans += (1 << k);
			}
		printf("%d\n", ans + 1);
	}
    return 0;
}


Measured memory_bytes: 9088
import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
H = l[0]
W = l[1]
a = [input() for c in range(H)]


print("#"*(W+2))
for i in range(H):
    print("#"+a[i]+"#")
print("#"*(W+2))

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

using namespace std;

typedef long long ll;

const int MAX = 100001;
int n, w, bw, bv;
ll dp[MAX];

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

	cin >> n >> w;

	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;

	for (int i = 0; i < n; ++i) {
		cin >> bw >> bv;

		for(int j = MAX - 1; j >= bv; j--){
			dp[j] = min(dp[j], dp[j - bv] + bw);
		}
	}

	int best = -1;
	for (int i = 0; i < MAX; ++i){
		if(dp[i] <= w){
			best = i;
		}
	}

	printf("%d\n", best);
}

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

int main(){
  vector<string> S(3);
  for(string &s:S)
    cin>>s;
  vector<queue<int>> A(3);
  for(int i=0;i<3;i++)
    for(char &c:S.at(i))
      A.at(i).push(c);
  int i=0;
  while(true){
    if(A.at(i).empty()){
      cout<<(char)('A'+i)<<endl;
      return 0;
    }
    char c=A.at(i).front();
    A.at(i).pop();
    i=(int)(c-'a');
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



int main(void) {
    
    
    char c;
    cin>>c;
    cout<<(char)(c+1)<<endl;
    
    
}


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

int main()
{
  unsigned H, W;
  std::cin >> H >> W;
  
  for (unsigned h = 0; h < H; ++h) {
    std::string S;
    std::cin >> S;
    
    std::cout << S << std::endl;
    std::cout << S << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program
{
	static void Main(string[] args)
	{
		int[] ABCK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int A = ABCK[0];
		int B = ABCK[1];
		int C = ABCK[2];
		int K = ABCK[3];


		if (K <= A)
			Console.WriteLine(K);
		else if (K <= A + B)
			Console.WriteLine(A);
		else
			Console.WriteLine(A - (K - A - B));
	}

	/// <summary>
	/// アナグラム
	/// </summary>
	/// <param name="word1"></param>
	/// <param name="word2"></param>
	/// <returns></returns>
	static bool IsAnagramOf(string word1, string word2)
	{
		return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
	}
	/// <summary>
	/// 最小公倍数
	/// </summary>
	/// <param name="a"></param>
	/// <param name="b"></param>
	/// <returns></returns>
	public static long Lcm(long a, long b)
	{
		return a * b / Gcd(a, b);
	}

	/// <summary>
	/// 最大公約数
	/// </summary>
	/// <param name="a"></param>
	/// <param name="b"></param>
	/// <returns></returns>
	public static long Gcd(long a, long b)
	{
		if (a < b)
			// 引数を入替えて自分を呼び出す
			return Gcd(b, a);
		while (b != 0)
		{
			var remainder = a % b;
			a = b;
			b = remainder;
		}
		return a;
	}
}




//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
//Boolean ok = false;

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();
//Console.WriteLine(cnt);

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];


Measured memory_bytes: 28196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b==0) return a;
	else return gcd(b,a%b);
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	int ans;
	rep(i,n){
		cin>>a[i];
		if(i==0) ans=a[i];
		else ans=gcd(ans,a[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ss  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element) != container.end())
#define ss  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(c) c.begin(), c.end()
#define pb push_back
#define mp make_pair
#define mod (1000000000 + 7)
#define inf (1e18+9)
#define fi first
#define se second
#define MAXN   1000001 
typedef long long ll;
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_set;

long long fastpow(long long n, long long x, long long m){
	
    long long ret = 1;
    
    while(x){
    if(x&1) (ret*=n)%=m;
    x>>=1;
    (n*=n)%=m;
    }
  
 return ret;
}
ll add(ll a,ll b){
	return((a%mod)+(b%mod))%mod;
}
ll prod(ll a,ll b){
	a%=mod;
	b%=mod;
	return ((a%mod)*(b%mod)%mod);
}
int main()
{
    int n,q,m;
    
    	cin>>n;
    	vector<int> v(n+2),ans(n+2);
    	for(int i=0;i<n;i++) cin>>v[i];
    	int sum=0;
    	ans[0]=0;ans[1]=abs(v[1]-v[0]);
    	for(int i=2;i<n;i++){
    		ans[i]=min(ans[i-1]+abs(v[i]-v[i-1]),ans[i-2]+abs(v[i]-v[i-2]));
		}
		cout<<ans[n-1]<<"\n";
   
    return  0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()

	cnt := 0
	for n != 0 {
		cnt++
		n = n/k
	}

	fmt.Fprintln(wr, cnt)
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <queue>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
typedef unsigned long long ull;
queue<ull>q;
int main()
{
    int k,cnt=0;
    For(i,1,9)q.push(i);
    cin>>k;
    ull temp,pre;
    For(i,1,k)
    {
        pre=q.front();q.pop();
        if(pre%10)
        {
            temp=pre*10+(pre%10)-1;
            q.push(temp);
            cnt++;
        }
        temp=pre*10+pre%10;
        q.push(temp);cnt++;
        if(pre%10!=9)
        {
            temp=pre*10+pre%10+1;
            q.push(temp);
            cnt++;
        }
    }
    cout<<pre<<endl;
    return 0;
}


Measured memory_bytes: 5112
#include<stdio.h>

 int main(){
  int a[10010];
 int n,m;
 scanf("%d%d",&n,&m);
 for(int i=0;i<m;i++)scanf("%d",&a[i]);
 int s=0;
 for(int i=0;i<m;i++)s+=a[i];
 if(s>n){
 printf("-1\n");
 }
 else{
 printf("%d\n",n-s);
 }
}


Measured memory_bytes: 1720
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest013-A
#  TODO https://atcoder.jp/contests/agc013/tasks/agc013_a

def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i]
		if flag == "Plus":
			if diff < 0:
				flag="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			elif diff < 0:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))


Measured memory_bytes: 14228
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextInt()
    val b = scanner.nextInt()
    val smallLargeOrEqual = if (a < b) "<" else if (a > b) ">" else "=="
    println("a ${smallLargeOrEqual} b")
}


Measured memory_bytes: 25352
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

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

  int32_t N;
  cin >> N;
  const double lower = static_cast<double>(N) / 1.08;
  const double upper = static_cast<double>(N + 1) / 1.08;
  int32_t result = -1;
  for (int32_t i = static_cast<int32_t>(lower); static_cast<double>(i) < upper; ++i) {
    if (static_cast<double>(i) >= lower) {
      result = i;
    }
  }
  if (result >= 0) {
    cout << result << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
const int mod = 1e9 + 7;
 
inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}
 
inline int64 modInv(int64 a)
{
  return (modPow(a, mod - 2));
}
 
int64 fact[202020], rfact[202020];
int N, A, B, C, D;
int64 dp[1001][1001];
 
int main()
{
  fact[0] = rfact[0] = 1;
  for(int i = 1; i < 102020; i++) {
    fact[i] = fact[i - 1] * i % mod;
    rfact[i] = modInv(fact[i]);
  }
 
  cin >> N >> A >> B >> C >> D;
 
  dp[A - 1][0] = fact[N];
  for(int j = A; j <= B; j++) { // j 人の組
    int64 bat = 1;
    for(int k = 0; k < C - 1; k++) (bat *= rfact[j]) %= mod;
    for(int k = C; k <= D; k++) { // k 個
      (bat *= rfact[j]) %= mod;
      for(int i = N - 1; i >= 0; i--) {
        int sum = i + j * k;
        if(sum > N) continue;
        (dp[j][sum] += 1LL * dp[j - 1][i] * bat % mod * rfact[k] % mod) %= mod;
      }
    }
    for(int k = N; k >= 0; k--) (dp[j][k] += dp[j - 1][k]) %= mod;
  }
  cout << dp[B][N] << endl;
}

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

int main(void){
  int n,m; cin >> n >> m;
  priority_queue<pair<int,int>> q;
  rep(i,n){
    int a;
    cin >> a;
    q.push(make_pair(a,1));
  }
  rep(i,m){
    int b,c;
    cin >> b >> c;
    q.push(make_pair(c,b));
  }
  ll ans = 0;
  rep(i,n){
    auto p =q.top();
    q.pop();
    ans += p.first;
    if(p.second >1){
      p.second--;
      q.push(p);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007 
#define INF 1000000009
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define so sizeof 
#define pii pair<ll,ll>
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define max3(a, b, c) max(c, max(a, b))
#define max4(a, b, c, d) max(d, max(c, max(a, b)))
#define repe(i,a) for(auto i:a)
#define st string
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rrep(i,a,b) for(ll i=b;i>=a;i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 
void solve(){
  ll n;
  cin>>n;
  ll a[n];
  ll dp[n];
  dp[n-1]=a[n-1];
  rep(i,0,n-1){
     cin>>a[i];
  }
  dp[n-1]=a[n-1];
  ll res=0;
  for(ll i=n-2;i>=0;i--){
      dp[i]=(a[i]+dp[i+1])%mod;
  }
  rep(i,0,n-2){
    res=(res+(a[i]*dp[i+1])%mod)%mod;
  }
  cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
#endif
    fast
    solve();
    return 0;
}

Measured memory_bytes: 6792
#include <iostream>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  while(n)
  {
    if(n % 10 == 7)
    {
      cout << "Yes";
      return 0;
    }
    n /= 10;
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 3620
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#mod = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    A=LIST()
    B=LIST()
    ans=0
    ta=A[0]
    for i in range(n):
        tb=B[i]
        ans+=min(ta,tb)
        ta,tb=max(0,ta-tb),max(0,tb-ta)
        ta+=A[i+1]
        ans+=min(ta,tb)
        ta=max(0,ta-tb)
        ta=min(ta,A[i+1])
        #print(ans,ta,tb)
    print(ans)

if __name__=='__main__':
    do()

Measured memory_bytes: 23972
class Solver():
    def __init__(self, A: [int]):
        self.A = A
        self.max_depth = len(A)

    def solve(self, tgt):
        self.tgt = tgt
        self.history = (self.max_depth+1)*[4000 * [None]]
        self.history = [[None for i in range(4000)] for x in range(self.max_depth + 1)]
        if self._rec_solve(0, 0):
            return 'yes'
        else:
            return 'no'

    def _rec_solve(self, _sum, index):
        if self.history[index][_sum] is not None:
            return self.history[index][_sum]
        if _sum == self.tgt:
            self.history[index][_sum] = True
            return True
        if index >= self.max_depth or _sum > self.tgt:
            self.history[index][_sum] = False
            return False
        self.history[index][_sum] = self._rec_solve(_sum + self.A[index], index + 1) or self._rec_solve(_sum, index + 1)
        return self.history[index][_sum]
            


if __name__ == '__main__':
    n = int(input())
    A = [int(i) for i in input().rstrip().split()]
    q = int(input())
    m_ary = [int(i) for i in input().rstrip().split()]
    s = Solver(A)
    for val in m_ary:
        print(s.solve(val))

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

using namespace std;

template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};

struct Vertex
{
	int color;
	Vertex(int a) : color(a) {}
	Vertex() : color(0) {}
};

using vertex = Vertex;

struct Edge
{
	int to;
	Edge(int t) : to(t) {}
	Edge() {}
};
using edge = Edge;
using graph = Graph<vertex, edge>;

long long res[3];

template<class V, class E>
bool is2graph(Graph<V, E>& G, int pos = 0, int par = -1, int color = 1)
{
	if (G.v[pos].color && G.v[pos].color != color) return false;
	if (G.v[pos].color) return true;
	G.v[pos].color = color;
	res[color]++;
	for (auto& n : G.e[pos]) {
		if (n.to == par) continue;
		if (!is2graph(G, n.to, pos, 3 - color)) return false;
	}
	return true;
}

int main()
{
	int N, M;
	cin >> N >> M;
	graph G(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G.add_edge(a, b);
		G.add_edge(b, a);
	}
	if (is2graph(G)) {
		cout << res[1] * res[2] - M << endl;
	} else {
		cout << (long long) N * (N - 1) / 2 - M << endl;
	}
}


Measured memory_bytes: 6656
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
import math
from collections import defaultdict, Counter

def warshall_floyd(d, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
    return d
MOD = 10**9 + 7
INF = 10**10

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n,a,b = getlist()
    nums = getlist()

    cnt = Counter(nums)

    cnt = sorted(cnt.items(), key=lambda x: -x[0])
    # print(cnt)
    ans = 0
    tmp_max = 0
    res = 0
    for i in range(a, b+1):
        remain = i
        acc_val = 0
        for it in cnt:
            if it[1] <= remain:
                remain -= it[1]
                acc_val += it[1] * it[0]

            else:
                acc_val += remain * it[0]
                cmb = comb(it[1], remain)
                mean = acc_val / i
                res += comb(50, i)
                if mean == tmp_max:
                    ans += cmb
                elif mean > tmp_max:
                    tmp_max = mean
                    ans = cmb
                # print(mean, acc_val, ans, res)
                break

            if remain == 0:
                mean = acc_val / i
                if mean == tmp_max:
                    ans  += 1
                elif mean > tmp_max:
                    tmp_max = mean
                    ans = 1

                break
    print(tmp_max)
    print(ans)

    # res = 0
    # for i in range(1, 51):
    #     res += comb(50, i)
    #
    # print(res)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

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

int main()
{
    ll N, M; cin >> N >> M;
    vector<ll> a(N, 0);
    vector<ll> b(N, 0);
    rep(i,M) {
        ll A, B; cin >> A >> B;
        if (A == 1) {
            a[B-1] = 1;
        }
        else if (B == 1) {
            a[A-1] = 1;
        }
        if (A == N) {
            b[B-1] = 1;
        }
        else if (B == N) {
            b[A-1] = 1;
        }
    }
    rep(i,N) {
        if (a[i] == 1 && b[i] == 1) {
                cout << "POSSIBLE" << endl;
                exit(0);
        }
    }
    cout << "IMPOSSIBLE" << endl;

}


Measured memory_bytes: 6736
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int A[N],i,j,cnt=0,temp,flag=1;
  for(i=0;i<N;i++)scanf("%d",&A[i]);

  while(flag){
      flag = 0;
      for(j=N-1;j>0;j--){
          if(A[j] < A[j-1]){
              temp = A[j];
              A[j] = A[j-1];
              A[j-1] = temp;
              cnt++;
              flag = 1;
          }
      }
  }
  for(i=0;i<N-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[N-1]);
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  for(int i = N; ; i++){
    bool flag = true;
    for(int j = 2; j*j <= i; j++){
      if(i%j == 0) flag = false;
    }
    if(flag){
      cout << i << "\n";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(c) sort((c).begin(),(c).end())
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define reprs(i, m, n) for(int i = n; i >= m; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N;
  cin >> N;

  if(N%3!=0){
    rep(i,N){
      ll a;
      cin>>a;
      if(a!=0){
        std::cout << "No" << '\n';
        return 0;
      }
    }
    std::cout << "Yes" << '\n';
    return 0;
  }

  ll y=0;
  ll a[N];
  rep(i,N){
    ll x;
    cin>>x;
    a[i]=x;
    y=max(x,y);
  }

  int k=0;
  rep(i,31){
  if(y >>i & 1) k=i+1;
  }
  int kind[N]; //0 1 2 3
  fill(kind,kind+N,3);

  int zerokind=3;
  int zerofound=0;
  int ct=0;

  rep(j,k){
    zerokind=3;
    ct=0;

    rep(i,N){
      ll aa=a[i];
      int r;
      r = aa >>j & 1;
      if(r==0){
        ct++;
      }
    }

    if(ct!=N&&ct!=N/3){
      std::cout << "No" << '\n';
      return 0;
    }

    if(ct==N/3){
  rep(i,N){
    ll aa=a[i];
    int r;
    r = aa >>j & 1;
      if(r==0){
        if(zerokind!=3){
          if(kind[i]==3){
            kind[i]=zerokind;
          }
          else{
            if(zerokind!=kind[i]){
              std::cout << "No" << '\n';
              return 0;
            }
          }
        }
        else{
          if(kind[i]==3){
            kind[i]=zerofound;
            zerofound++;
            zerokind=kind[i];
            if(zerofound>=4){
              std::cout << "No" << '\n';
              return 0;
            }
          }
          else{
            zerokind=kind[i];
          }
        }
      }
      else{
        if(zerokind!=3){
          if(kind[i]==zerokind){
            std::cout << "No" << '\n';
            return 0;
          }
        }
      }

    }
  }
  }

/*
  int ct0=0;
  int ct1=0;
  int ct2=0;

  rep(i,N){
    if(kind[i]==0) ct0++;
    if(kind[i]==1) ct1++;
    if(kind[i]==2) ct2++;
  }

  if(zerofound==1){
    if(ct0!=N/3){
      std::cout << "No" << '\n';
      return 0;
    }
  }
  if(zerofound==2){
    if(ct0!=N/3){
      std::cout << "No" << '\n';
      return 0;
    }
    if(ct1!=N/3){
      std::cout << "No" << '\n';
      return 0;
    }
  }
  */

  std::cout << "Yes" << '\n';

  return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
using namespace std;
#define reps(i,j,k) for(int i = j;i < k;i++)
#define rep(i,j) reps(i,0,j)
typedef pair < int,int > Pii;
bool F;
char change(int s){
	if(s == 0)return '+';
	if(s == 1)return '-';
	if(s == 2)return '*';
}
int calc(int a,int s,int b){
	if(s == 0)return a+b;
	if(s == 1)return a-b;
	if(s == 2)return a*b;
}
void solve(int num[5],int s[4],int dep){
	if(F)return ;
	if(dep == 3){
		if(calc(calc(calc(num[0],s[0],num[1]),s[1],num[2]),s[2],num[3]) == 10){
			printf("(((%d%c%d)%c%d)%c%d)\n",num[0],change(s[0]),num[1],change(s[1]),num[2],change(s[2]),num[3]);
			F = true;
			return ;
		}
		if(calc(calc(num[0],s[0],num[1]),s[1],calc(num[2],s[2],num[3])) == 10){
			printf("((%d%c%d)%c(%d%c%d))\n",num[0],change(s[0]),num[1],change(s[1]),num[2],change(s[2]),num[3]);
			F = true;
			return ;
		}
		
		return ;
	}
	rep(i,3){
		s[dep] = i;
		if(F)return ;
		solve(num,s,dep+1);
		if(F)return ;
	}
}
int main(){
	int a,b,c,d;
	while(scanf("%d%d%d%d",&a,&b,&c,&d),(a|b|c|d)){
		int num[4];
		F = false;
		num[0] = a;num[1] = b;num[2] = c;num[3] = d;
		sort(num,num+4);
		do{
			int s[4];
			solve(num,s,0);
			if(F)break;
		}while(next_permutation(num,num+4));
		if(!F)puts("0");
	}
	return 0;
}

Measured memory_bytes: 1056
from collections import defaultdict
from heapq import heappush, heappop, merge

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

day = defaultdict(list)
for a, b in ab:
    heappush(day[a], -b)

work, ans = [], 0
for i in range(1, m + 1):
    for j in day[i]:
        heappush(work, j)
    if len(work) > 0:
        ans -= heappop(work)
print(ans)


Measured memory_bytes: 106136
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;
lli combi(lli n, lli k){
  lli nume = 1;
  lli deno = 1;
  lli cnume = n;
  lli cdeno = k;
  F(i, k){
    nume *= cnume;
    cnume--;
    deno *= cdeno;
    cdeno--;
  }
  return nume / deno;
}

int main(){
  int N;
  cin >> N;
  string s[N];

  F(i, N){
    string st;
    cin >> st;
    vector<string> v;
    for(int j = 0; j < 10; j++){
      v.emplace_back(st.substr(j, 1));
    }
    sort(v.begin(), v.end());
    string tmps;
    tmps = v[0];
    FSG(j, 1, 10){
      tmps += v[j];
    }
    s[i] = tmps;
  }
  sort(s, s + N);

  lli cnt = 0;
  int cont = 1;
  FSG(i, 1, N){
    if(s[i-1] == s[i]){
      cont++;
    }
    if(i == N-1 || s[i-1] != s[i]){
      cnt += combi(cont, 2);
      cont = 1;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 7296
#include<iostream>
using namespace std;
using ll = long long;

int N, W;
ll w[110], v[110], INF = 1000000000000, dp[100100], V_SUM;

int main(){
	cin >> N >> W;
	for (int i = 0; i < N; i++){
		cin >> w[i] >> v[i];
		V_SUM += v[i];
	}
	for (int i = 0; i <= V_SUM; i++)dp[i] = INF;
	dp[0] = 0;
	for (int i = 0; i < N; i++){
		for (int j = V_SUM; j >= 0; j--){
			if (j >= v[i]) dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
		}
	}
	ll ans = 0;
	for (int i = 0; i <= V_SUM; i++)if (dp[i] <= W)ans = i;
	cout << ans << endl;
}

Measured memory_bytes: 1024
# coding: utf-8

L, R = tuple(map(int, input().split()))

max_i = 2019 * (int(L / 2019) + 1) 
R = max_i if max_i < R else R

res = float('inf')
for i in range(L, R):
    for j in range(i+1, R+1):
        res = min(res, i * j % 2019)

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

vector<ll> dp(440000);

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> s(n+1,0);
    rep(i,n){
        ll a;
        cin >> a;
        s[i+1] = s[i] + a;
    }
    ll ans = INF;
    REP(i,1,n){
        ll tmp = abs(2*s[i] - s[n]);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  if(s.at(0) == 'S'){
    cout << "Cloudy" << endl;
  }
  else if(s.at(0) == 'C'){
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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 int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  ll k; cin >> k;

  int n = 50;
  vector<ll> ans(n);

  REP(i,n) ans[i] = n-1;

  ll add = k / n;
  REP(i,n) ans[i] += add;

  ll m = k%n;

  REP(i,m) {
    ans[i] += n+1;
    REP(j,n) ans[j]--;
  }

  COUT(n);
  REP(i,n) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 32);
double EPS = 1e-4;

ll MOD = 1000000007;

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

  ll N = S.length();
  vi v1(N), v2(N), v3(N), v4(N);

  vi x(N + 1);
  {
    ll tmp = 1;
    for (ll i = 0; i <= N; i++) {
      x[i] = tmp;
      tmp = tmp * 3 % MOD;
    }
  }

  ll y = 0;
  for (char c: S) {
    if (c == '?') {
      y += 1;
    }
  }


  for (ll i = 0; i < N; i++) {
    if (i > 0) {
      v1[i] = v1[i - 1];
      v2[i] = v2[i - 1];
    }
    if (S[i] == 'A') {
      v1[i] += 1;
    }
    if (S[i] == '?') {
      v2[i] += 1;
    }
  }

  for (ll i = N - 1; i >= 0; i--) {
    if (i < N - 1) {
      v3[i] = v3[i + 1];
      v4[i] = v4[i + 1];
    }
    if (S[i] == 'C') {
      v3[i] += 1;
    }
    if (S[i] == '?') {
      v4[i] += 1;
    }
  }

  ll ans = 0;
  for (ll i = 1; i < N - 1; i++) {
    if (S[i] == 'B') {
      ans += v1[i - 1] * v3[i + 1] * x[y];
      if (y >= 1) {
        ans += v1[i - 1] * v4[i + 1] * x[y - 1];
        ans += v2[i - 1] * v3[i + 1] * x[y - 1];
      }
      if (y >= 2) {
        ans += v2[i - 1] * v4[i + 1] * x[y - 2];
      }
    }
    if (S[i] == '?') {
      if (y >= 1) ans += v1[i - 1] * v3[i + 1] * x[y - 1];
      if (y >= 2) ans += v1[i - 1] * v4[i + 1] * x[y - 2];
      if (y >= 2) ans += v2[i - 1] * v3[i + 1] * x[y - 2];
      if (y >= 3) ans += v2[i - 1] * v4[i + 1] * x[y - 3];
    }
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4480
#include <cstdio>
#include <queue>
using namespace std;
typedef pair<int, int> P;
char b[810][810];
int d[810][810];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int h, w;
int inb(int x, int y) {
	return 1 <= x && x <= h && 1 <= y && y <= w;
}
int go(int x, int k) {
	--x;
	return 1 + (x + k - 1) / k;
}
int main() {
	int k;
	int si, sj;
	scanf("%d%d%d", &h, &w, &k);
	for (int i = 1; i <= h; i++) {
		scanf("%s", b[i]+1);
		for (int j = 1; j <= w; j++) {
			if (b[i][j] == 'S') {
				si = i;
				sj = j;
			}
		}
	}
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			d[i][j] = 10000000;
		}
	}
	d[si][sj] = 0;
	queue<P> q;
	q.push(P(si, sj));
	while (q.size()) {
		int x = q.front().first, y = q.front().second;
		q.pop();
		if (x == 1 || x == h || y == 1 || y == w) {
			printf("1\n");
			return 0;
		}
		if (d[x][y] == k) {
			continue;
		}
		for (int z = 0; z < 4; z++) {
			int nx = x + dx[z], ny = y + dy[z];
			if (inb(nx, ny)) {
				if (b[nx][ny] == '.' && d[nx][ny] > 100000) {
					q.push(P(nx, ny));
					d[nx][ny] = d[x][y] + 1;
				}
			}
		}
	}
	int ans = 100000;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (d[i][j] < 100000) {
				int t = 100000;
				t = min(t, go(h + 1 - i, k));
				t = min(t, go(i, k));
				t = min(t, go(w + 1 - j, k));
				t = min(t, go(j, k));
				ans = min(ans, t);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

inline int64_t ceiling_div(int64_t a, int64_t b){ // ceiling(a/b)= floor((a+b-1)/b)
  return (a+b-1)/b;
}

int main(){
  int H,W,K;
  cin >> H >> W >> K;

  vector<vector<int>> cumsums(H);
  string buf;
  for(int i=0; i<H; i++){
    cin >> buf;
    int s= 0;
    cumsums.at(i).emplace_back(0);
    for(auto c:buf){
      if(c=='1'){ s++; }
      cumsums.at(i).emplace_back(s);
    }
  }

  int ans= INT_MAX;
  for(int tmp= 0; tmp< (1<<H-1); tmp++){
    vector<vector<int>> data;
    vector<int> buf_cumsum= cumsums.at(0);
    for(int i=1; i<H; i++){
      if((tmp & (1<<i-1)) != 0){
        data.emplace_back(buf_cumsum);
        buf_cumsum= cumsums.at(i);
      }
      else{
        for(int j=0; j<=W; j++){
          buf_cumsum.at(j)+= cumsums.at(i).at(j);
        }
      }
    }
    data.emplace_back(buf_cumsum);

    int cnt= __builtin_popcount(tmp);
    int idx_prev= 0;
    while(idx_prev < W){
      int idx= INT_MAX;
      for(auto piece:data){
        auto itr= upper_bound(piece.begin(), piece.end(), piece.at(idx_prev)+ K);
        int idx_p= distance(piece.begin(), itr-1);
        idx= min(idx, idx_p);
      }
      if(idx > idx_prev){
        idx_prev= idx;
        cnt++;
      }
      else{
        cnt= INT_MAX;
        break;
      }
    }
    cnt--; // 最後に空振りした分を相殺

    ans= min(ans, cnt);
  }

  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string s[20];
vector<int> v,v1,v2;
int main(){
    int i,j,l,r,h,w,k;
    cin >> h >> w >> k;
    for(i=0;i<h;i++){
        cin >> s[i];
    }
    int mn = h*w + 1;
    for(i=0;i<(1<<(h - 1));i++){
        v.clear(); v1.clear(); v2.clear();
        v.push_back(0);
        int x = i;
        int cnt = 0;
        while(cnt<h - 1){
            cnt++;
            if(x&1) v.push_back(cnt);
            x /= 2;
        }
        v.push_back(h);
        v1.resize((int)v.size() - 1); v2.resize((int)v.size() - 1);
        int ans = v.size() - 2;
        for(l=0;l<v.size() - 1;l++){
            int u = v[l],d = v[l + 1] - 1;
            for(r=u;r<=d;r++){
                v1[l] += (s[r][0]=='1');
            }
            if(v1[l]>k){
                ans = 1000000;
            }
        }
        for(j=1;j<w;j++){
            bool flag = false;
            for(l=0;l<v.size() - 1;l++){
                v2[l] = 0;
                int u = v[l],d = v[l + 1] - 1;
                for(r=u;r<=d;r++){
                    v2[l] += (s[r][j]=='1');
                }
                if(v1[l] + v2[l]>k) flag = true;
            }
            if(flag){
                ans++;
                for(l=0;l<v.size() - 1;l++){
                    v1[l] = v2[l];
                    if(v1[l]>k){
                        ans = 10000000;
                    }
                }
            }else{
                for(l=0;l<v.size() - 1;l++){
                    v1[l] += v2[l];
                }
            }
        }
        mn = min(mn,ans);
    }
    cout << mn << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;

int main() {
  int a[26],ans;
  string w; cin>>w;
  REP(i,26) a[i]=0;
  REP(i,w.size()) a[w[i]-'a']++;
  REP(i,26) if(a[i]%2) { cout << "No" <<endl; return 0;};
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static int[] cnth = new int[1500001];
	static int[] cntw = new int[1500001];

	static boolean solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		if (n + m == 0) return false;

		int[] h = new int[n+1];
		for (int i=1; i<=n; i++) {
			h[i] = in.nextInt();
			h[i] += h[i-1];
		}

		int[] w = new int[m+1];
		for (int i=1; i<=m; i++) {
			w[i] = in.nextInt();
			w[i] += w[i-1];
		}

		Arrays.fill(cnth,0);

		for (int i=1; i<=n; i++) {
			for (int j=1; j<=n; j++) {
				if (i-j < 0) continue;
				cnth[h[i] - h[i-j]]++;
			}
		}

		Arrays.fill(cntw,0);

		for (int i=1; i<=m; i++) {
			for (int j=1; j<=m; j++) {
				if (i-j < 0) continue;
				cntw[w[i] - w[i-j]]++;
			}
		}

		int ans = 0;
		for (int i=0; i<1500001; i++) {
			ans += cnth[i] * cntw[i];
		}

		out.println(ans);

		return true;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 77148
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define M 1000000007
#define pi acos(-1)
/*ll power(ll a,ll b)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res*a)%M;
        a = (a*a)%M;
        b = b >> 1;
    }
    return res;
}*/
/*ll modinv(ll a)
{
   return power(a,M - 2); 
}*/
/*vector<ll> primes(ll n)
{
    bool *sieve = new bool[n + 1];
    ll i,j;
    vector<ll> v;
    for(i = 3; i <= n; i+=2)
        sieve[i] = true;
    sieve[2] = true;
    for(i = 3; i*i <= n; i+=2)
    {
        if(sieve[i])
            for(j = i*i; j <= n; j+=i)
                sieve[j] = false;
    }
    if(n >= 2)
    {
        v.pb(2);
        for(i = 3; i <= n; i+=2)
        {
            if(sieve[i])
                v.pb(i);
        }
    }
    return v;
}*/

/*class graph{
public:
    vector<ll> *g;
    ll n;
    graph(ll v)
    {
        n = v + 1;
        g = new vector<ll> [n];
    }
    void addegde(ll f,ll s)
    {
        g[f].pb(s);
        g[s].pb(f);
    }
    void dfs(bool *visited,ll sv)
    {
        visited[sv] = true;
        for(auto x: g[sv])
        {
            if(!visited[x])
            {
                dfs(visited,x);
            }
        }
    }
    void bfs(ll sv){
       queue<ll> q;
       bool visited[n] = {};
       q.push(sv);
       visited[sv] = true;
       while(!q.empty())
       {
           ll node = q.front();
           q.pop();
           for(auto x : g[node])
           {
               if(!visited[x])
               {
                   visited[x] = true;
                   q.push(x);
               }
           }
       }
    }
};*/
int main()
{
    fast;
    string s1,s2;
    cin >> s1 >> s2;
    ll n,m;
    cin >> n >> m;
    string s3;
    cin >> s3;
    if(s1 == s3)
        cout<<(n - 1)<<" "<<m << endl;
    else if(s2 == s3)
        cout<<(n)<<" "<<(m - 1)<<endl;
    else
        cout<<n<<m<<endl;
    return 0;
}



Measured memory_bytes: 256
// C++ program to print all the cycles
// in an undirected graph
#include <bits/stdc++.h>
using namespace std;
int mod =1e9+7;
int main(){
int n;
cin >> n;
vector<long long int>A(n);
for(int i=0;i<n;++i)
    cin >> A[i];
vector<vector<long long int> >dp(n,vector<long long int>(n,1e18+8));
int L,R;
for(L=n-1;L>=0;--L){
    for(R=L;R<n;++R){
        if(L==R){
            dp[L][R]=0;
        }else{
            long long int s=0;
            for(int i=L;i<=R;++i)
                s+=A[i];
        // dp[L][R]=1e18+5;
           for(int i=L;i<R;++i){
            dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+s);

           }

        }

    }
}
cout << dp[0][n-1]<<endl;
return 0;



}


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

int main(){
    int a,b,c,d;
    cout << fixed << setprecision(12);
    double r;
    cin>>r;
    
    double PI = acos(-1);
    double area = r*r*PI;
    double cir = (r+r)*PI;
    cout << area <<" "<<cir<<endl;
}


Measured memory_bytes: 3224