akhauriyash/Code-Regression huggingface dataset:
/*
 * Author:  vawait
 * Created Time:  六  4/22 01:16:03 2017
 * File Name: a.cpp
 */
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define red(i, a, b) for (int i = (a); i >= (b); --i)
#define clr( x , y ) memset(x,y,sizeof(x))
#define sqr(x) ((x) * (x))
#define mp make_pair
#define pb push_back
#define db pop_back
typedef long long lint;
const int maxn = 101000;
int n , a[maxn];

void init()
{
    rep(i,1,n) scanf("%d",&a[i]);
}

void work()
{
    int x , k = -1, sum = 1;
    rep(i,2,n) {
        if ( a[i] == a[i-1] ) continue;
        x = a[i] > a[i-1];
        if ( k >= 0 && x != k ) {
            sum ++;
            k = -1;
        } else {
            k = x;
        }
    }
    printf("%d\n",sum);
}

int main()
{
    while ( cin >> n ) {
        init();
        work();
    }
    return 0;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 2e5+5;
const int M = 1e5+5;
string s;
vector<int> v[N];
int n;
ll a[N];

class UnionFind {
  int par[N]; // 親
  int rank[N]; // 木の深さ
  unsigned size_;
public:
  void init(int n) {
    for (int i=0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  unsigned size() {return size_;}
  // 木の根を求める
  int find(int x) {
    if(par[x] == x) {
     return x;
    } else {
     return par[x] = find(par[x]);
    }
  }
  // xとyの属する集合を併合
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
    }
  }
  // xとyが同じ集合に属するかいなか
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int m,x,y;
int p[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  UnionFind uf;
  cin >> n >> m;
  uf.init(n);
  rep(i,n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i,m) {
    cin >> x >> y;
    // cout << x << " ; " << y << endl;
    uf.unite(x-1,y-1);
  }
  int count = 0;
  rep(i,n) {
    // cout << i << " : " << p[i] << endl;
    // cout << uf.find(i) << " : " << uf.find(p[i]) << endl;
    if(uf.same(i, p[i])) count++;
  }
  cout << count << endl;
}


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

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

using namespace std;

int main(){
	int a,b; cin>>a>>b;
	if((a+b)%2==0) cout<<(a+b)/2<<endl;
	else           cout<<"IMPOSSIBLE"<<endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        struct rectangle
        {
            public long height, pos;
            public rectangle(long h, long p) { height = h; pos = p; }
        }
        static long getLargestRectangle(long[] buffer)
        {
            var s = new Stack<rectangle>();
            int size = buffer.Length;
            var maxv = 0L;

            for (var i = 0; i <= size; ++i)
            {
                var rect = new rectangle(0, i);
                if (i != size)
                    rect.height = buffer[i];
                if (s.Count == 0)
                { s.Push(rect); }
                else
                {
                    if (s.Peek().height < rect.height)
                    { s.Push(rect); }
                    else if (rect.height < s.Peek().height)
                    {
                        long target = i;
                        while (s.Count != 0 && rect.height <= s.Peek().height)
                        {
                            var pre = s.Pop();
                            var area = pre.height * (i - pre.pos);
                            maxv = Math.Max(maxv, area);
                            target = pre.pos;
                        }
                        rect.pos = target;
                        s.Push(rect);
                    }
                }
            }
            return maxv;
        }
        static long getLargestRectangle(long[,] buffer)
        {
            var H = buffer.GetLength(0);
            var W = buffer.GetLength(1);
            var T = new long[H][];
            for (var i = 0; i < H; ++i)
                T[i] = new long[W];
            for (var j = 0; j < W; ++j)
            {
                for (var i = 0; i < H; ++i)
                {
                    if (0 != buffer[i, j])
                        T[i][j] = 0;
                    else
                        T[i][j] = 0 < i ? T[i - 1][j] + 1 : 1;
                }
            }
            var maxv = 0L;
            for (var i = 0; i < H; ++i)
                maxv = Math.Max(maxv, getLargestRectangle(T[i]));
            return maxv;
        }

        static void Main(string[] args)
        {
            var HW = Sarray();
            var H = HW[0];
            var W = HW[1];
            
            var hwinfo = new long[H , W];
            for (var i = 0; i < H; ++i)
            {
                var c = Sarray();
                for (var j = 0; j < W; ++j)
                    hwinfo[i, j] = c[j];
            }
            WriteLine(getLargestRectangle(hwinfo));
        }
    }
}


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

using namespace std;

int main(){
	cin.tie(0);
  	ios::sync_with_stdio(false);
  	int d = 0, n = 0;
  	long long power = 0;
  	cin >> d >> n;
  	if(n == 100)
		n += 1;
    switch(d){
      case 0: power = 1; break;
      case 1: power = 100; break;
      case 2: power = 10000;
    }
  	
  	cout << power*n << endl;
	return 0;
}

Measured memory_bytes: 3628
import itertools


n = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
c = []
for i in range(1,n+1):
    c.append(i)
p_list = list(itertools.permutations(c, n))
c = p_list.index(tuple(q))
d = p_list.index(tuple(p))

print(abs(c-d))

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


int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<char>> a(n,vector<char>(n));
    vector<vector<char>> b(n,vector<char>(n));
    rep(i,n){
        rep(j,n){
            cin >> a[i][j];
        }
    }
    rep(i,m){
        rep(j,m){
            cin >> b[i][j];
        }
    }
    bool exist = false;
    rep(ly,n){
        rep(lx,n){
            if(ly + m > n || lx + m > n){
                continue;
            }
            bool match = true;
            rep(y,m){
                rep(x,m){
                    if(a[ly+y][lx+x] != b[x][y]) match = false;
                }
            }
            if(match){
                exist = true;
            }
        }
    }
    if(exist) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{	
	public static void main(String arg[])
	{
		Scanner in =new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int a[]=new int[n];
			double b[]=new double[n];
			for(int i=0;i<n;i++)
			{
				a[i]=in.nextInt();
				double h=in.nextDouble()/100;
				double w=in.nextDouble();
				b[i]=w/(h*h);
			}
			double ans =Integer.MAX_VALUE;
			int index=0;
			for(int i=0;i<n;i++)
			{
				double tmp =Math.abs(22-b[i]);
				if(ans>tmp)
				{
					ans =tmp;
					index=i;
				}
			}
			System.out.println(a[index]);
		}
	}
}

