akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final String S = sc.next();

        Pattern p = Pattern.compile("^[0-9]{" + A + "}-[0-9]{" + B + "}");
        System.out.println(p.matcher(S).matches() ? "Yes" : "No");
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back
#define inf 10000000000000

							
									//nestedcode


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    char c;
    cin>>c;
    if(c-'a' >= 0){
        cout<<'a';
    }else{
        cout<<'A';
    }
    
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    long long temp,ans=0;
    pair<int , int>a[100001];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        temp=min(m,a[i].second);
        if(m>0)
        {
            m-=temp;
            ans+=a[i].first*temp;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

dp = [INF]*(100001)
dp[0] = 0
dp[1] = 1
dp[6] = 1
dp[6**2] = 1
dp[6**3] = 1
dp[6**4] = 1
dp[6**5] = 1
dp[6**6] = 1
dp[9] = 1
dp[9**2] = 1
dp[9**3] = 1
dp[9**4] = 1
dp[9**5] = 1

for i in range(N):
	dp[i+1] = min(dp[i+1], dp[i]+1)
	if i+6 > N:
		continue
	dp[i+6] = min(dp[i+6], dp[i]+1)
	if i+9 > N:
		continue
	dp[i+9] = min(dp[i+9], dp[i]+1)
	if i+6**2 > N:
		continue
	dp[i+6**2] = min(dp[i+6**2], dp[i]+1)
	if i+9**2 > N:
		continue
	dp[i+9**2] = min(dp[i+9**2], dp[i]+1)
	if i+6**3 > N:
		continue
	dp[i+6**3] = min(dp[i+6**3], dp[i]+1)
	if i+9**3 > N:
		continue
	dp[i+9**3] = min(dp[i+9**3], dp[i]+1)
	if i+6**4 > N:
		continue
	dp[i+6**4] = min(dp[i+6**4], dp[i]+1)
	if i+9**4 > N:
		continue
	dp[i+9**4] = min(dp[i+9**4], dp[i]+1)
	if i+6**5 > N:
		continue
	dp[i+6**5] = min(dp[i+6**5], dp[i]+1)
	if i+6**6 > N:
		continue
	dp[i+6**6] = min(dp[i+6**6], dp[i]+1)
	if i+9**5 > N:
		continue
	dp[i+9**5] = min(dp[i+9**5], dp[i]+1)

# for i in range(N+1):
# 	print(i, dp[i])
print(dp[N])

Measured memory_bytes: 4604
def main():
    n = int(input())
    a = list(map(int, input().rstrip().split(' ')))
    M = 10**6 + 5
    cnt = [0 for _ in range(M)]
            
    for ai in a:
        if cnt[ai] != 0:
            cnt[ai] = 2
            continue
        for i in range(ai, M, ai):
            cnt[i] += 1
    ans = 0
    for ai in a:
        if cnt[ai] == 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

#define sz 100005
#define nl printf("\n");
#define ll long long int

char f,g;
bool flag;
pair < int ,int > pi;
map < int , int > mp;
vector < int > v,va,vb;
int arr[sz],brr[sz],crr[sz];



int main(){

    double a,b,c,d,temp=INT_MAX,ans=INT_MAX,temp2;
    int n,m, i,j,k, x=0,y=0,z=0,idx;

    cin>>n>>a>>b;
    for(i=1; i<=n; i++){
        cin>>c;

        temp=a-c*0.006;
        temp2=(temp-b);
        if(temp2<0)
            temp2*=-1.0;
        //cout<<temp2<<endl;

        if(temp2<ans){
            ans=temp2;
            idx=i;
        }
    }
    cout<<idx<<endl;



    return 0;

}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define ss second
#define ff first 
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0)return (power((x*x)%M,n/2))%M;else return ((x%M)*power(x,n-1)%M);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
    for (ll i = 1; i <= n; i++){ 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll ncrmod(ll n, ll r, ll p){ 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
   return (ncrmod(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p;  
} 
ll modInverse(ll a,ll m) 
{ 
   ll m0 = m; 
   ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
       ll q = a / m; 
       ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
vector<int>adg[200001];
int vis[200001];
int a=0;
void dfs(int n,int len){
a+=1;
vis[n]=1;
for(int i=0; i<adg[n].size(); i++){
if(vis[adg[n][i]]==0)
dfs(adg[n][i],len+1);
}
// return len;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int v,e,l,r;
cin>>v>>e;
for(int i=0; i<=200000; i++)
vis[i]=0;
while(e--){
cin>>l>>r;
adg[l].pb(r);
adg[r].pb(l);
}
int ans=INT_MIN;
for(int i=1; i<=v; i++){
if(vis[i]==0)
a=0,dfs(i,1),ans=max(a,ans);
}
cout<<ans;
return 0;
}

Measured memory_bytes: 24536
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int64_t A, B, N;
  cin >> A >> B >> N;

  cout << A * min(B - 1, N) / B << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <stack>
#define nmax 5000
#define mmax 200
using std::cin;
using std::cout;
long long max(long long a, long b)
{
    return (a < b) ? b : a;
}
struct pii
{
    int first, second;
    pii(int f, int s)
    : first(f), second(s) {}
};
int n, m, a[nmax+1], b[nmax+1][mmax+1], cl, cr, cv;
std::stack<pii> stk[mmax+1];
long long smt[nmax*4+1], lazy[nmax*4+1];
void propg(int id, int leaf)
{
    if(!leaf){
      smt[id << 1] += lazy[id];
      lazy[id << 1] += lazy[id];
      smt[id << 1 | 1] += lazy[id];
      lazy[id << 1 | 1] += lazy[id];
    }
    lazy[id] = 0;
}
void upd(int id, int l, int r)
{
    if(cl <= l && r <= cr){
      smt[id] += cv;
      lazy[id] += cv;
      propg(id, l == r);
      return;
    }
    propg(id, 0);
    int mid = (l + r) >> 1;
    if(cl <= mid) upd(id << 1, l, mid);
    if(mid < cr) upd(id << 1 | 1, mid + 1, r);
    smt[id] = max(smt[id << 1], smt[id << 1 | 1]);
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i < n; ++i)
      cin >> a[i];
    for(int i = 1; i <= n; ++i)
      for(int j = 1; j <= m; ++j)
        cin >> b[i][j];
    long long ans = 0;
    for(int i = 1; i <= n; ++i){
      for(int j = 1; j <= m; ++j){
        stk[j].push(pii(0, i));
        int c = i;
        while(!stk[j].empty() && stk[j].top().first < b[i][j]){
          cv = b[i][j] - stk[j].top().first;
          cr = c;
          c = (cl = stk[j].top().second) - 1;
          upd(1, 1, n);
          stk[j].pop();
        }
        stk[j].push(pii(b[i][j], c + 1));
      }
      long long k = smt[1];
      if(ans < k) ans = k;
      cv = -a[i];
      cl = 1;
      cr = i;
      upd(1, 1, n);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4608
#if _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T> & arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }



void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }





using ll = long long;
using ull = unsigned long long;


#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;


void exec() 
{
	int n;
	cin >> n;

	int count = 0;
	bool ok = 0;

	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		if (a != b) {
			count = 0;
		}
		else {
			++count;
			if (count >= 3) ok = 1;
		}
	}

	if (ok) cout << "Yes";
	else cout << "No";
}

















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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--)
			exec();
	}

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 8e5 + 10;
int n, d, a;
int x[N], h[N];
ll ex[N];
typedef pair<int, int> pa;
vector<pa> pav;
int main() {
    vector<int> num;
    cin >> n >> d >> a;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> h[i];
        num.push_back(x[i]);
        num.push_back(x[i] + 2*d + 1);
        pav.push_back(pa(x[i], h[i]));
    }

    sort(num.begin(), num.end());
    num.erase(unique(num.begin(), num.end()), num.end());
    sort(pav.begin(), pav.end());
    // for(int i = 0; i < num.size(); i++) {
    //     cout << num[i] << '\n';
    // }

    int lst = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        int xx = pav[i].first;
        ll hh = pav[i].second;
        int px = lower_bound(num.begin(), num.end(), xx) - num.begin() + 1;
        int nxx = lower_bound(num.begin(), num.end(), xx + 2*d+1) - num.begin() + 1;
        for(int j = lst+1; j <= px; j++) ex[j] += ex[j-1];
        hh -= ex[px]*1LL*a;
        if(hh < 0) hh = 0;
        ll need = hh / a + (hh % a != 0);
        // printf("i:%d   hh:%d  need:%d [%d,%d] nxx:%d\n", i, hh, need, lst+1, px, nxx);
        ans += need;
        ex[px] += need;
        ex[nxx] -= need; 
        lst = px;
        // cout << i << endl;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    string s;
    cin >> s;

    int a=0,b=0,c=0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'a') {
            a++;
        }
        if (s[i] == 'b') {
            b++;
        }
        if (s[i] == 'c') {
            c++;
        }
    }

    if ( (a*b*c) ) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define MAX 500001
