akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std; 
 
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fp(i,a,b,p) for(int i=a;i<b;i+=p)
#define SZ(x) (int)x.size()
#define INF 1e9
 
typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;	
 
 
int main(){
	int n;
	string s; 
	
	cin >> n >> s;
	
	int ans = 0;
	
	f(i,1,SZ(s)){
		vi left(28);
		vi right(28);
		int ret = 0;
		fr(j,i-1,0){
			left[s[j]-'a'] = 1;
		}
		
		f(j,i,SZ(s)){
			right[s[j]-'a'] = 1;
		}
		
		f(j,0,28){
			if(left[j]==1 && right[j]==1) ret++;
		}
		
		ans = max(ans,ret);
		
	}
	
	cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int
main(int argc,char *argv[])
{
  int A, B;
  scanf("%d%d", &A, &B);
  
  if((A * B) % 2 == 0){
    printf("%s\n", "No");
  }
  else{
    printf("%s\n", "Yes");
  }
  
  return 0;
}

Measured memory_bytes: 128
N = int(input())
ps = list(map(int, input().split()))
correct = list(range(1, N + 1))

# print(ps)
# print(correct)

count = 0
for i in range(N):
    if ps[i] != correct[i]:
        count += 1

if count > 2:
    print("NO")
else:
    print("YES")


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

int main() {
    int now=1, count=0;
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a.at(i);
    
    while(1){
        if(now == 2){
            cout << count << endl;
            break;
        }
        if(count >= N){
            cout << "-1" << endl;
            break;
        }
        now = a.at(now-1);
        count++;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;//d, v
const int max_n = 1e5;
const ll INF = 1e18;
ll n,m,k,q;
int color[max_n] = {0};
struct edge{
  ll to, cost;
};
vector<edge> G[max_n];
ll d[max_n];
void dijkstra(ll s){
  fill(d, d+n, INF);
  d[s] = 0;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0,s));
  while(que.size()){
    P p = que.top();  que.pop();
    ll v = p.se;
    if(d[v] < p.fi) continue;
    for(int i=0 ; i<G[v].size() ; i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main(){
  cin >> n ;
  for(int i=0 ; i<n-1 ; i++){
    ll x,y,z;  cin >> x >> y >> z;
    --x;  --y;
    G[x].push_back((edge){y,z});
    G[y].push_back((edge){x,z});
  }
  cin >> q >> k;
  vector<ll> ans(q,0);
  ll dk[n];
  --k;
  dijkstra(k);
  for(int i=0 ; i<q ; i++){
    ll x,y; cin >> x >> y;
    --x;  --y;
    ans[i] = d[x] + d[y];
  }
  for(int i=0 ; i<q ; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 11888
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
#define MOD 1000000007
typedef long long ll;
std::pair<int, int> arr[100005];
int seg[100005], app[100005], bot[100005], ex[100005], cnt;
void modify(int pos, int x)
{
	for (pos++; pos <= cnt; pos += pos & -pos)
		(seg[pos] += x) %= MOD;
}
int query(int pos)
{
	int res = 0;
	for (pos++; pos; pos -= pos & -pos)
		(res += seg[pos]) %= MOD;
	return res;
}
int main()
{
	// freopen("ARC101-F.in", "r", stdin);
	int n, m, cur = 0;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", bot + i);
	for (int i = 0; i < m; i++)
		scanf("%d", ex + i);
	for (int i = 0; i < n; i++)
	{
		int pos = std::upper_bound(ex, ex + m, bot[i]) - ex - 1;
		if (pos < 0)
			continue;
		arr[cur].first = bot[i] - ex[pos];
		pos = std::lower_bound(ex, ex + m, bot[i]) - ex;
		if (pos >= m)
			continue;
		arr[cur].second = ex[pos] - bot[i];
		app[cur] = arr[cur].second;
		cur++;
	}
	n = cur;
	std::sort(arr, arr + n);
	std::sort(app, app + n + 1);
	cnt = std::unique(app, app + n + 1) - app;
	modify(0, 1);
	for (int i = 0, j = 0; i < n; i = j)
	{
		while (j < n && arr[i].first == arr[j].first)
			j++;
		for (int k = j - 1; k >= i; k--)
		{
			arr[k].second = std::lower_bound(app, app + cnt, arr[k].second) - app;
			if (k + 1 != j && arr[k].second == arr[k + 1].second)
				continue;
			modify(arr[k].second, query(arr[k].second - 1));
		}
	}
	printf("%d\n", query(cnt - 1));
	return 0;
}


Measured memory_bytes: 2304
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int c[] = new int[n];
		int s[] = new int[n];
		int f[] = new int[n];
		for (int i = 1; i < n; i++) {
			c[i] = Integer.parseInt(sc.next());
			s[i] = Integer.parseInt(sc.next());
			f[i] = Integer.parseInt(sc.next());
		}
		for (int i = 1; i <= n; i++) {
			int t = 0;
			for (int j = i; j < n; j++) {
				if (t < s[j])
					t = s[j];
				else if ( t % f[j] != 0)
					t += f[j] - t % f[j];
				t += c[j];
			}
			out.println(t);
		}
		out.flush();
	}
}

Measured memory_bytes: 23492
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll t=1;
	//cin>>t;
	if(t)
	{
		ll n,i,w,j,x,y=0;
		cin>>n>>w;
		pair<ll,ll> arr[n+1];
		vector< vector< ll > > mat((n+1) , vector<ll> (w+1));
		arr[i].first=arr[i].second=0;
		for(i=1;i<=n;i++)
			cin>>arr[i].first>>arr[i].second;
		sort(arr,arr+n+1);
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=w;j++)
			{
				mat[i][j]=0;
				mat[i][j]=max(mat[i-1][j],mat[i][j-1]);
				//cout<<i<<" "<<j<<" "<<mat[i-1][j]<<" "<<mat[i][j-1]<<endl;
				if(arr[i].first<=j)
				{
					//cout<<"yash "<<arr[i].first<<" "<<j<<endl;
					y=j-arr[i].first;
					if(y<0)
						y=0;
					x=arr[i].second+mat[i-1][y];
					mat[i][j]=max(mat[i][j],x);
				}
				
			}
		}
		/*for(i=0;i<=n;i++)
		{
			for(j=0;j<=w;j++)
				cout<<mat[i][j]<<" ";
			cout<<endl;
		}*/
		cout<<mat[n][w]<<endl;
	}
	return 0;
}

Measured memory_bytes: 80256
def main():
    N, M = map(int, input().split())
    A = [
        input()
        for i in range(N)
    ]
    B = [
        input()
        for i in range(M)
    ]

    diff = N - M + 1
    for i in range(diff):
        for j in range(diff):
            a = [
                A[k][j:j + M]
                for k in range(i, i + M)
            ]
            if a == B:
                print("Yes")
                return

    print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
# 赤：X軸降順でソート
# 青：Y軸昇順でソート
# 青を順に処理して、条件を満たす赤があれば採用する
N = int(input())

red = [None] * N
for i in range(N):
  red[i] = tuple(map(int,input().split()))

red = sorted(red, key = lambda x:-x[0])

blue = [None] * N
for i in range(N):
  blue[i] = tuple(map(int,input().split()))

blue = sorted(blue, key = lambda x:x[1])

ans = 0
for b in blue:
  found = -1
  for i in range(len(red)):
    if red[i][0] < b[0] and red[i][1] < b[1]:
      ans += 1
      found = i
      break
  if found != -1:
    del red[found]

print(ans)

Measured memory_bytes: 3064
#!/usr/bin/perl

my $md = 998244353;

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @d = map { $_ - 0 } split(/\s+/,<STDIN>);

if( $d[0] != 0 ){
  print "0\n";
  exit(0);
}

if( $n == 1 ){
  print "1\n";
  exit(0);
}

my $mx = 0;
my @ct = ();
$#ct = $n;
for(my $i=1;$i<$n;$i++){
  $ct[$d[$i]] ++;
  $mx = $d[$i] if $d[$i] > $mx;
}

if( $ct[0] - 0 > 0 ){
  print "0\n";
  exit(0);
}

for(my $i=1;$i<=$mx;$i++){
  if( $ct[$i] - 0 == 0 ){
    print "0\n";
    exit(0);
  }
}

my $r = 1;
my $c = 1;
for(my $i=1;$i<=$mx;$i++){
  my $c1 = $ct[$i] - 0;
  my $a = 1;
  for(my $j=0;$j<$c1;$j++){
    $a = ( $a * $c ) % $md;
  }
  $r = ( $r * $a ) % $md;
  $c = $c1;
}
print "$r\n";



Measured memory_bytes: 19148
public class Main {
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		for (;;) {
			final int m = sc.nextInt();
			final int nmin = sc.nextInt();
			final int nmax = sc.nextInt();
			if (m == 0 && nmin == 0 && nmax == 0)
				break ;
			final int[] p = new int[m];
			for (int i = 0; i < m; ++i) {
				p[i] = sc.nextInt();
			}
			
			int n = nmin;
			for (int i = nmin + 1; i <= nmax; ++i) {
				if (p[n - 1] - p[n] <= p[i - 1] - p[i])
					n = i;
			}
			System.out.println(n);
		}
		sc.close();
	}

	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

}

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

