akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;



int main(int argc, char* argv[])
{
    int m, k;
    scanf("%d%d", &m, &k);

    int mm=1;
    int i;
    for(i=0; i<m; i++) {
        mm*=2;
    }
    if(k>=mm) {
        printf("-1\n"); return 0;
    }
    if(m==1) {
        if(k==1) {
            printf("-1\n"); return 0;
        }
        else {
            printf("0 0 1 1\n"); return 0;
        }
    }

    for(i=0; i<mm; i++) {
        if(i!=k) printf("%d ", i);
    }
    printf("%d ", k);
    for(i=mm-1; i>=0; i--) {
        if(i!=k) printf("%d ", i);
    }
    printf("%d\n", k);

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1);

    rep(i,n){
        int num=i+1;
        while(num<=n){
            a[num]++;
            num+=(i+1);
        }
    }

    ll sum=0;
    rep(i,n){
        ll tmp=i+1;
        sum+=a[i+1]*tmp;
    }
    cout << sum<<endl;
    return 0;
}


Measured memory_bytes: 81404
A, B = [int(i) for i in input().split()]
#print('A=',A)
#print('B=',B)

num_power_strip = 0
num = 1

while num < B:
    num_power_strip += 1
    num += A - 1
#    print(num_power_strip)
#    print(num)

print(num_power_strip)

Measured memory_bytes: 2940
A = input()
if A[0] == "A":
    B = A[2: -1]
    C = B.count("C")
    if C == 1:
        D = A.replace("A", "").replace("C", "")
        E = D.islower()
        if E == 1:
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")

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

int main() {
  int64_t n, k;
  cin >> n >> k;
  int64_t min = n;

  if (n > k) {
    n = n % k;
  }

  for (int i = 0; i < 100000000; i++) {
    n = abs(n - k);
    if (n < min) {
      min = n;
    }
  }

  cout << min << endl;
}

Measured memory_bytes: 256
'use strict'
function main(input) {
    input = input.split('\n')
    const troops = input[1].split('')
    const n = Number(input[0])
    let countsW = [0]
    for (let i = 1; i <= n; i++) {
        countsW[i] = (troops[i - 1] == 'W') ? countsW[i - 1] + 1 : countsW[i - 1];
    }
    let min, cnt = 0
    for (let i = 0; i < n; i++) {
        cnt = parseInt(countsW[i])
        cnt += n - (i + 1) - (countsW[n] - countsW[i + 1])
        min = (min < cnt) ? min : cnt
    }
    console.log(min)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    vector<int> cnt(n + 10, 0);
    for (int x = 1; x <= 110; ++x) {
        for (int y = 1; y <= 110; ++y) {
            for (int z = 1; z <= 110; ++z) {
                int s = x * x + y * y + z * z + x * y + y * z + z * x;
                if (s <= n) {
                    cnt[s]++;
                }
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        cout << cnt[i] << endl;
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
typedef long long ll;
void rd(int& n){cin>>n;}
void print(ll n){cout<<n<<endl;}
namespace Dinic {
    const int N = 1e4 + 7, M = 2e5 + 7;
    const ll inf = 1e18;
    int n, m, S, T, h[N], hi[N], e[M], t[M], tot = 1, d[N];
    ll mxf, f[M];
    inline void add(int x, int y, ll z, int o = 1) {
        e[++tot] = y, f[tot] = z, t[tot] = h[x], h[x] = tot;
        if (o) add(y, x, 0, 0);
    }
    inline bool bfs() {
        for (int i = 1; i <= n; i++) d[i] = 0;
        queue<int> q;
        q.push(S), d[S] = 1;
        while (q.size()) {
            int x = q.front();
            q.pop();
            for (int i = h[x]; i; i = t[i]) {
                int y = e[i];
                ll z = f[i];
                if (d[y] || !z) continue;
                q.push(y), d[y] = d[x] + 1;
                if (y == T) return 1;
            }
        }
        return 0;
    }
    ll dinic(int x, ll nwf) {
        if (x == T) return nwf;
        ll rst = nwf;
        for (int &i = hi[x]; i && rst; i = t[i]) {
            int y = e[i];
            ll z = f[i];
            if (d[y] != d[x] + 1 || !z) continue;
            ll k = dinic(y, min(z, rst));
            if (!k) d[y] = 0;
            else f[i] -= k, f[i^1] += k, rst -= k;
        }
        return nwf - rst;
    }
    inline void main() {
        while (bfs()) {
            for (int i = 1; i <= n; i++) hi[i] = h[i];
            ll now;
            while ((now = dinic(S, inf))) mxf += now; 
        }
    }
}

int main() {
    rd(Dinic::n), rd(Dinic::m), Dinic::S=1, Dinic::T=Dinic::n;
    for (int i = 1, x, y, z; i <= Dinic::m; i++)
        rd(x), rd(y), rd(z),x++,y++, Dinic::add(x, y, z);
    Dinic::main();
    print(Dinic::mxf);
    return 0;
}



Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e18
typedef long long ll;
typedef pair<ll,ll> P;



unsigned long long popCount64bitB(unsigned long long x) 
{ 
    x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) 
      +  (x & 0x5555555555555555UL); 
    x = ((x & 0xccccccccccccccccUL) >> 2) 
      +  (x & 0x3333333333333333UL); 
    x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) 
      +  (x & 0x0f0f0f0f0f0f0f0fUL); 
    x = ((x & 0xff00ff00ff00ff00UL) >> 8) 
      +  (x & 0x00ff00ff00ff00ffUL); 
    x = ((x & 0xffff0000ffff0000UL) >> 16) 
      +  (x & 0x0000ffff0000ffffUL); 
    x = ((x & 0xffffffff00000000UL) >> 32) 
      +  (x & 0x00000000ffffffffUL); 
    return x; 
} 

int main(void){
    ll n;
    cin>>n;
    if(n==1)cout<<0<<endl;
    else{
        cout<<n*(n-1)/2<<endl;
    }
	return 0; 
}

Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);int[] a=new int[101];for(int t,i,j,x,c;(t=s.nextInt())>0;System.out.println(c)){for(i=c=0;i<t;++i)a[i]=s.nextInt();for(i=t;i-->0;)for(j=0;j<i;++j)if(a[j]>a[j+1]){x=a[j];a[j]=a[j+1];a[j+1]=x;++c;}}}}

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

