akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
//#define int long long
const int inf = 2e9, mxp = 10, maxn = (1 << 18);


struct el
{
    int c, w;
    el(int _c = 0, int _w = 0) : c(_c), w(_w) {}
};
bool operator < (el a, el b)
{
    return a.w < b.w;
}
vector<el> els[(1 << mxp) + 10];
vector<int> pr[maxn];
int c[maxn], w[maxn], n;
void DPFS(int v, int d)
{
    //for(el e : els[v / 2]) t.pb(e);
    //cout << v << '\n';
    if(v > n) return;
    vector<el> t = els[v / 2];
    vector<el> t2;
    for(el e : els[v / 2]) t2.eb(e.c + c[v - 1], e.w + w[v - 1]);

    merge(all(t), all(t2), back_inserter(els[v]));
    //cout << v << '\n';
    //for(el e : els[v]) cout << e.w << ' ' << e.c << '\n';
    //cout << '\n';
    pr[v].resize(els[v].size(), 0);
    //cout << "DONE " << v << '\n';
    pr[v][0] = els[v][0].c;
    for(int i = 1; i < els[v].size(); i++) pr[v][i] =  max(pr[v][i - 1], els[v][i].c);

    if(d < mxp - 1)
    {
        DPFS(2 * v, d + 1);
        DPFS(2 * v + 1, d + 1);
    }

}
void solve(int ci)
{
    cin >> n;
    f(n) cin >> c[i] >> w[i];
    els[0].eb(0, 0);
    DPFS(1, 0);
    //cout << "DONE";
    int d[n + 1];
    d[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        d[i] = d[i - 1];
        if(1 << (d[i] + 1) <= i) d[i]++;
    }
    ic(q)
    fk(q)
    {
        ic(v)
        ic(l)
        int ans = 0;
        if(d[v] < mxp)
        {
            for(el e : els[v]) if(e.w <= l) ans = max(ans, e.c);
            cout << ans << '\n';
            continue;
        }
        vector<el> cp;
        for(; d[v] >= mxp; v = v / 2) cp.eb(c[v - 1], w[v - 1]);
        vector<el> cls;
        int cn = cp.size();
        f(1 << cn)
        {
            int cc = 0, cw = 0;
            fj(cn)
            {
                if((i >> j) & 1) cc += cp[j].c, cw += cp[j].w;
            }
            cls.eb(cc, cw);
        }
        sort(all(cls));
        int lp = els[v].size() - 1;
        f(cls.size())
        {
            while(lp - 1 >= 0 && els[v][lp].w + cls[i].w > l) lp--;
            if(els[v][lp].w + cls[i].w <= l) ans = max(ans, pr[v][lp] + cls[i].c);
        }
        cout << ans << '\n';
    }
}

signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 21192
// 2011/07/27 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string r, a;
		cin >> r >> a;
		if(r=="0"&&a=="0")	// ツ閉カツ篠堋療ア
			break;

		int hit = 0;
		int blw = 0;
		for(int i=0; i<4; i++)
			for(int j=0; j<4; j++)
				if(r[i]==a[j])
					if(i==j)
						hit++;
					else
						blw++;

		cout << hit << ' ' << blw << endl;
	}

	return 0;
}

Measured memory_bytes: 916
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(void)
{
	int  H , A;
	cin >> H  >> A;
	for(int i=1;i<=A;i++)
	{
		int a;
		cin >>a;
		H-=a;
	}
	if(H<=0) cout << "Yes";
	else cout << "No";

	return 0;
}


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

void solve() {
  int n;
  cin >> n;
  vector<int> v(n+1);
  rep(i,n+1) cin >> v[i];
  vector<int> u(n);
  rep(i,n) cin >> u[i];
  long ans = 0;
  rep(i,n) {
    if (v[i] >= u[i]) ans += u[i];
    else {
      ans += v[i];
      u[i] -= v[i];
      if (v[i+1] >= u[i]) {
        ans += u[i];
        v[i+1] -= u[i];
      } else {
        ans += v[i+1];
        v[i+1] = 0;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <cstring>
#include <fstream>

using namespace std;
using ll = long long;

int h[100005];
int dp[100005]; // dp[i] = cheapest cost to get to i

int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> h[i];
	memset(dp, 0x3f, sizeof dp);
	dp[1] = 0;
	for(int i = 2; i <= n; i++)
	{
		if(i - 1 >= 1)
			dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i]);
		if(i - 2 >= 1)
			dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i]);
	}
	cout << dp[n] << endl;
	return 0;
}



