akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

ll a[5],k;

int main(){
    inrep(5,a);
    cin >> k;

    if(a[4] - a[0] > k)P(":(");
    else P("Yay!");
	return  0;
}

Measured memory_bytes: 256
// Problem : C - Half and Half
// Contest : AtCoder Regular Contest 096
// URL : https://atcoder.jp/contests/arc096/tasks/arc096_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;																																																																																								void read(int&n){n=0;while(1){char c=getchar();if(c==' '||c=='\n')break;n=(n<<1)+(n<<3)+c-'0';}}void read(ll&n){n=0;while(1){char c=getchar();if(c==' '||c=='\n')break;n=(n<<1)+(n<<3)+c-'0';}}void write(int n){if(n>9)write(n/10),putchar(n%10+'0');else putchar(n+'0');}void write(ll n){if(n>9)write(n/10),putchar(n%10+'0');else putchar(n+'0');}template<class F,class... Ts>void read(F&f,Ts&...ts){read(f);read(ts...);}template<class F,class... Ts>void write(F&f,Ts&...ts) {write(f);putchar(' ');write(ts...);}template<class...Ts>void writeln(const Ts&...ts){write(ts...);putchar('\n');}

int a, b, c, x, y, ans = inf;

int main() { cin.tie(0)->sync_with_stdio(0);
	read(a, b, c, x, y);
	for(int i = 0; i <= max(x,y); i++) {
		ans = min(ans, i * (c << 1) + max(0, x - i) * a + max(0, y - i) * b);
	}
	write(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define MAX 120
int main(){
    int n,m;
    int A[MAX];
    double lim = 0;
    int sum=0; //総投票数
    int ans=0;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> A[i];
        sum += A[i];
    }
    lim = sum/(4.0*m);
    for(int i=0;i<n;i++){
        if((double)A[i] >= lim){
            ans++;
        }
    }
    
    if(ans >= m){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
  
    return 0;}


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

typedef long long ll;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int X, A;
    cin >> X >> A;
    cout << ((X < A) ? 0 : 10) << endl;
    return 0;
}

Measured memory_bytes: 3560
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
check=[-1]*n
finalans=-10**20
for i in range(n):
    if check[i]!=-1:
        continue
    loop=[i]
    now=i
    while p[now]!=i+1:
        check[now]=1
        loop.append(p[now]-1)
        now=p[now]-1
    L=len(loop)
    point=[0]*(L*2)
    point[0]=c[loop[0]]
    for j in range(1,L*2):
        if j<L:
            point[j]=point[j-1]+c[loop[j]]
        else:
            point[j]=point[j-1]+c[loop[j-L]]
    m=-10**20
    if point[L-1]>0:
        r=k%L
        if r==0:
            r=L
        for j in range(1,r+1):
            for t in range(j-1,j+L-1):
                cand=point[t]-point[t-j] if t-j>=0 else point[t]
                m=max(m,cand)
        ans=point[L-1]*(k//L)+m if r!=L else point[L-1]*((k//L)-1)+m
    else:
        for j in range(1,L+1):
            for t in range(j-1,j+L-1):
                cand=point[t]-point[t-j] if t-j>=0 else point[t]
                m=max(m,cand)
        ans=m
    finalans=max(ans,finalans)   
print(finalans)

Measured memory_bytes: 79812
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
	string s; cin >> s;
	int n = s.length();
	string ans(s);

	if (n==26) {
		if (s=="zyxwvutsrqponmlkjihgfedcba") {
			cout << -1 << endl;
			return 0;
		}
		vector<bool> used(26,false);

		for (int i = n-1; i > 0; --i) {
			if (s[i-1]<s[i]) {
				char under = s[i-1];
				used[(int)(s[i]-'a')]=true;
				ans.pop_back();
				ans.pop_back();
				rep(j,26) {
					if (used[j] &&  under<(char)(j+'a')) {
						ans.push_back((char)(j+'a'));
						break;
					}
				}
				break;
			}
			else {
				used[(int)(s[i]-'a')]=true;
				ans.pop_back();
			}
		}
	}
	else {
		vector<int> b(26);
		rep(i,n) b[(int)(s[i]-'a')]++;
		rep(i,26) if (b[i]==0) {
			ans.push_back(i+'a');
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main()
{
 //clock_t start=clock();
    std::string S;
    long K;
    std::cin >> K;
    std::cin >> S;
    if(S.length()<=K){
        std::cout << S << std::endl;
    }else{
        for(long i=0; i<K; i++){
            std::cout << S[i];
        }
        std::cout << "..." << std::endl;
    }
    //clock_t end=clock();
//std::cout << static_cast<double>(end-start)/CLOCKS_PER_SEC * 1000.0 << std::endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[4][1000000];
ll n;
ll dpdp[4][1000000];
ll dp(ll x, ll m)
{
    if(dpdp[m][x]!=-1)
        return dpdp[m][x];
    if(x>=n)
    {
        dpdp[m][x]=0;
        return 0;
    }
    ll ans=0;
    for (int i = 1; i < 4; ++i)
    {
        if (i!=m)
        {
            ans=max(ans, a[i][x]+dp(x+1, i));
        }
    }
    // cout << x << m << ans<<"\n";
    dpdp[m][x]=ans;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        dpdp[0][i]=-1;
        dpdp[1][i]=-1;
        dpdp[2][i]=-1;
        dpdp[3][i]=-1;
        cin >> a[1][i]>> a[2][i] >> a[3][i];
    }
    cout << dp(0, 0);
    return 0;
}

Measured memory_bytes: 31360
#include<stdio.h>

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a%b != 0) {
		printf("%d\n", (a / b) + 1);
	}
	else {
		printf("%d\n", a / b);
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int atcoder(){
    //入力
    string s,t;
    cin >> s >> t;
    bool ans = false;
    bool onaji = true;
    REP(i,0,s.length()){
        REP(j,0,t.length()){
            if(s[i]<t[j]) ans = true;
            if(s[i]!=t[j]) onaji = false;
        }
    }
    if(onaji && s.length()<t.length()) ans = true;
    //処理
    //出力
    if(ans) cout << "Yes" << ENT;
    else cout << "No" << ENT;
    return 0;
}

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


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        
        int dis = scanner.nextInt();
        int time = scanner.nextInt();
        int speed = scanner.nextInt();
        
        if(dis<=time*speed){
            System.out.print("Yes");
        }else{
            System.out.print("No");
        }
    }
}

Measured memory_bytes: 35640
package main

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

type TupleInt struct {
	first  int
	second int
}

func main() {
	sc := NewScanner()
	S := sc.Next()
	slice := strings.Split(S, "")
	sum := 0
	max := 0
	for _, str := range slice {
		if str== "A" || str== "T" || str== "C" || str== "G"  {
			sum++
		} else {
			sum = 0
		}
		max = Max(sum,max)
	}
	fmt.Println(max)


}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type SortInterFace []TupleInt

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].first < s[j].first
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define int int64_t
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   int n, cnt, ans;
   cin >> n;
   bool a = true;
   vector<int> x(n), y;

   rep(i, n)
   {
      cin >> x[i];
      y.push_back(x[i]);
   }

   gsort(y);

   rep(i, n)
   {
      if (a && y[0] == x[i])
      {
         cout << y[1] << '\n';
         a = false;
      }
      else
         cout << y[0] << '\n';
   }
}

