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

int H,W;
int t[1000][1000];
int total=0;

int main(){
  scanf("%d %d",&W,&H);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      scanf("%d",&t[i][j]);
      total+=t[i][j];
    }
  }

  for(int i=0;i<H;i++){
    int sum=0;
    for(int j=0;j<W;j++){
      sum+=t[i][j];
    }
    if( abs(sum - (W-sum) ) > 1 ){
      printf("no\n");
      return 0;
    }
  }
  
  for(int j=0;j<W;j++){  
    int sum=0;
    for(int i=0;i<H;i++){
      sum+=t[i][j];
    }
    if( abs(sum - (H-sum) ) > 1 ){
      printf("no\n");
      return 0;
    }
  }
  
  for(int i=0;i+1<H;i++){
    for(int j=0;j+1<W;j++){
      int f=t[i][j]+t[i+1][j]+t[i][j+1]+t[i+1][j+1];
      if(f%2==1){
        printf("no\n");
        return 0;
      }
    }
  }

  if( abs( total - (H*W-total) ) > 1) {
    printf("no\n");
    return 0;
  }
  
  printf("yes\n");
  return 0;
}



Measured memory_bytes: 7016
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5+5, mod = 1e9+7;

ll n, a[N], s[N], ans;

int main() {
	scanf("%lld", &n);
	for(int i=1;i<=n;i++) {
		scanf("%lld", &a[i]);
		s[i] = (s[i-1] + a[i]) % mod;
	}
	for(int i=1;i<=n;i++) ans = (ans + s[i-1] * a[i]) % mod;
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  int a[3][3];  
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  int n;
  cin>>n;
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  
  int h[3][3]={};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){      
      for(int k=0;k<n;k++){
        if(b[k]==a[i][j]){
          h[i][j]=1;
        }
      }      
    }
  }
  
  for(int i=0;i<3;i++){
    if(h[i][0]==1 && h[i][1]==1 && h[i][2]==1){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(h[0][i]==1 && h[1][i]==1 && h[2][i]==1){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  if(h[0][0]==1 && h[1][1]==1 && h[2][2]==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(h[2][0]==1 && h[1][1]==1 && h[0][2]==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
n,m = map(int,input().split())
dish = [0 for i in range(m)]
for i in range(n):
    s = list(map(int,input().split()))
    k = s[0]
    a = []
    for j in range(1,k+1):
        a.append(s[j])
    for j in range(len(a)):
        dish[a[j]-1]+=1
    a.clear()
cnt = 0
for i in range(len(dish)):
    if dish[i] == n:
        cnt+=1
print(cnt)

Measured memory_bytes: 18348
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const ll LINF = 1001002003004005006ll;

int main() {
    int a, b;
    cin >> a >> b;
    --a, --b;
    vector<vector<char>> hw(100, vector<char>(100, '.'));
    rep(i, 50) rep(j, 50) {
        if (i % 2 == 0 && j % 2 == 0 && b > 0) {
            hw[i][j] = '#';
            --b;
        } 
    }
    for (int i = 50; i < 100; ++i) {
        rep(j, 100) {
            hw[i][j] = '#';
            if (i % 2 == 1 && j % 2 == 0 && a > 0) {
                hw[i][j] = '.';
                --a;
            }
        }
    }
    cout << 100 << " " << 100 << endl;
    rep(i, 100) {
        rep(j, 100) cout << hw[i][j];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  in6 n,m;
  cin >> n >> m;
  vi high(n);
  rep(i,n) cin >> high[i];
  vi ans(n);
  rep(i,m) {
    in6 a,b;
    cin >> a >> b;
    if(high[a-1] > high[b-1]) ans[b-1]++;
    else if(high[a-1] < high[b-1]) ans[a-1]++;
    else { ans[a-1]++; ans[b-1]++; }
  }
  in6 count = 0;
  rep(i,n) if(ans[i] == 0) count++;
  cout << count;
  hinata;
}

Measured memory_bytes: 4000
from copy import deepcopy

k, n = map(int, input().split())

a = list(map(int, input().split()))
a = sorted(a)
max_ = max(a)
min_ = min(a)
a_ = deepcopy(a)
ans = 100000000000
for index in range(len(a)):
    # temp = max(a) - min(a)
    # print(max_,min_)
    temp = max_ - min_
    max_ = min_ + k
    if index != len(a)-1:
        min_ = a[index+1]
    a[index] = a[index] + k
    # print(temp)
    if ans > temp:
        ans = temp

max_ = max(a_)
min_ = min(a_)

for index in reversed(range(len(a))):
    # print(a_, temp, max(a_), min(a_))
    # temp = (max(a_) - min(a_))
    # print(max_,min_)
    temp = max_-min_
    min_ = max_ -k
    if index != 0:
        max_ = a_[index-1]
    # print(temp)
    # a_[index] -= k
    if ans > temp:
        ans = temp

print(ans)


Measured memory_bytes: 25672
N = int(input())
S = [input() for _ in range(2)]
M = 1000000007

if S[0][0] == S[1][0]:
    last_kind = 0
    ans = 3
    i = 1
else:
    last_kind = 1
    ans = 6
    i = 2
while i < N:
    if last_kind == 0 and S[0][i] == S[1][i]:
        ans *= 2
        last_kind = 0
        i += 1
    elif last_kind == 1 and S[0][i] == S[1][i]:
        last_kind = 0
        i += 1
    elif last_kind == 0 and S[0][i] == S[0][i+1]:
        ans *= 2
        last_kind = 1
        i += 2
    elif last_kind == 1 and S[0][i] == S[0][i+1]:
        ans *= 3
        last_kind = 1
        i += 2
    ans %= M

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int x[n];
    repi(i, n, 0)
    {
        cin >> x[i];
    }
    ll ans = INF;
    repi(j, 101, 1)
    {
        ll s = 0;
        repi(i, n, 0)
        {
            s += (j - x[i]) * (j - x[i]);
        }
        ans = min(ans,s);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = sorted(list(map(int, readline().split())))
    f = sorted(list(map(int, readline().split())), reverse=True)

    cor_v = 10 ** 19
    inc_v = -1
    while cor_v - inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for av, fv in zip(a, f):
            afv = av * fv
            if afv > bin_v:
                cost += (afv - bin_v + fv - 1) // fv
        #costが制約を満たすか
        if cost <= k:
            cor_v = bin_v
        else:
            inc_v = bin_v
    print(cor_v)



if __name__ == '__main__':
    solve()


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

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

static const double INF = 1E20;
const int M = 256;
int res[3];
int N;
int I[333];
int R[333], O[333];
double c[333];

int main(int argc, char *argv[])
{
  while(cin >> N, N){
    rep(i, N) cin >> I[i];
    double H = INF;
    rep(S, 16) rep(A, 16) rep(C, 16){
      R[0] = S;
      rep(i, N) R[i + 1] = (A * R[i] + C) % M;
      rep(i, N) O[i] = (I[i] + R[i + 1]) % M;
      rep(i, M) c[i] = 0.0;
      rep(i, N) c[O[i]] += 1.0;
      double e = 0.0;
      rep(i, M) if(c[i]) e -= c[i] * log2(c[i] / N) / N;
      if(H > e){
        H = e;
        res[0] = S;
        res[1] = A;
        res[2] = C;
      }
    }
    cout << res[0] << ' ' << res[1] << ' ' << res[2] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <math.h>
#include <vector>
#include <cstdlib>

using namespace std;

int main(int argc, const char * argv[]) {
        char A[4], B[4];
        int count = 0;

        cin >> A;
        cin >> B;

        if(A[0] == B[0]){ count++;}
        if(A[1] == B[1]){ count++;}
        if(A[2] == B[2]){ count++;}

        cout << count << endl;

        return 0;
}

Measured memory_bytes: 256
n = int(input())
t = [int(input()) for _ in range(n)]
def f(a,b):
    if b==0:
        return a
    else:
        return f(b,a%b)
t = sorted(t)[::-1]
l = t[0]
for i in range(1,len(t)):
    gcd = f(l,t[i])
    l = l*t[i]//gcd
print(l)

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

using namespace std;

typedef long long LL;

const int MX=400005;
const LL MXP=1000000000000000000ll;

char s[MX];int n;int bd[MX];
int T;
LL len[201],cf[201][26];
LL c[MX][26];
int typ;
#define A(x,y) for(int iA=0;iA<26;iA++)x[iA]+=y[iA]
void ini(){
	bd[0]=0;
	n=strlen(s);
	for(int i=1;i<n;i++){
		int t=bd[i-1];
		while(t&&s[t]!=s[i])t=bd[t-1];
		bd[i]=(s[t]==s[i]?t+1:0);
	}
	int l=bd[n-1];
	while(l>=n/2)l=bd[l-1];
	n-=l;
	memset(s+n,0,sizeof(char)*l);
	cerr<<s<<endl;
	T=n-bd[n-1];//最小正周期 
	cerr<<T<<endl;
	for(int i=0;i<n;i++){
		if(i)memcpy(c[i],c[i-1],sizeof(c[i]));
		c[i][s[i]-'a']++;
	}
	if(bd[n-1]%T){//fib
		typ=0;
		len[1]=n,len[2]=n+T;
		for(int i=0;i<26;i++)memcpy(cf[1],c[n-1],sizeof(cf[1]));
		memcpy(cf[2],cf[1],sizeof(cf[1]));
		A(cf[2],c[T-1]);
		for(int i=3;;i++){
			len[i]=len[i-1]+len[i-2];
			memcpy(cf[i],cf[i-1],sizeof(cf[i-1]));
			A(cf[i],cf[i-2]);
			if(len[i]>MXP)break;
		}
	}else{//cycle
		typ=1;
	}
}
LL cal(LL x,int ch){
	if(!x)return 0;
	if(typ)return (x%T?c[x%T-1][ch]:0)+c[T-1][ch]*(x/T);
	else{
		if(x<=n)return c[x-1][ch];
		for(int i=1;;i++){
			if(len[i+1]>x)return cf[i][ch]+cal(x-len[i],ch);
		}
	}
}
int main(){
	cin>>s;
	ini();
	LL L,R;cin>>L>>R;
	for(int i=0;i<26;i++)cout<<cal(R,i)-cal(L-1,i)<<' ';
	cout<<endl;
	return 0;
}


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

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

    int N, D, X;

    cin >> N >> D >> X;
    D--;

    for(int i = 0; i < N; i++) {
        int A;
        cin >> A;
        X++;
        X += D / A;
    }

    cout << X << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] S = new String[N];
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i=0; i<N; i++) {
			S[i] = sc.next();
			if(S[i].contains("AC")) a++;
			if(S[i].contains("WA")) b++;
			if(S[i].contains("TLE")) c++;
			if(S[i].contains("RE")) d++;
		}
		sc.close();
		System.out.println("AC x " + a);
		System.out.println("WA x " + b);
		System.out.println("TLE x " + c);
		System.out.println("RE x " + d);
	}

}

Measured memory_bytes: 65112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    intf n,m,a,b,cnt=0;
    cin >>n >>m;
    vector<intf> h(n);
    vector<bool> an(n,true);
    for(auto &e:h) cin >>e;


    rep(i,m){
        cin >>a >>b;
        a-=1;
        b-=1;
        if(h[a]>h[b]){
            an[b]=false;
        }else if(h[a]<h[b]){
            an[a]=false;
        }else{
            an[a]=false;
            an[b]=false;
        }
    }

    rep(h,n){
        if(an[h]){
            cnt++;
        }
    }

    cout << cnt <<endl;




}

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

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 1000005;

int n, comParity[MAXN], cnt2;
char s[MAXN];

void add(int n, int val) {
    while (n > 0 && n % 2 == 0) {
        n /= 2;
        cnt2 += val;
    }
}

bool isOddAnswer(vector<int> a) {
    int res = 0;
    for(int i = 0; i < a.size(); ++i)
        res += a[i] * comParity[i];
    return res % 2;
}

bool containOne(vector<int> a) {
    for(int x: a)
        if (x == 1)
            return true;
    return false;
}

int main() {
    scanf("%d", &n);
    scanf("%s", s);

    n -= 2;
    comParity[0] = 1;
    for(int k = 1; k <= n; ++k) {
        add(n - k + 1, 1);
        add(k, -1);
        comParity[k] = (cnt2 > 0) ? 0 : 1;
    }

    vector<int> a(n+1);
    for(int i = 0; i <= n; ++i)
        a[i] = abs(s[i] - s[i+1]);

    // for(int i = 0; i <= n; ++i) {
    //     printf("%d %d\n", a[i], comParity[i]);
    // }
    
    if (isOddAnswer(a))
        puts("1");
    else if (containOne(a)) 
        puts("0");
    else {
        for(int &x: a)
            x /= 2;
        int ans = isOddAnswer(a) ? 2 : 0;
        printf("%d\n", ans);
    }

    return 0;
}

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

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

    ll A, B, C;
    cin >> A >> B >> C;
    ll X = A, Y = B, Z = C;
    ll cnt = 0;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
        ll a = (B + C) / 2;
        ll b = (A + C) / 2;
        ll c = (A + B) / 2;
        if (a == X && b == Y && c == Z) {
            cout << -1 << endl;
            exit(0);
        }
        A = a;
        B = b;
        C = c;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node{
  int parent,left,right;
};

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u == NIL)return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1 = 0, h2 = 0;
  if (T[u].left != NIL ) h1 = setHeight(T[u].left) + 1;
  if (T[u].right != NIL) h2 = setHeight(T[u].right) +1;
  return H[u]= ( h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent == NIL)return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg =0;
  if(T[u].left != NIL)deg++;
  if(T[u].right != NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root = 0;
  scanf("%d",&n);

  for(int i =0;i<n;i++)T[i].parent = NIL;

  for(int i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left =l;
    T[v].right =r;
    if(l != NIL)T[l].parent =v;
    if(r != NIL)T[r].parent =v;
  }

  for(int i =0;i<n;i++)if(T[i].parent == NIL)root = i;

  setDepth(root,0);
  setHeight(root);

  for(int i=0;i<n;i++)print(i);

  return 0;
}



Measured memory_bytes: 2708
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  string s;
  cin >> s;
  i64 cnt = 0;
  for (i64 i = 0; i < s.size(); i++)
    if (s[i] == 'o')
      cnt++;
  if (8 <= cnt + 15 - s.size())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


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

// ダイクストラ法
// http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/26/dijkstra-copy.html
using P = pair<double, int>; // <最短距離, 頂点の番号>
void dijkstra(vector<vector<double>> &g, vector<double> &dist, int s)
{
	priority_queue<P, vector<P>, greater<P>> que;
	dist.assign(dist.size(), 1e13);
	dist[s] = 0.0;
	que.push(P(0.0, s));
	while (!que.empty())
	{
		P p = que.top();
		que.pop();
		int v = p.second;
		if (dist[v] < p.first)
			continue;
		for (int i = 0; i < g[v].size(); ++i)
		{
			double e = g[v][i];
			if (dist[i] > dist[v] + e)
			{
				dist[i] = dist[v] + e;
				que.push(P(dist[i], i));
			}
		}
	}
}

int main()
{
	double xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	int n;
	cin >> n;
	vector<double> x(n), y(n), r(n);
	rep(i, n) cin >> x[i] >> y[i] >> r[i];
	vector<vector<double>> g(n+2, vector<double>(n+2));
	rep(i, n - 1)
	{
		for (int j = i + 1; j < n; j++)
		{
			double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			if (r[i] + r[j] >= d)
			{
				g[i][j] = 0.0;
				g[j][i] = 0.0;
			}
			else
			{
				g[i][j] = d - r[i] - r[j];
				g[j][i] = d - r[i] - r[j];
			}
		}
	}
	rep(i, n)
	{
		double d = sqrt((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));
		if (r[i] >= d)
		{
			g[i][n] = 0.0;
			g[n][i] = 0.0;
		}
		else
		{
			g[i][n] = d - r[i];
			g[n][i] = d - r[i];
		}
		d = sqrt((x[i] - xt) * (x[i] - xt) + (y[i] - yt) * (y[i] - yt));
		if (r[i] >= d)
		{
			g[i][n + 1] = 0.0;
			g[n + 1][i] = 0.0;
		}
		else
		{
			g[i][n + 1] = d - r[i];
			g[n + 1][i] = d - r[i];
		}
	}
	double d = sqrt((xs - xt) * (xs - xt) + (ys - yt) * (ys - yt));
	g[n][n+1] = d;
	g[n+1][n] = d;
	// rep(i, n + 2) rep(j, n + 2) printf("%.3f%c", g[i][j], (j == n + 1) ? '\n' : ' ');
	vector<double> dist(n+2);
	dijkstra(g, dist, n);
	printf("%.10f\n", dist[n + 1]);
	return 0;
}

Measured memory_bytes: 14324
import java.util.*;

public class Main {
  public static int forward = 5;
  public static int back = 2;
  public static int right = 3;
  public static int left = 4;
  public static int up = 1;
  public static int down = 6;

  public static void north() {
    int a = forward;
    forward = up;
    up = back;
    back = down;
    down = a;
  }
  public static void east() {
    int a = right;
    right = up;
    up = left;
    left = down;
    down = a;
  }
  public static void south() {
    int a = back;
    back = up;
    up = forward;
    forward = down;
    down = a;
  }
  public static void west() {
    int a = left;
    left = up;
    up = right;
    right = down;
    down = a;
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] dice = new int[6];
    for(int i = 0; i < 6; i++) {
      dice[i] = sc.nextInt();
    }
    sc.nextLine();
    String[] direction = sc.nextLine().split("");
    for(int i = 0; i < direction.length; i++) {
      if(direction[i].equals("N")) {
        north();
      } else if(direction[i].equals("E")) {
        east();
      } else if(direction[i].equals("S")) {
        south();
      } else {
        west();
      }
    }
    System.out.println(dice[up - 1]);
  }
}



Measured memory_bytes: 26224
using System;


class AOJ
{

    public static void Main()
    {
        int[] a = new int[101];
        int n,Max=0;

        for(int i=0; i<=100; i++)
            a[i] = 0;

        while (true)
        {

            string s = Console.ReadLine();
            if (s == null) break;

            n = int.Parse(s);

            a[n]++;
        }

        for (int i = 0; i <= 100; i++)
        {
            if (a[i] > Max)
                Max = a[i];
        }

        for (int i = 0; i <= 100; i++)
        {
            if (a[i] == Max)
                Console.WriteLine(i);
        }
    }
}

Measured memory_bytes: 5608
#include <stdio.h>

int dp[45];

int fib(int x) {
  if (dp[x] != -1) {
    return dp[x];
  }
  
  if (x == 0 || x == 1) {
    dp[x] = 1;
    return dp[x];
  } else {
    dp[x] = fib(x - 1) + fib(x - 2);
    return dp[x];
  }
}

int main(void) {
  int i, n;
  for (i = 0; i < 45; i++) {
    dp[i] = -1;
  }
  scanf("%d", &n);

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

  return 0;
}

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

using namespace std;

int main()
{
    int X,Y,Z;
    int res=0,len=0;
    scanf("%d%d%d",&X,&Y,&Z);

    len+=Z;
    
    while(1)
    {
        len+=Y+Z;
        if(len>X)
            break;
        res++;
    }

    printf("%d\n",res);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n;
  cin >> n;
  int mh = 0;
  int cnt = 0;
  rep(i, n) {
    int h;
    cin >> h;
    if(h >= mh) {
      ++cnt;
      mh = h;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		FasterScanner sc = new FasterScanner(System.in);

		String n = sc.nextString();
		boolean c7 = false;
		for (int i = 0; i < n.length(); i++) {
			char c = n.charAt(i);
			if (c == '7') c7 = true;
		}
		if (c7) System.out.println("Yes");
		else System.out.println("No");
		
		sc.close();
	}
	
	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void close() {
			try {
				mIs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


Measured memory_bytes: 32520
import java.util.*;
 
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    int count = 0;
    char[] x = new char[N.length()];

    for(int i = 0 ; i < N.length() ; i ++){
      x[i] = N.charAt(i);
      count = (x[i] == 'p') ? count + 1 : count + 0;
    }
    System.out.println(N.length()/2 - count);
  }
}


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

const int ac = 2e5 + 5, bc = (1 << 18);
ll PR[ac];
ll CS[ac];

struct Tree
{
	vector<ll> T;
	Tree()
	{
		T.resize(bc * 2);
	}
	void update(int a, ll b)
	{
		a += bc;
		T[a] = b;
		while (a)
		{
			a /= 2;
			T[a] = min(T[a * 2], T[a * 2 + 1]);
		}
	}
	ll query(int a, int b)
	{
		a += bc; b += bc;
		ll m = min(T[a], T[b]);
		while (a / 2 != b / 2)
		{
			if (a % 2 == 0) m = min(m, T[a + 1]);
			if (b % 2 == 1) m = min(m, T[b - 1]);
			a /= 2; b /= 2;
		}
		return m;
	}
};

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q, a, b; cin >> n >> q >> a >> b; a--; b--;
	vector<ll> Q; Q.push_back(a);
	for (int i = 0; i < q; i++) { int x; cin >> x; x--; Q.push_back(x); } 
	ll s = 0;
	for (int i = 1; i <= q; i++) CS[i] = abs(Q[i] - Q[i - 1]), s += CS[i];
	Tree t1, t2;
	for (int i = 0; i < n; i++) t1.update(i, (ll)1e12), t2.update(i, (ll)1e12);
	t1.update(b, b); t2.update(b, -b);
	for (int i = 1; i <= q; i++)
	{
		ll w = min(t2.query(0, Q[i]) + Q[i], t1.query(Q[i], n - 1) - Q[i]) - CS[i];
		if (w < t1.query(Q[i - 1], Q[i - 1]))
		{
			t1.update(Q[i - 1], w + Q[i - 1]);
			t2.update(Q[i - 1], w - Q[i - 1]);
		}
	}
	ll m = 1e18;
	for (int i = 0; i < n; i++)
		m = min(m, t1.query(i, i) - i);
	cout << m + s << '\n';
}


Measured memory_bytes: 13808
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}
int main(){
  int N;
  long long X;
  cin>>N>>X;
  vector<long long>A(N+1);
  A.at(0)=X;
  for(int i=1;i<N+1;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  vector<long long>B(N);
  for(int i=0;i<N;i++){
    B.at(i)=A.at(i)-A.at(i+1);
  }
  sort(B.begin(),B.end());
  long long ans=B.at(0);
  for(int i=1;i<N;i++){
    ans=gcd(B.at(i),ans);
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
int H,N,A,a=0,sum=0;
scanf("%d %d",&H,&N);
while(a<N){
    scanf("%d",&A);
    sum+=A;
    ++a;
}
if(H-sum>0)
puts("No");
else
puts("Yes");
return 0;
}

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

using namespace std;

int main() {
    int i,j,n,p,q,temp;
    int a,b,t;
    int time=0;
    int flag=0;
    string s;
cin>>a>>b>>t;
time=t/a;
cout<<time*b;
    return 0;
}

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    Main abc124A = new Main();
    System.out.println(abc124A.solve(A, B));
  }

  public int solve(int A, int B){
    int[] array = new int[]{A, B};
    Arrays.sort(array);
    int temp = array[1];
    array[1] = array[1] - 1;
    Arrays.sort(array);
    temp += array[1];
    return temp;
  }
}


Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 2e5+10;
const int inf = 1e15;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int a[maxn],b[maxn];
bool check(int mid){
	int sum=0;
	for(register int i=1;i<=n;i++){
		if(a[i]*b[i]>mid){
			sum+=a[i];
			if(mid)sum-=mid/b[i];
		}
	}
	if(sum>m)return false;
	return true;
}

int cmp(int x,int y){return x>y;}

signed main(){
	n=read();m=read();
	for(register int i=1;i<=n;i++)a[i]=read();
	for(register int i=1;i<=n;i++)b[i]=read();
	sort(a+1,a+n+1);sort(b+1,b+n+1,cmp);
	int l=0,r=inf,ans=inf;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){r=mid-1;ans=mid;}
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3328
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      int[] A = new int[N];
      int total = 0;
      for(int i = 0; i < N; i++){
        A[i] = sc.nextInt();
        total += A[i];
      }
      
      // 人気商品判定
      int popular = total / (4 * M);
      if(total % (4 * M) > 0){
        popular++;
      }
      int count = 0;

      for(int i = 0; i < N; i++){
        if(popular <= A[i]){
          count++;
        }
      }
      
      String result = "No";
      if(M <= count){
        result = "Yes";
      }
      
      // 出力
      System.out.println(result);
    }
}