int main() {
    int64_t n, k;
    cin >> n >> k;

    vector<int64_t> h(n, 0);
    for(int i = 0; i < n; i++) cin >> h[i];
    sort(h.rbegin(), h.rend());

    int64_t ans = 0;
    for(int i = k; i < n; i++) {
        ans += h[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

#define REP(i,n) for(i=0;i<n;i++)

int gcd(int a,int b);

int main(void)
{
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<9&&b<9) printf("Yay!");
  else printf(":(");
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i] << " ";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int ans = 0;
int n,m,k;
int a[10],b[10];
char arr[10][10];
bool check(vector<int>&x,vector<int>&y,int res){
	for(int i = 0 ; i < x.size() ; i++){
		res-=a[x[i]];
	}
	for(int i = 0 ; i < y.size() ; i++){
		res-=b[y[i]];
	}
	for(int i = 0 ; i < x.size() ; i++){
		for(int j = 0 ; j < y.size() ; j++){
			if(arr[x[i]][y[j]]=='#'){
				res++;
			}
		}
	}
	return res==k;
}
int32_t main()
{
	cin >> n >> m >> k;
	char ch;
	int count = 0;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			cin >> arr[i][j];
			if(arr[i][j]=='#'){
				count++;
				a[i]++;
				b[j]++;
			}
		}
	}
	vector<vector<int>>v1,v2;
	vector<int>res;
	for(int i = 0 ; i < (1 << n) ; i++){
		for(int j = 0 ; j < n ; j++){
			if(i & (1<<j)){
				res.push_back(j);
			}
		}
		v1.push_back(res);
		res.clear();
	}
	res.clear();
	for(int i = 0 ; i < (1 << m) ; i++){
		for(int j = 0 ; j < m ; j++){
			if(i & (1<<j)){
				res.push_back(j);
			}
		}
		v2.push_back(res);
		res.clear();
	}
	int x = count;
	for(int i = 0 ; i < v1.size() ; i++){
		for(int j = 0 ; j < v2.size(); j++){
			if(check(v1[i],v2[j],x)){
				ans++;
			}
		}
	}
	cout << ans;
	
}


