akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <vector>

struct Node;

struct Path{
    Node* node;
    int length; //0 or 1
};

struct Node{
    std::vector<Path> neighber;
    int color; //0 or 1
    int id;
};

int reverse(int b){
    return -(b - 1);
}

void paint(Node *node, int color, Node *parent){
    node->color = color;
    //printf("painted %d %d", node->id, color);
    for(auto itr = node->neighber.begin(); itr != node->neighber.end(); ++itr){
        //printf("neighber of me: %d, parent: %d", itr->node->id, parent->id);
        if(itr->node->id != parent->id){
            if(itr->length == 0){
                paint(itr->node, color, node);
            }else{
                paint(itr->node, reverse(color), node);
            }
        }
    }
}

int main(){
    int number;
    scanf("%d", &number);
    Node nodes[number + 1]; //1-origin
    for(int i = 1; i < number + 1; i++){
        nodes[i].id = i;
    }
    for(int i = 0; i < number - 1; i++){
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        Path tov;
        tov.node = &nodes[v];
        tov.length = w % 2;
        nodes[u].neighber.push_back(tov);
        Path tou;
        tou.node = &nodes[u];
        tou.length = w % 2;
        nodes[v].neighber.push_back(tou);
    }
    paint(&nodes[1], 0, &nodes[1]);
    for(int i = 1; i < number + 1; i++){
        printf("%d\n", nodes[i].color);
    }
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<pair<int, int>, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

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

    sort(B.begin(), B.end());
    ll ans = 0;
    for (int j = N - 1; j >= 0; --j) {
        auto ritr = upper_bound(B.begin(), B.end(), j - A[j]);
        auto litr = lower_bound(B.begin(), B.end(), j - A[j]);
        ans += ritr - litr;
    }

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


Measured memory_bytes: 4784
# -*- coding: utf-8 -*-

a = ['#', '.']

while True:
    n = list(map(int, input().split()))
    if n[0] == 0 & n[1] == 0:
        break

    for i in range(n[0]):
        for j in range(n[1]):
            print('{0}'.format(a[(i + j) % 2]), end='')

        print()

    print()



Measured memory_bytes: 7016
#include <stdio.h>

int main(){
	
	int h, a;
	scanf("%d%d", &h, &a);
	getchar();
	
	int att = h % a;
	int num1 = h / a;
	int num2 = h / a+1; 
	
	(att == 0)? printf("%d\n", num1) : printf("%d\n", num2);
		
	return 0;
}

Measured memory_bytes: 1704
////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <regex>
using namespace std;

//// MACRO ////
#define countof(a) (sizeof(a)/sizeof(a[0]))

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--)
#define pos(c,i) c.being() + (i)
#define allof(c) c.begin(), c.end()
#define aallof(a) a, countof(a)
#define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define apartof(a,i,n) a + (i), a + (i) + (n)
#define long long long

#define EPS 1e-9
#define INF (1L << 30)
#define LINF (1LL << 60)