Measured memory_bytes: 4976
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N + 1), b(N);
	ll sum = 0;
	for (ll i = 0; i <= N; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	for (ll i = 0; i < N; i++)
	{
		cin >> b[i];
		if (i != 0 && b[i - 1] > 0) {
			a[i] = (a[i] > b[i - 1]) ? (a[i] - b[i - 1]) : 0;
		}
		if (a[i] > b[i]) {
			a[i] = a[i] - b[i];
			b[i] = 0;
		}
		else {
			b[i] -= a[i];
			a[i] = 0;
		}
	}
	if (b[N - 1] > 0) {
		a[N] = (a[N] > b[N - 1]) ? (a[N] - b[N - 1]) : 0;
	}
	ll ans = 0;
	for (ll i = 0; i < N + 1; i++)
	{
		ans += max(0LL, a[i]);
	}
	cout << sum - ans << endl;
	return 0;
}

Measured memory_bytes: 1792
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int n,ans=0,a=0,b=0,ab=0;
    R(n);
    string s;
    REP(i,n) {
        cin >> s;
        REP(j,SZ(s)-1) if ( s[j]=='A' && s[j+1]=='B' ) ans++;
        if ( s[0]=='B' && s.back()=='A' ) ab++;
        else if ( s[0]=='B' ) b++;
        else if ( s.back()=='A' ) a++;
    }
    if ( ab ) {
        ans+=ab-1;
        if ( a ) ans++,a--;
        if ( b ) ans++,b--;
    }
    ans+=min(a,b);
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3788
import bisect

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

