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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    s << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    s << ']';
	return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int w, h, x, y;
	cin >> w >> h >> x >> y;

	cout << (double)w*h/2.0 << sp << (x*2==w and y*2==h) << endl;

    return 0;
}


Measured memory_bytes: 256
n,y = gets.split.map(&:to_i)
(n + 1).times do |i|
  (n + 1).times do |j|
    tmp = y - (10000 * i + 5000 * j)
    if  tmp >= 0 && n - (i + j) >= 0
      if tmp == 1000 * (n - (i + j))
      	puts "#{i} #{j} #{ n - i - j}"
        exit
      end
    end
  end
end
puts "-1 -1 -1"

Measured memory_bytes: 14268
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

const mod = 1000000007

func mpow(a, b int) int {
	if b == 0 {
		return 1
	} else if b%2 == 0 {
		tmp := mpow(a, b/2)
		return tmp * tmp % mod
	}
	return mpow(a, b-1) * a % mod
}

var fracMemo = []int{1, 1}

func mfrac(n int) int {
	if len(fracMemo) > n {
		return fracMemo[n]
	}
	if len(fracMemo) == 0 {
		fracMemo = append(fracMemo, 1)
	}
	for len(fracMemo) <= n {
		size := len(fracMemo)
		fracMemo = append(fracMemo, fracMemo[size-1]*size%mod)
	}
	return fracMemo[n]
}

var ifracMemo = []int{1, 1}

func mifrac(n int) int {
	if len(ifracMemo) > n {
		return ifracMemo[n]
	}
	if len(ifracMemo) == 0 {
		fracMemo = append(ifracMemo, 1)
	}
	for len(ifracMemo) <= n {
		size := len(ifracMemo)
		ifracMemo = append(ifracMemo, ifracMemo[size-1]*mpow(size, mod-2)%mod)
	}
	return ifracMemo[n]
}