Measured memory_bytes: 3632
#!ruby -na
f=->n,m,a,b{a/m*n*~-n/2+(b-=m*y=(b+n*a%=m)/m
y>0?f[y,a,m,b%a]+y*=n+b/a:0)}
eval"p f[#{$F*?,}]"if$.>1

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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n) {
    rep(j, d) cin >> x.at(i).at(j);
  }
  int ans = 0;
  rep(i,n) {
    for (int j = i + 1; j < n; j++) {
      int norm = 0;
      rep(k, d) {
        int diff = abs(x.at(i).at(k) - x.at(j).at(k));
        norm += diff * diff;
      }
      bool b = false;
      for(int k = 0; k <= norm; k++) {
        if (norm == k * k) b = true;
      }
      if (b == true) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>

string S,T,U;
int A,B;
int main(){
    cin>>S>>T>>A>>B>>U;
    if(S==U)A--;
    if(T==U)B--;
    cout<<A<<" "<<B;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
for i in range(n):
    b = list(map(int, input().split()))
    c_r = [-1]
    c_l = [-1]
    for j in range(10):
        if c_r[-1] < b[j]:
            c_r.append(b[j])
        elif c_l[-1] < b[j]:
            c_l.append(b[j])
        else:
            print("NO")
            break
    else:
        print("YES")



Measured memory_bytes: 5592
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, team[101] = { 0 }, name[100] , a, b, c, d, hoz, iya;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		name[i]=1;
	for (int i = 1; i <= n*(n - 1) / 2; i++)
	{
		cin >> a >> b >> c >> d;
		if (c > d)
			team[a] += 3;
		else if (c == d)
		{
			team[a]++;
			team[b]++;
		}
		else
			team[b] += 3;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (team[i] < team[j])
			{
				name[i]++;

			}
			
		}
	}
	for (int i = 1; i <= n; i++)
		cout << name[i] << endl;
	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

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

  int N, K, S;
  cin >> N >> K >> S;
  if(K == 0){
    if(S != 1000000000){
      rep(i, N){
        cout << S+1 << ' ';
      }
      cout << endl;
    }
    else{
      rep(i, N){
        cout << 1 << ' ';
      }
      cout << endl;
    }
  }
  else{
    for(int i=0;i<K;i++){
      cout << S << ' ';
    }
    if(S != 1000000000){
      for(int i=0;i<N-K;i++){
        cout << S+1 << ' ';
      }
      cout << endl;
    }
    else{
      for(int i=0;i<N-K;i++){
        cout << 1 << ' ';
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1280
#include <atcoder/dsu>
#include <iostream>

using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    cin >>n >> q;
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3900
program main;
var N, a, b : integer;
    x : real;
begin
	read(N);
    x := N / 100;
    a := trunc(x) * 100;
    b := trunc((N - a) / 10) * 10;
    if trunc(x) = 7
    then writeln('Yes')
    else if trunc((N - a) / 10) = 7
        then writeln('Yes')
        else if (N - a - b) = 7
            then writeln('Yes')
            else writeln('No');
end.

Measured memory_bytes: 1324
#!/usr/bin/env python3
import sys


def solve(a: int, b: int, c: int):
    print(a + b + c - max(a, b, c))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define ll long long
#define MAX 1000003
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
	IOS;
	int n; cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(all(a));
	cout<<(a[n/2]-a[n/2-1])<<endl;
return 0;
}

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

using graph = vector<vector<int>>;

vector<int> topological_sort(const graph& g) {
	const int n = g.size();
	vector<int> in(n), st, res;
	for (int i = 0; i < n; ++i) for (auto to : g[i]) ++in[to];
	for (int i = 0; i < n; ++i) if (in[i] == 0) st.push_back(i);
	while (!st.empty()) {
		int v = st.back(); st.pop_back();
		res.push_back(v);
		for (auto to : g[v]) {
			--in[to];
			if (in[to] == 0) st.push_back(to);
		}
	}
	assert(count(in.begin(), in.end(), 0) == n);
	return res;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	graph G(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
	}
	auto ids = topological_sort(G);
	for (auto id : ids) {
		printf("%d\n", id);
	}
	return 0;
}



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

int main()
{
    int N,K;
    cin >> N>>K;
    int ans =0;
    for (int i =0;i<N;i++){
        int hh = 0;
        cin >> hh;
        if (hh<K)continue;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    count = 0
    for i in range(N):
        count += min(A[i], B[i])
        if A[i] < B[i]:
            b = B[i] - A[i]
            count += min(A[i + 1], b)
            A[i + 1] = max(0, A[i + 1] - b)
    print(count)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main(){
  int h,w;
  cin >> h >> w;
  vs d(h);
  int cnt = 0;
  rep(i,h){
    cin >> d.at(i);
    rep(j,w){
      cnt += (d.at(i).at(j) == '.');
    }
  }
  queue<pii> que;
  que.push(pii(0,0));
  vector<vl> dist(h, vl(w, -1));
  dist.at(0).at(0) = 0;
  while(que.size()){
    pii P = que.front();
    que.pop();
    rep(i,4){
      int nx,ny;
      nx = P.first + dx[i];
      ny = P.second + dy[i];
      if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if(d.at(nx).at(ny) == '#') continue;
      if(dist.at(nx).at(ny) == -1){
        dist.at(nx).at(ny) = dist.at(P.first).at(P.second) + 1;
        que.push(pii(nx,ny));
      }
    }
  }
  if(dist.at(h-1).at(w-1) == -1) cout << -1 << endl;
  else{
    cout << cnt - (dist.at(h-1).at(w-1) + 1) << endl;
  }
}



Measured memory_bytes: 3624
#include<iostream>
#include<cctype>
#include<string>
using namespace std;

string Toupper(string s){
    string t = s;
    for(int i=0; i<s.size(); i++){
        t[i] =toupper(s[i]);
        
    }
    return t;
}

int main(){
    
    string W, T;
    
    cin >> W;
    
    W = Toupper(W);
    
    int count = 0;
    while(1){
        cin >> T;
        if( T == "END_OF_TEXT") break;
        
        T = Toupper(T);
        
        if(W == T){
            count += 1;
        }
        
    }
    
    cout << count << endl;
    
    return 0;
    
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int a,b,c,k;std::cin>>a>>b>>c>>k;
    int p=1;
    for(int i=0;i<k;i++)p*=2;
    std::cout<<(a+b+c+(p-1)*std::max({a,b,c}))<<std::endl;
}

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

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

    vector<pair<int, long>> vec;
    int n;
    while (cin >> n && n > 0) {
        for (int i = 0; i < n; i++) {
            int id;
            long p, q;
            cin >> id >> p >> q;

            auto pre = find_if(
                vec.begin(), vec.end(),
                [&](const pair<int, long> &tar) { return tar.first == id; });
            if (pre != vec.end())
                pre->second += p * q;
            else
                vec.push_back(make_pair(id, p * q));
        }
        int count = 0;
        for (auto v : vec) {
            if (v.second >= 1000000) {
                cout << v.first << endl;
                count++;
            }
        }
        if (count == 0) cout << "NA" << endl;
        vec.clear();
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3124
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#define ll long long
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
using namespace std;

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[2] - a[0]<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class E
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	private const int OFFSET = 8000;

	public void Solve()
	{
		var a = GetString();
		var b = GetString();
		var c = GetString();

		var ab = isMatch(a, b);
		var ac = isMatch(a, c);
		var bc = isMatch(b, c);

		int A = a.Length;
		int B = b.Length;
		int C = c.Length;
		int ans = A + B + C;
		for(int i = -4000; i <= 4000; i++)
		{
			for(int j = -4000; j <= 4000; j++)
			{
				if(ab[i + OFFSET] && ac[j + OFFSET] && bc[j - i + OFFSET])
				{
					int l = Min(0, Min(i, j));
					int r = Max(A, Max(i + B, j + C));
					chmin(ref ans, r - l);
				}
			}
		}
		WriteLine(ans);
	}

	private bool[] isMatch(string a, string b)
	{
		var res = new bool[16002];
		for(int i = -8000; i <= 8000; i++)
			res[i + OFFSET] = isMatch(a, b, i);

		return res;
	}

	private bool isMatch(string a, string b, int pos)
	{
		int A = a.Length;
		int B = b.Length;
		for(int i = 0; i < B; i++)
		{
			if(b[i] == '?')
				continue;

			int j = pos + i;
			if(j < 0 || j >= A || a[j] == '?')
				continue;
			
			if(b[i] != a[j])
				return false;
		}
		return true;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x;
    //typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

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

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// nCr mod を計算する O(r)
// modintライブラリ必要
mint choose(int n, int r) {
    mint x = 1, y = 1;
    rep(i,r) {
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    mint ans=f(n);
    ans-=choose(n,a);
    ans-=choose(n,b);
    ans-=1;

    cout << ans.x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF (ll)(1e17+5)
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
ll pal(string s)
{
    string s1=s;
    reverse(s1.begin(),s1.end());
    return s1==s;
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
      string s;
      cin>>s;
      ll n=s.length();
      if(pal(s) && pal(s.substr(0,n/2)) && pal(s.substr((n/2+1),n/2))) 
       cout<<"Yes\n";
      else
       cout<<"No\n"; 
   }
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int, int>
#define pll pair <ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 1e3+5;

char a[L][L];
ll dp[L][L];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll H, W;
    cin >> H >> W;

    for(ll i=1; i<=H; i++)
    {
        for(ll j=1; j<=W; j++)
        {
            cin >> a[i][j];
        }
    }

    ll mod = 1e9+7;

    dp[1][1] = 1;

    for(ll i=0; i<=H; i++)
    {
        for(ll j=0; j<=W; j++)
        {

            if(!i || !j)
            {
                dp[i][j] = 0;
            }

            else
            {
                if(a[i][j]=='.')
                {
                    dp[i][j]+=dp[i][j-1];
                    dp[i][j]%=mod;
                    dp[i][j]+=dp[i-1][j];
                    dp[i][j]%=mod;
                }

                else
                {
                    dp[i][j] = 0;
                }
            }
        }
    }

    cout << dp[H][W] << endl;

    return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
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; }
ll extended_gcd(ll a, ll b, ll &x, ll &y) {
    if (b == 0) { x = 1; y = 0; return a; }
    ll xx, yy;
    ll res = extended_gcd(b, a%b, xx, yy); x = yy; y = xx - yy * (a / b);
    return res;
}

// const ll sz = 1e5 + 5;
// vector<ll> fac(sz, 1);

// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }

// * ALways PASS arrays, strings etc to functions BY REFERENCE

// const ll sz = 1e6 + 6;
// vector<bool> p(sz, true);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    // p[0] = p[1] = false;
    // for (ll i = 2; i*i <= sz; i++) if (p[i]) {
    //     for (ll j = i*i; j <= sz; j += i)
    //         p[j] = false;
    // }
    
    int t = 1;
    // cin >> t;

    while(t--) {
        ll n;
        cin >> n;
        
        if (n <= 1) {
            cout << 0 << endl;
            return 0;
        }
        
        ll res = powmod(10ll, n) % mod;
        res = (res - powmod(9ll, n) + mod) % mod;
        res = (res - powmod(9ll, n) + mod) % mod;
        res = (res + powmod(8ll, n)) % mod;
        
        cout << res << endl;
    }
    
	return 0;
}


Measured memory_bytes: 3636
def main():
    import queue
    import sys
    input = lambda : sys.stdin.readline().rstrip()
    sys.setrecursionlimit(max(1000, 10**9))



    n = int(input())
    minsum = [None] * n # (min, sum)
    for i in range(n):
        tmp = list(map(int, " ".join(input()).replace("(", "1").replace(")", "-1").split()))
        c = 0
        m = 0
        for item in tmp:
            c += item
            m = min(c, m)
        minsum[i] = (m, sum(tmp))
    minsum.sort()

    if sum(item[1] for item in minsum)!=0:
        print("No")
    else:
        minsum1 = [item for item in minsum if item[1]>=0]
        minsum2 = [(item[0]-item[1], -item[1]) for item in minsum if item[1]<0]
        minsum2.sort()
        c = 0
        for m,s in minsum1[::-1]:
            if c+m>=0:
                c += s
            else:
                print("No")
                return
        c = 0
        for m,s in minsum2[::-1]:
            if c+m>=0:
                c+=s
            else:
                print("No")
                return
        print("Yes")
main()

Measured memory_bytes: 174004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll q;
	cin>>q;
	set<ll>ch[26];
	for(ll i=0;i<n;i++){
		ll now=s[i]-'a';
		//cout <<now;
		ch[now].insert(i);
	}
	//cout <<endl;
	for(ll i=0;i<q;i++){
		ll y;
		cin>>y;
		if(y==1){
			ll x;char t;
			cin>>x>>t;
			x--;
			ll now=s[x]-'a';
			ch[now].erase(x);
			ll nex=t-'a';
			ch[nex].insert(x);
			s[x]=t;
			//cout <<s<<endl;
			//cout <<nex<<endl;
		}
		else{
			ll l,r;
			cin>>l>>r;
			l--;r--;
			ll cnt=0;
			for(ll j=0;j<26;j++){
				auto itr1=ch[j].lower_bound(l);
				ll la=*itr1;
				if(itr1==ch[j].end()){
					la=inf;
				}
				if(la<=r){
					cnt++;
				}
			}
			cout <<cnt<<endl;
		}
	}
	// your code goes here
	return 0;
}

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

int main()
{
	int X, Y;
	cin >> X >> Y;

	int ans = 0;
	if( X == 3 )  ans += 100000;
	else if( X == 2 )  ans += 200000;
	else if( X == 1 )  ans += 300000;
	if( Y == 3 )  ans += 100000;
	else if( Y == 2 )  ans += 200000;
	else if( Y == 1 )  ans += 300000;
	if( X == 1 && Y == 1 )  ans += 400000;

	cout << ans << endl;
}


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


int main() {
    vector<int> vec(3);
    for(int i = 0 ;i < vec.size(); i++){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    if(vec[0] == 5 && vec[1] == 5 && vec[2] == 7){
        cout <<  "YES" << endl; 
    }else{
        cout <<  "NO" << endl; 
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            (var points, var roadCount) = IOUtils.Read2Ints();

            var heights = IOUtils.ReadLongs().ToList();

            var roads = IOUtils.ReadIntLines(roadCount).ToList();

            var roadList1 = roads.GroupBy(l => l[0])
                                   .ToDictionary(g => g.Key, g => new HashSet<int>(g.Select(l => l[1])));
            var roadList2 = roads.GroupBy(l => l[1])
                                   .ToDictionary(g => g.Key, g => new HashSet<int>(g.Select(l => l[0])));

            var res = 0;

            for (int p = 1; p <= points; p++)
            {
                if (!roadList1.TryGetValue(p, out HashSet<int> nb1))
                {
                    nb1 = new HashSet<int>();
                }
                if (!roadList2.TryGetValue(p, out HashSet<int> nb2))
                {
                    nb2 = new HashSet<int>();
                }

                foreach (var nb in nb2)
                {
                    nb1.Add(nb);
                }

                if (nb1.Count == 0)
                {
                    res++;
                    continue;
                }
                var max = nb1.Max(n => heights[n - 1]);
                if (max < heights[p - 1])
                {
                    res++;
                }
            }

            Console.WriteLine(res);




            Console.ReadLine(); //TODO kes

        }
    }

    static class IOUtils
    {
        public static (int a, int b) Read2Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1]);
        }
        public static (int a, int b, int c) Read3Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1], vals[2]);
        }
        public static IEnumerable<int[]> ReadIntLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadInts();
            }
        }
        public static IEnumerable<long[]> ReadLongLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadLongs();
            }
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        public static ulong ReadUlong()
        {
            return ulong.Parse(Console.ReadLine());
        }
        public static int[] ReadInts()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        }
        public static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


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