N, M = cin()
l1 = [[] for i in range(N + 1)]
l2 = []
for i in range(M):
    in1, in2 = cin()
    l1[in1].append(in2)
    l2.append([in1, in2])

for i in range(N + 1):  l1[i] = sorted(l1[i])
    
for i in range(M):
    c = l2[i]
    n = bisect.bisect_left(l1[c[0]], c[1]) + 1
    ans = str(c[0]).zfill(6) + str(n).zfill(6)
    print(ans)

Measured memory_bytes: 107064
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m=parseMap(split(readline()))
    ab=[parseMap(split(readline())) for i in 1:n]
    sort!(ab,by=x->x[1])
    ans=0
    cnt=0
    for i in 1:n
        if cnt+ab[i][2]>=m
            ans+=ab[i][1]*(m-cnt)
            break
        else
            ans+=ab[i][1]*ab[i][2]
            cnt+=ab[i][2]
        end
    end
    println(ans)
end
main()

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

using namespace std;

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

    string S, T;
    cin >> S >> T;
    int res = 0;
    for (int i = 0; i < 3; ++i) {
        res += S[i] == T[i];
    }
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

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

	int n;
	cin>>n;
	bool h=true;
	rep(i,n){
		int a;cin>>a;
		if(a%2)h=false;
	}
	if(h)cout<<"second"<<endl;
	else cout<<"first"<<endl;
}


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

#define all(x) (x).begin(),(x).end()
typedef long long ll;

ll gcd(ll a, ll b){

    if(a < b) swap(a, b);

    if(b == 0) return a;
    return gcd(b, a % b);

}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
} 

void LCM(ll a, ll b, ll &a_last, ll &b_last){

    ll modA = a_last / a;
    if(a_last % a > 0) modA += 1;

    ll modB = b_last / b;
    if(b_last % b > 0) modB += 1;

    a_last = a * max(modA, modB);
    b_last = b * max(modA, modB);

}

int main(){

    int N;
    cin >> N;

    ll a, b, a_last, b_last;
    a_last = 1;
    b_last = 1;
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        LCM(a, b,  a_last , b_last) ;
    }
   
    cout << a_last + b_last << endl;

}

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

typedef long long ll;
typedef pair<int, int> ii;

