akhauriyash/Code-Regression huggingface dataset:
//abc076_d.cpp
//Sun Jul 29 10:19:29 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INF 100000000
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	double st[n+2],et[n+2];
	double v[n+2];
	st[0] = 0;
	et[0] = 0;
	v[0] = 0;

	double totaltime = 0;
	for (int i=1;i<=n;i++){
		st[i] = et[i-1];
		double tempt;
		cin >> tempt;
		et[i] = et[i-1]+tempt;
		totaltime += tempt;
	}
	
	for (int i=1;i<=n;i++){
		cin >> v[i];
	}

	st[n+1] = totaltime;
	et[n+1] = totaltime;
	v[n+1] = 0;

	double curtime = 0.5;
	double curv = 0;
	double ans = 0;
	while (curtime <= totaltime){
		double minv = INF;
		for (int i=0;i<n+2;i++){
			double tempv = 0;
			if (curtime <= st[i]){
				tempv = v[i]+st[i]-curtime;
			}else if (curtime <= et[i]){
				tempv = v[i];
			}else {
				tempv = v[i]+curtime-et[i];
			}
			if (tempv < minv){
				minv = tempv;
			}
		}
		ans += 0.25*(curv+minv);
		curv = minv;
		curtime += 0.5;
	}

	printf("%.4f",ans);
}

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

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {}
    int root(int x) {
        if(par[x] < 0) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }
    int issame(int x, int y) { return root(x) == root(y); }
    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(-par[x] < -par[y]) {
            swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
    }
};
// http://drken1215.hatenablog.com/entry/2019/02/14/124300
int main() {
    int N;
    cin >> N;
    vector<long long> x(N), y(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    using pint = pair<int, int>;
    using Edge = pair<long long, pint>;
    vector<Edge> edges;
    // x軸にソートして隣接している部分のみ
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
    for(int i = 0; i + 1 < ids.size(); i++) {
        int u = ids[i];
        int v = ids[i + 1];
        edges.push_back(Edge(x[v] - x[u], pint(u, v)));
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
    for(int i = 0; i + 1 < ids.size(); ++i) {
        int u = ids[i], v = ids[i + 1];
        edges.push_back(Edge(y[v] - y[u], pint(u, v)));
    }
    //ここまでで辺を作る
    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    long long res = 0;
    for(auto e : edges) {
        int u = e.second.first;
        int v = e.second.second;
        long long cost = e.first;
        if(uf.issame(u, v)) {
            continue;
        }
        uf.merge(u, v);
        res += cost;
    }
    cout << res << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> wa(N + 5, 0);
    for (int i = 0; i < M; i++) {
        int p;
        string s;
        cin >> p >> s;
        if (wa[p] >= 0 && s == "WA") wa[p]++;
        else if (wa[p] >= 0 && s == "AC") wa[p] = wa[p] * (-1) - 1;
    }
    int ac = 0, penalty = 0;
    for (auto a: wa){
        if (a < 0) {
            penalty += (a + 1) * (-1);
            ac++;
        }
    }
    cout << ac << " " << penalty << endl;
    return 0;
}

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


const int INF=1000000;
int x[100005];

int main() {
  int n,m; cin>>n>>m;
  rep(i, m) {
    int p;
    string S;
    cin>>p>>S;
    if (x[p]>=INF) continue;
    if (S[0]=='A') x[p]+=INF;
    else x[p]++;
  }
  int AC=0;
  int WA=0;
  rep(i, 100005) {
    if (x[i]>=INF) {
      AC++;
      WA+=(x[i]-INF);
    }
  }
  cout<<AC<<" "<<WA<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int a =-1;
  int i=1;
  while(true){
    scanf("%d", &a);
    if(a==0)
      break;
    cout << "Case " << i << ": " << a << endl;
    i++;
  }
}

Measured memory_bytes: 1208
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>


using namespace std;

using ll = long long int;
using lln = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()
const long MOD = pow(10, 9) + 7;

char alfa[] = { 'A','B' ,'C','D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y','Z' };

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

unsigned GetDigit(double num) {
	return log10(num) + 1;
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

class Mod {
public:
	static inline ll Add(ll a, ll b) {
		return (a + b) % MOD;
	}

	static inline ll Sub(ll a, ll b) {
		ll ans = (a - b) % MOD;
		return (ans < 0) ? (ans + MOD) : ans;
	}

	static inline ll Mul(ll a, ll b) {
		return (a * b) % MOD;
	}

	static inline ll Div(ll a, ll b) {
		return (a % MOD) * modinv(b, MOD) % MOD;
	}
};



template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

class man
{
public:
	int A;
	vector<pii> X;
	bool HeIsTrue;
private:

};

inline void Main() {
	ll X, Y, N;
	vector<ll> A;
	ll M1, D1, M2, D2;
	ll ans;
	ll sum = 0, count = 0,a =0;
	string S;
	string T;
	string Ans = "";
	int b[60];
	bool flag = false;

	cin >> N>>S;

	for (ll i = 0; i < N; i++) {
		if (S[i] == 'A' + a) {
			a++;
		}
		else {
			a = 0;
		}

		if (S[i] == 'A' + a) {
			a++;
		}

		if (a == 3) {
			count++;
			a = 0;
		}
	}

	cout << count;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;


#define MAX 500000
#define SENTINEL 2000000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2


int main(){
  string s;
  cin >> s;
  int cnt=0;
  for (int i=0; i<3; i++){
    if (s[i] == '1') cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

int main(void){
	int n, num;
	bool card[4][13] = {};
	char pattern;

	cin >> n;

	for (int i = 0; i<n; i++){
		cin >> pattern >> num;

		switch (pattern){
		case 'S':card[0][num - 1] = true; break;
		case 'H':card[1][num - 1] = true; break;
		case 'C':card[2][num - 1] = true; break;
		case 'D':card[3][num - 1] = true; break;
		}
	}

	for (int i = 0; i < 4; i++){
		for (int  j = 0; j < 13; j++){
			if (!card[i][j]){
				switch (i){
				case 0:cout << "S " << j + 1 << "\n"; break;
				case 1:cout << "H " << j + 1 << "\n"; break;
				case 2:cout << "C " << j + 1 << "\n"; break;
				case 3:cout << "D " << j + 1 << "\n"; break;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-7;
using namespace std;
int main()
{
	int k;
	scanf("%d",&k);
	if(k<=12)
	{
		printf("%d\n",k);return 0;
	}
	int a[maxn]={2,2,1};
	k-=12;
	for(int i=1;i<=k;i++)
	{
		int juu=1;
		for(int j=1;j<a[0];j++)
		{
			if(a[j]==a[j+1]&&a[j]==9)
			{
				juu++;continue;
			}
			if(a[j]>a[j+1])
			{
				juu++;continue;
			}
			a[j]=a[j]+1;
			for(int jj=j-1;jj>=1;jj--)a[jj]=max(0,a[jj+1]-1);break;
		}
		if(juu==a[0])
		{
			if(a[a[0]]==9)
			{
				a[0]++;
				a[a[0]]=1;
				for(int j=a[0]-1;j>=1;j--)a[j]=0;
			}
			else
			{
				a[a[0]]++;
				for(int jj=a[0]-1;jj>=1;jj--)a[jj]=max(0,a[jj+1]-1);
			}
		}
	}
	for(int i=a[0];i>=1;i--)printf("%d",a[i]);puts("");
}

Measured memory_bytes: 1024
def main():
    N = int(input())
    P = []
    M = []
    for i in range(N):
        s = input()
        left = 0
        right = 0
        rightmax = 0
        for c in s:
            if c == "(":
                left += 1
            else:
                right += 1
            rightmax = max(rightmax, right - left)
        leftdiff = left-right
        if leftdiff >= 0:
            P.append((leftdiff, rightmax, 0, s))
            continue
            
        left = 0
        right = 0
        leftmax = 0
        for c in reversed(s):
            if c == "(":
                left += 1
            else:
                right += 1
            leftmax = max(leftmax, left - right)
        M.append((leftdiff, 0, leftmax, s))

    R = []
    for e in sorted(P, key=lambda _e: _e[1]):
        R.append(e[3])
    for e in sorted(M, key=lambda _e: _e[2], reverse=True):
        R.append(e[3])

    nleft = 0
    for c in "".join(R):
        if c == "(":
            nleft += 1
        else:
            nleft -= 1
        if nleft < 0:
            print("No")
            return
        
    if nleft == 0:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 306468
N = readline.to_i
A = readline.split(' ').map {|x| x.to_i - 1}
B = readline.split(' ').map(&:to_i)
C = readline.split(' ').map(&:to_i)

ans = 0
prev = -2
A.each do |a|
  ans += B[a]
  ans += C[prev] if prev == a-1
  prev = a
end
puts ans



Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

void chmin(int64_t& a, int64_t b) {
	if (a > b) a = b;
}

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

	vector<int64_t> S(A), T(B);
	for (int i = 0; i < A; i++) cin >> S[i];
	for (int i = 0; i < B; i++) cin >> T[i];

	for (int i = 0; i < Q; i++) {
		int64_t x;
		cin >> x;
		//cout << "x:" << x << endl;

		int64_t s_itr, t_itr;
		s_itr = upper_bound(S.begin(), S.end(), x) - S.begin();
		t_itr = upper_bound(T.begin(), T.end(), x) - T.begin();
		if (s_itr == A) s_itr--;
		if (t_itr == B) t_itr--;

		int64_t ans = INT64_MAX;

		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				int64_t s, t;
				s = max((int64_t)0, s_itr - j);
				t = max((int64_t)0, t_itr - k);

				int64_t n, m;
				n = abs(S[s] - x) + abs(S[s] - T[t]);
				m = abs(T[t] - x) + abs(S[s] - T[t]);

				chmin(ans, n);
				chmin(ans, m);
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 4824
# -*- coding: utf-8 -*-
n, d = map(int,input().split())
xy = []
for i in range(n):
    xy.append([int(i) for i in input().split()])

ans = 0
for i in range(n):
    if xy[i][0] ** 2 + xy[i][1] ** 2 <= d ** 2:
        ans += 1
print(ans)


Measured memory_bytes: 42260
L,R = map(int,input().split())

mod = 10**9+7

def f(L,R):
    if L>R : return 0
    R = bin(R)[2:]
    N = len(R)
    ret = f(L,int("0"+"1"*(N-1),2))
    L = bin(L)[2:]
    if len(L) != N : L = "1"+"0"*(N-1)
    for i in range(N):
        if R[i] == "0" : continue
        R2 = R[:i] + "0" + "?"*(N-i-1)
        if i==0: R2 = R
        for j in range(N):
            if j==0 : L2 = L
            elif L[j] == "1" : continue
            else : L2 = L[:j] + "1" + "?"*(N-j-1)

            tmp = 1
            for r,l in zip(R2,L2):
                if r=="0" and l=="1" : tmp *= 0 ; break
                elif r=="?" and l=="?" : tmp = tmp*3%mod
                elif r=="?" and l=="0" : tmp = tmp*2%mod
                elif r=="1" and l=="?" : tmp = tmp*2%mod
            ret += tmp
            ret %= mod
    return ret

print(f(L,R))

Measured memory_bytes: 3064
N = int(input())
SP = [input().split() for _ in range(N)]

lista = []
for i in range(N):
    lista.append((SP[i][0],int(SP[i][1]),i+1))

SP_sorted1 = sorted(lista, key=lambda x:x[1], reverse=True)
SP_sorted2 = sorted(SP_sorted1, key=lambda x:x[0])

for j in SP_sorted2:
    print(j[2])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll h, w;
    cin >> h >> w;

    ll n;
    cin >> n;

    ll a[n];
    rep(i, 0, n){
        cin >> a[i];
    }

    ll x[h][w];
    ll c_a = 0;
    rep(i, 0, h){
        if(i % 2 == 0){
            rep(j, 0, w){
                x[i][j] = c_a + 1;
                a[c_a]--;
                if(a[c_a] == 0){
                    c_a++;
                }
            }
        }else{
            rrep(j, w - 1, 0){
                x[i][j] = c_a + 1;
                a[c_a]--;
                if(a[c_a] == 0){
                    c_a++;
                }
            }
        }
    }

    rep(i, 0, h){
        rep(j, 0, w){
            cout << x[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}


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

#define ll long long
#define lli long long int
#define vec vector
#define que queue
#define st stack
#define str string
#define p_q priority_queue
#define d_q dequeue

#define Pi acos(-1)
//const int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
#define modulo 123456789

#define mod(x) (x % modulo)
#define bool_tog(bool_x) bool_x = !bool_x
#define up_c(c) c -= ((c >= 'a' && c <= 'z') ? 32 : 0)
#define low_c(c) c += ((c >= 'A' && c <= 'Z') ? 32 : 0)

#define fi first
#define se second


int i,j,k,n,m,t,cnt;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    int digit = n % 10;
    switch (digit)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    default:
        break;
    }
    
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}
	long long int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

long long int lcm(long long int a, long long int b) {
	long long int L;
	L = a / gcd(a, b);
	L *= b;
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	for (int i = 2; i * i <= n; i++) {
		;
		if (is_prime.at(i)) {
			for (int j = i * i; j <= n; j += i) {
				is_prime.at(j) = false;
			}
		}
		Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}



int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}


int main() {
	long long int n;
	string s, t;
	cin >> s >> t;
	cout << t + s << endl;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> m >> n;
    cout << n*(n-1)/2+m*(m-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int n;
char a[200005];
int r[200005];
int main() {
	scanf("%d", &n);
	scanf("%s", a);
	if (a[0] == '#')r[0]++;
	for (int i = 1; i < n; i++) {
		r[i] = r[i - 1];
		if (a[i] == '#')r[i]++;
	}
	int ans = n-r[n-1];
	for (int i = 0; i < n; i++) {
		if (ans > r[i] * 2 + n - 1 - i - r[n - 1]) {
			ans = r[i] * 2 + n - 1 - i - r[n - 1];
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1152
using System;

namespace abc148B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            string S = str[0];
            string T = str[1];
            string[] A = new string[N];
            string[] B = new string[N];
            for(int M = 0; M < N; M++)
            {
                A[M] = S.Substring(M, 1);
                B[M] = T.Substring(M, 1);
            }
            string P = "";
            for(int M = 0; M < N; M++)
            {
                P = P + A[M] + B[M];
            }
            Console.WriteLine(P);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define vec vector
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false 
using namespace std;


ll kmm(ll a, ll b) {
	return(a*b) / __gcd(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 1e5+5;
ll modpower(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modpower((x*x)%mod,n/2);
    else
        return (x*modpower((x*x)%mod,(n-1)/2))%mod;

}

ll facpower(ll x){
	if(x==0)
		return 1;
	return ((x%mod)*(facpower(x-1)%mod))%mod;
}

void solve(){
	ll x,y,z;
	cin >> x >> y >> z;
	if(x+y+z>=22)
		cout << "bust";
	else
		cout << "win";
	
	
}

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


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

int main(void){
  int N, M;
  cin >> N >> M;
  if(N>=M) {cout << 0 << endl; return 0;}
  
  int X[M];
  priority_queue<int> d;
  for(int i=0; i<M; i++) cin >> X[i];
  sort(X, X+M);
//  for(int i=0; i<M; i++) cout << X[i] << endl;
  for(int i=0; i<M-1; i++) d.push(X[i+1]-X[i]);
  
  int range = X[M-1] - X[0];
//  cout << range << endl;
  int ans = range;
  for(int i=0; i<N-1; i++) {
    ans -= d.top(); d.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 1276
class Node(object):
    def __init__(self):
        self.left = None
        self.right = None
        self.value = None
        self.parent = None

class Tree(object):
    def __init__(self):
        self.root = None
        self.value_dic = {}
    
    def is_find(self,value):
        if value in self.value_dic:
            return True
        else:
            return False
    
    def find(self,value):
        node = T.root

        while node :
            if value == node.value:
                break
            elif value > node.value:
                node = node.right
            else :
                node = node.left
        return node

def insert(T,z):
    y = None
    x = T.root
    while x != None:
        y = x
        if z.value < x.value:
            x = x.left
        else:
            x = x.right
    
    z.parent = y
    if y == None:
        T.root = z
    elif z.value < y.value:
        y.left = z
    else :
        y.right = z

    T.value_dic[z.value] = 1

def getMinimum(z):
    while z.left != None:
        z = z.left
    return z

def getSuccessor(z):
    if z.right != None:
        return getMinimum(z.right)

    y = z.parent
    while y != None and z == y.right:
        z = y
        y = y.parent
    return y

def delete(T,z):
    # 削除する対象をyとする
    if z.left is None or z.right is None:
        y = z
    else:
        y = getSuccessor(z)

    # 子をxとする
    if y.left != None:
        x = y.left
    else:
        x = y.right
    

    # 子がいる場合
    if x != None:
        x.parent = y.parent
    
    if y.parent is None:
        T.root = x
    elif y.parent.left == y:
        y.parent.left = x
    else:
        y.parent.right = x
    
    if y != z:
        z.value = y.value



# 先行順巡回
def preorder(node):
    if node is None:
        return 
    print(" "+str(node.value),end="")    
    preorder(node.left)
    preorder(node.right)
    
# 中間順巡回 
def inorder(node):
    if node is None:
        return 
    inorder(node.left)
    print(" "+str(node.value),end="")
    inorder(node.right)
    
def print_all_node(root):
    stack = [root]
    while stack:
        node = stack.pop()
        print("p: ",node.parent,"r:",node.right,"l:",node.left)
        if node.left:
            stack.append(node.left)
        if node.right:
            stack.append(node.right)

if __name__ == "__main__":
    n = int(input())
    T = Tree()
    queries = [input().split() for _ in range(n)]
    for query in queries:
        if query[0] == "print":
            #print_all_node(T.root)
            inorder(T.root)
            print("")
            preorder(T.root)
            print("")

        else:
            command,value = query
            if command == "insert":
                node_z = Node()
                node_z.value = int(value)
                insert(T,node_z)
            elif command == "find":
                if T.is_find(int(value)):
                    print("yes")
                else:
                    print("no")
            elif command == "delete":
                node = T.find(int(value))
                if node:
                    T.value_dic.pop(int(value))
                delete(T,node)


Measured memory_bytes: 246552
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

cnt = 0
flag = False

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] == b[k][l]:
                    cnt += 1
        if cnt == m ** 2:
            flag = True
        else:
            cnt = 0

if flag:
    print('Yes')
else:
    print('No')


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

typedef struct node{
    int data;
    node *next;
    node *prev;
};
node *head = NULL, *tail = NULL;

void insertFirst(int data){
    node *newNode = new node();
    newNode->data = data;
    newNode->prev = newNode->next = NULL;
    if(head==NULL){
        head = tail = newNode;
    }
    else{
        head->prev = newNode;
        newNode->next = head;
        head = newNode;
    }
}

void deleteFirst(){
    if(head == NULL) return;
    node *temp = head;
    if(head == tail){
        head = tail = NULL;
    }
    else{
        head = head->next;
        head->prev = NULL;
    }
    free(temp);
}

void deleteLast(){
    if(tail == NULL) return;
    node *temp = tail;
    if(head == tail){
        head = tail = NULL;
    }
    else{
        tail = tail->prev;
        tail->next = NULL;
    }
    free(temp);
}

void deleteX(int val){
    node *traverser = head, *temp = NULL;
    while(traverser != NULL){
        if(traverser->data==val){
            temp = traverser;
            break;
        }
        traverser = traverser->next;
    }
    if(temp != NULL){
        if(temp==head) deleteFirst();
        else if(temp==tail) deleteLast();
        else{
            node *first, *second;
            first = temp->prev;
            second = temp->next;
            first->next = second;
            second->prev = first;
            free(temp);
        }
    }
}

void print(){
    node *traverser = head;
    int flag = 0;
    while(traverser != NULL){
        if(flag) printf(" ");
        else flag = 1;
        printf("%d", traverser->data);
        traverser = traverser->next;
    }
    printf("\n");
}

int main(){
    //FILE *inp = freopen("dli.txt", "r", stdin);
    int n, num;
    char cmd[20];
    scanf("%d\n", &n);
    while(n--){
        scanf("%s", cmd);
        if(strcmp(cmd, "deleteFirst")==0) deleteFirst();
        else if(strcmp(cmd, "deleteLast")==0) deleteLast();
        else {
            scanf("%d\n", &num);
            if(strcmp(cmd, "delete")==0) deleteX(num);
            else if(strcmp(cmd, "insert")==0) insertFirst(num);
        }
    }
    print();
    //fclose(inp);
    return 0;
}



Measured memory_bytes: 34388
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0)->sync_with_stdio(false);
	int n; cin >> n;
	int a[n], s[n];
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		a[i] = x + y;
		s[i] = x - y;
	}
	sort(a, a+n);
	sort(s, s+n);
	cout << max(a[n-1] - a[0], s[n-1] - s[0]) << '\n';
	return 0;
}

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

int main(){
  //配列に格納する必要はない！
  int N;
  string u;
  double x, ans; 
  
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> x >> u;
    if (u == "BTC") x = x * 380000.0;
    ans += x;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,M,X,Y=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]+[X]
y=[int(i) for i in input().split()]+[Y]

x.sort()
y.sort()

#print(x,y)

if x[-1] < y[0]:
    print("No War")
else:
    print("War")




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

typedef long long ll;

template<int MAX_N>
struct rolling_hash {
    ll rh1[MAX_N+1], rh2[MAX_N+1], pow1[MAX_N+1], pow2[MAX_N+2];
    ll B1, B2, M1, M2;
    rolling_hash() {
        B1 = 1009; B2 = 1007; M1 = 1000000007; M2 = 1000000009;
    }
    void init(const string& S) {
        rh1[0] = rh2[0] = 0;
        pow1[0] = pow2[0] = 1;
        for (int j = 0; j < S.size(); ++j) {
            rh1[j+1] = (rh1[j] * B1 % M1 + S[j]) % M1;
            rh2[j+1] = (rh2[j] * B2 % M2 + S[j]) % M2;

            pow1[j+1] = pow1[j] * B1 % M1;
            pow2[j+1] = pow2[j] * B2 % M2;
        }
    }
    pair<ll, ll> get_hash(int l, int r) { // [l, r]
        ll v1 = (rh1[r] - rh1[l] * pow1[r-l] % M1 + M1) % M1;
        ll v2 = (rh2[r] - rh2[l] * pow2[r-l] % M2 + M2) % M2;
        return make_pair(v1, v2);
    }
};

int N, M; string S;
rolling_hash<300000> rh;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M >> S;
    rh.init(S);

    set<pair<ll, ll> > hashes;
    int l = 0, r = 1;
    for (int j = 0; j < M; ++j) {
        string q; cin >> q;
        if (q == "L--") --l;
        if (q == "L++") ++l;
        if (q == "R--") --r;
        if (q == "R++") ++r;
        pair<ll, ll> val = rh.get_hash(l, r);
        hashes.insert(val);
    }
    cout << hashes.size() << endl;
    return 0;
}

Measured memory_bytes: 31332
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == ',') {
            cout << " ";
        } else {
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  for(int i=0; i < N; i++){
      int l, r;
      cin >> l >> r;
      sum +=  r - l + 1;
  }
  cout << sum;
}

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

namespace Tenka1_2019
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string ans = "Yes";
            if ((abc[0] < abc[1] && (abc[1] < abc[2] || abc[0] > abc[2])) || (abc[0] > abc[1] && (abc[1] > abc[2] || abc[2]>abc[0]))) { ans = "No"; }
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

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

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int mojPow(int n)
{
    if(n==0)return 1;
    else if(n % 2==0)
    {
        return mojPow(n/2)*mojPow(n/2);
    }
    else
    {
        return mojPow(n/2)*mojPow(n/2)*10;
    }
}

int main()
{
    int n, m;
    cin>>n>>m;
    bool izasao=false;
    map<int,int> mapa;
    for(int i = 0;i<m;i++)
    {
        int s,c;
        cin>>s>>c;
        if(mapa.find(s)!=mapa.end())
        {
            if(mapa[s]!=c)
            {
                izasao=true;
            }
        }

        else
        {
            mapa[s]=c;
        }
    }

    if(izasao)
    {
        cout<<-1<<'\n';
        return 0;
    }

    for(int i = ((mojPow(n-1)==1)?(0):(mojPow(n-1))); i<mojPow(n);i++)
    {
        string s = to_string(i);
        bool jelIzasao=false;
        for(map<int,int>::iterator it = mapa.begin();it!=mapa.end();++it)
        {
            //cout<<it->fi<<' '<<it->se<<'\n';
            if((it->fi-1>(int)s.size()) || ((s[it->fi-1]-'0')!=it->se))
            {
                jelIzasao=true;
                break;
            }
        }

        if(!jelIzasao)
        {
            cout<<i<<'\n';
            return 0;
        }
    }

    cout<<-1<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, a;
  cin >> n;
  rep(i,n)
  {
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 == 0 || a % 5 == 0) {

      } else {
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
}

Measured memory_bytes: 256
import java.util.*;

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

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

	int D;
	cin >> D;
	
	if (D==25) {
		cout << "Christmas" << endl;
	}	else if (D==24) {
		cout << "Christmas Eve" << endl;
	} 	else if (D==23) {
		cout << "Christmas Eve Eve" << endl;
	}	else if (D==22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

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


int main (){
    int n,m;
    cin >> n >> m;
    vector<ll> cnt(n+1,1);
    Rep(i,m){
        int tmp;
        cin >> tmp;
        cnt[tmp] = 0;
    }
    cnt[0] = 1;
    cnt[1] = (cnt[1] != 0)? 1 : 0;
    Fors(i,2,n){
        cnt[i] = (cnt[i] != 0)? (cnt[i-1]+cnt[i-2])%1000000007 : 0;
    }
    cout << cnt[n] << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <set>

#define MAX_N 100010

using namespace std;

struct uftree {
    int par[MAX_N], rank[MAX_N];
    uftree(int N) {
        for (int i=0; i<N; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]); // 高速化ポイント
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y]) par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    uftree uft(n);
    for (int i=0; i<m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uft.unite(x, y);
    }
    set<int> s;
    for (int i=0; i<n; i++) 
        s.insert(uft.root(i));
    cout << s.size() << '\n';
    return 0;
}


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

using namespace std;

int main(void) {
    int N, C;
    cin >> N >> C;
    vector< vector<int> > D(C, vector<int>(C));
    for(int p=0; p<C; p++) {
        for(int q=0; q<C; q++) {
            cin >> D[p][q];
        }
    }
    vector< vector<int> > num(3, vector<int>(C)); 
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            int c;
            cin >> c;
            num[(i+j+2)%3][c-1]++;
        }
    }

    int64_t ans = INT32_MAX;
    for(int i=0; i<C; i++) {
        for(int j=0; j<C; j++) {
            if(i ==j) continue;
            for(int k=0; k<C; k++) {
                if(i == k || j == k) continue;
                int64_t ans_tmp = 0;
                for(int color=0; color<C; color++) {
                    ans_tmp += D[color][i] * num[0][color];
                    ans_tmp += D[color][j] * num[1][color];
                    ans_tmp += D[color][k] * num[2][color];
                }
                ans = min(ans, ans_tmp);
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define prl(x) cout << (x) << endl

template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {return '"' + s + '"';}
string to_string(char c){return string(1, c);}
string to_string(const char* s) {return to_string((string) s);}
string to_string(bool b){return (b ? "true" : "false");}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p){return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p){return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) res += ", ";
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template<typename T>
string to_string(priority_queue<T>& q){
    priority_queue<T> copy;
    bool first = true;
    string res = "{";
    while(!q.empty()){
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(q.top());
        copy.push(q.top());
        q.pop();
    }

    swap(q, copy);
    res += "}";
    return res;
}

void debug_out() {cerr << endl;}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef _LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main(void){
    string s; ll answer = 0;
    cin >> s;

    // AGC037A
    ll n = s.length(), cur = 0; bool nxt = true;
    while (cur < n){
        if (cur == n - 1) answer++, cur++;
        else if (s[cur] == s[cur + 1] && cur + 2 < n)
            answer += 2, cur += 3;
        else if (s[cur] == s[cur + 1])
            answer++, cur += 2;
        else
            answer++, cur++;        
    }

    prl(answer);
    return 0;
}


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

int checka,checkz,panjang;
string s;

int main(){
	checka=200001;
    checkz=-1;
	cin>>s;
	panjang=s.length();
	for(int i=0;i<panjang;i++){
		if(s[i]=='A' && i<checka){
			checka=i;
		}else if(s[i]=='Z' && i>checkz){
			checkz=i;
		}
    }
    cout<<checkz-checka+1<<endl;
}

Measured memory_bytes: 3692
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
  
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
  
const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
   
ll mn[2*MAX_N-1], part[2*MAX_N-1];
int m;
  
void init(int n){
    m=1;
    while(m<n) m*=2;
    for(int i=0; i<2*m-1; i++){
        mn[i]=INF;
        part[i]=INF;
    }
}
 
void eval(int k, int l, int r){
    if(part[k]<INF){
        mn[k]=part[k];
        if(k<m-1){
            part[2*k+1]=part[k];
            part[2*k+2]=part[k];
          	mn[2*k+1]=part[2*k+1];
          	mn[2*k+2]=part[2*k+2];
        }
        part[k]=INF;
    }
}
   
void update(int a, int b, ll x, int k, int l, int r){
    if(r<=a || b<=l) return;
  	eval(k, l, r);
    if(a<=l && r<=b){
        part[k]=x;
        eval(k, l, r);
    }else{
        update(a, b, x, k*2+1, l, (l+r)/2);
        update(a, b, x, k*2+2, (l+r)/2, r);
        mn[k]=min(mn[2*k+1], mn[2*k+2]);
    }
}
   
ll find(int a, int b, int k, int l, int r){
    if(b<=l || r<=a){
        return INF;
    }
    eval(k, l, r);
    if(a<=l && r<=b){
        return mn[k];
    }else{
        return min(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
    }
}
  
int main()
{
    int n, q;
    cin>>n>>q;
    init(n);
    for(int i=0; i<q; i++){
        int tp;
        cin>>tp;
        if(tp==0){
            int s, t; ll x;
            cin>>s>>t>>x;
            update(s, t+1, x, 0, 0, m);
        }else{
            int s, t;
            cin>>s>>t;
            cout<<find(s, t+1, 0, 0, m)<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int c=0;
    string w[7]={"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"},s;
    cin>>s;
    for(int i=0;i<7;i++)
    {
        if(s==w[i]) c=0;
        c++;
    }
    cout<<c;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int a[] = new int[n];
        sc.reset();
        for(int i = 0; i<n;i++){
            a[i] = sc.nextInt();
        }
        insertionSort(a,n);
    }
 
    static void insertionSort(int[] arrays, int n){
        showArrays(arrays);
        int i,j,v;
        for(i=1;i<n;i++){
            v=arrays[i];
            j=i-1;
            while(j>=0 && arrays[j]>v){
                arrays[j+1] = arrays[j];
                j--;
            }
            arrays[j+1] = v;
            showArrays(arrays);
        }
    }
 
    static void showArrays(int[] arrays){
        String str = "";
        for(int a: arrays){
            str += Integer.toString(a)+ " ";
        }
        System.out.println(str.trim());
    }
}


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

long long a[200005], pref[200005], res = 0;
int main() {
   int n, mod = 1000000007;
   cin >> n;
   for (int i = 1; i <= n; i++) {
       cin >> a[i];
       pref[i] = a[i]+pref[i-1];
   }
   for (int i = 1; i <= n; i++) {
       res += ((pref[i-1]%mod)*(a[i]%mod))%mod;
   }
   cout << res%mod;
}

Measured memory_bytes: 6756
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

bool chk(string s) {
  ll n = (ll)s.size();
  ll n2 = n / 2;
  bool ret = true;
  rep(i, n2) {
    if (s[i] != s[n - 1 - i]) {
      ret = false;
      break;
    }
  }
  return ret;
}

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

  vll as(n);
  map<ll, ll> mp;
  rep(i, n) {
    cin >> as[i];
    mp[as[i]]++;
  }

  ll tot = 0;
  for(auto kv : mp){
    ll v = kv.second;
    tot += v * (v - 1) / 2;
  }

  rep(i, n) { 
    ll n = mp[as[i]];
    ll m = mp[as[i]] - 1;
    ll ans = tot - n * (n - 1) / 2 + m * (m - 1) / 2;
    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;

int a,b, total;

int main()
{
    cin >> a >> b;
    if(a>12){
        cout << b;
    } else if(a>5){
        total = b / 2;
        cout << total;
    } else {
        cout << "0";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 200000 + 10;
int N, K;
int a[MAX];

int main(void) {
    cin >> N >> K;
    REP(i, N) {
        cin >> a[i];
    }
    map<int, int> cnt;
    REP(i, N) {
        cnt[a[i]]++;
    }
    VPII v;
    FORE(e, cnt) {
        v.EB(MP(e.second, e.first));
    }
    RSORT(v);
    int ans = 0;
    while (v.size() > K) {
        ans += v.back().first;
        v.pop_back();
    }
    cout << ans << endl;
}


Measured memory_bytes: 12536
#include <iostream>
using namespace std;
using ll = long long;

int main() {
    ll a, b, k; cin >> a >> b >> k;
    ll eat_a = min(a, k);
    a -= eat_a;
    k -= eat_a;
    ll eat_b = min(b, k);
    b -= eat_b;
    k -= eat_b;

    printf("%lld %lld\n", a, b);
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;

ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (!(b & 1)) {
        return fastPow(x * x, b / 2);
    } else
        return x * fastPow(x * x, (b - 1) / 2);
}

//__builtin_popcount ();
int main() {
    FAST
    int n,t;
    cin>>n>>t;
    int arr[n];
    int mx=0,ok=-1,ans=0;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    for(int i=n-1;i>=0;i--)
    {
        mx=max(mx,arr[i]);
        if(mx-arr[i]>ok)
        {
            ok=mx-arr[i];
            ans=1;
        }
        else if(mx-arr[i]==ok)
            ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
from fractions import gcd
k = int(input())
check = [[1 for _ in range(k+3)] for i in range(k+3)]
for i in range(1, k+2):
    for j in range(1, k+2):
        check[i][j] = gcd(i, j)

result = 0
for s in range(1, k+1):
    for t in range(s, k+1):
        x = check[s][t]
        for u in range(t+1, k+1): 
            result += check[x][u]
result *= 6
result += k*(k+1)//2
print(result)

Measured memory_bytes: 11068