#define INFTY 2000000000

int count =0; 
void marge (int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int L[MAX/2+1],R[MAX/2+1];
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i=0; i<n1; i++) L[i]= A[left+i];
  for(i=0; i<n2; i++) R[i]= A[mid+i];

  /* printf("確認\n");
  for(i=0; i<n1; i++)printf("%d ",L[i]);
  printf("\n");
  for(i=0; i<n2; i++)printf("%d ",R[i]);
  printf("\n");
  printf("確認終了\n");
  */
    
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = j = 0;
  
  for(k=left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}

void margeSort(int A[],int left,int right){
  int mid;
  // printf("mragrSort\n");
  if (left+1 < right){
    mid = (left + right)/2;
    margeSort(A,left,mid);
    margeSort(A,mid,right);
    marge(A,left,mid,right);
  }
}

int main(){
  int i,j,n;
  int A[MAX];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  //  printf("マージソート開始\n");
  margeSort(A,0,n);
  
  for(i=0; i<n; i++){
    if(i>=1)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 5588
import java.util.Scanner; 
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double ans = 1;
		int N = scan.nextInt();
		double p = Math.pow(10,9);
		for(int i = 2; i <= N; i++) {
			ans = i * ans % (p + 7);	
		}
		scan.close();
		int rs = (int)ans;
		System.out.println(rs);
	}
}