Measured memory_bytes: 23508
#include<stdio.h>

int main()
{
    int n,k,i,num[100010],a,ans=0;
    scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&(num[i]));
		if(num[i]==1)a=i;//1の場所の添え字
	}
	k--;
	ans=(n-1+k-1)/k;
	
    printf("%d",ans);
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int sen[10][10000], C, R, a[10][10000];

int solve(){
  int res = 0;
  rep(i, R){
    int c = 0;
    rep(j, C) if(a[j][i]) c++;
    res += max(c, C - c);
  }
  return res;
}

int dfs(int n){
  if(n == C){
    memcpy(a, sen, sizeof(sen));
    return solve();
  }
  int res = 0;
  res =  dfs(n+1);
  rep(i, R) sen[n][i] = sen[n][i] ^ 1;
  res = max(res, dfs(n+1));
  rep(i, R) sen[n][i] = sen[n][i] ^ 1;
  return res;
}

int main(){
  while(scanf("%d%d", &C, &R) && C+R){
    rep(i, C) rep(j, R) scanf("%d", &sen[i][j]);

    printf("%d\n", dfs(0));
  }
  return 0;
}

Measured memory_bytes: 1984
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define loop(i,n)for(i=0;i<n;i++)
#define INF 1000000000
using ll = long long int;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;


