akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ResistorsInParallel | diff ResistorsInParallel.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ResistorsInParallel.cpp && ./a.out

/*
 
 8/18/2019
 
 21:02-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  double B;
  REP(i,N) B+=1.0/A[i];
  cout<<(1.0/B)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static int M = 1046527; 
	static int L = 14;
	static char[][] H = new char[M][L];
	
	static int getChar(char ch) {
		if (ch == 'A') return 1;
		else if (ch == 'C') return 2;
		else if (ch == 'G') return 3;
		else if (ch == 'T') return 4;
		else return 0;
	}
	
	static long getKey(char[] str) {
		long sum=0, p=1;
		for (int i=0; i< str.length; i++) {
			sum += p*(getChar(str[i]));
			p *= 5;
		}
		return sum;
	}
	
	static int h1(int key) {
		return key % M;
	}
	static int h2(int key) {
		return 1 + (key % (M-1));
	}
	
	static int insert(char str[]) {
		int key, h;
		key = (int)getKey(str);
		for (int i=0; ; i++) {
			h = (h1(key) + i*h2(key)) % M;
			if (new String(H[h]).equals(new String(str))) return 1;
			else if (H[h][0] == 0) {
				H[h] = str;
				return 0;
			}
		}
	}
	
	static int find(char[] str) {
		int key, h;
		key = (int)getKey(str);
		for (int i=0; ; i++) {
			h = (h1(key) + i*h2(key)) % M;
			if (new String(H[h]).equals(new String(str))) return 1;
			else if (H[h][0] == 0) return 0;
		}
	}
	
	public static void main(String[] args) {
		int i, n;
		char[] str = new char[L];
		char[] com = new char[9];
		
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for (i=0; i<n; i++) {
			com = sc.next().toCharArray();
			str = sc.next().toCharArray();
			
			if (com[0] == 'i') {
				insert(str);
			} else {
				if (find(str)==1) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
		sc.close();
	}
}



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

int arr[100100];

main()
{
	int n,t;
	scanf("%d %d",&n,&t);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	int spot=0;
	int st=arr[0],most=0;
	for(int i=1;i<n-1;i++)
	{
		if(arr[i]>=arr[i+1])
		{
			int ben=arr[i]-st;
			if(ben>0&&ben>most)
			{
				most=ben;
				spot=1;
			}
			else if(ben>0&&ben==most)spot++;
		}
		st=min(st,arr[i]);
	}
	int ben=arr[n-1]-st;
	if(ben>0&&ben>most)
	{
		most=ben;
		spot=1;
	}
	else if(ben>0&&ben==most)spot++;
	printf("%d",spot);
}

Measured memory_bytes: 640
import math

n=int(input())
t=int(input())
mint=t
t1=int(input())
if t1<t: mint=t1
maxtt=t1-t


for i in range(2,n):
    t=int(input())
 
    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=t
    
print(int(maxtt)) 


Measured memory_bytes: 5668
def main():
    s = input()
    t = input()
    if t in s:
        print(s.replace('?', 'a'))
        return
    s = "".join(reversed(list(s)))
    t = "".join(reversed(list(t)))
    anses = []

    for i in range(len(s)):
        for j in range(len(t)):
            if i+j < len(s) and (s[i+j] == t[j] or s[i+j] == '?'):
                continue
            else:
                break
        else:
            # 合っていた
            ans = (s[:i]+t+s[i+len(t):]).replace('?', 'a')
            anses.append("".join(reversed(list(ans))))
            continue
    anses.sort()
    print(anses[0] if anses else "UNRESTORABLE")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

int main()
{
	string s;
	ll ans=0;
	cin>>s;
	sort(s.begin(),s.end());
	if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
<?php

$dict = array(
	'I' => 1,
	'V' => 5,
	'X' => 10,
	'L' => 50,
	'C' => 100,
	'D' => 500,
	'M' => 1000,
);

while ($line = trim(fgets(STDIN))) {
	$sum = 0;
	$len = strlen($line);
	for ($i = 0; $i < $len; $i++) {
		$now = $line[$i];
		if ($i < $len - 1) {
			$next = $line[$i + 1];
			if ($dict[$now] < $dict[$next]) {
				$sum -= $dict[$now];
			} else {
				$sum += $dict[$now];
			}
		} else {
			$sum += $dict[$now];
		}
	}
	echo "$sum\n";
}

Measured memory_bytes: 6596
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.exceptions(cin.failbit)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const int mod=1000000007;
const int inf=1e9+100;
const int N=315;
ld dp[N+1][N+1][N+1];
int a[4];

int main()
{
	boost;
	ld n;
	cin>>n;
	
	for(int k=0;k<=n;k++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int i=0;i<=n;i++)
			{
				if(i or j or k) dp[i][j][k]=(n/(ld(i+j+k)))+((k>0)?(dp[i][j+1][k-1]*k)/(ld(i+j+k)):0.0)+((j>0)?(dp[i+1][j-1][k]*j)/(ld(i+j+k)):0.0)+((i>0)?(dp[i-1][j][k]*i)/(ld(i+j+k)):0.00);
				//cout<<i<<" "<<j<<" "<<k<<" : "<<fixed<<setprecision(15)<<dp[i][j][k]<<endl;
				//check((n/(ld(i+j+k))));
			}
		}
	}
	int cn=int(n);
	while(cn--)
	{
		int t;
		cin>>t;
		a[t]++;
	}
	cout<<fixed<<setprecision(15)<<dp[a[1]][a[2]][a[3]];


	return 0;
}

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

class Union_Find {
private:
    std::vector<int> par;
    std::vector<int> rank;

public:
    Union_Find(int n) { // ?????????: O(n)
	par = rank = std::vector<int>(n);
	for(int i=0; i<n; i++) {
	    par[i]  = i;
	    rank[0] = 0;
	}
    }

    int root(int x) { // ??¨??????????±???????: O(?±(n)) 
	if(par[x] == x) return x;
	return par[x] = root(par[x]); // ??????????????????????????????????????????
    }

    void unite(int x, int y) { // x,y????????????????????????: O(?±(n)) 
	x = root(x); y = root(y);
	if( x == y ) return;

	if( rank[x] < rank[y] ) par[x] = y;
	else {
	    par[y] = x;
	    if( rank[x] == rank[y] ) rank[x]++;
	}
    }

    bool same(int x, int y) { //x,y??????????????????????????????????????????: O(?±(n)) 
	return root(x) == root(y);
    }
};

int main() {

    int n,q;
    std::cin >> n >> q;

    Union_Find uf(n);
    for(int i=0; i<q; i++) {

	int c,x,y;
	std::cin >> c >> x >> y;

	if(c==0)
	    uf.unite(x,y);
	else
	    std::cout << uf.same(x,y) << std::endl;
    }

}

    

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

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

using namespace std;

int main(){
	int a,b; cin>>a>>b;
	if(a+b<10) cout<<a+b<<endl;
	else cout<<"error"<<endl;

	return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split(' ');
            var N = r[0].ToInt();
            var M = r[1].ToInt();
            var max = Math.Pow(10, N).ToInt();
            var min = Math.Pow(10, N - 1).ToInt();
            if (min == 1) min = 0;
            var l = new Dictionary<int, int>();
            var ans = 0;
            for (int i = 0; i < M; i++)
            {
                var sc = Console.ReadLine().Split(' ');
                var s = sc[0].ToInt();
                var c = sc[1].ToInt();
                if (l.ContainsKey(s))
                {
                    if (l[s] == c)
                    {
                        continue;
                    }
                    else
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
                l.Add(s, c);
                ans += Math.Pow(10, N - s).ToInt() * c;
                if (s == 1 && ans < min)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            if (ans >= max)
            {
                Console.WriteLine(-1);
                return;
            }
            if (ans < min)
            {
                ans += min;
            }
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }

    public static class Extensions
    {
        public static int ToInt(this object str)
        {
            return int.Parse(str.ToString());
        }

        public static decimal ToDecimal(this object str)
        {
            return decimal.Parse(str.ToString());
        }
    }
}


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

int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;  
  int n = S.size();
  if (n == 1)
  {
    cout << K/2 << endl;
  }

  else if (n%2 == 1 && S.find_first_not_of(S[0]) == -1)
  {
    cout << K*n/2 << endl;
  }
  
  
  else  
  {
    ll Count1 = 0;
    ll Count2 = 0;

    rep(i,n-1) if(S[i] == S[i+1]){
      Count1++;
      i++;
    }

    string T = S + S;
    rep(i,2*n-1) if(T[i] == T[i+1]){
      Count2++;
      i++;
    }

    ll edge = (Count2-Count1*2);

    cout << edge*(K-1) + Count1*K << endl;
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,cnt=0,flag=0;
    double sum=0;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    double chk=sum*((double)1/(4*m));
    for(int i=0;i<n;i++){
        if(a[i]>=chk){
            cnt++;
            if(cnt==m){
                flag=1;
                break;}
        }
    }
    //cout<<chk;
    if(flag)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


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

int main(){
  int D;
  cin>>D;
  int C[26];
  map<int,int>mp;
  for(int i=0;i<26;i++){
    cin>>C[i];
    if(C[i]<10){
      mp[i]++;
    }   
  }
  int S[365][26];
  for(int i=0;i<365;i++){
    for(int j=0;j<26;j++){
      cin>>S[i][j];
    }
  }
  
  int flag=1;
  int temp=0;
  int now=0;
  int maxans=0;
  while(temp<365){
    maxans=0;
    now=0;
    for(int i=0;i<26;i++){
      if(S[temp][i]>maxans){
        now=i;
        maxans=S[temp][i];
      }
    }    
    
    if(mp[temp%26]==0){
      cout<<temp%26+1<<endl;
      temp++;
      continue;
    }

    cout<<now+1<<endl;
    temp++;
  }
  return 0;
}



Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<sstream>
using namespace std;

int main()
{
	string str;
	while (cin >> str) {
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '@') {
				int len = str[i + 1] - '0';
				//cout << "len" << len << endl;
				char c = str[i + 2];
				for (int j = 0; j < len; j++) {
					cout << c;
				}
				i += 2;
			}
			else {
				cout << str[i];
			}
			
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>
int main(){
  int x,y;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0&&y==0)break;
    if(x<y)printf("%d %d\n",x,y);
    else printf("%d %d\n",y,x);
  }
  return 0;
}

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

#define DEBUG 0
 


int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int counter = 0;

    while(A >= B){
        B = B * 2;
        counter++;
    }

    while(B >= C){
        C = C * 2;
        counter++;
    }

    if(counter > K){
        cout << "No";
    }else{
        cout << "Yes";
    }




    return 0;

 
}



Measured memory_bytes: 3592
#define NDEBUG
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define lb(x) ((x)&(-(x)))
#define dalao 998244353
#define _dalao 1000000007
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
typedef long long ll;
int n,a[N];
ll l,r;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	l=r=2;
	for(int i=n;i;i--){
		ll mi=(l+a[i]-1)/a[i],mx=r/a[i];
		l=mi*a[i],r=(mx+1)*a[i]-1;
		if(l>r)return puts("-1"),0;
	}
	cout<<l<<" "<<r;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#define MIN(x,y) (((x)<(y))?(x):(y))

int main(void){
  int N,i,min=0,max=0;
  int a[101],color[10]={};
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<N;i++){
    if(1 <= a[i] && a[i] <= 399){
      color[0]++;
    }else if(400 <= a[i] && a[i] <= 799){
      color[1]++;
    }else if(800 <= a[i] && a[i] <= 1199){
      color[2]++;
    }else if(1200 <= a[i] && a[i] <= 1599){
      color[3]++;
    }else if(1600 <= a[i] && a[i] <= 1999){
      color[4]++;
    }else if(2000 <= a[i] && a[i] <= 2399){
      color[5]++;
    }else if(2400 <= a[i] && a[i] <= 2799){
      color[6]++;
    }else if(2800 <= a[i] && a[i] <= 3199){
      color[7]++;
    }else if(3200 <= a[i]){
      color[8]++;
    }
  }
  for(i=0;i<8;i++){
    if(color[i]) min++;
  }
  max = min + color[8];
  if(min == 0) min++;
  printf("%d %d\n",min,max);
  return 0;


}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



 
int main() {
    int n, x;
    cin >> n >> x;
    vector<vector<int>> p(n, vector<int>(3));
    for (int i = 0; i < n; i++) {
        int s, t, c;
        cin >> s >> t >> c;
        p.at(i) = vector<int>{s, t, c};
    }
    sort(begin(p), end(p));
    vector<pair<int, int>> r(30);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 30; j++) {
            if (p.at(i).at(0) > r.at(j).second || p.at(i).at(2) == r.at(j).first) {
                r.at(j) = make_pair(p.at(i).at(2), p.at(i).at(1));
                chmax(ans, j + 1);
                break;
            } 
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;

  if (n % 2 == 0) {
    cout << n / 2 << endl;
  } else {
    cout << (n + 1) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <numeric>
#include <iterator>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    ll k, n, m;
    set<ll> a, b;
    set<ll> result;

    cin >> n;
    rep(i, n) {
        cin >> k;
        a.insert(k);
    }

    cin >> m;
    rep(i, m) {
        cin >> k;
        b.insert(k);
    }

    set_intersection(a.begin(), a.end(),
        b.begin(), b.end(),
        inserter(result, result.end()));

    for_each(result.begin(), result.end(), [](ll x) {
        cout << x << endl;
        });

}


Measured memory_bytes: 23788
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    int k;
    cin >> k;
    ll sum=0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
                sum+=__gcd(a,__gcd(b,c));
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
from collections import deque
import sys

def main():
    y = deque()
    input()
    for order in sys.stdin:
        if order[0] == "i":
            y.appendleft(order[7:-1])
        elif order[6] == " ":
            try:
                y.remove(order[7:-1])
            except:
                pass
        elif order[6] == "F":
            y.popleft()
        else:
            y.pop()
    print(" ".join(y))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 69732
#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
class Node{
public:
    int x=0,y=0,step=0;
    Node(){};
    Node(int x,int y,int step):x(x),y(y),step(step){};
};
queue<Node> q;
char Map[55][55];
int map[55][55]={0};
int dit[4][2]={0,1,0,-1,1,0,-1,0};
int main()
{
    int h,m,nw=0;
    cin>>h>>m;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>Map[i][j];
            if(Map[i][j]=='.') nw++;
        }
    }
    q.push(Node(1,1,0));
    int f=0;
    while(!q.empty())
    {
        Node N = q.front();
        q.pop();
        if(N.x==h&&N.y==m)
        {
            f=N.step;
            break;
        }
        for(int i=0;i<4;i++)
        {
            int x=N.x+dit[i][0];
            int y=N.y+dit[i][1];
            if(x>=1&&x<=h&&y>=1&&y<=m&&Map[x][y]=='.'&&map[x][y]==0)
            {
                q.push(Node(x,y,N.step+1));
                map[x][y]=1;
            }

        }
    }
    if(f!=0) cout<<nw-f-1<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int arr[] = new int[n + 1];
		
		for (int i = 1; i <= n; i++) {
			arr[i] = sc.nextInt();
		}
		
		int sum = 0;
		
		for (int i = 1; i <= n; i++) {
			if (arr[i] != i) {
				if (arr[arr[i]] == i) {
					sum++;
				}
			}
		}
		
		System.out.println(sum / 2);
	}
}

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

data = list(map(int,input().split()))

d = dict()

for x in data:
    if d.__contains__(x):
        d[x]+=1
    else:
        d[x]=1
         
    if d.__contains__(x-1):
        d[x-1]+=1
    else:
        d[x-1]=1
    if d.__contains__(x+1):
        d[x+1]+=1
    else:
        d[x+1]=1
res = 0
for v in d.values():
    res = max(res,v)
print(res)


Measured memory_bytes: 18756
def getinputdata():

    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

s = "".join(arr_data[0])

if s.find("N")>=0 and s.find("S")>=0 and s.find("E")>=0 and s.find("W")>=0:
    
    print("Yes")
    
elif s.find("N")>=0 and s.find("S")>=0 and s.find("E")==-1 and s.find("W")==-1:
    
    print("Yes")
    
elif s.find("E")>=0 and s.find("W")>=0 and s.find("N")==-1 and s.find("S")==-1:
    
    print("Yes")
    
else:
    
    print("No")



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

int main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    
    ll s,w;
    cin>>s>>w;
    if(s>w)
        cout<<"safe"<<endl;
    else
        cout<<"unsafe"<<endl;
}

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

int main(){
  int A,B,Q;
  cin>>A>>B>>Q;
  vector<ll> s(A+1),t(B+1),x(Q);
  s[0] = t[0] = -1e18;
  for(int i=1;i<=A;i++) cin>>s[i];
  for(int i=1;i<=B;i++) cin>>t[i];
  for(int i=0;i<Q;i++) cin>>x[i];
  s.push_back(1e18);
  t.push_back(1e18);
  for(int i=0;i<Q;i++){
    ll rs = *lower_bound(s.begin(),s.end(),x[i]);
    ll ls = *(lower_bound(s.begin(),s.end(),x[i]) - 1);
    ll rt = *lower_bound(t.begin(),t.end(),x[i]);
    ll lt = *(lower_bound(t.begin(),t.end(),x[i]) - 1);
    ll lsd = x[i] - ls;
    ll rsd = rs - x[i];
    ll ltd = x[i] - lt;
    ll rtd = rt - x[i];
    ll ans = max(lsd, ltd);
    ll ans2 = max(rsd, rtd);
    ll ans3 = lsd + rtd + min(lsd, rtd);
    ll ans4 = ltd + rsd + min(ltd, rsd);
    ans = min(ans, ans2);
    ans = min(ans, ans3);
    ans = min(ans, ans4);
    cout<<ans<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3680
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int a[100010];
signed main() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n)cin >> a[i];
	loop(i,1,n) {
		if (a[i] > a[i - 1])ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3900
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var q = Search(n);
            Console.WriteLine(q + n / q - 2);
        }

        private static long Search(long n)
        {
            for (long i = (long)Math.Sqrt(n); i > 1; i--)
            {
                if (n % i == 0) return i;
            }
            return 1;
        }
    }
}


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

int main() {
    int n;
    cin >> n;

    int h = n / 3600;
    int m = (n % 3600) / 60;
    int s = (n % 3600 % 60);

    cout << h << ':' << m << ':' << s << '\n';

    return 0;
}


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

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

int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);///Beware of use it, if u use it dont use scanf or printf
    int r;
    cin>>r;
    cout<<r*r<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
	int n,k;
	char s[15];
	scanf("%d",&n);
	scanf("%s",s);
	scanf("%d",&k);
	for(int i=0;i<strlen(s);i++){
		if(s[i]!=s[k-1]){
			s[i]='*';
		}
	}
	printf("%s",s);
	return 0;
}

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

int main()
{
	char cn[16];
	int a, b;
	
	for (int i = 0; i < 9; i++) {
		cin >> cn >> a >> b;
		cout << cn << " " << a + b << " " << 200 * a + 300 * b << endl;
	}

	return 0;
}



Measured memory_bytes: 3072
using System;

class Program
{
    static void Main()
    {
        // variables
        int x = int.Parse(Console.ReadLine());
        int i = 1;

        while (x != 0)
        {
            // Output
            Console.WriteLine("Case {0}: {1}", i, x);
            // Input
            x = int.Parse(Console.ReadLine());
            i++;
        }
    }
}

Measured memory_bytes: 9208
from collections import defaultdict
MOD = 10**9 + 7
n = int(input())
s = input()

d = defaultdict(int)
for i in range(n):
    d[s[i]] += 1

ans = 1
for c in d:
    ans *= d[c] + 1
    ans %= MOD
ans -= 1
print(ans)


Measured memory_bytes: 3444
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    cal = 0
    for j in range(m):
        cal += a[i][j]*b[j]
    cal += c
    if cal > 0:
        ans += 1

print(ans)

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

int main() {

	int n; cin >> n;
	const int f = 380000;
	double  ans = 0;
	for (int i = 0; i < n; i++) {
		double x; string s; cin >> x >> s;
		if (s == "JPY") {
			ans+=x;
		}
		else {
			ans+=x*f;
		}
	}
	cout << fixed << setprecision(11) << ans << endl;
	return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define ml cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
//ll ans;

// ll dfs(vi v ,ll m ){
//   if(visited[]) 
// }
int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);    
    // ll a,b,c,d;
    // cin>>a>>b>>c>>d;
    
    // // while(a!=0 && c!=0){
    // //     c-=b;
    // //     a-=d;
    // // }
    // ll ans = a/d + (a%d==0)? 0: 1 ;
    // ll  p = c/b + (c%b==0)? 0: 1 ;
    // if(ans<=p){
    //     yes;
    // }else{
    //     no;
    // }

    ll n;cin>>n;
    set<string> s;
    string str;
    while(n--){
        cin>>str;
        s.insert(str);
    }
    cout<<s.size();
	return 0;
}






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

struct Edge {
  int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;

// v: ノード, p: 親, u: 子
void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  for (auto e : g[v]) {
    int u = e.to;
    int ei = e.id;
    if (u == p) continue;  // 親はみない
    if (k == c) k++;
    ans[ei] = k;
    k++;
    dfs(u, ans[ei], v);
  }
}

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

  int n;
  cin >> n;
  g.resize(n);
  ans = vector<int>(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;

    g[a].push_back((Edge){b, i});
    g[b].push_back((Edge){a, i});
  }

  dfs(0);

  int k = 0;
  for (int i = 0; i < n; i++) {
    k = max(k, int(g[i].size()));
  }
  cout << k << endl;

  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define ms(a,b)         memset(a, b, sizeof(a))
#define pb(a)           push_back(a)
#define db              double
#define ll              long long
#define loop(i,e,n)      for(int i=e;i<=n;i++)
#define TEST_CASE(t)    for(int z=1;z<=t;z++)
ll PowFun(ll base, ll power){ll ans = 1;for(int i = 1; i <= power; i++){ans *= base;}return ans;}
double phi = acos(-1);
using namespace std;

    void solve()
    {
        ll n; cin>>n;
        ll arr[n+5] = {};
        for(ll i = 1; i <= n; i++)
        {
            for(ll j = i; j <= n; j += i)
            {
                arr[j]++;
            }
        }
        ll sum = 0;
        for(ll i = 1; i <= n; i++)
        {
            sum += arr[i]*i;
        }
        cout<<sum<<endl;
    }

    int main()
    {
        solve();
    }



Measured memory_bytes: 81748
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end()
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int n; CI n;
	VI L(n); CI L;

	sort(all(L));
	int tmp = 0;
	REP(i, n - 1) {
		tmp += L[i];
	}
	if (tmp > L[n - 1])CO "Yes" EN;
	else CO "No" EN;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.array;


string solve(int n, char[] ans = []) {
    int s = 0;
    while (n || s) {
        n += s; s = 0;
        int x = n % 100;
        int l = (x % 10 ? 10 - x % 10 : 0);
        int u = x / 10 + (l == 0 ? 0 : 1);
        while (u >= 10) {
            s++;
            u -= 10;
        }
        ans ~= l + '0';
        ans ~= u + '0';
        n /= 100;
    }
    return cast(string)ans.reverse;
}

string solvePlus(int n) {
    return solve(n / 10, [n % 10 + '0']);
}

string solveMinus(int n) {
    return solve(-n);
}

void main() {
    int n;
    while (readf("%d\n", &n), n) {
        if (n >= 0) {
            solvePlus(n).writeln;
        } else {
            solveMinus(n).writeln;
        }
    }
}

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

using namespace std;

using int64 = long long;

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

  int latte = 0, malta = S.size() - 1;
  int ret = 0;
  while(latte < malta) {
    if(S[latte] != S[malta]) {
      if(S[latte] == 'x') {
        ++ret;
        ++latte;
      } else if(S[malta] == 'x') {
        ++ret;
        --malta;
      } else {
        cout << -1 << endl;
        return (0);
      }
    } else {
      ++latte;
      --malta;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 512
import java.io.*;

class Main
{
	public static void main(String args[])
	{
		try
		{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			int x = Integer.parseInt(br.readLine());

			x *= x*x;

			System.out.println(x);

		}
		catch(Exception e)
		{
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 17016
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXM = 4e2 + 5;
const int MAXN = 26 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;

int n=26, m;
int c[MAXN];
int a[MAXM][MAXN];

int p[MAXM];

ll solve(void)
{
	static int lst[MAXN];
	memset(lst,0,sizeof(lst));
	
	ll ans = 0;
	for(int k=1; k<=m; ++k)
	{
		ans += a[k][ p[k] ];
		for(int i=1; i<=n; ++i) if(i != p[k])
			ans -= c[i] * (k-lst[i]);
		lst[ p[k] ] = k;
	}
	return ans;
}

int main(void)
{
	scanf("%d",&m);
	for(int i=1; i<=n; ++i) scanf("%d",&c[i]);
	for(int i=1; i<=m; ++i)
		for(int j=1; j<=n; ++j)
			scanf("%d",&a[i][j]);
	
	static int lst[MAXM];
	
	ll ans = 0;
	for(int k=1; k<=m; ++k)
	{
		ll mx = -linf;
		int mxi = -1;
		for(int i=1; i<=n; ++i)
		{
			ll res = a[k][i];
			for(int j=1; j<=n; ++j) if(j!=i)
				res -= c[j] * (k-lst[j]);
			
			if(mxi==-1 || mx < res)
				mxi = i, mx = res;
		}
		lst[mxi] = k;
		
		ans += mx;
		p[k] = mxi;
	}
	
	int T = 1e4;
	while(T--)
	{
		int pos = rand()%m + 1;
		int x = rand()%n + 1;
		
		int old = p[pos];
		p[pos] = x;
		if(solve() < ans) p[pos] = old;
	}
	
	for(int i=1; i<=m; ++i)
		printf("%d\n",p[i]);
	return 0;
}

Measured memory_bytes: 1784
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      // スペース区切りの整数の入力
      int N = sc.nextInt();


        boolean Flg_99=false;
        for (int i=1;i<10;i++){
          for (int s=1;s<10;s++){
            if (N==i*s){
              Flg_99=true;
            }
          }
        }
      
      if (Flg_99){       
        System.out.println("Yes");
      }else{
        System.out.println("No");      
      }
   }
}



Measured memory_bytes: 21972
#include<stdio.h>
main ()
{
  unsigned long long n, i,j,sum1=0,sum2=0,temp;
  scanf("%llu", &n);
  unsigned long long x[n];
  for (i = 0; i < n; i++) scanf ("%llu", &x[i]);
  for(i=0;i<n-1;i++){
      for(j=0;j<n-1;j++){
          if(x[j]<x[j+1])
          {
              temp=x[j];
              x[j]=x[j+1];
              x[j+1]=temp;
          }
      }
  }
  for(i=0;i<n;i+=2)sum1+=x[i];
  for(i=1;i<n;i+=2)sum2+=x[i];
  printf("%llu\n",sum1-sum2);
  return 0;
}


Measured memory_bytes: 1696
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
long long int comb(long long int n,long long int r){
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
    long long int i,j;
    rep(i,0,n+1){
        v.at(i).at(0)=1;
        v.at(i).at(i)=1;
    }
    rep(i,0,n+1){
        rep(j,0,i)v.at(i).at(j)=v.at(i-1).at(j-1)+v.at(i-1).at(j);
    }
    return v.at(n).at(r);
}
int main(void){
    int N,i,j,M=0;
    cin>>N;
    vector<string> data(N);
    vector<int> dat(N,1);
    rep(i,0,N)cin>>data.at(i);
    sort(all(data));
    rep(i,0,N){
        rep(j,i+1,N){
            if(dat.at(i)==0)break;
            if(data.at(i)==data.at(j)){
                dat.at(i)++;
                dat.at(j)--;
            }else break;
        }
    }
    rep(i,0,N)M=max(M,dat.at(i));
    rep(i,0,N)if(dat.at(i)==M)cout<<data.at(i)<<endl;
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long ans,q;
	cin>>q;
	long long s=sqrt(q);
	for(int i=s;i>=1;i--)
	{
		if(q%i==0)
		{
			ans=q/i;
			break;
		}
	}
	int sum=0;
	while(ans)
	{
		ans/=10;
		sum++;
	 } 
	 cout<<sum<<endl;
	return 0;
}

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

signed main(){
	int a, b, c;
	scanf("%lld%lld%lld", &a, &b, &c);
	if(c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

const int M=256;

double calc(int S,int A,int C,int* I,int N)
{
	int R[N]; R[0]=S;
	repi(i,1,N+1)
		R[i]=(A*R[i-1]+C)%M;
	int hist[256]={};
	repi(i,1,N+1)
		hist[(I[i]+R[i])%M]++;
	double res=0;
	rep(i,256) if(hist[i])
		res+=-1.*hist[i]/N*log(1.*hist[i]/N);
	return res;
}

int main()
{
	for(int N;cin>>N,N;){
		int I[N+1];
		rep(i,N) cin>>I[i+1];
		
		double mn=1e100;
		int S0,A0,C0;
		rep(S,16) rep(A,16) rep(C,16){
			double tmp=calc(S,A,C,I,N);
			if(mn-EPS>tmp)
				S0=S,A0=A,C0=C,mn=tmp;
		}
		
		cout<<S0<<' '<<A0<<' '<<C0<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<map>

using namespace std;


int main(){
    char s[5];
    map<char, int> m;
    for(int i=0;i<4;i++){
        cin >> s[i];
    }
    for(int i=0;i<4;i++){
        m[s[i]]++;
    }
    bool ans=true;
    for(int i=0;i<4;i++){
        if(m[s[i]]!=2){
            ans=false;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stack>

using namespace std;

struct da{ int x,y; };

int main() {
	int x,y,i,j,c,f1,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
	char d[101][101],g[2]={'.','#'};
	da a,b;
	stack<da> st[2];
 while(cin >> x >> y) {
	 if (x==0) break;
     for (i=0;i<y;i++) cin >> d[i];
	 c=0; f1=0;
	 for (i=0;i<y;i++) for (j=0;j<x;j++) if (d[i][j]=='&') {a.x=j; a.y=i; st[0].push(a);}
	 while(f1==0) {
	 while(!st[c % 2].empty()) {
		 a=st[c % 2].top(); st[c % 2].pop();
		 if (a.x==0 || a.x==x-1 || a.y==0 || a.y==y-1) { f1=1; continue;}
		 for (i=0;i<4;i++) {
			 b.x=a.x+dx[i]; b.y=a.y+dy[i];
			 if (d[b.y][b.x]==g[c % 2]) { st[c % 2].push(b); d[b.y][a.x]='&';}
			 if (d[b.y][b.x]==g[(c+1) % 2]) { st[(c+1) % 2].push(b); d[b.y][a.x]='&';}
		 }
	 }
	 c++;
	 }
	 while(!st[c % 2].empty()) st[c % 2].pop();
	 cout << c/2 << endl;
 }
 return 0;
 }

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

int main() {
	int n, qe;
	cin>>n>>qe;
	vector<vector<int>> a(n);
	for (int i = 0; i < n-1; i++) {
		int s, e;
		cin>>s>>e;
		a[s-1].push_back(e-1);
		a[e-1].push_back(s-1);
	}
	vector<long long int> c(n);
	for (int i = 0; i < qe; i++) {
		int ve, va;
		cin>>ve>>va;
		c[ve-1] += va;
	}
	vector<long long int> an(n);
	queue<pair<int, long long int>> q;
	vector<int> v(n, 0);
	q.push({0, c[0]});
	v[0] = 1;
	while (!q.empty()) {
		pair<int, long long int> pa = q.front();
		q.pop();
		int x = pa.first;
		long long int y = pa.second;
		an[x] = y;
		for (int i = 0; i < a[x].size(); i++) {
			if (v[a[x][i]] == 0) {
				v[a[x][i]] = 1;
				q.push({a[x][i], c[a[x][i]] + y});
			}
		}
	}
	for (long long int i : an) cout<<i<<" ";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 21108
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
ans = 0
for i in a[:-1]:
    x -= i
    if x >= 0:
        ans += 1
    else:
        break
if a[-1] == x:
    ans += 1
print(ans)

Measured memory_bytes: 3060
// author: Wenxing Mei
//   date: 2018-06-11 16:52
//     ac: 2018-06-11 16:52
#include <bits/stdc++.h>
using namespace std;

// 如果dp[1] ~ dp[n-1]都知道了，你会怎么解决这个问题??
// 考虑最后选择的是k，那么就转化成 dp[n-k] + 1
// 因此只要知道前面的答案，就可以通过尝试每一种硬币来得到当前的答案

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);

    vector<int> dp(n + 1, 0);

    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1] + 1;
        for (int j = 6; j <= i; j *= 6) dp[i] = min(dp[i], dp[i - j] + 1);
        for (int j = 9; j <= i; j *= 9) dp[i] = min(dp[i], dp[i - j] + 1);
    }

    printf("%d\n", dp[n]);
    return 0;
}

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

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{

  double n, x;
  cin >>  n >> x;

  vector<long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  //x 以下
  //まず、a[i]>xならその差分は必ず-する

  // 5
  // 8 3 5 2 4 4 4
  // 5 3 5 2 4 4 4
  // 8 8 7 6 8 8
  // 3 3 2 1 3 3
  // a + 2b + 2c + 2d + 2e + 2f + 2g + h = -15
  //

  //貪欲法でとける
  long ans = 0;
  if (a[0] > x) {
    ans = a[0] - x;
    a[0] = x;
  }
  for (int i = 1; i < n; ++i) {
    if (a[i] + a[i - 1]  > x) {
      ans += (a[i] + a[i - 1] - x);
      a[i] =  a[i] - (a[i] + a[i - 1] - x);
    }
  }



  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    H, N = [int(x) for x in input().split()]
    AB = []
    for _ in range(N):
        a, b = [int(x) for x in input().split()]
        AB.append([a, b])

    dp = [0] * (H + 1)

    for i in range(1, H + 1):
        mi = float("inf")
        for a, b in AB:
            mi = min(mi, dp[max(i - a, 0)] + b)
        dp[i] = mi

    print(dp[H])



if __name__ == '__main__':
    main()


Measured memory_bytes: 42092
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	if n <= 999 {
		fmt.Printf("ABC\n") // output for debug
	} else {
		fmt.Printf("ABD\n") // output for debug
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int H  = keyboard.nextInt();
		int W  = keyboard.nextInt();
		
		String[]gazou = new String[2*H];
		
		for(int i = 0; i < H; i++) {
				gazou[2*i] = keyboard.next();
				gazou[2*i+1] = gazou[2*i];
		}
		
		for(int k = 0; k < 2*H; k++) {
				System.out.println(gazou[k]);
		}
		keyboard.close();	
	}
}


Measured memory_bytes: 23684