akhauriyash/Code-Regression huggingface dataset:
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;
 
  
 
signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);

  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " <<  a << " " << b << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{
    int R,G,B,N; cin>>R>>G>>B>>N;

    int ans=0;
    for(int i=0;R*i<=N;i++){
        for(int j=0;R*i+G*j<=N;j++){
            int rest=N-(R*i+G*j);
            if(rest%B==0){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

int rd() {
	int x = 0, f = 1; char c = getchar();
	while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
	return x * f;
}
const int N = 1e5 + 10;

struct edge {
	int nxt, to;
}e[N << 1];
int head[N], fa[N], dep[N], sz[N], path[N], tot, B, W, numb, numw, n, cnt;

void add_edge(int u, int v) {
	e[++cnt].nxt = head[u], e[head[u] = cnt].to = v;
}

void dfs(int u, int p) {
	sz[u] = 1;
	for (int i = head[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if (v == p) continue;
		fa[v] = u;
		dep[v] = dep[u] + 1;
		dfs(v, u);
		sz[u] += sz[v];
	}
}

int main() {
	n = rd();
	for (int i = 1; i < n; i ++) {
		int u = rd(), v = rd();
		add_edge(u, v), add_edge(v, u);
	}
	dfs(1, 0);
	int u = n;
	while (u) {
		path[++tot] = u;
		u = fa[u];
	}
	for (int i = 1; i <= tot / 2; i ++) swap(path[i], path[tot - i + 1]);
	B = (tot + 1) / 2, W = tot / 2;
	numb = sz[1] - sz[path[B + 1]];
	numw = sz[path[B + 1]];
	if (numb > numw) puts("Fennec"); else puts("Snuke");
	return 0;
}

Measured memory_bytes: 8576
import sys
 
for line in sys.stdin:
  A, B, C = [int(s) for s in line.split()]
  
if ((A - B) * (B - C) * (C - A) == 0) and (int(A!=B) + int(B!=C) + int(C!=A)):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int cnt[1010],n;
string s[1010],z;
int main(){
	while(cin>>n&&n){
	cin>>z;cout<<z<<endl;n--;
	memset(cnt,114514,sizeof(cnt));
	for(int i=0;i<n;i++){
		cin>>s[i];
		int k=0;
		for(int j=s[i].size()-1;j>=0;j--){
			if(s[i][j]=='.')s[i][j]=' ';
			else k=j-1;
		}
		for(int j=k+1;j<1010;j++)cnt[j]=114514;
		for(int j=cnt[k];j<i;j++)s[j][k]='|';
		s[i][k]='+';cnt[k]=i+1;
	}
	for(int i=0;i<n;i++)cout<<s[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3820
#include <iostream>
#define INF 1e9
using namespace std;
long long cnt;
int n , i , j;
void merge(int A[],int L,int M,int R){
  int n1=M-L;
  int n2=R-M;
  int a[500000],b[500000];
  for(i=0;i<n1;i++)a[i]=A[L+i];
  for(i=0;i<n2;i++)b[i]=A[M+i];
  a[n1]=INF,b[n2]=INF;
  i=0,j=0;

  for(int k=L;k<R;k++){
    if(a[i]<=b[j]) A[k]=a[i++];
    else A[k]=b[j++],cnt+=(n1-i);
  }
}
 
void mergeSort(int A[],int L,int R){
  if(L+1<R){
    int M=(L+R)/2;
    mergeSort(A,L,M);
    mergeSort(A,M,R);
    merge(A,L,M,R);
  }
}
 
int main(){
  int a[500000];
  cin>>n;
  for(i=0;i<n;i++)cin>>a[i];
  mergeSort(a,0,n);
  
  cout <<cnt<<endl;
}


Measured memory_bytes: 4656
#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>
#include<vector>
#include<unordered_set>
#include<algorithm>

using namespace std;

namespace
{

}

#if 1
int main()
{
	int a, b;
	cin >> a;
	cin >> b;

	bool isExist = false;
	if ((a * b % 2) == 1)
	{
		isExist = true;
	}
	else if (((a * b * 2) % 2) == 1)
	{
		isExist = true;
	}
	else if (((a * b * 3) % 2) == 1)
	{
		isExist = true;
	}

	if (isExist)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}


	return 0;
}
#endif


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = l[0], B = l[1], C = l[2], D = l[3];

            var start = Math.Max(A, C);
            var end = Math.Min(B, D);

            Console.WriteLine(Math.Max(0, end - start));
        }
    }
}


Measured memory_bytes: 11348
import java.util.*

fun <T : Comparable<T>> min(i: T, j:T):T {
    return if (i < j) i else j
}
fun main(args: Array<String>) {
    val (N) = readLine()!!.split(" ").map { it.toLong() }
    val list = divisor(N)
    var min = Long.MAX_VALUE
    list.forEach {
        val a = N / it
        min = min(min, a + it)
    }
    print(min-2)
}

fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

Measured memory_bytes: 44332
#D問題
N = int(input())
A = list(map(int,input().split()))

srui = [0]
xrui = [0]

for a in A:
    srui.append(srui[-1]+a)
    xrui.append(xrui[-1]^a)
    
#print(srui,xrui)
ans = 0
J = 1
for i in range(N):
    I = i+1
    while J <= N and (srui[J]-srui[I-1]) == (xrui[J]^xrui[I-1]):
        J+=1
    J-=1
    ans += J-I+1
            
print(ans)

Measured memory_bytes: 100428
#include<bits/stdc++.h>
#define ll long long
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
const int maxn=500500;
int n,m,cnt;
int a[maxn];
struct node
{
	int b,c;
}e[maxn];
bool cmp(node d1,node d2)
{
	if(d1.c!=d2.c)return d1.c<d2.c;
	return d1.b<d2.b;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		//e[i]=a[i];
		//q.push(a[i]);
		//if(!mp[a[i]])mp[a[i]]=++cnt;
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&e[i].b,&e[i].c);
		//e[i+n]=c[i];
		/*
		while(b[i]&&q.top()<c[i]){
			//int p=q.top();
			q.pop();
			q.push(c[i]);
			b[i]--;

		}*/
		
		//if(!mp[c[i]])mp[c[i]]=++cnt;
	}
	ll res=0;
	
	/*
	while(!q.empty())
	{
		ans+=(ll)q.top();
		q.pop();
	}cout<<ans<<endl;*/
	sort(e+1,e+1+m,cmp);
	//for(int i=1;i<=n+m;i++)if(!mp[e[i]])mp[e[i]]=++cnt;
	/*
	for(int i=1;i<=n;i++)d[mp[a[i]]]++;
	build(1,cnt,1);
	for(int i=1;i<=m;i++)
	{
		int l=1,r=mp[c[i]]-1,ans=mp[c[i]]-1;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(can(mid,b[i]))ans=mid,r=mid-1;
			else l=mid+1;
		}
		int t=query(ans);
		if(t>=b[i])t=b[i];
		else t=t;
		change(1,cnt,1,1,ans,-t);
		change(1,cnt,1,mp[c[i]],mp[c[i]],t);
		//add(1,cnt,1,mp[c[i]],t);
	}*/
	sort(a+1,a+1+n);
	int lst=m;
	for(int i=1;i<=n;i++)
	{
		while(e[lst].b==0&&lst)lst--;
		if(e[lst].b&&e[lst].c>a[i])
		{
			a[i]=e[lst].c;
			e[lst].b--;
		}
		while(e[lst].b==0&&lst)lst--;
		res+=(ll)a[i];
	}cout<<res<<endl;
}



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

string S, T;

int main(){
  cin >> S >> T;
  int a, b;
  cin >> a >>b;
  string buf;
  cin >> buf;
  if(buf.compare(S) == 0){
    cout <<  a-1  << " " << b << endl;
  }else{
    cout <<  a  << " " << b-1 << endl;
  }

  return 0;

}


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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


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

    vector<ll> wei(n+1,0);
    vector<ll> val(n+1,0);

   for(ll i=1;i<=n;i++){
        cin>>wei.at(i)>>val.at(i);
    }

    vector<ll> dp(w+1,0);

   for(ll i=1;i<=n;i++){
       for(ll j=w;j>=0;j--){
           if(j<wei.at(i))break;
           dp.at(j) = max(dp.at(j),dp.at(j-wei.at(i))+val.at(i));
       }
   }

   cout<<dp.at(w)<<endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import bisect
import math

n, h = map(int, input().split())
a, b = [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
max_a = max(a)
b.sort()
idx = bisect.bisect_right(b, max_a)
ans = 0
tmp = 0
for i in range(n - 1, -1, -1):
    tmp += b[i]
    if tmp >= h:
        print(n - i)
        exit()
    if i <= idx:
        break

print(n - idx + math.ceil((h - sum(b[idx:])) / max_a))


Measured memory_bytes: 11312
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
#define INFTY (1<<30)
class Edge{
public:
  int t,w;
  Edge(){}
  Edge(int t,int w):t(t),w(w){}
};
vector<Edge>G[MAX];
int n,d[MAX];
bool vis[MAX];
int cnt;
void bfs(int s){
  for(int i=0;i<n;i++) d[i]=INFTY;
  queue<int>Q;
  Q.push(s);
  d[s]=0;
  int u;
  while(!Q.empty()){
    u=Q.front(); Q.pop();
    for(int i=0;i<G[u].size();i++){
      Edge e=G[u][i];
      if(d[e.t]==INFTY){
	d[e.t]=d[u]+e.w;
	Q.push(e.t);
      }
    }
  }
}
void solve(){
  //適切な始点sから最も遠い節点tgtを求める
  bfs(0);
  int maxv=0;
  int tgt=0;
  for(int i=0;i<n;i++){
    if(d[i]==INFTY) continue;
    if(maxv<d[i]){
      maxv=d[i];
      tgt=i;
    }
  }
  //tgtから最も遠い節点距離maxvを求める
  bfs(tgt);
  maxv=0;
  for(int i=0;i<n;i++){
    if(d[i]==INFTY) continue;
    maxv=max(maxv,d[i]);
  }
  cout<<maxv<<endl;
}
main(){
  int s,t,w;
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>s>>t>>w;
    G[s].push_back(Edge(t,w));
    G[t].push_back(Edge(s,w));
  }
  solve();
}



Measured memory_bytes: 9784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxN = 1e5+7;
const int maxM = 1e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
const ll INF = (1ll)<<60;
//const int INF = 2e9+9;
const int MOD = 1e9+7;

ll x,y;

int main()
{
	scanf("%lld %lld",&x,&y);
	ll cnt = 2020;
	ll md = 2019;
	if(y-x+1>=3000)
	{
		cnt = 0;
	}
	else
	{
		for(int i=x;i<=y;i++)
		{
			for(int j=i+1;j<=y;j++)
				cnt = min(cnt,(ll)i*j%md);
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main()
{
	string a;
	cin >> a;
	int n = a.size();
	if (n == 2) {
		
		cout << a << endl;

	}
	else {
		cout << a[2] << a[1] << a[0] << endl;
		
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

string S, T;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> S >> T;
  string ans = "~";
  rep(offset, S.length()) {
    string out(S);
    bool ok = true;
    rep(i, T.length()) {
      if (offset+i >= S.length()) { ok  = false; break; }
      if (S[offset+i] != '?' && S[offset+i] != T[i]) { ok = false; break; }
      out[offset+i] = T[i];
    }
    rep(i, S.length()) if (out[i] == '?') out[i] = 'a';
    if (ok) ans = min(ans, out);
  }
  if (ans == "~") ans = "UNRESTORABLE";
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#coding:utf-8

def prim(n,G):
    dist=0
    visited=[False]*n
    cost=[1000000]*n
    pi=[0]*n
    cost[0]=0
    pi[0]=-1
    while True:
        mincost=1000000
        u=0
        for i in range(n):
            if visited[i]==False and cost[i]<mincost:
                mincost=cost[i]
                u=i
        if mincost==1000000:
            break
        visited[u]=True

        for i in range(n):
            if visited[i]==True or G[u][i]==-1:
                continue
            if G[u][i]<cost[i]:
                cost[i]=G[u][i]
                pi[i]=u
    print(sum(cost))
    
if __name__=="__main__":
    n=int(input())
    G=[]
    for i in range(n):
        G.append(list(map(int,input().split())))
    prim(n,G)

Measured memory_bytes: 7852
function main(input){
    let args = input.split(" ").map(item=>parseInt(item));
    if(args[0]<args[1] && args[1]<args[2]){
        console.log("Yes");
    }else{
        console.log("No");
    }
    
}

main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 15120
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu


h, w = [int(i) for i in input().split()]
s = [[0 for _ in range(w + 2)] for _ in range(h + 2)]
table = [[0 for _ in range(w + 2)] for _ in range(h + 2)]

for i in range(h):
    _s = input()
    s[i + 1][1:1+w] = [_s[i] for i in range(len(_s))]

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == "#":
            table[i + 1][j - 1] += 1
            table[i + 1][j] += 1
            table[i + 1][j + 1] += 1
            table[i][j + 1] += 1
            table[i][j - 1] += 1
            table[i - 1][j - 1] += 1
            table[i - 1][j] += 1
            table[i - 1][j + 1] += 1
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == "#":
            table[i][j] = "#"
for i in range(1, h + 1):
    print(listToString(table[i][1:w+1]))


Measured memory_bytes: 3192
package main
import "fmt"

func main() {
	var d, n int
	fmt.Scan(&d)
	fmt.Scan(&n)
  if (n == 100) {
		n++;
	}
  if (d == 0) {
      fmt.Println(n)
  }
  if (d == 1) {
      fmt.Println(n*100)
  }
  if (d == 2) {
      fmt.Println(n*10000)
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    string ans = "";

    for(int i=0; i<s.size(); i++){
        if(i%2 == 0) ans += s[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
ll tas(ll x, ll y) { return (x + y) % MOD; }
ll hik(ll x, ll y) { return (x + MOD - (y % MOD)) % MOD; }
ll kak(ll x, ll y) { return ((x % MOD) * (y % MOD)) % MOD; }
ll power(ll x, ll y) {
	if (y == 0) {
		return 1;
	}
	else if (y == 1) {
		return x % MOD;
	}
	else if (y % 2 == 0) {
		ll pow = power(x, y / 2);
		return (pow * pow) % MOD;
	}
	else {
		ll pow = power(x, y / 2);
		return (((pow * pow) % MOD) * x) % MOD;
	}
}
ll war(ll x, ll y) { return kak(x, power(y, MOD - 2)); }

int main() {
	int n; cin >> n;
	VI d(n);
	REP(i, n) cin >> d[i];
	if (d[0] != 0) {
		cout << 0;
		return 0;
	}
	VI a(n, 0); ll ans = 1;
	REP(i, n) a[d[i]]++;
	if (a[0] != 1) {
		cout << 0;
		return 0;
	}
	for (int i = 1; i < n; i++) {
		if (a[i - 1] == 0 && a[i] != 0) {
			cout << 0;
			return 0;
		}
		ans = kak(ans, power(a[i - 1], a[i]));
	}
	cout << ans % MOD;
}

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

int main(){
        string s;
        cin >> s;

        string ans="Yes" ;

        for (int i = 0; i < 4; ++i){
                int c = 0;
                for (int j = 0; j < 4; ++j){
                        if (s[i]==s[j]) c += 1 ;
                }
                if (c != 2) {
                        ans="No";
                }
        }
        cout << ans << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);
    color[r] = c;
    while (!S.empty()) {
        int u = S.top();S.pop();
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            if (color[v] == NIL) {
                color[v] = c;
                S.push(v);
            } 
        }
    }
}

void assignColor() {
    int id = 1;
    for (int i = 0; i < n; i++) color[i] = NIL;
    for (int u = 0; u < n; u++) {
        if (color[u] == NIL) dfs(u, id++);
    }
}

int main() {
    int s, t, m, q;

    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> s >> t;
        if (color[s] == color[t]) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8956
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		
		for(int i = 0; i < num; i ++ ){
			insertionSort(num, scanner);
		}
		
		scanner.close();
	}
	
	public static void output(int[] array, int num){
	   //出力
	   StringBuilder sb = new StringBuilder("");
	   sb.append(array[0]);
	   for (int i = 1; i < num; i++) {
		  sb.append(" ").append(array[i]);
	   }
		System.out.println(sb);
	}
	
	public static void insertionSort(int num,  Scanner scanner){
		int off = scanner.nextInt();		//いらないけど仕方ない
		int ope_num = scanner.nextInt();
		int[] array = new int[num];
		
		for(int i = 0; i < ope_num; i ++ ){
			array[scanner.nextInt() - 1] = 1;
		}
		output(array, num);
	}
}


Measured memory_bytes: 29968
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	int n,m;
	cin>>n>>m;
	map<int,vector<int> > f;
	rep(i,0,n){
		int x,y;
		cin>>x>>y;
		f[x].pb(y);
	}
	priority_queue<int> pq;
	int ans=0;
	rep(i,1,m+1){
		for(int j:f[i]){
			pq.push(j);
		}
		if(sz(pq)){
			ans+=pq.top();
			pq.pop();
		}
	}
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 10880
n, m, k = [int(i) for i in input().split()]
ro = [-1] * n
r = [0] * n
co = [1] * n
ab = []
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    ab.append([a, b])
    while ro[a] != -1:
        a = ro[a]
    while ro[b] != -1:
        b = ro[b]
    if a != b:
        if r[a] > r[b]:
            ro[b] = a
            r[a] = max(r[a], r[b] + 1)
            co[a] += co[b]
        else:
            ro[a] = b
            r[b] = max(r[b], r[a] + 1)
            co[b] += co[a]
ans = []
for i in range(n):
    while ro[i] != -1:
        i = ro[i]
    ans.append(co[i]-1)
for a, b in ab:
    ans[a] -= 1
    ans[b] -= 1

for _ in range(k):
    c, d = [int(i) - 1 for i in input().split()]
    e, f = c, d
    while ro[c] != -1:
        c = ro[c]
    while ro[d] != -1:
        d = ro[d]
    if c == d:
        ans[e] -= 1
        ans[f] -= 1


print(" ".join(list(map(str, ans))))


Measured memory_bytes: 110808
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int n,f[N];
int main()
{
	scanf("%d",&n);
	for (int i=2,x;i<=n;i++) scanf("%d",&x), f[x]++;
	for (int i=1;i<=n;i++) printf("%d\n",f[i]);
}

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

int main(){
	int N;
    double x;
    string u;
  	double sum=0.0;
  
  	cin >> N;
    for (int i=0;i<N;i++){
        cin >> x >> u;      	
      
      	if(u=="JPY"){
        	sum += x;
        }else{
        	sum += 380000*x;	
        }
    }  
  	cout << sum << endl;
  
    return 0; 
}

Measured memory_bytes: 256
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

n = parseInt(require('fs').readFileSync(config.input, 'ascii'), 10);

fib = new Array(n + 1);
fib[0] = 1;
fib[1] = 1;
for (i = 2; i <= n; i++) fib[i] = fib[i-1] + fib[i-2];
console.log(fib[n]);

Measured memory_bytes: 15508
let rec range a b = if a >= b then [] else a :: range (a+1) b
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let g = Array.init n (fun _ -> []) in
  for _ = 1 to m do
    Scanf.scanf " %d %d" @@ fun x y -> g.(x-1) <- y-1 :: g.(x-1)
  done;
  let dp = Array.make n (-1) in
  let rec f v =
    if dp.(v) >= 0 then dp.(v)
    else begin
      let l = 1 + List.fold_left (fun s w -> max s (f w)) (-1) g.(v) in
      dp.(v) <- l;  l
    end
  in
  range 0 n |> List.fold_left (fun s i -> max s (f i)) 0
  |> Printf.printf "%d\n"


Measured memory_bytes: 15744
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextLong()
    val a = (0 until n).map { Class016c(sc.next().toInt(), sc.next().toInt()) }
    println(problem061c(n, k, a))
}

fun problem061c(n: Int, k: Long, a: List<Class016c>): Int {
    val a2 = a.sortedBy { it.a }
    var k2 = k
    var ans = 0
    for (i in 0 until n) {
        val tmp = a2[i].b
        if (tmp < k2) {
            k2 -= tmp
        } else {
            ans = a2[i].a
            break
        }
    }
    return ans
}

data class Class016c(var a: Int, var b: Int)

Measured memory_bytes: 76532
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

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

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

func main() {
	n, a, b, c := nextInt(), nextInt(), nextInt(), nextInt()
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = nextString()
	}

	nums := []int{a, b, c}
	ans := make([]rune, 0)
	for i, v := range s {
		left := rune(v[0]) - 'A'
		right := rune(v[1]) - 'A'
		if nums[left] == 0 && nums[right] == 0 {
			fmt.Println("No")
			return
		}
		if i != len(s)-1 && v != s[i+1] && nums[left] == 1 && nums[right] == 1 {
			next := s[i+1]
			nextLeft := rune(next[0]) - 'A'
			nextRight := rune(next[1]) - 'A'
			if left == nextLeft || left == nextRight {
				nums[left]++
				nums[right]--
				ans = append(ans, 'A'+rune(left))
			} else {
				nums[left]--
				nums[right]++
				ans = append(ans, 'A'+rune(right))
			}
		} else if nums[left] >= nums[right] {
			nums[left]--
			nums[right]++
			ans = append(ans, 'A'+rune(right))
		} else {
			nums[left]++
			nums[right]--
			ans = append(ans, 'A'+rune(left))
		}
	}
	fmt.Println("Yes")
	for _, v := range ans {
		fmt.Printf("%c\n", v)
	}
}


Measured memory_bytes: 6108
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 入力
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();

        StringBuffer tmp = new StringBuffer();
        for (int i = 0; i < n; i++) {
            tmp.append(s.charAt(i));
            tmp.append(t.charAt(i));
        }
        String out = tmp.toString();

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 22228
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <regex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int n,m,x;
    cin >> n >> m >> x;
    int left = 0,right = 0;
    for (int i = 0; i < m; i++) {
        int tmp;
        cin >> tmp;
        if (tmp > x) {
            right++;
        }
        else if(tmp < x) {
            left++;
        }
    }
    cout << min(left,right) << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.math.*;
class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		BigInteger ret=new BigInteger("0");
		while(s.hasNext()){
			String str=s.next();
			String [] a=str.split("[^0-9]");
			for(int i=0;i<a.length;i++){
				if(a[i].length()>0)ret=ret.add(new BigInteger(a[i]));
			}
		}
		System.out.println(ret.toString());
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t n; cin >> n;
	int64_t ans = 0;
	for(int64_t i = 1; i <= n; ++i) {
		if(i % 3 == 0 or i % 5 == 0) continue;
		ans += i;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3624
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (mut n, _): (usize, usize) = parse_line().unwrap();
    let d: Vec<String> = parse_line().unwrap();

    loop {
        let s = n.to_string();
        let mut denied = false;
        for t in d.iter() {
            if s.contains(t) {
                denied = true;
            }
        }
        if !denied {
            break;
        }
        n += 1;
    }
    println!("{}", n);
}


Measured memory_bytes: 2180
n,k = map(int,input().split())
mod = 10**9 + 7
combo1 = 1
combo2 = 1
p = 0
for i in range(1,k+1):
    if n-k >= i - 1:
        if i > 1:
            combo1 = combo1*(k-i+1)//(i-1)
            combo2 = combo2*(n-k+2-i)//i
        else:
            combo1 = 1
            combo2 = combo2*(n-k+2-i)//i
        print((((combo1)%mod)*((combo2)%mod))%mod)
        #print(combo1,combo2)
    else:
        p = i
        break
if p > 0:
    for i in range(k-p+1):
        print(0)

Measured memory_bytes: 3316
#include <math.h>
#include <stdio.h>
#define p2(x) ((x)*(x))
#define mul(rx,ry,x1,y1,x2,y2) ((rx)=(x1)*(x2)-(y1)*(y2),(ry)=(x2)*(y1)+(x1)*(y2))
#define R 1
double X[300],Y[300],hyp,t,pl,dx,dy,x[2],y[2];
int main(){int N,M,m,i,j,k,z;for(;scanf("%d",&N),N;printf("%d\n",M)){
	for(i=0;i<N;i++)scanf("%lf%lf",X+i,Y+i);
	for(M=1,i=0;i<N;i++)for(j=i+1;j<N;j++){
		hyp=hypot(X[j]-X[i],Y[j]-Y[i]);
		if(hyp>2*R)continue;
		//t=( p2(R)-p2(R)+p2(hyp) )/( 2*hyp );
		t=hyp/2;
		pl=sqrt(p2(R)-p2(t));
		dx=(X[j]-X[i])/hyp;
		dy=(Y[j]-Y[i])/hyp;
		mul(x[0],y[0],dx,dy,t,pl);
		mul(x[1],y[1],dx,dy,t,-pl);
		for(z=0;z<2;z++){
			x[z]+=X[i],y[z]+=Y[i];
			for(m=k=0;k<N;k++)if(p2(X[k]-x[z])+p2(Y[k]-y[z])<p2(R)+1e-9)m++;
			if(M<m)M=m;
		}
	}
}return 0;}

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

long long N, S, A[1 << 18], B[1 << 18];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) { cin >> A[i]; A[i] *= -1; }
	for (int i = 1; i <= N; i++) {
		int pos1 = lower_bound(B, B + S, A[i] + 1) - B;
		if (pos1 == S) { S++; }
		B[pos1] = A[i];
	}
	cout << S << endl;
	return 0;
}

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

int main(){
    int H, W;
    while(true){
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 0; i < H; ++i){
            for(int j = 0; j < W; ++j){
                if(i == 0 || i == H - 1 || j == 0 || j == W - 1 ) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>

int main(){
	
	
	char day[15];
	
	scanf("%s",day);
	
	if(day[0]=='M' && day[1]=='O' && day[2]=='N'){
		printf("6\n");
	}	
	
	if(day[0]=='T' && day[1]=='U' && day[2]=='E'){
		printf("5\n");
	}
	
	if(day[0]=='W' && day[1]=='E' && day[2]=='D'){
		printf("4\n");
	}
	
	if(day[0]=='T' && day[1]=='H' && day[2]=='U'){
		printf("3\n");
	}
	
	if(day[0]=='F' && day[1]=='R' && day[2]=='I'){
		printf("2\n");
	}
	if(day[0]=='S' && day[1]=='A' && day[2]=='T'){
		printf("1\n");
	}
	if(day[0]=='S' && day[1]=='U' && day[2]=='N'){
		printf("7\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	string s;
	cin >> s;
	int flag = 0;

	for(int i =0; i < s.size();i++){
		if(flag == 0){
			if(s[i] == 'C')flag =1;
		}else{
			if(s[i] == 'F'){
				cout << "Yes" <<endl;
				return 0;
			}
		}
	}
	cout <<"No" <<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element



//---------- 1000000007 ----------
const int MOD = 1000000007;
int m_add(int a, int b)
{
	return (a + b) % MOD;
}
int m_sub(int a, int b)
{
	return (a + MOD - b) % MOD;
}
int m_mul(int a, int b)
{
	return (a * b) % MOD;
}
int m_pow(int x, int n)
{
	if (n == 0) return 1;
	ll res = m_pow((x * x) % MOD, n / 2);
	if (n & 1) res = (res * x) % MOD;
	return res;
}
int m_divide(int a, int b)
{
	return m_mul(a, m_pow(b, MOD - 2));
}
int m_comb(int n, int r)
{
	int i;
	int p = 1;
	for (i = 1; i <= r; i++)
	{
		p = m_mul(p, (n - i + 1));
		p = m_divide(p, i);
	}
	return p;
}
int m_comb_with_rep(int n, int r)
{
	return m_comb(n + r - 1, r);
}



int N, M;
int dp[100010];
bool flg[100010];

signed main()
{
	int a[5];
	int k;
	REP(i, 5) cin >> a[i];
	cin >> k;
	for (int i = 0; i < 5; i++)
	{
		for (int j = i + 1; j < 5; j++)
		{
			if (abs(a[i] - a[j]) > k)
			{
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include<assert.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    bool p = 1, s = 1;

    set<int> st;
    rep(i, 0, n) {
        int q = a[i];
        for (int j = 2; j * j <= q; j++) {
            if (q % j == 0) {
                //if (*st.find(j) == j) {
                if(st.count(j)>0){
                    p = 0;
                    break;
                }
                st.insert(j);
                while (q % j == 0) {
                    q /= j;
                }
            }
        }
        assert(q>=1);
        if (q != 1) {
            //assert((*st.find(q)==q)==(st.count(q)>0));
            //if (*st.find(q) == q) p = 0;
            //if(st.count(q)>0)p=0;
            if(st.find(q)!=st.end())p=0;
        }
        st.insert(q);
        if (!p) break;
    }

    // for (auto p : st) cout << p << " ";

    int now = a[0];
    rep(i, 0, n) { now = gcd(now, a[i]); }
    if (now != 1) s = 0;

    if (p) {
        cout << "pairwise coprime\n";
    } else if (s) {
        cout << "setwise coprime\n";
    } else {
        cout << "not coprime\n";
    }
}


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

class data {
public:
  int p[5]={1868,1912,1926,1989,2017};
  char c[4]={'M','T','S','H'};
};
int main() {
  int E, Y;
  cin >> E >> Y;
  data d;
  if (E==0) {
    int idx;
    for (int i=0; i<4; i++) {
      if (d.p[i]<=Y && Y<d.p[i+1]) {
        idx = i;
        break;
      }
    }
    printf("%c%d\n", d.c[idx], Y-d.p[idx]+1);
  } else {
    printf("%d\n", Y+d.p[E-1]-1);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    cout << ((e - a > k) ? ":(" : "Yay!") << '\n';
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[200000], b[200000];
ll sumA[200010]= {0},sumB[200010]= {0};

ll mx(ll x, ll y)
{
    if(x>y)
        return x;
    else
        return y;
}
int main()
{
    int  n,m;
    ll k,ans;
    cin >> n >> m >> k;
    for(int i=0; i<n; ++i)
    {
        cin >> a[i];
        sumA[i+1] = sumA[i]+(ll)a[i];
    }
    for(int i=0; i<m; ++i)
    {
        cin >> b[i];
        sumB[i+1] = sumB[i]+(ll)b[i];
    }
    ans=0;
    int j=m;
    for(int i=0; i<=n; ++i)
    {
        if(sumA[i]>k)
            break;
        while(sumA[i]+sumB[j]>k)
            --j;
        ans=mx(i+j, ans);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9888
#include <bits/stdc++.h>
using namespace std;
char s1[305], s2[305];
int len1, len2, tp1, tp2;
int main(){
    while(1){
       // puts("INN");
        scanf("%s",s1);
        if(s1[0]=='.')break;
        scanf("%s",s2);
        len1 = strlen(s1);
        len2 = strlen(s2);
        if(len1 == len2){
            for(int i = 0 ;i < len1 ;i++){
                if(s1[i] != s2[i]) goto BYY;
            }
        }else{
            goto BYY;
        }
        puts("IDENTICAL");
        continue;
        BYY:;
        tp1 = tp2 = 0;
        int gg = 0;
        while(tp1 != len1 || tp2 != len2){
//            printf("qwq %d %d\n",tp1,tp2);
            if(s1[tp1] != s2[tp2]){
                puts("DIFFERENT");
                goto BYEE;
            }
            if(s1[tp1] == '"' && s2[tp2]=='"'){
                int t1,t2;
                for(t1 = tp1+1;s1[t1]!= '"' ;t1++ ) ;
                for(t2 = tp2+1;s2[t2]!= '"' ;t2++ ) ;
                bool flag = false;
                if(t1-tp1 == t2-tp2){
                    for(int i = tp1 ; i <= t1 ; i++){
                        if(s1[tp1++]!=s2[tp2++]){
                            flag = true;
                            break;
                        }
                    }
                }else{
                    flag = true;
                }
                if(flag)gg++;
                tp1 = t1+1;
                tp2 = t2+1;
                if(gg>1){
                    puts("DIFFERENT");
                    goto BYEE;
                }
            }else{
                tp1++,tp2++;
            }


        }
        if(gg==1)puts("CLOSE");
        BYEE:;

    }
}

Measured memory_bytes: 3068
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int ans=0;
  int buf=1;
  while(1){
    if(buf<b){
      buf+=a-1;
      ans++;
    }
    else break;
  }
  if(b==1) ans=0;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
/*
author: diradon
25-Aug-19
18:02:50
*/

#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    cin >> n;
    int a[n+5][3];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            cin >> a[i][j];
    
    for (int i = 1; i < n; i++)
    {
        a[i][0] += max(a[i-1][1], a[i-1][2]);
        a[i][1] += max(a[i-1][0], a[i-1][2]);
        a[i][2] += max(a[i-1][0], a[i-1][1]);
    }

    cout << max(a[n-1][0], max(a[n-1][1], a[n-1][2])) << "\n";
}

Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
    int n,a[200001],flag[200001]={};
    vector<int> v;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=n;i>=1;i--){
        int cnt=0;
        for(int j=i;j<=n;j+=i){
            cnt+=flag[j];
        }
        if(cnt%2!=a[i]){
            flag[i]=1;
            v.push_back(i);
        }
    }
    if(!v.empty()){
        sort(v.begin(),v.end());
    }
    printf("%ld\n",v.size());
    for(int i=0;i<v.size();i++){
        printf("%d ",v[i]);
    }
    if(!v.empty()){
        printf("\n");
    }
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N = 2e5 + 5, MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, h[N], dp[N];

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

    cin>>n;
    for(int i = 1; i <= n; i++) cin>>h[i];

    for(int i = 2; i <= n; i++){
        if(h[i] <= h[i - 1])    dp[i] = dp[i - 1] + 1;
    }

    cout<<*max_element(dp + 1, dp + n + 1);



    return 0;
}


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


void solve () {
    int n;
    cin >> n;
    vector<unordered_map <int, int>> a(2);
    for  (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[i & 1][x]++;
    }
    vector<pair<int, int>> even, odd;
    even.push_back({0, 0});
    odd.push_back({0, 0});
    for (auto p : a[0]) {
        even.push_back({p.second, p.first});
    }
    for (auto p : a[1]) {
        odd.push_back({p.second, p.first});
    }
    sort(even.begin(), even.end(), greater<pair<int, int>>());
    sort(odd.begin(), odd.end(), greater<pair<int, int>>());
    int ans = 1e5;
    n /= 2;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            int plus = 0;
            if(even[i].second == odd[j].second) {
                plus = 1e5;
            }
            ans = min (ans, plus + (n - even[i].first) + (n - odd[j].first));
        }
    }
    cout << ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10000
#define STRLEN 20

int main(void){
    int row, col, n=0, count, ans = 0;
    scanf("%d %d %d", &col, &row, &n);
    char a[7][7];
    for(int i=0;i < col;i++){
            scanf("%s", a[i]);
    }


    for(int h=0;h < 1<<col;h++){
        for(int w=0; w < 1<<row;w++){
            count = 0;
            for(int i=0; i < col; i++){
                if((h>>i) % 2 == 1) continue;
                for(int l=0; l < row; l++){
                    if((w>>l) % 2 == 1) continue;
                    if(a[i][l] == '#') count++;
                }
            }
            if (count == n) ans++;
        }
    }

    printf("%d\n", ans);
    return 0;

}


Measured memory_bytes: 1736
from itertools import permutations


def check(queen):
    for r1, c1 in queen:
        for r2, c2 in queen:
            if r1 == r2 and c1 == c2:
                break
            if r1 == r2:
                return False
            if c1 == c2:
                return False
            if r1 + c1 == r2 + c2:
                return False
            if r1 - c1 == r2 - c2:
                return False
    return True


k = int(input())
row, col = list(range(8)), list(range(8))
queen = []
for _ in range(k):
    r, c = map(int, input().split())
    queen.append((r, c))
    row.remove(r)
    col.remove(c)

for l in permutations(col):
    queen_tmp = queen[:]
    for r, c in zip(row, l):
        queen_tmp.append((r, c))
    if check(queen_tmp):
        board = [''.join('Q' if (r, c) in queen_tmp else '.' for c in range(8)) for r in range(8)]
        print(*board, sep='\n')
        break


Measured memory_bytes: 5664
S = list(input())

S2 = S.copy()

counter = 0
counter2 = 0

switch = True
for i in range(len(S)):
    if switch:
        if S[i] == '1':
            S[i] = '0'
            counter+=1
        
        if S2[i] == '0':
            S2[i] = '1'
            counter2+=1

    else:
        if S[i] == '0':
            S[i] = '1'
            counter+=1
        
        if S2[i] == '1':
            S2[i] = '0'
            counter2+=1

    if switch:
        switch = False
    else:
        switch = True

if counter < counter2:
    print(counter)
else:
    print(counter2)




Measured memory_bytes: 4652
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
char a[50][50];
char b[50][50];
int main() {
    int N,M;
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    for(int i=0;i<M;i++){
        cin>>b[i];
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cnt=0;
        for(int k=0;k<M;k++){
            for(int l=0;l<M;l++){
                if(b[k][l]==a[i+k][j+l]) {
                    cnt++;
            }    
        }
        }
        if(cnt==M*M) {cout<<"Yes"<<endl;
        return 0;}
    }
    }
     cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int N, M;
	cin >> N >> M;

	vector<string> A(N), B(M);
	inputVector(A, N);
	inputVector(B, M);

	bool ok = false;
	rep(y, N - M + 1) {
		rep(x, N - M + 1) {
			bool flag = true;
			rep(ay, M) rep(ax, M) {
				flag &= A[y + ay][x + ax] == B[ay][ax];
			}
			ok |= flag;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256