#define MAX 100005


int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
  ll a,c,b,d;
   cin>>a>>b>>c>>d;
   ll ans1 = (a*c);
   ll ans2 = (a*d);
   ll ans3 = (b*c);
   ll ans4 = (b*d);
   cout<<max(max(ans1,ans2),max(ans3,ans4))<<endl;
    return 0;
}


Measured memory_bytes: 3652
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

result1 = 0
for i in range(n):
    tmp = x[i] - y[i]
    if tmp > 0:
        result1 += tmp
    else:
        result1 -= tmp
        
result2 = 0
for i in range(n):
    tmp = x[i] - y[i]
    tmp = tmp**2
    result2 += tmp
result2 = math.sqrt(result2)

result3 = 0
for i in range(n):
    tmp = x[i] - y[i]
    tmp = tmp**3
    if tmp > 0:
        result3 += tmp
    else:
        result3 -= tmp
result3 = math.pow(result3, 1.0/3.0)

result4 = 0        
for i in range(n):
    tmp = x[i] - y[i]
    tmp = tmp**2
    tmp = math.sqrt(tmp)
    if tmp > result4:
        result4 = tmp
        
print(result1)
print(result2)
print(result3)
print(result4)


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

int main() {
  long long n, a, b;
  long long h[100001] = {};
  int i;
  scanf("%lld %lld %lld", &n, &a, &b);
  long long big = 0;
  for (i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
    if (big < h[i]) {
      big = h[i];
    }
  }
  long long imin = 0;
  long long imax = big / b + 1;
  long long imid;
  while (imax-1 > imin) {
    long long count = 0;
    long long temp[100001] = {};
    imid = imin + (imax - imin) / 2;
    for (i = 0; i < n; i++) {
      temp[i] = h[i];
      temp[i] -= b * imid;
      if (temp[i] < 0) {
	temp[i] = 0;
      }
    }
    for (i = 0; i < n; i++) {
      count += temp[i] / (a-b);
      if (temp[i] % (a-b) != 0) {
	count += 1;
      }
    }
    if (count > imid) {
      imin = imid;
    } else {
      imax = imid;
    }
    /*printf("%lld %lld\n", imin, imax);*/
  }
  printf("%lld\n", imax);
  return 0;  
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long long unsigned int ull;
#define INF 1LL << 29

int main() {
	string t, b;
	cin >> t >> b;
	vector<vector<ll> > dp(t.size() + 1, vector<ll>(b.size() + 1, 0));//dp[i][j] 後ろからi番目にj個選んだ時の場合の数
	dp[t.size()][b.size()] = 1;
	for (int i = t.size() - 1; i >= 0; i--)for (int j = b.size(); j >= 0; j--) {
		if (t[i] == b[j]) {
			dp[i][j] = dp[i + 1][j] + dp[i + 1][j + 1];
		}
		else {
			dp[i][j] = dp[i + 1][j];
		}
		if (dp[i][j] > 1000000007)dp[i][j] %= 1000000007;
	}
	cout << dp[0][0] << endl;
	return 0;
}


Measured memory_bytes: 10896
using System.Linq;
using System;
class Program
{
    static void Main(string[] args)
    {
        var input = System.Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(input[0]);
        var t = long.Parse(input[1]);
        var tList = System.Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
        long timer = 0;
        var index = 0;
        while(true)
        {
            if (index < tList.Length-1)
            {
                timer += Math.Min(t,tList[index+1]-tList[index]);
            }
            else
            {
                timer += t;
                break;
            }
            index++;
        }
        Console.WriteLine(timer);
        //System.Console.Read();
    }
}

Measured memory_bytes: 30752
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}

