akhauriyash/Code-Regression huggingface dataset:
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7,N=2002*2002;
int pw(int x,int y){
	int z=1;
	for (;y;y>>=1,x=1ll*x*x%M)
		if (y&1) z=1ll*z*x%M;
	return z;
}
int INV(int x){return pw(x,M-2);}
int fac[N],inv[N],f[2002][2002],i,j,n,k;
int C(int n,int m){return 1ll*fac[n]*inv[m]%M*inv[n-m]%M;}
int main(){
	scanf("%d%d",&n,&k);
	if (k==1) return puts("1"),0;
	fac[0]=1;
	for (i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%M;
	inv[N-1]=INV(fac[N-1]);
	for (i=N-2;~i;i--) inv[i]=1ll*inv[i+1]*(i+1)%M;
	for (i=0;i<=n;i++)
		for (f[i][0]=1,j=1;j<=i;j++) f[i][j]=(f[i-1][j]+1ll*f[i][j-1]*(n-j+1)%M*C(n*k-i-(j-1)*(k-1)-1,k-2)%M)%M;
	printf("%d",f[n][n]);
}

Measured memory_bytes: 46336
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<set>
#include<cmath>

#define REP(i,s,e) for(int i=int(s);i<int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)


using namespace std;

int main(){

int N;
cin >> N;

int a,b,c;
rep(i,N){

cin >> a >> b >> c;

if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==b*b+a*a)
cout << "YES" << endl;
else cout << "NO" << endl;

}

return 0;

}

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

#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a);i!=(b);++i)
#define all(v) (v).begin(), (v).end()
#define rs resize
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

ostream& operator<<(ostream &out, const pii &a) { return out << '(' << a.x << ", " << a.y << ')'; }
istream& operator>>(istream &in, pii &a) { return in >> a.x >> a.y; }

const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

// lambda-expression: [] (args) -> retType { body }

void run()
{
	int a, b;
	cin >> a >> b;
	a %= 2;
	b %= 2;
	a *= b;
	if (a % 2 == 0) cout << "Even" << endl;
	else cout << "Odd" << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// cerr << boolalpha;
	(cout << fixed).precision(10);

	run();

	return 0;
}

Measured memory_bytes: 256
import sys
# input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        x, y, c = map(int, input().split())
        yield x-1, y-1, c

def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    yield(min(a) + min(b))

    for x, y, c in readlines(M):
        a_ = a[x]
        b_ = b[y]

        yield a_ + b_ - c

print(min(main()))


Measured memory_bytes: 18736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int main()
{
	int n;cin>>n;
	map<string,int> mp;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	int max1=-1;
	tr(mp,it)
	{
		max1=max(max1,it->second);
	}
	set<string> st;
	tr(mp,it)
	{
		if(it->second == max1)
		{
			st.insert(it->first);
		}
	}
	tr(st,it)
	{
		cout<<*it<<endl;
	}
	return 0;
}

Measured memory_bytes: 34560
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

int A, B, C;
int a[100], b[100], c[100];

int main()
{
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	memset(c, 0, sizeof(c));
	scanf("%d%d%d", &A, &B, &C);
	if((A & 1) || (B & 1) || (C & 1)) printf("0\n");
	else {
		while(A != 0) {
			a[++a[0]] = A % 2;
			A >>= 1;
		}
		while(B != 0) {
			b[++b[0]] = B % 2;
			B >>= 1;
		}
		while(C != 0) {
			c[++c[0]] = C % 2;
			C >>= 1;
		}
		int ans = 1 << 30;
		for(int i = 1; i <= max(a[0], max(b[0], c[0])); i++) {
			bool flag1 = 0, flag0 = 0;
			if(a[i] || b[i] || c[i]) flag1 = 1;
			if(!a[i] || !b[i] || !c[i]) flag0 = 1;
			if(flag1 && flag0) {ans = i; break;}
		}
		if(ans == 1 << 30) printf("-1\n");
		else printf("%d\n", ans - 1);
	}
}

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