vector<int> cal(int rs, int ls, int posr, int posl, vector<int> N)
{
  if ((rs % 2 == 0 && ls % 2 == 0) || (rs % 2 == 1 && ls % 2 == 1))
  {
    N.at(posl) = (rs + ls) / 2;
    N.at(posr) = (rs + ls) / 2;
  }
  else if (rs > ls)
  {
    if (rs % 2 == 0)
    {
      N.at(posl) = (rs + ls) / 2 + 1;
      N.at(posr) = (rs + ls) / 2;
    }
    else
    {
      N.at(posr) = (rs + ls) / 2 + 1;
      N.at(posl) = (rs + ls) / 2;
    }
  }
  else
  {
    if (ls % 2 == 0)
    {
      N.at(posr) = (rs + ls) / 2 + 1;
      N.at(posl) = (rs + ls) / 2;
    }
    else
    {
      N.at(posl) = (rs + ls) / 2 + 1;
      N.at(posr) = (rs + ls) / 2;
    }
  }
  return N;
}

void print(vector<int> N)
{
  for (int i = 0; i < N.size(); i++)
  {
    if (i == 0)
      cout << N.at(i);
    else
      cout << ' ' << N.at(i);
  }
  cout << endl;
}

int main()
{
  string S;
  cin >> S;
  vector<int> N(S.size(), 0);
  bool prevR = 1;
  int rs = 0, ls = 0, posr, posl;
  for (int i = 0; i < S.size(); i++)
  {
    if (i == S.size() - 1)
    {
      ls++;
      if (S.at(i - 1) == 'R')
      {
        posr = i - 1;
        posl = i;
      }
      N = cal(rs, ls, posr, posl, N);
    }
    else if (prevR && S.at(i) == 'R')
    {
      rs++;
    }
    else if (prevR && S.at(i) == 'L')
    {
      ls++;
      posr = i - 1;
      posl = i;
      prevR = 0;
    }
    else if (!prevR && S.at(i) == 'R')
    {
      N = cal(rs, ls, posr, posl, N);
      rs = 1, ls = 0;
      prevR = 1;
    }
    else if (!prevR && S.at(i) == 'L')
    {
      ls++;
    }
  }
  print(N);
}