int main() {
  int n;
  cin>>n;
  set<int> st;
  int a;
  for(int i=0;i<n;++i){
    cin>>a;
    st.insert(a);
  }
  if(n==st.size())cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 9600
fn main() {
    proconio::input! {
        n: usize,
        q: usize,
        tuv: [(usize, usize, usize); q],
    }

    let mut dsu = DSU::new(n);

    for i in 0..q {
        let (t, u, v) = tuv[i];
        if t == 1 {
            println!("{}", if dsu.same(u, v) { 1 } else { 0 });
        } else {
            dsu.merge(u, v)
        }
    }
}

struct DSU {
    n: usize,
    parent: Vec<Option<usize>>,
    rank: Vec<usize>,
}

impl DSU {
    fn new(n: usize) -> Self {
        Self {
            n,
            parent: vec![None; n],
            rank: vec![1; n],
        }
    }

    fn merge(&mut self, u: usize, v: usize) {
        assert!(u < self.n);
        assert!(v < self.n);

        let (up, vp) = (self.top(u), self.top(v));
        if up != vp {
            let (p, c) = if self.rank[up] > self.rank[vp] { (up, vp) } else { (vp, up) };
            self.rank[p] += self.rank[c];
            self.rank[c] = 0;
            self.parent[c] = Some(p);
        }
    }

    fn same(&mut self, u: usize, v: usize) -> bool {
        assert!(u < self.n);
        assert!(v < self.n);

        self.top(u) == self.top(v)
    }

    fn top(&mut self, u: usize) -> usize {
        assert!(u < self.n);

        if let Some(p) = self.parent[u] {
            let p = self.top(p);
            self.parent[u] = Some(p);
            p
        } else {
            u
        }
    }
}


Measured memory_bytes: 11652
import sys
input = lambda: sys.stdin.readline().rstrip()

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


# 1-index
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
        self.depth = n.bit_length()
        
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        """assert i > 0"""
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
            
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)
    
    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.n and sum_ + self.data[k] < x:
                sum_ += self.data[k]
                pos += 1 << i
        return pos + 1, sum_

