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

int main()
{
	using vd = std::vector<long double>;
	int N, M;
	std::vector<std::vector<int>> edges;
	scanf("%d%d", &N, &M);
	edges.resize(N);
	for (int i{}; i < M; i++)
	{
		int s, t;
		scanf("%d%d", &s, &t);
		s--; t--;
		edges[s].push_back(t);
	}
	vd E(N);
	for (int i{N - 2}; i >= 0; i--)
		for (auto& e: edges[i])
			E[i] += (E[e] + 1) / edges[i].size();
	long double ans{E[0]};
	for (int i{N - 2}; i >= 0; i--)
	{
		if (edges[i].size() == 1) continue;
		long double max{};
		for (auto& e: edges[i])
			max = std::max(max, E[e] + 1);
		vd ignoreE(N);
		for (int j{N - 2}; j >= 0; j--)
		{
			for (auto& e: edges[j])
				ignoreE[j] += ignoreE[e] + 1;
			if (j == i)
				ignoreE[j] -= max;
			int size{(int)edges[j].size()};
			if (j == i) size--;
			ignoreE[j] /= size;
		}
		ans = std::min(ans, ignoreE[0]);
	}
	printf("%.9Lf\n", ans);

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main() {

	int x, y;

	for (int i = 1;; i++) {

		cin >> x >> y;

		if (x == 0 && y == 0)break;

		if (x < y) {
			
			cout << x <<" "<< y << "\n";

		}
		else {
			cout << y <<" "<< x << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
int main(){
    int N, M;
    string A;
    scanf("%d %d", &N, &M);
    vector<string> a;
 
    while (N--){
        cin >> A;
        a.push_back(A);
    }
 
    sort(a.begin(), a.end());
 
    for (auto i : a)
        cout << i;
    cout << "\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=3e5;
const int mod=1e9+7;
using namespace std;

int main(){
	int n , m, a, b, c;
	cin>>n;
	int arr[n+1];

	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	sort(arr+1, arr+n+1);
	cout<<arr[n/2+1]-arr[n/2];

}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;
public class Main {
 public static void main(String[] args) throws Exception {
   Scanner file = new Scanner(System.in);
   int n = file.nextInt();
   HashMap<ArrayList<Character>, Integer> hm = new HashMap<>();
   long t = 0;
   for (int i = 0; i < n; i++) {
     String s = file.next();
     ArrayList<Character> a = new ArrayList<>();
     for (char c : s.toCharArray()) a.add(c);
     Collections.sort(a);
     if (!hm.containsKey(a)) hm.put(a, 0);
     t += hm.get(a);
     hm.put(a, hm.get(a) + 1);
   }
   System.out.println(t);
 }
}


Measured memory_bytes: 77808
# 入力処理
N = int(input())
X_list = [int(x) for x in input().split() ]
ans = 1000000
# P を 1から100まで全ケース試す。
for p in range(1,101):
  temp = 0
  for x in X_list:
    temp += (x-p)**2
  ans = min(ans, temp)

print(ans)

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var (
		n int
		s string
	)
	fmt.Scan(&n, &s)

	var ans string
	for i := 0; i < len(s); i++ {
		a := s[i] + byte(n)
		if a > 'Z' {
			a = a - 26
		}
		ans += string(a)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


int main(){
    ll x,y;
    cin>>x>>y;
    ll ans=0;
    if(x*y>=0&&y>=x)ans=y-x;
    else if(x*y>0&&y<=x)ans=x-y+2;
    else ans=abs(abs(x)-abs(y))+1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#define ll long long
using namespace std;

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

	double sum = 0.0;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		sum += 1.0 / (double)a;
	}
	
	std::cout << std::fixed;
	cout << std::setprecision(6) << 1.0 / sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d)<<endl;
}   



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

using namespace std;


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




namespace Vac
{
	//i日目に活動xを行った時の最大の幸福度をメモする
	int dp[3][100000];

	void solve()
	{
		int N; cin >> N;
		vector<int> A(N, 0), B(N, 0), C(N, 0);
		for (int i = 0; i < N; ++i) {
			int a, b, c; cin >> a >> b >> c;
			A[i] = a;
			B[i] = b;
			C[i] = c;
		}

		//i日目に活動xを行った時の最大の幸福度をメモする
		memset(dp, 0, sizeof(dp));
		const int a = 0, b = 1, c = 2;
		dp[a][0] = A[0];
		dp[b][0] = B[0];
		dp[c][0] = C[0];
		for (int i = 1; i < N; ++i) {
			dp[a][i] = A[i] + max(dp[b][i - 1], dp[c][i - 1]);
			dp[b][i] = B[i] + max(dp[a][i - 1], dp[c][i - 1]);
			dp[c][i] = C[i] + max(dp[a][i - 1], dp[b][i - 1]);
		}
		vector<int> happy(3);
		happy[a] = dp[a][N - 1];
		happy[b] = dp[b][N - 1];
		happy[c] = dp[c][N - 1];
		cout << max({dp[a][N-1], dp[b][N-1], dp[c][N-1]}) << endl;
	}
}

int main()
{
	Vac::solve();
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  int p=1000000007;
  vector<int64_t> f(s*2+1,1);
  for(int i=1;i<=s*2;i++)
    f.at(i)=f.at(i-1)*i%p;
  vector<int64_t> fi(s*2+1,1);
  int q=p-2;
  vector<bool> b;
  while(q>0){
    b.push_back(q%2==1);
    q/=2;
  }
  for(int i=(int)b.size()-1;i>=0;i--){
    fi.at(s*2)=fi.at(s*2)*fi.at(s*2)%p;
    if(b.at(i))
      fi.at(s*2)=fi.at(s*2)*f.at(s*2)%p;
  }
  for(int i=s*2;i>=1;i--)
    fi.at(i-1)=fi.at(i)*i%p;
  int64_t a=0;
  s-=3;
  for(int i=s,j=1;i>=0;i-=3,j++)
    a=(a+f.at(i+j-1)*fi.at(i)%p*fi.at(j-1))%p;
  cout<<a<<endl;
}

Measured memory_bytes: 3684
#include<stdio.h>

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);
    
    int i;
    for(i=M/N + 1;i>0;i--){
        if(M % i == 0){
            //printf("%d\n",M/i);
            if(M/i >= N){
                printf("%d",i);
                return 0;
            }
        }        
    }
}

Measured memory_bytes: 128
def main():
    N, M, *a = map(int, open(0).read().split())
    div = 1000000007
    broken = set(a)
 
    comb_list = [0] * (N + 1)
    comb_list[0] = 1
    if 1 not in broken:
        comb_list[1] = 1
 
    for i in range(2, N + 1):
        if i in broken:
            continue
        comb_list[i] = (comb_list[i - 1] + comb_list[i - 2]) % div
 
    print(comb_list[-1])
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
# include <bits/stdc++.h>
using namespace std;
# define eps 1e-8
# define INF 1e20
# define pi  acos(-1.0)
# define MX  100005
struct Node
{
    int x, s;
};

int k;
bool vis[MX];

int main()
{
    scanf("%d",&k);
    deque<Node> Q;
    Q.push_front((Node){1,0});
    while (!Q.empty())
    {
        Node tp = Q.front(); Q.pop_front();
        if (vis[tp.x]) continue;
        vis[tp.x]=1;
        if (tp.x==0)
        {
            printf("%d\n",tp.s+1);
            break;
        }
        Q.push_front((Node){(tp.x*10)%k,tp.s});
        Q.push_back((Node){(tp.x+1)%k,tp.s+1});
    }
    return 0;
}


Measured memory_bytes: 1152
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
V<int> h(n);
int ma=0;
int ans=0;
for(int i=0;i<n;i++){
    cin>>h[i];
    if(ma<=h[i])ans++;
    chmax(ma,h[i]);
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int A = Integer.parseInt(tokens[0]);
		int B = Integer.parseInt(tokens[1]);
		int C = Integer.parseInt(tokens[2]);
		int X = Integer.parseInt(tokens[3]);
		int Y = Integer.parseInt(tokens[4]);
		// 個別にそろえる方法とABを活用する方法双方を計算して，小さいほうを出力する
		int resultA = X * A + Y * B;
		int resultB = 0;
		if (X > Y) {
			// ABをY個買ってAをX-Y個買う
			resultB = (X - Y) * A + Y * C * 2;
		} else {
			resultB = X * C * 2 + (Y - X) * B;
		}
		int resultC = C * (Math.max(X, Y)) * 2;
		System.out.println(Math.min(Math.min(resultA, resultB), resultC));

		in.close();
	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

bool check(string s)
{
	string str = s;
	reverse(str.begin(), str.end());
	return str == s;
}

int32_t main()
{
	IOS;
	string s;
	cin >> s;
	int n = s.size();
	string s1 = s.substr(0, (n - 1) / 2);
	string s2 = s.substr((n + 3)/2 - 1);
	if(check(s) && check(s1) && check(s2))
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long int n,m;
  scanf("%lld%lld",&n,&m);
  long long int a[m],i,sum=0;
  for(i=0;i<m;i++){
    scanf("%lld",&a[i]);
    sum+=a[i];
  }
  if(sum>n){
    printf("-1");
    return 0;
  }
  printf("%lld",n-sum);
  return 0;
}

Measured memory_bytes: 1756
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 103;
int n, k, v[N], tmp[N], tot, ans, tt;
int main(){
	scanf("%d%d", &n, &k);
	for(Rint i = 1;i <= n;i ++) scanf("%d", v + i);
	for(Rint l = 0;l <= n;l ++)
		for(Rint r = n + 1;r > l;r --){
			tot = tt = 0;
			for(Rint i = 1;i <= l;i ++) tmp[++ tot] = v[i];
			for(Rint i = n;i >= r;i --) tmp[++ tot] = v[i];
			if(k < tot) continue;
			sort(tmp + 1, tmp + tot + 1);
			for(Rint i = tot;i;i --)
				if(i <= k - tot) tt += max(tmp[i], 0);
				else tt += tmp[i];
			ans = max(ans, tt);
		}
	printf("%d", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,val[200100],m,fa[200100],res;
struct node{
	int x,y,z;
	node(int u=0,int v=0,int w=0){x=u,y=v,z=w;}
	friend bool operator<(const node&u,const node&v){return u.z<v.z;}
};
vector<node>v;
inline void read(int &x){
	x=0;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
}
inline void print(int x){
	if(x<=9)putchar('0'+x);
	else print(x/10),putchar('0'+x%10);
}
void solve(int l,int r){
	if(l==r)return;
	int mid=(l+r)>>1;
	int ml=l,mr=r,mn;
	mn=0x3f3f3f3f3f3f3f3f;
	for(int i=l;i<=mid;i++)if(val[i]-i*m<mn)mn=val[i]-i*m,ml=i;
	mn=0x3f3f3f3f3f3f3f3f;
	for(int i=r;i>mid;i--)if(val[i]+i*m<mn)mn=val[i]+i*m,mr=i;
	for(int i=l;i<=mid;i++)v.push_back(node(i,mr,val[i]+val[mr]+(mr-i)*m));
	for(int i=r;i>mid;i--)v.push_back(node(ml,i,val[ml]+val[i]+(i-ml)*m));
	solve(l,mid),solve(mid+1,r);
}
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
bool merge(int x,int y){
	x=find(x),y=find(y);
	if(x==y)return false;
	fa[x]=y;
	return true;
}
signed main(){
	read(n),read(m);
	for(int i=1;i<=n;i++)read(val[i]),fa[i]=i;
	solve(1,n),sort(v.begin(),v.end());
	for(auto i:v){
		if(n==1)break;
		if(merge(i.x,i.y))n--,res+=i.z;
	}
	print(res);
	return 0;
}

Measured memory_bytes: 103776
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    int n,t,a;
    cin>>n;
    cin>>t>>a;
    vector<int> h;
    int point;
    double mindis=INF;
    rep(i,n)
    {
        int l;
        cin>>l;
        h.push_back(l);
    }
    rep(i,n)
    {
        double temp=t-h[i]*0.006;
        if(mindis>abs(a-temp))
        {
            mindis=abs(a-temp);
            point=i+1;
        }
    }
    cout<<point<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> ans(n);
  rep(i, n){
    cin >> a[i];
  }
  int m=0;
  for(int i=n-1; i>=0; i--){
    int sumi=0;
    int ki=(i+1)*2;
    while(ki<=n){
      sumi^=ans[ki-1];
      ki+=i+1;
    }
    ans[i]=a[i]^sumi;
    m+=ans[i];
  }
  cout << m << endl;
  rep(i, n){
    if(ans[i]){
      cout << i+1 << " ";
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2432
def getlist():
	return list(map(int, input().split()))

N = int(input())
W = getlist()

ans = float("inf")

s1 = 0
s2 = sum(W)

for i in range(N):
	s1 += W[i]
	s2 -= W[i]
	val = abs(s1 - s2)
	if val < ans:
		ans = val

print(ans)

Measured memory_bytes: 3064
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> p(N);
    for(int i=0; i<N; i++) {
        cin >> p[i];
    }

    sort(p.begin(), p.end());

    int ans = 0;
    for(int i=0; i<N; i++) {
        if(i + 1 == N) ans += p[i] / 2;
        else ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
const int MAX_N = 100000;
const ll MOD = 1000000007;

int main() {
  int N, A[MAX_N];
  std::map<int, int> cnt;
  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> A[i];
    ++cnt[A[i]];
  }

  ll ans  = 1;
  for(int i = 0; i < N; ++i) {
    int d = std::abs(2 * i - N + 1);
    if(cnt[d] == 0) {
      std::cout << 0 << std::endl;
      return 0;
    } else {
      ans *= cnt[d]; ans %= MOD;
      --cnt[d];
    }
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 3584
[n,w] = [int(i) for i in input().split()]
wei_val = []
for i in range(n):
    wei_val.append([int(j) for j in input().split()])
"""
dp[i][w_zantei] = v
i : i番目までの品物
w_zantei : 合計の重さがこれになる
v : 価値

更新式
dp[i][w_zantei] = max(dp[i][w_zantei],dp[i - 1][w_zantei - wei_val[0]] + wei_val[1]) (if w >= w_zantei+wei_val[i][0])
dp[i][w_zantei] = dp[i-1][w_zantei] (if w < w_zantei+wei_val[0])
"""
dp = [[0]* (w+1) for i in range(n)]
for i in range(n):
    for w_zantei in range(w+1):
        if w_zantei >= wei_val[i][0]:
            dp[i][w_zantei] = max(dp[i-1][w_zantei],dp[i - 1][w_zantei - wei_val[i][0]] + wei_val[i][1])
        else:
            dp[i][w_zantei] = dp[i-1][w_zantei]
print(dp[n-1][w])


Measured memory_bytes: 120172
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<functional>
#include<vector>
#include<math.h>
using namespace std;

const int BIG=100000000;

int main(){
  int N;
  cin>>N;
  int A[N][2];
  for(int i=0;i<N;i++){
    cin>>A[i][0]>>A[i][1];
  }
  vector<int> order(N);
  for(int i=0;i<N;i++) order[i]=i;
  double lensum=0;
  do{
    for(int i=0;i<N-1;i++){
     lensum += sqrt(pow((A[order[i]][0]-A[order[i+1]][0]),2)+pow((A[order[i]][1]-A[order[i+1]][1]),2));
    }
  }while(next_permutation(order.begin(), order.end()));
   
   double mother=1;
   for(int i=N;i>=1;i--) mother *=i;                                                             
    printf("%f7",lensum/mother);                                                                        
                                                                            
}

Measured memory_bytes: 3716
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if(n.substring(0,1).equals("9")) {
            System.out.println("Yes");
        } else if (n.substring(1,2).equals("9")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
int main(void)
{
	int a[3],s,i,j;
	for(i=0;i<3;i++)
		scanf("%d",&a[i]);
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				s=a[i];
				a[i]=a[j];
				a[j]=s;
			}
		}
	}
	printf("%d",a[0]);
	for(i=1;i<3;i++)
		printf(" %d",a[i]);
	printf("\n");
	return 0;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    map<char ,int > mp;
    rep(i,3){
        char c; cin >> c;
        mp[c]++;
    }

    cout << 700 + 100 * mp['o'] << endl;

    return 0;
}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

struct Node{
    ll index;
    ll state;
    Node(ll i, ll s){
        index = i;
        state = s;
    }
    Node(){}
    string ToString(){
        stringstream ss;
        ss << "Node " << index << ' ' << state;
        return ss.str();
    }
};

vector<vector<Node> > G[3];
const int N_MAX = 100010;

ll d[3][N_MAX];

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

    // input
    ll N, M;
    cin >> N >> M;
    G[0].resize(N);
    G[1].resize(N);
    G[2].resize(N);

    FOR(i, 0, M){
        ll u, v;
        cin >> u >> v;
        u--;
        v--;
        G[0][u].push_back(Node(v, 1));
        G[1][u].push_back(Node(v, 2));
        G[2][u].push_back(Node(v, 0));
    }

    ll S, T;
    cin >> S >> T;
    S--;
    T--;

    FOR(i, 0, 3){
        FOR(j, 0, N_MAX){
            d[i][j] = inf;
        }
    }

    queue<Node> que;
    que.push(Node(S, 0));
    d[0][S] = 0;

    while(!que.empty()){
        auto cur = que.front();
        que.pop();

        for(Node to : G[cur.state][cur.index]){
            if(d[to.state][to.index]!=inf) continue;
            d[to.state][to.index] = d[cur.state][cur.index] + 1;
            que.push(to);
        }
    }

    if(d[0][T]==inf){
        p(-1);
    }else{
        p(d[0][T]/3);
    }
    
    return 0;
}

Measured memory_bytes: 19072
n,a,b,c = map(int, input().split())

l = [int(input()) for i in range(n)]

import itertools

bumboo=["A","B","C","D"]

prod = list(itertools.product(bumboo,repeat=n))

temp = []

for i in prod:
    tempa = 0
    tempb = 0
    tempc = 0
    for j in range(n):
        if i[j] =="A":
            tempa += l[j]
        elif i[j] =="B":
            tempb += l[j]
        elif i[j] =="C":
            tempc += l[j]
    if tempa*tempb*tempc == 0:
        pass
    else:
        temp.append(abs(tempa-a)+abs(tempb-b)+abs(tempc-c)+10*(n-3-i.count("D")))
print(min(temp))

Measured memory_bytes: 18564
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int a, b;
    cin >> a >> b;
    
    for(int i = 0; i < 100000; i++) {
        if ((i*8)/100 == a && (i*10)/100 == b) {
            cout << i << endl;
            return 0;
        }        
    }

    cout << -1 << endl;

    return 0;
}

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

int main()
{
	long long n,inp,ans1=0,ans2=0,sum=0,k1,k2;
	cin>>n;
	vector<long long> v;
	for(long long i=0;i<n;i++)
	{
		cin>>inp;
		sum+= inp;
		v.push_back(inp);
	}
	k1= sum/n;
	k2= sum/n+1;
	for(int i=0;i<(int)v.size();i++)
	{
		ans1+=(k1-v[i])*(k1-v[i]);
	}
	for(int i=0;i<(int)v.size();i++)
	{
		ans2+=(k2-v[i])*(k2-v[i]);
	}
	cout<<min(ans1,ans2)<<endl;
return 0;
}

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

int main(){
	int n, k; cin>>n>>k;
	int arr[n];
	int dp[n];
	for(int i = 0; i < n; i++) cin>>arr[i];
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		int p = i-1;
		for(int j = i-2; j >= i-k && j >= 0; j--){
			if(dp[p] + abs(arr[i] - arr[p]) > dp[j] + abs(arr[i] - arr[j])) p = j;
		}
		dp[i] = dp[p] + abs(arr[i] - arr[p]);
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
N, T = map(int,input().split())
A = list(map(int,input().split()))
max_profit = [0]
Min = A[0]
for i in range(N-1):
  if A[i] < Min:
    Min = A[i]
  if A[i+1] - Min > max_profit[0]:
    max_profit = [A[i+1] - Min]
  elif A[i+1] - Min == max_profit[0]:
    max_profit.append(A[i+1] - Min)
print(len(max_profit))



Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    if (A.at(i) % 2 == 0)
    {
      if (A.at(i) % 3 == 0 || A.at(i) % 5 == 0)
      {
      }
      else
      {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    ll a,b,c,k;
    cin >> a >>b >> c >> k;

    if(a>=k)cout << k << endl;
    else if(k>a and k-a<=b)cout << a << endl;
    else cout << a-(k-a-b) << endl;
 
    
    return 0;

}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cmath>

#define int long long
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

using namespace std;

int N;
int F[101][11];
int P[101][11];

signed main()
{
    cin >> N;
    REPS(i, N) REPS(j, 10) cin >> F[i][j];
    REPS(i, N) REPS(j, 11) cin >> P[i][j];

    int ans = -(1 << 30);
    REPS(i, (1 << 10) - 1)
    {
        int c = 0;
        REPS(j, N)
        {
            int tmpc = 0;
            REPS(k, 10)
            {
                if ((i >> (k-1)) & 1) tmpc += F[j][k];
            }
            c += P[j][tmpc+1];
        }
        ans = max(ans, c);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for x in range(N)]
M = int(input())
T = [input() for x in range(M)]

c = {"":0}
for s in S:
    c[s] = c.get(s, 0) + 1
for t in T:
    c[t] = c.get(t, 0) - 1

print(max(c.values()))





Measured memory_bytes: 3060
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int BIG = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    int n,w; cin>>n>>w;

    vector< pair<int,int> >v(n+1);

    repa(i,1,n)
        cin>>v[i].ff>>v[i].ss;

   // sort(v.begin()+1,v.end());

    int dp[n+1][w+1];

    repa(i,0,n)
        repa(j,0,w)
            dp[i][j] = 0;

    repa(i,1,n)
    {
        repa(j,1,w)
        {
            int bufValue = -v[i].ss;

            if (j-v[i].ff>=0)
                bufValue = dp[i-1][j-v[i].ff]; 

            dp[i][j] = max( dp[i-1][j], bufValue + v[i].ss );
        }
    }

    cout<< dp[n][w] <<endl;
}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int p, q;
  while (cin >> p >> q) {
    map<int, int> mp;
    int pos = 0, l = -1, r = -1;
    string digit = "";
    bool finite = false;
    while (true) {
      p *= 10;
      if (mp.find(p) != mp.end()) {
        l = mp[p], r = pos;
        break;
      }
      mp[p] = pos++;
      digit += p / q + '0';
      p %= q;
      if (p == 0) {
        finite = true;
        break;
      }
    }
    cout << digit << endl;
    if (!finite) cout << string(l, ' ') << string(r - l, '^') << endl;
  }

  return 0;
}


Measured memory_bytes: 3012
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#define pb push_back
#define mp make_pair
using namespace std;
const int N = 1e5 + 5;

int n;
string s;

int nxt[N];
int cur_root, NFV;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    cin >> s;
    n = s.size();

    s = "T" + s;
    for(int i = 1; i < n; i++)
        if(s[i] != s[n - i])
        {
            //cerr << i << " " << n - i << endl;
            cout << -1 << endl;
            return 0;
        }

    if(s[n] == '1')
    {
        cout << -1 << endl;
        return 0;
    }

    if(s[1] == '0')
    {
        cout << -1 << endl;
        return 0;
    }

    for(int i = 1; i < n; i++)
    {
        if(s[i - 1] == '1')
            nxt[i] = i - 1;
        else
            nxt[i] = nxt[i - 1];
    }

    cur_root = 1;
    NFV = 1;
    for(int i = n - 1; i >= 1; i = nxt[i])
    {
        int diff = i - nxt[i];
        if(i == n - 1)
            diff++;
        for(int j = 1; j <= diff; j++)
        {
            NFV++;
            if(NFV <= n)
              cout << cur_root << " " << NFV << endl;
        }
        cur_root = NFV;
    }


    return 0;
}


Measured memory_bytes: 2048
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //入力値を取得する
        Scanner sc = new Scanner(System.in);
        
        // 実行回数を取得する
        int execNum = Integer.parseInt(sc.next());
        
        //黒板の数値をリストに格納する
        List<Integer> numList = new ArrayList<Integer>();
        for(int i=0;i<execNum;i++) {
            numList.add(Integer.parseInt(sc.next()));
        }
        
        //操作回数を定義する
        int opeNum = 0;
        
        //偶数フラグを設定する
        boolean evenFlg = true;
        
        //取得した数値を2で割っていく。剰余が1のものが出てきたらfor文を抜ける
        while(evenFlg) {
          
          	//剰余判定・計算処理
            for(int j=0;j < numList.size();j++) {
                //numList.get[j]を定義する
                int jNum = numList.get(j);
                if (jNum % 2 == 0) {
                    //偶数であるため2で割った数を再びリストに格納する
                    numList.set(j,jNum / 2);
                } else {
                    // 奇数が出た、または整数ではなかったため偶数フラグをfalseに変更する
                    evenFlg = false;
                }
            }
        
            //偶数フラグのチェック処理
            if (!evenFlg) {
                //奇数が出た場合は操作回数検証while文を抜ける
                break;
            } else {
                //全て偶数であったため、操作回数を1増やす
                opeNum++;
            }
        }
        
        //操作回数を出力する
        System.out.println(opeNum);
    }
}


Measured memory_bytes: 23764
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



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


    Scanner cin;

    Tuple<int, int>[] l, r;
    int[] left, right;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();

        int MAX = 300000;
        int HALF = MAX / 2;
        int[] asum = new int[MAX];
        int[] bsum = new int[MAX];
        asum[HALF] = bsum[HALF] = 1;


        left = new int[N];
        right = new int[N];
        for (int i = 0; i < N; i++)
        {
            int L, R;
            L = cin.nextInt();
            R = cin.nextInt();
            left[i] = L; right[i] = R;
            asum[L + HALF]++; bsum[R + HALF]++;
        }

        for (int i = 1; i < MAX; i++)
        {
            bsum[i] += bsum[i - 1];
        }
        for (int i = MAX - 2; i >= 0; i--)
        {
            asum[i] += asum[i + 1];
        }

        long ans = 0;
        for (int i = 0; i < MAX - 1; i++)
        {
            ans += Math.Min(asum[i + 1], bsum[i]);
        }

        Console.WriteLine(ans * 2);
    }

}






class Scanner
{
    string[] s;
    int i;

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

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

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

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

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

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

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


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int main() {
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;

  ll c_q = n * 4 * q;
  ll c_h = n * 2 * h;
  ll c_s = n * 1 * s;
  ll c_d = n / 2 * d + (n % 2) * min({s, 2 * h, 4 * q});

  ll ans = min({c_q, c_h, c_s, c_d});

  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction



def main():
    num = int(input())
    data = list(map(int, input().split()))

    now_ind = 1
    break_num = 0

    for i in range(num):
        if data[i] == now_ind:
            now_ind += 1
        else:
            break_num += 1

    if break_num == num:
        print(-1)
    else:
        print(break_num)



if __name__ == '__main__':
    main()



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

#define UNKNOWN 1000000009

int N, M;

int par[100010];
int unir[100010];
int weight[100010];

void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		unir[i] = 0;
		weight[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	}else{
		int pp = par[x];
		int np = find(par[x]);
		weight[x] = weight[x] + weight[pp];
		par[x] = np;
		return np;
	}
}

int calcw(int x){
	find(x);
	if(par[x] == x){
		return 0;
	}else{
		return weight[x];
	}
}

int calcw(int x, int y){
	if(find(x) != find(y)){
		return UNKNOWN;
	}
	return calcw(y) - calcw(x);
}

void unite(int x, int y, int w){
	int px = find(x);
	int py = find(y);
	if(px == py){
		return;
	}
	int nw = calcw(x) - calcw(y) + w;
	if(unir[px] < unir[py]){
		swap(px, py);
		nw = -nw;
	}
	par[py] = px;
	weight[py] = nw;
	if(unir[px] == unir[py]) unir[px]++;
}

bool same(int x, int y){
	return find(x) == find(y);
}

void outtree(){
	cout << "-----" << endl;
	for(int i = 0; i <= N; i++){
		cout << par[i] << " " ;
	}
	cout << endl;
	for(int i = 0; i <= N; i++){
		cout << weight[i] << " " ;
	}
	cout << endl;
	for(int i = 0; i <= N; i++){
		cout << unir[i] << " " ;
	}
	cout << endl;
}	


int main(){
	while(cin >> N >> M, N){
		init(N + 1);
		for(int i = 0; i < M; i++){
	//		outtree();
			char c;
			int a, b, w;
			cin >> c;
			if(c == '!'){
				cin >> a >> b >> w;
				unite(a, b, w);
			}else{
				cin >> a >> b;
				int ret = calcw(a, b);
				if(ret == UNKNOWN){
					cout << "UNKNOWN" << endl;
				}else{
					cout << ret << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 4232
program seven_five_six
  implicit none
  integer :: n, i
  integer :: n2, n4, n14, n24, n74
  integer :: a, cd(100)
  
  read(*,*) n
  
  if (n .lt. 10) then
     write(*,'(i0)') 0
     stop
  end if
  
  cd = 0
  do i = 2, n
     call add_prime_factor(cd,i)
  end do

  n2 = 0
  n4 = 0
  n14 = 0
  n24 = 0
  n74 = 0
  a = 0
  
  do i = 2, n
     if (cd(i) .ge. 2) n2 = n2 + 1
     if (cd(i) .ge. 4) n4 = n4 + 1
     if (cd(i) .ge. 14) n14 = n14 + 1
     if (cd(i) .ge. 24) n24 = n24 + 1
     if (cd(i) .ge. 74) n74 = n74 + 1
  end do
  
  a = n4*(n4-1)*(n2-2)/2 + n14*(n4-1) + n24*(n2-1) + n74
  
  write(*,'(i0)') a
  
  stop
contains

  function is_prime_number(n) result(ret)
    implicit none
    integer, intent(in) :: n
    logical             :: ret
    integer             :: p(25), i
    p = (/ 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 /)
    do i = 1, 25
       if (n .eq. p(i)) then
          ret = .true.
          return
       end if
    end do
    ret = .false.
    return
  end function is_prime_number

  subroutine add_prime_factor(cd,n)
    implicit none
    integer, intent(inout) :: cd(100)
    integer, intent(in)    :: n
    integer                :: i, m
    m = n
    do while (m .gt. 1)
       do i = 2, m
          if (is_prime_number(i) .and. mod(m,i) .eq. 0) then
             cd(i) = cd(i) + 1
             m = m / i
             exit
          end if
       end do
    end do
    return
  end subroutine add_prime_factor
  
end program seven_five_six

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<sstream>
#include<set>
#include<map>
#include<algorithm>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair

int n,m,g;
int v[4],e[51],val[51];
double dp[51][5001];

int main(){
	while(cin>>n>>g>>m,n){
		rep(i,n)cin>>v[i];
		rep(i,g+1)e[i]=0;
		rep(i,m){
			int a,b,c; cin>>a>>b>>c;
			e[a]=b; val[a]=c;
		}
		rep(i,g+1)rep(j,5001)dp[i][j]=0;
		dp[0][0]=1;
		
		rep(i,g)rep(j,5001)if(dp[i][j]>0){
			rep(k,n){
				int t=min(g,i+v[k]),money=j;
				if(e[t]==1){
					t=min(g,t+val[t]);
				}
				else if(e[t]==2){
					money+=val[t];
				}
				else if(e[t]==3){
					money=max(0,money-val[t]);
				}
				dp[t][money]+=dp[i][j]/n;
			}
		}
		
		double ans=0;
		rep(i,5001)ans+=dp[g][i]*i;
		cout<<(int)ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_N = 100;
const int MAX_M = 100;
const double INF = 1e77;

int M, N;
int X1[MAX_M], Y1[MAX_M];
int X2[MAX_N], Z2[MAX_N];

double width(int *X, int *Y, int n, double x){
	double lb = INF, ub = -INF;
	for(int i=0;i<n;i++){
		double x1 = X[i], y1 = Y[i], x2 = X[(i+1)%n], y2 = Y[(i+1)%n];
		if((x1 - x) * (x2 - x)  <= 0 && x1 != x2){
			double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
			lb = min(lb, y);
			ub = max(ub, y);
		}
	}
	return max(0.0, ub - lb);
}

void solve(){
	int min1 = *min_element(X1, X1 + M), max1 = *max_element(X1, X1 + M);
	int min2 = *min_element(X2, X2 + N), max2 = *max_element(X2, X2 + N);
	vector<int> xs;
	for(int i=0;i<M;i++) xs.push_back(X1[i]);
	for(int i=0;i<N;i++) xs.push_back(X2[i]);
	sort(xs.begin(), xs.end());

	double res = 0;
	for(int i=0;i+1<xs.size();i++){
		double a = xs[i], b = xs[i+1], c = (a + b) / 2;
		if(min1 <= c && c <= max1 && min2 <= c && c <= max2){
			double fa = width(X1, Y1, M, a) * width(X2, Z2, N, a);
			double fb = width(X1, Y1, M, b) * width(X2, Z2, N, b);
			double fc = width(X1, Y1, M, c) * width(X2, Z2, N, c);
			res += (b - a) / 6 * (fa + 4 * fc + fb);
		}
	}
	printf("%.10f\n", res);
}

int main(){
	while(cin >> M >> N && (M|N)){
		for(int i=0;i<M;i++) cin >> X1[i] >> Y1[i];
		for(int i=0;i<N;i++) cin >> X2[i] >> Z2[i];
		solve();
	}
	return 0;
}

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

map<ll,ll>l2;

int main()
{
    ll n;
    cin>>n;
    ll s=0;vector<ll>v;
    for(int i = 1; i<=n;i++){
        ll a,b;
        cin>>a;
        if(!l2[a])v.push_back(a);
        l2[a]++;
    }
    for(int i=0;i<v.size();i++){
        if(l2[v[i]]&1)s++;
    }
    cout<<s;

    return 0;
}


Measured memory_bytes: 7284
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N;
    string S;
    cin >> N >> S;
    
    if(N%2!=0){
        cout << "No";
        return 0;
    }
    
    if(S.substr(0,N/2)==S.substr(N/2)) cout << "Yes";
    
    else cout << "No";
    
    
    return 0;
    
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001

using namespace std;

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

ll fact[MAX_N];
void fact_init(ll n) {
  fact[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = mod(fact[i-1] * i);
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  ll MIN = min(N, M);
  ll MAX = max(N, M);
  if (MAX - MIN > 1) {
    cout << 0 << endl;
    return 0;
  }

  fact_init(MAX);

  ll ans = mod(fact[MAX] * fact[MIN]);
  if (MAX - MIN == 0) {
    ans = mod(2 * ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

const int N = 100000 + 10;

int n, h[N];
int a, b;

bool check(int c) {
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    int t = h[i] - c * b;
    if (t >= 0) cnt += (t + a - 1) / a;
    if (cnt > c) return false;
  }
  return true;
}

int main() {
  scanf("%d%d%d", &n, &a, &b);
  a -= b;
  for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
  int l = 0, r = *std::max_element(h + 1, h + n + 1) / b + 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid)) r = mid; else l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  void operator++() {
      x += 1;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  void operator--() {
      x -= 1;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
    int n,m;
    cin >> n >> m;
    set<int> a;
    rep(i,m) {
        int na;
        cin >> na;
        a.insert(na);
    }
    vector<mint> dp(n+1,0);
    dp[0] = 1;
    if(a.count(1)) dp[1] = 0;
    else dp[1] = 1;
    rep2(i,2,n+1) {
        if(a.count(i)) continue;
        dp[i] = dp[i-1]+dp[i-2];
    }
    cout << dp[n].x << endl;
}

Measured memory_bytes: 5760
(H, W), (N, _), As = readlines.map{|l| l.split.map(&:to_i)}

puts N.times.flat_map{|n| [n + 1] * As[n]}.each_slice(2*W).flat_map{|a| a.take(W) + a.drop(W).reverse}.each_slice(W).map{|a| a.join(' ')}

Measured memory_bytes: 2684
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector <char> a(3);
	vector <char> b(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> b[i];
	}
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (a[i] == b[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{
    ll n; cin>>n;
//ll SUN, MON, TUE, WED, THU, FRI, SAT;
string s;
cin>>s;
for(ll i=0;i<s.size();i++)
{
    s[i]=s[i]+n;
    if(s[i]>90)
    {
        s[i]=s[i]-26;
    }
    cout<<s[i];
}
cout<<endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    ll r;
    cin>>r;
    cout<<3*r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    double a[n+1];
    double prob[n+1][n+1];
    for(int i=1;i<=n;i++)
    cin>>a[i];
   for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
      prob[i][j]=0;
      }}

      prob[n][0]=(1-a[n]);
      prob[n][1]=a[n];
  for(int j=(n-1);j>=1;--j){
  for(int i=0;i<=(n-j+1);++i){
prob[j][i]=(1-a[j])*prob[j+1][i];
if(i>=1)
prob[j][i]+=((a[j])*prob[j+1][i-1]);
//cout<<prob[j][i]<< "  ";
      }
    //  cout<<endl;
      }
      double ans=0;
      for(int i=n;i>(n/2);--i){
      ans+=prob[1][i];
      }
      cout<<fixed<<setprecision(10)<<ans;
    return 0;}


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

int main()
{
    int x,n,flag=0;
    cin >> n >>x;
    vector<int> sure(x);
    for(int i = 0;i < x;i++){
        cin >> sure.at(i);
    }
    int hu=1;
    flag = 1;
    while(flag != 0){
        flag = 0;
        for (int i = 0; i < x; i++){
            if(sure.at(i)==n){
                flag = 1;
                break;
            }
        }
        if(flag != 1){
            cout << n <<endl;
          break;
        }
        flag = 0;
        for (int i = 0; i < x; i++)
        {
            if (sure.at(i) == n-hu)
            {
                flag = 2;
                break;
            }
        }
        if(flag != 2){
            cout << n- hu<<endl;
          break;
        }
        flag = 0;
        for (int i = 0; i < x; i++)
        {
            if (sure.at(i) == n+hu)
            {
                flag = 3;
                break;
            }
        }
        if (flag != 3)
        {
            cout << n + hu <<endl;
          break;
        }
        hu++;
    }
    if(n == 0){
        cout <<x;
    }
}

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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] A = new char[H][];
		for (int i = 0; i < H; ++i) {
			A[i] = sc.next().toCharArray();
		}
		char[][] blue = new char[H][W];
		char[][] red = new char[H][W];
		for (char[] a : blue) {
			Arrays.fill(a, '#');
		}
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				red[i][j] = A[i][j];
			}
		}
		for (int r = 1; r < H; r += 2) {
			for (int c = 1; c < W - 1; ++c) {
				red[r][c] = '#';
				if (A[r][c] != '#') blue[r][c] = '.';
			}
		}
		for (int r = 2; r < H - 1; r += 2) {
			int c = r % 4 == 0 ? 1 : W - 2;
			red[r][c] = '#';
			if (A[r][c] != '#') blue[r][c] = '.';
		}
		for (int i = 0; i < H; ++i) {
			System.out.println(String.valueOf(red[i]));
		}
		System.out.println();
		for (int i = 0; i < H; ++i) {
			System.out.println(String.valueOf(blue[i]));
		}
	}

}


Measured memory_bytes: 18856