int main()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n + 1);
	vector<bool> seen(n + 1, false);
	seen[1] = true;
	for (ll i = 1; i < n + 1; i++)
	{
		cin >> a[i];
	}
	if (k < n)
	{
		int now = 1;
		for (ll i = 0; i < k; i++)
		{
			now = a[now];
		}
		cout << now << endl;
		return 0;
	}
	ll now = 1;
	k--;
	for (; k != 0; k--)
	{
		now = a[now];
		if (seen[now])
			break;
		seen[now] = true;
	}
	if (k == 0)
	{
		cout << now << endl;
		return 0;
	}
	vector<bool> seen_2(n + 1, false);
	seen_2[now] = true;
	ll repeat = 1;
	for (ll i = 0;; i++)
	{
		now = a[now];
		if (seen_2[now])
			break;
		seen_2[now] = true;
		repeat++;
	}
	// cout << k << endl;
	// cout << repeat << endl;
	k %= repeat;
	// cout << k << endl;
	for (ll i = 0; i < k; i++)
	{
		now = a[now];
	}
	cout << now << endl;

	return 0;
}

Measured memory_bytes: 4776
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;

bool prime[1000000];
int dp[100010];

int main(void)
{
    int q;
    cin >> q;

    //trueの配列を用意して、素数ではないものをfalseにしていく。
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false;
    for(int i = 2; i*i <= 1000000; i++){
        if(prime[i]){
            for(int j = 2 * i; j <= 1000000; j += i){
                prime[j] = false;
            }
        }
    }

    //2017に似た数を調べて見つけたら1を代入する。
    for(int i = 1; i < 100010; i++){
        if(i%2 && prime[i] && prime[(i+1)/2]){
            dp[i] = 1;
        }
    }

    //累積和を作る。
    for(int i = 1; i < 100010; i++){
        dp[i] += dp[i-1];
    }

    //いつも通り累積和の答えの出し方をする。
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        cout << dp[r] - dp[l-1] << endl;
    }

    return 0;
}