bit = BIT(N)
for idx, a in enumerate(A):
    bit.add(idx+1, a)

for i in range(Q):
    qry = list(input().split())
    if qry[0] == "0":
        bit.add(int(qry[1])+1, int(qry[2]))
    else:
        print(bit.get(int(qry[1]), int(qry[2])))

Measured memory_bytes: 136768
n=int(input())
import math
ansa=[0]
ansb=[0]
ans=[]
cnt=0
x=0
y=0
for i in range(1,n+1):
    while 9**(x+1)<=i:
        x+=1
    for j in range(x,-1,-1):
        z=(math.floor(i/(9**j))%9)
        i-=(9**j)*z
        cnt+=z
    ansa.append(cnt)
    cnt=0    
    
for i in range(1,n+1):
    while 6**(y+1)<=i:
        y+=1
    for j in range(y,-1,-1):
        z=(math.floor(i/(6**j))%6)
        i-=(6**j)*z
        cnt+=z
    ansb.append(cnt)
    cnt=0
    
for i in range(n+1):
    ans.append(ansa[i]+ansb[n-i])
    
print(min(ans))   



Measured memory_bytes: 5548
#include <stdio.h>

int gcd(int x,int y);

int main(void) {
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n",gcd(x,y));
	
	return 0;
}

int gcd(int x,int y){
	int a,r;
	if(x<y) {
		a=x;
		x=y;
		y=a;
	}
	for(;;){
		r=x%y;
		if(r==0) break;
		else {
			x=y;
			y=r;
		}
	}
	return y;
}


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

int main() {
    char C;
    cin >> C;

    if ((C == 'a') || (C == 'i') || (C == 'u') || (C == 'e') || (C == 'o')) {
        cout << "vowel" << endl; 
    }
    else cout << "consonant" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b + c + d == 1 + 9 + 7 + 4
            && a * b * c * d == 1 * 9 * 7 * 4) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  
  int ans = 0;
  rep(i,a+1){
    rep(j,b+1){
      rep(k,c+1){
        if(x == 500*i + 100*j + 50*k) ans++;
      }
    }
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
/**/
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

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

	int N;
	long long A,B;
	long long res = 0;
	cin>>N>>A>>B;
	vector<long long> x(N);
	for(int i = 0;i < N;i++)
		cin>>x[i];
	for(int j = 1;j < N;j++) {
		res += min(B,A * (x[j] - x[j-1]));
	}
	cout<<res<<'\n';
	return 0;
}
/**/


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