bool isPrime(int n) {
  for(int i = 2; i <= sqrt(n); ++i){
    if(n%i == 0) return false;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  while(N--){
    int a;
    cin >> a;
    cnt += isPrime(a);
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 0
/*GOD     IS    GREAT,
  SO    AM    I*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define op(z) cout<<z<<endl
#define ops(z) cout<<z<<" "
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout<<#x<<" "<<x<<endl
int main()
{
  ll n,k,i,j;
  cin>>n;
  for(i=1;i<10;i++)
  {
	for(j=1;j<=9;j++)
    {
	if(i*j==n)op("Yes"),exit(0);
    }}
  op("No");}

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

using namespace std;

int main() {

    int n;

    while(cin >> n, n) {

        string f;
        int cnt = 0;
        char now, bef = 0;

        for(int i = 0; i < n; ++i) {
            cin >> f;
            now = f[1];
            if(now == bef) {
                ++cnt;
            }
            bef = now;
        }

        cout << cnt << endl;

    }

}

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

int main() {
  int N;
  int ans = 0; 
  cin >> N;
  vector<int> bou(N);
  for (int i=0; i < N; i++) {
    cin >> bou.at(i);
  }
  sort(bou.begin(), bou.end());
  for (int i=0; i < N - 2; i++) {
    int bi = bou.at(i);
    int j = i + 1;
    while (j < N - 1) {
      int bj = bou.at(j);
      int k = j + 1;
      while (k < N) {
        int bk = bou.at(k);
        if (bi < bj + bk && bj < bk + bi &&
            bk < bi + bj) {
          ans++;
        }
        k++;
      }
      j++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(r) r.begin(),r.end()
using namespace std;
typedef int64_t ll;
typedef vector<ll> vll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        n *= 2;
        vll l(n);
        for (int i = 0; i < n; i++) {
            in >> l[i];
        }
        sort(all(l));
        ll ans = 0;
        for (int i = 0; i < n; i += 2) {
            ans += min(l[i], l[i + 1]);
        }
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
def func(n):
  if n % 2 == 0:
    return n//2
  else:
    return 3 * n + 1
  
s = int(input())

ans=[s]
for i in range(1000000):
  temp = func(ans[-1])
  try:
    t = ans.index(temp)
    print(i + 2)
    break
  except:
    ans.append(temp)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define array_input int n;cin>>n;int a[n+1],i;for(i=1;i<=n;i++){cin>>a[i];}
#define array_output for(i=1;i<=n;i++){cout<<a[i]<<" ";}cout<<endl;
#define INF 2147483647
#define long_INF 18446744073709551615
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
const double pi=acos(-1);
const double eps=1e-6;
 
int main()
{
	ios::sync_with_stdio(false);
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	cout<<s1[0]<<s2[1]<<s3[2]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N, W;
    cin >> N >> W;
    vector< multiset<llint, greater<llint> > > m(4);
    llint w1;
    REP(i, N){
        llint w, v;
        cin >> w >> v;
        if(i == 0) w1 = w;
        w -= w1;
        m[w].insert(v);
    }
    llint ans = -1;
    REP(i, N+1)REP(j, N+1-i)REP(k, N+1-i-j)REP(l, N+1-i-j-k){
        if(i*w1 + j*(w1+1) + k*(w1+2) + l*(w1+3) > W) continue;
        llint tmp = 0;
        REP(p, 4){
            int ct;
            switch(p){
                case 0:
                    ct = i; break;
                case 1:
                    ct = j; break;
                case 2:
                    ct = k; break;
                case 3:
                    ct = l; break;
            }
            for(auto x : m[p]){
                if(ct == 0) break;
                tmp += x;
                ct--;
            }
        }
        ans = max(ans, tmp);
    }

    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=2e5+5;
int num[45][45];
int a[maxm];
int n;
signed main(){
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){//用字符串读,避免误差
        string s;cin>>s;
        int num=0;
        int cnt=-1;
        for(auto x:s){
            if(isdigit(x)){
                num=num*10+x-'0';
                if(cnt>0)cnt--;
            }else{//小数点
                cnt=9;
            }
        }
        if(cnt==-1)cnt=9;//如果没有小数点
        while(cnt-->0)num=num*10;
        a[i]=num;
    }
    for(int i=1;i<=n;i++){
        int c2=0,c5=0;
        while(a[i]%2==0){
            c2++;
            a[i]/=2;
        }
        while(a[i]%5==0){
            c5++;
            a[i]/=5;
        }
        num[c2][c5]++;
    }
    int ans=0;
    for(int i=18;i<=90;i++){
        for(int j=18;j<=90;j++){
            //枚举结果数对(i,j)
            for(int x=0;x<45&&x<=i;x++){
                for(int y=0;y<45&&y<=j;y++){
                    int xx=i-x,yy=j-y;
                    if(xx<0||xx>=45||yy<0||yy>=45)continue;
                    if(xx==x&&yy==y){//相等的情况特判一下,不能匹配自己
                        ans+=num[x][y]*(num[x][y]-1);
                    }else{
                        ans+=num[x][y]*num[xx][yy];
                    }
                }
            }
        }
    }
    ans/=2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
int main() {
  int s,count;
  count = 0;
  cin >> s;
  if ( s / 100 == 1 ) {
    count++;
  }
  if ( s / 10 % 10 == 1 ) {
    count++;
  }
  if ( s % 10 == 1 ) {
    count++;
  }
  cout << count << endl;
}

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



int main()
{
    int N,W, w, v;
    scanf("%d%d",&N,&W);

    vector<long long int> weight(N), value(N);

    for(int i = 0; i < N; i++)
    {
        scanf("%lld%lld",&weight[i],&value[i]);
    }


    vector<vector<long long int> > maxValue(W+1, vector<long long int> (N+1,0));

    for(int i = 0; i <= W; i++)
    {
        for(int j = 0; j <= N; j++)
        {
            if(i == 0 || j == 0)
                maxValue[i][j] = 0;
            else if(weight[j-1] > i)
                maxValue[i][j] = maxValue[i][j-1];
            else
            {
                long long temp1 = maxValue[i][j-1];
                long long  temp2 = maxValue[i - weight[j-1]][j-1] + value[j-1];

                maxValue[i][j] = max(temp1, temp2);
            }

        }
    }

    printf("%lld\n",maxValue[W][N]);

    return 0;
}

Measured memory_bytes: 82304
import sys
import math as mas

n=int(input())
for t in range(n):
	i=int(t)
	a=int(input())
	b=int(input())
	a+=b
	if a<10**80:print(a)
	else:print("overflow")
	
#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Measured memory_bytes: 7616
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)

#print(A_CS)
ans = 0
for i in range(n-1):
#    print(A[i], A_CS[-i-2])
#    A_CS -= A[i]
    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)

Measured memory_bytes: 39524
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n m
a1 b1
...
am bm

n m 50
 */
int n,m;
int ans[50];
int main(){
  cin>>n>>m;
  REP(i,m){
    int a,b;
    cin>>a>>b;
    ans[a-1]++;
    ans[b-1]++;
  }

  REP(i,n){
    cout<<ans[i]<<endl;
  }
  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;

int main() {
  int N,M;
  cin>>N>>M;
  
  vector<int>vec(N,1);
  vector<long long> vech(N);
for (int i = 0; i < N; i++) {
  cin >> vech.at(i);
}
  vector<vector<int>> data(M, vector<int>(2));
 
  
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
      data.at(i).at(j)--;
    }
    if(vech.at(data.at(i).at(0))==vech.at(data.at(i).at(1))){
      vec.at(data.at(i).at(0))=0;
      vec.at(data.at(i).at(1))=0;
    }
     else if(vech.at(data.at(i).at(0))<vech.at(data.at(i).at(1))){
        vec.at(data.at(i).at(0))=0;
     }
      else{
        vec.at(data.at(i).at(1))=0;
      }
       
             
      
    
}
           int ans=0;
  cin>>ans;
          for (int i = 0; i < N; i++) {
 if(vec.at(i)==1){
   ans++;
} 
          }
            cout<<ans<<endl;
}

Measured memory_bytes: 9824
import std.stdio,std.conv,std.string;

void main(){
    bool[9][9] m;
    foreach(y;0..8){
        foreach(x,c;readln.chomp){
            m[y*2][1+x*2]=c=='1';
        }
        foreach(x,c;readln.chomp){
            m[y*2+1][x*2]=c=='1';
        }
    }
    int x,y,dir=6;
    while(true){
        final switch(dir){
            case 2:
                if(x!=8&&m[y][x+1]){
                    x+=2;
                    dir=6;
                    dir.p;
                }else if(y!=8&&m[y+1][x]){
                    y+=2;
                    dir.p;
                }else{
                    dir=4;
                }
                break;
            case 4:
                if(y!=8&&m[y+1][x]){
                    y+=2;
                    dir=2;
                    dir.p;
                }else if(x!=0&&m[y][x-1]){
                    x-=2;
                    dir.p;
                }else{
                    dir=8;
                }
                break;
            case 6:
                if(y!=0&&m[y-1][x]){
                    y-=2;
                    dir=8;
                    dir.p;
                }else if(x!=8&&m[y][x+1]){
                    x+=2;
                    dir.p;
                }else{
                    dir=2;
                }
                break;
            case 8:
                if(x!=0&&m[y][x-1]){
                    x-=2;
                    dir=4;
                    dir.p;
                }else if(y!=0&&m[y-1][x]){
                    y-=2;
                    dir.p;
                }else{
                    dir=6;
                }
        }
        if(!x&&!y)break;
    }
    writeln;
}

void p(int dir){
    final switch(dir){
        case 2:'D'.write;break;
        case 4:'L'.write;break;
        case 6:'R'.write;break;
        case 8:'U'.write;break;
    }
}

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

#define all(x) (x).begin(), (x).end()
#define itn int
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 2222;
vector<int> a[N];
string s;

long long level[N];
int cnt[N];
long long minsuml[N];
long long suml[N];

void dfs(int v, int p) {
	long long res = 0;
	if (s[v] == '1') {
		res += level[v];
		cnt[v] = 1;
	}
	vector<int> tos;
	vector<long long> sumls;
	for (int x : a[v]) {
		if (x != p) {
			level[x] = level[v] + 1;
			dfs(x, v);
			suml[v] += suml[x] + cnt[x];
			sumls.push_back(suml[x] + cnt[x]);
			tos.push_back(x);
			cnt[v] += cnt[x];
		}
	}
	if (tos.empty()) {
		minsuml[v] = suml[v];
		return;
	}
	int idx = max_element(all(sumls)) - sumls.begin();
	if (suml[v] / 2 < sumls[idx]) {
		long long newsuml = suml[v] - sumls[idx] + minsuml[tos[idx]] + cnt[tos[idx]];
		if (newsuml / 2 >= minsuml[tos[idx]] + cnt[tos[idx]]) {
			minsuml[v] = suml[v] % 2;
		} else {
			minsuml[v] = newsuml - 2 * (newsuml - (minsuml[tos[idx]] + cnt[tos[idx]]));
		}
	} else {
		minsuml[v] = suml[v] % 2;
	}
}

long long solve(int r) {
	memset(level, 0, sizeof(level));
	memset(cnt, 0, sizeof(cnt));
	memset(minsuml, 0, sizeof(minsuml));
	memset(suml, 0, sizeof(suml));
	dfs(r, -1);
	// if (r == 2) {
	// 	for (int i = 0; i < 7; ++i) {
	// 		cerr << i + 1 << ": " << suml[i] << " " << minsuml[i] << " " << cnt[i] << " " << level[i] << "\n";
	// 	}
	// }
	if (minsuml[r] == 0) {
		return suml[r] / 2;
	} else {
		return -1;
	}
}

int main() {
	int n = nxt();
	cin >> s;
	for (int i = 0; i < n - 1; ++i) {
		int u = nxt() - 1, v = nxt() - 1;
		a[u].push_back(v);
		a[v].push_back(u);
	}

	long long ans = -1;
	for (int r = 0; r < n; ++r) {
		long long tmp = solve(r);
		if (ans == -1 || (tmp > -1 && tmp < ans)) {
			ans = tmp;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 768
N = int(input())
A = [int(i) for i in input().split()]

flg = [0,0,0,0,0,0,0,0,0]
for i in range(N):
    if   A[i] <  400: flg[0] = 1
    elif A[i] <  800: flg[1] = 1
    elif A[i] < 1200: flg[2] = 1
    elif A[i] < 1600: flg[3] = 1
    elif A[i] < 2000: flg[4] = 1
    elif A[i] < 2400: flg[5] = 1
    elif A[i] < 2800: flg[6] = 1
    elif A[i] < 3200: flg[7] = 1
    else:             flg[8] += 1

colmin = max(sum(flg[0:8]), 1)
colmax = sum(flg)
print(colmin, colmax)


Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int h[105];

int ans=0;

void water(int k,int l){
	//cout<<ans;
	int min=1000;
	int imin;
	if(k==l){
		ans+=h[k];
		return;
	}
	if(k>l)
		return;
	for(int i=k;i<=l;i++){
		if(h[i]==0){
			water(k,i-1);
			water(i+1,l);
			return;
		}
		if(min>h[i]){
			min=h[i];
			imin=i;
		}
	}
	ans+=min;
	for(int i=k;i<=l;i++){
		h[i]-=min;
	}
	water(k,imin-1);
	water(imin+1,l);
}
	
int main(){
	cin>>n;
	REP(i,n){
		cin>>h[i];
	}
	water(0,n-1);
	cout<<ans<<endl;
}

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

using namespace std;

const int N = 1299710;

vector<bool> p;

void init(){
    p.assign(N, true); p[0] = p[1] = false;
    for(int i=2; i<=N; ++i)if(p[i]){
        for(int j=i<<1; j<=N; j+=i)p[j] = false;
    }
}

int main(){
    init();
    for(int k; cin >> k, k;){
        int lo = k, hi = k;
        while(!p[lo])lo--;
        while(!p[hi])hi++;
        cout << hi - lo << '\n';
    }
    return 0;
}

Measured memory_bytes: 1272
INF = 10 ** 7
def solve(N):
    ans = 0
    for i in range(len(N)):
        if i == 0:
            before = [0] * 11
            before[int(N[i])] += 1
            ans += before[0]
        elif N[i] == '0':
            now = [0] * 11
            for j in range(11):
                k = j*10%11
                now[k] += before[j]
            ans += now[0]
            before = now
        else:
            M = int(N[i])
            now = [0] * 11
            for j in range(11):
                k = (j*10 + M)%11
                now[k] += before[j]
            now[M%11] += 1
            ans += now[0]
            before = now
    print(ans)

def main():
    while True:
        N = input()
        if N == '0':
            return
        solve(N)
if __name__ == '__main__':
    main()



Measured memory_bytes: 5964
h,w=map(int,input().split())
a=[0]*(w+2)
m=[a]
ans='Yes'
for i in range(h):
    s=input()
    m.append([0]+[1 if x=='#' else 0 for x in s]+[0])
m.append(a)
for i in range(1,h+1):
    for j in range(1,w+1):
        if m[i][j]==1 and sum(m[i][j-1:j+2],m[i-1][j]+m[i+1][j])==1:
            ans='No'
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N;
    cin >> N;
    string letters = "0abcdefghijklmnopqrstuvwxyz";
    vector <char> S;
    while (N >= 1){
        long long mod = N % 26;
        if (mod == 0) {
            S.push_back('z');
            N--;
        }
        else S.push_back(letters[mod]);
        N /= 26;
    }
    for (int i = S.size()-1; i >=0; i--)
        cout << S[i];
    cout << endl;
}


Measured memory_bytes: 3600
use whiteread::parse_line;

fn main() {
    let (n, k): (usize, usize) = parse_line().unwrap();
    let s: Vec<u32> = parse_line().unwrap();
    let mut maxsum = 0;
    let mut maxi = 0;
    let mut ans = 0.0;

    for i in 0..n - k + 1 {
        let sum = s[i..i + k].iter().sum();
        if sum > maxsum {
            maxsum = sum;
            maxi = i;
        }
    }
    for i in 0..k {
        ans += (1 + s[maxi + i]) as f64 / 2.0;
    }
    println!("{}", ans);
}


Measured memory_bytes: 3940
h, w = list(map(int, input().split()))
import sys

if w == 1 or h == 1:
  print('1')
  sys.exit()

if w % 2 == 0:
  print(h * w // 2)
else:
  if h % 2 == 0:
    print((w // 2 + w // 2 + 1) * h // 2)
  else:
    print((w // 2 + w // 2 + 1) * (h // 2) + w // 2 + 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


template<class T>
void show_1d_vector(const vector<T> &v){
    for(auto v1: v) {
        cout << v1 << " ";
    }
    cout << endl;
}


int main(){
    ll n, d ,a;
    cin >> n >> d >> a;

    vector<pll> xh(n);
    vector<ll> p(n);
    for(int i = 0; i < n; i++){
        cin >> xh[i].first >> xh[i].second;
    }

    map<ll,ll> mp;
    sort(all(xh));
    for(int i = 0; i < n; i++){
        p[i] = xh[i].first;
    }

    for(int i = 0; i < n; i++){
        mp[i] = xh[i].first;
    }

    vector<ll> imos(n+2,0);
    ll ans = 0;
    //show_1d_vector(p);
    for(int i = 0; i < n; i++){
        if(i>0){
            imos[i] += imos[i-1];
        }
        if(xh[i].second-imos[i]<=0){
            ll needed = 0;
        }else{
            ll needed = (xh[i].second-imos[i])/a;
            if(xh[i].second%a != 0){needed++;}
            ans += needed;
            imos[i] += needed*a;
            ll range=xh[i].first + 2*d;

            auto it = lower_bound(p.begin(), p.end(), range+1);

            ll index = it - p.begin();
            imos[index] -=  needed*a;
        }
        //show_1d_vector(imos);

    }
    cout << ans << endl;


    return 0;

}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;


template <typename T>using ordered_set = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;

#define PI              acos(-1.0)
#define en '\n'
#define Infi 0x3f3f3f3f
#define LInfi 0x3f3f3f3f3f3f3f3f



#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);


const int dx[] = {+1,-1,+0,+0};                         // 4 X directions
const int dy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int dx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int dy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int  ll;
typedef unsigned long long int llu;

vector<int> cost;

int dp[1000005];
int make(int id){


    if(id>=cost.size()-1){
        return 0;
    }
    int p1=Infi,p2=Infi;

    if(dp[id]!=-1)return dp[id];

    if(id+1<cost.size())
     p1 = abs(cost[id]-cost[id+1]) + make(id+1);
    if(id+2<cost.size())
     p2 = abs(cost[id]-cost[id+2]) + make(id+2);

    return dp[id] = min(p1,p2);

}


int main(void){


    int n;
    cin >> n;

    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        cost.push_back(x);
    }

    for(int i=0;i<1000005;i++){
        dp[i]=-1;
    }

    cout << make(0) << endl;

    return 0;
}


Measured memory_bytes: 7800
fun main(arg: Array<String>) {
    val S = next()
    val N = S.length - 1
    val e = Eval()
    var ans = 0L
    for (b in 0 until 1.shl(N)) {
        val P = BooleanArray(N + 1)
        for (n in 0 until N) {
            if (b.shr(n).and(1) == 1) P[n] = true
        }
        val Ex = StringBuilder()
        for (n in 0 until N + 1) {
            Ex.append(S[n])
            if (P[n]) Ex.append('+')
        }
        ans += e.eval(Ex.toString())
    }


    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


class Eval {
    private val num_list = java.util.ArrayList<Long>()
    private val ope_list = java.util.ArrayList<Char>()
    private fun _list_init() {
        num_list.clear()
        ope_list.clear()
    }
    private fun _lexical_analysis(formula: String) {
        val sequenceList = formula.toCharArray()
        var set_num = 0L
        for (token in sequenceList) {
            if ("+-*/".indexOf(token) > -1) {
                ope_list.add(token)
                num_list.add(set_num)
                set_num = 0L
            } else if ("123456789".indexOf(token) > -1) {
                set_num *= 10L
                set_num += (token - '0').toLong()
            }
        }
        num_list.add(set_num)
    }
    fun _calculation(): Long {
        var num1_num: Long
        var num2_num: Long
        var set_num: Long
        var num1_id: Int
        var num2_id: Int
        var hit_count = 0
        for (token in ope_list) {
            var hit_id = -1
            if (token == '*' || token == '/') {
                hit_id = ope_list.indexOf(token)
                ope_list[hit_id] = '@'
                num1_id = hit_id - hit_count
                num2_id = hit_id - hit_count + 1
                num1_num = num_list[num1_id]
                num2_num = num_list[num2_id]
                set_num = if (token == '*') num1_num * num2_num else num1_num / num2_num
                num_list[num1_id] = set_num
                num_list.removeAt(num2_id)
                hit_count++
            }
        }
        while (ope_list.remove('@')) { }
        for (token in ope_list) {
            num1_id = 0
            num2_id = 1
            num1_num = num_list[num1_id]
            num2_num = num_list[num2_id]
            set_num = num1_num + if (token == '+') num2_num else -num2_num
            num_list[num1_id] = set_num
            num_list.removeAt(num2_id)
        }
        return num_list[0]
    }

    fun eval(formula: String): Long {
        _list_init()
        _lexical_analysis(formula)
        val anser = _calculation()
        return anser
    }
}


Measured memory_bytes: 31860
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    StringBuilder bl = new StringBuilder();
    int id,l,r,root=-1;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Node [] node = new Node[n];

    for(int i = 0; i<n; i++){
      node[i] = new Node();
    }

    for(int i = 0; i<n; i++){
      id = sc.nextInt();
      l = sc.nextInt();
      r = sc.nextInt();
      node[id].left = l;
      node[id].right = r;
      if(l != -1) node[l].parent = id;
      if(r != -1) node[r].parent = id;
    }

    for(int i = 0;i<n; i++){
      if(node[i].parent==-1)root = i;
    }
    bl.append("Preorder\n");
    Pre_order(root, node,bl);
    bl.append("\nInorder\n");
    In_order(root, node, bl);
    bl.append("\nPostorder\n");
    Post_order(root, node,bl);
    System.out.println(bl);

  }
  static void Pre_order(int u, Node node[], StringBuilder bl){
    if(u==-1){
      return ;
    }
    bl.append(' ').append(u);
    Pre_order(node[u].left,node,bl);
    Pre_order(node[u].right,node,bl);

  }

  static void In_order(int u, Node node[], StringBuilder bl){
    if(u == -1){
      return;
    }
    In_order(node[u].left, node, bl);
    bl.append(' ').append(u);
    In_order(node[u].right, node,bl);
  }

  static void Post_order(int u, Node node[], StringBuilder bl){
    if(u == -1){
      return;
    }
    Post_order(node[u].left, node, bl);
    Post_order(node[u].right, node,bl);
    bl.append(' ').append(u);
  }

}

class Node{
  int parent = -1;
  int left = -1;
  int right = -1;
}


Measured memory_bytes: 26440
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
#define allr(vec) vec.rbegin(),vec.rend()
using namespace std;

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

using ll=int64_t;

using vb=vector<bool>;
using vc=vector<char>;
using vs=vector<string>;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

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

  ll A; string B; cin >>A >>B;

  ll B100=(B[0]-'0')*100+(B[2]-'0')*10+(B[3]-'0');

  cout <<A*B100/100 <<'\n';
  return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>>A(H, vector<char>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A.at(i).at(j);
		}
	}
	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			if (i == 0 || j == 0 || i == H + 1 || j == W + 1) cout << '#';
			else cout << A.at(i - 1).at(j - 1);
		}
		cout << endl;
	}
}

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

int main(){
	int n,h;
	cin>>n>>h;
	vector<int> b(n+1);
	b[n]=0;
	int ma=0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a>>b[i];
		ma=max(ma,a);
	}
	
	sort(b.begin(),b.end(),greater<int>());
	
	
	int kai=0;
	while(h>0){
		if(ma<b[kai]){
			h-=b[kai];
			kai++;
		}else{
			break;
		}
	}
	if(h>0){
		kai+=h/ma;
		if(h%ma!=0)kai++;
	}
	cout<<kai<<endl;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    vec<ll> a;
    ll con = 1;
    rep(i, 1, n) {
        if(s[i] != s[i - 1]) {
            a.push_back(con);
            con = 1;
        } else {
            con++;
        }
    }
    a.push_back(con);

    if(a.size() == 1) {
        ll m = n * k;
        cout << m / 2 << en;
        return;
    }

    ll t = 0;
    REP(i, a.size()) {
        t += a[i] / 2;
    }
    ll ans = t * k;
    if(s[0] == s[n - 1]) {
        ans += ((a[0] + a[a.size() - 1]) / 2 - a[0] / 2 - a[a.size() - 1] / 2) * (k - 1);
    }
    cout << ans << en;
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void){
    char s;
    scanf("%c", &s);
    if(s == 'A')printf("T\n");
    else if(s == 'T')printf("A\n");
    else if(s == 'C')printf("G\n");
    else if(s == 'G')printf("C\n");
    return 0;
}

Measured memory_bytes: 128
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func check7(sum int, arr []int, eq string) {
	if len(arr) == 0 {
		if sum == 7 {
			fmt.Printf("%s=7\n", eq)
			os.Exit(0)
		}
	} else {
		check7(sum+arr[0], arr[1:], fmt.Sprintf("%s+%d", eq, arr[0]))
		check7(sum-arr[0], arr[1:], fmt.Sprintf("%s-%d", eq, arr[0]))
	}
}

func main(){
	var abcd string
	fmt.Scan(&abcd)
	arr := make([]int, 4)
	for i, v := range abcd {
		arr[i] = int(v - '0')
	}
	check7(arr[0], arr[1:], strconv.Itoa(arr[0]))
}

Measured memory_bytes: 640
S = list(input())
N = len(S)
S_mae = S[:int((N-1)/2)]
S_usi = S[int((N+1)/2):]

if S_mae == S_mae[::-1] and S_usi == S_usi[::-1] and S == S[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main() {
  long X, A, B;
  cin >> X;
  for (long i = -200; i <= 200; i++){
    for (long j = -200; j <= 200; j++){
      if (i*i*i*i*i - j*j*j*j*j == X){
        A = i;
        B = j;
        break;
      }
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 3632
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  if(A%3==0||B%3==0||(A+B)%3==0) cout << "Possible" << endl;
  else  cout << "Impossible" << endl;

}

Measured memory_bytes: 256
n = int(input())
mat = []
for _ in range(n):
  mat.append(list(map(int,input().split())))

d = [[False]*n for _ in range(n)]

for k in range(n):
  for i in range(n):
    for j in range(n):
      if mat[i][j] > mat[i][k]+mat[k][j]:
        print(-1)
        exit()

      if mat[i][j] == mat[i][k]+mat[k][j] and mat[i][k]>0 and mat[k][j]>0:
        d[i][j] = True

ans = 0
for i in range(n):
  for j in range(i+1, n):
    if not d[i][j]:
      ans += mat[i][j]

print(ans)

Measured memory_bytes: 70168
n=int(input())
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[n-1])

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	ll n;
	cin >> n;
	vector<pll> p(n);
	rep(i, n) {
		ll a;
		cin >> a;
		p[i] = pll(a, i + 1);
	}
	sort(p.begin(), p.end(), greater<pll>());

	vector<vll> dp(n + 1, vll(n + 1));
	rep(i, n) {
		ll a = p[i].first;
		ll x = p[i].second;
		for(int l = 0; l <= i; l++) {
			int r = i - l;
			chmax(dp[l + 1][r], dp[l][r] + a * abs(x - l - 1));
			chmax(dp[l][r + 1], dp[l][r] + a * abs(n - r - x));
		}
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++) chmax(ans, dp[i][n - i]);
	cout << ans << endl;
}


Measured memory_bytes: 34676
package main

import (
	"fmt"
)

var n, m, q int
var abcd [][]int
var arrs [][]int
var memo map[int]map[string]bool = map[int]map[string]bool{}

func main() {
	fmt.Scan(&n, &m, &q)
	create(1, []int{})
	ans := 0
	abcd = make([][]int, q)
	for i := 0; i < q; i++ {
		abcd[i] = make([]int, 4)
		fmt.Scan(&abcd[i][0], &abcd[i][1], &abcd[i][2], &abcd[i][3])
	}
	for _, arr := range arrs {
		score := 0
		for _, seq := range abcd {
			if arr[seq[1]-1]-arr[seq[0]-1] == seq[2] {
				score += seq[3]
			}
		}
		if score > ans {
			ans = score
		}
	}
	fmt.Println(ans)
}

func create(i int, arr []int) {
	if memo[i][fmt.Sprintf("%v", arr)] {
		return
	}
	if len(arr) == n {
		arrs = append(arrs, arr)
		return
	}
	if i > m {
		return
	}
	if memo[i] == nil {
		memo[i] = map[string]bool{}
	}
	memo[i][fmt.Sprintf("%v", arr)] = true
	create(i+1, append([]int{}, arr...))
	create(i+1, append(arr, i))
	create(i, append(arr, i))
}


Measured memory_bytes: 48472
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  string S; cin >> S;
  int c0 = 0, c1 = 0;
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == '0') ++c0;
    else             ++c1;
  }
  cout << min(c0, c1) * 2 << endl;
}