Measured memory_bytes: 1400
N    = int(input())
A, B = map(int, input().split())
P    = list(map(int, input().split()))

P.sort()

a = [p for p in P if p <= A]
b = [p for p in P if A + 1 <= p and p <= B]
c = [p for p in P if B + 1 <= p]

print(min(len(a), len(b), len(c)))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>

class BinaryIndexedTree
{
private:
    std::vector<int> vals;
    int n;
public:
    BinaryIndexedTree(int n_)
        : vals(n_, 0), n(n_) { }

    void add(int a, int w)
    {
        for (int x = a; x <= n; x += x & -x) {
            vals[x - 1] += w;
        }
    }

    int sum(int a) const
    {
        int ret = 0;
        for (int x = a; x > 0; x -= x & -x) {
            ret += vals[x - 1];
        }
        return ret;
    }
};

class SnLine
{
private:
    struct ProdRange
    {
        ProdRange() { l = r = 0; }
        ProdRange(int l_, int r_) { l = l_; r = r_; }
        int l, r;
    };

    static ProdRange makeProdRange(int l, int r)
    {
        return ProdRange { l, r };
    }

    std::vector< std::vector<ProdRange> > prList;

    int numProds;
    int numStops;

public:
    SnLine(int numStops_)
    {
        numStops = numStops_;
        numProds = 0;
        prList.resize(numStops);
    }