//// i/o helper ////

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
struct _Writer { bool f; _Writer() : f(false) { } template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define WRITE(...) _Writer(), __VA_ARGS__; cout << endl

//// start up ////
void solve();
int main()
{
	solve();
	return 0;
}

////////////////////
/// template end ///
////////////////////

void solve()
{
	int testcases = INF;
	REP(testcase, testcases)
	{
		READ(int, N, M);
		if (!(N | M)) { break; }
		READ(int, r);
		struct entry { int t, n, m, s; };
		vector<entry> log;
		REP(i, r)
		{
			READ(int, t, n, m, s);
			log.push_back({ t, n, m, s });
		}

		READ(int, q);
		REP(i, q)
		{
			int ret = 0;

			READ(int, ts, te, m);
			int stack = 0, first;
			for (entry e : log)
			{
				if (e.m == m)
				{
					if (e.s) { if (!stack) { first = e.t; } stack++; }
					else { stack--; if (!stack) { ret += max(0, min(e.t, te) - max(first, ts)); } }
				}
			}
			WRITE(ret);
		}
	}
}

Measured memory_bytes: 1240
#include <iostream>
#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>

using namespace std;

int main(){
  int n;
  int a[105];
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  sort(a,a+n);
  cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; ++i)
#define RREP(i,n) for(int i = 0; i >= n; ++i)
typedef priority_queue <int> pi;
typedef priority_queue <int, vector<int>, greater<int>> pg;
typedef unsigned long long int ulli;

int N,A;

int main(){
    cin >> N >> A;
    if(N % 500 <= A){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  char S;
  const char* result = "Three";
  for (int i = 0; i < N; ++i) {
    cin >> S;
    if (S == 'Y') {
      result = "Four";
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 200105;
vector<pair<int,int>>a[maxn];
ll mx[maxn<<2], lz[maxn<<2];
void update(int x, int l, int r, int ql, int qr, ll v) {
	if (ql <= l && qr >= r) {
		mx[x] += v;
		lz[x] += v;
		return;
	}
	int mid = (l + r) >> 1;
	if (ql <= mid) {
		update(x<<1, l, mid, ql, qr, v);
	}
	if (qr > mid) {
		update(x<<1|1, mid + 1, r, ql, qr, v);
	}
	mx[x] = max(mx[x << 1], mx[x << 1 | 1]) + lz[x];
}
void go() {
	int n, m;
	cin >> n >> m;
	f (m) {
		int x, y, z;
		cin >> x >> y >> z;
		a[y].pb({x, z});
	}
	f1(n) {
		update(1,1,n,i,i,mx[1]);
		for (auto &j : a[i]) {
			update(1,1,n,j.F, i, j.S);
		}
	}
	cout << max(mx[1],0LL) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}

Measured memory_bytes: 21736
// B - Trained?
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vi A(N+1); rp(i, 1, N+1) cin>>A[i];
	int a = 1;
	rp(t, 1, N+1){
		a = A[a];
		if(a==2){
			cout<< t <<endl;
			return 0;
		}
	}
	cout<< -1 <<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        int m = n;
        while (true) {
            int a = m % 10;
            sum += a;
            m = m / 10;
            if (m == 0) {
                break;
            }
        }
        System.out.println(n % sum == 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 21844
#!/usr/bin python3
# -*- coding: utf-8 -*-

# ワーシャルフロイド法
# 全頂点間最短路
# d[i][j]は2頂点間i, j間の移動コストを格納, Mは頂点数

from scipy.sparse.csgraph import floyd_warshall
from collections import Counter

def main():
    H, W = map(int,input().split())
    d = [list(map(int,input().split())) for _ in range(10)]
    fw=floyd_warshall(d)
    p = []
    for i in range(H):
        p+=list(map(int,input().split()))
    p = Counter(p)
    ret = 0
    for i in range(10):
        if i==1: continue
        ret += p[i]*fw[i][1]
    print(int(ret))


if __name__ == '__main__':
    main()

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e5 + 5;



int n;
int a[maxn];
int ans[maxn];
int used[maxn];
int indeg[maxn];

void dfs(int idx, int lo) {
    if (idx == n) {
	for (int i=0; i<n; i++) {
	    cout<<ans[i]+1<<" ";
	}
	cout<<endl;
	exit(0);
    }

    // Prune: a[ans[idx-1]] can't go after anyone
    if (idx>0 && !used[a[ans[idx-1]]] && indeg[a[ans[idx-1]]] == n-idx-1) {
	return;
    }
    while (used[lo]) lo++;
    for (int x=lo; x<n; x++) {
	if (used[x]) continue;
	if (idx>0 && a[ans[idx-1]]==x) continue;
	int _lo = x==lo ? lo+1 : lo;
	used[x]=1;
	ans[idx]=x;
	indeg[a[x]]--;
	dfs(idx+1, _lo);
	indeg[a[x]]++;
	ans[idx]=0;
	used[x]=0;
    }
}

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

    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i];
	--a[i];
	indeg[a[i]]++;
    }

    dfs(0,0);
    out(-1);
    
    
    return 0;
}


Measured memory_bytes: 12976
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;

vector <LL> v[405][405];
LL n,m;
LL vis[405],p[405];
LL e[405][405],ans[405][405],a[405][405];

LL dfs(LL u){
	if(!u) return 1;
	for(LL i = 1;i <= n + n;i ++){
		if(e[u][i] <= 0) continue;
		if(vis[i]) continue;
		vis[i] = 1;
		if(dfs(p[i])){
			p[u] = i; p[i] = u;
			return 1;
		}
	}
	return 0;
}

void get_match(LL x){
	memset(p,0,sizeof(p));
	for(LL i = 1;i <= n;i ++){
		memset(vis,0,sizeof(vis));
		dfs(i);
	}
	for(LL i = 1;i <= n;i ++){
		e[i][p[i]] --; e[p[i]][i] --;
		ans[x][i] = v[i][p[i]][v[i][p[i]].size() - 1];
		v[i][p[i]].pop_back();
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cin >> a[i][j];
			e[i][(a[i][j] - 1) / m + 1 + n] ++;
			e[(a[i][j] - 1) / m + 1 + n][i] ++;
			v[i][(a[i][j] - 1) / m + 1 + n].push_back(a[i][j]);
		}
	}
	for(LL i = 1;i <= m;i ++) get_match(i);
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cout << ans[j][i] << (j == m ? '\n' : ' ');
		}
	}
	for(LL i = 1;i <= m;i ++){
		for(LL j = 1;j <= n;j ++){
			for(LL k = 1;k <= n;k ++){
				if(ans[i][j] < ans[i][k]) swap(ans[i][j],ans[i][k]);
			}
		}
	}
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cout << ans[j][i] << (j == m ? '\n' : ' ');
		}
	}
	return 0;
}

Measured memory_bytes: 6912
N = int(input())

if N < 600:
    print(8)
elif N < 800:
    print(7)
elif N < 1000:
    print(6)
elif N < 1200:
    print(5)
elif N < 1400:
    print(4)
elif N < 1600:
    print(3)