func nCr(n, r int) int {
	if n == r {
		return 1
	}
	if n < r || r < 0 {
		return 0
	}
	ret := 1
	ret *= mfrac(n)
	ret %= mod
	ret *= mifrac(r)
	ret %= mod
	ret *= mifrac(n - r)
	ret %= mod
	return (ret)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, K := getInt(), getInt()

	J := N - K
	for i := 0; i < K; i++ {
		n := K - 1
		r := i
		// out("A", n, r)
		a := nCr(n, r)
		n = J + 1
		r = J - i
		// out("B", n, r)
		b := nCr(n, r)
		c := (a * b) % mod
		out(c)
	}

}


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

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

    vector<long>a(n+1);
    rep(i,0,n+1){
        cin>>a[i];
    }

    vector<long>b(n);
    rep(i,0,n){
        cin>>b[i];
    }

    long sum=0;

    rep(i,0,n){
        long x=min(a[i],b[i]);
        sum+=x;
        a[i]-=x;
        b[i]-=x;
        x=min(a[i+1],b[i]);
        sum+=x;
        a[i+1]-=x;
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 1792
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <climits>
using namespace std;

// 双対セグメント木 (Dual Segment Tree)
// ref: https://kimiyuki.net/blog/2019/02/22/dual-segment-tree/
template <typename MonoidType, typename OperatorType, class SegFunc>
struct DualSegmentTree {
    int n;
    vector<MonoidType> bottom;
    vector<OperatorType> lazy;
    OperatorType E;

    inline void build(const vector<MonoidType> &v) {
        int m = v.size();
        n = 1; while(n < m) n *= 2;
        bottom = v; bottom.resize(n);
        lazy.resize(n - 1, E);
    }

    DualSegmentTree() {}
    DualSegmentTree(OperatorType E_, vector<MonoidType> v) : E(E_) {
        build(v);
    }

    void update(int a, int b, OperatorType x, int l, int r, int k) {
        if(b <= l or r <= a) return;
        if(a <= l and r <= b) {
            if(k < lazy.size())
                lazy[k] = SegFunc::lazy_update(lazy[k], x);
            else
                bottom[k-n+1] = SegFunc::update(bottom[k-n+1], x);
        }
        else {
            int mid = (l + r) >> 1;
            update(0, n, lazy[k], l, mid, 2*k+1);
            update(0, n, lazy[k], mid, r, 2*k+2);
            lazy[k] = E;
            update(a, b, x, l, mid, 2*k+1);
            update(a, b, x, mid, r, 2*k+2);
        }
    }

    void update(int a, int b, OperatorType x) {
        update(a, b, x, 0, n, 0);
    }

    MonoidType query(int k) {
        MonoidType res = bottom[k];
        for(k = (k+n)>>1; k>0; k>>=1) { // 1-indexed
            res = SegFunc::update(res, lazy[k-1]);
        }
        return res;
    }
};


void DSL_2_D() {
    using Pair = pair<int, int>;
    struct SegFunc {
        static Pair lazy_update(Pair a, Pair b) { return b.second ? b : a; }
        static int update(int x, Pair p) {
            if(p.second == 0) return x;
            return p.first;
        }
    };

    int N, Q; cin >> N >> Q;
    DualSegmentTree<int, Pair, SegFunc> seg(make_pair(0, 0), vector<int>(N, INT_MAX));

    int indexed = 0;
    for(int i=0; i<Q; i++) {
        int q; cin >> q;
        if(q == 0) {
            int s, t, x; cin >> s >> t >> x;
            s -= indexed, t -= indexed, t++;
            seg.update(s, t, make_pair(x, 1));
        }
        if(q == 1) {
            int x; cin >> x; x -= indexed;
            cout << seg.query(x) << endl;
        }
    }
}

int main() {
    DSL_2_D();
    // DSL_2_E();
}



Measured memory_bytes: 4724
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long long n,a[200005],s[200005];
long long sum(0),ans=2e14;
int main(){
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		if(!i) s[i]=a[i];
		else s[i]=s[i-1]+a[i];
		sum+=a[i];
	}
	for(int i=0;i<n-1;++i){
		ans=min(abs(s[i]-(sum-s[i])),(long long)ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
b=[int(input()) for i in range(n)]

aa = []
aa.append(a1)
aa.append(a2)
aa.append(a3)

a = aa[:]
for _ in range(n):
  for i in range(3):
    for j in range(3):
      if aa[i][j] == b[_]:
        a[i][j] = 0

if a[0][0] == a[0][1] and a[0][1] == a[0][2] :
  print("Yes")
elif a[1][0] == a[1][1] and a[1][1] == a[1][2] :
  print("Yes")
elif a[2][0] == a[2][1] and a[2][1] == a[2][2] :
  print("Yes")
elif a[0][0] == a[1][0] and a[1][0] == a[2][0]:
  print("Yes")
elif a[0][1] == a[1][1] and a[1][1] == a[2][1]:
  print("Yes")
elif a[0][2] == a[1][2] and a[1][2] == a[2][2]:
  print("Yes")
elif a[0][0] == a[1][1] and a[1][1] == a[2][2]:
  print("Yes")
elif a[0][2] == a[1][1] and a[1][1] == a[2][0]:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3188
n = STDIN.gets
t, a = STDIN.gets.chomp.split().map { |x|
  x.to_i
}
hArray = STDIN.gets.chomp.split().map { |x|
  t - x.to_i * 0.006
}

min = 100000
resultIndex = 0

hArray.each_with_index { |x, idx|
  if (a - x).abs < min then
    min = (a - x).abs
    resultIndex = idx
  end
}

p resultIndex + 1


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

ll f(int y,int x){
  return 7*y+x-7;
}

ll solve(ll n,ll k){
  if(n<=200){
    ll res=0;
    
    for(int i=1;i<=n-2;i++){
      for(int j=1;j<=5;j++){

        int sum=0;
        for(int di=0;di<=2;di++)
          for(int dj=0;dj<=2;dj++)
            sum+=f(i+di,j+dj);

        if(sum%11==k)res++;
      }
    }

    return res;
  }
    
}

ll ans[200];
int main(){
  ll n,k;
  cin>>n>>k;
if(n<100){ cout<<solve(n,k)<<endl; return 0; }
  for(ll i=0;i<200;i++){
    ans[i]=solve(i,k);
  }

  for(ll i=80;;i++){
    if(i%11 == n%11){
      ll dist=n-i;
      cout<< ans[i]+dist/11LL*5LL<<endl;
      break;
    }
  }
  return 0;
}


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

using namespace std;

#define int long long

const int N = 2005, inf = 1e18;
int n, K, q, a[N], ans = inf;
bool unUse[N];

int solve (int pos) {
    int ret = 0, cnt = 0;
    priority_queue<int, vector<int>, greater<int> > pq, choo;

    unUse[n + 1] = 1;
    for (int i = 1; i <= n + 1; ++i) {
        if (unUse[i]) {
            while (pq.size() >= K) choo.push(pq.top() ), pq.pop();
            while (!pq.empty() ) pq.pop();
        }
        else pq.push(a[i]);
    }

    if (choo.size() < q) return 2 * inf;

    while (cnt < q) ret = max(ret, choo.top() ), choo.pop(), cnt ++;

    cnt = 1;
    for (int i = pos + 1; i <= n; ++i) {
        if (unUse[i]) break;
        cnt ++;
    }
    for (int i = pos - 1; i > 0; --i) {
        if (unUse[i]) break;
        cnt ++;
    }
    if (cnt < K) return inf;
    return ret;
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> K >> q;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    for (int i = 1; i <= n; ++i) {
        memset(unUse, 0, sizeof unUse);
        for (int j = 1; j <= n; ++j) if (a[j] < a[i]) unUse[j] = 1;
        ans = min(ans, solve(i) - a[i]);
    }

    cout << ans;

    return 0;
}


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

#define f(i,x,y)			for(int i=x; i<y; i++)
#define ll 					long long 
#define mp 					make_pair
#define F 					first
#define S 					second
#define N 					100005


int main()
{
	int n,w;
	cin>>n>>w;
	int wt[n+1], p[n+1];
	f(i,1,n+1)
		cin>>wt[i]>>p[i];

	ll dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	
	f(i,1,n+1)
	{
		f(j,0,w+1)
		{
			if(j>=wt[i])
			{
				dp[i][j] = max(dp[i-1][j-wt[i]]+p[i] , dp[i-1][j]);
			}
			else
				dp[i][j] = dp[i-1][j];
		}
	}
		
	
cout<<dp[n][w];
	

	return 0;
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    ll i,j,k,n;
    string s;

    cin>>n>>s;

    k=1;
    repj(i,1,n){
        if(s[i]!=s[i-1]){
            k++;
        }
    }
    cout<<k;
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
struct node{int w,id;}a[N];
bool cmp(node a,node b){
	return (a.w==b.w)?a.id<b.id:a.w<b.w;
}
int n,k,q,b[N],c[N],d[N],ans,vis[N];
int main(){
	ans=1e9+5;
	scanf("%d%d%d",&n,&k,&q);
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i].w);
		b[i]=a[i].w;
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;++i){
		int l=1,r=0,cnt=0;
		while (r<=n){
			while (vis[l]) ++l;
			r=l;
			while (!vis[r]&&r<=n) ++r;
			int tot=0;
			for (int j=l;j<r;++j)
				c[++tot]=b[j];
			sort(c+1,c+tot+1);
			for (int j=1;j<=tot-k+1;++j)
				d[++cnt]=c[j];
			l=r;
		}
		if (cnt<q) break;
		sort(d+1,d+cnt+1);
		ans=min(ans,d[q]-a[i].w);	
		vis[a[i].id]=1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3884
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    x = S()
    s = 0
    ans = len(x)
    for i in x:
        if i == "S":
            s += 1
        else:
            if s > 0:
                s -= 1
                ans -= 2
    print(ans)
    return

#B
def B():
    n = I()
    a = LI()
    f = [0 for i in range(n+1)]
    for i in range(n):
        f[a[i]] = i
    l = [i for i in range(n+1)]
    r = [i for i in range(n+1)]
    ans = 0
    for i in range(1,n+1)[::-1]:
        j = f[i]
        ans += (j-l[j]+1)*(r[j]-j+1)*i
        l[r[j]+1] = l[j]
        r[l[j]-1] = r[j]
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 84196
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int list[2000000];
int head=999999,tail=999999;

void Insert(int x){
  head--;
  list[head]=x;
}

void Delete(int x){
  for(int i=head;i<tail;++i)
    if(list[i]==x){
      for(int j=i;j<tail-1;++j)
	list[j]=list[j+1];
      tail--;
      break;
    }
}

void DeleteFirst(){
  head++;
}

void DeleteLast(){
  tail--;
}

int main(){
  int n;
  scanf("%d",&n);
  
  char c[12];
  int num;
  for(int i=0;i<n;++i){
    scanf("%s",c);
    if(!strcmp(c,"insert")){
      scanf("%d",&num);
      Insert(num);
    }
    else if(!strcmp(c,"delete")){
      scanf("%d",&num);
      Delete(num);
    }
    else if(!strcmp(c,"deleteFirst"))
      DeleteFirst();
    else if(!strcmp(c,"deleteLast"))
      DeleteLast(); 
  }
  
  for(int i=head;i<tail;i++){
    if(head<i)putchar(' ');
    printf("%d",list[i]);
  }
  putchar('\n');
}

Measured memory_bytes: 5288
#include<bits/stdc++.h>
using namespace std;
string a;
int main(){
	cin>>a;
	for(int i=0;i<a.size();i++){
		if(a[i]==a[i+1]){
			cout<<"Bad";
			return 0;
		}
	}
	cout<<"Good";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m=0,a[110],b[110],c[30];
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
		cin>>a[i];
	m+=a[1];	
	for(int i=2;i<=n;i++)
	{
		if(i==n)
			m+=a[i-1];
		else	
			m+=min(a[i-1],a[i]);	
	}
	cout<<m<<endl;
} 

Measured memory_bytes: 256
import itertools

n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(q)]

ls = itertools.combinations_with_replacement([i + 1 for i in range(m)], n)

ans = 0
for A in ls:
    total = 0
    for a, b, c, d in abcd:
        if A[b - 1] - A[a - 1] == c:
            total += d
    ans = max(ans, total)
print(ans)


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

public class Main {

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

      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      for(int i=0; i!=n; i++)
        seq[i] = Integer.parseInt(br.readLine());

      System.out.println( shellSort(seq, n) );

      StringBuilder str = new StringBuilder(n*5);
      for (int i : seq)
        str.append(i).append("\n");
      str.setLength(str.length()-1);
      System.out.println(str);
    }
  }

  public static int shellSort(int a[], int n) {
    int cnt=0;
    int m = 0;
    int[] aG = new int[100];
    for (int g=1,max=n+1; g < max; g=(g*3+1)) {
      aG[m++] = g;
    }
    StringBuilder str = new StringBuilder(m*5);
    str.append(m).append("\n");

    for(int i=(m-1); i!=-1; i--){
      cnt += insertionSort(a, n,aG[i]);
      str.append(aG[i]).append(" ");
    }

    str.setLength(str.length()-1);
    System.out.println(str);

    return cnt;
  }
  
  public static int insertionSort(int a[], int max, int g) {
    int cnt=0;

    for (int i=g,j=0,v=0; i < max; i++) {
      for( j=(i-g), v=a[i]; j>=0 && a[j]>v; j-=g ) {
        a[j+g] = a[j];
        cnt++;
      }
      a[j+g] = v;
    }

    return cnt;
  }
}