Measured memory_bytes: 21588
N = int(input())
number = N
List = [0 for i in range(1000000)]
answer = 0

def cul(x):
    number = 1
    while x >= (number+2)*(number + 1)//2:
        number += 1
    return number

i = 2
while number > 1:
    while number % i == 0:
        number //= i
        List[i] += 1
    i +=1

    if i == 1000001:
        answer = 1
        break

for x in List:
    if x == 0:
        continue
    else:
        answer += cul(x)

print(answer)

Measured memory_bytes: 16656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  int c=0;
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<n-1;i++){
    if(a.at(i)>=a.at(i+1)){
      b.at(c)++;
    }
    else{
      c=i+1;
    } 
  }
  sort(b.begin(), b.end());
  cout << b.at(n-1) << endl;
}


Measured memory_bytes: 4848
S = input()
list_S = list(S)
str_len = int(len(list_S) / 2)
one = list(S[:str_len])
two = list(reversed(list(S[-str_len:])))  
hug = 0
for i in range(len(one)):
  if not one[i] == two[i]:
    hug = hug + 1
print(hug)


Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}


int main(){
    int N;
    cin >> N;
    string S[N];
    pair<string,int> A[N];
    map<string,int>mp;
    pair<string,int> B[N];
    REP(i,N) cin >> S[i],++mp[S[i]],B[i]=make_pair(S[i],mp[S[i]]);
    int num_max=0;
    int num_rel=0;
    for(int i=0;i<N;++i){
        num_max=max(num_max,mp[S[i]]);
    }   
    for(int i=0;i<N;++i){
        if(num_max==mp[S[i]]){
            ++num_rel;
        }
    }
    map<string,int> mp_2;
    vector<string>T;
    for(int i=0;i<N;++i){
        if(B[i].second==num_max){
            T.push_back(B[i].first);
        }
    }
    int L=T.size();
    sort(T.begin(),T.end());
    for(int i=0;i<L;++i){
        cout << T[i] << endl;
    }
    }


Measured memory_bytes: 34676
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

char G['Z'][2];

void init() {
    G['A'][0]='X';
    G['A'][1]='Y';
    G['X'][1]='Z';
    G['Z'][0]='W';
    G['Z'][1]='B';
    G['Y'][0]='X';
    G['W'][0]='B';
    G['W'][1]='Y';
    G['B'][0]='Y';
    G['B'][1]='X';

}
string s;
bool solve() {
    char v = 'A';
    rep(i,s.size()) {
        v = G[v][s[i]-'0'];
        if(v==0) return false;
    }
    if(v=='B') return true;
    return false;

}

int main() {
    init();
    while(cin>>s) {
        if(s=="#") break;
        printf("%s\n",solve()?"Yes":"No");

    }
    return 0;
}

Measured memory_bytes: 1168
/*
	Date:2020.5.10
	Name:Aliemo
*/
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define int long long
#define rr register

#define MAXN 1010
#define inf 1e18

using namespace std;

inline int read(int &T) {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) {f |= ch == '-'; ch = getchar();}
	while (isdigit(ch)) {s = s * 10 + (ch ^ 48); ch = getchar();}
	return T = f ? -s : s;
}

void print(int x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}

int n, m, x, minn = inf;

int c[20], t[20];

int a[20][20];