elif N < 1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  string a, b;
  cin >> a >> b;
  bool ans = false;
  if (sz(a) > sz(b)){
    print("GREATER");
  }
  else if(sz(a)<sz(b)){
    print("LESS");
  }
  else{
    rep(i,sz(a)){
      if(a[i]==b[i]){
        if(i==sz(a)-1){
          ans = true;
        }
        continue;
      }
      else if(a[i]>b[i]){
        print("GREATER");
        break;
      }
      else if(a[i]<b[i]){
        print("LESS");
        break;
      }
    }
  }
  if(ans){
    print("EQUAL");
  }
}

Measured memory_bytes: 256
S = input()
a = int(S[:2])
b = int(S[2:])
if 0 < a <= 12:
    if 0 < b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < b <= 12:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    int X,Y,Z;
    X=A+B;
    Y=A-B;
    Z=A*B;
    if(X<=Y){X=Y;}
    if(X<=Z){X=Z;}
    cout << X<< endl;
    return 0;
    
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            int count = 0;
            for(int i = 0; i<s.Length;i++)
            {
                if (s[i] != t[i])
                    count++;
            }
            Console.WriteLine("{0}", count);
        }
    }
}


Measured memory_bytes: 18180
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
struct edge {int a,b,c;}; 
int N;
edge W[100005];
int DP[100005][3]; //日にち, i日目にした活動, i日目までの幸福度の最大値

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

  cin >> N;
  int a,b,c;
  rep(i, N) {
    cin >> a >> b >> c;
    edge e = {a,b,c};
    W[i] = e;
  }

  rep(i, N) {
    if (i==0) {
      DP[0][0] = W[0].a;
      DP[0][1] = W[0].b;
      DP[0][2] = W[0].c;
      continue;
    }
    DP[i][0] = max(DP[i-1][1]+W[i].a, DP[i-1][2]+W[i].a);
    DP[i][1] = max(DP[i-1][0]+W[i].b, DP[i-1][2]+W[i].b);
    DP[i][2] = max(DP[i-1][0]+W[i].c, DP[i-1][1]+W[i].c);
  }

  int ans = max(DP[N-1][0], DP[N-1][1]);
  ans = max(ans, DP[N-1][2]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 1024
//by tzupengwang™
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<iostream>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

int h, w;
char s[15][15];

char t[15][15];
bool mr[15][15];
bool mc[15][15];

void init() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i ++) {
    scanf("%s", s[i]);
  }

  for (int i = 0; i < h; i ++) {
    for (int j = i + 1; j < h; j ++) {
      vector<char> v1, v2;
      for (int k = 0; k < w; k ++) {
        v1.push_back(s[i][k]);
        v2.push_back(s[j][k]);
      }
      sort(v1.begin(), v1.end());
      sort(v2.begin(), v2.end());

      mr[i][j] = mr[j][i] = true;
      for (int k = 0; k < w; k ++)
        if (v1[k] != v2[k]) {
          mr[i][j] = mr[j][i] = false;
          break;
        }
    }
  }
  // column
  for (int i = 0; i < w; i ++) {
    for (int j = i + 1; j < w; j ++) {
      vector<char> v1, v2;
      for (int k = 0; k < h; k ++) {
        v1.push_back(s[k][i]);
        v2.push_back(s[k][j]);
      }
      sort(v1.begin(), v1.end());
      sort(v2.begin(), v2.end());

      mc[i][j] = mc[j][i] = true;
      for (int k = 0; k < h; k ++)
        if (v1[k] != v2[k]) {
          mc[i][j] = mc[j][i] = false;
          break;
        }
    }
  }
}

bool ans;
int usdc[15];
int cl[15];

int usdr[15];
int rw[15];

void dfs2(int now) {
  if (ans) return;
  if (now < 0) {
    bool good = true;
    for (int i = 0; i < h and good; i ++) {
      for (int j = 0; j < w and good; j ++) {
        if (s[rw[i]][cl[j]] != s[rw[h - i - 1]][cl[w - j - 1]])
          good = false;
      }
    }
    if (good) ans = true;
    return;
  }

  if (now + now + 2 == w + 1) {
    for (int pt = 0; pt < w; pt ++) {
      usdc[pt] = true;
      cl[now] = pt;
      dfs2(now - 1);
      usdc[pt] = false;
    }
  } else {
    int pt = 0;
    while (usdc[pt]) pt ++;
    usdc[pt] = true;
    cl[now] = pt;
    for (int pt2 = pt + 1; pt2 < w; pt2 ++) {
      if (!usdc[pt2] && mc[pt][pt2]) {
        usdc[pt2] = true;
        cl[w - now - 1] = pt2;
        dfs2(now - 1);
        usdc[pt2] = false;
      }
    }
    usdc[pt] = false;
  }
}

void dfs1(int now) {
  if (ans) return;
  if (now < 0) {
    dfs2((w - 1) / 2);
    return;
  }

  if (now + now + 2 == h + 1) {
    for (int pt = 0; pt < h; pt ++) {
      usdr[pt] = true;
      rw[now] = pt;
      dfs1(now - 1);
      usdr[pt] = false;
    }
  } else {
    int pt = 0;
    while (usdr[pt]) pt ++;
    usdr[pt] = true;
    rw[now] = pt;
    for (int pt2 = pt + 1; pt2 < h; pt2 ++) {
      if (!usdr[pt2] && mr[pt][pt2]) {
        usdr[pt2] = true;
        rw[h - now - 1] = pt2;
        dfs1(now - 1);
        usdr[pt2] = false;
      }
    }
    usdr[pt] = false;
  }
}