Measured memory_bytes: 3728
#include<iostream>

using namespace std;

int main(){
	char S[200000];
	cin >> S;
	int first, last;
	for(int i = 0; i < 200000; i++){
		if(S[i] == 'A'){
			first = i;
			break;
		}
	}
	for(int i = 200000 - 1; i >= 0; i--){
		if(S[i] == 'Z'){
			last = i;
			break;
		}
	}
	cout << last - first + 1 << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    int i,x[N], min=2000,max= 0;
    for(i=0; i<N; i++){
        scanf("%d", &x[i]);
        if(min > x[i])min = x[i];
        if(max < x[i])max = x[i];
    }
    printf("%d\n", (int)((float)(min+max)/2 - min + 0.5));
    return 0;
}



Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
左から
*/

ll n,b[110],a[110]={},ans=0;

void init(){
	cin>>n;
	rep(i,n-1)cin>>b[i];
}

int main(void){
	init();
	a[0]=b[0];
	reg(i,1,n-2){
		a[i]=min(b[i-1],b[i]);
	}
	a[n-1]=b[n-2];
	rep(i,n)ans+=a[i];
	// rep(i,n)cerr<<a[i]<<" ";
	// cerr<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <valarray>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstring>
#include <sstream>
using namespace std;
 
#define REP(i,n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-9;
 
struct P {
  int  y, x;
  int f;
  int S;
  P(int y, int x, int f, int S) : y(y),x(x),f(f),S(S) {}
};
 
char ba[50][50];
char ms[10][50][50];
int dist[50][50][2][1<<10];
 
int main() {
  int w, h;
  cin >> w >> h;
  int sx,sy;
  int gx,gy;
  REP(i,h) {
    REP(j,w) {
      cin >> ba[i][j];
      if (ba[i][j] == '%') {
        sy = i; sx = j;
      } else if (ba[i][j] == '&') {
        gy = i, gx = j;
      }
    }
  }
  int m;
  cin >> m;
  REP(k,m) {
    REP(i,h) {
      REP(j,w) {
        cin >> ms[k][i][j];
      }
    }
  }
  queue<P> Q;
  memset(dist,-1,sizeof(dist));
  Q.push(P(sy,sx,0,0));
  dist[sy][sx][0][0] = 0;
  const int dy[] = {-1,0,1,0};
  const int dx[] = {0,1,0,-1};
  int ans = -1;
  while(!Q.empty()) {
    P p = Q.front(); Q.pop();
    int d = dist[p.y][p.x][p.f][p.S];
    int y = p.y;
    int x = p.x;
    int S = p.S;
    bool f = p.f;
 
    // // cout << x << " " << y << " " << f << " " << bitset<2>(S) << "  " << d << end
    //   l;
     
    if (ba[y][x] == '&') {
      ans = d;
      break;
    }
     
    REP(k,4) {
      int yy = p.y + dy[k];
      int xx = p.x + dx[k];
      if (yy<0||yy>=h||xx<0||xx>=w) continue;
      // if (yy==5 && xx==1) {
      //   cout << "!!!!!!!!!!!!!" << endl;
      //   cout << ba[yy][xx] << endl;
      // }
      if (ba[yy][xx] == '#') continue;
      bool ff;
      if (ba[yy][xx] == '^') ff = 1;
      if (ba[yy][xx] == '_') ff = 0;
      if (islower(ba[yy][xx])) ff = 0;
      if (isupper(ba[yy][xx])) ff = 1;
      if (ba[yy][xx] == '&' || ba[yy][xx] == '%') ff = 0;
       
      REP(i,m) {
        if (S>>i&1) {
          if (ms[i][yy][xx] == '*') ff ^= 1;
        }
      }
      // if (yy==5 && xx==1 && ba[yy][xx] == 'B') {
      //   cout << "!!!!!!!" << ff << " " << f << " " << x << " " << y << endl;
      // }
 
      if (ba[yy][xx] != '|' && ff != f) continue;
 
      if (dist[yy][xx][p.f][p.S] == -1) {
        dist[yy][xx][p.f][p.S] = d+1;
        Q.push(P(yy,xx,p.f,p.S));
      }
    }
    if (isalpha(ba[y][x])) {
      int k;
      if (islower(ba[y][x])) {
        k = ba[y][x] - 'a';
      } else {
        k = ba[y][x] - 'A';
      }
      bool ff = f;
      if (ms[k][y][x] == '*') {
        ff ^= 1;
      }
 
      int T = S ^ (1<<k);
      if (dist[y][x][ff][T] == -1) {
        dist[y][x][ff][T] = d+1;
        Q.push(P(y,x,ff,T));
      }
    }
    if (ba[y][x] == '|') {
      bool ff = f^1;
      if (dist[y][x][ff][S] == -1) {
        dist[y][x][ff][S] = d+1;
        Q.push(P(y,x,ff,S));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 21860
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
    int num;
    int max = 0,min = 0;
    long long sum = 0;

    cin >> num;

    if((num > 10000) &&
       (num <= 0))
    {
        return 0;
    }

    int *a = new int[num];

    if(a != NULL)
    {
    for(int i = 0; i < num; i++)
    {
        cin >> a[i];
        if((a[i] <= 1000000) &&
           (a[i] >= -1000000) )
        {   
        sum += (long long) a[i];
        if(i == 0)
        {
            max = a[i];
            min = a[i];
        }
        else if(max < a[i])
        {
            max = a[i];
        }
        else if(min > a[i])
        {
            min = a[i];
        }
        }
    }
    cout << fixed << setprecision(11) << min << " " << max << " " << sum << endl;

    delete a;
    }
    return 0;
}


Measured memory_bytes: 3132
<?php

$input = trim(fgets(STDIN),"\r\n");
$lines = explode(' ', $input);

$width = $lines[0];
$height = $lines[1];
$circle_x = $lines[2];
$circle_y = $lines[3];
$circle_r = $lines[4];

if( ($circle_x+$circle_r) > $width || ($circle_x-$circle_r) < 0 || ($circle_y+$circle_r > $height) || ($circle_y-$circle_r) < 0)
	echo "No\n";
else
	echo "Yes\n";

Measured memory_bytes: 6552