void dfs(int x, int ans, int opt) {
	// cout << ans << " ";
	if (x == n + 1) {
		bool f = 0;
		for (rr int i = 1; i <= m; i++) if (t[i] > 0) f = 1;
		if (!f)	{
			minn = min(minn, ans);
			// cout << ans << " ";
		}
		return ;
	}
	if (opt == 1) {
		for (rr int i = 1; i <= m; i++) t[i] -= a[x][i];
		// cout << ans << " ";
		dfs(x + 1, ans + c[x], 1);
		dfs(x + 1, ans + c[x], 0);
		// for (rr int i = 1; i <= m; i++) cout << t[i] << " ";
		// cout << "\n";
		for (rr int i = 1; i <= m; i++) t[i] += a[x][i];
	}
	else {
		dfs(x + 1, ans, 1);
		dfs(x + 1, ans, 0);
	}
}

signed main() {
	n = read(n);
	m = read(m);
	x = read(x);
	for (rr int i = 1; i <= m; i++) t[i] = x;
	for (rr int i = 1; i <= n; i++) {
		c[i] = read(c[i]);
		for (rr int j = 1; j <= m; j++) a[i][j] = read(a[i][j]);
	}
	dfs(1, 0, 1);
	dfs(1, 0, 0);
	if (minn != inf) print(minn), putchar('\n');
	else puts("-1");
}


Measured memory_bytes: 3584
#include<stdio.h>

int main(void)
{
  int i,i1,j,j1,h,w,S,S1,S2;

  while(1)
    {
      scanf("%d%d",&h,&w);
      if(h==0 && w==0) break;
      S=h*h+w*w;
      S2=150*150;
      for(i=1;i<=150;i++)
	{
	  for(j=150;j>=i+1;j--)
	    {
	      S1=i*i+j*j;
	      if(S<S1 && S2>S1 || S==S1 && h<i && S2>S1)
		{
		  S2=S1;
		  i1=i;
		  j1=j;
		}
	    }
	}
      printf("%d %d\n",i1,j1);
    }
  return 0;
}

Measured memory_bytes: 600
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    var aaa = chunk.toString();
    var line = aaa.split("\n")
    for(var i in line){
        line[i] = new Number(line[i])
    }
    
    line.sort(function(a,b){
        if( a > b ) return -1;
        if( a < b ) return 1;
        return 0;
    });
    //line.sort();
    for(var i = 0;i<3;i++){
        console.log(line[i].toString());
    }
    //console.log(line)
});

Measured memory_bytes: 15932
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100000;

int n, k;
ll s[MAXN]; int d[MAXN];

