akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define M 1046527

char H[M][14];

int getChar(char ch)
{
    if ( ch == 'A')
        return 1;
    if( ch == 'C')
        return 2;
    if ( ch == 'G')
        return 3;
    if( ch == 'T')
        return 4;
}

long long getKey(char str[])
{
    long long temp = 0;;
    int  p =1;
    for ( int i = 0 ; i < strlen(str); i++ )
    {
        temp += p * getChar(str[i]);
        p *= 5;
    }
    return temp;
}

int h1( long long key)
{
    return key % M;
}

int h2( long long key)
{
    return 1+ key%(M-1);
}

void insert( char str[])
{
    long long key = getKey(str);
    int temp;
    for(int i =0;;i++)
    {
        temp = (h1(key) + i*h2(key))%M;
        if(strcmp(str,H[temp]) == 0)
            return;
        else if(strlen(H[temp]) == 0)
        {
            strcpy(H[temp], str);
            return ;
        }
    }

    return;
}

int find(char str[])
{
    int h;
    long long key;
    key = getKey(str);
    for (int i =0;;i++)
    {
        h = (h1(key) + i*h2(key))%M;
        if(strcmp(str,H[h]) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
}

int main()
{
    char a[14];
    int n;
    int judge;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",a);
        if ( a[0] == 'i')
        {
            scanf("%s",a);
            insert(a);
        }
        else {
            scanf("%s",a);
            find(a) == 1 ? printf("yes\n"):printf("no\n");
        }
    }

    return 0;
}



Measured memory_bytes: 16912
#include<bits/stdc++.h>
#define ll long long 
#define MM(arr,x) memset(arr,x,sizeof(arr))
#define INF 0x3f3f3f3f
#define Maxn 1e5+10;
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	ll ans=0,k,now=0;
	cin>>k;
	while(ans<=99999999)
	{
		ans++;
		now=(now*10+7)%k;
		if(now==0) 
		{
			cout<<ans;
			return 0;
		}
	}
	cout<<-1;
	return 0;
} 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t ma){if(ma+1 > IsPrime.size())IsPrime.resize(ma+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=ma; ++i)if(IsPrime[i])for(size_t j=2; i*j<=ma; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
const int mod = 1000000007;
ll n,m,ac=0,answa=0,ma = 0;
std::vector<ll> p; std::vector<string> s; std::vector<bool> ck; std::vector<ll> wa;
int main(){
  cin >> n >> m;
  ck.resize(n+1); wa.resize(n+1); p.resize(m); s.resize(m);
  for (size_t i = 0; i <= n; i++){
    ck[i] = true;
    wa[i] = 0;
  }
  for (size_t i = 0; i < m; i++) {
    cin >> p[i] >> s[i];
    if(ck[p[i]]){
      if(s[i] == "AC"){
        ck[p[i]] = false;
        ac++;
      }
      if(s[i] == "WA"){
        wa[p[i]]++;
      }
    }
  }
  for (size_t i = 0; i <= n; i++) {
    if(!(ck[i])){
      answa += wa[i];
    }
  }
  cout << ac << " " << answa << endl;
}


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

#define rep(i, n, N) for(ll i=(n); i<(N); i++)
using namespace std;
typedef long long ll;
int N, A;
int x[50];
ll dp[51][51][3010];
//-----------------------------------------------------------------
int main() {
	cin >> N >> A;
	rep(i, 0, N) cin >> x[i];
 
	dp[0][0][0] = 1;
	rep(i, 0, N) rep(j, 0, N) rep(k, 0, 2500) if(dp[i][j][k]){
		dp[i + 1][j][k] += dp[i][j][k];
		dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
	}
 
	ll ans = 0;
	rep(i, 1, N + 1) ans += dp[N][i][i*A];
	cout << ans << endl;
}

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

int main() {
int a,b;
cin>>a;
cin>>b;
if (b%2==0)
{
    if(a>=13)
    cout<<b;
    else if((6<=a)&&(a<=12))
    cout<<b/2;
    else
     cout<<b-b;
    
}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define lli long long int
//#include<boost\multiprecision\cpp_int.hpp>
//using namespace boost::multiprecision;
lli gcd(lli a,lli b){
  if(a==0)
    return b;
  if(b>a)
    return gcd(b,a);
  return gcd(a%b,b);
}
lli finder(lli p,lli q,lli r){
  lli re=p;
  re=re-p/q;
  re=re-p/r;
  lli k=(q*r)/gcd(q,r);
  re=re+(p/k);
  return re;
}
int main(){
  lli a,b,c,d,i;
  cin>>a>>b>>c>>d;
  //k=(c*d)/gcd(c,d);
  cout<<finder(b,c,d)-finder(a-1,c,d)<<"\n";
  return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

#N = int(input())
#N, M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
S = input()

print(S[:3])

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll L, R;
    cin >> L >> R;

    if(R-L>=2019) cout<<0<<endl;
    else{
        ll res = numeric_limits<ll>::max();
        for(ll i=L; i<=R; i++){
            for(ll j=i+1; j<=R; j++){
                res = min(res, (i*j)%2019);
            }
        }
        cout<<res<<endl;
    }

    return 0;
}

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

string s;

bool check(int l)
{
    for(int i=0;i<l/2;i++)
        if(s[i]!=s[i+l/2])
            return false;

    return true;
}

int main()
{
    cin >> s;
    int l=s.length();
    for(int i=(l-1)/2*2;i>=2;i-=2)
    {
        if(check(i))
        {
            printf("%d\n",i);
            return 0;
        }
    }

    return 0;
}

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

using namespace std;

int main()
{
   int n,cnt=0;
   
   cin >> n;
   
   int a[n];
   
   for(int i=0;i<n;i++) cin >> a[i];
   
   for(int i=1;i<n-1;i++)
   {
       int ma=0,mi=0;
       
       ma = max(a[i-1],a[i+1]);
        mi = min(a[i-1],a[i+1]);
        if(a[i]<ma && a[i]>=mi) cnt++;
   }
   
   cout << cnt;
    return 0;
}


Measured memory_bytes: 256
/*
    dp[L][L] = 0 since there is no cost to combine a single item
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll INF = 1e18L;
ll s[405], dp[405][405];

int main() {
    int n;
    s[0] = 0;
    cin >> n;
    vector<int> a (n+1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0)
            s[i] = a[i];
        else
            s[i] = s[i-1] + a[i];
    } 
    for (int i = n-1; i >= 0; i--) {
        for (int j = i; j < n; j++) {
            if (i == j) {
                dp[i][j] = 0;
            }
            else {
                dp[i][j] = INF;
                for (int k = i; k < j; k++) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s[j] - s[i-1]);
                }
            }
        }
    }
    printf("%lld\n", dp[0][n-1]);
    // cout << "" << dp[0][n-1];
}


Measured memory_bytes: 1536
N,M = map(int,input().split())
cities = [[0]*N for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    cities[a-1][b-1]+=1
    cities[b-1][a-1]+=1

roads = [0]*N
for i in range(N):
    roads[i]=sum(cities[i])
    print(roads[i])

Measured memory_bytes: 3064
/**==============================================================*
*            "Bismillahir Rahmanir Raheem"                       *
*        Author          :  Misbah Uddin Tareq.                  *
*        Semester        :  5(C),CSE                             *
*        University      :  Leading University,Sylhet.           *
*===============================================================**/

#include<bits/stdc++.h>
using namespace std;
#define  ll                     long long
#define  pb                     push_back
#define  pii                    pair<int,int>
#define  pll                    pair<ll,ll>
#define  ff                     first
#define  ss                     second
#define  MX                     100005
#define  endl                   "\n"
#define  mod                    1e9+7
#define  pi                     acos(-1.0)
#define  PQ                     priority_queue
#define  mem(a,b)               memset(a, b, sizeof(a))
#define  bug(a)                 cout<<#a<<":"<<a<<endl
#define  all(x)                 (x).begin(),(x).end()
#define  allr(x)                (x).rbegin(),(x).rend()
#define  double_print(x,a)      cout<<fixed<<setprecision(x)<<a<<endl


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

    ll x;
    cin>>x;
    
    if(x>=400 && x<=599)
        cout<<8<<endl;
    else if(x>=600 && x<=799)
        cout<<7<<endl;
    else if(x>=800 && x<=999)
        cout<<6<<endl;
    else if(x>=1000 && x<=1199)
        cout<<5<<endl;
    else if(x>=1200 && x<=1399)
        cout<<4<<endl;
    else if(x>=1400 && x<=1599)
        cout<<3<<endl;
    else if(x>=1600 && x<=1799)
        cout<<2<<endl;
    else
        cout<<1<<endl;
    

    return 0;
}


Measured memory_bytes: 3644
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from collections import deque

def main():
	n,m=MI()
	print((n+m)*(n+m-1)//2-n*m)





if __name__ == "__main__":
	main()

Measured memory_bytes: 38256
use std::collections::HashMap;
use std::io::{self, BufRead};
 
fn main() {
    let si = io::stdin();
    let mut si = si.lock();
    si.read_until(b'\n', &mut Vec::new()).unwrap();
    println!("{}", si.split(b' ')
        .map(|r| String::from_utf8(r.unwrap()).unwrap().trim_right().parse::<u32>().unwrap())
        .fold(HashMap::new(), |mut map, a| { *map.entry(a).or_insert(0) += 1; map })
        .iter()
        .fold(0, |acc, (&a, &n)| acc + if n < a { n } else { n - a })
    );
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define lf long double
#define F first
#define S second
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <pair <ll,ll> >vii;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    ll n=s.size();
    vii a;
    ll in=0;
    vi ans(n,0);
    while(in<n)
    {
        ll low=in;
        ll index;
        while(low<n && s[low]=='R')
        {
            low++;
        }
        index=low;//low && low-1;
        ll n1=low-in;
        while(low<n && s[low]=='L')
        {
            low++;
        }
        ll num=low-in;
        ll n2=num-n1;
        in=low;
        if(num%2==0)
        {
            ans[index]=num/2;
            ans[index-1]=num/2;
        }
        else
        {
            ans[index]=num/2;
            ans[index-1]=num/2;
            ll left=max(n1,n2)-min(n1,n2);
            if(n1>n2)
            {
                ans[index-1]++;
            }
            else
            {
                ans[index]++;
            }
            ll steps=max(n1,n2);
            if(steps%2==0)
            {
                swap(ans[index],ans[index-1]);
            }
        }
    }
    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 1488
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n): a[i] -= 1
d = [0] * n
nd = [0] * n
r = []
nr = []
i = 0
while True:
    i = a[i]
    if d[i]: break
    d[i] = 1
    r.append(i)
nr.append(i)
nd[i] = 1
while True:
    i = a[i]
    if nd[i]: break
    nd[i] = 1
    nr.append(i)
res = k%len(r)
if len(r) >= k:
    print(r[k-1]+1)
else:
    k -= len(r)
    k %= len(nr)
    print(nr[k-1]+1)

Measured memory_bytes: 32432
# -*- coding: utf-8 -*-
#mitsui a
import sys
import math
import collections
#sys.setrecursionlimit(100000)

#n=int(input())

tmp = input().split()
a,b = list(map(lambda a: int(a), tmp))
tmp = input().split()
c,d = list(map(lambda a: int(a), tmp))


if(a==c):
	print(0)
else:
	print(1)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;
  int accnt=0;
  int wacnt=0;
  int c;
  int m;
  string t;
  cin>>n>>m;
  vector <int> v(n,0);
  rep(i,m){
    cin>>c>>t;
    c--;
    if(t=="AC"){
      if(v[c]!=-1){
        accnt++;
        wacnt+=v[c];
        v[c]=-1;
      }
    }
    else{
      if(v[c]!=-1){
        v[c]++;
      }
    }
  }
  cout<<accnt<<" "<<wacnt;
}

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

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define len(s) s.length()
#define all(a) a.begin(), a.end()

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;

vector <int> mp;  
map <int, int> Hash;  

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        Hash[x]++;
        mp.pb(x);
    }
    sort(all(mp));
    mp.erase(unique(all(mp)), mp.end());
    if(n > 3 && (int)mp.size() > 3){
        cout << "No" << '\n';
        return 0;
    }
    if((int)mp.size() == 1){
        if(mp[0] != 0){
            cout << "No" << '\n';
            return 0;
        }
        cout << "Yes" << '\n';
        return 0;
    }
    if((int)mp.size() == 3){
       if(((mp[0]^mp[1]) == mp[2] || (mp[1]^mp[2]) == mp[0] || (mp[0]^mp[2]) == mp[1]) && 
                              (Hash[mp[0]] == Hash[mp[1]] && Hash[mp[1]] == Hash[mp[2]])){
           cout << "Yes" << '\n';
           return 0;
       }
       cout << "No" << '\n';
       return 0;
    }
    if((int)mp.size() == 2){
        if((mp[0] == 0 || mp[1] == 0) && (2 * Hash[0] == Hash[(mp[0] == 0 ? mp[1] : mp[0])])){
            cout << "Yes" << '\n';
            return 0; 
        }
    }
    cout << "No" << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

Measured memory_bytes: 4216
a,b,k=map(int,input().split())
#n=int(input())
#for i in range(n):
#    p[i]=[int(input()),i]
t=0
for i in range(k):
    if t==0:
        if a%2==0:
            a,b=(a)//2,b+(a)//2
        else:
            a,b=(a-1)//2,b+(a-1)//2
    if t==1:
        if b%2==0:
            b,a=(b)//2,a+(b)//2
        else:
            b,a=(b-1)//2,a+(b-1)//2
    t=1-t
print(a,b)

Measured memory_bytes: 38256
object Main extends App {
	val N = scala.io.StdIn.readInt
	val a = scala.io.StdIn.readLine.split(" ").map(_.toLong)
	
	var count = 0
	var count1 = 0

	for(i<-a){
		if(i%4L == 0L) count = count + 1
		if(i%2L == 0L && i%4L != 0L) count1 = count1 + 1
	}

	if(count1%2 == 0){
		val A = N - count1
		if((A%2 == 0 && A/2 <= count)) print("Yes")
		else if((A-1)%2 == 0 && (A-1)%2 <= count) print("Yes")
		else print("No")
	}else{
		val A = N - count1 + 1
		if((A%2 == 0 && A/2 <= count)) print("Yes")
		else if((A-1)%2 == 0 && (A-1)%2 <= count) print("Yes")
		else print("No")
	}
}


Measured memory_bytes: 42604
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main(void) {
	int N,K,T,U,V,L;
	cin >> N >> K >> T >> U >> V >> L;
	vector<int> D(N);
	for (int i = 0; i < N; ++i) {
		cin >> D[i];
	}
	double res = 0;
	bool boost = false;
	int ind,rem,car;
	ind = rem = car = 0;
	for (int l = 1; l < L+1; ++l) {
		if (boost) {
			res += (double)1/V;
		}
		else {
			res += (double)1/U;
		}

		if (l == D[ind]) {
			if (car == K || (!boost)) {
				rem = (V * T) + 1;
				boost = true;
			}
			else {
				++car;
			}
			++ind;
		}

		if (rem > 0) {
			--rem;
			if (rem == 0) {
				if (car > 0) {
					rem = V * T;
					--car;
				}
				else {
					boost = false;
				}
			}
		}
	}
	cout << setprecision(30) << res << endl;
	return 0;
}

Measured memory_bytes: 3256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

Int modpow(Int a, Int n, Int mod) {
    Int ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret = ret * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }

    return ret;
}