Measured memory_bytes: 87676
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};

#define lim 3005

ll dp[lim][lim][4],r,c,k,v[200005],MAP[lim][lim];

ll F(ll x,ll y,ll now){
    if(x>r or y>c) return 0;
    ll &ret = dp[x][y][now];
    if( ~ret  ) return ret;
    ret = 0;
    ll val=MAP[x][y];
    if(val and now<3){
        ret = val + F(x,y+1,now+1);
        ret = max(ret,val+F(x+1,y,0));
    }
    ret = max(ret,F(x,y+1,now));
    ret = max(ret,F(x+1,y,0));
    return dp[x][y][now] = ret;
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll x,y,z;
    sfl(r),sfl(c),sfl(k);
    FOR(i,k){
        sfl(x),sfl(y),sfl(z);
        MAP[x][y]=z;
    }
    memset(dp,-1,sizeof dp);
    ll ans = F(1,1,0);
    pfl(ans);
    return 0;
}

Measured memory_bytes: 356732
package main

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

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

func next() string {
	return reader.next()
}

func nextInt() int {
	i, err := strconv.Atoi(reader.next())
	if err != nil {
		panic(err)
	}
	return i
}

func nextLine() string {
	return reader.nextLine()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func main() {
	_, A, B := nextInt(), nextInt(), nextInt()
	S := next()
	passed, rankB := 0, 0
	for _, r := range S {
		ans := "No"
		switch r {
		case 'a':
			if passed < A+B {
				ans = "Yes"
				passed++
			}
		case 'b':
			rankB++
			if passed < A+B && rankB <= B {
				ans = "Yes"
				passed++
			}
		}
		fmt.Println(ans)
	}
}


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

void solve(){
    int n;cin>>n;
    int a[n];
    int ans=10000000,buf;
    fol(i,n){
        cin>>a[i];
    }
    for(int i=-100;i<=100;i++){
        buf = 0;
        fol(j,n){
            buf+=(a[j]-i)*(a[j]-i);
        }
        ans = min(ans,buf);
    }
    cout << ans <<endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(x,y) '(' << x << ',' << y << ')'
ll MOD = 1000000007;
ll INF = 214748364700000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll tableF[200010];
ll tableI[200010];

ll modfact(ll a,ll m){
   if(tableF[a] != -1){
      return tableF[a];
   }
   if(a == 1){
      tableF[a] = 1;
      return tableF[a];
   }
   ll res = 1;
   res = a * modfact(a-1,m);
   res %= m;
   tableF[a] = res;
   return res;
}

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}

ll modCON(ll n,ll r,ll m){
   if(n < 200010){
   ll res = 1;
   if(n < 0 || r < 0 || n < r){
      return 0;
   }
   res *= tableF[n];
   res %= m;
   res *= tableI[r];
   res %= m;
   res *= tableI[n-r];
   res %= m;
   return res;
   }else{
   ll res = 1;//tableを持ってないときよう
   for(int i = 1;i <= n;i++){
      res *= i;
      res %= m;
   }
   for(int i = 1;i <= r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   for(int i = 1;i <= n-r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   return res;
   }
}

void modfill(ll m){//忘れない　約200ms
   fill(tableF,tableF+200010,-1);
   fill(tableI,tableI+200010,-1);
   tableF[0] = 1;
   tableI[0] = 1;
   for(int i = 1;i < 200010;i++){
      tableF[i] = modfact(i,m);
      tableI[i] = modinv(tableF[i],m);
   }
}


int main(){
    modfill(MOD);
   ll N,K;
   cin >> N >> K;
   vector<ll> A(N);
   rep(i,N) cin >> A[i];
   sort(ALL(A));
   reverse(ALL(A));
   ll M = 0,m = 0;
   rep(i,N-K+1){
       M += A[i] * modCON(N-i-1,K-1,MOD) % MOD;
       while(M < 0){
          M += MOD * 100000000;
       }
       M %= MOD;
   }
   reverse(ALL(A));
   rep(i,N-K+1){
       m += A[i] * modCON(N-i-1,K-1,MOD) % MOD;
       while(m < 0){
          m += MOD * 10000000;
       }
       m %= MOD;
   }
   ll ans = M - m;
   while(ans < 0){
      ans += MOD * 10000000;
   }
   cout << ans % MOD << endl; 
}


Measured memory_bytes: 4096
#include <iostream>
#include <set>

int main(int argc, char *argv[]) {
  int q;
  std::cin >> q;
  std::multiset<long> s;
  for (int i = 0; i < q; ++i) {
    int c, x;
    std::cin >> c >> x;
    switch (c) {
    case 0:
      s.insert(x);
      std::cout << s.size() << std::endl;
      break;
    case 1:
      std::cout << s.count(x) << std::endl;
      break;
    case 2:
      s.erase(x);
      break;
    case 3:
      int r;
      std::cin >> r;
      for (auto i = s.lower_bound(x); i != s.upper_bound(r); ++i) {
        std::cout << *i << std::endl;
      }
    }
  }
}



Measured memory_bytes: 12304
#include<bits/stdc++.h>
#define D(...) fprintf(stderr,__VA_ARGS__)
#define int long long
#define LL long long
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
int n,a[10];
signed main(){
	rep(i,1,5){
		rd(a[i]);
		if(!a[i])pt(i,'\n'),exit(0);
	}
	return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
    x=0;static char ch;static bool flag;flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
const int maxn = 128;
struct Edge{
    int u,v,d;
    Edge(){}
    Edge(int a,int b,int c){
        u = a;v = b;d = c;
    }
}e[maxn];
int n = 20,m = 0;
int main(){
    int L;read(L);-- L;
    for(n = 0;(1 << n) <= L;++ n);
    if(n == 1){
        n = 2;
        printf("2 2\n1 2 0\n1 2 1\n");
        return 0;
    }
    for(int i=1;i<n;++i) e[++m] = Edge(i,i+1,0);
    for(int i=1;i<n;++i) e[++m] = Edge(i,i+1,1 << i-1);
    int res = 1 << n-1;L -= res-1;
//  printf("strat L = %d\n",L);
    for(int i=n-1;i;--i){
        while(L >= (1 << i-1)){
          //printf("at i = %d,decrease %d\n",i,1 << i-1);
            L -= (1 << i-1);
            e[++m] = Edge(i,n,res);
            res += (1 << i-1);
        }
    }
    //assert(m <= 60 && n <= 20);
    printf("%d %d\n",n,m);
    for(int i=1;i<=m;++i){
        printf("%d %d %d\n",e[i].u,e[i].v,e[i].d);
    }
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int x;
	scanf("%d",&x);
	int ans = 0;
	for (int i = 1; i <= x;i++){
		if (i % 2 == 0)continue;
		int count=0;
		for (int j = 1; j <= x; j++) {
			if (i % j == 0)count++;
		}
		if (count == 8)ans++;
	}
	printf("%d", ans);
}


Measured memory_bytes: 1708
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define maxn 500010
#define mod 1000000007
int p[510][510];
void sol(int l,int r,int x){
    if(l==r) return;
    int mid=(l+r)/2;
    for(int i=l;i<=mid;i++){
        for(int j=mid+1;j<=r;j++){
            p[i][j]=x;
        }
    }
    sol(l,mid,x+1);
    sol(mid+1,r,x+1);
}
int main(){
    int n;
    scanf("%d",&n);
    sol(1,n,1);
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++) printf("%d ",p[i][j]);
        printf("\n");
    }
    // if(n>=1){
    //     for(int i=1;i<=n;i++){
    //         if(i%3==0) p[i]=3;
    //         else p[i]=i%4;
    //     }
    // }
    // else{
    //     for(int i=1;i<n;i++){
    //         if(p[i])continue;
    //         cnt++;
    //         for(int j=i;j<n;j+=2*cnt){
    //             p[j]=cnt;
    //         }
    //     }
    // }
    // for(int i=n-1;i>0;i--){
    //     for(int j=1;j<=i;j++)printf("%d ",p[j]);
    //     printf("\n");
    // }
    return 0;
}

Measured memory_bytes: 1536
n = int(input())
a = list(map(int, input().split()))

ans = 1
flag = 0
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        flag = 1
        break

if flag == 1 and (0 not in a):
    ans = -1
if 0 in a:
    ans = 0

print(ans)


Measured memory_bytes: 21788
N,M = list(map(int,input().split()))
AC_list = [[0] * 2 for i in range(N)]
WA_count = 0
AC_count = 0
for i in range(M):
    A = list(input().split())
    if AC_list[int(A[0])-1][0] == 1:
        pass
    else:
        if A[1] == "AC":
            AC_list[int(A[0])-1][0] = 1
        else:
            AC_list[int(A[0])-1][1] += 1
for i in range(N):
    if AC_list[i][0] == 1:
        if 0 < AC_list[i][1]:
            WA_count += AC_list[i][1]
        AC_count += 1
print(AC_count,WA_count)

Measured memory_bytes: 13172
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func check1(f, t, n int, s string) bool {
	for i := f + 1; i <= t; i++ {
		if s[i] == '#' && s[i-1] == '#' {
			return false
		}
	}
	return true
}

func check2(b, d int, s string) bool {
	if b == 0 {
		b++
	}
	if d == len(s)-1 {
		d--
	}
	for i := b; i <= d; i++ {
		if s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' {
			return true
		}
	}

	return false
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, A, B, C, D := getInt(), getInt()-1, getInt()-1,
		getInt()-1, getInt()-1
	s := getString()

	ans := true
	if s[C] == '#' || s[D] == '#' {
		ans = false
	}
	ret := check1(A, C, N, s)
	ans = ans && ret

	ret = check1(B, D, N, s)
	ans = ans && ret

	if C > D {
		ret = check2(B, D, s)
		ans = ans && ret
	}
	if ans {
		out("Yes")
	} else {
		out("No")
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;

int vx[4] = {1, -1, 0, 0};
int vy[4] = {0, 0, 1, -1};
char m[1010][1010];
int main()
{
	int h, w;
	queue<pii> q;
	cin >> h >> w;
	rep(i,h){
		rep(k,w){
			char c;
			cin >> c;
			if(c=='#'){
				q.push(make_pair(k + 1, i + 1));
			}
			m[i + 1][k + 1] = c;
		}
	}
	int ans = 0;
	while (true)
	{
		queue<pii> nq;
		while(!q.empty()){
			nq.push(q.front());
			q.pop();
		}
		while(!nq.empty()){
			pii pos = nq.front();
			nq.pop();
			rep(i,4){
				int x = pos.first + vx[i];
				int y = pos.second + vy[i];
				if (m[y][x] == '.')
				{
					m[y][x] = '#';
					q.push(make_pair(x, y));
				}
			}
		}
		if(q.empty()){
			break;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9744
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

import bisect as bs
import numpy as np
A.sort()
C.sort()
#B_a:b未満のAのパーツ数、B_c:b超のCのパーツ数
B_a = np.array([bs.bisect_left(A,b) for b in B]) 
B_c = np.array([N-bs.bisect_right(C,b) for b in B])
ans = np.dot(B_a, B_c)
print(ans)

Measured memory_bytes: 47404
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<ll,ll> pint;
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}

int main(){
    ll k,a,b;cin>>k>>a>>b;
    bool flag= false;
    REP(i,a,b+1){
        if(i%k==0){
            flag= true;
        }
    }
    if(flag){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<pair<int,int> > a(n);
    rep(i,0,n){
        int l,r;
        cin>>l>>r;
        a[i] = make_pair(r,l);
    }
    sort(a.begin(),a.end());
    int time=0;
    rep(i,0,n){
        time+=a[i].second;
        if(time > a[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	map<string,int> myMap;
	map<string,int>::iterator mit;
	string S;
	int Max=0;
	for (int i=0;i<N;i++){
		cin>>S;
		mit=myMap.find(S);
		if (mit==myMap.end()){
			myMap[S]=1;
			if (Max<1){
				Max=1;
			}
		}else{
			(*mit).second++;
			if (Max<(*mit).second){
				Max=(*mit).second;
			}
		}
	}
	map<string,int> myMap1;
	for (mit=myMap.begin();mit!=myMap.end();mit++){
		if ((*mit).second==Max){
			myMap1[(*mit).first]=Max;
		}
	}
	for (mit=myMap1.begin();mit!=myMap1.end();mit++){
		cout<<(*mit).first<<endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    string in;
    cin >> in;
    long k;
    cin >> k;
    for (int i=0; i<in.length(); i++) {
        if (in[i] == 'a') continue;
        if (k >= (1 + 'z' - in[i])) {
            k -= 1 + 'z' - in[i];
            in[i] = 'a';
        }
    }
    if (k != 0) in[in.length()-1] = 'a' + (in[in.length()-1] - 'a' + k % 26) % 26;
    cout << in << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long n, a, b, mn = 1e15, sm = 0;
  scanf("%lld", &n);
  for(int i = 0; i < n; i++){
    scanf("%lld%lld", &a, &b);
    sm += a;
    if(a > b) mn = min(mn, b);
  }
  printf("%lld\n", (mn != 1e15 ? sm-mn : 0));
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}

int main(){
  int N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  rep(i,N){
    if(A[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }

  ll now = 1;
  ll maxi = 1;
  rep(i,18) maxi *= 10;
  rep(i,N){
    if((1e18+now-1)/now < A[i]){

      cout << -1 << endl;
      return 0;
    }
    now *= A[i];
    if(now>maxi){
      cout << -1 << endl;
      return 0;
    }
  }

  cout << now << endl;
  return 0;
}


Measured memory_bytes: 4052
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi
#import numpy as np
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  n = int(input())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  C = list(map(int, input().split()))
  A.sort()
  B.sort()
  C.sort()
  ans = 0
  for y in B:
    i = bisect_left(A, y)
    j = bisect_right(C,y)
    if i>0 and j != len(C):
      ans += i*(n-j)
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 118496
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int h, w, n;

int judge(vector<int> a, vector<int> b, vector<string> data) {
  int ret = 0;
  for (auto x : a) {
    for (auto y : b) {
      if (data[x][y] == '#') ret++;
    }
  }
  return ret;
}

int main() {
  cin >> h >> w >> n;
  unordered_map<int, int> h_map;
  unordered_map<int, int> w_map;
  vector<string> data;
  int sum = 0;
  int ans = 0;
  REP(i, h) {
    string x;
    cin >> x;
    data.push_back(x);
  }

  REP(i, h) {
    REP(j, w) {
      if (data[i][j] == '#') {
        h_map[i]++;
        w_map[j]++;
        sum++;
      }
    }
  }

  for (int bit = 0; bit < (1 << h); ++bit) {
    for (int bit2 = 0; bit2 < (1 << w); ++bit2) {
      vector<int> a;
      vector<int> b;
      int tmp = 0;
      for (int i = 0; i < h; ++i) {
        if (bit & (1 << i)) {
          a.push_back(i);
          tmp += h_map[i];
        }
      }

      for (int j = 0; j < w; ++j) {
        if (bit2 & (1 << j)) {
          b.push_back(j);
          tmp += w_map[j];
        }
      }

      if (sum - tmp + judge(a, b, data) == n) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3564
#include<iostream>
#include<set>
using namespace std;main(){int n,m,i,t,x;while(cin>>n>>m,n|m){
set<int> s;for(i=0;i++<n+m;s.insert(t))cin>>t;x=t=0;for(set<int>::iterator r=s.begin();r!=s.end();t=*r++)if(x<*r-t)x=*r-t;cout<<x<<endl;}}

Measured memory_bytes: 1332
#include<bits/stdc++.h>
using namespace std;
#define maxn 20
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n;
long long a[maxn];
long long dfs(int l,int r,int L,int R)
{
	if(l>r)return 0;
	long long res=1e18;
	for(int i=l;i<=r;i++)
		res=min(res,dfs(l,i-1,L,L+R)+dfs(i+1,r,L+R,R)+a[i]*(L+R));
	return res;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]);
	printf("%lld\n",a[1]+a[n]+dfs(2,n-1,1,1));
    return 0;
}


Measured memory_bytes: 384
/*  Isn't it lovely, all alone?             */
/*  Heart made of glass, my mind of stone   */
/*  Tear me to pieces, skin to bone         */
/*  Hello, welcome home                     */

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll mod=1000000007;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n;
cin>>n;

cout<<n+(n*n)+(n*n*n)<<endl;

}
return 0;
}




















Measured memory_bytes: 3608
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;

int main(){
    list<int> g[3];
    g[0] = {1, 3, 5, 7, 8, 10, 12};
    g[1] = {4, 6, 9, 11};
    g[2] = {2};
    int x, y;
    cin >> x >> y;
    for (int i=0; i<3; i++){
        if (find(g[i].begin(),g[i].end(),x) != g[i].end() && find(g[i].begin(),g[i].end(),y) != g[i].end()){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll A;
  string B;
  cin >> A >> B;
  for(ll i = 0; i < B.size(); i++) {
    if(B.at(i) == '.') B.erase(i, 1);
  }
  cout << A * (stoi)(B) / 100 << endl;
}

Measured memory_bytes: 3572
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
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()
{
	ll  i, j, k, l, m, sum, flag, N, x, y, M, K, H, W, B;
	cin >> K;
	vector<ll>A(K);
	REP(i, 0, K) {
		cin >> A[i];
	}
	ll min, max;
	reverse(A.begin(), A.end());
	if (A[0] != 2) {
		output("-1");
		return 0;
	}
	min = max = 2;
	REP(i, 1, K) {
		if (min%A[i]!=0&&max + A[i - 1] - 1 - min >= A[i]) {
		
				min = min + A[i] - min % A[i];
		

			max = (max + A[i - 1] - 1)/A[i]*A[i] ;
			//output(min); output(max);
		}
		else if (min%A[i] == 0) {
			min = min ;

			max = (max + A[i - 1] - 1) / A[i] * A[i];
			//output(min); output(max);
		}
		else if (min%A[i] > (max + A[i - 1] - 1) % A[i]) {
			min = min + A[i] - min % A[i];

			max = (max + A[i - 1] - 1) / A[i] * A[i];
			//output(min); output(max);
		}
		else {
			output("-1");
			return 0;
		}
	}
	max = max + A[K - 1] - 1;
	output(min);
	output(max);
	
}













Measured memory_bytes: 1024
n=int(input())
l=list(map(int,input().split()))

ans=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      if i <= j <= k:
        if l[i]==l[j] or  l[j]==l[k] or l[i]==l[k]:
          continue
        if max(l[i],l[j],l[k]) < l[i] +l[j] + l[k] - max(l[i],l[j],l[k]):
          ans+=1
print(ans)

Measured memory_bytes: 74528
/*
 *    FileName:
 *      Source:
 *        Date:
 *      Author: Mew
 *	  Function:
 */
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<iterator>
#include<ctime>
using namespace std;
int main()
{
	string s;
	cin >> s;
	for(unsigned int i=0;i<s.length();i++){
		cout<<s[i];
		if(i == 3)cout<<' ';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    vi a2(n);
    rep(i,n){
        a2.at(i) = a.at(i);
    }
    map<int64_t,int64_t> map;
    sort(a.begin(), a.end());
    int64_t tmp = 1;
    for(int64_t i=1; i<n; i++){
        if(a.at(i) != a.at(i-1)) {
            map.insert(make_pair(a.at(i-1), tmp));
            tmp=1;
            continue;
        }
        tmp++;
    }
    map.insert(make_pair(a.at(n-1), tmp));
    int64_t sum = 0;
    for(pair<int64_t, int64_t> p: map){
        sum += p.second*(p.second-1)/2;
    }
    rep(i,n){
        cout << sum-((map.at(a2.at(i)))-1) << endl;
    }
}


Measured memory_bytes: 12672
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a == b)
            System.out.println(c);
        else if (b == c)
            System.out.println(a);
        else

            System.out.println(b);
    }
}


Measured memory_bytes: 25300
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 61;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<vector<lint>> dp(N + 4, vector<lint>(2, -LINF));
	dp[0][0] = -A[0];
  	dp[0][1] = dp[1][1] = 0;
  	dp[1][0] = -A[1];

	for (int i = 0; i < N; i++) {
		
		chmax(dp[i + 2][0], dp[i][0] + A[i]);
		chmax(dp[i + 2][0], dp[i][1] + 0   );
		chmax(dp[i + 2][1], dp[i][1] + A[i]);

		if (i & 1) {
			chmax(dp[i + 3][0], dp[i][1] + A[i]);
		}
		else {
			chmax(dp[i + 3][0], dp[i][0] + A[i]);
			chmax(dp[i + 3][0], dp[i][1] + 0);
			chmax(dp[i + 3][1], dp[i][1] + A[i]);
          	chmax(dp[i + 4][0], dp[i][1] + A[i]);
		}

	}

	lint ans = -LINF;
  	bool offset = N & 1;
	chmax(ans, dp[N + 0 - offset][1]);	
  	chmax(ans, dp[N + 1 - offset][1]);	
  	chmax(ans, dp[N + 2 - offset][0]);	
  	chmax(ans, dp[N + 3 - offset][0]);
  	
  	cerr << dp << endl;

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 18536
#include <stdio.h>

int main(void){
    
    int S,h,m,s;
    
   
	scanf("%d", &S);


    h = S / 3600;
	m = (S % 3600)/60;
	s = (S % 3600) % 60;

	printf("%d:%d:%d\n", h,m,s);
    
  
    
    
    return 0;
    
}


Measured memory_bytes: 2108