akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;

int main()   {

      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no


//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n);
        readll(x);
        readll(m);

        if (n<=100100) {
            ll ret = 0, a = x;
            forr(i,0,n) {
                ret += x;
                x *= x; x %= m;
            }
            cout << ret << endl;
            continue;
        }

        vector<int> which(m,-1);
        ll curr = x;
        int i = 1;
        while (true) {
            which[curr] = i;
            ++i;
            curr *= curr; curr %= m;
            if (which[curr]!=-1) {break;}
        }

        ll ret = 0;
        ll a = x;
        forr(j,0,which[curr]-1) {
            ret += a;
            a *= a; a %= m;
        }
        n -= (which[curr]-1);
        ll cycle_sum = 0;
        ll cycle_count = i - which[curr];
        forr(j,0,cycle_count) {
            cycle_sum += a;
            a *= a; a %= m;
        }
        ll no_cycles = n/cycle_count;
        ret += no_cycles * cycle_sum;
        n %= cycle_count;
        forr(j,0,n) {
            ret += a;
            a *= a; a %= m;
        }
        cout << ret << endl;

    }
    return 0;
}


Measured memory_bytes: 3696
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = dp[i-1][j-1]+1
				} else if S[i-1] != T[j-1] && dp[i-1][j] > dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1]
				}
				// if S[i-1] == T[j-1] {
				// 	dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				// } else {
				// 	dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				// }
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}