int main()
{
    int a, b, c, isum, jsum, ksum, sum = 0, count = 0;

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> sum;

    for (int i = 0; a >= i; i++)
    {
        isum += 500 * i;
        for (int j = 0; b >= j; j++)
        {
            jsum += 100 * j + isum;
            for (int k = 0; c >= k; k++)
            {
                ksum += 50 * k + jsum;

                if (sum == ksum)
                {
                    count++;
                }
                ksum = 0;
            }
            jsum = 0;
        }
        isum = 0;
    }
    cout << count;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    int prev_num;
    cin >> prev_num;
    
    int cnt = 1;
    bool increase = false, decrease = false;
    for (int i = 1; i < N; i++) {
        int a;
        cin >> a;
        if (prev_num < a) increase = true;
        else if (prev_num > a) decrease = true;
        if (increase && decrease) {
            cnt++;
            increase = decrease = false;
        }
        prev_num = a;
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    string s;cin>>s;
    string ss=s.substr(0,3);
    cout<<ss<<endl;
    //-------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------








































Measured memory_bytes: 3660
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int solve(int cnt, int x, int y, vint c, vint s, vint f) {
	if (cnt > cnt / f[x]*f[x]) {
		cnt = cnt / f[x] * f[x] + f[x];
	}
	else {
		cnt = cnt / f[x]*f[x];
	}
	if (cnt < s[x]) {
		cnt = s[x];
	}
	cnt += c[x];
	if (x + 1 == y) {
		return cnt;
	}
	else {
		return solve(cnt, x + 1, y, c, s, f);
	}
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vint ans(n + 2, 0);
	ans[0] = 0;
	rep(i, n) {
		if (i == 0) {
			ans[i + 1] = ans[0] + abs(a[i]);
			continue;
		}
		ans[i + 1] = ans[i] + abs(a[i] - a[i - 1]);
	}
	ans[n + 1] = ans[n] + abs(a[n - 1]);
	int cnt = 0;
	rep(i, n) {
		if (i == 0) {
			cnt = ans[i + 2] - abs(a[i + 1]);
		}
		else if (i == n - 1) {
			cout << ans[n - 1] + abs(a[n - 2]) << endl;
			break;
		}
		else {
			cnt = ans[i + 2] - ans[i] - abs(a[i + 1] - a[i - 1]);
		}
		cout << ans[n + 1] - cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
using namespace std;
int count(int n,int cou)
{
    return n%2==0 ? count(n/2,cou+=1) : cou; 
}
int main()
{
    int n, cou=0, aa=0;
    int ans=0;
    cin >> n;
    for(int i=1; i<=n; i++) 
    {
        int a=count(i,cou);
        if(a>=aa)
        {
            aa=a; ans=i;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B = IL()

if A==B:
    print(max(A,B)*2)
else:
    print(max(A,B)*2-1)

Measured memory_bytes: 12484
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int A,B,X;
    cin>>A>>B>>X;
    
    
    if(A>X){
        cout<<"NO"<<endl;
    }else if(A<X&&A+B<X){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
    
}


Measured memory_bytes: 256
m1,d1 = map(int,input().split())
m2,d2 = map(int,input().split())
if m1 in [1,3,5,7,8,10,12] and d1==31:
  print(1)
elif m1 in [4,6,9,11] and d1==30:
  print(1)
elif m1==2 and d1 in [28,29]:
  print(1)
else:
  print(0)

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int digit_sum(int num){
    if(num==0) return 0;
    return num%10+digit_sum(floor(num/10));
}

int main(){
    int N;
    cin >>N;
    int X=digit_sum(N);
    if(N%X==0){
        cout <<"Yes"<<endl;
    }else{
        cout <<"No"<<endl;
    }
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  
  int a[n];
  rep(i,n) cin >> a[i];
  
  sort(a,a+n,greater<int>());
  int alice = 0, bob = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0){
      alice += a[i];
    }else{
      bob += a[i];
    }
  }
  
  cout << alice - bob << endl;
}

Measured memory_bytes: 3596
N, Q = map(int, input().split())
str = input()
length = [list(map(int, input().split())) for _ in range(Q)]

ans = [0 for _ in range(N)]
for i in range(1, N):
    if (str[i-1] == "A") and (str[i] == "C"):
        ans[i] = ans[i-1] + 1
    else:
        ans[i] = ans[i-1]

for l1, l2 in length:
    # print(ans)
    print(ans[l2-1] - ans[l1-1])


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 

using ll = long long;

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

constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll mod){ll r=1;while(e>0){if(e&1)r=(r%mod)*(b%mod)%mod;b=(b%mod)*(b%mod)%mod;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i < v.size()-1)s<<", ";}s<<']';return s;}

vector<vector<int>> G;

vector<int> dis;
vector<int> aok;
void rec(int i, int p, int d, bool ao){
    if(ao) {
        aok[i] += d;
        dis[i] -= d;
    }
    else{ 
        dis[i] += d;
    }
    for(int ni : G[i]){
        if(p == ni) continue;
        rec(ni, i, d+1, ao);
    }
}

int main(){
    
    int n, u, v;
    scanf("%d%d%d", &n, &u, &v);
    G.resize(n);
    --u; --v;
    dis.resize(n, 0);
    aok.resize(n, 0);
    rep(i, n-1){
        int A, B;
        scanf("%d%d", &A, &B);
        --A; --B;
        G[A].emplace_back(B);
        G[B].emplace_back(A);
    }
    rec(u, -1, 0, false);
    rec(v, -1, 0, true);
    int en = 0;
    int mx = 0;
    for(int i = 0; i < n; ++i){
        if(dis[i] < 0 and aok[i] > mx){
            mx = aok[i];
            en = i;
        }
    }
    ppp(aok[en]-1);
    return 0;
}


Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fi first
#define so second
#define ps push_back
#define pii pair<int,int>
#define mod 1000000007
#define TT int t;cin>>t;while(t--)

signed main()
{
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    int p[a],q[b],r[c];
    int i=a-x,j=b-y,k=0;
    for(i=0;i<a;i++) cin>>p[i];
    for(i=0;i<b;i++) cin>>q[i];
    for(i=0;i<c;i++) cin>>r[i];
    i=a;j=b;k=c;
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    int sum=0,count=0,countx=0,county=0;
    while(count<x+y)
    {
        int m=max(max(p[i-1],q[j-1]),r[k-1]);
        if(m==p[i-1])
        {
            if(countx<x) {countx++;sum+=p[i-1];i--;}
            else
            {
                if(q[j-1]>r[k-1]) {county++;sum+=q[j-1];j--;}
                else {sum+=r[k-1];k--;}
            }
        }
        else if(m==q[j-1])
        {
            if(county<y) {county++;sum+=q[j-1];j--;}
            else
            {
                if(p[i-1]>r[k-1]) {countx++;sum+=p[i-1];i--;}
                else {sum+=r[k-1];k--;}
            }
        }
        else {sum+=r[k-1];k--;}
        count++;
    }
    /*for(int ii=a-1;ii>=i;ii--) sum+=p[ii];
    for(int ii=b-1;ii>=j;ii--) sum+=q[ii];
    while(k>=0 && i<a && j<b && (p[i]<=r[k] || q[j]<=r[k]))
    {
        if(p[i]<r[k] && q[j]<r[k])
        {
            if(p[i]<q[j]) {sum-=p[i];i++;}
            else {sum-=q[j];j++;}
        }
        else
        {
            if(p[i]<r[k]) {sum-=p[i];i++;}
            else {sum-=q[j];j++;}
        }
        sum+=r[k];
        k--;
    }*/
    cout<<sum<<endl;
}


Measured memory_bytes: 2560
use proconio::{fastout, input};
use superslice::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [isize; n],
        mut b: [isize; n],
        mut c: [isize; n]
    }
    a.sort();
    c.sort();
    let mut sum = 0;
    for bb in b {
        let lower_a = a.lower_bound(&bb);
        let upper_c = c.upper_bound(&bb);
        sum += lower_a * (n-upper_c);
    }

    println!("{}", sum);
}


Measured memory_bytes: 7776
#include <stdio.h>
#include <bits/stdc++.h>
     
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i, 0, n)
        cin >> a[i];
    if (n == 1)
    {
        cout << (k == a[0] ? "POSSIBLE\n" : "IMPOSSIBLE\n");
        return 0;
    }
    int g = a[0];
    rep(i, 0, n)
        g = __gcd(g, a[i]);
    int maxx = a[0];
    rep(i, 0, n)
        maxx = max(maxx, a[i]);
    cout << (k <= maxx && k % g == maxx % g ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#define SIZE 10010

using namespace std;

int main()
{
    int n,i,a,b,total=0;
    scanf("%d%d",&a,&b);
    if(a>b)
    {
        total=a;
        a--;
    }
    else
    {
        total=b;
        b--;
    }
    if(a>b)
    {
        total+=a;
    }
    else
    {
        total+=b;
    }
    printf("%d\n",total);
    return 0;
}


Measured memory_bytes: 256
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]
s = list(map(int, list(input())))