void process() {
  ans = false;
  dfs1((h - 1) / 2);
  puts(ans ? "YES" : "NO");
}

int main() {
/*
#ifdef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  int Cases;
  scanf("%d", &Cases);
  for (int cs = 1; cs <= Cases; cs ++) {
*/
    init();
    process();
/*
  }
*/
  return 0;
}


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

int main() {
  long long int n,c,k;
  cin >> n >> c >> k;
  vector<long long int> list(n);
  for (long long int i=0;i<n;i++) {
    cin >> list.at(i);
  }
  sort(list.begin(), list.end());
  long long int count=1,temp_time=list.at(0),temp_num=0;
  
  for (int i=0;i<n;i++) {
    temp_num++;
    if (temp_num>c||list.at(i)-temp_time>k) {
      count++;
      temp_num=1;
      temp_time=list.at(i);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int K = stdIn.nextInt();
		Integer[] l = new Integer[N];
		for(int i = 0; i < N; i++) {
			l[i] = stdIn.nextInt();
		}
		Arrays.sort(l, Collections.reverseOrder());
		
		int ans = 0;
		for(int i = 0; i < K; i++) {
			ans += l[i];
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - I miss you...
            var S = Console.ReadLine();
            var e = Enumerable.Repeat("x", S.Length);

            Console.WriteLine(String.Join("", e));
        }
    }
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
//template<typename... Args>
//void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	string st;
    cin>>st;
    if(st[2]==st[3]&&st[4]==st[5]) cout<<"Yes";
    else cout<<"No";
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

vector<int> g[100000];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<int> que;
  vector<int> d(n, -1);
  d[0] = 0;
  vector<int> ans(n, -1);
  ans[0] = 0;
  que.push(0);
  while (que.size()) {
    int v = que.front();
    que.pop();
    for (auto u : g[v]) {
      if (d[u] == -1) {
        ans[u] = v;
        d[u] = d[v] + 1;
        que.push(u);
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    if (ans[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) {
    cout << ans[i] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 10728
s=input()
s=s[::-1]
memo=[0]*2019
memo[0]=1
current=0

for i in range(len(s)):
    current+=int(s[i])*pow(10,i,2019)
    current%=2019
    memo[current]+=1

ans=0
for i in memo:
    if i>=2:
        ans+=i*(i-1)//2
print(ans)

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

#define INF 100005
int dp[INF];

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    int tmp;
    rep(i,n){
        cin>>h[i];
    }

    if(n==2){
        cout<<abs(h[1]-h[0])<<endl;
        return 0;
    }else if(n==3){
        cout<<min(abs(h[1]-h[0]), abs(h[2]-h[0]))<<endl;
    }

    dp[0] = h[0];
    dp[1] = abs(h[0]- h[1]);
    dp[2] = abs(h[0]- h[2]);

    for(int i=3; i<n; i++){
        dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]));
    }

    cout<<dp[n-1]<<endl;

}


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

int main(){
  vector<string> s = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string a;
  cin >> a;
  for(int i = 0;i<7;i++){
    if (a == s.at(i)){
        cout << s.size()-i << endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int a = scanner.nextInt();
		    int b = scanner.nextInt();
		    String s = scanner.next();
		    
		    int count = 0;
		    
		    for(int i = 0; i < s.length(); i++) 
		    {
		    	if(s.substring(i, i+1).equals("-")) 
		    	{
		    		count++;
		    	}
		    }
		    
		    
		    if(count == 1) 
		    {
		    	if(s.indexOf("-") == a) 
		    	{
		    		System.out.println("Yes");
		    	}
		    	else 
		    	{
		    		System.out.println("No");
		    	}
		    }
		    else 
	    	{
	    		System.out.println("No");
	    	}
			
		    scanner.close(); }
		  }

Measured memory_bytes: 23764
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define ll long long
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>

int main(){
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, 3) if(S[i] == T[i])ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    rep(i, N) cin >> A[i];
    
    set<long long> B;
    vector<long long> S;
    rep(i, N) {
        if (B.count(A[i])) {
            S.push_back(A[i]);
            B.erase(A[i]);
        } else {
            B.insert(A[i]);
        }
    }
    
    if (S.size() < 2) {
        cout << 0 << endl;
    } else {
        sort(S.rbegin(), S.rend());
        cout << S[0] * S[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> vec(n);
  REP(i, n) {
    cin >> vec[i];
  }
  vector<int> g(n);
  int ans = 0;
  REP(i, n) {
    while(g[i] < vec[i]) {
      int j = i+1;
      while(g[j] < vec[j]) {
        j++;
      }
      for (int k = i; k < j; k++) {
        if (g[k] == vec[k]) break;
        g[k]++;
      }
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	}
}

Measured memory_bytes: 45688
def f(n):
  ret={1}
  for i in range(2,int(n**.5)+1):
    if n%i==0:
      ret.add(i)
      while n%i==0:
        n//=i
    else:pass
  if n:
    ret.add(n)
  return ret
a,b=map(int,input().split())
print(len(f(a)&f(b)))

Measured memory_bytes: 3060
import math
import heapq
def dijkstra(s,m,n):
    visited=[0]*n
    d=[float("inf")]*n
    d[s]=0
    while True:
        mincost=float("inf")
        for i in xrange(n):
            if visited[i]!=2 and d[i]<mincost:
                mincost=d[i]
                u=i
        if mincost==float("inf"):
            break
        visited[u]=2
        for v in xrange(n):
            if visited[v]!=2:
                if d[u]+m[u][v]<d[v]:
                    d[v]=d[u]+m[u][v]
                    visited[v]=1
    return d

def main():
    xs,ys,xt,yt=map(int,raw_input().split())
    n=int(raw_input())
    c=[[xs,ys,0]]+[map(int,raw_input().split()) for _ in xrange(n)]+[[xt,yt,0]]
    dist=[[float("inf")]*(n+2) for _ in xrange(n+2)]
    for i in xrange(n+2):
        for j in xrange(n+2):
            if i==j:continue
            dist[i][j]=min(dist[i][j],dist[j][i],max(math.sqrt(abs(c[i][0]-c[j][0])**2+abs(c[i][1]-c[j][1])**2)-c[i][2]-c[j][2],0))
            dist[j][i]=dist[i][j]
    ans=dijkstra(0,dist,n+2)
    print(ans[n+1])
main()


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

int main(void){
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if(a == b + c) cout << "Yes" << endl;
    else if(b == a + c) cout << "Yes" << endl;
    else if(c == a + b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;

}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = str(input())

Sarr = [True if s == '.' else False for s in S]
#print(Sarr)

def canmove(st):
  global N, Sarr
  can = [False] * N
  can[st-1] = True
  for i in range(st, N):
    if Sarr[i]:
      if can[i-1] or can[i-2]:
        can[i] = True
  return can

Acan = canmove(A)
Bcan = canmove(B)
#print(Acan)
#print(Bcan)

ans = Acan[C-1] and Bcan[D-1]
#print(ans)

def canpass(st, ed):
  global Sarr
  for i in range(st, ed-1):
    if Sarr[i] and Sarr[i+1] and Sarr[i+2]:
      return True
  return False

if C > D:
  ans = ans and canpass(B-2, D)
#print(ans)

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

Measured memory_bytes: 7988
#include <bits/stdc++.h>
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp  make_pair
#define pb  push_back
#define  sz(x)   (int)x.size()
#define  all(x)  x.begin(), x.end()
#define	 allr(x)  x.rbegin(), x.rend()
#define  bit(x)  __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
int mul (int x, int y) { return ((ll)x * y) % mod; } 
int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int) 3e5;
 
ll dis[maxn], cost[maxn];
ll sum[maxn], ans[maxn], rans[maxn];

void solve () {
	int n; cin >> n;
	ll c; cin >> c;
	
	ll res = 0;
	for (int i = 1; i <= n; i ++) {
		cin >> dis[i] >> cost[i];
		sum[i] = sum[i-1] + cost[i];
		ans[i] = max (ans[i-1], sum[i] - dis[i]);
		res = max (res, ans[i]);
	}

	for (int i = n; i >= 1; i --) {
		rans[i] = max (rans[i+1], (sum[n] - sum[i-1]) - (c - dis[i]));
		res = max (res, rans[i]);
	}

	for (int i = 1; i <= n; i ++) {
		res = max (res, (sum[i] - (dis[i] * 2) + rans[i + 1]));
		res = max (res, ((sum[n] - sum[i-1]) - (c - dis[i]) * 2) + ans[i - 1]);
	}

	cout << res;
}

main () { fast_in;
    int t = 1; //cin >> t;
    while (t --) {
    	solve ();    
    }
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s[n];
    int i,j;
    for(i=0;i<n;i++)
        cin >> s[i];
    int m;
    cin >> m;
    string t[m];
    for(i=0;i<m;i++)
        cin >> t[i];

    int counter[n];
    for(i=0;i<n;i++)
        counter[i]=0;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(s[i]==s[j])
                counter[i]++;
        }
        for(j=0;j<m;j++){
            if(s[i]==t[j])
                counter[i]--;
        }
    }

    int max=counter[0];
    for(i=0;i<n;i++){
        if(max<counter[i])
            max=counter[i]; 
    }
    if(max<0)
        max=0;
    cout << max << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  char a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  if(c==d&&e==f)cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main () {
  char str [222];
  scanf ("%s", str ) ;
  int n= strlen (str ) ;
  for (int i=n -2; i; i -=2) {
	if( strncmp (str , str +i/2 , i/2) ==0) {
	  printf ("%d\n" ,i) ;
	  return 0;
	}
  }
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int A, B;
    cin >> A >> B;
    int tap = 0;
    int plag = 1;
    for (;;)
    {
        if (plag >= B) break;
        ++tap;
        plag += A - 1;
    }
    cout << tap << endl;
}


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

using namespace std;

int N;

int main(){
  ios_base::sync_with_stdio(false); 
  cin >> N;
  vector<int> v(N);
  long long x = 0LL, y = 0LL;
  for(int i=0; i<N; ++i){
     cin >> v[i];
       x += v[i];
  }
  long long res = INT_MAX;
  for(int i=N-1; i>=1; --i){
    y += v[i];
    x -= v[i];
    res = min(res, abs(x-y));
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    int ans = 0;
    rep(0, i, N)
    {
        cin >> A[i];
    }
    sort(all(A));
    cout << A[N - 1] - A[0] << endl;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))
dp = [999999] * N

dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(N-2):
    dp[i + 2] = min((dp[i] + abs(h[i] - h[i+2])), (dp[i+1] + abs(h[i+1] - h[i+2])))
   
print(dp[N-1])


Measured memory_bytes: 13924
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    int b[n];
    int lt=(n%2 ? n/2 : n/2 -1), rt = (n%2 ? n/2 +1 : n/2);
    REP(i, n){
        int a; cin >> a;
        if((n-i)%2) b[lt--] = a;
        else b[rt++] = a;
    }
    REP(i, n){
        if(i) cout << " ";
        cout << b[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3072
a, b, k = [int(x) for x in input().split()]

# a,bの最大公約数
def gcd(A, B):
    if A%B == 0:
        return B
    return gcd(B, A%B)

# 約数を列挙。
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

wk1 = gcd(a, b)
wk2 = make_divisors(wk1)
ans = wk2[-k]
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>

#define FALSE 0
#define CROSS 1
#define A_IN_B -2
#define B_IN_A 2
#define OTHER -10

#define compile 0

struct circle
{
	double x; //中心のx座標
	double y; //中心のy座標
	double r; //円の半径
};

int func_judge(double ax, double ay, double ar, double bx, double by, double br);
void func_output(int result);

main()
{
	int n = 0, i = 0; //データセット代入変数, 制御変数
	int result = OTHER; //-2,0,1,2以外なら何でも良い
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		struct circle a = {0, 0, 0}; //構造体変数の宣言(円a)
		struct circle b = {0, 0, 0}; //構造体変数の宣言(円b)
		
		scanf("%lf %lf %lf %lf %lf %lf", &a.x, &a.y, &a.r, &b.x, &b.y, &b.r); //入力
		result = func_judge(a.x, a.y, a.r, b.x, b.y, b.r); //結果の計算
		func_output(result);
		result = OTHER;
	}
	return 0;
}

int func_judge(double ax, double ay, double ar, double bx, double by, double br)
{
	double dis_a_to_b = 0; //円aと円bの距離を代入する変数
	dis_a_to_b = sqrt(pow(ax - bx, 2) + pow(ay - by, 2)); //中心間の距離を計算
	
#if compile == 2
		printf("dis_a_to_b = %lf ar = %lf br = %lf\n", dis_a_to_b, ar, br);
#endif
	
	
	if(ar > (br + dis_a_to_b)) //aの半径rがbの半径rと円aと円bの中心座標の距離の和よりも大きい場合
	{
		return B_IN_A;
	}
	else if(br > (ar + dis_a_to_b)) //bの半径rがaの半径rと円aと円bの中心座標の距離の和よりも大きい場合
	{
		return A_IN_B;
	}
	else if((ar + br) < dis_a_to_b) //aの半径rとbの半径rの和が2つの円の距離未満である場合
	{
		return FALSE;
	}
	else if((ar + br) >= dis_a_to_b)
	{
		return CROSS;
	}
	else
	{
		return OTHER;
	}
}
void func_output(int result)
{
	printf("%d\n", result);
	//printf("result = %d ", result);
	/*
	switch(result)
	{
	case -2:
		printf("%d\n", result);
		break;
	case 0:
		printf("%d\n", result);
		break;
	case 1:
		printf("%d\n", result);
		break;
	case 2:
		printf("%d\n", result);
		break;
	}
	*/
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iso646.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

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

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

ll gcd(ll n, ll m) {
    if(n > m) {
        ll l = n;
        n = m;
        m = l;
    }
    while(1) {
        ll l = n;
        n = m % n;
        m = l;
        if(n == 0) {
            break;
        }
    }
    return m;
}

int main() {

    ll K;
    cin >> K;
    ll i, j, k;
    ll ans = 0;
    for(i = 0; i < K; i++) {
        for(j = 0; j < K; j++) {
            for(k = 0; k < K; k++) {
                ans += gcd(i + 1, gcd(j + 1, k + 1));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,s;cin >> n>>k >> s;
  vl v(n);
  if(s==1000000000){
    rep(i,n){
      if(i<k)v[i] = s;
      else v[i] = s-1;
    }
  }else{
    rep(i,n){
      if(i<k)v[i] = s;
      else v[i] = 1000000000;
    }
  }
  rep(i,n){
    cout << v[i] << " ";
  }
}

Measured memory_bytes: 2176
#122-B
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
S=S()
Q=["A","T","G","C"]
ans=0
cnt=0
for s in S:
    if s in Q:
        cnt+=1
    else:
        ans=max(ans,cnt)
        cnt=0
ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3064
use std::io;

fn input() -> String{
    let mut input:String = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn main() {
    let ch: char = input().as_str().chars().nth(0).unwrap();
    if ch.is_ascii_uppercase() {
        println!("A");
    } else {
        println!("a");
    }
}


Measured memory_bytes: 2060
from collections import deque


def bfs(graph, start, end):
    queue = deque([start])
    visited = [-1] * len(graph)
    visited[start] = 0
    while queue:
        pos = queue.popleft()
        if pos == end: return visited[pos]
        for next_pos in graph[pos]:
            if visited[next_pos] == -1:
                visited[next_pos] = visited[pos] + 1
                queue.append(next_pos)
    return -1

def solve():
    N, M = map(int, input().split())
    graph = [[] for i in range(N * 3)]
    for i in range(M):
        u, v = map(lambda s: int(s) - 1, input().split())
        graph[N * 0 + u].append(N * 1 + v)
        graph[N * 1 + u].append(N * 2 + v)
        graph[N * 2 + u].append(N * 0 + v)
    S, T = map(lambda s: int(s) - 1, input().split())
    dist = bfs(graph, S, T)
    return dist // 3 if dist != -1 else -1


print(solve())


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    s.at(i)=(char)(s.at(i)+n);
    if('Z'<s.at(i)) s.at(i)=(char)(s.at(i)-26);
  }
  cout << s << endl;
}

Measured memory_bytes: 256
# 解説を確認、このような、最大（最小値）の出し入れが頻繁にあるデータでは、
# 「優先度付きキュー」というデータ構造を用いると容易になるようだ。
# 新規要素の Push & Pop が O(N log N) でできるとのこと。

from heapq import heapify,heappush,heappop

n=int(input())
a=list(map(int,input().split()))

a1=a[0:n]
a_m=a[n:2*n]
a2=[ -x for x in a[2*n:3*n] ] # nega_list

a1_sums=[sum(a1)]
a2_sums=[sum(a2)]
heapify(a1)
heapify(a2)

# 左のシマに真ん中のシマを徐々に追加し、都度最小値を取り出す
for aa in a_m:
  heappush(a1,aa)
  p=heappop(a1)
  a1_sums.append(a1_sums[-1]+aa-p)

# 右のシマは都度最大値を取り出す
a_m.reverse()
for aa in a_m:
  heappush(a2,-aa)
  p=heappop(a2)
  a2_sums.append(a2_sums[-1]-aa-p)

max_val=-float("inf")
for i in range(0,n+1):
  max_val=max(max_val,a1_sums[i]+a2_sums[n-i])

print(max_val)


Measured memory_bytes: 42728
N = int(input())
List = list(map(int, input().split()))
a=[0]*(N+1)
b=[0]*(N+1)
for i in List:
    a[i]+=1
    
#print(a)
def fun(x):
    num=x*(x-1)/2

    return int(num)
sum=0
for i in range(0,N+1):
    b[i]=int(a[i]*(a[i]-1)/2)
    sum+=b[i]
#print(b,sum)
for k in range(1,N+1):
    q=b[List[k-1]]-(a[List[k-1]]-2)*(a[List[k-1]]-1)/2
    c=sum-q
    print(int(c))


Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll a[200000];
ll ans = 0;
unordered_map<ll, ll> mp;
int main(){
  int n;
  cin >> n;
  rep(i, n){
    cin >> a[i];
    if(mp.count(a[i])) mp.at(a[i])++;
    else mp[a[i]] = 1;
  }
  for(pair<ll, ll> x : mp){
    ans += x.second * (x.second-1)/2;
  }
  rep(i, n){
    cout << ans - mp.at(a[i]) + 1<<endl;
  }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    // ABC005 - A - STring //
    
    string x; cin >> x;
    int n = x.size();
    
    vi data(n, 0);
    int ng = 0;
    
    rep(i, n){
        if(i == 0){
            if(x[i] == 'S') data[i] = 1;
            else ng++;
        } 
        else{
            if(x[i] == 'S') {
                data[i] = data[i-1] + 1;
            } else {
                if(data[i-1] == 0) ng++;
                else data[i] = data[i-1] - 1;
            }
        }
    }
    cout << ng*2 << endl;
	return;
}

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

Measured memory_bytes: 1428
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    a.sort!"a < b";
    long len = a.uniq.array.length;

    writeln(len == n ? "YES" : "NO");
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void ipElems(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int main(void) {
	long long n;
	long long cnt[5] = { 0 };
	char s[11];
	long long ans = 0;

	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		if (s[0] == 'M')cnt[0]++;
		if (s[0] == 'A')cnt[1]++;
		if (s[0] == 'R')cnt[2]++;
		if (s[0] == 'C')cnt[3]++;
		if (s[0] == 'H')cnt[4]++;
	}
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++)ans += cnt[i] * cnt[j] * cnt[k];
		}
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;

int main() {
    int T;
    cin >> T;
    while(T--) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        int flg = 1;
        if(a < b) flg = 0;
        else {
            if(d < b) flg = 0;
            else {
                if(c < b) {
                    a = a % b;
                    d = d % b;
                    ll l = c - a, r = b - a;
                    ll g = __gcd(d, b);
                    if(l < 0) flg = 0;
                    else if(d == 0 || (l / g + 1) * g >= r) flg = 1;
                    else flg = 0;
                }
            }
        }
        cout << (flg ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
     if(s[0]==t[0]&&s[1]==t[1]&&s[2]==t[2]){cout<<3<<endl;}
     else if(s[0]==t[0]&&s[1]==t[1]&&s[2]!=t[2]){cout<<2<<endl;}
     else if(s[0]==t[0]&&s[1]!=t[1]&&s[2]==t[2]){cout<<2<<endl;}
     else if(s[0]!=t[0]&&s[1]==t[1]&&s[2]==t[2]){cout<<2<<endl;}
     else if(s[0]!=t[0]&&s[1]!=t[1]&&s[2]==t[2]){cout<<1<<endl;}
     else if(s[0]!=t[0]&&s[1]==t[1]&&s[2]!=t[2]){cout<<1<<endl;}
     else if(s[0]==t[0]&&s[1]!=t[1]&&s[2]!=t[2]){cout<<1<<endl;}
     else {cout<<0<<endl;}
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int n,i,v[400010],x[200010],ap[200010];
long long sol;
void build()
{
    for(i=n-1; i>=1; --i)
        v[i]=min(v[i*2],v[i*2+1]);
}
void answer(int l,int r)
{
    int L=l+n-1;
    int R=r+n;
    int ans=200010;
    while(L<R)
    {
        if(L%2==1)ans=min(ans,v[L++]);
        if(R%2==1)ans=min(ans,v[--R]);
        L/=2;
        R/=2;
    }
    int poz=ap[ans];
    sol+=1LL*ans*(poz-l+1)*(r-poz+1);
    if(poz!=1&&l<=poz-1)answer(l,poz-1);
    if(poz!=n&&poz+1<=r)answer(poz+1,r);
}
int main()
{
  //  freopen("a.in","r",stdin);
  //  freopen("a.out","w",stdout);
    scanf("%d",&n);
    for(i=0; i<n; ++i)
    {
        scanf("%d",&v[i+n]);
        x[i+1]=v[i+n];
        ap[v[i+n]]=i+1;
    }
    build();
    answer(1,n);
    printf("%lld\n",sol);
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define LL long long
#define INF 1e18
#define MAXN 100005
 
LL min(LL x, LL y) {if(x<y) return x; return y;}
 
int n, m, s, t, u, v;
LL a, b, f=1e15, ans[MAXN];
 
struct Graph
{
	int cnt, head[MAXN], vis[MAXN];
	LL dis[MAXN];
	
	struct Edge {int next, to; LL dis;} edge[MAXN*2];
	
	std::queue<int> q;
	
	void addedge(int from, int to, LL dis)
	{
		edge[++cnt].next=head[from];
		edge[cnt].to=to;
		edge[cnt].dis=dis;
		head[from]=cnt;
	}
	
	void spfa(int s)
	{
		for(int i=1; i<=n; i++) dis[i]=INF;
		memset(vis, 0, sizeof(vis));
		q.push(s); vis[s]=1; dis[s]=0;
		while(!q.empty())
		{
			int x=q.front(); q.pop();
			vis[x]=0;
			for(int i=head[x]; i; i=edge[i].next)
			{
				int to=edge[i].to;
				if(dis[to]>dis[x]+edge[i].dis)
				{
					dis[to]=dis[x]+edge[i].dis;
					if(!vis[to]) q.push(to), vis[to]=1;
				}
			}
		}
	}
} g1, g2;
  
int main()
{
	
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i=1; i<=m; i++)
	{
		scanf("%d%d%lld%lld", &u, &v, &a, &b);
		g1.addedge(u, v, a); g1.addedge(v, u, a);
		g2.addedge(v, u, b); g2.addedge(u, v, b);
	}
	g1.spfa(s);  g2.spfa(t);
	ans[n+1]=INF;
	for(int i=n; i>=1; i--) ans[i]=min(ans[i+1], g1.dis[i]+g2.dis[i]);
	for(int i=1; i<=n; i++) printf("%lld\n", f-ans[i]);
}

Measured memory_bytes: 12032
w, h, n = map(int, input().split())
coord_list = [list(map(int, input().split())) for i in range(n)]

x_min = 0
y_min = 0
x_max = w
y_max = h
for a in coord_list:
    if a[2] == 1:
        x_min = max(a[0], x_min)
    elif a[2] == 2:
        x_max = min(a[0], x_max)
    elif a[2] == 3:
        y_min = max(a[1], y_min)
    elif a[2] == 4:
        y_max = min(a[1], y_max)

ans = max((x_max - x_min), 0) * max((y_max - y_min), 0)
print(ans)

Measured memory_bytes: 3064