Measured memory_bytes: 9792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    int ans = INF;
    for(int i=1; i<=100; i++){
        int sum = 0;
        rep(j, n) sum += (v[j] - i) * (v[j] - i);
        chmin(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "memory.h"

int input_int()
{
    const size_t BUF_SIZE = 100;
    char buf[BUF_SIZE];

    memset(buf, 0, BUF_SIZE);
    return atoi(fgets(buf, BUF_SIZE, stdin));
}

char *input_str(unsigned len)
{
  char *buf = (char *)malloc(len);
  memset(buf, 0, len);
  return fgets(buf, len, stdin);
}

int main(void)
{
  int n = input_int();

  char *buf = input_str((100 + 1) * 2);
  char *s = strtok(buf, " ");
  char *t = strtok(NULL, " ");

  for (int i = 0; i < n; i++) {
    printf("%c%c", *(s+i), *(t+i));
  }
  fputc('\n', stdout);
  free(buf);

  return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll big2 = 998244353;

ll indeg[100001] = {0};
vector<vl> C(100001, vl());
vector<vl> C2(100001, vl());

ll PAR[100001] = {0};

ll DP[100001] = {0};
ll root = 0;

ll dp(ll i){
    if(i == root){
        PAR[i] = -1;
        DP[i] = 0;
        return 0;
    }
    if(DP[i] != 0)return DP[i];

    ll best = -1;

    for(int c1 = 0; c1 < sz(C2[i]); c1++){
        ll a = C2[i][c1];
        ll d = dp(a);
        if(d > best){
            best = d;
            PAR[i] = a;
        }
    }
    DP[i] = best+1;
    return DP[i];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

    cin >> n >> m;
    for(int c1 = 0;  c1 < n+m-1; c1++){
        cin >> a >> b;
        a--;
        b--;
        C[a].push_back(b);
        C2[b].push_back(a);
        indeg[b]++;
    }

    for(int c1 = 0; c1 < n; c1++){
        if(indeg[c1] == 0)root  = c1;
    }

    for(int c1 = 0; c1 < n; c1++){
        dp(c1);
    }

    for(int c1 = 0; c1 < n; c1++){
        cout << PAR[c1]+1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 17152
import queue

n = int(input())

connect = [ [] for _ in range(n)]
distances = dict()

for i in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    connect[u].append(v)
    connect[v].append(u)
    distances[(u, v)] = w
    distances[(v, u)] = w

colors = [-1] * n
colors[0] = 0
q = queue.Queue()
q.put(0)

while not q.empty():
    x = q.get()

    for y in connect[x]:
        if colors[y] != -1:
            continue
        colors[y] = (colors[x] + distances[(x, y)]) % 2
        q.put(y)

print(*colors, sep='\n')


Measured memory_bytes: 53588
# -*- coding: utf-8 -*-
#ARC66C
import sys

n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

a=[]
for i in range(0,(n+1)//2):
	a.append(0)
for i in range(0,n):
	a[hoge[i]//2]+=1

if(a[0]%2!=n%2):
	print(0)
else:
	for i in range(1,(n+1)//2):
		if(a[i]!=2):
			print(0)
			sys.exit()
	print((max(a[0],1)*pow(2,(n-1)//2))%1000000007)



Measured memory_bytes: 14136
mod = int(1e9+7)
X, Y = map(int, input().split())

if (2*X-Y) < 0 or (-X+2*Y) < 0 or (2*X-Y)%3 or (-X+2*Y)%3:
    print(0)
    exit()

x = (2*X-Y)//3
y = (-X+2*Y)//3

if x > y:
    tmp = x
    x = y
    y = tmp

ans = 1
for i in range(1, x+1):
    ans *= (i+y)
    ans %= mod
    ans *= pow(i, mod-2, mod)
    ans %= mod

print(ans)


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

#define int long long

int n,m;

main(){
	cin>>n>>m;
	int ans=0;
	int t=0;
	
	t=min(n,m/2);
	ans+=t;
	m-=t*2;
	ans+=m/4;
	
	cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int r = sc.nextInt();
        if(n>=10){
            System.out.println(r);
        }
        else{
            System.out.println(r+100*(10-n));
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll n,a,b;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>a>>b;
	ll ans=n/(a+b);
	ans*=a;
	ans+=min(a,n%(a+b));
	cout<<ans;	
	re 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max(a,b) ((a)>(b) ? (a):(b))
int N,W;
int v[100],w[100];
int dp[101][10001];
int rec(int i,int j){
    int res;
    if(dp[i][j]>=0) return dp[i][j];
    if(i==N) res=0;
    else if(j<w[i]) res=rec(i+1,j);
    else res=max(rec(i+1,j),rec(i+1,j-w[i])+v[i]);
    return dp[i][j]=res;
}

int main(void){
    int i,j;

    scanf("%d%d",&N,&W);
    for(i=0;i<N;i++){
	scanf("%d%d",&v[i],&w[i]);
    }
    for(i=0;i<=100;i++) for(j=0;j<=10000;j++) dp[i][j]=-1;
    printf("%d\n",rec(0,W));

    return 0;
}

Measured memory_bytes: 4544
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
string s;
cin>>s;
n=s.length();
if(s[0]!=s[n-1])
{
	if(n%2==1)ol("First");
	else ol("Second");
}
else
{
	if(n%2==0)ol("First");
	else ol("Second");
}
return 0;
}


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

typedef long long ll;

int main()
{
    string temp;
    cin >> temp;
    vector <int> number;
    int i;
    for(i = 0;i < temp.size();++i){
        number.push_back(temp.at(temp.size() - i - 1) - '0');
    }
    i = 0;
    ll ans = 0;
    while(true){
        if(i == number.size()){
            break;
        }
        if(number.at(i) <= 4){
            ans += number.at(i);
        }else{
            if(i != number.size()-1){
                if(number.at(i) >= 6){
                    ans += 10 - number.at(i);
                    ++number.at(i+1);
                }else if(number.at(i) == 5){
                    if(number.at(i+1) >= 5){
                        ans += 5;
                        ++number.at(i+1);
                    }else{
                        ans += 5;
                    }
                }
            }else{
                if(number.at(i) >= 6){
                    ans += 1;
                    ans += 10 - number.at(i);
                }else{
                    ans += 5;
                }
            }
        }
        ++i;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  long double w, h;
  long double x, y;
  cin >> w >> h >> x >> y;
  //vector<int> l(n);
  //for(int i = 0; i < n; i++)
  //  cin >> l.at(i);
  
  int ans = 0;
  if(x == (long double)w / 2 && y == (long double)h / 2)
    ans = 1;
  
  long double men = 0.0;
  men = w * h / 2.0;
  
  cout << fixed << setprecision(10) << men;
  cout << ' ' << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	--N;
	
	ll diff = B - A;
	
	bool ans = false;
	for (ll i = 0; i < N + 1; ++i) {
		ll l = -(N - i) * D + i * C;
		ll r = -(N - i) * C + i * D;
		ans |= l <= diff && diff <= r;
	}
	
	puts([&] {
		return ans;
	}() ? "YES": "NO");
	
	return 0;
}


Measured memory_bytes: 256
from collections import *
from heapq import *
from itertools import *
from fractions import gcd

from decimal import *
import copy
from bisect import *
import time
import sys
import math
input=lambda :sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
N=int(input())
#A,B=map(int,input().split())
#A=list(map(int,input().split()))
c=0
for a in range(1,N+1):
    if not (a%3==0 or a%5==0):
        c+=a
print(c)


Measured memory_bytes: 72828
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
ll a, b, c;
ll k;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> a >> b >> c >> k;
    ll kol = min(a, k);
    k -= kol;
    ll rez = kol;
    kol = min(b, k);
    k -= kol;
    kol = min(c, k);
    rez -= kol;
    cout << rez << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<29;
const double eps = 1e-4;
const double PI=3.1415926535897932;

LL s[100009];

int main(){
	DRI(n);
	REP(i,n)scanf("%lld",&s[i]);
	sort(s,s+n);
	int st=0,en=n;
	while(st<en){
		int mi=(st+en)/2;
		LL v=0;
		REP(i,mi){
			v+=s[i];
		}
		bool legit=1;
		REPP(i,mi,n){
			if(s[i]>2*v){
				legit=0;break;
			}
			v+=s[i];
		}
		if(legit)en=mi;
		else st=mi+1;
	}
	printf("%d",n-st+1);
}


Measured memory_bytes: 1024
n = int(input())

dp = [10**6 for _ in range(10**6)]
dp[0] = 0

for i in range(n):
    j6 = 1
    while j6 <= n:
        dp[i+j6] = min(dp[i+j6],dp[i]+1)
        j6 *= 6
    j9 = 1
    while j9 <= n:
        dp[i+j9] = min(dp[i+j9],dp[i]+1)
        j9 *= 9
print(dp[n])

Measured memory_bytes: 147932
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1000000007;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

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;
}
#pragma endregion

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        return (par[x]==x?x:par[x]=root(par[x]));
    }
    bool merge(int x, int y){
        x=root(x); y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){return root(x)==root(y);}
    int size(int x){return rank[root(x)];}
    int count(){return num;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    UnionFind UF(N);
    for (;M--;){
        int A,B; cin >> A >> B;
        UF.merge(--A,--B);
    }

    cout << UF.count()-1 << '\n';
}

Measured memory_bytes: 3992
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#define int long long
using namespace std;
signed main() {
    int a = 0, ans = 0; double n, b = 0; cin >> n;
    for (int h = 1; h < sqrt(n); h++) {
        a = n / h; b = n / h;
        if (a == b && h != n / h - 1) {
            ans += n / h - 1;
        }
    }
    cout << ans << endl;
}

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

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        int index = 0;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        int count = 0;
        long total = 0;

        while ((line = br.readLine()) != null) {
            if (index == 0) {
                index = Integer.parseInt(line);
            } else {
                int[] array = new int[index];
                java.util.StringTokenizer st = new StringTokenizer(line, " ");
                while (st.hasMoreTokens()) {
                    array[count] = Integer.parseInt(st.nextToken());
                    total += array[count];
                    count++;
                }
                for (int i = 0; i < (index - 1); i++) { //昇順
                    for (int j = (index - 1); j > i; j--) {
                        if (array[j - 1] > array[j]) {
                            int tmp = array[j - 1];
                            array[j - 1] = array[j];
                            array[j] = tmp;
                        }
                    }
                }

                System.out.println(array[0] + " " + array[index - 1] + " " + total);

                if (index == count) {
                    break;
                }
            }

        }

    }
}



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

int main() {
  ll a;
  string b;
  cin >> a >> b;

  ll x = 100;
  ll bi = 0;
  for (char c : b) {
    if (c == '.') continue;
    bi += (c - '0') * x;
    x /= 10;
  }
  cout << a * bi / 100 << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;


namespace util {

// 累乗
ll pow(ll x, ll n)
{
  if (n == 0) {return 1LL;}
  ll ret = 1LL;
  while (n > 0) {ret *= x; n--;}
  return ret;
}

// 桁和
ll digitSum(ll x)
{
  std::string s = std::to_string(x);
  ll ret = 0LL;
  for (auto c : s) {ret += c - '0';}
  return ret;
}

} // namespace util


// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }


ll get_snuke_num(ll N)
{
  typedef std::pair<ld, ll> P;
  std::priority_queue< P, std::vector<P>, std::greater<P> > que;

  for (ll d = 0; d <= 15; d++) {
    ll x = util::pow(10, d) * std::floor(N / util::pow(10, d) + 1) - 1;
    ld y = (ld)x / (ld)util::digitSum(x);
    //print(N, d, x, y);
    que.push(std::pair<ld, ll>(y, x));
  }

  P p = que.top();
  return p.second;
}

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

  ll K;
  std::cin >> K;

  ll N = 1;
  for (ll k = 0; k < K; k++) {
    print(N);
    N = get_snuke_num(N+1);
  }

  return 0;
}


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

signed main(){
  int N; cin >> N;
  vs S(N);
  rep(i,N) cin >> S[i];
  map<char, int> mp;
  rep(i,S[0].size()) mp[S[0][i]]++;
    
  rep2(i,1,N){
    map<char, int> tmp;
    rep(j,S[i].size()) tmp[S[i][j]]++;
    for(auto it : mp)  mp[it.first] = min(it.second, tmp[it.first]);
  }
  
  for(auto it : mp){
    if(it.second !=0) cout << string(it.second, it.first);
  }
  cout << endl;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  int count = 0;
  for(int i=0; i<s.size(); i++){
    if(s.at(i) == 'A' || s.at(i) == 'T' || s.at(i) == 'G' || s.at(i) == 'C'){
      count++;
    }
    else{
      if(count > ans){
        ans = count;
      }
      count = 0;
    }
  }
  cout << max(ans,count) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

int main()
{
  int n, A, B, C, D;

  scanf("%d%d%d%d%d", &n, &A, &B, &C, &D);
  n--;

  ll treb = abs(B - A);
  
  REP(pl, n+1) {
    int mn = n - pl;
    ll lev = (ll) C * pl - (ll) D * mn;
    ll des = (ll) D * pl - (ll) C * mn;
    if (treb >= lev && treb <= des) {
      TRACE(pl _ mn _ lev _ des _ treb);
      printf("YES\n");
      return 0;
    }
  }
  
  printf("NO\n");
 
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll tmp = c-a-b;
    if(tmp <= 0){
        cout << "No" << endl;
        return 0;
    }
    tmp = tmp*tmp;
    ll tmp2 = 4*a*b;
    if(0 < tmp-tmp2){
        cout << "Yes" << endl;
    }else{
        cout << "No"  << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int d[128][128],solve[128];
int main(){
      //input
      int n,m,row,t;
      queue<int> que;
      cin >> n;
      for(int i= 0;i<n;i++){
            cin >>row>>m;
            for(int j = 0;j<m;j++){
                  cin>>t;
                  d[row][t] = 1;
            }
      }
      //debug
      //for(int i = 0;i<=n;i++){
      //for(int j = 0;j<=n;j++)cout << d[i][j] << ' ';cout << endl;}

      //solve
      fill(solve,solve+n+2,-1);
      que.push(1);
      solve[1] = 0;
      while(!que.empty())
      {
            int p = que.front();
            que.pop();
            for(int i = 1;i<=n;i++)
            {
                  if(d[p][i] && solve[i]==-1)
                  {
                        que.push(i);
                        solve[i] = solve[p] + 1;
                  }
            }
      }
      for(int i = 1;i<=n;i++)
            cout << i << ' '<< solve[i]<<endl;


}

Measured memory_bytes: 1252
n = int(input())
Rlist = [int(input()) for _ in range(n)]
min_val = Rlist[0]
ans = -10**10
for i in range(1, n):
    ans = max(ans, Rlist[i]-min_val)
    min_val = min(min_val, Rlist[i])
print(ans)



Measured memory_bytes: 13596
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
template<typename T>
struct compress{
    std::map<T,int> zip;
    vector<T> unzip;
    compress(vector<T> x){
        unzip=x;
        sort(All(x));
        x.erase(unique(All(x)),x.end());
        REP(i,x.size()){
            zip[x[i]]=i;
        }
    }
    size_t operator[](int k){return zip[unzip[k]];}
};
int main(){
    ll N,D,A;cin>>N>>D>>A;
    vector<pair<ll,ll>> monster(N);
    REP(i,N) cin>>monster[i].first>>monster[i].second;
    sort(All(monster));
    vector<ll> pos;
    REP(i,N){
        pos.push_back(monster[i].first);
        pos.push_back(monster[i].first+2*D);
    }
    sort(All(pos));
    compress<ll> z(pos);
    vector<ll> imos(2*N);
    ll i=0,now=0,cnt=0;
    ll ans=0;
    while(i<2*N&&now<N){
        // cout<<z.unzip[i]<<" "<<cnt<<endl;
        if(z.unzip[i]==monster[now].first){
            monster[now].second-=A*cnt;
            if(monster[now].second>0){
                ll C=(monster[now].second+A-1)/A;
                imos[z.zip[z.unzip[i]+2*D]]-=C;
                cnt+=C;
                ans+=C;
            }
            now++;
        }
        else{
            cnt+=imos[z[i]];
        }
        ++i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 38580
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * n

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i - 1]
            i &= i - 1
        return s

    def update(self, i, x):
        while i < self.n:
            self.data[i] += x
            i |= i + 1
        return


n, m = map(int, input().split())
c = list(map(int, input().split()))
b = BIT(n)
for i in range(n):
    b.update(i, c[i])

for i in range(m):
    t, x, y = map(int, input().split())
    if t == 1:
        print(b.sum(y) - b.sum(x))
    else:
        b.update(x, y)


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

#define INF (1LL<<60)

int main(){
	int n,k;	cin>>n>>k;
	vector<int> candles(n,0);

	for(int i=0;i<n;i++){
		cin>>candles[i];
	}
	long long ans=INF;
	int lPos=0,rPos=0;

	while(1){
		if(rPos>=n)break;

		int count=rPos-lPos;
		if(count>k-1){
			lPos++;
			count--;
		}else if(count<k-1){
			rPos++;
			count++;
		}

		if(count==k-1){
			//printf("%d <--> %d\n",candles[lPos], candles[rPos]);
			long long tmp1=abs(candles[lPos]) + abs(candles[rPos]-candles[lPos]);
			long long tmp2=abs(candles[rPos]) + abs(candles[rPos]-candles[lPos]);
			long long tmp=min(tmp1,tmp2);

			ans=min(ans,tmp);

			rPos++;
			lPos++;
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def S(n):
    s = 0
    while n != 0:
        s += n % 10
        n //= 10
    return s

# @mt
def slv(K):
    ans = [(i, i/S(i)) for i in range(1, 10)]
    for i in range(16):
        a = i
        if a > 4:
            a = 4
        for j in range(1, 10**a):
            b = (10**(i-a+1))*j + (10**(i-a+1)-1)
            if b < 10**(i-1):
                continue
            s = S(b)
            
            while ans[-1][1] > b/s or ans[-1][0] == b:
                (ans.pop())
            ans.append((b, b/s))
            # print(ans[-1])
    # error_print(len(ans))
    # for r in ans:
    #     error_print(r)
    error_print(len(ans))
    
    return '\n'.join(map(str, map(lambda x: x[0], ans[:K])))


def main():
    K = read_int()
    print(slv(K))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5452
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N, T, A;
  cin >> N >> T >> A;
  vector<ll> hs(N);
  for (auto i = 0; i < N; i++) cin >> hs[i];
  ll min_idx = 0;
  for (auto i = 0; i < N; i++) {
    double a = T - (double) hs[min_idx] * 0.006 - A;
    double b = T - (double) hs[i] * 0.006 - A;
    if ((a >= 0 ? a : -a) > (b >= 0 ? b : -b)) min_idx = i;
  }

  cout << (min_idx + 1) << endl;

  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int n,d,x;
  cin>>n>>d>>x;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  x+=n;
  d--;
  for(int i=0;i<n;i++){
    x+=d/a[i];
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

signed main(){
/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/
  int A, B, C, K;
  cin >> A >> B >> C;
  cin >> K;

  while (B <= A) { B *= 2; K--; };
  while (C <= B) { C *= 2; K--; };

  cout << ((K < 0) ? "No" : "Yes") << endl;

  return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
#define MAX 3030
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX],sg[MAX];
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1;
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;}
void dfs(int u,int ff)
{
	sg[u]=0;
	for(int i=h[u];i;i=e[i].next)
		if(e[i].v!=ff&&a[e[i].v]<a[u]){dfs(e[i].v,u);if(!sg[e[i].v])sg[u]=1;}
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	for(int i=1,u,v;i<n;++i)u=read(),v=read(),Add(u,v),Add(v,u);
	for(int u=1;u<=n;++u){dfs(u,0);if(sg[u])printf("%d ",u);}
	puts("");return 0;		
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {

    string s; cin >> s;
    pair<char,ll> mem;
    vector<ll> d(s.length(),0);
    mem = make_pair('R',0);
    vector<ll> ans(s.length(),0);

    rep(i,s.length()){
        if(mem.first != s[i]){
            if(mem.first == 'R') {
                for (int j = mem.second; j < i; j++) {
                    d[j] = i - j;
                }
                mem = make_pair('L',i);
            }  else if(mem.first == 'L'){
                 for (int j = mem.second; j < i; j ++){
                     d[j] = j - mem.second +1;
                 }
                 mem = make_pair('R',i);
            }
        }
    }

    for(int i = s.length() - 2; i >= 0; i --){
        if(s[i] == 'R'){
            for(int j = s.length()-1; j >= mem.second ; j --) {
                d[j] = j - i;
            }
            break;
        }
    }

    rep(i,s.length()){
        if(s[i] == 'R'){
            if(d[i]%2 == 0) ans[i+d[i]] ++;
            else ans[i+d[i]-1] ++;
        }else{
            if(d[i]%2 == 0) ans[i-d[i]] ++;
            else ans[i-d[i]+1] ++;
        }
    }

    rep(i,s.length()) cout << ans[i] << " ";

    


    


    

    return 0;
}


Measured memory_bytes: 5068
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        var s = cin.next();

        int a = -1;
        int z = -1;

        for(int i = 0;i<s.Length;i++)
        {
            if (a == -1 && s[i] == 'A') a = i;
            if (s[i] == 'Z') z = i;
        }

        Console.WriteLine(z - a + 1);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 4184
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x = max(x, y)
#define chmin(x,y) x = min(x, y)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b);
    priority_queue<int> r;
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    sort(rall(p));
    sort(rall(q));
    rep(i, x) r.push(p[i]);
    rep(i, y) r.push(q[i]);
    rep(i, c) {
        int r1;
        cin >> r1;
        r.push(r1);
    }
    ll ans = 0;
    rep(i, x + y) {
        int g = r.top();
        r.pop();
        ans += (ll) g;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6152
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b;cin>>a>>b;
  int n=b-a;
  P((n*(n-1))/2-a);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define Sheep 'S' 
#define Walf 'W' 
typedef char Animal;
using namespace std;

int N; 
string s;

Animal calcNextAnimal(Animal a,Animal b,int i ){
  if(a == Sheep){
    if(b == Sheep){
      if(s[i] == 'o') return Sheep;
      else return Walf;
    }else{
      if(s[i] == 'o') return Walf;
      else return Sheep;
    }
  }else{
    if(b == Sheep){
      if(s[i] == 'o') return Walf;
      else return Sheep;
    }else{
      if(s[i] == 'o') return Sheep;
      else return Walf;
    }
  }
}

int calcIndex(int i){
  if(i < N) return i;
  else return i - N;
}

bool isTrue(Animal A,Animal B){
  Animal tmpA,tmpB,tmp;
  string buf = "";
  tmpA = A;
  tmpB = B;
  buf = buf + A + B;
  for(int i=1;i<N+1;i++){
    tmp = calcNextAnimal(tmpA,tmpB,calcIndex(i));
    buf += tmp;
    tmpA = tmpB;
    tmpB = tmp;
  }
  if(buf[0] == buf[N] && buf[1] == buf[N+1]){
    cout << buf.substr(0,N) << endl;
    return true;
  }else{
    return false;
  }
}

int main(){
  cin >> N >> s;
  
  if(isTrue(Sheep,Sheep) || isTrue(Sheep,Walf) || isTrue(Walf,Sheep) || isTrue(Walf,Walf))
    return 0;
  else{
    cout << -1 << endl;
    return 0;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;


int main() {
	long long N,x;
	cin >> N >> x;
	vector<vector<long long>>cost(N,vector<long long>(N,mod*100000));
	for (size_t i = 0; i < N; i++)
	{
		cin >> cost.at(0).at(i);
	}
	for (size_t i = 0; i < N-1; i++)
	{
		for (size_t j = 0; j < N; j++)
		{
			cost.at(i + 1).at((j + 1) % N) = min(cost.at(i).at(j), cost.at(i).at((j + 1) % N));
		}
	}
	//i周目の最小コスト：i周目までの最小値の和＋x*i
	vector<long long> scost(N);
	for (size_t i = 0; i < N; i++)
	{
		for (size_t j = 0; j < N; j++)
		{
			scost.at(i) += cost.at(i).at(j);
		}
		scost.at(i) += i * x;
	}
	sort(scost.begin(),scost.end());
	cout << scost.at(0) << endl;
}

Measured memory_bytes: 33024
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int dist[110][110];

int main()
{
	int n,m;
	cin >> n >> m;
	
	vector<pair<int,pair<int,int> > > v;
	
	REP(i,n)REP(j,n)dist[i][j] = 1000000;
	
	REP(i,m)
	{
		int a,b,c;
		cin >> a >> b >> c;
		
		dist[a-1][b-1] = dist[b-1][a-1] = c;
		v.PB(MP(c,MP(a-1,b-1)));
	}
	
	REP(k,n)REP(i,n)REP(j,n)
	{
		dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
	}
	
	//SHOW2d(dist,n,n);
	
	int ans = 0;
	
	REP(i,m)
	{
		if(v[i].FI > dist[v[i].SE.FI][v[i].SE.SE])
		{
			ans++;
		//	cout << v[i].SE.FI << ':' << v[i].SE.SE << endl;
		}
	}
	
	cout << ans << endl;
		
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
  int a, b, c;
  std::cin >> a;
  std::cin >> b;
  std::cin >> c;

  int count = 0;
  for(int n = a; n <= b; n++){
    if(c % n == 0) count++;
  }

  std::cout << count << std::endl;
  
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int main()
{
    string N;
    int n,K,l;
    cin >> N;
    cin >> K;
    l = N.size();
    
    int dp[l+1][K+1][2]={0};
    
    
    for(int i=0;i<l+1;i++){
        for(int j=0; j<K+1; j++){
            for(int k=0;k<2;k++){
                dp[i][j][k]=0;
            }
        }
    }

    dp[0][0][0] = 1;

    
    for(int i=0;i<l;i++){
        for(int j=0; j<K+1; j++){
            for(int k=0;k<2;k++){
                n = N[i] - '0';
                for(int d=0;d<10;d++){
                    int next_i = i+1;
                    int next_j = j;
                    int next_k = k;
                    if(d != 0){
                        next_j += 1;
                    }
                    if(next_j > K)
                        continue;
                    if(k==0){
                        if(d > n)
                            continue;
                        if(d < n)
                            next_k = 1;
                    }
                    dp[next_i][next_j][next_k] += dp[i][j][k];
                }
            }
        }
    }
    
    cout << dp[l][K][0] + dp[l][K][1];
    return 0;
}
/*
    int m,n,k,cand;
    cin >> m >> n >> k;

    int a[m+1] = {0};
    a[0] = n;

    for(int i=0;i<k;i++){
        cin >> cand;
        for(int j=0; j<m+1; j++){
            if(a[j]>0){
                a[j]--;
                a[cand]++;
            }
        }
    }
    
    int maxi=0;
    for(int i=1;i<m+1;i++){
        if(a[i]>maxi) 
            maxi = a[i];
    }

    for(int i=1;i<m+1;i++){
        if(a[i]==maxi) 
            cout << i << endl;
    }


    for(int i=1;i<m+1;i++){
        cout << a[i] << endl;
    }
*/
 



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

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int x, a, b;
  string r;

  cin >> x >> a >> b;

  r = b <= a ? "delicious" : b <= a + x ? "safe" : "dangerous";

  cout << r << '\n';

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();

		char[] str = sc.next().toCharArray();
		int dp[] = new int[n];

		for(int i = 0; i < n; i++){
			if(str[i] == 'o'){
				if(i <= c){
					dp[i] = 1;
				}
				else {
					dp[i] = dp[i - c - 1] + 1;
				}
			}
			else {
				if(i == 0){
					dp[i] = 0;
				}
				else {
					dp[i] = dp[i - 1];
				}
			}

//			System.out.print(dp[i]+" ");
		}
//		System.out.println();

		if(dp[n - 1] > k){
			return;
		}

		Stack<Integer> stack = new Stack<Integer>();

		int current;
		int count = 0;
		int latestIndex = -1;
		int firstIndex = -1;
		for(int i = n - 1; i >= 0; i--){
			current = dp[i];
//			System.out.println("i = "+i+ " number "+current);

			if(str[i] == 'o'){
				count++;
				latestIndex = i;
				if(firstIndex == -1){
					firstIndex = i;
				}
			}

			if(i == 0 || dp[i - 1] != current){
				if(count == 1){
					stack.add(latestIndex + 1);
				}
				count = 0;
				if(i != 0){
//					i -= c;

					i = Math.min(i, firstIndex - c);
				}
				firstIndex = -1;

			}
		}

		while(!stack.isEmpty()){
			System.out.println(stack.pop());
		}
	}

}


Measured memory_bytes: 45260
#include<iostream>
#include<math.h>
#include<vector>
#include<memory.h>

int main() {
	int H, N;
	int c = 0;
	std::cin >> H >> N;
	std:: vector<int>A;
	for (int i = 0; i < N; i++) {
		int k;
		std::cin >> k;
		A.emplace_back(k);
		c += A[i];
	}
	if (H <= c) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;

}

Measured memory_bytes: 892