akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
typedef long long ll;


int main() {
  int n;
  cin >> n;
  int ans = 0;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  while(true){
    if(*max_element(h.begin(), h.end()) == 0) break;
    int i = 0;
    while(i < n){
      if(h[i] == 0)i++;
      else{
        ans++;
        while(i < n && h[i] > 0){
          h[i]--;
          i++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int H, A[MAX + 1];

void maxHeapify(int i) {
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  if (l <= H && A[l] > A[i]) {
    largest = l;
  } else {
    largest = i;
  }

  if (r <= H && A[r] > A[largest]) {
    largest = r;
  }

  if (largest != i) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
};

int main() {
  cin >> H;

  for (int i = 1; i <= H; i++) {
    cin >> A[i];
  }

  for (int i = H / 2; i > 0; i--) {
    maxHeapify(i);
  }

  for (int i = 1; i <= H; i++) {
    cout << ' ' << A[i];
  }
  cout << endl;
};



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

int main() {
    long long  N, M;
    cin >> N >> M;
    long long p[100100];
    vector<string> S(100100);
    for (int i = 0; i < M; i++) {
        cin >> p[i];
        cin >> S[i];
    }

    vector<long long> WA(N);
    vector<bool> AC(N);
    for (int i = 0; i < N; i++) AC[i] = false;
    long long correct = 0, wrong = 0;

    for (int i = 0; i < M; i++) {
        if (S[i] == "WA" && !(AC[p[i]-1])) WA[p[i]-1] ++;
        else if (S[i] == "AC") AC[p[i]-1] = true;
    }

    for (int i = 0; i < N; i++) {
        if (AC[i] == true) {
            correct ++;
            wrong += WA[i];
        }
    }

    cout << correct << " " << wrong << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

long long a[10005];

int main() 
{
	int d, n;
	scanf("%d%d", &d, &n);
	int ans = 1;
	printf("%d", n + (n / 100));
	for(int i = 1; i <= d; i++) printf("00");
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    }
}

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

int main(void){
  char *s, *t;
  int n;
  char *ans;

  scanf("%d", &n);
  
  s = (char *)malloc(n+2);
  t = (char *)malloc(n+2);
  ans = (char *)malloc(2*n+4);

  scanf("%s", s);
  scanf("%s", t);

  for(int i=0; i<n+1; i++){
    ans[2*i] = s[i];
    ans[2*i+1] = t[i];
  }

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxi(v) distance(v.begin(),max_element(v.begin(),v.end()))
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(int  i=a;i<=b;i++)
/*Special*/
#define Ezio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(something)  cerr<<#something<<" - "<<something<<"\n";         

int main()
{
  
   Ezio
   ll t,m,n,k,x,a,b;
   string s;
   
   cin>>n>>m>>k;
   x=0;
   vector<ll>A(n+1);
   vector<ll>B(m+1);
   fn(i,n){
     cin>>a;
     x+=a;
     A[i]=x;
   }
   x=0;
   fn(i,m){
     cin>>a;
     x+=a;
     B[i]=x;
   }
   ll an=0;
   for(ll i=0,j=m;i<=n;i++){
     
     if(A[i]>k) break;
     
     while(B[j]>k-A[i]) j--;
     an=max(an,i+j);
   }
   
   cout<<an<<endl;
   return 0;
}
    

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

using namespace std;

const int MOD = 1e9 + 7;

string s;
int cnt, ans;

int sum(int a, int b) {
    return (a + b) % MOD;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int power(int a, int p) {
    int res = 1;
    for (; p; p /= 2) {
	if (p % 2)
	    res = mul(res, a);
	a = mul(a, a);
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++)
	if (s[i] == '1') {
	    ans = sum(ans, mul(power(2, cnt), power(3, n - i - 1)));
	    cnt++;
	}
    return cout << sum(ans, power(2, cnt)), 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

vector<int> g[100002], ans;
bool used[100002]{};
int n, m;

void dfs(int s) {
    ans.push_back(s);
    used[s] = true;
    for (int i = 0; i < g[s].size(); i++) {
        if (used[g[s][i]])
            continue;
        used[g[s][i]] = true;
        dfs(g[s][i]);
        return;
    }
    return;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int st = 0;
    for (int i = 0; i < n; i++) {
        if (g[i].size() == 1) {
            st = i;
            break;
        }
    }
    dfs(st);
    bool flag = true;
    while (flag) {
        flag = false;
        for (int i = 0; i < g[st].size(); i++) {
            if (!used[g[st][i]]) {
                vector<int> sub;
                sub = ans;
                ans.clear();
                dfs(g[st][i]);
                reverse(ans.begin(), ans.end());
                for (int j = 0; j < sub.size(); j++) {
                    ans.push_back(sub[j]);
                }
                st = ans[0];
                flag = true;
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        if (i == ans.size() - 1)
            cout << ans[i] + 1 << endl;
        else
            cout << ans[i] + 1 << " ";
    }
    return 0;
}

Measured memory_bytes: 9976
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]a = new int[N];
			int goukei = 0;
			
			for(int i = 0;i<N;i++) {
				a[i] = scan.nextInt();
				Map<Integer,Integer> map  = primefact(a[i]);
				
				if(map.get(2)!=null) {
					goukei+=map.get(2);
				}		
			}
			
			
			System.out.println(goukei);
	
			
		}
	}
	
	
	
	
	/*for(Integer key:A.keySet()) {
	System.out.println(key);//素数
	System.out.println(A.get(key));//素数の指数
	}みたいな感じで表示できる*/	
	private static Map<Integer,Integer> primefact(int n){//入力ｎの素数とその指数をmapに格納
		Map<Integer,Integer> map = new TreeMap<Integer,Integer>();
		for(int i = 2;i*i<=n;i++) {
			if(n%i!=0) {
				continue;
			}
			int ex = 0;//素因数分解した素数たちの指数
			
			while (n % i == 0) {//iでわれる限りやる
				++ex;
				n /= i;
				}		
			map.put(i, ex);//(素数、その素数の指数)
		}
		if(n!=1) {//もし最後に素数が残ったら入れておく
			map.put(n, 1);
		}
		return map;
	}
}


Measured memory_bytes: 37576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ios                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define fill(x, v) memset(x, v, sizeof(x))
const ll mod = 1000000007;
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
//--------dsu----------
vector<int> volume(1000000);
vector<int> parent(1000000);

void initialise_dsu()
{
    for (int i = 0; i < volume.size(); i++)
        volume[i] = 1;
    for (int i = 0; i < parent.size(); i++)
        parent[i] = i;
}

int find_par(int v)
{
    return (v == parent[v] ? v : parent[v] = find_par(parent[v]));
}

void union_sets(int a, int b)
{
    a = find_par(a);
    b = find_par(b);
    if (a != b)
    {
        if (volume[a] < volume[b])
            swap(a, b);
        parent[b] = a;
        volume[a] += volume[b];
    }
}

int power(int x, unsigned int y, int p)
{
    int res = 1;

    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
//-------------------------
string arr;
map<pair<char, char>, char> mpsym;

int main()
{
    ios;

    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll x = k; x <= n + 1; x++)
    {
        ans += (n * x - (x) * (x - 1) + 1) % mod;
        ans = ans % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11048
def main():
    X,Y,A,B,C = map(int,input().split())
    R = [int(i) for i in input().split()]
    G =  [int(i) for i in input().split()]
    N =  [int(i) for i in input().split()]
    R.sort(reverse=True)
    G.sort(reverse=True)
    N.sort(reverse=True)
    E = R[:X] + G[:Y] + N
    E.sort(reverse=True)
    print(sum(E[:(X+Y)]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 23644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] dp = new int[n][3];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < 3; j++) {
                dp[i][j] = sc.nextInt();
            }
        }
        for(int i = n - 2; i >= 0; i--) {
            // 0
            dp[i][0] += Math.max(dp[i + 1][1], dp[i + 1][2]);
            // 1
            dp[i][1] += Math.max(dp[i + 1][2], dp[i + 1][0]);
            // 2
            dp[i][2] += Math.max(dp[i + 1][0], dp[i + 1][1]);
        }
        System.out.println(Math.max(dp[0][0], Math.max(dp[0][1], dp[0][2])));
    }
}


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

using namespace std;
typedef long long ll;

int main(void) {
    int n, e, flag = 0;
    ll p, q;

    while (scanf("%d", &n), n) {
        vector<int> v;
        map<int, ll> mp;
        for (int i = 0; i < n; i++) {
            scanf("%d %lld %lld", &e, &p, &q);
            if (!mp[e]) v.push_back(e);
            mp[e] += p * q;
        }

        flag = 0;
        for (int i = 0; i < v.size(); i++) {
            if (mp[v[i]] < 1000000) continue;
            printf("%d\n", v[i]);
            flag = 1;
        }
        
        if (!flag) puts("NA");
    }
    return 0;
}


Measured memory_bytes: 3268
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, S: "List[str]"):
    c_h = [[0] * W for _ in range(H)]
    c_w = [[0] * W for _ in range(H)]
    for i in range(H):
        tmp = 0
        cnt = 0
        for j in range(W):
            if S[i][j] == '#':
                for k in range(tmp, j):
                    c_h[i][k] = cnt
                cnt = 0
                tmp = j + 1
            else:
                cnt += 1
        for k in range(tmp, W):
            c_h[i][k] = cnt
    for j in range(W):
        tmp = 0
        cnt = 0
        for i in range(H):
            if S[i][j] == '#':
                for k in range(tmp, i):
                    c_w[k][j] = cnt
                cnt = 0
                tmp = i + 1
            else:
                cnt += 1
        for k in range(tmp, H):
            c_w[k][j] = cnt
    ret = 0
    for i in range(H):
        for j in range(W):
            ret = max(ret, c_h[i][j] + c_w[i][j] - 1)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 121820
use proconio::input;
use std::collections::HashMap;

fn max(a: &str, b:&str) -> bool {
  if a.len() == b.len() {
    a > b
  } else {
    a.len() > b.len()
  }
}

fn main() {
  input! {
    n: usize,
    m: usize,
    mut vals: [usize;m]
  }

  let mut dp: Vec<String> = vec![String::from("");n+1];
  let mut map: HashMap<usize, usize> = HashMap::new();
  let def: [usize;9] = [2, 5, 5, 4, 5, 6, 3, 7, 6];
  let mut index = 1;
  for v in def.into_iter() {
    map.insert(index, *v);
    index += 1;
  }
  
  let vals: Vec<(String, usize)> = vals
  .into_iter()
  .map(|v| (v.to_string(), *map.get(&v).unwrap()))
  .collect();
  
  for v in vals.iter() {
    if n+1 <= v.1 { continue }
    let next = v.0.to_string();
    if max(&next, &dp[v.1]) {
      dp[v.1] = next;
    }
  }
  
  for current in 0..=n {
    for (num, cost) in vals.iter() {
      let cost = *cost;
      if current < cost { continue }
      if &dp[current - cost] == "" { continue }
      
      let next = (dp[current - cost].clone() + &num).to_string();
      if max(&next, &dp[current]) {
        dp[current] = next;
      }
    }
  }
  println!("{}", dp[n]);
}

Measured memory_bytes: 28320
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int[] a = new int[3];
        int count = 0;
        for(int i = 0; i < s.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }

        int b = a[0] - a[1];

        if (a[2]-b>0) Console.WriteLine(a[2] - b);
        else Console.WriteLine(0);

    }

}

Measured memory_bytes: 13140
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 999999999999999;
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n){
    scanf("%ld",&(a.at(i)));
    --a.at(i);
  }
  vector<bool> b(n,false);
  
  //cnt : テレポート回数
  ll cnt = 0;
  //now : 現在の街のid , lp_id : ループの始まりであり、終わりでもある街
  ll now = 0,lp_id;
  while(1){
    // k回テレポートした場合
    if( cnt == k ){
      cout << now+1 << endl;
      return 0;
    }
    //すでに訪れたかどうか <- 訪れているのならループしている
    if( b.at(now) ){
      lp_id = now;
      break;
    }else{
      b.at(now) = true;
    }
    //テレポートする
    now = a.at(now);
    ++cnt;
  }
  
  k -= cnt;
  ll lp_len = 0;
  //ループの長さを数える
  while(1){
    if( lp_len != 0 && now == lp_id ) break;
    now = a.at(now);
    ++lp_len;
  }
  
  //kの残り
  k %= lp_len;
  
  cnt = 0;
  now = lp_id;
  
  while(1){
    if( cnt == k ){
      cout << now+1 << endl;
      return 0;
    }
    now = a.at(now);
    ++cnt;
  }
 
  
  return 0;
}