string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  bool ok = true;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == ((i & 1) ? 'R' : 'L')) {
      ok = false;
      break;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
lst_B = list(map(int, input().split()))

AC = 0
for _ in range(N):
    lst_A = list(map(int, input().split()))
    judge = C
    for a, b in zip(lst_A, lst_B):
        judge += a*b
    if judge > 0:
        AC += 1
print(AC)


Measured memory_bytes: 3064
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	s = chomp(s);
	int ans = 0;
	for(int i=0;i<s.length;i++){
	    char c = s[i];
	    int n1,n2;
	    if(c == 'I') n1 = 1;
	    else if (c=='V') n1 = 5;
	    else if (c=='X') n1 = 10;
	    else if (c=='L') n1 = 50;
	    else if (c=='C') n1 = 100;
	    else if (c=='D') n1 = 500;
	    else if (c=='M') n1 = 1000;
	    if(i<to!int(s.length)-1){
		c = s[i+1];
		if(c == 'I') n2 = 1;
		else if (c=='V') n2 = 5;
		else if (c=='X') n2 = 10;
		else if (c=='L') n2 = 50;
		else if (c=='C') n2 = 100;
		else if (c=='D') n2 = 500;
		else if (c=='M') n2 = 1000;
		if(n1 < n2){
		    n1 = n2 - n1;
		    i++;
		}
	    }
	    ans += n1;
	}
	writeln(ans);
    }

}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=6005,INF=1<<29;
ll dp[MAX][2*MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    N*=3;
    dp[0][6000]=1;
    
    for(int i=0;i<N;i++){
        for(int j=1;j<=12000;j++){
            dp[i+3][j]+=dp[i][j]*(N-i-1)%M*(N-i-2)%M;
            dp[i+3][j]%=M;
            
            dp[i+2][j-1]+=dp[i][j]*(N-1-i)%M;
            dp[i+2][j-1]%=M;
            
            dp[i+1][j+1]+=dp[i][j];
            dp[i+1][j+1]%=M;
        }
    }
    
    ll ans=0;
    
    for(int j=6000;j<=12000;j++){
        ans+=dp[N][j];
        ans%=M;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 563456
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

res = 1
tank = [0,0,0]

for e in a:
    cnt = 0
    idx = -1
    if tank[0] == e:
        cnt += 1
        idx = 0
    if tank[1] == e:
        cnt += 1
        idx = 1       
    if tank[2] == e:
        cnt += 1
        idx = 2
    
    if cnt == 0:
        print(0)
        exit()
    
    res = res*cnt%mod
    tank[idx] += 1

print(res)

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

int dfs(int flg, long long state, int limit){
  if (state > limit) return 0;
  int cnt = 0;
  if (flg == 0b111) {
    //cout << state<< endl;
    cnt++;
  }
  
  cnt += dfs(flg|0b001, state*10+3, limit);
  cnt += dfs(flg|0b010, state*10+5, limit);
  cnt += dfs(flg|0b100, state*10+7, limit);
  
  return cnt;

}
int main() {
  int N;
  cin >> N;
  
  int cnt = 0;
  
  cnt = dfs(0, 0, N);
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int n,m,ah,am,bh,bm,bt,at,r=0,i,t[20];
  char s[60],d[20][60];
  scanf("%d %d",&n,&m);
  scanf("%*d:%*d %*s %d:%d %s",&bh,&bm,s);
  bt=bh*60+bm;
  for(i=1;i<n;i++){
    scanf("%d:%d %s %d:%d %*s",&ah,&am,s,&bh,&bm);
    at=ah*60+am;
    if(at-bt>=m){
      strcpy(d[r],s);
      t[r++]=at-bt;
    }
    bt=bh*60+bm;
  }
  printf("%d\n",r);
  for(i=0;i<r;i++)printf("%s %d\n",d[i],t[i]);
  return 0;
}

Measured memory_bytes: 616
import copy
Row = int(input())
List = []
for i in range (Row):
  List.append(int(input()))
NewList = copy.deepcopy(List)
NewList.sort()
high = NewList[Row-1]
secondHigh = NewList[Row-2]
for i in range(Row):
  if List[i] == high:
    print(secondHigh)
  else:
    print(high)
  

Measured memory_bytes: 19188
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	as <- sort <$> readIntegers
	print $ fromMaybe (-1) $ foldl f ( Just 1 ) as

f ( Just a ) b
	| a * b <= 10 ^ 18 = Just $ a * b
	| otherwise = Nothing
f _ _ = Nothing

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

ll sum(ll l, ll r) { return (l + r) * (r - l + 1) / 2; }

int main() {
  int n, k;
  cin >> n >> k;
  mint ans = 0;
  for (int i = k; i <= n + 1; i++) {
    mint min = sum(0, i - 1);
    mint max = sum(n - i + 1, n);
    // cout << min.x << ' ' << max.x << endl;
    ans += max - min + 1;
  }
  cout << ans.x << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  ll ans = 0;
  REP(i, N) ans += (ll)(i+1) * (N-i);
  REP(i, N-1) {
    int a = nextLong() - 1;
    int b = nextLong() - 1;
    if (a > b) swap(a, b);
    ans -= (ll)(a + 1) * (N - b);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int main() {
	ll x,y,ans=0;
	cin>>x>>y;
	ll tmp=x;
	while(tmp<=y){
		ans++;
		if(tmp>1e18)break;
		tmp*=2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define int long long
#define ff first
#define ss second
#define fill(x, v) memset(x, v, sizeof(x))
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define ios std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
/*
std::cout << std::setprecision(9) << f << '\n';//3.141590000;
map<char,int>::reverse_iterator rit;
for(rit = mp.rbegin(); rit!=mp.rend(); rit++)
*/
int n, m, k, t, mod = 1e9 + 7;
vector<int> gr[2 * 100000 + 1];
pair<int, int> dfs(int node, int par)
{
    int all_white = 1;//ways of getting all white immediate children 
    int some_black = 0;//ways of getting some black immediate children
    for (int child : gr[node])
    {
        if (child != par)
        {
            pair<int, int> p = dfs(child, node);
            some_black = (((all_white + some_black) * p.ss) % mod + (p.ff * some_black) % mod) % mod;
            all_white = (all_white * p.ff) % mod;
        }
    }
    int white = (all_white + some_black) % mod;
    int black = all_white;
    return {white, black};
}
int32_t main()
{
    ios;
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        gr[x].pb(y);
        gr[y].pb(x);
    }
    pair<int, int> ans = dfs(1, -1);
    cout << (ans.ff + ans.ss) % mod << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define vec vector

int dp[55][55];

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

void dfs(int x, int y)
{
	if (!dp[x][y]) return;
	dp[x][y] = 0;
	rep(i, 8) dfs(x + dx[i], y + dy[i]);
}

int main(void)
{
	while(1) {
		int w, h;
		cin >> w >> h;
		if (!w) break;
		rep(i, h + 2) rep(j, w + 2) dp[i][j] = 0;
		rep(i, h) rep(j, w) {
			cin >> dp[i + 1][j + 1];
		}
		
		int ret = 0;
		rep(i, h) rep(j, w) {
			if (!dp[i + 1][j + 1]) continue;
			ret++;
			dfs(i + 1, j + 1);
		}
		cout << ret << endl;
	}
	return 0;

}

		

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin >> n;
  int x[n];
  rep(i,n) cin >> x[i];
  int ans=1001001001;
  for(int j=1;j<101;j++){
    int sum = 0;
    for(int i=0;i<n;i++){
      sum+=((x[i]-j)*(x[i]-j));
    }
    ans=min(ans,sum);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
if len(s)!=1:
  l=[]
  for k in range(2**(len(s)-1)):
    l.append(format(k,'0'+str(len(s)-1)+'b'))
  c=0
  for i in range(2**(len(s)-1)):
    m=list(l[i])
    m.append('1')
    x=0;y=0
    for j in range(len(s)):
      if m[j]=='0':y+=1
      else:
        c+=int(s[x:x+y+1])
        x=j+1
        y=0
  print(c)
else:print(int(s))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true) {
		int ans = 0;
		int N, M;
		vector<int> s1, s2, S;
		vector<int> min1, min2;
		
		cin>>N>>M;
		
		if(!N && !M) break;
		
		s1.resize(N);
		s2.resize(N);
		S.resize(M);
		
		for(int i = 0; i < M; i++){
			int k;
			
			cin>>S[i]>>k;
			
			for(int j = 0; j < k; j++){
				int c;
				
				cin>>c;
				
				c--;
				
				s1[c] += S[i];
				
				if(k == 1) s2[c] += S[i];
			}
		}
		
		min1 = s2;
		min2 = s2;
		
		for(int i = 1; i < N; i++){
			min1[i] = min(min1[i], min1[i-1]);
		}
		
		for(int i = N-2; i >= 0; i--){
			min2[i] = min(min2[i], min2[i+1]);
		}
		
		for(int i = 0; i < N; i++){
			int minimum = INF;
			
			if(i) minimum = min1[i-1];
			if(i+1!=N) minimum = min(min2[i+1], minimum);
			
			ans = max(ans, s1[i] - minimum + 1);
		}
		
		cout<<ans<<endl;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 3360
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 1000000000000000
#define MAX 200001
#define MOD 1000000007  

int main(){
    ll N, x;
    ll ans = INF;
    cin >> N >> x;
    vector<ll> a(N);
    vector<ll> b(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < N; i++){
        ll res = 0;
        for(int j = 0; j < N; j++){
            if(i == 0) b[j] = a[j];
            else if(j - i < 0){
                b[j] = min(b[j], a[N - i + j]);
            }
            else if(j - i >= 0){
                b[j] = min(b[j], a[j - i]);
            }
        }
        for(int k = 0; k < N; k++){
            res += b[k];
        }
        res += i * x;
        ans = min(ans, res);
    }
    cout << ans << endl;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for(int i = 0; i >= 0; i++){
        if(c-b<=0){
            cout << "Yes" << endl;
            return 0;
        }
        c -= b;
        if(a-d<=0){
            cout << "No" << endl;
            return 0;
        }
        a -= d;
    }
}

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

using namespace std;

void solve() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int _ = 0; _ < m; _++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].emplace_back(y);
    }

    int root;

    const int INF = 0x3f3f3f3f;
    int mi_len = INF;
    vector<int> trk(n, 0);
    vector<int> pth;
    vector<int> res;
    function<void(int)> dfs = [&](int u){
        trk[u] = 1;
        pth.emplace_back(u);
        for (int v: g[u]){
            if (v == root && (int)pth.size() < mi_len) {
                mi_len = pth.size();
                res.clear();
                res = pth;
            }
            if (!trk[v]) dfs(v);
        }
        pth.pop_back();
    };
    for (int i = 0; i < n; i++) {
        fill(trk.begin(), trk.end(), 0);
        root = i; dfs(i);
    }
    if (mi_len < INF) {
        cout << mi_len << "\n";
        for (auto& x: res) {
            cout << (x+1) << "\n";
        }
    } else cout << -1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int l, r, ct = 0, cont = 0;
    vector<int> positions;
    for(int i = 0; i < n; i++) {
        if(!(s[i] == 'A' and s[i+1] == 'C')) positions.push_back(ct);
        else {
            positions.push_back(ct);
            ct++;
        }
    }
    while(q--) {
        cont = 0;
        cin >> l >> r;
        cout << positions[r-1] - positions[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1528
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }






int main() {
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> a(h);
    ll sy = 0, sx = 0;
    REP(i, h){
        cin >> a[i];
        REP(j, w){
            if(a[i][j] == 'S'){
                sy = i; sx = j;
            }
        }
    }
    
    struct data{
        ll y, x, d;
    };
    queue<data> que;
    que.push({sy, sx, k});
    const ll dy[4] = {-1, 0, 1, 0};
    const ll dx[4] = {0, 1, 0, -1};
    vector<vector<bool>> used(h, vector<bool>(w));
    used[sy][sx] = true;
    while(!que.empty()){
        auto t = que.front(); que.pop();
        ll y = t.y, x = t.x, d = t.d;
        if(y == 0 || y == h - 1 || x == 0 || x == w - 1){
            cout << 1 << endl;
            return 0;
        }
        
        REP(i, 4){
            ll yy = y + dy[i], xx = x + dx[i];
            if(a[yy][xx] != '#' && !used[yy][xx] && d > 0){
                que.push({yy, xx, d - 1});
                used[yy][xx] = true;
            }
        }
    }
    
    ll ans = INF;
    REP(i, h){
        REP(j, w){
            if(used[i][j]){
                ll tmp = min({i, j, h - 1 - i, w - 1 - j});
                ans = min(ans, 1 + ((tmp % k == 0)? tmp / k : tmp / k + 1));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1280
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
int main(void){

	while(1){
		long long int b;
		

		cin>>b;
		if(b==0){
			break;
		}

		LRFOR(n,1e5,1){
			if((2*b)%n==0){
				long long int a=(((2*b)/n)-n+1);
				if(a%2==0&&a>=1){
					cout<<a/2<<" "<<n<<endl;
					break;
				}
			}
		}

	}

}


Measured memory_bytes: 3108
from collections import deque

N = int(input())

data = [[] for i in range(N)]


for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    data[a].append((i,b))###(edge no.,edgeの行き先)
    data[b].append((i,a))###(edge no.,edgeの行き先)

l = 0

for i in range(N):
    l = max(l,len(data[i]))

print(l)

stack = deque([(0,-1)]) ###(頂点番号, 前の頂点からきた色)
visit = [0]*N
visit[0] = 1
color = [0]*(N-1)

while stack:
    x = stack.pop()
    c = 1
    for y in data[x[0]]:
        if visit[y[1]] == 1:
            continue
        else:
            visit[y[1]] = 1
            if c != x[1]:
                color[y[0]]=c
                stack.append((y[1],c))
                c += 1
            else:
                color[y[0]]=c+1
                stack.append((y[1],c+1))
                c += 2

#print(color)
for i in range(N-1):
    print(color[i])

Measured memory_bytes: 40008
#define d for(x=0;x<N;x++){for(y=0;y<N;y++
c,m[10][10],x,N;main(y){for(;scanf("%d",&N),N;){d)m[x][y]=(x+y)*(x-~y)/2-~(x+y&1?x:y);}printf("Case %d:\n",++c);d)printf("%3d",x+y<N?m[x][y]:N*N+1-m[N+~x][N+~y]);puts("");}}exit(0);}

Measured memory_bytes: 616
#include<stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if (a<b){
        printf("a < b\n");
    } else if(a>b){
        printf("a > b\n");
    } else {
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn=400005;

struct {
	ll sum,lazy;	
} S[maxn];
int n,q;

void update(int id,int ql,int qr,int v,int l,int r) {
	if (ql==l && qr==r) {
		S[id].lazy+=v;
		return;
	}
	if (S[id].lazy) {
		S[id].sum+=S[id].lazy*(r-l+1);
		if (l!=r) {
			S[id<<1].lazy+=S[id].lazy;
			S[id<<1|1].lazy+=S[id].lazy;
		}
		S[id].lazy=0;
	}
	int m=l+r>>1;
	if (qr<=m) update(id<<1,ql,qr,v,l,m);
	else if (ql>m) update(id<<1|1,ql,qr,v,m+1,r);
	else update(id<<1,ql,m,v,l,m), update(id<<1|1,m+1,qr,v,m+1,r);
	S[id].sum=S[id<<1].sum+S[id<<1|1].sum+S[id<<1].lazy*(m-l+1)+S[id<<1|1].lazy*(r-m);
}

ll query(int id,int ql,int qr,int l,int r) {
	if (S[id].lazy) {
		S[id].sum+=S[id].lazy*(r-l+1);
		if (l!=r) {
			S[id<<1].lazy+=S[id].lazy;
			S[id<<1|1].lazy+=S[id].lazy;
		}
		S[id].lazy=0;
	}
	int m=l+r>>1;
	if (ql==l && qr==r) return S[id].sum;
	if (qr<=m) return query(id<<1,ql,qr,l,m);
	else if (ql>m) return query(id<<1|1,ql,qr,m+1,r);
	else return query(id<<1,ql,m,l,m)+query(id<<1|1,m+1,qr,m+1,r);
}

int main() {
	cin>>n>>q;
	for (int i=0;i<q;i++) {
		bool op; cin>>op;
		int s,t,x;
		if (op) {
			cin>>s>>t;
			cout<<query(1,s,t,1,n)<<'\n';
		}
		else {
			cin>>s>>t>>x;
			update(1,s,t,x,1,n);
		}
	}
}



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

int A[3];

int main() {
	for (int i = 0; i < 3; ++i) scanf("%d", A+i);
	sort(A, A+3);
	
	int tot = 0;
	while (A[1] < A[2]) A[0]++, A[1]++, tot++;
	while (A[0] < A[1]) A[0] += 2, tot++;
	if (A[0] > A[1]) tot++;

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

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,m,x,mn=1e18; ll ar[13],mt[13][13],fl[13];
void maxval(ll i){
    if(i==n+1){
        ll j,k,l,tmp[13]={0},cc=0;
        for(j=1;j<=n;j++){
            if(fl[j]==0) continue;
            cc+=ar[j];
            for(k=1;k<=m;k++){
                tmp[k]+=mt[j][k];
            }
        }
        int flg=1;
        for(j=1;j<=m;j++){
            if(tmp[j]<x){
                flg=0;
                break;
            }
        }
        if(flg){
            mn=min(mn,cc);
        }
        return ;
    }

    maxval(i+1);
    fl[i]=1;
    maxval(i+1);
    fl[i]=0;
}
int main(){
  
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll i,j,k,l;
    cin>>n>>m>>x;
    for(i=1;i<=n;i++){
        cin>>ar[i];
        for(j=1;j<=m;j++){
            cin>>mt[i][j];
        }
    }

    maxval(1);
    if(mn==1e18){
        cout<<"-1";
    }
    else cout<<mn;
    return 0;   
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int ans=1,n,k;
int main(){
	cin>>n>>k;
	while(n--) ans+=min(ans,k);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 10010
#define int long long
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,a[N],b[N],x;
signed main()
{
	// freopen("read.in","r",stdin);
	n=read(); x=0;
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	for(int i=1;i<=n;i++)
		if(a[i]>b[i]) x+=b[i]-a[i];
		else x+=(b[i]-a[i])/2;
	// cout << x << endl;
	if(x>=0) puts("Yes"); else puts("No");
}

Measured memory_bytes: 384
/*D - RGB Triplets*/
#include <bits/stdc++.h>
using namespace std;

using Long = long long;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string cad;
	int tam;

	cin >> tam >> cad;

	vector <Long> acumR(tam);
	vector <Long> acumG(tam);
	vector <Long> acumB(tam);

	Long ans = 0;

	for (int i = tam - 1; i >= 0; --i)
	{
		if (i + 1 < tam)
		{
			acumR[i] = acumR[i + 1];
			acumG[i] = acumG[i + 1];
			acumB[i] = acumB[i + 1];
		}
		
		if(cad[i] == 'R')
			acumR[i]++;
		else if(cad[i] == 'G')
			acumG[i]++;
		else
			acumB[i]++;
	}

	int dist;

	for (int i = 0; i < tam; ++i)
	{
		if(cad[i] == 'R'){
			for (int j = i + 1; j < tam ; ++j)
			{
				if(cad[j] == 'G'){
					
					dist = j - i;
					ans += acumB[j];

					if(j + dist < tam){
						if(cad[j + dist] == 'B')
							ans--;
					}
				}

				if(cad[j] == 'B'){
					
					dist = j - i;
					ans += acumG[j];

					if(j + dist < tam){
						if(cad[j + dist] == 'G')
							ans--;
					}
				}
			}
		}

		else if(cad[i] == 'G'){
			for (int j = i + 1; j < tam ; ++j)
			{
				if(cad[j] == 'R'){
					
					dist = j - i;
					ans += acumB[j];

					if(j + dist < tam){
						if(cad[j + dist] == 'B')
							ans--;
					}
				}

				if(cad[j] == 'B'){
					
					dist = j - i;
					ans += acumR[j];

					if(j + dist < tam){
						if(cad[j + dist] == 'R')
							ans--;
					}
				}
			}
		}
		else{
			for (int j = i + 1; j < tam ; ++j)
			{
				if(cad[j] == 'R'){
					
					dist = j - i;
					ans += acumG[j];

					if(j + dist < tam){
						if(cad[j + dist] == 'G')
							ans--;
					}
				}

				if(cad[j] == 'G'){
					
					dist = j - i;
					ans += acumR[j];

					if(j + dist < tam){
						if(cad[j + dist] == 'R')
							ans--;
					}
				}
			}
		}

	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3716
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]

ans=-10**18
for i in range(1,2**10):
  tmp=0
  for j in range(N):
    cnt=0
    for k in range(10):
      if i&(1<<k) and F[j][k]:
        cnt+=1
    tmp+=P[j][cnt]
  ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 3064