Measured memory_bytes: 13000
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int n,r;cin>>n>>r;
  if(n>9) p(r);
  else p(r+100*(10-n));
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=200005;
int n,m,ans,a[N],tong[N],sum[N];
int main(){
	n=read(); m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)tong[a[i]]++;
	for(int i=1;i<=n;i++)for(int j=i-tong[i]+1;j<=i;j++)if(j>0)sum[j]++;
	for(int i=1;i<=n;i++)if(sum[i]==0)ans++;
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		if(a[x]-tong[a[x]]+1>0&&--sum[a[x]-tong[a[x]]+1]==0)ans++; tong[a[x]]--;
		a[x]=y; 
		tong[a[x]]++; if(a[x]-tong[a[x]]+1>0&&++sum[a[x]-tong[a[x]]+1]==1)ans--;
		writeln(ans);
	}
}

Measured memory_bytes: 3712
#include<iostream>
using namespace std;
 
int main()
{
  int n,a,v,maxa=-1,maxv=-1;
 
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>v;
    if(maxv<v){
      maxa=a;
      maxv=v;
    }
    else if(maxv==v && a<maxa){
      maxa=a;
      maxv=v;
    }
  }
  cout<<maxa<<" "<<maxv<<endl;
  return 0;
}


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

int main(){
    double l; cin>>l;
    double ans=pow(l/3,3);
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt() - 1;
        }
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            int a = array[i];
            int b = array[a];
            
            if (b == i) count++;
        }
        System.out.println(count / 2);
    }
}