fl = []
rl = []

cnt0 = 0
cnt1 = 0
for i in range(n):
  if s[i] == 0:
    if cnt0 == 0:
      rl.append(cnt1)
      cnt1 = 0
    cnt0 += 1
  elif s[i] == 1:
    if cnt1 == 0 and i != 0:
      fl.append(cnt0)
      cnt0 = 0
    cnt1  += 1

if cnt0 != 0:
  fl.append(cnt0)
  rl.append(0)
elif cnt1 != 0:
  rl.append(cnt1)

rllen = rl[0]
for i in range(min(k, len(fl))):
  rllen += fl[i] + rl[i+1]

maxr = rllen
for i in range(max(0, len(fl)-k)):
  rllen += (fl[i+k] + rl[i+k+1])
  rllen -= (fl[i] + rl[i])
  if maxr < rllen:
    maxr = rllen 

print(maxr)

Measured memory_bytes: 50936
#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAX = 2e5 + 10;
using namespace std;
ll a[MAX];
void solve() {
    ll n,sum=0,ans=0;
    cin>>n;
    for (int i = 0; i < n; ++i)
        cin>>a[i],sum+=a[i]%mod;
    for(int i=0;i<n;i++)
        ans=(((sum-a[i]+mod)%mod*a[i]%mod)+ans)%mod;
    cout<<(ans%2==0?ans/2:(ans+mod)/2)<<endl;
}

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

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)