    void addProdRange(int l, int r)
    {
        int d0 = r - l;
        prList[d0].emplace_back(l, r);
        ++numProds;
    }

    void solve()
    {
        BinaryIndexedTree bit(numStops);
        
        int numRemainingProds = numProds;

        for (int d = 1; d <= numStops; ++d)
        {
            int r = numRemainingProds;

            if (1 < d)
            {
                for (int a = d; a <= numStops; a += d)
                {
                    r += bit.sum(a);
                }
            }

            std::cout << r << std::endl;

            for(const ProdRange& pr : prList[d - 1])
            {
                bit.add(pr.l, 1);
                bit.add(pr.r + 1, -1);
                --numRemainingProds;
            }
        }
    }
};

int main()
{
    int N, M;
    std::cin >> N >> M;

    SnLine sl(M);

    for (int i = 0; i < N; ++i)
    {
        int l, r;
        std::cin >> l >> r;
        sl.addProdRange(l, r);
    }

    sl.solve();
    return 0;
}


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

int main()
{
	double hei ;

	double high = 0 ;
	double low = 0 ;

	while( cin >> hei )
	{
		if( hei > high ) high = hei ;

		if( low == 0 ) low = hei ;
		else
		{
			if( hei < low ) low = hei ;
		}
	}

	high -= low ;
	printf("%.1f\n",high) ;

	return 0 ;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

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

  long long tot = 0;
  int index;
  for (int i = 1; i <= N; i++) {
    tot += i;
    index = i;
    if (tot >= N) break;
  }

  int Exclusion = tot - N;

  for (int i = 1; i <= index; i++) {
    if (i != Exclusion) cout << i << endl;
  }
}


Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll tmp = 1;
    rep(i, N) {
        ll T;
        cin >> T;
        tmp = lcm(tmp, T);
    }
    print(tmp);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};