Measured memory_bytes: 49264
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for (int(i) = a; (i) < (b); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define FFOR(i, a, b) for (int(i) = a; (i) > (b); --(i))
#define rrep(i, n) FFOR(i, 0, n)
#define vsort(v) sort((v).begin(), (v).end());           //小さい順
#define rvsort(v) sort(v.begin(), v.end(), greater<>()); //大きい順
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define all(c) (c).begin(), (c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout << (p) << endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 123456789012345
#define int ll
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn = 1e5 + 10;

// initialization here
//
int a[maxn];
//
// initialization finish

// your function is here
//
int pow(int a, int b) {

  int ans = 1;
  while (b) {
    if (b & 1)
      ans *= a % mod;
    ans %= mod;
    a *= a % mod;
    a %= mod;
    b >>= 1;
  }
  return ans;
}
//
// your function finished

signed main() {
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = n - 1; i >= 0; i -= 2) {
    if (i == 0) {
      if (a[i] != 1) {
        cout << 0 << endl;
        return 0;
      }
    } else {
      if (a[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  for (int i = n; i >= 0; i -= 2)
    if (a[i] != 0) {
      cout << 0 << endl;
      return 0;
    }
  int ans = 1;
  rep(i, n / 2) {
    ans = ans * 2 % mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
A = list(map(int, input().split()))
B=[0]*K
A+=B
dp=[10**100]*110000
dp[0]=0


for i in range(N):
    for j in range(1,K+1):
        dp[i+j]=min(dp[i+j],dp[i]+abs(A[i]-A[i+j]))
        #print(dp)

print(dp[N-1])

Measured memory_bytes: 53600
#include <iostream>
#include <algorithm>
#include <vector>
#include "cmath"
#include <cstdlib>

using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, W;

    cin >> N >> W;

    vector<ll> w(N);
    vector<ll> v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    // i番目、重さjのときの価値の最大
    vector<vector<ll> > dp(N, vector<ll>(W+1, 0));
    for (int j = w[0]; j < W + 1; j++) {
        dp[0][j] = v[0];
    }
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < W+1; j++) {
            dp[i][j] = j >= w[i] ? max(
                    dp[i-1][j],
                    dp[i-1][j - w[i]] + v[i]
            ) : dp[i-1][j];
        }
    }
    cout << dp[N-1][W] << endl;

    return 0;
}

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


int main(){
	string s, t;
	cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());

	if(s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
mod=10**9+7
def fact(n):
    ans=1
    for i in range(1,n+1):
        ans*=i
        ans%=mod
    return ans

x,y=map(int,input().split())
if (x+y)%3!=0: print(0)
else:
    temp=(x+y)//3
    if x<temp or x>2*temp: print(0)
    else:
        dx=x-temp
        fc_temp=fact(temp)
        fc_dx=fact(dx)
        fc_temp_dx=fact(temp-dx)
        fc_dx=pow(fc_dx,mod-2,mod)
        fc_temp_dx=pow(fc_temp_dx,mod-2,mod)
        ans=fc_temp*fc_dx%mod*fc_temp_dx%mod
        print(ans)

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

int main() {
	int a,b,c,d,e;
	cin >> a;
	c = 0;
	d = 0;
	for (int i = 1; i <= a; i++) {
		cin >> b;
		if (b > c) {
			d = c;
			c = b;
			e = i;
		} else if (b > d) {
			d = b;
		}
	}
	for (int j = 1; j <= a; j++) {
		if (j == e) {
			cout << d << endl;
		} else {
			cout << c << endl;
		}
	}
}


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

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

    vector<int> a(pow(10, 5) + 1, 0);
    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        a[d]++;
    }

    int X_count = 0;
    int last_index = a.size() - 1;
    for (int c = 0; c <= last_index; c++) {
        int count = a[c];
        if (c > 0) {
            count += a[c - 1];
        }
        if (c < last_index) {
            count += a[c + 1];
        }

        if (count > X_count) {
            X_count = count;
        }
    }

    cout << X_count << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdint>

using namespace std;

struct node_t {
  int64_t val;
  node_t *parent;
  node_t *left;
  node_t *right;
};

static node_t *root = nullptr;

static node_t *create_node(int64_t val, node_t *parent)
{
  node_t *node = new node_t;
  node->val = val;
  node->parent = parent;
  node->left = nullptr;
  node->right = nullptr;
  return node;
}

static void insert_node(node_t *node, int64_t val)
{
  if (val < node->val) {
    node_t *left = node->left;
    if (left != nullptr) {
      insert_node(left, val);
    } else {
      node->left = create_node(val, node);
    }
  } else {
    node_t *right = node->right;
    if (right != nullptr) {
      insert_node(right, val);
    } else {
      node->right = create_node(val, node);
    }
  }
}

void binary_search_tree_insert(int64_t val)
{
  if (root == nullptr) {
    root = create_node(val, nullptr);
  } else {
    insert_node(root, val);
  }
}

static void walk(node_t *node, void (*preorder)(int64_t), void (*inorder)(int64_t), void (*postorder)(int64_t))
{
  if (node == nullptr) return;

  if (preorder != nullptr) preorder(node->val);

  walk(node->left, preorder, inorder, postorder);
  if (inorder != nullptr) inorder(node->val);

  walk(node->right, preorder, inorder, postorder);
  if (postorder != nullptr) postorder(node->val);
}

void binary_search_tree_walk(void (*preorder)(int64_t), void (*inorder)(int64_t), void (*postorder)(int64_t))
{
  walk(root, preorder, inorder, postorder);
}

#if !defined(TEST)
#include <iostream>
#include <string>
#include <vector>

static vector<int64_t> pre;
static vector<int64_t> in;

static void print_vector(vector<int64_t> &vec)
{
  for (uint32_t i = 0; i < vec.size(); i++) {
    cout << " " << vec[i];
  }
  cout << endl;
}

static void preorder(int64_t val)
{
  pre.push_back(val);
}

static void inorder(int64_t val)
{
  in.push_back(val);
}

int32_t main()
{
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    string command;
    cin >> command;
    if (command[0] == 'i') {
      int64_t val;
      cin >> val;
      binary_search_tree_insert(val);
    } else if (command[0] == 'p') {
      pre.clear();
      in.clear();
      binary_search_tree_walk(preorder, inorder, nullptr);
      print_vector(in);
      print_vector(pre);
    }
  }

  return 0;
}
#endif

Measured memory_bytes: 34448
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,sum;
  sum=0;
  cin>>N;
  vector<int>vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<N-1;i++){
    sum+=vec.at(i);
  }
  if(sum>vec.at(N-1)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int N, K;

int main() {
    scanf("%d %d", &N, &K);

    double ansprobablewin = 0.0;
    
    for (int i = 1; i <= N; i++) {
        int countcoin = 0;
        while(1){
            if (pow(2.0, (double)countcoin)*i >= K) break;
            countcoin++;
        }
        ansprobablewin += 1.0 /(N*pow(2.0, (double)countcoin));
    }

    printf("%.10f\n", ansprobablewin);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

vector<int> G[SIZE],children[SIZE];
int N;
bool visited[SIZE],is_art_point[SIZE];
int visited_order[SIZE],parent[SIZE],lowest[SIZE],number;
ll sum_W;
ll W[SIZE],dp[SIZE];


void dfs(int current_node,int pre_node){
	visited_order[current_node] = lowest[current_node] = number;  //訪問順を記録
	number++;

	visited[current_node] = true;
	dp[current_node] = W[current_node];

	int next;

	for(int i = 0; i < G[current_node].size(); i++){

		next = G[current_node][i];

		if(!visited[next]){

			parent[next] = current_node;
			children[current_node].push_back(next);
			dfs(next,current_node);
			dp[current_node] += dp[next];
			lowest[current_node] = min(lowest[current_node],lowest[next]); //ボトムアップ的に、lowestが求まる
		}else if(visited[next] == true && next != pre_node){ //dfsTreeを遡る場合

			lowest[current_node] = min(lowest[current_node],visited_order[next]);
		}
	}
}

void func(){

	for(int i = 0; i < N; i++){

		visited[i] = false;
		is_art_point[i] = false;
		dp[i] = 0;
	}

	number = 1;
	dfs(0,-1);

	int tmp_parent,root_num = 0;

	vector<int> V;

	for(int i = 1; i < N; i++){

		tmp_parent = parent[i];
		if(tmp_parent == 0){

			root_num++;

		}else if(visited_order[tmp_parent] <= lowest[i]){

			V.push_back(tmp_parent);
		}
	}
	if(root_num >= 2){
		V.push_back(0);
	}
	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	for(int i = 0; i < V.size(); i++){
		is_art_point[V[i]] = true;
	}

	for(int i = 0; i < N; i++){

		if(!is_art_point[i]){

			printf("%lld\n",sum_W-W[i]);
			continue;
		}

		ll ans = 0;
		int child;

		if(i == 0){

			for(int k = 0; k < children[i].size(); k++){

				child = children[i][k];
				ans = max(ans,dp[child]);
			}

		}else{

			ll parent_sum = sum_W-dp[i];

			for(int k = 0; k < children[i].size(); k++){

				child = children[i][k];
				ans = max(ans,dp[child]);
				if(lowest[child] < visited_order[i]){ //親の成分と連結している子成分

					parent_sum += dp[child];
				}
			}

			ans = max(ans,parent_sum);
		}
		printf("%lld\n",ans);
	}
}


int main(){
	int E;

	scanf("%d %d",&N,&E);

	sum_W = 0;

	for(int i = 0; i < N; i++){

		scanf("%lld",&W[i]);
		sum_W += W[i];
	}

	int from,to;

	for(int i = 0; i < E; i++){
		scanf("%d %d",&from,&to);
		from--;
		to--;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	func();

	return 0;
}



Measured memory_bytes: 15968
#include <bits/stdc++.h>
#pragma GCC optmize("03")
#define boost ios::sync_with_stdio(); cin.tie(); cout.tie();
using namespace std;
typedef long long ll;
void solve()
{
    int a;
    cin >> a;
    cout << a + a*a+ a*a*a;
}

int main()
{
    boost
    //int t; cin >> t; while(t--)
    solve();
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int i;
	i=m-n+1;
	int j;
	j=m+n-1;
	for(int t=i;t<j;t++){
		printf("%d ",t);
	}
	printf("%d",j);
	return 0;
} 

Measured memory_bytes: 256
import sys

import numpy as np
TYPE_NUM = 26
DAYS = 2

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        temp_delta_satis = np.zeros([TYPE_NUM, TYPE_NUM], dtype=int)
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis[:, idx] = np.sum(-c*(d+1-last)) + val
            if D != d+1:
                for idx2 in range(TYPE_NUM):
                    val2 = s[d+1, idx2]
                    org2 = last[idx2]
                    last[idx2] = d+2
                    temp_delta_satis[idx2, idx] += np.sum(-c*(d+2-last)) + val2
                    last[idx2] = org2
            last[idx] = org
        opt_idx = np.unravel_index(np.argmax(temp_delta_satis), temp_delta_satis.shape)[1]
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()

Measured memory_bytes: 27500
N = int(input())
matrix = [[0,0,0,0,0,0,0,0,0,0] for _ in range(10)]
for i in range(1,N+1):
    first = int(str(i)[0])
    last = int(str(i)[-1])
    matrix[first][last] += 1
ans = 0
for i in range(10):
    for l in range(10):
        ans += matrix[i][l]*matrix[l][i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll n;
    cin >> n;
    map<string, ll> mp;
    ll ans = 0;
    for (ll i = 0; i < n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    for(auto i:mp){
        if (i.second >= 2) ans += (i.second) * (i.second - 1) / 2;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, M; cin >> N >> M;
    bool check[N+1] = {0};
    FOR(i,0,M-1){
        int A, B; cin >> A >> B;
        check[A] ^= 1;
        check[B] ^= 1;
    }
    bool ok = 1;
    FOR(i,1,N) ok &= !check[i];
    cout << (ok ? "YES" : "NO");
}



Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
#define EPS (1e-10)
#define equal(a,b) (fabs((a)-(b)) < EPS)
const int MAX = 1e5;

class Point{
public:
    double x,y;
    
    Point(double x = 0,double y = 0):x(x),y(y){}
    Point operator + (Point p){
        return Point(x+p.x,y+p.y);
    }
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
    Point operator * (double a){
        return Point(a*x,a*y);
    }
    
    double abs(){
        return sqrt(norm());
    }
    double norm(){
        return x*x+y*y;
    }
    bool operator < (const Point &p)const{
        return x != p.x ? x < p.x : y < p.y;
    }
    
    bool operator == (const Point &p){
        return equal(x,p.x)&&equal(y,p.y);
    }
};

typedef Point Vector;

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

double cross(Vector a,Vector b){
    return a.x*b.y - b.x*a.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw( Point p0 , Point p1 , Point p2 ){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if( cross(a,b) > EPS ) return COUNTER_CLOCKWISE;
    if( cross(a,b) < -EPS ) return CLOCKWISE;
    if( dot(a,b) < -EPS ) return ONLINE_BACK;
    if( a.norm() < b.norm() ) return ONLINE_FRONT;
    return ON_SEGMENT;
}

typedef vector<Point> Polygon;

Polygon andrewScan(Polygon s){
    Polygon u,l;
    
    if(s.size() < 3) return s;
    sort(s.begin(),s.end());
    
    u.push_back(s[0]);
    u.push_back(s[1]);
    l.push_back(s[s.size()-1]);
    l.push_back(s[s.size()-2]);
    
    for(int i = 2 ; i < s.size() ; i++){
        for(int n = u.size() ; n >=2 && ccw(u[n-2],u[n-1],s[i]) != CLOCKWISE; n--){
            u.pop_back();
        }
        u.push_back(s[i]);
    }
    
    for(int i = s.size()-3 ; i >= 0 ; i--){
        for(int n = l.size() ; n >=2 && ccw(l[n-2],l[n-1],s[i]) != CLOCKWISE; n--){
            l.pop_back();
        }
        l.push_back(s[i]);
    }
    
    reverse(l.begin(),l.end());
    
    for(int i = u.size() -2 ; i >= 1 ; i--){
        l.push_back(u[i]);
    }
    
    return l;
}

int main(){
    Point p1,p2,p3,p4;
    
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf"
                ,&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y,&p4.x,&p4.y) != EOF){
        Polygon pp;
        pp.push_back(Point(p1.x,p1.y)); pp.push_back(Point(p2.x,p2.y));
        pp.push_back(Point(p3.x,p3.y)); pp.push_back(Point(p4.x,p4.y));
        if(!(4-andrewScan(pp).size())) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cstring>
#include <iomanip>
#include <queue>
#include <deque>
#include <cmath>
using namespace std;
#define inf 280201280201280201
#define mn 100005
#define FLN "test"
#define int long long
typedef pair<int, int> ii;
//constance

//common data structures and templates
template<typename T>
struct SegmentTree{
};
//gb
int x, y;
//functions here
void input(){
}
void solve(){
}

//#define LOCAL 1

signed main(signed argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#ifdef LOCAL
	   freopen(FLN".inp", "r", stdin);
	   freopen(FLN".out", "w", stdout);
#endif
  cin >> x >> y;
  int ans = 0;
  while(x<= y){
    ++ans; 
    x<<=1;
  }
  cout << ans;
	return 0;
}


Measured memory_bytes: 632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int left = 1;
        int right = n;
        StringBuilder sb = new StringBuilder();
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < m; i++) {
            int a = right - left;
            int b = left - right + n;
            if (a == b || set.contains(a) || set.contains(b)) {
                right--;
            }
            set.add(a);
            set.add(b);
            sb.append(left).append(" ").append(right).append("\n");
            left++;
            right--;
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 63092
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    map<ll, ll> mp;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
        auto itr = mp.find(a[i]);
        if(itr == end(mp))mp[a[i]] = 1;
        else mp[a[i]]++;
    }
    sort(ALL(a), greater<ll>());
    ll ans = 0;
    rep(i, a.size()){
        if(mp[a[i]]<1)continue;
        rep(j, 35){
            if((1LL<<j)<a[i])continue;
            ll t = (1LL<<j)-a[i];
            auto itr = mp.find(t);
            if(itr!=end(mp)){
                if(t==a[i]){
                    if(mp[t]>1){
                        ans++, mp[t]--, mp[a[i]]--;
                        break;
                    }
                }
                else if(mp[t]>0){
                    ans++, mp[t]--, mp[a[i]]--;
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 14336
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2

    if n != 1:
        a.append(n)

    return a

N = int(input())
a = prime_factorize(N)
z = set()
cnt = 0

while len(a) > 0:
    num = a.pop(0)
    cursor = num
    while True:
        if num not in z:
            z.add(num)
            break
        elif len(a) <= 0:
            break
        elif cursor != a[0]:
            break
        num *= a.pop(0)

print(len(z))

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}


//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cou<<""<<endl;

int main(){
  int N,K;cin>>N>>K;
  vi d(K);vvi A(K);
  rep(i,K){
    cin>>d[i];
    rep(j,d[i]){
      int a;cin>>a;a--;
      A[i].push_back(a);
    }  
  }
  int cnt=0;
  vb bu(N);
  rep(i,N){
    bu[i]=false;
  }
  rep(i,K){
    rep(j,d[i]){
      bu[A[i][j]]=true;
    }
  }
  rep(i,N){
    if(!bu[i])cnt++;
  }
  cout<<cnt<<endl;

  
}






Measured memory_bytes: 3732
#include <cstdio>

int w[100002];

int main(int argc, char const *argv[])
{
    int n, k;
    scanf("%d %d\n", &n, &k);
    int l = 0, r = 0;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d\n", &w[i]);
        if (w[i] > l)
            l = w[i];
        r += w[i];
    }

    while (l < r)
    {
        int m = (l + r) / 2;
        int s = 0, c = 1;
        for (int i = 0; i < n; ++i)
        {
            s += w[i];
            if (s > m) {
                s = w[i];
                c++;
            }
        }
        if (c <= k)
            r = m;
        else
            l = m + 1;
    }

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

Measured memory_bytes: 1416
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int s,w;
    cin>>s>>w;
    if(s<=w)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
typedef long long ll;
string str;
ll alp[26], res;
int main(void){
    // Your code here!
    cin >> str;
    for (ll i = 0; i < str.length(); i++) {
        alp[str[i] - 'a']++;
    }
    res = 1;
    for (ll i = 0; i < 26; i++) {
        for (ll j = i + 1; j < 26; j++) {
            res += alp[i] * alp[j];
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 640
from collections import defaultdict
dic = defaultdict(int)
S = str(input())
N = len(S)
for i in range(N):
  dic[S[i]] += 1
#print(dic)

ans = 1 #もともと
L = list(dic.keys())
for i in range(len(L)):
  for j in range(i+1,len(L)):
    temp = dic[L[i]]*dic[L[j]]
    ans += temp
print(ans)

Measured memory_bytes: 73972
function Main(s) {
  var a = s[1].split(" ").map(a => parseInt(a));
  var min = Math.min(...a);
  var max = Math.max(...a);
  var ans = 1e9;
  for(var i = min; i <= max; i++){
    var cost = 0;
    for(var j = 0; j < a.length; j++){
      var n = i - a[j];
      cost += n * n;
    }
    if(ans > cost) ans = cost;
    else break;
  }
	console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s,s2="",s3="";
    cin>>s;
    for(int i=0;i<n/2;i++){
       s2+=s[i];
    }
    for(int i=n/2;i<n;i++){
       s3+=s[i];
    }
    if(s2==s3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::stdin;
use std::cmp::Ordering;

fn main() {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut ps = String::new();
    stdin().read_line(&mut ps).unwrap();
    let mut ps: Vec<usize> = ps.trim().split_whitespace().flat_map(str::parse).collect();
    let mut sc = 0;
    for i in 0..n {
        if i + 1 < ps[i] {
            sc += 1;
        }
    }

    if sc > 1 {
        println!("NO");
    } else {
        println!("YES");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int f(int x) {
    return x%2==0 ? x/2 : 3*x+1;
}
int main()
{
    int s;
    while (~scanf("%d", &s)) {
        
        int ans=0, n=1, cur=s;
        map<int,int> vis;
        vis[s] = 1;
        while (1) {
            cur = f(cur);
            n++;
            if (!vis[cur]) {
                vis[cur] = n;
            } else {
                ans = n;
                break;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time
    
    def getTime(self):
        return self.time
    
    def dispatch(self,qtm):
        self.time -= qtm

n, q = map(int,input().rstrip().split())
que = []
for i in range(n):
    name,time = map(str,input().rstrip().split())
    time = int(time)
    que.append(Task(name,time))

p = 0
while que:
    t = que.pop(0)
    if t.getTime() > q:
        p += q
        t.dispatch(q)
        que.append(t)
    else:
        p += t.getTime()
        print(t.name + " " + str(p))


Measured memory_bytes: 17252
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  printf("%d\n", (n - 1 + k - 2) / (k - 1));
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 105
int n,f[N][N],h[N],w[N],m;
int ksm(int x,int y)
{
	int s = 1;
    for(int i = y; i > 0; i >>= 1){
    	if(i & 1) s = 1ll * s * x % mod;
    	x = 1ll * x * x % mod;
	}
    return s;
}
 
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&h[i]),w[++m]=h[i];
    std::sort(w+1,w+m+1);
    m=std::unique(w+1,w+m+1)-w-1;
    for (int i=1;i<=n;i++) h[i]=std::lower_bound(w+1,w+m+1,h[i])-w;
    f[0][0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=h[i]+1;j<=h[i-1];j++) (f[i][0]+=f[i-1][j]*2%mod)%=mod;
        (f[i][0]+=f[i-1][0]*2%mod)%=mod;
        for (int j=1;j<=h[i];j++)
        {
            f[i][j]=(ll)f[i-1][j]*ksm(2,w[h[i]]-w[h[i-1]])%mod;
            if (h[i-1]>=j) continue;
            if (j>1) (f[i][j]+=(ll)f[i-1][0]*(ksm(2,w[j]-w[j-1])-1)%mod*2%mod*ksm(2,w[h[i]]-w[j])%mod)%=mod;
            else (f[i][j]+=(ll)f[i-1][0]*(ksm(2,w[j])-2)%mod*ksm(2,w[h[i]]-w[j])%mod)%=mod;
        }
    }
    int ans=0;
    for (int i=0;i<=m;i++) (ans+=f[n][i])%=mod;
    printf("%d",ans);
    return 0;
}

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

using namespace std;


int countRoots(vector<int> l, const vector<vector<int> >& em, int pos){
    int count = 0;
    if(l.size()==0) return 1;
    for(int i=0; i!= l.size(); i++){
        if(em[l.at(i)][pos]|| em[pos][l.at(i)]){
            vector<int> newl(l);
            newl.erase(newl.begin() + i);
            count += countRoots(newl, em, l.at(i));
        }
    }
    return count;
}
int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int> > em(N, vector<int>(N, 0));
    int t1, t2;
    for(int i=0; i!=M; i++){
        cin >> t1 >> t2;
        em.at(t1-1).at(t2-1)++;
    } 
    vector<int> left(N-1);
    iota(left.begin(), left.end(), 1);
    cout << countRoots(left, em, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int dp[3010][3010];

int main() {
  string s, t; cin >> s >> t;
  rep(i, s.size()) {
    rep(j, t.size()) {
      if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
      chmax(dp[i+1][j+1], dp[i+1][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  string res;
  int i = s.size(), j = t.size();
  while(i > 0 && j > 0) {
    if(dp[i][j] == dp[i-1][j]) i--;
    else if(dp[i][j] == dp[i][j-1]) j--;
    else {
      res = s[i-1] + res;
      i--;
      j--;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 35584
#include<iostream>
using namespace std;
int main(void){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
    return 0;
  }
  else if(a+b<c+d){
    cout<<"Right"<<endl;
    return 0;
  }
  cout<<"Balanced"<<endl;
  return 0;
}


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

signed main() {
	string s, t;
	while(cin >> s >> t){
	ll n = s.size(), m = t.size(), ans = 0;
	rep(h, n) {
		ll cnt = 0;
		rep(i, n + m) {
			if (h + i == n || i == m) { break; }
			if (s[h + i] == t[i]) { cnt++; }
			else { ans = max(ans, cnt); cnt = 0; }
		}
		ans = max(ans, cnt);
	}
	rep(h, m) {
		ll cnt = 0;
		rep(i, n + m) {
			if (i == n || h + i == m) { break; }
			if (s[i] == t[h + i]) { cnt++; }
			else { ans = max(ans, cnt); cnt = 0; }
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
long long int ans=0;
for(int i=1;i<=n;i++)
{
    if(i%5!=0&&i%3!=0&&i%15!=0)
   {
ans+=i;
// cout<<i<<" ";
   } 

}
cout<<ans;
}


Measured memory_bytes: 3632
N, K = map(int,input().split())
A = list(map(int,input().split()))

p = 0

if K > N:
    city = [-1]*N
    city[0] = 1
    while city[A[p]-1] == -1:
        city[A[p]-1] = city[p]+1
        p = A[p]-1
    K = (K-city[p]) % (city[p]-city[A[p]-1]+1)
    p = A[p]-1

for i in range(K):
    p = A[p]-1

print(p+1)


Measured memory_bytes: 32244
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <random>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll t, a, x = 1, y = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> t >> a;
        ll u = (x - 1) / t + 1, v = (y - 1) / a + 1;
        x = t * max(u, v);
        y = a * max(u, v);
    }
    cout << x + y;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a.begin(), a.end());

	vector<int> mp;
	int tmp = 0;
	for (int i = 0; i < N; i++) {
		tmp ^= a[i];
	}

	sort(mp.begin(), mp.end());

	if (tmp == 0) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////

int main()
{
    int N;
    io >> N;
    vector<bool> zoro(N);
    for (int i = 0; i < N; i++)
    {
        int d1, d2;
        io >> d1 >> d2;
        zoro[i] = (d1 == d2);
    }

    int keep = 0;
    bool ans = false;
    for (int i = 0; i < N; i++)
    {
        if (zoro[i])
            keep++;
        else
            keep = 0;

        if (keep >= 3)
        {
            ans = true;
            break;
        }
    }
    
    io << YesNo(ans) << BR;
}

Measured memory_bytes: 3684