Measured memory_bytes: 2048
# -*- coding: utf-8 -*-
 
X = int(input())

AB_max = 0
abs_X = abs(X)

for i in range(10**9):
  if ( i**5-(i-1)**5 > 10**9 ):
    AB_max = i
    break

#print(AB_max)

for i in range(AB_max+1):
  for j in range(AB_max+1):
    
    A = i**5
    B = j**5
    
    if ( A-B==X ):
      print(i,j)
      break
    elif ( A-(-B)==X ):
      print(i,-j)
      break
    elif ( (-A)-B==X ):
      print(-i,j)
      break
    elif ( (-A)-(-B)==X ):
      print(-i,-j)
      break
      
  else:
    continue
  break


Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
    a[i]--;
  }
  int ans=0;
  REP(i,n){
    if(a[a[i]]==i){
      ans++;
    }
  }
  ans /= 2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;


int main() {
	int a,b,c;
	cin >> a >> b >> c;
	long long ans = 0;
	int t = min(b, c);
	ans += 2 * t;
	b -= t;
	c -= t;
	if (a == 1) cout << endl;
	if (b) {
		ans += b;
	}
	else if (c) {
		if (c > a + 1) {
			ans += a + 1;
		}		
		else {
			ans += c;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
	string s;
	int i, j, n, max = 0, cnt = 0;
	int k = 0;
	cin >> s;
	for (i = 0; i < s.size();) {
		if (s[i] == 'R') {
			while (s[i] == 'R') {
				i++;
				cnt++;
				if (cnt > max) {
					max = cnt;
				}
			}
		}
		else cnt = 0, i++;
	}

	cout << max;

	return 0;
}


Measured memory_bytes: 3192
#include <stdio.h>

int main(void){
	int y, m, d;
	char ans[256];
	while(scanf("%d%d%d",&y,&m,&d) != EOF){
		if(y < 1868 || (y == 1868 && m < 9) || (y == 1868 && m == 9 && d < 8)){
			sprintf(ans,"pre-meiji");
		}else if(y < 1912 || (y == 1912 && m < 7) || (y == 1912 && m == 7 && d < 30)){
			sprintf(ans,"meiji %d %d %d",y - 1867,m,d);
		}else if(y < 1926 || (y == 1926 && m < 12) || (y == 1926 && m == 12 && d < 25)){
			sprintf(ans,"taisho %d %d %d",y - 1911,m,d);
		}else if(y < 1989 || (y == 1989 && m == 1 && d < 8)){
			sprintf(ans,"showa %d %d %d",y - 1925,m,d);
		}else{
			sprintf(ans,"heisei %d %d %d",y - 1988,m,d);
		}
		puts(ans);
	}
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N,M;
    cin >> N >> M;
    int A[N];
    int x;
    int a=0,W=0;
    string z;
    rep(i,N) A[i]=-1;
    rep(i,M) {
        cin >> x >> z;
        if(A[x-1]<=0){
            if(z=="AC") {
                a++;
                A[x-1]=A[x-1]*(-1);
                W+=(A[x-1]-1);
            }
            else A[x-1]--;
        }
    }
    cout << a << " " << W << endl;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define F first
#define S second
const int N = 1e5 + 87;
const int M = 2e5 + 87;
vector<int> g[N];
int a[N];
bool vis[N], ans[M];
pii e[M];
void dfs(int u)
{
    vis[u] = 1;
    for (int i : g[u]) {
        int v = e[i].F ^ e[i].S ^ u;
        if (!vis[v]) {
            dfs(v);
            if (a[v]) {
                a[v] ^= 1;
                a[u] ^= 1;
                ans[i] = 1;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pii> vp(n);
    for (auto & p : vp)
        cin >> p.F >> p.S;
    sort(begin(vp), end(vp));
    for (int i = 0; i < n; ++i)
        a[i] = vp[i].S ^ (i ? vp[i - 1]. S : 0);
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        ++r;
        l = lower_bound(vp.begin(), vp.end(), pii(l, -1)) - vp.begin();
        r = lower_bound(vp.begin(), vp.end(), pii(r, -1)) - vp.begin();
        if (l < r) {
            e[i] = {l, r};
            g[l].push_back(i);
            g[r].push_back(i);
        }
    }
    for (int i = n; i >= 0; --i) 
        if (!vis[i]) {
            dfs(i);
            if (i < n && a[i]) {
                cout << "-1\n";
                return 0;
            }
        }
    int k = accumulate(ans, ans + m, 0);
    cout << k << '\n';
    for (int i = 0; i < m; ++i)
        if (ans[i])
            cout << i + 1 << " \n"[--k == 0];
}


Measured memory_bytes: 14592
#include <iostream>
using namespace std;
void drawBorder(int w,int h);
int main(int argc, const char * argv[]) {
    int w,h;
    while (1) {
        cin >> w >> h;
        if (w==0&&h==0) {
            break;
        }
        drawBorder(w, h);
    }
    return 0;
}
void drawBorder(int w ,int h){
    for (int i=1; i<=w; i++) {
        for (int j=1; j<=h; j++) {
            if ((i+j)%2==0) {  //i+jの偶数奇数
                cout <<'#';
            }else{
                cout <<'.';
            }
        }
        cout<<endl; //改行
    }
    cout<<endl; //改行
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
    using namespace std;
     
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

    /* REPmacro */
    #define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
    #define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
    #define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
     
    /*alias*/
    #define ALL(x) (x).begin(),(x).end()
    #define SZ(x) ((int)(x).size())
    #define F first
    #define S second
    #define PB push_back
    #define EB emplace_back
    #define MP make_pair 
     
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define next asdnext
    #define prev asdprev
    #define itn int
     
    /*using*/
    using ll = long long;
    using ull = unsigned long long;
    using unsi = unsigned;
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using pii = pair<int, int>;
    using db = double;
    using plex = complex<double>;
    using vs = vector<string>;
     
    /*template*/
    template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
     
    /*struct*/
    struct aaa{
        aaa(){
            cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
        };
    }aaaaaaa;
     
    /* const */
    const int INF = 1001001001;
    const ll LINF = 1001001001001001001ll;
    const int MOD = 1e9 + 7; //10^9
    const db EPS = 1e-9;
    const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };  //Counterclockwise from the 9o'clock direction
    //Take the x-axis downward and the y-axis right
     
    //#define int ll
    //#define int long long
     
    //water,sugar,disslove,capacity
    int a,b,c,d,e,f;
     
    signed main()
    {
	cin >>a>>b>>c>>d>>e>>f;
 
 
	double con = 0.0;
	int water = 0,sugar = 0;
	for(int w = 0; w <=30; w++){
	for(int x = 0; x <= 30; x++){
	for(int y = 0; y <= ceil((double)f/c); y++){
	for(int z = 0; z <= ceil((double)f/d); z++){
      
		int water_weight = a*w+b*x, sugar_weight = c*y+d*z;
		int total = 100*water_weight + sugar_weight;
      
		if(total <= f && sugar_weight <= water_weight*e){
		  if(con < (double)sugar_weight/total){
            
			con = (double)sugar_weight/total;
			water = 100*water_weight;
			sugar = sugar_weight;
		  }
		}
	 }
	 }
	 }
	 }
      
 	  if(con == 0) water = 100*a;
 
	  cout << water+sugar << " " << sugar << endl;
      return 0;
    }

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, v1, v2;
  cin >> n;
  map<int, int> hist1;
  map<int, int> hist2;
  for(int i = 0; i < n / 2; ++i)
  {
    cin >> v1 >> v2;
    hist1[v1]++;
    hist2[v2]++;
  }

  vector<P> h1{ P(0, -1) };
  vector<P> h2{ P(0, -1) };
  for(const auto& h : hist1)
  {
    h1.emplace_back(P(h.second,  h.first));
  }
  for(const auto& h : hist2)
  {
    h2.emplace_back(P(h.second,  h.first));
  }
  sort(h1.rbegin(), h1.rend());
  sort(h2.rbegin(), h2.rend());

  ll ans = 0;
  int i1 = 0, i2 = 0;
  if (h1[0].second == h2[0].second)
  {
    if (h1[0].first == h2[0].first)
    {
      h1[1] > h2[1] ? i1++ : i2++;
    }
    else
    {
      h1[0] < h2[0] ? i1++ : i2++;
    }
  }
  ans = n - h1[i1].first - h2[i2].first;
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 8852