int main()
{
    string S;
    cin >> S;
    int res = 0;
    rep(i, 0, 4)
    {
        if (S[i] == '+')
        {
            res++;
        }
        else
        {
            res--;
        }
    }
    cout<<res<<endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
int a[14];
for(int i = 0; i <= 13; i++) a[i] = 0;
a[4] = 1;
a[6] = 1;
a[9] = 1;
a[11] = 1;
a[2] = 2;
int b, c;
cin >> b >> c;
if(a[b] == a[c]) cout << "Yes" << endl;
else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    a_xor = a[0] ^ a[1]
    for i in range(2, N):
        a_xor = a_xor ^ a[i]
    if (a_xor == 0):
        print("Yes")
    else:
        print("No")
resolve()

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

using namespace std;

using ll = int64_t;
using ull = uint64_t;
using ld = long double;

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& x : a) {
        cin >> x;
    }
    int ptr = 0;
    int ans = 0;
    while (ptr < n) {
        int go = ptr;
        while (go < n && a[go] == a[ptr]) {
            go++;
        }
        int len = go - ptr;
        ptr = go;
        ans += len / 2;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 896
N,M=map(int,input().split())
S_C=[list(int(x) for x in input().split()) for _ in range(M)]

for i in range(10**N):
    i=str(i)
    if len(i)!=N:
        continue
    if all([i[s-1]==str(c) for s,c in S_C]):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3064
#include <stdio.h>

int isSame(const int *A,const int *B)
{
	int p1, p2, t1, t2, f1, f2, e, h;

	h = 0;
	for (p1 = 0; p1 < 6; p1++)
	{
		if (A[0] == B[p1] && A[5] == B[5 - p1])
		{
			h = 1;
			break;
		}
	}
	if (!h) return 0;

	h = 0;
	for (p2 = 0; p2 < 6; p2++)
	{
		if (p2 == p1 || p2 == 5 - p1) continue;
		if (A[1] == B[p2] && A[4] == B[5 - p2])
		{
			h = 1;
			break;
		}
	}
	if (!h) return 0;

	t1 = p1 / 3;
	t2 = t1 > 0 ? 3 - (t1 + p1 % 3) : p1 % 3;
	f1 = p2 / 3;
	f2 = f1 > 0 ? 3 - (f1 + p2 % 3) : p2 % 3;

	e = t1 ^ f1;
	e = f2 - (t2 + 1) % 3 != 0 ? !e * 3 : e * 3;
	e += e > 0 ? (t2 + f2) - 1 : 3 - (t2 + f2);
		
	if (A[2] != B[e] || A[3] != B[5 - e]) return 0;

	return 1;	
}

int main()
{
	int A[6];
	int B[6];
	int i;

	for (i = 0; i < 6; i++) scanf("%d", &A[i]);
	for (i = 0; i < 6; i++) scanf("%d", &B[i]);

	if (isSame(A, B)) printf("Yes\n");
	else printf("No\n");

	return 0;

}

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

const int N = 2 * 1e5 + 10;
const int mod = 1e9 + 7;
using namespace std;

int ksm(int a, int b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)
		{
			res = 1ll * res * a % mod;
		}
		b >>= 1;
		a = 1ll * a * a % mod;
	}
	return res;
}
int n;
struct edge
{
	int y;
	int next;
}ed[2*N];
int en;
int head[N];
void add_edge(int x, int y)
{
	en++;
	ed[en].y = y;
	ed[en].next = head[x];
	head[x] = en;
}
int f[N];//sizeu;
int ans[N]; //��kΪ���ڵ�ʱ�� N��/ans��k�����Ǵ𰸡�size�Ļ� 
void dfs(int u, int fa)
{
	for(int p = head[u]; p != 0; p = ed[p].next)
	{
		int v = ed[p].y;
		if(v == fa) continue;
		dfs(v, u);
		f[u] += f[v];
	}
	f[u]++;
}
void move(int u, int fa)
{
	for(int p = head[u]; p != 0; p = ed[p].next)
	{
		int v = ed[p].y;
		if(v == fa)
		{
			continue;
		}
		ans[v] = 1ll * ans[u] * ksm(f[v], mod-2) % mod * (n - f[v]) % mod;
		move(v, u);
	}
}
int main()
{
	cin >> n;
	for(int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		add_edge(a, b);
		add_edge(b, a);
	}
	dfs(1, 0);//����ÿ������1Ϊ�������Ĵ�С��
	ans[1] = 1;
	for(int i = 1; i <= n; i++)
	{
		ans[1] = 1ll * ans[1] * f[i] % mod;
	}
	move(1, 0);
	int t = 1;
	for(int i = 1; i <= n; i++)
	{
		t = 1ll * i * t % mod; 
	}
	for(int i = 1; i <= n; i++)
	{
		printf("%lld\n", 1ll * t * ksm(ans[i], mod-2) % mod);
	}
	return 0;
}