Int factorial(Int n, Int mod = 1) {
    Int ret = 1;
    if (mod == 1) {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
        }

        return ret;
    } else {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
            ret %= mod;
        }

        return ret;
    }
}

int main() {
    Int n, a, b;
    cin >> n >> a >> b;
    Int ans = modpow(2, n, MOD) - 1;

    Int nca = 0, ncb = 0, x = 1;
    for (Int i = n - a + 1; i < n + 1; i++) {
        x *= i;
        x %= MOD;
    }
    nca = x * modpow(factorial(a, MOD), MOD - 2, MOD) % MOD;

    x = 1;
    for (Int i = n - b + 1; i < n + 1; i++) {
        x *= i;
        x %= MOD;
    }
    ncb = x * modpow(factorial(b, MOD), MOD - 2, MOD) % MOD;

    ans = ans - nca - ncb;
    while (ans < 0) {
        ans += MOD;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    string s;
    cin >> s;
    bool f = true;
    for(int i = 0; i < s.size(); i++){
        char c = s[i];
        if(i % 2 == 0){
            if(c == 'L'){
                f = false;
            }
        }else{
            if(c == 'R'){
                f = false;
            }
        }
    }
    cout << (f? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  int r,g,b; cin >>r>>g>>b;
  int num = 100*r+10*g+b;
  if(num%4 == 0) cout << "YES" <<endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
N, M = gets.chomp.split.map(&:to_i)
is_ac = {}
wa_cnts = {}
cnt_ac = cnt_pn = 0
M.times do
  pi, si = gets.chomp.split

  next if is_ac[pi]

  if si == 'AC'
    is_ac[pi] = true
    cnt_ac += 1
    cnt_pn += wa_cnts[pi] || 0
  else
    wa_cnts[pi] ||= 0
    wa_cnts[pi] += 1
  end
end
puts "#{cnt_ac} #{cnt_pn}"


Measured memory_bytes: 15228
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
int a[200001],pd[200001];
signed main()
{
	int x=1,y=0;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	while(pd[x]==0)
	{
		k--;
		pd[x]=1;
		x=a[x];
		if(k==0)
		{
			printf("%lld",x);
			return 0;
		}
	}
	for(int i=1;i<=n;i++)
	pd[i]=0;
	while(pd[x]==0)
	{
		k--;
		y++;
		pd[x]=1;
		x=a[x];
		if(k==0)
		{
			printf("%lld",x);
			return 0;
		}
	}
	k%=y;
	while(k)
	{
		x=a[x];
		k--;
	}
	printf("%lld",x);
    return 0;
}

Measured memory_bytes: 6964
N, M = [int(_) for _ in input().split()]
KL = [[int(_) for _ in input().split()] for _ in range(N)]

UF = list(range(M + 1))


def find(a, x):
    if a[x] != x:
        a[x] = find(a, a[x])
    return a[x]


def unite(a, x, y):
    X = find(a, x)
    Y = find(a, y)
    Z = min(X, Y)
    a[X], a[Y] = Z, Z


def same(a, x, y):
    return find(a, x) == find(a, y)


for kl in KL:
    K, L = kl[0], kl[1:]
    for i in range(K - 1):
        unite(UF, L[i], L[i + 1])
for kl in KL:
    if not same(UF, KL[0][1], kl[1]):
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 21908
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] x = new int[n];
      for(int i = 0;i < n;i++)x[i] = sc.nextInt();
      int sum = 0;
      for(int i = 0;i < n;i++){
      	sum += Math.min(x[i],k-x[i])*2;
      }
      System.out.println(sum);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int main()
{
	IOS();
	
	
	int a,b;
	cin>>a>>b;
	if(a<=b)
	{
		for(int i=0;i<b;i++)
		cout<<a;
	}
	else 
	{
		for(int i=0;i<a;i++)
		cout<<b;
	}
	
	
	
	
	
	
	
	

	
	
	return 0;
}



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

const long long MOD = 2019;

int main() {
    long long L, R;
    cin >> L >> R;

    if (R - L >= 2019) {
        cout << 0 << endl;
    }
    else {
        long long mn = 1LL << 60;
        for (int i = L % MOD; i <= R % MOD - 1; i++) {
            for (int j = i + 1; j <= R % MOD; j++) {
                mn = min(mn, i * j % MOD);
            }
        }
        cout << mn << endl;
    }

    return 0;
}

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

int main(){
  long long A, B, AB, X, Y;
  cin >> A >> B >> AB >> X >> Y;
  long long ans = A * X + B * Y;
  for(long long i = 0; i <= max(X, Y) * 2;  i++){
    long long total = AB * (i * 2);
    long long nA = max(0LL, X - i);
    long long nB = max(0LL, Y - i);
    total += A * nA + B * nB;
    ans = min(ans, total);
  }
  cout << ans << endl;
}

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

using namespace std;

string s;

int main(){
	cin >> s;
	if(s.size()%2){
		cout << "No" << endl;
		return 0;
	}
	for(int i = 0; i < s.size()-1; ++i){
		if(i%2) continue;
		if(s[i] != 'h' || s[i+1] != 'i'){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main()
{
    int n,k; scanf("%d %d",&n,&k);
    
    int a[n+1];
    for(int i=1; i<=n; i++) scanf("%d",&a[i]);
    
    int dp[n+1];
   
    
    dp[0] = 0; dp[1] = 0;
    
    for(int i=2; i<=n; i++){
        int tmp = 999999999;
        for(int j=1; j<=k; j++){
            if(i-j<1) break;
            tmp = min(tmp, dp[i-j]+abs(a[i]-a[i-j]));
        }
        dp[i] = tmp;
    }
    cout << dp[n];
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

N, M, X, Y = map(int, input().split())

x = list(map(int, input().split()))
y = list(map(int, input().split()))

# print(x)
# print(y)

x.append(X)
y.append(Y)

# print(x)
# print(y)

# print(max(x))
# print(min(y))

# 戦争が起こるなら War、そうでないなら No War を出力せよ。

if max(x) < min(y):
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
k, n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
max = 0
1.upto(n - 1) do |i|
    d = a[i] - a[i - 1]
    max = d if d > max
end
d0 = k + a[0] - a[n - 1]
max = d0 if d0 > max
puts k - max

Measured memory_bytes: 15364
use std::time::{Duration, Instant};

use proconio::input;
use rand::Rng;
use rand_pcg::Mcg128Xsl64;

const V: usize = 26;

struct State {
    cc: Vec<i32>,
    ss: Vec<Vec<i32>>,
    tt: Vec<usize>,
}

impl State {
    fn new(cc: Vec<i32>, ss: Vec<Vec<i32>>, tt: Vec<usize>) -> State {
        State { cc, ss, tt }
    }

    fn calc_score(&self) -> i32 {
        let mut score = 0;
        let mut last = vec![0; V];
        for (d, &t) in self.tt.iter().enumerate() {
            let day = d as i32 + 1;
            last[t] = day;
            score += self.ss[d][t];
            score -= last
                .iter()
                .zip(self.cc.iter())
                .map(|(&l, &c)| c * (day - l))
                .sum::<i32>();
        }
        score
    }

    fn find_before(&self, day: usize, target: usize) -> usize {
        for (i, &t) in self.tt[..day].iter().enumerate().rev() {
            if t == target {
                return day - i - 1;
            }
        }
        day
    }

    fn find_after(&self, day: usize, target: usize) -> usize {
        for (i, &t) in self.tt[day + 1..].iter().enumerate() {
            if t == target {
                return i + 1;
            }
        }
        self.tt.len() - day
    }

    fn diff(&self, day: usize, new: usize) -> i32 {
        let now = self.tt[day];
        if new == now {
            return 0;
        }
        let mut diff = self.ss[day][new] - self.ss[day][now];
        diff -= {
            let b = self.find_before(day, now) as i32;
            let a = self.find_after(day, now) as i32;
            self.cc[now] * (a * b + a)
        };
        diff += {
            let b = self.find_before(day, new) as i32;
            let a = self.find_after(day, new) as i32;
            self.cc[new] * (a * b + a)
        };
        diff
    }
}

fn main() {
    let now = Instant::now();
    input! {
        d: usize,
        cc: [i32; V],
        ss: [[i32; V]; d],
    }
    let mut rng = Mcg128Xsl64::new(1);
    let tt = {
        let mut tt = Vec::with_capacity(d);
        for _ in 0..d {
            tt.push(rng.gen_range(0, V));
        }
        tt
    };
    let mut state = State::new(cc, ss, tt);

    let limit = Duration::from_millis(1900);
    while now.elapsed() < limit {
        for _ in 0..10000 {
            let day = rng.gen_range(0, d);
            let target = rng.gen_range(0, V);
            let diff = state.diff(day, target);
            if diff > 0 {
                state.tt[day] = target;
            }
        }
    }
    for &t in state.tt.iter() {
        println!("{}", t + 1);
    }
}


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

int main(){
    int n;
    cin >> n;
    vector<int>S(13);vector<int>H(13);vector<int>C(13);vector<int>D(13);
    for(int i = 0; i < n; i++){
        string A;int a;
        cin >> A >> a;
        if(A == "S"){
            S[a-1] = 1;
        }else if(A == "H"){
            H[a-1] = 1;
        }else if(A == "C"){
            C[a-1] = 1;
        }else if(A == "D"){
            D[a-1] = 1;
        }
    }
        
    for(int i = 0; i < 13; i++){
        if(S[i] == 0){
            cout<<"S "<< i+1 << endl; 
        }
    }
    for(int i = 0; i < 13; i++){
        if(H[i] == 0){
            cout<<"H "<< i+1 << endl; 
        }
    }
    for(int i = 0; i < 13; i++){
        if(C[i] == 0){
            cout<<"C "<< i+1 << endl; 
        }
    }
    for(int i = 0; i < 13; i++){
        if(D[i] == 0){
            cout<<"D "<< i+1 << endl; 
        }
    }
   
    
}


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


def primes(n: int):
    d = [True for i in range(n+1)]
    for i in range(2, n+1):
        if d[i]:
            for j in range(2, math.floor(n/i)+1):
                d[j*i] = False
    result = []
    for i in range(2, n+1):
        if d[i] and i % 5 == 1:
            result.append(i)
    return result


def solve(N: int):
    p = primes(55555)
    result = p[0:N]
    resultStr = ""
    isFirst = True
    for i in result:
        if not isFirst:
            resultStr += " "
        resultStr += str(i)
        isFirst = False
    print(resultStr)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    char a[105];
    int a1[105];
    memset(a1,0,sizeof(a1));
    cin>>n;
    cin>>a;
    int maxn = 0;
    for (int i = 0; i < n-1; i++)
    {
        int sum = 0;
        for (int j = 0; j <= i; j++)
        {
            int flag = 0;
            for (int k = i+1; k < n; k++)
            {
                if (a1[k] != 1&&a[j] == a[k])
                {
                    flag = 1;
                    a1[k] = 1;
                }
            }
            if (flag == 1)
            {
                sum++;
                for (int t = j+1; t <= i; t++)
                {
                    if (a[t] == a[j])
                        a1[t] = 1;
                }
                a1[j] = 1;
            }
        }
        if (sum > maxn)
            maxn = sum;
        memset(a1,0,sizeof(a1));
    }
    cout<<maxn<<endl;
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll q, ans = 0;cin >> q;
	priority_queue<ll> small;
	priority_queue<ll, vector<ll>, greater<ll>> large;
	REP(_, q){
		ll type;cin >> type;
		if(type == 1){
			ll a, b;cin >> a >> b;
			ans += b;
			small.push(a);
			large.push(a);
			ll aa = small.top();small.pop();
			ll bb = large.top();large.pop();
			if(aa > bb){
				ans += aa - bb;
				swap(aa, bb);
			}
			small.push(aa);
			large.push(bb);
		}
		else {
			cout << small.top() << " " << ans << endl;
		}
	}

	return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N;

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

	ll ans = N / 11 * 2;
	N %= 11;
	if(1 <= N && N <= 6){
		ans++;
	}
	else if(7 <= N){
		ans += 2;
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
import bisect

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

A.sort()
B.sort()
C.sort()
c_len = len(C)

cnt = 0
for b in B:
    a_cnt = bisect.bisect_left(A,b)
    c_cnt = c_len - bisect.bisect_right(C,b)
    cnt +=  a_cnt * c_cnt

print(cnt)

Measured memory_bytes: 23328
#include <iostream>
#include <vector>

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;
    xs.push_back(2020);

    int q;
    std::cin >> q;
    while (q--) {
        int i;
        std::cin >> i;
        --i;
        if (xs[i] + 1 < xs[i + 1]) ++xs[i];
    }

    xs.pop_back();
    for (auto x : xs) std::cout << x << "\n";
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3224
use std::io::{self, BufRead};
use std::collections::BTreeSet;

fn bfs(es: &Vec<Vec<usize>>, rest: &mut BTreeSet<usize>, n: usize) {
  rest.remove(&n);
  for &c in &es[n] {
    if rest.contains(&c) {
      bfs(es, rest, c);
    }
  }
}

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (n, m) = (xs[0], xs[1]);
  let mut es: Vec<Vec<usize>> = vec![Vec::new(); n];
  for _ in 0..m {
    let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
    let (x, y) = (xs[0] - 1, xs[1] - 1);
    es[x].push(y);
    es[y].push(x);
  }
  let mut rest: BTreeSet<usize> = (0..n).collect();
  let mut count: usize = 0;
  while !rest.is_empty() {
    let n = rest.iter().next().unwrap().clone();
    bfs(&es, &mut rest, n);
    count += 1;
  }
  println!("{}", count);
}

Measured memory_bytes: 28156
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n; 
    int ans=0;
    rep(i,n) {
        int a;
        cin >> a;
        if (i%2==0 && a%2==1) ++ans;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    ll N; cin >> N;
    ll A[N];
    rep(i,N)cin >> A[i];
    int b=0;
    int cnt=1;
    for(int i=1;i<N;i++){
        if(b==0){
            if(A[i]-A[i-1]>0)b=1;
            if(A[i]-A[i-1]<0)b=-1;
        }
        if(b*(A[i]-A[i-1])<0){
            b=0;
            cnt++;
        }
    }
    cout << cnt;
    


}

/*



 */



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int long long
const int N = 1e5+7;

int n, m, c, ans;

int t[N];

VI G[N];

int comp[N];
int size[N];
int cnt[N];

bitset<N> vis, spojna;

void dfs(int v)
{
	comp[v] = c;
	++size[c];

	for(auto it:G[v])
	{
		if(!comp[it])
			dfs(it);
	}
}

VI vec;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> m;

	if(m==n-1)
	{
		cout << 0;
		return 0;
	}

	for(int i = 1; i <= n; ++i)
	{
		cin >> t[i];
		vec.pb(i);
	}

	for(int i = 1; i <= m; ++i)
	{
		int a, b;
		cin >> a >> b;
		++a;
		++b;
		G[a].pb(b);
		G[b].pb(a);
	}

	for(int i = 1; i <= n; ++i)
	{
		if(!comp[i])
		{
			++c;
			dfs(i);
		}
	}

	sort(ALL(vec), [](int a, int b)
	{
		return t[a]<t[b];
	});

	for(auto it:vec)
	{
		if(!spojna[comp[it]])
		{
			ans += t[it];
			spojna[comp[it]] = 1;
			vis[it] = 1;
		}
	}

	int curr = c-2;

	for(auto it:vec)
	{
		if(!vis[it] && cnt[comp[it]]+1<min(size[comp[it]], c-1))
		{
			++cnt[comp[it]];
			ans += t[it];
			--curr;
		}

		if(!curr)
			break;
	}

	if(curr)
	{
		cout << "Impossible";
		return 0;
	}

	cout << ans;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N, M;
int k[111];
vec<int> s[111];
int p[111];

bool check(set<int> t) {
	set<int> on;
	rep (i, M) {
		int cnt = 0;
		rep (j, s[i].size()) {
			if (t.count(s[i][j])) {
				cnt++;
			}
		}
		if (cnt % 2 == p[i]) {
			on.insert(i);
		}
	}
	
	return on.size() == M;
}

int dfs(int sw, set<int> t) {
	if (sw >= N) {
		return check(t);
	}
	int ret = 0;
	
	ret += dfs(sw + 1, t);
	t.insert(sw);
	ret += dfs(sw + 1, t);

	return ret;
}

signed main() {
	cin >> N >> M;
	rep (i, M) {
		cin >> k[i];
		rep (j, k[i]) {
			int t;
			cin >> t;
			t--;
			s[i].push_back(t);
		}
	}
	rep (i, M) {
		cin >> p[i];
	}

	set<int> aa;
	int ans = dfs(0, aa);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n,R[200000],i,j,maxv,minv;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%d",&R[i]);
	}
	minv=R[0];
	maxv=-2000000000;
	for(j=1;j<=n-1;j++){
		if(maxv<(R[j]-minv)){
			maxv=R[j]-minv;
		}
		if(minv>R[j]){
			minv=R[j];
		}
	}	
	printf("%d\n",maxv);
	
	return 0;
}


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vi a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll ans = 1;
  const ll mod = 1e9+7;
  vi c(n+10);
  c[0] = 3;
  rep(i, n) {
    ans = ans*c[a[i]]%mod;
    c[a[i]]--;
    c[a[i]+1]++;
  }
  cout << ans << endl;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll X;
	cin >> X;

	ll val = 100;
	int cnt = 1;
	while (true) {
		val = 1.01 * val;
		if (val >= X){
			break;
		}
		cnt++;
	}

	cout << cnt << "\n";

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vpii = vector<pii>;

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

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int X,max=0;
    cin >>X;
    FOR(i,2,10){
        FOR(j,1,31){
            if((int)pow(j,i)>X) break;
            if(((int)pow(j,i)>max)&&((int)pow(j,i)<=X)) max=(int)pow(j,i);
        }
    }
    cout <<max;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main() {
	
	double x1, y1, x2, y2;
	
	while( cin >> x1 >> y1 >> x2 >> y2) {
		
		double dx = x2 - x1, dy = y2 - y1;
		
		cout << fixed << setprecision(8) << sqrt( dx * dx + dy * dy) << "\n";
		
	}
	
	return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll tot;



int main(){
	fio; cout<<fixed<<setprecision(25);	
	string s; cin >> s;
	int n = s.length();

	for(int i = 0;i < (1<<(n-1)) ; ++i){
		int prev = 0;
		for(int j = 0;j < n-1 ; ++j){
			if(i&(1<<j)){
				// trace(i , j , prev , s.substr(prev , j-prev+1));
				tot += stoll(s.substr(prev , j-prev+1));
				prev = j+1;
			}
		}
		tot += stoll(s.substr(prev));
	}
	cout << tot << endl;

	return 0;
}















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

namespace ITP2_5_B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            Node[] coordinates = new Node[n];
            string[] line;
            for (int i = 0 ; i < n ; i++)
            {
                line = Console.ReadLine().Split(' ');
                coordinates[i] = new Node(int.Parse(line[0]), int.Parse(line[1]), line[2], long.Parse(line[3]), line[4]);
            }

            Array.Sort(coordinates);

            var sb = new StringBuilder();
            for (int i = 0 ; i < n ; i++) sb.AppendLine(coordinates[i].Print());
            Console.Write(sb.ToString());
        }

        internal struct Node:IComparable<Node>
        {
            internal int Value { get;  set; }
            internal int Weight { get;  set; }
            internal string Type { get;  set; }
            internal long Time { get;  set; }
            internal string Name { get;  set; }
            internal Node(int value, int weight, string type, long time, string name)
            { Value = value; Weight = weight; Type = type; Time = time; Name = name; }
            internal string Print() { return Value.ToString() + " " + Weight.ToString() + " " + Type + " " + Time.ToString() + " " + Name; }

            public int CompareTo(Node other)
            {
                if (Value.CompareTo(other.Value) != 0) return Value.CompareTo(other.Value);
                if (Weight.CompareTo(other.Weight) != 0) return Weight.CompareTo(other.Weight);
                if (Type.CompareTo(other.Type) != 0) return Type.CompareTo(other.Type);
                if (Time.CompareTo(other.Time) != 0) return Time.CompareTo(other.Time);
                if (String.CompareOrdinal(Name,other.Name) != 0) return String.CompareOrdinal(Name, other.Name);
                return 0;
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n, k;
  cin >> n >> k;
  vll a(n);
  vin(a);

  vll count(200001, 0);
  vrep(i, a) count.at(i)++;
  sort(all(count));
  auto itlow = lower_bound(all(count), 1);
  ll kind = distance(itlow, count.end()) - k;
  cout << (kind <= 0 ? 0 : accumulate(itlow, itlow + kind, 0)) << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n];
	int b;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int nakayoshi;
	for (int i = 0; i < n; ++i)
	{
		if(i+1==a[a[i]-1]){
			nakayoshi+=1;
		}
	}
	// 出力
	cout << nakayoshi/2 << endl;
	return 0;
}

Measured memory_bytes: 640