int main(){
    int r,c,k;cin >> r >> c >> k;
    vector<vector<vector<LL>>> dp(r + 1, vector<vector<LL>> (c + 1, vector<LL> (4, 0)));
    vector<vector<vector<LL>>> s(r + 1, vector<vector<LL>> (c + 1));
    for (int i = 0; i < k; i++) {
        LL a,b,v;cin >> a >> b >> v;
        a--,b--;
        s[a][b].pb(v);
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if(s[i][j].size()) sort(RALL(s[i][j]));
        }
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            for (int x = 0; x < 4; x++) {
                LL a = dp[i][j][x];
                chmax(dp[i][j+1][x], a);
                chmax(dp[i+1][j][0], a);
                for (int l = 0; l < min(4 - x, (int)s[i][j].size()); l++) {
                    if(x+1<4) a += s[i][j][l];
                    chmax(dp[i][j+1][x+l+1], a);
                    chmax(dp[i+1][j][0], a);
                }
            }
        }
    }
    LL ans = dp[r - 1][c][0];
    for (int i = 0; i < 4; i++) {
        chmax(ans, dp[r][c - 1][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 854136
// https://atcoder.jp/contests/arc083/tasks/arc083_b

package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)

	var A = make([][]int, N)

	sum := 0
	for i := 0; i < N; i++ {
		A[i] = make([]int, N)
		for j := 0; j < N; j++ {
			var a int
			fmt.Scanf("%d", &a)
			A[i][j] = a
			sum += a
		}
	}

	dupes := 0
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			if i == k || A[i][k] == 0 {
				continue
			}
			for j := i + 1; j < N; j++ {
				if k == j || A[k][j] == 0 {
					continue
				}
				if A[i][j] > A[i][k]+A[k][j] {
					fmt.Println(-1)
					return
				} else if A[i][j] == A[i][k]+A[k][j] {
					dupes += A[i][j]
					A[i][j] = 0
					A[j][i] = 0
				}
			}
		}
	}

	fmt.Println((sum/2 - dupes))
}