Measured memory_bytes: 4332
#include <stdio.h>

int main(void)
{
    int A=0 ,B=0;

    scanf("%d",&A);
    scanf("%d",&B);

    if(A >= 10 || B >= 10){
        printf("-1\n");
    }
    else{
        printf("%d\n",A*B)  ;
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
signed main() {
	int N;
	cin >> N;
	
	vector<int> A(N);
	vector<int> B(100005 , 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[A[i]]++;
		B[A[i] + 1]++;
		B[A[i] + 2]++;
	}
	cout <<*max_element(B.begin(), B.end()) << endl;
	return 0;
	
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

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

vector<int> e(300010), w(300010);

int main() {
	int n;
	string s;
	cin >> n >> s;
	int east = 0, west = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'W') e[i + 1] = e[i] + 1;
		else e[i + 1] = e[i];
		if (s[n - 1 - i] == 'E') w[i + 1] = w[i] + 1;
		else w[i + 1] = w[i];
	}
	int ans = INF;
	for (int i = 1; i <= n; i++) {
		ans = min(ans, e[i - 1] + w[n - i]);
	}
	cout << ans << endl;
}

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

template<typename T> T prime_fact(T x, vector<
T> &factor) { // 素因数分解（返り値はxの正の約数の個数）
    T r = 1;
    for (T i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            T cnt = 1;
            while (x % i == 0) {
                factor.push_back(i);
                x /= i;
                cnt++;
            }
            r *= cnt;
        }
    }
    if (x != 1) {
        factor.push_back(x);
        r *= 2;
    }
    return r;
}

