akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = 
		  new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		
		String[] st = str.split(" ");
		
		int a = Integer.parseInt(st[0]);
		int b = Integer.parseInt(st[1]);
		
		System.out.println(a*b+" "+2*(a+b));
	}
}

Measured memory_bytes: 24256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    S = input()

    ans = 0
    cur = 0

    for char in S:
        if char == "I":
            cur += 1
        else:
            cur -= 1

        ans = max(ans, cur)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61700
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  int c=0;
  rep(i,s.size()){
    if(c==0 && s[i]=='C')c++;
    if(c==1 && s[i]=='F')c++;
  }
  if(c==2)cout << "Yes" << endl;
  else cout << "No" << endl;
return 0;}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = n;
    for(int i = 0; i < n - 1; i++) {
        if(s[i] != s[i + 1]) {
            ans = min(ans, max(i + 1, n - i - 1));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul  7 18:46:49 2020

@author: naoki
"""
N, K = map(int, input().split())
red_num = N-K

mod = 1000000007

kai = [1 for _ in range(2001)]
for i in range(2,2001):
    kai[i] = kai[i-1]*i%mod


for i in range(1,min(K, red_num+1)+1):
    place_option = kai[red_num+1]*pow(kai[i],mod-2,mod)*pow(kai[red_num+1-i],mod-2,mod)
    devide_option = kai[K-i+(i-1)]*pow(kai[K-i],mod-2,mod)*pow(kai[i-1],mod-2,mod)
    answer = (place_option%mod * devide_option%mod)%mod

    print(answer)

if red_num+1<K:
    for i in range(red_num+1,K):
        print(0)

Measured memory_bytes: 74372
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	ll n;
	cin>>n;
	vector<ll>a(n);
	map<ll,ll>cnt;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	sort(a.begin(),a.end(),greater<ll>());
	ll ans=0;
	for(ll i=0;i<n;i++){
		if(cnt[a[i]]==0)continue;
		for(ll j=33;j>=1;j--){
			ll power=(ll)1<<j;
			if(power<=a[i])break;
			if(cnt[power-a[i]]>0){
				if(power==2*a[i]&&cnt[a[i]]==1)continue;
				ans++;
				cnt[a[i]]--;
				cnt[power-a[i]]--;
				break;
			}
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 77696
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

string S;
int K;

int main(void){
	cin>>S>>K;
	vector<string> vec;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 1; j <= K; j++) {
			string tmp = S.substr(i, j);
			vec.push_back(tmp);
		}
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());

	cout<< vec[K - 1] <<endl;
	
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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;
}



int main(){
    ll a,b;
    cin >> a >> b;
    ll ans = 0;
    if(2*b <= a){
        ans = a - 2*b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main() {
  int n;
  while (1) {
    scanf("%d", &n);
    if (n==0)
      break;
    
    int tmp1, tmp2, a=0, b=0;
    
    for (int i=n; i>0; i--) {
      scanf("%d %d", &tmp1, &tmp2);
      if (tmp1>tmp2)
	a+=tmp1+tmp2;
      else if (tmp1==tmp2)
	a+=tmp1, b+=tmp2;
      else
	b+=tmp1+tmp2;
    }
    printf("%d %d\n", a, b);
  }
  return 0;
}

Measured memory_bytes: 1028
N = int(input())
happiness = [[0,0,0] for i in range(N)]
for i in range(N) :
	feeling = [int(i) for i in input().split()]
	for j in range(3) :
		if i != 0 :
			if j == 0 :
				happiness[i][j] = feeling[j] + max(happiness[i-1][1], happiness[i-1][2])
			elif j == 1 :
				happiness[i][j] = feeling[j] + max(happiness[i-1][0], happiness[i-1][2])
			elif j == 2 :
				happiness[i][j] = feeling[j] + max(happiness[i-1][0], happiness[i-1][1])
		else :
			happiness[i] = feeling
			break
print(max(happiness[N-1]))

Measured memory_bytes: 57852
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
void vprint() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}
template <class T> void mprint(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << "";
        }
    }
}

template <class T> vector<T> prime(T N) {
    vector<T> pri;
    vector<bool> is_prime;
    is_prime    = vector<bool>(N + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < N + 1; i++) {
        if (is_prime[i]) {
            pri.push_back(i);
            for (int j = 2 * i; j < N + 1; j += i)
                is_prime[j] = false;
        }
    }
    return pri;
}

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

    int N;
    cin >> N;
    auto pri = prime(55555);
    vector<int> ans;
    REP(i, pri.size()) {
        if (pri[i] % 5 == 1) {
            ans.emplace_back(pri[i]);
        }
        if (ans.size() == N)
            break;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true) {
			int H = scan.nextInt();
			int W = scan.nextInt();
			if(H == 0 && W == 0) {
				break;
			}
			StringBuilder sb = new StringBuilder();
			StringBuilder sb2 = new StringBuilder();
			for(int i = 0; i < W; i++) {
				if(i % 2 == 0) {
					sb.append("#");
					sb2.append(".");
				}else {
					sb.append(".");
					sb2.append("#");
				}
			}
			for(int i = 0; i < H; i++) {
				if(i % 2 == 0) {
					System.out.println(sb.toString());
				}else {
					System.out.println(sb2.toString());
				}
			}
			System.out.println();
		}
		scan.close();
	}
}


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

int N, K;
int h[100000];

int main() {
    cin >> N >> K;
    rep(i, N) cin >> h[i];

    sort(h, h + N);

    long long ans = 1000000000;
    for (int i = 0; i <= N - K; i++) {
        long long left = h[i];
        long long right = h[i + K - 1]; 
        ans = min(ans, right - left);
    }

    cout << ans << endl;
}

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

int main(){
	long long x;	cin>>x;
	long long ans=x/11;		ans*=2;
	x%=11;

	if(x){
		if(x>6)ans+=2;
		else ans++;
	}

	cout<<ans<<endl;


	return 0;
}


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

#define MAX_N 100000

tuple<int, int, int>X[MAX_N];
int n, m, a, b, c;
int V[MAX_N];

int main() {
	while (true) {
		for (int i = 0; i < MAX_N; i++) {
			X[i] = make_tuple(0, 0, 0);
			V[i] = 0;
		}
		V[1] = 1;
		cin >> n >> m;
		if (n == 0 && m == 0) {
			break;
		}
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> c;
			X[i] = make_tuple(a, b, c);
		}
		sort(X, X + m);
		for (int i = 0; i < m; i++) {
			int a1 = get<0>(X[i]);
			int a2 = get<1>(X[i]);
			int a3 = get<2>(X[i]);
			if (V[a2] == 1) {
				V[a3] = 1;
			}
		}
		int sum = 0;
		for (int i = 0; i < MAX_N; i++) {
			sum += V[i];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 4572
#include <iostream>
#include <cstdio>
#include <iomanip>

using namespace std;

int main()
{
  int a;
  int b;
  char op;
  while(1)
  {
    cin >> a >> op >> b;
    
    if(op=='?')
      break;
    if(op=='+')
      cout << a+b<<"\n";
    if(op=='-')
      cout << a-b<<"\n";
    if(op=='*')
      cout << a*b<<"\n";
    if(op=='/')
      cout << a/b<<"\n";
  }
}

Measured memory_bytes: 1164
N, L = map(int, input().split())

S_list = []
S = 0
for i in range(N):
    S_list.append(i+L)
    S += (i+L)


m = 1000
M = -1000
f = 0
for s in S_list:
    if s < m:
        m = s
    if M < s:
        M = s
    if s == 0:
        f = 1
        break

if f == 0:
    if S > 0:
        S = S - m
    else:
        S = S - M

print(S)

Measured memory_bytes: 3064
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

int calc(unsigned l, const vector<int> &a, const vector<int> &b) {
	unsigned i = l;
	for(const auto &e : a) {
		if(e == b[i]) {
			if(++i == b.size()) break;
		}
	}
	return i - l;
}

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

	vector<int> a(n), b(m);
	for(auto &e : a) cin >> e;
	for(auto &e : b) cin >> e;

	int ans = 0;
	for(unsigned l = 0; l < b.size(); ++l) {
		chmax(ans, calc(l, a, b));
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1236
# C
N = int(input())
enter = []
A = [0] * N
for a in range(N):
    ai = int(input())
    tmp_enter = [list(map(int, input().split())) for _ in range(ai)]
    A[a] = ai
    enter.append(tmp_enter)

ans_list = [0]
for i in range(2 ** N):
    # iは誰が正直者かを表す
    honest = []
    unkind = []
    flag = True
    for j in range(N):
        if (i >> j) & 1:
            honest.append(j)
        else:
            unkind.append(j)
    ##print(i, honest, unkind)
    for h in honest:
        for k in range(A[h]):
            if enter[h][k][1] == 1:
                if (enter[h][k][0]-1) in unkind:
                    flag = False
                    break
            if enter[h][k][1] == 0:
                if (enter[h][k][0]-1) in honest:
                    flag = False
                    break
    if flag:
        ans_list.append(len(honest))
print(max(ans_list))

Measured memory_bytes: 46316
#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 ori = n;
  int d = 0;
  while (n > 0) {
    n /= 10;
    ++d;
  }

  int ans = 0;
  for (int i = 1; i <= d; ++i) {
    if (i % 2 == 0) continue;
    if (i == d) {
      int s = 1;
      rep(j, i - 1) s *= 10;
      ans += ori - s + 1;
    } else {
      int s = 1;
      rep(j, i - 1) s *= 10;
      ans += 9 * s;
    }
  }

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


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

using namespace std;

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

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
int i=b;
int ss=c,s=e;
while(i<a){
 i=i+b;
 ss=ss+c;
}
int j=d;
while(j<a){
j=j+d;
s=s+e;
}
cout<<min(s,ss)<<endl;
}



Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll par[100010];
ll ran[100010];
ll num[100010];
ll root(ll x) {
	return par[x] == x ? x : par[x] = root(par[x]);
}
bool same(ll x, ll y) {
	return root(x) == root(y);
}
void unite(ll x, ll y) {
	x = root(x);
	y = root(y);
	if (x == y)return;
	if (ran[x] < ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ran[x] == ran[y])ran[x]++;
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, q, a, b;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		par[i] = i;
		cin >> num[i];
	}
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		unite(a, b);
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (same(num[i], i + 1))ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> num(N);
    for (int i=0; i<N; i++) {
        int a;
        cin >> a;
        num.at(a-1)++;
    }
    sort(num.rbegin(), num.rend());
    int sum = 0;
    for (int i=K; i<N; i++) sum += num.at(i);
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
int trick[110];
using namespace std;

int main()
{
    int n,k;
    int d;
    int m;
    int ans=0;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++)
        trick[i]=0;
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&d);
        for(int j=1;j<=d;j++)
        {
            scanf("%d",&m);
            trick[m]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(trick[i]==0)
            ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 3812
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const int N = 50005;
int dp[N];
int a[22];
int n, m;

int dfs(int x) {
    if (dp[x] != -1) {
        return dp[x];
    }
    int tmp = 1e9;
    for (int i = 0; i < m; ++i) {
        if (x >= a[i]) {
            tmp = min(dfs(x - a[i]) + 1, tmp);
        }
    }
    dp[x] = tmp;
    return dp[x];
}

int main() {
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    
    cout << dfs(n) << endl;
    
    
}


Measured memory_bytes: 5652
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	int N;
	cin >> N;
	if (N == 1) {
		PRI("Hello World");
	}
	else {
		int a, b;
		cin >> a >> b;
		PRI(a + b);
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int count=0;
    int max=0;
    for(int i=0;i<n;i++){
        if(a[i]>=max){
            max=a[i];
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int MAX_V = 1000;
static const int MAX_E = 2000;
static const int INF = 1 << 30;

struct edge{int from, to, cost;};

edge es[MAX_E];

int d[MAX_V];
int V, E;
bool def = true;

void shortest_path(int s){
	for(int i = 0; i < V; i++) d[i] = INF;
	d[s] = 0;
	int cnt = 0;
	while(true){
		cnt++;
		bool update = false;
		for(int i = 0; i < E; i++){
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update) break;
		if(cnt == V){
			def = false;
			return;
		}
	}
}

int main(){
	int r;
	scanf("%d %d %d", &V, &E, &r);
	for(int i = 0; i < E; i++){
		scanf("%d %d %d", &es[i].from, &es[i].to, &es[i].cost);
	}
	shortest_path(r);
	if(!def) printf("NEGATIVE CYCLE\n");
	else{
		for(int i = 0; i < V; i++){
			if(d[i] == INF) printf("INF\n");
			else printf("%d\n", d[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(),v.end()
#define vil vector<long int>
#define vi vector<int> 
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007 
#define MOD 998244353
void solve(ll T){
int n;
cin>>n;
vi a(n),b(n),c(n);
for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
}
int da[n+1],db[n+1],dc[n+1];
da[0]=0;
db[0]=0;
dc[0]=0;
for(int i=1;i<=n;i++){
    da[i]=a[i-1]+max(db[i-1],dc[i-1]);
    db[i]=b[i-1]+max(da[i-1],dc[i-1]);
    dc[i]=c[i-1]+max(da[i-1],db[i-1]);
}
cout<<max(da[n],max(db[n],dc[n]))<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
ll T;
T=1;
//cin>>T;
while(T--){
   solve(T);
return 0;
}
}

Measured memory_bytes: 5548
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int n = sc.nextInt(), m = sc.nextInt();
                        int[][] a = new int[n][m];
                        for (int i = 0; i < n; i++) {
                                for (int j = 0; j < m; j++) {
                                        a[i][j] = sc.nextInt();
                                }
                        }
                        int[] x = new int[m];
                        for (int i = 0; i < m; i++) {
                                x[i] = sc.nextInt();
                        }
                        for (int i = 0; i < n; i++) {
                                int ans = 0;
                                for (int j = 0; j < m; j++) {
                                        ans += x[j] * a[i][j];
                                }
                                System.out.println(ans);
                        }
                }
        }
}


Measured memory_bytes: 40212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int m = 1e9+7;
ll binpow(ll a, ll b){
    a %= m;
    ll res = 1;
    while(b){
        if(b&1){
            res = (res * a) % m;
        }
        a = (a * a)% m;
        b >>= 1;
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    cout<<((binpow(10LL, n) - (2 * binpow(9LL, n))%m + binpow(8LL, n)) + m)%m<<"\n";
    return 0;
}

Measured memory_bytes: 3560
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i].first;
        x[i].second = i;
    }
    sort(x.begin(), x.end());
    vector<int> ord(n);
    for (int i = 0; i < n; i++) {
        ord[x[i].second] = i;
    }

    int med1 = x[n / 2 - 1].first, med2 = x[n / 2].first;

    for (int i = 0; i < n; i++) {
        int ret = 0;
        if (ord[i] <= n / 2 - 1) {
            ret = med2;
        } else {
            ret = med1;
        }
        cout << ret << endl;
    }

    return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std ;
int main()
{
      int k ;
      cin>>k ;
      vector<int> v;
      for(int i=0 ; i<k ; i++)
      {
            int a ;
            cin>>a ;
            v.push_back(a);
      }
      map<int ,int> p ;
      for(auto u : v)
      {
            p[u]++ ;
      }
      int l=0 ;
      for(auto u : p)
            if(u.first <= u.second)
      {
            l+=u.second-u.first ;

      }
      else
      {
            l+=u.second ;

      }

      cout<<l<<endl ;


}

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


int main(){
    int N,M;
    cin >> N >> M;
    priority_queue<int> A;
    rep(i,N){
        int a;
        cin >> a;
        A.push(a);
    }
    
    rep(i,M){
        int b;
        b=A.top()/2;
        A.pop();
        A.push(b);
    }

    ll ans=0;
    while(A.size()!=0){
        ans+=A.top();
        A.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 892
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  char    stk[ 128 ];
  char  * sp = stk;
  int     fl = 1, lfs = 1;

  for ( ; ; )
  {
    const int ch = getchar ( );

    if ( lfs && ch == '.' ) break ;
    lfs = !!( ch == '\n' );
    if ( ch == '.' )
    {
      puts ( fl && sp == stk ? "yes" : "no" );
      fl = 1; sp = stk;
    }

    if ( fl && ch == '(' ) *( sp++ ) = ')';
    if ( fl && ch == ')' ) fl = !!( ( sp != stk ) && ( *( --sp ) == ch ) );
    if ( fl && ch == '[' ) *( sp++ ) = ']';
    if ( fl && ch == ']' ) fl = !!( ( sp != stk ) && ( *( --sp ) == ch ) );
  }

  return ( 0 );
}

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

#define ll long long

string frm, to;
ll a,b;
char ch;
ll n;

int main()
{
    ll n;
    cin>>a>>b;
    ll ones=0, zeros = 0;
    for(int i=0; i<a; i++) cin>>n, frm+=(n+'0'), ones+=(frm[i]=='1'), zeros+=(frm[i]=='0');
    to = "";
    ll one = 0, zero = 0;
    for(int i=0; i<b; i++)
    {
        cin>>n;
        while(n--)
        {
            if(i%2==0) to+='0', zero++;
            else to+='1', one++;
        }
    }
    string newto="null";

    if(zero!=zeros or one!=ones)
    {
        for(int i=0; i<to.size(); i++) to[i] = (!(to[i]-'0'))+'0';
    }
    else if(zero==one)
    {
        newto = "";
        for(int i=0; i<to.size(); i++) newto += (!(to[i]-'0'))+'0';
    }
    ll res = 0, ans = 0;

//    cout << frm << endl;
//    cout << to << " " << newto << endl;

    string newfrm = frm;

    for(int i=0; i<frm.size(); i++)
    {
        int tmp = i;
        if(frm[i]=='0' && to[i]=='1')
        {
            int cnt = 0;
            while(frm[i]=='0' && i<frm.size()) cnt++, i++;
            swap(frm[i], frm[i-cnt]);
            res += cnt;
        }
        else if(frm[i]=='1' && to[i]=='0')
        {
            int cnt = 0;
            while(frm[i]=='1' && i<frm.size()) cnt++, i++;
            swap(frm[i], frm[i-cnt]);
          //  cout << res << " " << cnt << endl;
            res += cnt;
        }
        i = tmp;
    }

    ans = res;

    if(newto!="null")
    {
        res = 0;
        for(int i=0; i<newfrm.size(); i++)
        {
            int tmp = i;
            if(newfrm[i]=='0' && newto[i]=='1')
            {
                int cnt = 0;
                while(newfrm[i]=='0' && i<newfrm.size()) cnt++, i++;
                swap(newfrm[i], newfrm[i-cnt]);
                res += cnt;
            }
            else if(newfrm[i]=='1' && newto[i]=='0')
            {
                int cnt = 0;
                while(newfrm[i]=='1' && i<frm.size()) cnt++, i++;
                swap(newfrm[i], newfrm[i-cnt]);
              //  cout << res << " " << cnt << endl;
                res += cnt;
            }
            i = tmp;
        }

        ans = min(ans, res);
    }


    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  =1e6+1 , limit = 1e17 , mod=1e9+7;
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}
int32_t main(){
    boost;
        
        
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    
    int cr=0;
    int cb=0;
    int cg =0;
    
    
    
    int crg=0;
    int crb=0;
    int cbr=0;
    int cbg=0;
    int cgr=0;
    int cgb=0;
    int res =0;
    for(int i =0 ; i < n ; i++ ){
        
        if(s[i]=='R'){cr++;    res = res + cbg + cgb ;   cgr = cgr + cg ;  cbr = cbr + cb;}
        if(s[i]=='G'){cg++;   res = res  +cbr + crb ;    cbg = cbg + cb;  crg = crg  + cr;}
        if(s[i]=='B'){cb++;   res = res+ cgr + crg;     cgb = cgb + cg;  crb = crb + cr;}
        
        

    }
    
    // cout<<res<<endl;
    
    
    for(int i =2 ; i < n ; i= i +2){
        
        
        for(int j = 0 ; j < n - i ; j++ ){
                
                char a1 = s[j];
                char a2 = s[j+i];
                char a3 = s[(j+i+j)/2];
                
                
                if(a1 != a2 && a2!=a3 && a1!=a3){
                    res--;
                }       
                
        }   
        
        
        
    }
    cout<<res<<endl;
    
    
    
    
}

Measured memory_bytes: 3656
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,C=map(int, sys.stdin.readline().split()) 
stc=[ map(int, sys.stdin.readline().split()) for _ in range(N)]
stc.sort(key=lambda x:(x[0]) )
max_t=max(stc, key=(lambda x: x[1]))[1]

channel=[ deque() for _ in range(C+1) ]

for s,t,c in stc:
    try:
        prev_s,prev_t=channel[c].pop()
        if prev_t==s:
            channel[c].append((prev_s,t))
        else:
            channel[c].append((prev_s,prev_t))
            channel[c].append((s,t))
    except:
        channel[c].append((s,t))


T=[ 0 for _ in range(max_t+1) ] #時間軸

c=1
for c in range(1,C+1):  #チャンネル
    while channel[c]:
        s,t=channel[c].pop()
        for i in range(s,t+1):
            T[i]+=1

print max(T)


Measured memory_bytes: 50844
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int n;

  cin >> n;

  int res = 1000000000;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;

    int count = 0;
    while (k % 2 == 0) {
      k >>= 1;
      count++;
    }
    res = min(res, count);
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();

    sc.close();

    long ans = K * (long) Math.pow(K-1, N-1);

    System.out.println(ans);

  }

}

Measured memory_bytes: 21844
import numpy as np
A, B, H, M = list(map(int, input().split()))
hth = (np.pi / 6.0) * H + (2.0*np.pi / (12*60)) * M
mth = (np.pi / 30.0) * M
hvec = A * np.array([np.cos(hth), np.sin(hth)])
mvec = B * np.array([np.cos(mth), np.sin(mth)])
tmp = np.linalg.norm(hvec - mvec)
print(tmp)

Measured memory_bytes: 27192
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
A = list(map(lambda x: int(x)-1, input().split()))
dic = {}
for a in A:
    dic[a] = dic.get(a, 0)+1
for i in range(N):
    print(dic.get(i, 0))

Measured memory_bytes: 34744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		solve(a, b);
	}

	static void solve(int a, int b) {

		int c = a + b;
		String[] arr = new String[c];

		try {
			for (int i = 0; i < a; i++) {
				arr[i * 2] = "e";
			}

			for (int i = 1; i < b; i++) {
				arr[(i * 2) - 1] = "s";
			}
			System.out.println("Yay!");

		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 21844
arr=[int(input()) for i in range(5)]
brr=[]
result=0

for i in range(5):
    if arr[i]%10!=0:
        brr.append(arr[i]%10)
    else:
        brr.append(arr[i])
ans=brr.index(min(brr))



for i in range(5):
    if i==ans or arr[i]%10==0:
        result+=arr[i]
    else:
        result+=arr[i]+10-arr[i]%10
        
print(result)


Measured memory_bytes: 3064
c = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
a, b = gets.split.map(&:to_i)
ai = c.index(a)
bi = c.index(b)
if ai > bi
    puts 'Alice'
elsif ai < bi
    puts 'Bob'
else
    puts 'Draw'
end

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		for(int i=0;i<n;i++) {
			a[i] = in.nextLong();
		}
		for(int i=0;i<n;i++) {
			b[i] = in.nextLong();
		}
		in.close();
		long[] pow2 = new long[30];
		pow2[0] = 1;
		for(int i=1;i<=29;i++) {
			pow2[i] = pow2[i-1]*2;
		}
		long ans = 0;
		for(int k=0;k<29;k++) {
			long[] tmpa = new long[n];
			long[] tmpb = new long[n];
			for(int i=0;i<n;i++) {
				tmpa[i] = a[i] % pow2[k+1];
				tmpb[i] = (b[i] % pow2[k+1])*2;
			}
			Arrays.sort(tmpb);
			long count = 0;
			for(int i=0;i<n;i++) {
				long start1 = Arrays.binarySearch(tmpb, (pow2[k]-tmpa[i])*2-1);
				start1 = start1<0 ? -(start1+1):start1+1;
				long end1 = Arrays.binarySearch(tmpb, (pow2[k]*2-tmpa[i])*2-1);
				end1 = end1<0 ? -(end1+1):end1+1;
				long start2 = Arrays.binarySearch(tmpb, (pow2[k]*3-tmpa[i])*2-1);
				start2 = start2<0 ? -(start2+1):start2+1;
				long end2 = Arrays.binarySearch(tmpb, (pow2[k]*4-tmpa[i])*2-1);
				end2 = end2<0 ? -(end2+1):end2+1;
				count += (end1 - start1)%2 + (end2 - start2)%2;
				count = count%2;
			}
			if(count%2==1) ans += pow2[k];
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 158492
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

 
n, m = map(int, readline().split())
 
adj = [[] for _ in range(n)]
 
for i in range(m):
    a, b = map(int, readline().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
 
 
import heapq
 
MAX = 10 ** 9 + 5
 
visited = [False for _ in range(n)]
dist = [MAX for _ in range(n)]
path = [0 for _ in range(n)]
 
def dji(start):
    dist[start] = 0
    q = [(0, 0)]
    while len(q) > 0:
        v = heapq.heappop(q)
        if visited[v[1]]:
            continue
        visited[v[1]] = True
        for u in adj[v[1]]:
            if dist[v[1]] + 1 < dist[u]:
                dist[u] = dist[v[1]] + 1
                path[u] = v[1] + 1
                heapq.heappush(q, (dist[u], u))
 
dji(0)
if all(visited):
    print("Yes")
    for i in path[1:]:
        print(i)
else:
    print("No")

Measured memory_bytes: 41192
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	string s;
	vi c (26, 0);
	cin >> s;
	REP(i, SZ(s))
		++c[s[i] - 'a'];

	bool flag = true;
	REP(i, 26)
		if (c[i] > 1)
			flag = false;

	if (flag)
		cout << "yes";
	else
		cout << "no";
	cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int a,b;
	scan(a);scan(b);
	if(b%a==0) prin(a+b);
	else prin(b-a);
	return 0;
}


Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int x = 0, y = 0, z = 0, w = 0;
    for (int i= 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "AC") x++;
        else if (s == "WA") y++;
        else if (s == "TLE") z++;
        else w++;
    }
    cout << "AC x " << x << endl;
    cout << "WA x " << y << endl;
    cout << "TLE x " << z << endl;
    cout << "RE x " << w << endl;
    return 0;
}




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

using namespace std ;

int main ( )
{
    string s ;
    cin >>s;
    int count = 0 ;
    
    int i = 0 , j ;
    for ( i = 0, j = s.size() -1  ; i < s.size()/2 and j >= s.size()/2 ; i++ , j--  )
    {
        if ( s[i] != s[j ])
        {
            //cout << s[i] << "  " << s[j] << endl;
            count ++ ;
        }
    }
    
    cout << count << endl  ;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=9982453;

const int MAX=510000;

vll fac(MAX);
vll finv(MAX);
vll inv(MAX);

void combinit(ll m){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    rep2(i,2,MAX){
        fac[i]=fac[i-1]*i%m;
        inv[i]=m-inv[m%i]*(m/i)%m;
        finv[i]=finv[i-1]*inv[i]%m;
    }
}

ll combi(ll n,ll k,ll m=inf){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%m)%m;
}

int main(){
    combinit(inf);
    ll s;cin>>s;
    ll tmp=s/(ll)3+(ll)1;
    ll ans=(ll)0;
    for(ll k=(ll)1;k<tmp;k++)ans+=combi(s-(ll)2*k-(ll)1,k-(ll)1);
    cout<<ans%inf<<endl;
}

Measured memory_bytes: 14956
#include<stdio.h>
int main(){
  long long int sum;
  int a,n,i,min,max;
  scanf("%d",&n);
  scanf("%d",&a);
  min=max=sum=a;
  for(i=1;i<n;i++){
    scanf("%d",&a);
    sum+=a;
    if(min>a){
      min=a;
    }
    if(max<a){
      max=a;
    }
  }
  printf("%d %d %ld\n",min,max,sum);
  return(0);
}

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

typedef long long ll;
typedef unsigned long long ull;

template<unsigned long long SIZE> class unionFind{
    protected:
        long long uni[SIZE];
        long long diff_weight[SIZE];
    public:
        unionFind(){
            for(int i=0;i<SIZE;i++){
                uni[i]=-1;
                diff_weight[i]=0;
            }
        }
        unsigned long long root(unsigned long long a){
            if(a>=SIZE) throw std::range_error("与えられたインデックスが木の範囲外です");
            if(uni[a]<0) return a;
            else{
                unsigned long long r=root(uni[a]);
                diff_weight[a]+=diff_weight[uni[a]];
                return uni[a]=r;
            }
        }
        long long weight(unsigned long long a){
            root(a);
            return diff_weight[a];
        }
        long long diff(unsigned long long a, unsigned long long b){
            if(isSame(a,b)) return weight(b)-weight(a);
            else return INT64_MAX;
        }
        unsigned long long count(unsigned long long a){
            return -uni[root(a)];
        }
        bool merge(unsigned long long a, unsigned long long b, long long w=1){
            w+=weight(a);  w-=weight(b);
            a=root(a);  b=root(b);
            if(a==b) return false;
            if(uni[a]>uni[b]){
                swap(a, b);
                w=(-w);
            }
            uni[a]+=uni[b];
            uni[b]=a;
            diff_weight[b]=w;
            return true;
        }
        bool isSame(unsigned long long a,unsigned long long b){
            return root(a)==root(b);
        }
};

int main(){
    unionFind<100001> uf;
    int N, M;
    cin >> N >> M;
    int p[100001], ip[100001];
    for(int i=1;i<=N;i++){
        cin >> p[i];
        ip[p[i]] = i;
    }
    for(int i=0;i<M;i++){
        int x,y;
        cin >> x >> y;
        uf.merge(x,y);
    }

    int ans = 0;
    for(int i=1;i<=N;i++){
        if(uf.isSame(i, ip[i])) ans++;
    }

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

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i,j;
    string s;
    cin>>n;
    cin>>s;
    int pre[26]={0},suf[26]={0},ans=0,tp;
    for (i=0;i<n;i++)
        suf[s[i]-'a']++;
    for (i=0;i<n-1;i++)
    {
        pre[s[i]-'a']++;
        suf[s[i]-'a']--;
        tp=0;
        for (j=0;j<26;j++)
        {
            if (pre[j]>0 && suf[j]>0)
                tp++;
        }
        ans=max(ans,tp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int n,m,p,q;
vector<int>edge[100001];
bool vis[100001];
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=1; i<=m ;i++){
		cin >> p >> q;
		edge[p].push_back(q);
		edge[q].push_back(p);
	}
	deque<int>ans;
	ans.push_back(1);
	vis[1]=true;
	while(true){
		int cur=ans.back();
		bool ok=true;
		for(int i=0; i<edge[cur].size() ;i++){
			if(!vis[edge[cur][i]]){
				ans.push_back(edge[cur][i]);
				vis[edge[cur][i]]=true;
				ok=false;
				break;
			}
		}
		if(ok) break;
	}
	while(true){
		int cur=ans.front();
		bool ok=true;
		for(int i=0; i<edge[cur].size() ;i++){
			if(!vis[edge[cur][i]]){
				ans.push_front(edge[cur][i]);
				vis[edge[cur][i]]=true;
				ok=false;
				break;
			}
		}
		if(ok) break;
	}
	cout << ans.size() << endl;
	for(int i=0; i<ans.size()-1 ;i++){
		cout << ans[i] << ' ';
	}
	cout << ans.back() << endl;
}

Measured memory_bytes: 6784
#include <stdio.h>
#include <ctype.h>

typedef long long ll;

ll n, k;
ll w[100001];

int check(ll P) {
  ll sum = 0, cnt = 0;
  ll i;
  for(i = 0; i < n; i++) {
    if(w[i] > P) return 0;
    sum += w[i];
    if(sum > P) {
      cnt++;
      sum = w[i];
    }
  }
  return cnt < k;
}

int main() {
  ll i;
  
  scanf("%lld %lld", &n, &k);
  for(i = 0; i < n; i++) scanf("%lld", w+i);
  w[n] = 0;
  n++;

  ll lb = 0, ub = 1000000010;
  
  while(lb + 1 < ub) {
    ll mb = (lb+ub) / 2;
    if(check(mb)) ub = mb;
    else lb = mb;
  }

  printf("%d\n", ub);

  return 0;
}

Measured memory_bytes: 1376
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>
#include<stack>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;

int dy8[8] = { 2,2,-2,-2,1,1,-1,-1 };
int dx8[8] = { 1,-1,1,-1,2,-2,2,-2 };
int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };


/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
constexpr ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

// vector
template <typename T>
istream& operator>>(istream & is, vector<T> & vec) { for (T& x : vec) is >> x; return is; }
// pair
template <typename T, typename U>ostream& operator<<(ostream & os, pair<T, U> & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; }
// vector
template <typename T>ostream& operator<<(ostream & os, const vector<T> & vec) { os << "{";	for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; }
// map
template <typename T, typename U>ostream& operator<<(ostream & os, map<T, U> & map_var) { os << "{";	repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; }
// set
template <typename T>ostream& operator<<(ostream & os, set<T> & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; }


int main() {

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

	int N;
	cin >> N;
	string S;
	cin >> S;
	int ans = 1;
	for (int i = 1; i < N; i++)
	{
		if (S[i] == S[i - 1]) {

		}
		else
		{
			ans++;
		}
	}
	cout << ans << endl;

	
}


Measured memory_bytes: 512
n=int(input())
lines=[]
Taro=0
Hanako=0

for i in range(n):
    lines.append(input().split(" "))
    if lines[i][0] > lines[i][1]:
        Taro+=3
    elif lines[i][0] == lines[i][1]:
        Taro+=1
        Hanako+=1
    else:
        Hanako+=3

print(Taro, Hanako)


Measured memory_bytes: 5712
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){
  int a;
  bool fg[4];
  vector<int>v;

  while(true){

    v.clear();
    fill(fg,fg+4,false);

    for(int i=0;i<5;i++){
      cin >> a;
      if(a==0)return 0;
      v.push_back(a);
    }    

    for(int i=0;i<5;i++)fg[v[i]]=true;
    if((fg[1] && fg[2] && fg[3]) ||
       (fg[1] && !fg[2] && !fg[3]) ||
       (!fg[1] && !fg[2] && fg[3]) ||
       (!fg[1] && fg[2] && !fg[3])){
      for(int i=0;i<5;i++)cout << 3 << endl;
    }
    
    if(fg[1] && fg[2] && !fg[3]){
      for(int i=0;i<5;i++){
	if(v[i]==1)cout << 1 << endl;
	else if(v[i]==2)cout << 2 << endl;
      }
    } 
    if(fg[1] && !fg[2] && fg[3]){
      for(int i=0;i<5;i++){
      	if(v[i]==1)cout << 2 << endl;
	else if(v[i]==3)cout << 1 << endl;
      }
    }
    if(!fg[1] && fg[2] && fg[3]){
      for(int i=0;i<5;i++){
	if(v[i]==2)cout << 1 << endl;
	else if(v[i]==3)cout << 2 << endl;
      }
    }
	  
  }

  return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>  
int main()  
{  
    char a[22];  
    
     
        for(int i=0;i<20;i++)  
            scanf("%c",&a[i]);  
        for(int i=0;i<=4;i++)  
            printf("%c",a[i]);  
        printf(" ");  
        for(int i=6;i<=12;i++)  
            printf("%c",a[i]);  
        printf(" ");  
        for(int i=14;i<=18;i++)  
            printf("%c",a[i]);  
          
      
    return 0;  
}  

Measured memory_bytes: 128