Measured memory_bytes: 4844
N = int(input())
A = list(map(int,input().split()))
A.sort()

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)

Measured memory_bytes: 68412
n=int(input())
dic1={}
bokk=[]
list0=[]
for i in range(n):
  c,p=map(str,input().split())
  p=int(p)
  list0.append([c,p])
  if c not in dic1:
    dic1[c]=[]
  dic1[c].append(p)
dic1=dict(sorted(dic1.items()))
for i,k in dic1.items():
  k.sort(reverse=True)
  for j in k:
    bokk.append([i,j])
for i in bokk:
  print(list0.index(i)+1)

Measured memory_bytes: 9212
#include<iostream>
using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (a - b >= 0)cout << "delicious" << endl;
	else if (b - a <= x)cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    set<int> dic;
    int N; cin >> N;
    while (N--) {
        int a; cin >> a;
        dic.emplace(a);
    }
    int M; cin >> M;
    while (M--) {
        int b; cin >> b;
        if (dic.count(b)) dic.erase(b);
    }

    for (auto i : dic) cout << i << ln;
}


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

int main(){
 int a, b, k, i;
 cin>>a>>b>>k;
 if(k>(b-a)/2)for(i=a;i<=b;i++)cout<<i<<endl;
 else{
  for(i=a;i<=a+k-1;i++)cout<<i<<endl;
  for(i=b-k+1;i<=b;i++)cout<<i<<endl;
 }
}


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