Measured memory_bytes: 4736
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    k = int(input())


    distance = max(a, b, c, d, e) - min(a, b, c, d, e)
    if distance <= k:
        print("Yay!")
    else:
        print(":(")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.util.LinkedList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);

        while (true) {
            final int q = scanner.nextInt();
            final int lim = scanner.nextInt();
            if (q == 0 && lim == 0) {
                break;
            }
            int counter = 0;
            final List<Integer> array = new LinkedList<Integer>();
            for (int i = 0; i < q; i++) {
                final int query = scanner.nextInt();
                final int xi = scanner.nextInt();
                switch (query) {
                    case 0:
                        array.add(xi);
                        counter++;
                        break;
                    case 1:
                        array.remove(xi - 1);
                        counter--;
                        break;
                    case 2:
                        System.out.println(array.get(xi - 1));
                        break;
                    case 3:
                        array.remove(Integer.valueOf(xi));
                        counter--;
                        break;
                }
                if (counter > lim) {
                    array.remove(0);
                    counter--;
                }
            }
            System.out.println("end");
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 17000
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  ll sum = 0;
  sort(RALL(A));
  int count = 0;
  rep(i,N-1)
  {
    if(i==0) sum += A[0];
    else
    {
      if(i%2==0)
      {
        sum += A[i/2];
      }
      else
      {
        sum += A[i/2+1];
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4840
def actual(N, M, X, A):
    # マスXの左右それぞれにある料金所の数を調べればOK
    toll_gates_left = [a_i for a_i in A if a_i < X]
    toll_gates_right = [a_i for a_i in A if X < a_i]

    return min(len(toll_gates_left), len(toll_gates_right))

N, M, X = map(int, input().split())
A = list(map(int, input().split()))

print(actual(N, M, X, A))


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
using namespace std;
 
int main(){
    int n;
    cin>>n;
    rep(i,0,n){
        int ans=0;
        double x1,y1,x2,y2,x3,y3,x4,y4,m1,m2;
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        if(x1==x2||x3==x4){
            if(x1==x2&&x3==x4) ans=1;
        }else{
            m1=(y2-y1)/(x2-x1);
            m2=(y4-y3)/(x4-x3);
            if(fabs(m1-m2)<1e-10) ans=1;
        }
        if(ans) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1224
#include<stdlib.h>

int main(void){
  int n;
  scanf("%d", &n);
  int i;
  int num[n];
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
  }
  int j,k;
  int p1=0;
  int p2=0;
  int dif[n];
  int min = 1000000000;
  for(i=0;i<n-1;i++){
    for(j=0;j<i+1;j++){
      p1+=num[j];
    }
    //printf("%d番目のp1:%d",i,p1);
    for(k=i+1;k<n;k++){
      p2+=num[k];
    }
    //printf("%d番目のp2:%d",i,p2);
    dif[i]=abs(p1-p2);
    //printf("%d番目のdif:%d",i,dif[i]);
    if(dif[i]<min){
      min = dif[i];
    }
    p1=0;
    p2=0;
  }
  printf("%d",min);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI=2147483647;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int x; cin >>x;
  cout <<x*x*x <<endl;
}



Measured memory_bytes: 3112