void run() {
	scanf("%d%d", &n, &k); REP(i, n) scanf("%lld%d", &s[i], &d[i]);
	ll l = 0, h = s[0] + (ll)(k - 1)*d[0];
	while (l + 1 < h) {
		ll m = l + (h - l) / 2;
		ll cnt = 0;
		REP(i, n) {
			if (s[i] > m) continue;
			ll len = m - s[i];
			ll now = 1 + len / d[i];
			cnt += now; if (cnt >= k) break;
		}
		//printf("%lld: %lld\n", m, cnt);
		if (cnt >= k) h = m; else l = m;
	}
	printf("%lld\n", h);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int n,m;
string s[105];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>s[i];
	for (int i=1;i<=m+2;++i) cout<<"#";
	cout<<endl;
	for (int i=1;i<=n;++i) cout<<"#"<<s[i]<<"#"<<endl;
	for (int i=1;i<=m+2;++i) cout<<"#";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	vector<LL> A(N);
	rep(i,N) cin >> A[i];
	map<LL,LL> s, d;
	rep(i,N) s[(i+1)+A[i]]++;
	rep(i,N) d[(i+1)-A[i]]++;
	LL ans=0;
	for(auto itr:s){
		ans+=itr.second*d[itr.first];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 38944
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    ll N;
    cin >> N;
    
    ll ans=N;
    
    for(ll i=1; i*i<=N; i++){
        if(N%i==0){
            ans = min(ans, (i-1)+(N/i -1) );
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define int long long

const int N = (int)55, MOD = (int)1e9 + 7, INF = (int)3e18;

int c[N], a[N][N];
int b[N];

main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    for (int i = 1; i <= n; ++i) {
        cin >> c[i];
        for (int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    int ans = INF;
    for (int mask = 0; mask < (1 << n); ++mask) {
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if ((mask >> i) & 1) {
                cnt += c[i + 1]; 
                for (int j = 1; j <= m; ++j) b[j] += a[i + 1][j];
            }
        }
        bool ok = 1;
        for (int i = 1; i <= m; ++i) ok &= (b[i] >= x);
        if (ok) ans = min(ans, cnt);
        for (int i = 1; i <= m; ++i) b[i] = 0;
    }if (ans == INF) ans = -1;
    cout << ans;
    return 0;
}

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

const int MAX = 6000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int x, y; cin >> x >> y;
    COMinit();

    long long cnt = 0;
    int a_max = max(x/2, y);
    for (int i = 0; i <= a_max; i++)
    {
        if((y - i)% 2 == 1) continue;
        int b1 = x - 2 * i;
        int b2 = (y - i) / 2;
        if(b1==b2) cnt += COM(b1 + i, i);
        cnt %= MOD;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 140928
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
ab = sorted(AB, key=lambda x: x[1])

t = 0
ans = 'Yes'
for a_b in ab:
    t += a_b[0]
    if t > a_b[1]:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 55176
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

struct Data{

	bool operator<(const struct Data &arg) const{

		return line < arg.line;
	}
	int index;
	string line;
};

struct Node{
	int children[26];
	bool finish_FLG;
};


int N;
int length[SIZE];
int L[SIZE],R[SIZE];
int num_node;
map<int,int> MAP,rev_MAP,TAIL;
set<int> SET;
Data data[SIZE];
Node nodes[1000005];

int main(){

	scanf("%d",&N);

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

		cin >> data[i].line;
		data[i].index = i;
		length[i] = data[i].line.length();
	}

	sort(data,data+N);

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

		MAP[data[i].index] = i; //文字列がdataのどこにあるか
		rev_MAP[i] = data[i].index; //dataのi番目の文字列は何か

		L[i] = BIG_NUM; //自分を含む最小のindex
		R[i] = -BIG_NUM; //自分を含む細大のindex
	}

	num_node = 0;

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

		for(int k = 0; k < 26; k++){

			nodes[i].children[k] = -1;
		}
		nodes[i].finish_FLG = false;
	}

	int root = 0;

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

		int tmp_index = 0; //文字列のインデックス
		int tmp_ch = data[i].line[tmp_index]-'a';

		int tmp_loc = root; //トライ木上の位置
		tmp_index = 0;

		while(true){

			if(nodes[tmp_loc].finish_FLG){ //終端する文字列あり

				int k = TAIL[tmp_loc];
				R[k] = i;
			}

			if(nodes[tmp_loc].children[tmp_ch] == -1){

				nodes[tmp_loc].children[tmp_ch] = ++num_node;
			}
			//子ノードに移動
			tmp_loc = nodes[tmp_loc].children[tmp_ch];
			tmp_index++;

			if(tmp_index == length[rev_MAP[i]]){ //今回の数字が最後の文字だった場合
				nodes[tmp_loc].finish_FLG = true;
				TAIL[tmp_loc] = rev_MAP[i];
				L[rev_MAP[i]] = i;
				R[rev_MAP[i]] = i;
				break;
			}
			tmp_ch = data[i].line[tmp_index]-'a';
		}
	}

	int num_query;
	scanf("%d",&num_query);

	int command,num;

	set<int>::iterator it;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d",&command,&num);
		num--;

		switch(command){
		case 1:

			SET.insert(MAP[num]);
			break;

		case 2:

			SET.erase(MAP[num]);
			break;

		case 3:

			if(L[num] == BIG_NUM){ //元々自分を含む文字列なし

				printf("-1\n");
				break;
			}

			it = SET.lower_bound(L[num]);

			if (it == SET.end() || *it > R[num]){

				printf("-1\n");

			}else{

				printf("%d\n", rev_MAP[*it]+1);
			}
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 133356
N,M=map(int, input().split())
TO = set([])
FM = set([])
for i in range(M):
    f,t = map(int, input().split())
    if f == 1:
        TO.add(t)
    elif t == N:
        FM.add(f)
if len(TO & FM)>0:
    ans = 'POSSIBLE'
else:
    ans = 'IMPOSSIBLE'
print(ans)

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

int sum(int n){
	int counter  = 0;
	while(n > 0){
		counter += n % 10;
		n /= 10;
	}
	return counter;
}

int main(){
	int n;
	cin >> n;
	int check = sum(n);
	if(n % check == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  vector<int> original(5,0);
  vector<int> digit(5,0);
  original[0] = a;
  original[1] = b;
  original[2] = c;
  original[3] = d;
  original[4] = e;
  digit[0] = a%10;
  digit[1] = b%10;
  digit[2] = c%10;
  digit[3] = d%10;
  digit[4] = e%10;
  for(int i=0;i<5;i++){
    if(digit[i] == 0){
      digit[i] = 9;
    }
  }
  int minElementIndex = min_element(digit.begin(),digit.end()) - digit.begin();
  int ret = 0;
  for(int i = 0; i < 5; i++){
    if(i != minElementIndex){
      ret = ret + (original[i] + ((10 - original[i] % 10 == 10) ? 0 : 10 - original[i] % 10));
    }
  }
  ret = ret + original[minElementIndex];
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main(){
  int n;
  cin>>n;
  
  int az=0;
  int bz=0;
  int abz=0;

  vector<ll> a(n);
  vector<ll> b(n);
  map<pair<ll,ll>,int> p;
  rep(i,n){
  cin>>a[i]>>b[i];
    if(a[i]==0 && b[i]!=0) az++;
    if(b[i]==0 && a[i]!=0) bz++;
    if(a[i]==0 && b[i]==0) abz++;
    if(a[i]!=0 && b[i]!=0) {
      ll c=gcd(abs(a[i]),abs(b[i]));
      if(a[i]<0) c=-c;
      auto x=mp(a[i]/c,b[i]/c);
      if(p.count(x)) p.at(x)++;
      else p[x]=1;
    }
  }

  ll ans=1;

for(auto x : p) {
  auto y=mp(x.fi.se,-x.fi.fi);
  if(x.fi.se<0) {
    y.fi*=-1;
    y.se*=-1;
  }
  if(p.count(y)) {  
    ll memo=jou(2,x.se)+jou(2,p.at(y))-1;
    memo%=mod;
    ans*=memo;
    ans%=mod;
    p.erase(y);
  }
  else {
    ans*=jou(2,x.se);
    ans%=mod;
  }
}

  ans*=jou(2,az)+jou(2,bz)-1;
  ans%=mod;

  ans+=abz;

  cout << (ans+mod-1)%mod << endl;   //0匹
}

Measured memory_bytes: 18768
#include <vector>
#include <queue>
#include <map>
#include <cstdio>
using namespace std;
#define X 4
#define Y 2
main(){
	int i=0,t;
	map<vector<int>,pair<int,int> >m;
	queue<vector<int> >q;
	vector<int>v;
	for(;i<X*Y;i++)v.push_back(i);
	m[v]=make_pair(0,0);
	for(q.push(v);!q.empty();){
		v=q.front();q.pop();
		int coor=m[v].first,x=coor%X,y=coor/X;
		int depth=m[v].second;
		if(0<x){
			swap(v[coor],v[coor-1]);
			if(m.find(v)==m.end())m[v]=make_pair(coor-1,depth+1),q.push(v);
			swap(v[coor],v[coor-1]);
		}
		if(x<X-1){
			swap(v[coor],v[coor+1]);
			if(m.find(v)==m.end())m[v]=make_pair(coor+1,depth+1),q.push(v);
			swap(v[coor],v[coor+1]);
		}
		if(0<y){
			swap(v[coor],v[coor-X]);
			if(m.find(v)==m.end())m[v]=make_pair(coor-X,depth+1),q.push(v);
			swap(v[coor],v[coor-X]);
		}
		if(y<Y-1){
			swap(v[coor],v[coor+X]);
			if(m.find(v)==m.end())m[v]=make_pair(coor+X,depth+1),q.push(v);
			swap(v[coor],v[coor+X]);
		}
	}
	v.clear();
	for(i=0;~scanf("%d",&t);){
		v.push_back(t);
		if(++i==X*Y){
			printf("%d\n",m[v].second);
			v.clear();i=0;
		}
	}
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int mod = 998244353;
int suff[200002];
long long dp[200002];
int x[200002], d[200002];
pii p[200002];
int st[1000002];
void update(int n, int s, int e, int idx, int v){
    if(s == e) st[n] = v;
    else{
        int mid = (s+e)/2;
        if(idx <= mid) update(n+n, s, mid, idx, v);
        else update(n+n+1, mid+1, e, idx, v);
        st[n] = max(st[n+n], st[n+n+1]);
    }
}
int query(int n, int s, int e, int l, int r){
    if(s > r || l > e) return 0;
    if(l <= s && e <= r) return st[n];
    int mid = (s+e)/2;
    int q1 = query(n+n, s, mid, l, r);
    int q2 = query(n+n+1, mid+1, e, l, r);
    return max(q1, q2);
}
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &x[i], &d[i]);
        p[i] = pii(x[i], d[i]);
    }   
    sort(p+1, p+1+n);
    for(int i=1;i<=n;i++) x[i] = p[i].first, d[i] = p[i].second;
    dp[n+1] = 1;
    for(int i=n;i>=1;i--){
        int lo = i, hi = n;
        while(lo <= hi){
            int mid = (lo+hi)/2;
            if(abs(x[i]-x[mid]) < d[i]) suff[i] = mid, lo = mid+1;
            else hi = mid-1;
        }
        suff[i] = max(suff[i], query(1, 1, n, i, suff[i]));
        update(1, 1, n, i, suff[i]);

        dp[i]++;
        dp[i] = (dp[i]*1ll*dp[suff[i]+1])%mod;
        dp[i] = (dp[i] + dp[i+1])%mod;
    }
    printf("%d\n", dp[1]);
}

Measured memory_bytes: 9600
import sys

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())

def main():
    K = i2n()
    
    if K%2==0:
        print(-1)
        return
    
    if K % 7:
        L = 9*K
    else:
        L = 9*K//7
    a = 1
    for i in range(1,L+1):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print(-1)
main()

Measured memory_bytes: 9180
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
int main()
{
    lli n, m;
    cin >> n >> m;
    lli ans = 0;
    if (m / 2 >= n) {
        lli b = n;
        lli a = (m - 2 * b) / 4;
        ans = max(a + b, ans);
        b = n - 1;
        a = (m - 2 * b) / 4;
        ans = max(a + b, ans);
    } else {
        lli b = m / 2;
        lli a = 0;
        ans = max(a + b, ans);
        a = 1;
        b = (m - 4 * a) / 2;
        ans = max(a + b, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

----------------------------------------------------------------------

solve :: Int -> Int -> [Int] -> Int
solve n k xs = minimum $ zipWith f xs (drop (k-1) xs)
  where
    f p q | q <= 0 = -p
          | p >= 0 = q
          | q <= (-p) = 2 * q + (-p)
          | (-p) <= q = 2 * (-p) + q


tmain :: B.ByteString -> Int
tmain cont =
  let n : k : xs = bsReadInts cont
  in solve n k xs

main = putStrLn . show . tmain =<< B.getContents


Measured memory_bytes: 13564
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N, K;
ll A[505];

bool check(ll num) {
	vector<ll> mod;

	rep(i, N) {
		mod.push_back(A[i]%num);
	}

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

	ll cost = 0;
	ll start = 0;
	ll end = N - 1;
	ll pn = 0;

	//cout << " num = " << num << endl;

	//rep(i, N) {
	//	cout << "mod[" << i << "] = " << mod[i] << endl;
	//}
	
	while(start <= end) {
		//cout << "start = " << start << " end = " << end << " pn = " << pn << " cost " << cost << endl;
		if(pn < 0) {
			pn += mod[start];
			cost += mod[start];
			start++;
		} else {
			if(mod[end] != 0) {
				pn -= (num - mod[end]);
				cost += (num - mod[end]);
			}
			end--;
		}
	}
	//cout << "start = " << start << " end = " << end << " pn = " << pn << " cost " << cost << endl;

	return cost/2 <= K;
}

int main(){

	cin >> N >> K;
	rep(i, N)  cin >> A[i];


	ll sum = 0;
	rep(i, N) sum += A[i];

	vector<ll> divi;
	for(ll i = 1; i * i <= sum; i++) {
		if(sum % i == 0) {
			divi.push_back(i);
			if(i != sum/i) {
				divi.push_back(sum/i);
			}
		}
	}

	ll ans = 1;

	for(ll num: divi) {
		if(check(num)) {
			ans = max(ans, num);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int h, w;
    string s[1001];

    cin >> h >> w;

    REP(i, h)
    cin >> s[i];

    int res = 0;

    //TODO:
    int t[1001][1001];

    memset(t, 0, sizeof(t));

    queue<P> q;

    REP(i, h)
    {
        REP(j, w)
        {
            if (s[i][j] == '#')
            {
                q.push({i, j});
                t[i][j] = 0;
            }
        }
    }

    while (q.size())
    {
        P p = q.front();
        q.pop();

        int i = p.first;
        int j = p.second;

        if (s[i][j] != '#')
            continue;

        s[i][j] = '*';

        REP(k, 4)
        {
            int ni = i + di[k];
            int nj = j + dj[k];

            if (0 <= ni && ni < h && 0 <= nj && nj < w && s[ni][nj] == '.')
            {
                s[ni][nj] = '#';
                q.push({ni, nj});
                t[ni][nj] = t[i][j] + 1;
            }
        }
    }

    res = 0;
    REP(i, h)
    REP(j, w)
    res = max(res, t[i][j]);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define ld double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define DOW(i, n) for(int i = n - 1; 0 <= i; --i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);


using namespace std;

int a, b, c;
int d[100005];

int main() {
	cin >> a >> b >> c;
	for (int i = 1; i <= b; ++i) d[i] = c;
	int f = (c == 1000000000 ? 1 : c + 1);
	for (int i = b + 1; i <= a; ++i) d[i] = f;
	for (int i = 1; i <= a; ++i) cout << d[i] << " ";
	
	
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

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

	vector<int32_t> A(N + 2, 0);
	for (int32_t i = 1; i < N + 1; i++) {
		cin >> A[i];
	}

	vector<int32_t> dist(N + 2, 0);
	int32_t total = 0;
	for (int32_t i = 0; i < N + 1; i++) {
		dist[i] = abs(A[i + 1] - A[i]);
		total += dist[i];
	}

	vector<int32_t> dist_next(N + 2, 0);
	for (int32_t i = 0; i < N; i++) {
		dist_next[i] = abs(A[i + 2] - A[i]);
	}

	for (int32_t i = 1; i < N + 1; i++) {
		cout << total - dist[i] - dist[i - 1] + dist_next[i - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 2432
// AtCoder :: Beginner Contest 175 :: B - Making Triangle 
// https://atcoder.jp/contests/abc175/tasks/abc175_b

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll solve(vector<ll> &sides) {
    ll soln{0};
    for (int i{0}; i < sides.size(); i++) {
        for (int j{i+1}; j < sides.size(); j++) {
            for (int k{j+1}; k < sides.size(); k++) {
                ll a{sides[i]};
                ll b{sides[j]};
                ll c{sides[k]};
                if (a == b || b == c || a == c) {
                    continue;
                }
                if (((a + b) > c) && ((b + c) > a) && ((c + a) > b)) {
                    soln += 1;
                }
            }
        }
    }
    return soln;
}

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

    int N;
    cin >> N;
    vector<ll> sides;
    sides.reserve(N);
    copy_n(istream_iterator<ll>(cin), N, back_inserter(sides));
    cout << solve(sides) << "\n";
    return EXIT_SUCCESS;
}


Measured memory_bytes: 3656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class BRGBBoxes {
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            long r = sc.nextLong();
            long g = sc.nextLong();
            long b = sc.nextLong();

            long n = sc.nextLong();

            long ans = 0;

            for (long i = 0; i <= n / r; ++i) {
                for (long j = 0; j <= (n - i * r) / g; ++j) {
                    long rem = n - i * r - j * g;
                    if (rem % b == 0)
                        ans++;
                }
            }

            out.print(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , ans , t , cntL[MAXN] , cntR[MAXN];
string s;

ll get(string s){
    ll ans = 0;
    for(ll i = 0 ; i + 1 < s.size() ; i++){
        if(s.substr(i , 2) == "AB") ans++;
    }
    return ans;
}

int main() {
    fast_io;

    cin >> n;
    for(ll i = 0 ; i < n ; i++){
        cin >> s;
        ans += get(s);
        cntL[s[0] - 'A']++;
        cntR[s[s.size() - 1] - 'A']++;
        if(s[0] == 'B' && s[s.size() - 1] == 'A')  t++;
    }

    if(cntL[1] == t && cntR[0] == t)    cntR[0] = max(0LL , cntR[0] - 1);
    ans += min({n - 1 , cntR[0] , cntL[1]});
    cout << ans << endl;

    return 0;
}
/*
todo :
    1- set constants
    2- check TimeLimit and MemoryLimit
    3- check special test cases
    4- don't forget BS can help you that is good idea(use for loop for floats)
    5- don't forget printf and scanf can help you in your code speed
*/


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

using namespace std;

const int N = 1e6 + 6, mod = 1e9 + 7;
long long dp[N];

int main() {
  int n, h, d;
  long long sum = 0, fac = 1;
  scanf("%d %d %d", &n, &h, &d);
  for (int i = 1; i <= n; ++i) {
    fac = fac * i % mod;
    sum = (sum + fac) % mod;
  }
  dp[0] = fac;
  long long cur = fac;
  for (int i = 1; i < h; ++i) {
    dp[i] = sum * cur % mod;
    cur = (cur + dp[i]) % mod;
    if (i >= d)
      cur = (cur + mod - dp[i-d]) % mod;
  }
  cur %= mod;
  if (cur < 0)
    cur += mod;
  printf("%lld\n", cur);
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    cout<<"ABC"<<n<<endl;
    
    
 
return 0;
}


Measured memory_bytes: 256