template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

vector<P> prime_factirize(ll n) {
    vector<P> res;

    for (ll a = 2; a * a <= n; ++a) {
        if (n % a != 0) continue;

        ll ex = 0;
        while (n % a == 0) {
            ++ex;
            n /= a;
        }

        res.emplace_back(a, ex);
    }
    if (n != 1) res.emplace_back(n, 1);

    return res;
}


int main() {
    ll a, b; cin >> a >> b;
    ll g = gcd(a, b);
    vector<P> res = prime_factirize(g);
    cout << (res.size() + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector< int > vi;
typedef vector< ll > vll;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define fi first
#define se second
#define endl '\n'
#define mod 1000000007  //1e9+7
#define pi 3.14159265358979323846
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define inf INT_MAX
const int N = 2e5 + 5;


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

   	int n, k;
   	cin >> n >> k;

   	vi a(n);
   	rep(i,0,n) cin >> a[i];

   	vll dp(n,LLONG_MAX);
   	dp[0] = 0;

   	rep(i,1,n)
   	{
   		rep(j,i-k,i)
   		{
   			if(j < 0) continue;
   			dp[i] = min(dp[i],dp[j]+abs(a[i]-a[j]));
   		}
   	}

   	cout << dp[n-1];

	return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int start_a = 0,start_b = a;
  while(1){
    if( start_a <= c && c <= start_b ){
      cout << c << endl;
      break;
    }
    //int check = c - b;
    start_a += a + b;
    start_b = start_a + a;
    if( c < start_a ){
      c += 60;
     
      // if( c - start_b == check ){
      if( c > 100000 ){
	cout << -1 << endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

vector<int> parent;

int find(int a){
	if(parent[a] == a) return a;

	return parent[a] = find(parent[a]);
}

void unit(int a, int b){
	int pa = find(a);
	int pb = find(b);
	parent[pa] = pb;
	return;
}

int main(void){
	int n,m;
	cin>>n>>m;
	rep(i,2*n+2){
		parent.push_back(i);
	}
	int x,y,z;
	rep(i,m){
		cin>>x>>y>>z;
		if(true || z%2==0){
			unit(x,y);
			unit(x+n,y+n);
		}else{
			unit(x,y+n);
			unit(y,x+n);
		}
	}
	vector<bool> checked;
	rep(i,2*n+2){
		checked.push_back(false);
	}
	int ans = 0;
	reps(i,n){
		int p = find(i);
		if(checked[p]) continue;
		checked[p] = true;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1652
#include<bits/stdc++.h>
using namespace std;
 void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
 int main()
{
    fast();
    double r;
    const double pi = 3.14159265359;
    cin >> r;
    cout << 2 * r * pi;
   
    return 0;
    }
   

Measured memory_bytes: 3756
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;

int main()
{
	int D,T,S;
	cin >> D >> T >> S;
	if (D > S * T) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}

}



Measured memory_bytes: 3132
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	const int stations[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};
	int n;
	scanf("%d", &n);
	rep(i, n){
		int s, g;
		scanf("%d%d", &s, &g);
		
		for(s = 5<s || s<g ? s : 15-s; stations[s] != stations[g]; s=(s+1)%15)
			printf("%d ", stations[s]);
		printf("%d\n", stations[g]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
string n;int ans,k;
int g(int a,int b){
  int res=1;
  for(int i=0;i<b;i++)res*=a-i;
  for(int i=1;i<=b;i++)res/=i;
  while(b--)res*=9;
  return res;
}
int f(int i,int a){
  int res=0,rem=n.size()-i;
  if(rem<a)return 0;
  if(!a)return 1;
  if(n[i]=='0')return f(i+1,a);
  return f(i+1,a-1)+(n[i]-'1')*g(rem-1,a-1)+g(rem-1,a);
}

signed main(){
  cin>>n>>k;
  cout<<f(0,k)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <stack>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	int n; cin >> n;
	cout << n + n*n + n*n*n;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;


int n;
vector<int> v;

vector<int> del(vector<int> a, int p){
    vector<int> ans;
    for(int i = 0;i < a.size();i++){
        if(p != i){
            ans.push_back(a[i]);
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        int val;
        cin >> val;
        v.push_back(val);
    }
    vector<int> op;
    for(int i = 1;i <= n;i++){
        int pos = -1;
        for(int j = v.size();j >= 1;j--){
            if(v[j - 1] == j){
                pos = j - 1;
                break;
            }
        }
        if(pos == -1){
            cout << -1 << endl;
            return 0;
        }else{
            v = del(v, pos);
            op.push_back(pos + 1);
        }
    }
    reverse(op.begin(), op.end());
    for(auto val : op){
        cout << val << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve(arr,n):
    hashmap=dict()
    for index in range(1,n+1):
        key=index+arr[index-1]
        if hashmap.get(key)!=None:
            hashmap[key]+=1
        else:
            hashmap[key]=1    
    count=0
    for index in range(1,n+1):
        key=index-arr[index-1]
        if hashmap.get(key)!=None:
            count+=hashmap[key]
    return count        






n=int(input())
arr=[int(i) for i in input().split()]
print(solve(arr,n))    


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

int main() {
    long long n; cin >> n;
    
    long long mn = 10000000000;
    for(long long a = 1; a < sqrt(n)+1; ++a) {
        if(n % a != 0) continue;
        
        long long b = n / a;
        if(mn > max(a, b)) mn = max(a, b);
    }
    
    int res = 0;
    while(mn) {
        mn /= 10;
        ++res;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_lines = [];
var output;
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

reader.on('line', (line) => {
    input_lines.push(parseInt(line));
  });

reader.on('close', () => {
    var K = input_lines[0];
    var seq = 7 % K;
    var flag = false;
    var cnt = 1;

    while(cnt <= K){
        if(seq == 0){
            flag = true;
            break;
        }
        cnt++;
        seq = ((seq * 10) % K + 7) % K;
    }

    if(flag){
        output = cnt;
    } else {
        output = -1;
    }

    console.log(output);
});

Measured memory_bytes: 32984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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 n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll res=0;
    rep(i,n){
        if(a[i]<i+1) continue;
        if(a[a[i]-1]==i+1) res++;
    }
    cout<<res<<endl;
    return 0;
}

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

int main() {
  int N;
  double sum=0;
  cin >> N;
  rep(i, N){
    double A;
    cin >> A;
    sum = sum + 1 / A;
  }
  cout << 1 / sum << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int n, m;

int check(int k) {
    return m / k >= n;
}

int main() {
    scanf("%d%d", &n, &m);
    int sqrt_m = int(sqrt(m) + 0.5);
    int res = 1;
    for (int i = 1; i <= sqrt_m; i++) {
        if (m % i == 0) {
            if (check(i)) {
                res = max(res, i);
            }
            if (check(m / i)) {
                res = max(res, m / i);
            }
        }
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int t = n, c = 0;
	while (t > 0) {
		c += t % 10;
		t /= 10;
	}
	if (n % c == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 2e5 + 10;
int x[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    vector < int > f;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        f.emplace_back(x);
    }
    sort(f.begin(), f.end());
    int who = f[0];
    for (int i = 1; i + 1 < n; i++) {
        if (abs(2 * f[i] - f.back()) < abs(2 * who - f.back())) who = f[i];
    }
    cout << f.back() << " " << who;
    return 0;
}

Measured memory_bytes: 3872
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    string S; cin >> S;
    bool b = true;
    repp(i,0,S.size()) {
        if (i%2==0) {
            b &= S[i] == 'R' || S[i] == 'U' || S[i] == 'D';
        } else {
            b &= S[i] == 'L' || S[i] == 'U' || S[i] == 'D';
        }
    }
    if (b) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int h, w, d;
    cin >> h >> w >> d;

    vector<int> b(h * w), c(h * w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;
            a--;

            b[a] = i * w + j;
        }
    }

    for (int k = d; k < h * w; k++) {
        int i0 = b[k - d] / w;
        int j0 = b[k - d] % w;
        int i1 = b[k] / w;
        int j1 = b[k] % w;
        c[k] = c[k - d] + abs(i1 - i0) + abs(j1 - j0);
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;

        cout << c[r] - c[l] << '\n';
    }

    return 0;
}

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

int main() {
  int n,k,q;
  cin >>n >> k >> q;
  vector<int> v(n,k-q);
  rep(i,q){
     int a; cin >> a;
     a--;
     v[a]++;
  }
  rep(i,n){
     if(v[i]<=0)
     cout << "No" << endl;
     else 
     cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	long long N;
	cin >> N;
	auto f = 0;
	for (auto X = N; X > 0; X /= 10)
	{
		f += X % 10;
	}

	if (N % f == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
<?php
function isPrime( $x )
{
    if( 2 == $x ) return true;
    if( 0 == $x%2 ) return false;
    for( $i=3; $i*$i<=$x; $i++ ) {
        if( 0 == $x%$i ) { return false; }
    }
    return true;
}
	$n = trim( fgets( STDIN ) );
	$cnt = 0;
	$primes = [];
	while( $n-- ) {
		$num = trim( fgets( STDIN ) );
		if(  FALSE !== array_search( $num, $primes ) || isPrime( $num ) ) {
			if( FALSE === array_search( $num, $primes ) ) {
				array_push( $primes, $num );
			}
			$cnt++;
		}
	}
	print $cnt;
?>

Measured memory_bytes: 15348
#include<stdio.h>
     
int main(void)
{
   int a,b,k,n,i;
   scanf("%d%d%d",&a,&b,&k);
     
   for(i=a;i<=b;i++){
      if((i<=a+k-1)||(i>=b-k+1))
         printf("%d\n",i);
     }
     return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var s, t, u string
	var a, b int
	fmt.Scan(&s, &t, &a, &b, &u)
	if u == s {
		fmt.Printf("%d %d\n", a-1, b)
	} else {
		fmt.Printf("%d %d\n", a, b-1)
	}
}

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

int main(){
    int n, d; cin >> n >> d;
    vector<vector<int>> vec(n);
    rep(i, n){
        vec[i].resize(d);
        rep(j, d) cin >> vec[i][j];
    }
    int ans = 0;
    rep(i, n){
        for (int j = i; j < n; j++){
            if (i == j) continue;
            double dist = 0;
            rep(k, d){
                dist += pow(abs(vec[i][k] - vec[j][k]), 2); 
            }
            double sqrt_dist = (double)sqrt(dist);
            if (pow((int)sqrt_dist, 2) == dist) ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	}

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

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 34888
N = input()
R_min = input()
R_max = 0
diff_max = R_max - R_min

R = R_min
for i in range(0, N-1):
    R = input()
    a = R - R_min
    if diff_max < a:
        diff_max = a
    if R < R_min:
        R_min = R

print(diff_max)


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 998244353;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a,b,c,d;
  cin>>a>>b>>c>>d;

  ll dp[c+3][d+3];
  REP(i,c+1)REP(j,d+1)dp[i][j]=0;
  dp[a][b]=1;
  for(ll y=a; y<=c; y++){
    for(ll x=b; x<=d; x++){
      dp[y+1][x]=(dp[y+1][x]+dp[y][x]*x%MOD)%MOD;
      dp[y][x+1]=(dp[y][x+1]+dp[y][x]*y%MOD)%MOD;
      dp[y+1][x+1]=(dp[y+1][x+1]-dp[y][x]*x%MOD*y%MOD+MOD)%MOD;
    }
  }

  cout<<dp[c][d]<<endl;

}



Measured memory_bytes: 73936
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<string> s(n);
  REP(i, 0, n) {
    cin >> s[i];
    sort(ALL(s[i]));
  }
  string ans = s[0];
  DUMP(s);
  REP(i, 1, n) {
    stringstream update;
    int cur = 0;
    REP(c, 0, ans.length()) {
      for (int d = cur; d < s[i].length(); d++) {
        if (ans[c] == s[i][d]) {
          update << ans[c];
          cur = d+1;
          break;
        }
      }
    }
    ans = update.str();
    DUMP(i, ans);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int, int> > a;
    rep (i, n) {
        int n;
        cin >> n;
        a.push_back(make_pair(n, i + 1));
    }
    sort(a.begin(), a.end());
    rep (i, n) {
        if (i == n - 1) cout << a[i].second << endl;
        else cout << a[i].second << " ";
    }
    
    return 0;
}



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

#define ll long long

int main(){
    ll n,x,i;
    cin>>n;
    for (i=1;i<=n;i++) {
        cin>>x;
        if (x%2==0) {
            if ((x%3!=0)&&(x%5!=0)) {
                cout<<"DENIED";
                exit(0);
            }
        }
    }
    cout<<"APPROVED";
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

vector<int> uf, usz;
int nc;

void init(int n){
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

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

int find(int a){
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}

void union_(int a, int b){
  a = find(a);
  b = find(b);

  if(a != b){
    if(usz[a] >= usz[b]){
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}

int check(int a, int b){
  return (find(a) == find(b)) ? 1 : 0;
}

int get_size(int a){
  return usz[find(a)];
}

int main() {
  ll n;
  cin>>n;
  init(n);
  vector<pair<pair<ll,ll>, ll> > v1;
  vector<pair<pair<ll,ll>, ll> > v2;
  vector<pair<ll, pair<ll,ll> > > v3;
  rep(i,0,n){
    ll a,b;
    cin>>a>>b;
    v1.pb(mp(mp(a,b),i));
    v2.pb(mp(mp(b,a),i));
  }
  sort(all(v1));
  sort(all(v2));
  rep(i,0,v1.sz-1){
    ll a1 = v1[i+1].fi.fi-v1[i].fi.fi;
    ll b1 = v1[i].se;
    ll c1 = v1[i+1].se;
    ll a2 = v2[i+1].fi.fi-v2[i].fi.fi;
    ll b2 = v2[i].se;
    ll c2 = v2[i+1].se;
    v3.pb(mp(a1,mp(b1,c1)));
    v3.pb(mp(a2,mp(b2,c2)));
  }
  sort(all(v3));
  ll ans = 0;
  rep(i,0,v3.sz){
    ll a3 = v3[i].fi;
    ll b3 = v3[i].se.fi;
    ll c3 = v3[i].se.se;
    if(check(b3,c3)==0){
      ans += a3;
      union_(b3,c3);
    }
  }
  cout << ans <<endl;
  return 0;
}

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

int main(){
  int mod;
  cin>>mod;
  
  int val=7%mod;
  
  for(int i=1;i<=1e7;i++){
    if(val==0){
      cout<<i<<endl;
      exit(0);
    }
    val=(val*10+7)%mod;
  }
  
  cout<<"-1"<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int fx4[] = {1 , -1 , 0 , 0};
int fy4[] = {0 , 0 , 1 , -1};
int Kfx[]= {-2,-2,2,2,1,1,-1,-1}; ///knight move x - exis
int Kfy[]= {1,-1,1,-1,2,-2,2,-2}; ///knight move y- exis
int fx8[]= {1,1,1,0,0,-1,-1,-1};
int fy8[]= {0,1,-1,1,-1,0,1,-1};
#define ll long long int
#define pii pair<int,int>
#define llu unsigned long long
#define inf 1<<28
#define gama 0.57721566490
#define PI              acos(-1.0)
#define INF             0x7fffffff
#define MOD             1000000007
#define EPS             1e-7
#define all(r)(r).begin(),(r).end()
/*
bool status[mx];
void sieve(){
   long long int  i,j;
    for(i=2;i<=mx;i++)
    {
        status[i]=0;
    }
    for( i=2;i<=sqrt(mx);i++){
        if(status[i]==0)
        {
            for(j=i*i;j<=mx;j+=i){
                status[j]=1;
            }
        }
    }
}*/
ll BM( ll a , ll b , ll m )
{
    if ( b == 0 ) return 1 ;
    ll x = BM(a,b/2,m);
    x = (( x % m) * (x % m))%m;

    if( b % 2 ) x = (( x % m) * (a %m)) % m ;
    return x ;
}
#define dd double
#define sc scanf
#define pr printf
#define VI vector<int>
#define VS vector<string>
#define VC vector<char>
#define VLL vector<long long int>
#define FILE freopen("input.txt","rt",stdin); freopen("output.txt","w",stdout);
#define p_b push_back
#define mem(x,y) memset(x,y,sizeof(x))
#define F(i,a,b) for(i=a;i<=b;i++)
#define sc1(a) scanf("%d",&a)
#define scL1(a) scanf("%lld",&a)
#define scL2(a,b) scanf("%lld%lld",&a,&b)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define fori(N)          for(int i = 0; i<(N); i++)
#define forj(N)         for(int j = 0; j<(N); j++)
#define fork(N)         for(int k = 0; k<(N); k++)
#define forl(N)         for(int l = 0; l<(N); l++)
#define ford(N)         for(int d = 0; d<(N); d++)
#define fori1(N)          for(int i = 1; i<=(N); i++)
#define forj1(N)         for(int j = 1; j<=(N); j++)
#define fork1(N)         for(int k = 1; k<=(N); k++)
#define ford1(N)         for(int d = 1; d<=(N); d++)
#define sqr(x)           (x)*(x)
#define TEST int test,te=0;cin>>test;
#define segment_tree int l=(n*2),r=(n*2)+1,mid=(l+r)/2
#define Mx 100005
#define mx 10005

int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);///Beware of use it, if u use it dont use scanf or printf
    int n;
    cin>>n;
    string a;
    cin>>a;
    int f=0;
    if(n%2==1){
    	f=1;
	}
	int j=n/2;
	for(int i=0;i<n/2;i++){
		if(a[i]!=a[j])f=1;
		j++;
	}
	if(f==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> cards(N);
    for (int i = 0; i < N; i++){
        cin >> cards.at(i);
    }
    sort(cards.begin(), cards.end(), greater<int>());

    int aliceScore = 0;
    int bobScore = 0;
    for (int i = 0; i < N; i++){
        if (i % 2 == 0){
            aliceScore += cards.at(i);
        } else {
            bobScore += cards.at(i);
        }
    }
    cout << aliceScore - bobScore << endl;

}

Measured memory_bytes: 256
## ABC 083
## B - Some Sums
n,a,b = (int(_) for _ in input().split())

ans = 0
for i in range(1,n+1):
    nl = list(str(i))
    s = 0
    for j in nl:
        s += int(j)
    if(a <= s <= b):
        ans += i
    
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc =  new Scanner(System.in);
		int number = sc.nextInt();
		int[] values = new int[number];
		int[] costs = new int[number];
		int sum = 0;
		
		for(int i=0;i<number;i++)
			values[i] = sc.nextInt();
		for(int i=0;i<number;i++) {
			costs[i] = sc.nextInt();
			if(values[i]-costs[i]>0)
				sum += values[i]-costs[i];
		}
		sc.close();
		System.out.println(sum);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 int main(){
     int N;cin>>N;
     string s,t;cin>>s>>t;
     string ans;
     for(int i=0;i<N;i++){
         ans+=s[i];
         ans+=t[i];
     }
     cout<<ans<<endl;
    }
        






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int k;
    cin >> k;
    if (7 % k == 0)
    {
        cout << 1 << endl;
        return 0;
    }

    vector<bool> used(k, false);
    int ans = 2;
    int cur = 7 % k;
    used[cur] = true;

    while (true)
    {
        cur = (cur * 10 + 7) % k;
        if (used[cur])
        {
            cout << -1 << endl;
            return 0;
        }
        used[cur] = true;
        if (cur == 0)
        {
            break;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3728