Measured memory_bytes: 7680
import java.util.*;


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

    	int n=sc.nextInt();
			int v[]=new int[n];
			int c[]=new int[n];
			int total=0;

			for(int i=0;i<n;i++){
				v[i]=sc.nextInt();
			}
			for(int i=0;i<n;i++){
				c[i]=sc.nextInt();
			}

			for(int i=0;i<n;i++){
				if(v[i]-c[i]>0){
					total+=v[i]-c[i];
				}
			}

			System.out.println(total);


	}
}


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

int main(void){
    char s[4];
    scanf("%s",s);
    if (s[0]==s[1] && s[1]==s[2] && s[2]==s[3]){
        printf("No\n");
    } else if (s[0]==s[1] && s[2]==s[3]){
        printf("Yes\n");
    } else if (s[0]==s[2] && s[1]==s[3]){
        printf("Yes\n");
    } else if (s[0]==s[3] && s[1]==s[2]){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

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

void main_()
{
    ll N;
    cin >> N;
    unordered_map<string, ll> ss;
    for (ll i = 0; i < N; ++i) {
        string s;
        cin >> s;
        sort(begin(s), end(s));
        ss[s]++;
    }

    auto ans = accumulate(begin(ss), end(ss), 0LL,
        [](auto acc, auto&& i) {
            auto m = i.second;
            // acc + mC2
            return acc + m * (m - 1) / 2;
        });

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 10660
#include <stdio.h>
int main()
{
  int dice[2][6];
  int vector[3][4]={{0,2,5,3},{0,1,5,4},{1,2,4,3}};
  int i,j,k,l,m,c;
  for(i=0;i<2;i++)
  {
    for(j=0;j<6;j++)
    {
      scanf("%d",&dice[i][j]);
    }
  }
  for(i=0;i<2;i++)
  {
    for(j=0;j<4;j++)
    {
      int temp = dice[1][vector[i][0]];
      for(k=0;k<3;k++)
      {
    dice[1][vector[i][k]] = dice[1][vector[i][k+1]];
      }
      dice[1][vector[i][3]] = temp;
      c = 0;
      for(k=0;k<6;k++)
      {
    if(dice[0][k]==dice[1][k])c++;
      }
      if(c==6)break;
      for(m=0;m<3;m++){
    for(k=0;k<4;k++)
    {
      int temp = dice[1][vector[m][0]];
      for(l=0;l<3;l++)
      {
        dice[1][vector[m][l]] = dice[1][vector[m][l+1]];
      }
      dice[1][vector[m][3]] = temp;
      c=0;
      for(l=0;l<6;l++)
      {
        if(dice[0][l]==dice[1][l])c++;
      }
      if(c==6)break;
    }
    if(c==6)break;
      }
      if(c==6)break;
    }
    if(c==6)break;
  }
  if(c==6)printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);

    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.merge(x, y);
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(uf.issame(i, p[i])){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5080
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const input = stdin.split('\n')

const [n, q] = input[0].split(' ').map(Number)

const ab = []
const px = []
for (let i = 1; i < n + q; i++) {
  const abpx = input[i].split(' ').map(Number)
  if (i < n) {
    ab.push(abpx)
  } else {
    px.push(abpx)
  }
}

const ans = () => {
  let countList = []
  let nodes = []

  for (let i = 0; i < n + 1; i++) {
    countList.push(0)
    nodes.push(0)
  }

  for (let i = 0; i < px.length; i++) {
    const [parent, x] = px[i]

    countList[parent] += x
  }

  for (let i = 0; i < ab.length; i++) {
    const [parent, child] = ab[i]

    nodes[child] = parent
  }

  for (let i = 1; i <= n; i++) {
    const parent = nodes[i]
    const count = countList[parent]

    countList[i] += count
  }

  countList.shift()
  let res = `${countList[0]}`
  for (let i = 1; i < countList.length; i++) {
    res += ` ${countList[i]}`
  }

  console.log(res)
}

ans()


Measured memory_bytes: 124000
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S, T;
	int g = 0;
	cin >> S >> T;
	for (size_t i = 0; i < 3; i++)
	{
		if (S.at(i)==T.at(i))
		{
			g++;
		}
		
	}
	cout << g;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

string s; cin  >> s;
int ss = s.size(), ans = 0;

rep(i, 0, ss / 2){
    if (s[i] == 'x'){
        if (s[ss - 1 - i] != 'x'){
            s.insert(ss, 1, 'x');
            ++ans;
            ss = s.size();
        }
    } 
    else if (s[i] != s[ss - 1 - i] && s[ss - 1 - i] != 'x') {
        cout << -1 << "\n";
        return 0;
    }
    
    if (s[ss - 1 - i] == 'x'){
        if (s[i] != 'x'){
            s.insert(i, 1, 'x');
            ++ans;
            ss = s.size();
        }
    }
    else if (s[i] != s[ss - 1 - i] && s[i] != 'x'){
        cout << -1 << "\n";
        return 0;
    }
}
cout << ans << "\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 720
import java.util.Scanner;

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

    int rest;
    int t = s / (60 * 60);
    rest = s % (60 * 60);
    int m = (rest) / 60;
    rest = rest % 60;

    System.out.println(t + ":" + m + ":" + rest);
  }
}



Measured memory_bytes: 26364
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,m;cin >> n>> m;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    priority_queue<int> pq;
    rep(i,n)pq.push(a[i]);
    rep(i,m){
        if(pq.size() == 0)continue;
        auto hoge = pq.top();pq.pop();
        pq.push(hoge/2);
    }
    int ret = 0;
    while(pq.size()){
        ret += pq.top();pq.pop();
        
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 5040
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
map<int,int> mii;

int vis[200050];
int main()
{
    //ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll ans=(x/500)*1000;
    x%=500;
    ans+=x/5*5;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int N,Q;cin>>N>>Q;
  string S;cin>>S;
  S = "S" + S;
  dump(S);

  int c[N+1]={};
  rep(n, 1, N+1){
    c[n] = c[n-1];
    if (S[n]=='C' and S[n-1]=='A') {
      c[n]++;
    }
  }
  dump_1d(c, N+1);
  rep(q, Q){
    int l,r;
    cin>>l>>r;
    dump(l,r);
    int res = c[r] - c[l-1];
    if (S[l]=='C' and S[l-1]=='A') res--;
    cout << res << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1772
/*
                                                  
  _|_|                              _|  _|    _|  
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|    
_|    _|  _|_|          _|          _|  _|_|      
_|    _|  _|          _|      _|    _|  _|  _|    
  _|_|    _|        _|_|_|_|    _|_|    _|    _|  
                                                                                                    
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
int main(){
    int n;cin>>n;
    if(n&(n-1)){
        cout<<"Yes"<<endl;
        cout<<"1 2"<<endl<<"2 3"<<endl<<"3 "<<n+1<<endl<<n+1<<' '<<n+2<<endl<<n+2<<' '<<n+3<<endl;
        for(int i=4;i+1<=n;i+=2){
            cout<<"1 "<<i<<endl<<i<<' '<<i+n+1<<endl;
            cout<<"1 "<<i+1<<endl<<i+1<<' '<<i+n<<endl;
        }
        if(n%2==0){
            rep(i,4,n){
                int tmp=i^1^n;
                if(tmp<n&&tmp!=3){
                    cout<<i<<' '<<2*n<<endl<<tmp<<' '<<n;
                    return 0;
                }
            }
        }
    }else{
        cout<<"No";
    }
    return 0;
}

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



int main() 
{
  ll A,B; cin>>A>>B;
  cout<<A*B<<endl;

  return 0;
}

Measured memory_bytes: 3596
import java.util.*;
public class Main {
	public static void main(String[] args) {
		
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int [] a = new int[n];
		for(int i = 0; i < n; ++i) {
			a[i] = input.nextInt();
		}
		Arrays.sort(a);
		boolean status = true;
		for(int i = 0; i < n - 1; ++i) {
			if(a[i] == a[i + 1]) {
				status = false;
				break;
			}
		}
		String answer = "YES";
		if(!status) {
			answer = "NO";
		}
		System.out.println(answer);
		input.close();	
	}
}


Measured memory_bytes: 63872