int main() {
	int n;
    cin >> n;
    vector<int> a(n);
    map<int, bool> m;
    set<int> s;
    rep(i, n) {
        cin >> a[i];
        if (s.count(a[i])) {
            m[a[i]] = true;
        } else {
            s.insert(a[i]);
        }
    }
    const int _n = 1e6;
    vector<bool> b(_n+1, true);
    for (int x : s) {
        for (int i = x + x; i <= _n; i += x) {
            b[i] = false;
        }
    }
    int cnt = 0;
    rep(i, n) {
        if (m[a[i]]) {
            continue;
        }
        if (b[a[i]]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 23040
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n;
  cin >> n;
  
  for (int i = 0; i < 100; i++) {
    int cnt = 7*i;
    if (cnt > n) break;
    for (int j = 0; j < 100; j++) {
      int cnt = 7*i + 4*j;
      if (cnt > n) break;
      if (cnt == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  return 0;
}




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

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
bool rh(char c){
	switch (c)
	{
	case 'a':
	case 'b':
	case 'c':
	case 'd':
	case 'e':
	case 'f':
	case 'g':
	case 'q':
	case 'r':
	case 's':
	case 't':
	case 'v':
	case 'w':
	case 'x':
	case 'z':
		return true;
	default:
		return false;
	}
}

int main() {
	string s;
	while (cin>>s,s!="#"){
		bool hand;//false true
		hand = rh(s[0]);
		int count = 0;
		for (int i = 1; i < s.length(); i++){
			if (hand != rh(s[i])){
				hand = rh(s[i]);
				count++;
			}
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 3172
N=int(input())
ans=0
c=[[0 for _ in range(10)] for _ in range(10)]

for n in range(1,N+1):
    i=n%10
    j=n
    while 10<=j:
        j=j//10
    c[i][j]=c[i][j]+1

for i in range(10):
    for j in range(10):
        ans=ans+c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	char s[19];
	int len,i;
	gets(s);
	len=strlen(s);
	for(i=0; i<len; i++)
	{
		if(s[i]!=',')
			printf("%c",s[i]);
		else
			printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1532
#include <stdio.h>
int main()
{
	int N,b,c;
    scanf("%d",&N);
    b=N%10;
    c=N/10;
    if(b==9||c==9){
    	printf("Yes");
    	
	}else{
		printf("No");
	}
	return 0;
 } 

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int main(){
  int n;cin>>n;
  int s[101];
  rep(i,n) cin>>s[i];
  int sum=0;
  rep(i,n) sum+=s[i];
  sort(s,s+n);
  int j=0;
  while(sum%10==0){
    if(j==n){
      sum=0;
      break;
    }
    if(s[j]%10==0){
      j++;
      continue;
    }
    sum-=s[j];
    j++;
  }
  prin(sum);

  
  

  

  return 0;
}


Measured memory_bytes: 256
const int isDebugMode = 1;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b , a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

ll MAX_I = 1001001;

int main(){
    ll K; cin >> K;
    ll num = 7 % K;
    for(ll cnt = 1; cnt < MAX_I; cnt++){
        if(num == 0){
            pt(cnt);
            return 0;
        }
        num *= 10;
        num += 7;
        num %= K;
    }
    pt(-1);
}

Measured memory_bytes: 3652
import java.util.Scanner

object Main {
    def main(args: Array[String]): Unit = {
        val scanner = new Scanner(System.in)
        val n: Int = scanner.nextInt
        val k: Int = scanner.nextInt
        val hates: List[Int] = List.fill(k)(scanner.nextInt)

        println(calc(n, hates))
    }

    def calc( n: Int, hates: List[Int]): Int ={
      (n to (10*n)).find(p => p >= n && !isIncludingHateNum(p, hates)).get
    }

    def isIncludingHateNum(payment: Int, hates: List[Int]): Boolean ={
      val pays:List[Int] = (payment.toString.grouped(1)).toList.map(_.toInt)
      pays.exists(hates.contains(_))
    }
}


Measured memory_bytes: 105520
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
#define ld long double

int main(void)
{
    ll n, x, t;
    cin >> n >> x >> t;

    if(n%x)
        cout << ((n / x) + 1) * t;
    else
        cout << (n / x) * t;
}

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

int main()
{
  string s;
  cin>>s;
  if(s.at(0) == 'S')
    cout<<"Cloudy"<<endl;
  else if(s.at(0) == 'C')
    cout<<"Rainy"<<endl;
  else
    cout<<"Sunny"<<endl;
    
  return 0;
}

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	// your code goes here
	string s1,s2;
	cin >> s1 >> s2;
	if(s1.length() > s2.length()){
		cout << "GREATER";
		return 0;
	}
	else if(s1.length() < s2.length()){
		cout << "LESS";
		return 0;
	}
	else if(s1.length() == s2.length()){
		REP(i,s1.length()){
			if(s1[i] > s2[i]){
				cout << "GREATER";
				return 0;
			}
			else if(s1[i] < s2[i]){
				cout << "LESS";
				return 0;
			}
		}
	}
	cout << "EQUAL";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

const int base = (1<<20);
int tree[2*base+1];
void add(int l, int r) {
	l += base;
	r += base;
	tree[l]++;
	if(l != r) tree[r]++;
	while(l/2 != r/2) {
		if(l%2==0) tree[l+1]++;
		if(r%2==1) tree[r-1]++;
		l/=2;
		r/=2;
	}
}
int query(int x) {
	int res = 0;
	x += base;
	while(x) {
		res += tree[x];
		x/=2;
	}
	return res;
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, q;
	cin>>n>>q;
	vector<int> c(n);
	vector<vector<pii>> queries(n+1);
	for(int i=0; i<n; ++i) {
		cin>>c[i];
	}
	for(int i=0; i<q; ++i) {
		int l, r;
		cin>>l>>r;
		queries[r-1].push_back({l-1, i});
	}
	vector<int> res(q);
	vector<int> last(n+1, -1);
	for(int i=0; i<n; ++i) {
		add(last[c[i]]+1, i);
		for(auto j: queries[i]) {
			res[j.nd] = query(j.st);
		}
		last[c[i]]=i;
	}
	for(int i=0; i<q; ++i) {
		cout<<res[i]<<'\n';
	}
}


Measured memory_bytes: 35188
#include <stdio.h>
int main(void){
    int a[10000] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf("%d",&k);
    printf("%d",a[k-1]);
    return 0;
}

Measured memory_bytes: 256
import sys
N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
mod = 10**9 + 7

cnt_one = [0] * 60
cnt_zero = [0] * 60

def count_bin(a):
    base = 1
    for i in range(60):
        if a % (base * 2) > 0:
            cnt_one[i] += 1
            a -= base
        else:
            cnt_zero[i] += 1
        base *= 2

for a in A:
    count_bin(a)

base = 1
ans = 0
for one, zero in zip(cnt_one, cnt_zero):
    ans += one * zero * base
    ans %= mod
    base *= 2
    base %= mod
print(ans)

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

void Main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  int cnt = 0;
  int t[n];
  t[0] = cnt;
  memset(t, 0, sizeof(t));
  for (int i = 1; i < n; i++) {
    if (s[i] == 'C' && s[i - 1] == 'A') t[i] = ++cnt;
    else t[i] = cnt;
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << t[r - 1] - t[l - 1] << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int main(){
    int n,i,s,v,j,c[101];
    cin >> n;
    
    for(i=0; i<n; i++)cin >> c[i];
    for(s=0; s<n-1; s++)cout << c[s] << " ";
    cout << c[n-1] << endl;

    for(i=1; i<n; i++){
        v=c[i];
        j=i-1;
    while(j>=0&&c[j]>v){
        c[j+1]=c[j];
        j--;
    }
    c[j+1]=v;
    for(s=0;s<n-1;s++) cout << c[s] << " ";
    cout << c[n-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 


int main()
{	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
		
	
	ll n;
	cin>>n;
	
	ll ans = 0;
	
	for(ll i=1;i<=n;i++)
	{
		if((i%3 == 0) || (i%5 == 0))
		{
			
		}
		else{
			ans += i;
		}
	}
	
	cout<<ans<<endl;
	
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define sc scanf
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
template <typename it>int o(it a){cout<<a<<endl;return 0;}
int n,l;
int pie[N]={0};
int sum=0;
int main(){
    cin>>n>>l;
    for(int i=1;i<=n;i++)sum+=pie[i]=l+i-1;
    int res=1e9;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(res>abs(pie[i])){
            res=abs(pie[i]);ans=i;
        }
    }
    o(sum-pie[ans]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll sum = accumulate(v.begin(), v.end(), 0LL);
    ll snuke = 0;
    ll ans = INF;
    for (int i = 0; i < n - 1; i++) {
        snuke += v[i];
        ans = min(ans, abs(snuke * 2 - sum));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdbool.h>

int main(void){
   int N;
   scanf("%d",&N);
   int n[N];
   bool judge=true;
   for(int i=0;i<N;i++){
      scanf("%d",&n[i]);
   }
   for(int i=0;i<N;i++){
      if(n[i]%2==0){
         if(n[i]%3==0||n[i]%5==0){
      }else{
         judge=false;
         break;
      }
      }
   }
   if(judge){
      printf("APPROVED");
   }else{
      printf("DENIED");
   }
   return 0;
}


Measured memory_bytes: 1736
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
mean_temp = [t-i*0.006  for i in h]
abs_temp = [abs(a-i) for i in mean_temp]
min_index = abs_temp.index(min(abs_temp))
print(min_index+1)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

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

    // 切り替わった回数が答えになる
    int ans = 0;
    for(int i=0; i<s.length()-1; ++i){
        if(s[i] != s[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import queue
H,W=map(int, input().split())
inmap = [input() for _ in range(H)]

q = queue.Queue(2500)
q.put((0,0,1))
cood = [(1,0),(-1,0),(0,1),(0,-1)]
res = 0

visited = set((0,0))

while not q.empty():
    x,y,cnt=q.get(False)
    if x+1 == W and y+1 == H:
        res = cnt
        break
    for dx, dy in cood:
        if x+dx >= 0 and x+dx < W and y+dy >= 0 and y+dy < H:
            if inmap[y+dy][x+dx] != '#' and not (x+dx, y+dy) in visited:
                q.put((x+dx, y+dy, cnt+1))
                visited.add((x+dx, y+dy))

black = 0
for i in range(H):
    for j in range(W):
        if inmap[i][j] == '#':
            black += 1

# print((W-1, H-1) in visited)
if res == 0:
    print(-1)
else:
    print(H*W - black - res)


Measured memory_bytes: 45288
#include<bits/stdc++.h> 
using namespace std; 
// Binary indexed tree supporting binary search.
 
 
#define x first
#define y second
#define forn(i, n) for(int i = 0; i < int(n); ++i)
typedef pair<int, int> pii;

int H,W,A,B;
void solve(){
	cin>>H>>W>>A>>B;
	forn(i,B){
		forn(j,A){
			cout<<0;
		}
		forn(j,W-A){
			cout<<1;
		}
		cout<<'\n';
	}
	forn(i,H-B){
		forn(j,A){
			cout<<1;
		}
		forn(j,W-A){
			cout<<0;
		}
		cout<<'\n';
	}
}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	solve();
	
	return 0;	
}

Measured memory_bytes: 1280
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<ll,ll> PII;
typedef vector<ll> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+5;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll n;
void solve(){
	//cin>>n; 
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout<<"Yes";
	} else{
		cout<<"No";
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {
	int n; cin >> n;
	int c[20], v[20];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] > c[i]) {
			ans += v[i] - c[i];
		}
	}

	cout << ans << endl;







}

Measured memory_bytes: 256
//10.0.3.47 perfec
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
#define ULL unsigned long long
using namespace std;
int read(){
	int f=0,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
char S[MAXN+5];
int s1[MAXN+5],s2[MAXN+5],s[MAXN+5];
int main(){
	scanf("%s",S+1);
	int n=strlen(S+1);
	for(int i=1;i<=n;i++){
		if(S[i]=='R')
			s1[i]=s1[i-1]+1;
		else s1[i]=0;
		//printf("%d ",s1[i]);
	}
	//puts("");
	for(int i=n;i>=1;i--){
		if(S[i]=='L')
			s2[i]=s2[i+1]+1;
		else s2[i]=0;
		
	}
//	for(int i=1;i<=n;i++)
	//printf("%d ",s2[i]);
	//puts("");
	for(int i=1;i<n;i++)
		if(s1[i]&&!s1[i+1]){
			int R=s1[i],L=s2[i+1];
			s[i]=(R+1)/2+L/2;
			s[i+1]=R/2+(L+1)/2;
			i++;
		}
	for(int i=1;i<=n;i++)
		printf("%d",s[i]),putchar(i==n?'\n':' ');
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
char modmodmod(char ch) {
	if(ch=='b')return 'd';
	if(ch=='d')return 'b';
	if(ch=='p')return 'q';
	if(ch=='q')return 'p';
}
int main() {
	string str,tmp;
	cin>>str;
	tmp=str;
	reverse(str.begin(),str.end());
	for(int i=0; i<str.size(); i++)
		str[i]=modmodmod(str[i]);
	puts(tmp==str?"Yes":"No");
	return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	if(n == 7 || n == 5 || n == 3) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}


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

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;
const int MAX_N = 1e5+100;
LL a[MAX_N];

int main(){
    //freopen("in.txt", "r", stdin); 
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	int cnt = 0;
	LL ans = 0;
	LL mn = 1LL << 60;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		LL x = ((a[i] < 0) ? -a[i] : a[i]);
		ans += x;
		mn = min(x, mn);
		if(a[i] < 0) ++cnt;
	}
	if(cnt&1) {
		ans -= 2LL*mn;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

static const int64_t MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int64_t> AS(N);
  for (int i = 0; i < N; i++) cin >> AS[i];

  int64_t sum = 0;
  for (int i = 0; i < 64; i++) {
    int count_zeros = 0;
    int count_ones = 0;
    for (int64_t A : AS) {
      if (A & (1LL << i)) {
        count_ones++;
      } else {
        count_zeros++;
      }
    }
    int64_t K = (1LL << i) % MOD;
    K = K * count_zeros % MOD;
    K = K * count_ones % MOD;
    sum = (sum + K) % MOD;
  }
  cout << sum << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
#define endl "\n";
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define POSITIVE_INFINITY 9223372036854775807
#define NEGATIVE_INFINITY -9223372036854775807
const ll MOD = 1000000007;

int main()
{
  FASTER;
  int n;
  cin >> n;
  vector<int>v(n);
  for (int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int lg = v[n - 1];
  int sum = 0;
  for (int i = 0; i < n - 1; i++){
    sum += v[i];
  }
  if (lg < sum){
    cout << "Yes\n";
  }
  else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
if n == 1:
    print(0)
    exit()

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d
 
fac = factorize(n)
ans = 0
for v in fac.values():
    n = 1
    while v >= n:
        v -= n
        ans += 1
        n += 1
print(ans)


Measured memory_bytes: 9436
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func sum(n []int) int {
	a := 0
	for _, v := range n {
		a += v
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	n := getInt()

	l := make([]int, n)
	for i := range l {
		l[i] = getInt()
	}
	a := sum(l)
	sort.Ints(l)

	if l[n-1] < (a - l[n-1]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	string S;
	cin >> S;
	string M = "keyence", A, B;
	for(int i = 0; i < 7; i ++){
		if(S[i] == M[i])A.pb(S[i]);
		else break;
	}
	for(int i = 1; i <= 7; i ++){
		if(S[S.size() - i] == M[M.size() - i])B.pb(S[S.size() - i]);
		else break;
	}
	if(A.size() + B.size() >= 7)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void){
    int a,b,h,m;
    double h_num, m_num, arg, rad, ans;
    scanf("%d %d %d %d", &a, &b, &h, &m);
    h_num = h/12.0 * 360;
    m_num = m/60.0 * 360;
    h_num += m/60.0 * 30;
    // printf("h : %f\n m : %f\n", h_num, m_num);
    arg = fabs(h_num - m_num);
    if(arg >= 180) arg -= 360.0;
    // printf("arg : %f\n", arg);
    rad = arg/180.0 * 3.14159265358979323846264338325028841971;
    // printf("rad = %f\n", sin(rad));
    ans = sqrt((a*sin(rad))*(a*sin(rad)) + (b - a*cos(rad))*(b - a*cos(rad)));
    printf("%.20f", ans);
}


Measured memory_bytes: 2536
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
if sum(a)==0:
  print('Yes')
else:
  if n%3!=0:
    print('No')
  else:
    s = len(set(a))
    if s>3:
      print('No')
    else:
      l = Counter(a)
      tf = 1
      if s==3:
        for v in l.values():
          if v!=n//3:
            tf = 0
        li = list(set(a))
        if li[0]^li[1]^li[2]!=0:
          tf = 0
      elif s==2:
        if 0 not in l.keys():
          tf = 0
        else:
          for k in l.keys():
            if k==0 and l[k]!=n//3:
              tf = 0
      else:
        tf = 0
      print('Yes' if tf else 'No')

Measured memory_bytes: 20888
k = int(input())

found = False
l = set()

n = 7
i = 0
while True:
    i += 1
    n %= k
    if n == 0:
        found = True
        break
    if n in l:
        break

    l.add(n)
    n = n * 10 + 7

if found:
    print(i)
else:
    print(-1)
    

Measured memory_bytes: 77892
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>

typedef long long ll;

using namespace std;

int main() {
	int a, flg = 0, ans = 0;

	cin >> a;

	for (int i = 1; i <= 9; i++) {
		ans = a / i;
		if (a == ( ans * i ) && ans > 0 && ans < 10  ) {
			cout << "Yes" << endl;
			break;
		}

		if (i == 9) {
			flg = 1; 
		}
	}

	if (flg == 1) {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        String[] inputList = input.split(" ");

        Integer[] Agrp = {1, 3, 5, 7, 8, 10, 12};
        Integer[] Bgrp = {4, 6, 9, 11};
        Integer[] Cgrp = {2};

        if(Arrays.asList(Agrp).contains(Integer.parseInt(inputList[0]))){
            if(Arrays.asList(Agrp).contains(Integer.parseInt(inputList[1]))){
                System.out.println("Yes");
            }else{
            	System.out.println("No");
            }
        }else if(Arrays.asList(Bgrp).contains(Integer.parseInt(inputList[0]))){
        	if(Arrays.asList(Bgrp).contains(Integer.parseInt(inputList[1]))){
                System.out.println("Yes");
            }else{
            	System.out.println("No");
            }
        }else if(Arrays.asList(Cgrp).contains(Integer.parseInt(inputList[0]))){
        	if(Arrays.asList(Cgrp).contains(Integer.parseInt(inputList[1]))){
                System.out.println("Yes");
            }else{
            	System.out.println("No");
            }
        }
        else{
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
int x, y, z;
int main(){
    cin >>x >> y >>z;
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    if(x > y)   swap(x, y);
    if(y > z)   swap(y, z);
    cout << y - x + z - y << endl;
    return 0;
}


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

#define ARRAY_LENGTH (100010)

// Infinity value
const long long INF = 1LL << 60;

template<class T>
inline bool chmin(T& a, T b){
  if(a > b){
    a = b;
    return true;
  }else{
    return false;
  }
}

int main(void)
{
  int N;
  long long H[ARRAY_LENGTH];
  long long dp[ARRAY_LENGTH];

  std::cin >> N;

  // Input costs
  for(int i = 0;i < N;i++){
    std::cin >> H[i];
  }

  // Initialize DP
  for(int i = 0;i < ARRAY_LENGTH;i++){
    dp[i] = INF;
  }

  // Initial condition
  dp[0] = 0;

  // Loop
  for(int i = 1;i < N;i++){
    chmin(dp[i], dp[i-1] + abs(H[i] - H[i-1]));
    if(i > 1){
      chmin(dp[i], dp[i-2] + abs(H[i] - H[i-2]));
    }
  }

  std::cout << dp[N-1] << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
 
 typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define ll          long long
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
 
const int hell=1000000007;

int a[1000010]={0};

int power(int a,int b)
{
  if(b==0)return 1;
   int t=power(a,b/2);
   t*=t;
   t%=hell;
   if(b&1)t*=a;
   t%=hell;
   return t;
}

int inverse(int a)
{
  return power(a,hell-2);
}




int solve()
{
  
  string a,b;
  cin>>a>>b;
  int ans=0;
  rep(i,0,3)if(a[i]==b[i])ans++;
  cout<<ans;
 return 0;

}
 

signed main()
{  int t=1;

//pri();
  
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    
 
 

  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
// cin>>t;
 
    int k=1;
     
   while(t--)
     {
      // cout<<"Case #"<<k<<":"<<endl;k++;
     // cout<<endl;
      solve();
     }
        exit(0);
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, M;

ll fact[100001];

int main(){
  cin >> N >> M;
  fact[0] = 1;
  REP(i, 100000) {
    fact[i + 1] = fact[i] * (i + 1) % MOD; 
  }
  if(abs(N - M) >= 2) {
    cout << 0 << endl;
  } else if(abs(N - M) == 1) {
    cout << fact[N] * fact[M] % MOD << endl;
  } else {
    cout << fact[N] * fact[M] % MOD * 2 % MOD << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
A=input()
S=[]
S.append(A[0])
S.append(A[1])
S.append(A[2])
S.append(A[3])
  
S.sort()
if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve():
  n,m =(int(i) for i in input().split())
  uf = UnionFind(n)
  for i in range(m):
    x,y,z = (int(i) for i in input().split())
    uf.union(x-1,y-1)

  print(len(uf.roots()))
solve()

Measured memory_bytes: 7896
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

# if not 1 in a:
#     print(-1)

# hst = []
btn = 0
cnt = 0

while cnt <= 10**7:
    # hst.append(btn)
    btn = a[btn]
    cnt += 1
    if btn == 1:
        print(cnt)
        exit()

print(-1)

Measured memory_bytes: 49240
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int n;
  cin >> n;
  int v[9] = {111, 222, 333, 444, 555, 666, 777, 888, 999};
  for (int i = 0; i < 9; i++) {
    if (n <= v[i]) {
      cout << v[i] << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint d(n);
    rep(i,n) cin >> d[i];
    sort(all(d));
    d.erase(unique(all(d)),d.end());
    cout << d.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll k;
    cin >> k;
    ll c[8];
    memset(c, -1, sizeof(c));
    rep(i, k) {
        ll x, y;
        cin >> x >> y;
        c[x] = y;
    }
    ll v[8];
    rep(i, 8) v[i] = i;

    vector<string> ans(8, "........");

    do {
        bool ok = true;
        rep(i, 8) {
            if (c[i] != -1 && v[i] != c[i]) ok = false;
            rep(j, 8) {
                if (i >= j) continue;
                if (c[j] != -1 && v[j] != c[j]) ok = false;
                if (abs(i - j) == abs(v[i] - v[j])) ok = false;
            }
        }
        if(ok) rep(i, 8) ans[i][v[i]] = 'Q';
    } while(next_permutation(v, v+8));

    rep(i, 8) cout << ans[i] << endl;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
    {
        cout<<"bust";
    }
    else
    {
        cout<<"win";
    }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
c=0
for _ in range(2**n):
  s=str(bin(_))[2:].zfill(n)
  f=1
  for i in range(m):
    a=0
    for j in range(1,k[i][0]+1):
      a+=int(s[k[i][j]-1])
    if a%2!=p[i]:
      f=0
      break
  if f:
    c+=1
print(c)


Measured memory_bytes: 41580
#!/usr/bin/env python3
import sys
from collections import defaultdict

rl = sys.stdin.buffer.readline
INF = sys.maxsize

V, E = map(int, rl().split())
ES = [tuple(map(int, rl().split())) for i in range(E)]



# グラフを初期化する
G = defaultdict(lambda: defaultdict(lambda: INF))
for e in ES:
  G[e[0]][e[1]] = e[2]


dp = defaultdict(lambda: defaultdict(lambda: INF))
dp[0][0] = 0

for s in range(1 << V):
  for v in range(V):
    if s & (1 << v) == 0: # s に頂点v が含まれていないときを考える
      for u in range(V):
        dp[s | (1 << v)][v] = min(dp[s | (1 << v)][v], dp[s][u] + G[u][v])


print(dp[(1 << V) - 1][0] if dp[(1 << V) - 1][0] < INF else -1)


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

int main() {
    ll D, N;
    cin >> D >> N;
    ll ans;
    if(N != 100){
        ans = pow(100,D) * N;
    }
    else{
        ans = pow(100,D) * 101;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<string> s(n,"");
	map<char,int> cnt;
	for (char c = 'a'; c <= 'z'; c++) {
		cnt[c]=1000;
	}
	for(int i = 0; i < n;i++){
		map<char,int> cnt2;
		for (char c = 'a'; c <= 'z'; c++) {
			cnt2[c]=0;
		}
		cin >> s[i];
		for (auto x : s[i]){
			cnt2[x]++;
		}
		for (auto p : cnt2) {
			cnt[p.F] = min(cnt[p.F],p.S);
		}
	}
	for (auto p : cnt) {
		while (p.S--) {
			cout << p.F; 
		}
	}
	cout << "\n";
	

}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int N, K;
	cin >> N >> K;
	vector<Int> a(N + 1, 0);
	vector<Int> S(N + 1, 0);
	for (int i = 1; i <= N; ++i) {
		cin >> a[i];
		S[i] = S[i - 1] + a[i];
	}

	map<Int, Int> mp;
	Int ans = 0;
	for (int i = 0; i <= N; ++i) {
		if (i - K >= 0) { mp[ (S[i - K] - i + K) % K ] -= 1; }
		
		Int idx = (S[i] - i + K) % K;
		ans += mp[idx];
		mp[idx] += 1;
	}
	cout << ans << endl;

	return 0;
}


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



// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(100005);


//nPk
 mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n,k);
    res *= comb.fact[k];
    return res;
}




//組み合わせの数nCrを計算
   int calcNumOfCombination(int n, int r){
       int num = 1;
       for(int i = 1; i <= r; i++){
           num = num * (n - i + 1) / i;
       }
       return num;
   }



int main() {
  ll n;
  cin>>n;
  vector<ll>a(n+1);
  map<ll,ll>mp;
  ll id1; ll id2;
  rep(i,n+1){
    cin>>a[i];
    if(mp[a[i]]!=0){
      id2=i+1;
      id1=mp[a[i]];
    }
    mp[a[i]]=i+1;
  //  cout<<mp[a[i]]<<endl;
  }
//cout<<id1<<' '<<id2<<endl;
  ll x=n-id2+id1;
  rep(i,n+1){
    mint all=comb(n+1,i+1);
    mint mn=comb(x,i);
   // cout<<x<<' '<<i<<' '<<all<<endl;
    mint ans=all-mn;
    cout<<ans<<endl;
  }


}


Measured memory_bytes: 11392
function Main(arg) {
 
    var N = arg.split("\n")[0];

    if (N === "Sunny") {
       console.log("Cloudy");
    }
    else if (N === "Cloudy") {
        console.log("Rainy");
    }
    else if (N === "Rainy") {
        console.log("Sunny");
    }
}

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


Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int a, b, c, d;cin>>a>>b>>c>>d;
  if(a+b==c+d)cout<<"Balanced"<<endl;
  else if(a+b>c+d)cout<<"Left"<<endl;
  else cout<<"Right"<<endl;
}

Measured memory_bytes: 256