akhauriyash/Code-Regression huggingface dataset:
/*
Author: CNYALI_LK
LANG: C++
PROG: C.cpp
*/
#include<bits/stdc++.h>
#define up(a,b,c) for (ll a(b),end##a(c);a<=end##a;++a)
#define down(a,c,b) for (ll a(b),end##a(c);a>=end##a;--a)
#define uup(a,c,b) for (ll a(b),end##a(c);a<=end##a;++a)
#define udown(a,b,c) for (ll a(b),end##a(c);a>=end##a;--a)
#define endl '\n'
#define debug(...) fprllf(stderr,__VA_ARGS__)
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
typedef long long ll;
struct inout{
	static const ll ibufl=1<<25;
	static const ll obufl=1<<25;
	char in_buf[ibufl],out_buf[obufl],*inf,*ouf;
	inout(){
		inf=in_buf;ouf=out_buf;
	}
	void init(){
		fread(in_buf,1,ibufl,stdin);
	}
	inout& operator >>(ll &a){
		ll fh=1;
		while(!(isdigit(*inf)||*inf=='-'))++inf;
		if(*inf=='-')fh=-1,++inf;
		a=0;
		while(isdigit(*inf)){a=a*10+*inf-'0';++inf;}
		a*=fh;
		return *this;
	}
	inout& operator >>(char &a){
		while(*inf==' '||*inf=='\n')++inf;
		a=*inf;
		++inf;
		return *this;
	}
	inout& operator >>(char *a){
		while(*inf==' '||*inf=='\n')++inf;
		while(!(*inf==' '||*inf=='\n'||*inf=='\0')){*a=*inf;++inf;++a;}
		*a='\0';
		return *this;
	}

	inout& operator >>(double &a){
		ll fh=1;
		double s;
		while(!(isdigit(*inf)||*inf=='-'||*inf=='.'))++inf;
		if(*inf=='-')fh=-1,++inf;
		a=0;
		while(isdigit(*inf)){a=a*10+*inf-'0';++inf;}
		if(*inf=='.'){
			s=0.1;
			++inf;
			while(isdigit(*inf)){
				a+=s*(*inf-'0');
				++inf;
				s*=0.1;
			}
		}
		if(*inf=='E'||*inf=='e'){
			ll ss;
			++inf;
			*this>>ss;
			if(ss>0){
				while(ss){
					--ss;
					a*=10;
				}
			}
			if(ss<0){
				while(ss){
					++ss;
					a/=10;
				}
			}
			
		}
		a*=fh;
		return *this;
	}
	void writell(ll x){
		if(x/10)writell(x/10);
		*ouf=x%10+'0';
		++ouf;
	}
	inout& operator <<(ll a){
		
		if(a<0){*ouf='-';++ouf;a=-a;}
		writell(a);
		return *this;
	}
	static const ll sz=7;
	inout& operator <<(char a){
		*ouf=a;++ouf;
		return *this;
	}
	inout& operator <<(char *a){
		while(*a){
			*ouf=*a;
			++ouf;
			++a;
		}
		return *this;
	}
	inout& operator <<(double a){
		if(a<-eps){*ouf='-';++ouf;a=-a;}
		writell((ll)a);
		a-=(ll)a;
		*ouf='.';
		++ouf;
		up(i,1,sz){
			a=a*10;
			*ouf=(ll)a+'0';
			++ouf;
			a-=(ll)a;
		}
		return *this;
	}
	void out(){
		fwrite(out_buf,1,ouf-out_buf,stdout);
		ouf=out_buf;
	}
};
inout io;
template<class T>void chkmin(T &a,T b){a=a<b?a:b;}
template<class T>void chkmax(T &a,T b){a=a>b?a:b;}
ll a[101010];
ll cmp(ll a,ll b){return a>b;}
int  main(){
#ifdef cnyali_lk
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	io.init();
	ll n;
	io>>n;
	up(i,1,n){io>>a[i];	}
	sort(a+1,a+n+1,cmp);
	ll t=1,s=0,area=1;
	while(t<=n&&s<2){
		if(a[t]==a[t+1]){
			++s;
			area*=a[t];
			++t;
		}
		++t;
	}
	if(s<2)io<<0LL<<endl;
	else io<<area<<endl;
	
	
	io.out();
	return 0;
}


Measured memory_bytes: 4096
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int a, p;
  cin >> a >> p;
  p += a * 3;
  cout << p / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A1,A2,A3,s;
    scanf("%d%d%d",&A1,&A2,&A3);
    s=A1+A2+A3;
    if (s>=22)
        printf("bust");
    else
        printf("win");
    return 0;
}


Measured memory_bytes: 128
# Nが偶数なら x + y = 偶数
# 移動距離 < tの変化
import sys

N = int(input())
t = [0] * N
x = [0] * N
y = [0] * N
for i in range(N):
    t[i], x[i], y[i] = map(int, input().split())

t.insert(0, 0)
x.insert(0, 0)
y.insert(0, 0)

for j in range(1, len(t)):
    if t[j] % 2 == 0:
        if (x[j] + y[j]) % 2 != 0:
            print("No")
            sys.exit()
    else:
        if (x[j] + y[j]) % 2 == 0:
            print("No")
            sys.exit()
    if ((x[j] - x[j-1]) + (y[j] - y[j-1])) > t[j] - t[j-1]:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 11636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));


signed main(){
    
    int n; cin >> n;
    vector<Pll> v(n);
    rep(i,n){
        cin >> v[i].fi >> v[i].se;
    }
    sort(ALL(v));
    ll ans=v[n-1].fi-v[0].fi+1;
    ans+=v[0].fi-1LL;
    ans+=v[n-1].se;
    cout << ans << endl;
}




Measured memory_bytes: 4824
#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <unordered_map>

using namespace std;

const int64_t MOD = 998244353;

int main() {
	int n;
	cin >> n;
	vector<int> v;
	vector<int> c;
	for (int i = 0; i < n; ++i) {
		int vi;
		cin >> vi;
		v.push_back(vi);
	}
	for (int i = 0; i < n; ++i) {
		int ci;
		cin >> ci;
		c.push_back(ci);
	}
	int cost = 0;
	for (int i = 0; i < n; ++i) {
		int a = v[i] - c[i];
		if (a > 0) {
			cost += a;
		}
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  //入力層
  inputs = input.split(" ");
  N = +inputs[0];
  A = +inputs[1];
  B = +inputs[2];
  
  costA = N*A;
  
  if(costA >= B)
  	console.log(B);
  else
    console.log(costA);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

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

	deque<int> ans;
	int odd = 0;
	if( n % 2 ) odd = 1;
	for( int i = 0; i < n; i++ ) {
		if( (i + odd) % 2 == 0 ) ans.push_back( a[i] );
		else ans.push_front( a[i] );
	}

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


Measured memory_bytes: 3840
#include<iostream>

unsigned x,y;

unsigned gcd(unsigned a, unsigned b){
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}

unsigned lcm(unsigned a, unsigned b){
	return a/gcd(a,b)*b;
}

int main(){
	while(std::cin >> x >> y)
		std::cout << gcd(x,y) << ' ' << lcm(x,y) << std::endl;
	return 0;
}

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

using namespace std;

int main(){
	int a,b[11],c[11],e,sum;
	
	cin >> e;
	

	
	while(1){
	
		if(e==0) break;
		
		cin >> a;
		
		sum=0;
		
		for(int i=0;i<a;i++) cin >>b[i] >>c[i];
		
		for(int i=0;i<a;i++){
			if(b[i]-c[i]<0){
				sum+=(-1*(b[i]-c[i]));
			}else sum+=b[i]-c[i];
		}
		
		if(e<=sum){
			printf("OK\n");
		}else printf("%d\n",e-sum);
		
		cin >> e;
		
		
	}
	return 0;
}

Measured memory_bytes: 1148
#include<stdio.h>

#define N 100000
#define Q 50000

int main(){
  int S[N];
  int T[Q];
  int i,j,k=0,n,q,count=0;
  int l,m,r;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&T[i]);

  for(i=0;i<q;i++){
    r=n;
    l=0;
    while(l<r){
      m=(l+r)/2;

      if(S[m]>T[i]){
	r=m;
	continue;
      }
      
      else if(S[m]<T[i]){
	l=m+1;
	continue;
      }

      else{
	count++;
	break;
      }
    }
  }
 
  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 110;
int n, m;
vector<int> all_m;
void dfs(int d, int s, vector<int> w)
{
	if(d >= m)
	{
		all_m.push_back(s);
		return ;
	}
	dfs(d + 1, s, w);
	dfs(d + 1, s + w[d] ,w);
	dfs(d + 1, abs(s - w[d]), w);
}
int main() 
{
	while(scanf("%d%d", &n, &m))
	{
		if(!n && !m) break;
		all_m.clear();
		vector<int> a(n), w(m);
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 0; i < m; i++) cin >> w[i];
		sort(a.begin(), a.end());
		a.erase(unique(a.begin(), a.end()), a.end());
		dfs(0, 0, w);
		sort(all_m.begin(), all_m.end());
		all_m.erase(unique(all_m.begin(), all_m.end()), all_m.end());
		for(int i = 0; i < all_m.size(); i++)
		{
			for(int j = 0; j < a.size(); j++)
			{
				if(all_m[i] == a[j])
					a.erase(a.begin() + j);
			}
		}
		if(a.empty())
		{
			puts("0");
			continue;
		}
		
		vector<vector<int> >  mul(a.size() + 1);
		for(int i = 0; i < a.size(); i ++)
		{
			for(int j = 0; j < all_m.size(); j++)
			{
				mul[i].push_back(a[i] + all_m[j]);
				mul[i].push_back(abs(a[i] - all_m[j]));
			}
			sort(mul[i].begin(), mul[i].end());
			mul[i].erase(unique(mul[i].begin(), mul[i].end()), mul[i].end());
		}
		
		vector<int> res = mul[0];
		
		for(int k = 1; k < a.size(); k++)
		{
			vector<int> l1 = res;
			vector<int> l2 = mul[k]; 
			int i = 0, j = 0;
			res.clear();
			while(i < l1.size() && j < l2.size())
			{
				if(l1[i] < l2[j])
					++i;
				else if(l1[i] > l2[j])
					++j;
				else 
				{
					if(res.empty() || res[res.size() - 1] != l1[i]) res.push_back(l1[i]);
					++i, ++j;
				} 
			}
		}
		
		if(res.empty()) printf("-1\n");
		else 
			printf("%d\n", res[0]);
	}
	return 0;
}


Measured memory_bytes: 23456
#include<iostream>
#include<cmath>
#include<string>

using namespace std;

#define REP(i,n) for(int i = 0;i < n ;i++)
#define EPS 1e-8

int n,hx,hy,dx,dy;
int x[30],y[30];

bool flag;

void dfs(int unvisit,int cx,int cy,double t)
{
	if(flag) return;
	if(unvisit == 0)flag = true;
	
	else
	{
		REP(i,n)
		{
			if(!((unvisit >> i) & 1))continue;
			if(hypot(dx-x[i],dy-y[i]) <= t + hypot(cx-x[i],cy-y[i]))return;
		}
		
		REP(i,n)
		{
			if(!((unvisit >> i) & 1))continue;
			dfs((unvisit & ~(1 << i)),x[i],y[i],t + hypot(cx-x[i],cy-y[i]));
		}
	}
}

string solve()
{
	flag = false;
	dfs((1<<n)-1,hx,hy,0);
	return (flag)?"YES":"NO";
}

int main()
{
	while(cin >> n >> hx >> hy >> dx >> dy,n)
	{
		REP(i,n)
		{
			cin >> x[i] >> y[i];
		}
		
		cout << solve() << endl;
		
	}
	
	return 0;
	
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	
	priority_queue<pair<ll,ll> > h;
	
	while(a--)
	{
		ll w;
		cin>>w;
		h.push(make_pair(w,1));
	}
	
	while(b--)
	{
		ll w;
		cin>>w;
		h.push(make_pair(w,2));
	}
	while(c--)
	{
		ll w;
		cin>>w;
		h.push(make_pair(w,3));
	}
	
	ll z=x+y;
	ll ans=0;
	
	while(z)
	{
		pair<ll,ll> f=h.top();
		h.pop();
		if(f.second==3)
		{
			ans+=f.first;
			--z;
		}
		else if(f.second==1 && x)
		{
			ans+=f.first;
			--x;
			--z;
		}
		else if(f.second==2 && y)
		{
			ans+=f.first;
			--y;
			--z;
		}
	}
	
	cout<<ans<< endl;
	return 0;
}


Measured memory_bytes: 10476
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}
use std::io::{Write, stdout};
fn main() {
    let n:usize = read();
    let mut v:Vec<i32> = read_vec();
    v.sort();
    v.reverse();
    let mut v:Vec<f64> = v.into_iter().map(|x| x as f64).collect();
    for i in 0..n-1 {
        let x = (v.pop().unwrap() + v.pop().unwrap()) / 2.0;
        v.push(x);
    }
    println!("{}", v.pop().unwrap());

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define INF 1000000000
#define INFLL 1000000000000000010ll
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))
#define mid(x,y) (((x)+(y))>>1)
int dist[100005][15];
priority_queue<pair<int,ii> > pq;
vector<int> adj[100005];
int n,m,q,col[100005];
int main() {
	memset(dist,-1,sizeof(dist));
	scanf("%d%d",&n,&m);
	int a,b;
	for (int i=0;i<m;i++) {
		scanf("%d%d",&a,&b);
		--a,--b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	scanf("%d",&q);
	int v,d;
	for (int i=0;i<q;i++) {
		scanf("%d%d%d",&v,&d,&col[i]);
		--v;
		dist[v][d]=max(dist[v][d],i);
		pq.push(mp(i,mp(v,d)));
	}
	while(!pq.empty()) {
		pair<int,ii> p=pq.top();
		pq.pop();
		v=p.second.first,d=p.second.second;
		if (p.first<dist[v][d]) continue;
		if (d==0) continue;
		for (int x:adj[v]) {
			if (dist[v][d]>dist[x][d-1]) {
				dist[x][d-1]=dist[v][d];
				pq.push(mp(dist[x][d-1],mp(x,d-1)));
			}
		}
	}
	for (int i=0;i<n;i++) {
		int ans=-1;
		for (int j=0;j<=10;j++) ans=max(ans,dist[i][j]);
		if (ans==-1) printf("0\n");
		else printf("%d\n", col[ans]);
	}
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

vector< pair<ll,ll> > prime_factorize(ll n){
    vector<pair<ll, ll> > res;
    for (ll p = 2; p*p<=n; ++p){
        if(n%p != 0) continue;
        int num = 0;
        while(n%p == 0){
            ++num; 
            n /= p; 
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n,1));
    return res;
}
	const int MAX = 510000;
 long long fac[MAX], finv[MAX], inv[MAX];
 
 // テーブルを作る前処理
 void COMinit() {
     fac[0] = fac[1] = 1;
     finv[0] = finv[1] = 1;
     inv[1] = 1;
     for (int i = 2; i < MAX; i++){
         fac[i] = fac[i - 1] * i % MOD;
         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
         finv[i] = finv[i - 1] * inv[i] % MOD;
     }
 }
 
 // 二項係数計算
 long long COM(int n, int k){
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
 }

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

    int n,m,ans=1;
    cin>>n>>m;

    VPii fact=prime_factorize(m);
    for(auto x : fact){
        int i=x.second;
        ans = (ans * COM(n+x.second-1,n-1))%MOD;
    }
    cout<<ans<<endl;
    return 0;
}


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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)

typedef long long ll;

int main (void) {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    std::cin >> n;
    std::cout << n*(n-1)/2 << std::endl;
    return 0;
}

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

#define int  long long
#define pb emplace_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n , m;
	cin >> n >> m;
	
	int a[n];
	map<int,int> mp;
	f(i,0,n)    cin >> a[i];
	
	while(m--)
	{
		int x,y;
		cin >> x >> y;
		mp[y] += x;
	}

	vector<pair<int,int>>v;
	for(auto x : mp)
	{
		v.pb(make_pair(x.F , x.S));
	}
	
	sort(v.rbegin(),v.rend());

	sort(a,a+n);

	int sum = 0;
	
	int j = 0 , i;
	for( i= 0  ; i< n ; i++)
	{
		if(j >= v.size())  break;
		if(v[j].S <= 0 ) j++;
		sum += max(a[i] , v[j].F);

		if(v[j].F > a[i])   v[j].S--;
		
	}
	
	for( ; i < n ; i++)  sum += a[i];

	cout << sum;
}







Measured memory_bytes: 9464
#include<bits/stdc++.h>
using namespace std;
bool d[10],f;
int main(){
	long long n,k,i,j;
	cin>>n>>k;
	for(i=1;i<=k;i++){
		cin>>j;
		d[j]=1;
	}
	string s;
	char c[10];
	for(i=0;i<=9;i++)c[i]='0'+i;
	for(i=n;i<=n*100;i++){
		stringstream ss;
		ss<<i;
		s=ss.str();
		f=1;
		for(j=0;j<10;j++){
			if(d[j]&&s.find(c[j])!=-1){
				f=0;
				break;
			}
		}
		if(f){
			cout<<i<<'\n';
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            out.println(Math.min(n * a, b));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<int>ans(n);
	rep(i, n)ans[a[i] - 1] = i + 1;
	rep(i, n) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 1664
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	for (int i=0;i<n;i++){
		int hn,gn;
		vector<int> hd;
		cin >> hn;
		cin >> gn;
		int prev_hp;
		cin >>prev_hp;
		for(int j=1;j<hn;j++){
			int hp;
			cin >> hp;
			hd.push_back(hp-prev_hp);
			prev_hp=hp;
		}
		sort(hd.begin(),hd.end());
		long long ans=0;
		for(int j=0;j<hn-gn;j++){
			ans+=hd[j];
		}
		cout << ans << endl;
	}

}


Measured memory_bytes: 1860
//AOJ 0009 Prime Number
//2016.6.25
//Algorithm:Prime
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

const int maxn=1000006;
bool prime[maxn];
int n;
int cnt[maxn];

int main()
{
	for(int i=1;i<maxn;i++)
		prime[i]=true;
	prime[1]=false;
	for(int i=2;i<maxn;i++)
		if(prime[i])
			for(int j=i*2;j<maxn;j+=i)
				prime[j]=false;
	for(int i=1;i<maxn;i++)
		cnt[i]=cnt[i-1]+prime[i];
	while(cin>>n)
	{
		cout<<cnt[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6044
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#define int long long
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0,-1 }; // x軸方向への変位
int dy[4] = { 1, 0,-1, 0 }; // y軸方向への変位

int dp[600][600];	//dp[i][j]はaをiグラム、bをjグラム持つときの最小価格

void update(int a, int b, int c, int N) {
	

	//この薬品をすでに使っているセルを管理する必要あり
	bool used[600][600];
	for (int i = 0; i < 500; i++) {
		for (int j = 0; j < 500; j++) {
			used[i][j] = false;
		}
	}

	if(dp[a + a][b + b] > dp[a][b]+c){
		dp[a + a][b + b] = dp[a][b] + c;
		used[a + a][b + b] = true;
	}
	if (dp[a][b] > c) {
		dp[a][b] = c;
		used[a][b] = true;
		
	}

	for (int i = 0; i < 500; i++) {
		for (int j = 0; j < 500; j++) {
			if (i == a && j == b) continue;
			if (dp[i][j] != LL_HALFMAX && used[i][j] == false) {
				//dp[i + a][j + b] = min(dp[i][j] + c, dp[i + a][j + b]);
				//もし金額が定義されてて、そこに薬品を追加してセルの最安値を更新できるなら、usedを立ててセルの価格を更新
				if (dp[i + a][j + b] > dp[i][j] + c) {
					used[i + a][j + b] = true;
					dp[i + a][j + b] = dp[i][j] + c;
				}
			}
		}
	}
}

signed main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	for (int i = 0; i < 600; i++) {
		for (int j = 0; j < 600; j++) {
			dp[i][j] = LL_HALFMAX;
		}
	}

	for (int i = 0; i < N; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		update(a, b, c, N);
	}

	int ans = LL_HALFMAX;
	for (int i = 0; i < 500; i++) {
		for (int j = 0; j < 500; j++) {
			double target = (double)Ma / (double)Mb;
			double now = (double)i / (double)j;
			if (abs(target - now) < 0.000001 && dp[i][j] < ans) {
				ans = dp[i][j];
			}

		}
	}

	if(ans <40000) cout << ans << "\n";
	else cout << "-1" << "\n";

	return 0;




}

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

int main() {
  int N, A = 0, B = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
  	cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < N; i++) {
  	if (i%2 == 0) {
    	A += a.at(i);
    } else {
    	B += a.at(i);
    }
  }
  cout << A - B << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int H, W, K; cin >> H >> W >> K;
  string S[H]; rep(i,H) cin >> S[i];

  int result = INF;
  rep(i,1<<(H-1)) {
    vector<vector<int>> choco; choco.push_back({0});
    int rtmp = 0, cs = 1;
    rep(j,H-1) {
      if (i&(1<<j)) { choco.push_back({j+1}); rtmp++; cs++; }
      else choco[cs-1].push_back(j+1);
    }
    // for (auto x: choco) debug(all(x));

    vector<int> count(cs,0);
    bool ok = true;
    rep(j,W) {
      int mac = 0, tmac = 0;
      vector<int> tc(cs,0);
      rep(c,cs) {
        for (auto x: choco[c]) tc[c] += S[x][j] == '1';
        mac = max(mac, count[c]+tc[c]);
        tmac = max(tmac, tc[c]);
      }
      if (tmac>K) { ok = false; break; }
      if (mac>K) {
        rep(k,cs) count[k] = tc[k];
        rtmp++;
      } 
      else rep(k,cs) count[k] += tc[k];
    }
    if (!ok) continue;
    // cout << i << "->" << rtmp << endl;
    result = min(result,rtmp);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool like[35][35];
int main () {
	int N,M;
	cin >> N >> M;
	for (int i = 0; i < N; ++i)
	{
		int count;
		cin >> count;
		for (int j = 0; j < count; ++j)
		{
			int tmp;
			cin >> tmp;
			like[i][tmp-1] = true;
		}
	}
	int result = 0;
	for (int xi = 0; xi < M; ++xi)
	{
		bool check = true;
		for (int yi = 0; yi < N; ++yi)
		{
			if(like[yi][xi] == false){
				check = false;
				break;
			}
		}
		if(check){
			result ++;
		}
	}
	cout << result << endl;
}

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

namespace ABC152A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, M;
            string a;
            var word = Console.ReadLine().Split(' ');
            N = int.Parse(word[0]);
            M = int.Parse(word[1]);
            if (N == M)
            { a = "Yes"; }
            else { a = "No"; }
            Console.WriteLine(a);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
while true
    m, nmin, nmax = gets.chomp.split.map(&:to_i)
    break if [m, nmin, nmax] == [0, 0, 0]
    arr = []
    m.times{arr << gets.to_i}
    max, max_i = nil, nil
    (nmin).upto(nmax){|i|
        if max.nil? || max <= (arr[i] - arr[i-1]).abs
            max, max_i = (arr[i] - arr[i-1]).abs, i
        end
    }
    puts max_i
end


Measured memory_bytes: 6876
H,W=map(int,input().split())

import heapq
def dijkstra_heap(s):
  #始点sから各頂点への最短距離
  dist,used={},{}
  for v in vlist:
    dist[v]=float("inf")
    used[v]=False
  dist[s]=0
  used[s]=True

  hq_edge=[]
  for v,w in edge[s]:
    heapq.heappush(hq_edge,(w,v))

  while len(hq_edge):
    min_w,min_v=heapq.heappop(hq_edge)
    #まだ使われてない頂点の中から最小の距離のものを探す
    if used[min_v]:
      continue

    dist[min_v]=min_w
    used[min_v]=True
    for v,w in edge[min_v]:
      if not used[v]:
        heapq.heappush(hq_edge,(min_w+w,v))

  return dist

cmat=[]
for i in range(10):
  cmat.append(list(map(int,input().split())))
#print(cmat)

amat=[]
for i in range(H):
  amat.append(list(map(int,input().split())))
#print(amat)

vlist=list(range(10))
edge={}
for i in range(10):
  edge[i]=[]
  for j in range(10):
    edge[i].append((j,cmat[i][j]))
    
mindist=[10**9]*10
for i in range(10):
  res=dijkstra_heap(i)
  #print(i,res)
  mindist[i]=res[1]
#print(mindist)

answer=0
for i in range(H):
  for j in range(W):
    if amat[i][j]==-1:
      continue
    answer+=mindist[amat[i][j]]
    
print(answer)

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

int main() {
	
	int h,w;
	cin >> h >> w;
	vector<vector<int>> c(10,vector<int>(10));
	vector<vector<int>> a(h,vector<int>(w));
	for(int i=0; i<=9; i++){
		for(int j=0; j<=9; j++) cin >> c.at(i).at(j);
		c.at(i).at(i) = 0;
	}
	vector<int> b(10);
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++) {
			cin >> a.at(i).at(j);
			if(a.at(i).at(j)>=0) b.at(a.at(i).at(j))++;
		}
	}
	for(int k=0; k<10; k++){
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k) + c.at(k).at(j));
			}
		}
	}
	int ans{};
	for(int i=0; i<10; i++){
		ans += c.at(i).at(1)*b.at(i);
	}
	cout << ans << endl;
} 

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

//#define int long long

using namespace std;

int a[100001];

int main () {
    int n;
    cin >> n;
    n *= 2;
    for (int i = 1;i <= n;i ++) {
    	cin >> a[i];
    }
    int ans = 0;
    sort (a + 1, a + n + 1);
    for (int i = 1;i <= n;i += 2) {
		ans += a[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;

int n,k;

int v=1;

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		if(v<k) v*=2;
		else v+=k;
	}
	cout<<v<<endl; //result
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

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

	vector<int> ans;
	for(int i=0;i<n;i++){
		int mx = -1;
		for(int j=0;j<a.size();j++){
			if(a[j]==j){
				mx = j;
			}
		}
		if(mx!=-1){
			ans.pb(mx);
			a.erase(a.begin()+mx);
		}
	}
	if(a.size()){
		cout<<-1<<endl;
	}
	else{
		reverse(ans.begin(), ans.end());
		for(int i:ans){
			cout<<i+1<<endl;
		}
	}
}

Measured memory_bytes: 256
import Data.List
main = interact $ unlines . map (figure_on_surface . dropWhile (=='0')) . parse . lines

parse [] = []
parse ("":xs) = parse xs
parse xs = concat (take 8 xs) : parse (drop 8 xs)
 
figure_on_surface xs
 | isPrefixOf "1100000011" xs = "A"
 | isPrefixOf "1000000010000000100000001" xs = "B"
 | isPrefixOf "1111" xs = "C"
 | isPrefixOf "1000000110000001" xs = "D"
 | isPrefixOf "11000000011" xs = "E"
 | isPrefixOf "100000001100000001" xs = "F"
 | isPrefixOf "110000011" xs = "G"

Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105;
struct node
{
    int x,y;
    bool operator<(const node&o)const
    {
        return atan2(y,x)<atan2(o.y,o.x);
    }
}a[N<<1];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++) a[i+n]=a[i];
    double ans=0;
    for(int i=1;i<=n;i++)
    {
        ll x=0,y=0;
        for(int j=i;j<i+n;j++)
        {
            x+=a[j].x;y+=a[j].y;
            ans=max(ans,sqrt(x*x+y*y));
        }
    }
    printf("%.15f\n",ans);
}


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

#define INF (1<<31-1)
#define ll long long


int main(){

	ll N, M;
	ll result;

	cin >> N >> M;

	if (N > M) swap(N, M);

	if (N >= 3) result = (N - 2)*(M - 2);
	else if (N == 2) result = 0;
	else if(N==1 && M>1)result = M - 2;
	else result = 1;

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    if b:
        return gcd(b, a%b)
    else:
        return a

#input = __import__('sys').stdin.readline
N, X = map(int, input().split())
l = list(map(int, input().split()))
res = -1

for i in range(N):
    d = abs(l[i] - X)
    
    if res == -1:
        res = d
    else:
        res = gcd(res, d)

print(res)

Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<string> A(N);
    rep(i, N) cin >> A[i];
    
    int ans = 0;
    rep(a, N) {
//        cout << "--" << a << endl;
        bool ok = true;
        rep(i, N) rep(j, N) {
//            cout << A[i][j] << "," << A[(j + a) % N][(i - a + N) % N] << endl;
            if(A[i][j] != A[(j + a) % N][(i - a + N) % N]) ok = false;
        }
        if(ok) ans += N - a;
    }
    
    rep(a, 1, N) {
//        cout << "--" << a << endl;
        bool ok = true;
        rep(i, N) rep(j, N) {
//            cout << A[i][j] << "," << A[(j - a + N) % N][(i + a) % N] << endl;
            if(A[i][j] != A[(j - a + N) % N][(i + a) % N]) ok = false;
        }
        if(ok) ans += N - a;
    }
    output(ans);
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;

int n, m, r;
int p[8];
int cost[200][200];

signed main() {
	int i, j, k;
	
	cin >> n >> m >> r;
	for (i = 0; i < r; i++) { cin >> p[i]; p[i]--; }
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) cost[i][j] = 1145141919;
	for (i = 0; i < n; i++) cost[i][i] = 0;
	for (i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		cost[a][b] = cost[b][a] = c;
	}
	
	for (k = 0; k < n; k++) {
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
	
	int ans = 1145141919810;
	vector<int> perm;
	for (i = 0; i < r; i++) perm.push_back(i);
	
	do {
		int sumDist = 0;
		for (i = 1; i < r; i++) {
			sumDist += cost[p[perm[i - 1]]][p[perm[i]]];
		}
		ans = min(ans, sumDist);
	}while (next_permutation(perm.begin(), perm.end()));
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1144
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    l = list(map(int, input().split()))
    l.sort(reverse=True)
    x=(l[0]-l[1])+(l[0]-l[2])
    if x%2==0:
        print(x//2)
    else:
        print(x//2+2)
resolve()

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NMX = Sarray();
            var N = NMX[0];
            M = NMX[1];
            X = NMX[2];
            C = new long[N];
            A = new long[N][];
            var Asum = new long[M];
            for (var i = 0; i < N; ++i)
            {
                var ca = Sarray();
                C[i] = ca[0];
                A[i] = ca.Skip(1).ToArray();
                for (var j = 0; j < M; ++j)
                    Asum[j] += A[i][j];
            }
            if (Asum.Any(a => a < X))
            {
                WriteLine(-1);
                return;
            }
            var ans = dfs(N, 0, new long[M]);
            WriteLine(ans);
        }
        static long M;
        static long X;
        static long[] C;
        static long[][] A;
        static long dfs(long cnt, long cost, long[] Asum)
        {
            if (cnt <= 0)
            {
                if (Asum.Any(a => a < X))
                    return long.MaxValue;
                return cost;
            }
            var AsumS = new long[M];
            --cnt;
            for (var i = 0; i < M; ++i)
                AsumS[i] = Asum[i] + A[cnt][i];
            return Min(dfs(cnt, cost + C[cnt], AsumS), dfs(cnt, cost, Asum));//選んだ場合選ばなかった場合
        }
    }
}

Measured memory_bytes: 28912
#include <bits/stdc++.h>
#ifndef LOCAL
#pragma GCC optimize(3)
#endif
#define ls (rt<<1)
#define rs (rt<<1)|1
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e6+100;
const int mod=1e9+7;
ll loc[100][30];
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n, d;
    cin >> n >> d;
    for (int i=0; i<n; i++) {
        for (int j=0; j<d; j++) {
            cin >> loc[i][j];
        }
    }
    int ans=0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            ll dis=0;
            for (int k=0; k<d; k++) {
                dis += (loc[i][k] - loc[j][k]) * (loc[i][k] - loc[j][k]);
            }
            ll tmp = sqrt(dis);
            if (tmp * tmp == dis) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; ++i)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int Uniform_Random(int a, int b){ // (a <= x <= b)

  random_device rd;
  mt19937 mt(rd());
  
  uniform_int_distribution<int> rv1(a, b);
  return rv1(mt);
  
}
 
int main(){
  
  double n, k; cin >> n >> k;
  double ans = 0;

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

    int sum = i;
    double temp = 1 / n;

    while(sum < k){
      sum *= 2;
      temp /= 2;
    }

    ans += temp;
  }

  printf("%.10f\n", ans);

  return 0; 
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for ( int i = 1; i <= n; i++ ) cin >> a[i];

	int cnt = 0;
	for ( int i = 1; i <= n; i++ ) {
		if ( a[a[i]] == i ) cnt++;
	}

	cout << cnt / 2 << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int a,b,c,ab,abc,k,ck;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &k);
	ab = a + b;
	abc = a + b + c;
	ck = a - (k - ab);
	
	if(a >= k){
		printf("%d", k);
	}else{
		if(ab >= k){
			printf("%d", a);
		}else{
			printf("%d", ck);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1736
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int N    = scan.nextInt();
        int Q    = scan.nextInt();
        String S = scan.next();

        int[] acCount = new int[N];
        String subStr;


        for(int i = 0; i < N; i++) {

            if(i == 0){

              acCount[i] = 0;

            }else{

                subStr =S.substring(i-1,i+1);
                //System.out.println(subStr);

                if(subStr.equals("AC")){

                    acCount[i] = 1;
                }

                acCount[i] = acCount[i-1] + acCount[i];
            }

            //System.out.println(i+1 + "文字目まで:" + acCount[i]);
        }



        int[] ans = new int[Q];
        for(int i = 0; i < Q; i++) {

            int l    = scan.nextInt();
            int r    = scan.nextInt();

            ans[i] = acCount[r-1] - acCount[l-1];
        }



        for(int i = 0; i < Q; i++) {

            System.out.println(ans[i]);
        }



    }

}

Measured memory_bytes: 96296
d = gets.to_i
c = gets.split.map(&:to_i)
s = d.times.map{gets.split.map(&:to_i)}
t = d.times.map{gets.to_i}

last_event_dates = Array.new(26, 0)
satisfaction_sum = 0
t.each_with_index do |type, day|
  satisfaction_sum += s[day][type - 1]

  last_event_dates[type - 1] = day + 1
  c.each_with_index do |c_v, index|
    satisfaction_sum -= c_v * (day + 1 - last_event_dates[index])
  end

  puts satisfaction_sum
end

Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int dx[]={-1,0,1,-1,1,-1,0,1};
int dy[]={-1,-1,-1,0,0,1,1,1};
int main(){
    int h,w;
    cin>>h>>w;
    vs vec;
    vec.pb(string('.',w+2));
    REP(i,h){
        string t;
        cin>>t;
        string st=".";
        st+=t;
        st+=".";
        vec.pb(st);
    }
    vec.pb(string('.',w+2));
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            if(vec[i][j]=='#'){
                cout<<"#";
                continue;
            }
            int t=0;
            REP(k,8){
                if(vec[i+dx[k]][j+dy[k]]=='#'){
                    t++;
                }
            }
            cout<<t;
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
sys.setrecursionlimit(2*n)
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    graph[a].append((b, i))
    graph[b].append((a, i))

def DFS(node, p_node=-1, p_color=-1):
    color = 1
    for c_node, edge in graph[node]:
        if c_node==p_node:
            continue
        if color==p_color:
            color += 1
        ans[edge] = color
        DFS(c_node, node, color)
        color += 1
ans = [0]*(n-1)
DFS(0)
k = max(len(i) for i in graph)
print(k)
[print(i) for i in ans]

Measured memory_bytes: 85696
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		printf("%d", A[i]);
		if (i != n - 1)
			printf(" ");
	}
	printf("\n");
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}

typedef struct node
{
	int data;
	struct node* left, * right;
}NODE;

NODE* root = NULL;

void insert(int key)
{
	NODE** p, * new;

	p = &root;

	while (*p != NULL)
	{
		if (key == (*p)->data)
			return NULL;
		else if (key < (*p)->data)
			p = &(*p)->left;
		else
			p = &(*p)->right;
	}

	if ((new = (NODE*)malloc(sizeof(NODE))) == NULL)
		printf("error\n");

	new->left = new->right = NULL;
	new->data = key;
	*p = new;
}

void inorder(NODE* p)
{
	if (p == NULL)
		return;
	else
	{
		inorder(p->left);
		printf(" %d", p->data);
		inorder(p->right);
	}
}

void preorder(NODE* p)
{
	if (p == NULL)
		return;
	else
	{
		printf(" %d", p->data);
		preorder(p->left);
		preorder(p->right);
	}
}

void print_tree(NODE* p)
{
	inorder(p);
	printf("\n");
	preorder(p);
	printf("\n");
}

int main()
{
	int m;
	char str[10];
	int num;

	scanf("%d", &m);

	int i;

	for (i = 0; i < m; i++)
	{
		scanf("%s",str);
		if (strcmp(str, "insert") == 0)
		{
			scanf("%d", &num);
			insert(num);
		}
		else
			print_tree(root);
	}

	return 0;
}


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

int n, key, j;

void print(int a[]) {
  for(int i = 0; i < n; ++i)
    cout << (i!=0?" ":"") << a[i];
  cout << endl;
}

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

    for (int i=1; i<n; i++) {
        key = a[i];
        j = i - 1;
        while( j >= 0 and a[j] > key) {
            a[j+1] = a[j];
            j--;            
        }
        a[j+1] = key;
        print(a);
    }
    return 0;
}



Measured memory_bytes: 3068
// n using Sieve of Eratosthenes 
#include <bits/stdc++.h> 
#include <iostream>
#include <cmath>
using namespace std;
# define M_PI 3.14159265358979323846 
#define ll long long int
 
int main(){
ll n;cin>>n;
ll a[n]={0};
for(int i=0;i<(n-1);i++){
    ll x;cin>>x;
    a[x-1]++;
}
for(int i=0;i<n;i++) cout<<a[i]<<"\n";
return 0;	
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define REPR(i,n) for (int i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORE(x,xs) for (auto& x : xs)

const int MAX = 1e5+10;
const int ROOT = 0;
int N, MOD;
vi G[MAX], child[MAX];
ll dp1[MAX]; // dp1[v]:0を根としたとき、vを黒としたときのvより下の場合の数
ll dp2[MAX]; // dp2[v]:0を根としたとき、vを黒としてvより下が全部白の時の場合の数
vi mult1[MAX]; // mult1[v][i]:vの子jのdp1[j]を小さい方からi-1までかけたもの
vi mult2[MAX]; // mult2[v][i];vの子jのdp1[j]を大きい方からi+1までかけたもの
int parent[MAX];
int num[MAX]; // num[v]:vがparent[v]の何番目の子

void dfs1(int v, int p) {
    parent[v] = p;
    dp1[v] = 1;
    int count = 0;
    FORE (x, G[v]) {
        if (x == p) continue;
        dfs1(x, v);
        (dp1[v] *= dp1[x]+1) %= MOD;
        child[v].push_back(x);
        num[x] = count++;
    }
}

void calcMult(int v) {
    if (child[v].size() == 0) return;
    mult1[v] = mult2[v] = vi(child[v].size());
    mult1[v][0] = 1;
    REP (i, child[v].size()-1) {
        (mult1[v][i+1] = mult1[v][i] * (dp1[child[v][i]]+1)) %= MOD;
    }
    mult2[v][child[v].size()-1] = 1;
    REPR (i, child[v].size()-1) {
        (mult2[v][i] = mult2[v][i+1] * (dp1[child[v][i+1]]+1)) %= MOD;
    }
    FORE (x, child[v]) calcMult(x);
}

void dfs2(int v) {
    dp2[v] = 1;
    if (parent[v] != v) {
        int p = parent[v], c = num[v];
        dp2[v] = (dp2[p] * (mult1[p][c] * mult2[p][c] % MOD)+1) % MOD;
    }
    FORE (x, child[v]) dfs2(x);
}

int main () {
	cin >> N >> MOD;
    REP (i, N-1) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs1(ROOT, ROOT);
    calcMult(ROOT);
    dfs2(ROOT);

    REP (i, N) cout << dp1[i] * dp2[i] % MOD << endl;
}

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

int main() {
	long n, m;
	cin >> n >> m;
	long ans = 1;
	if (n == 1) {
		cout << m << endl;
		return 0;
	}
	for (long i = 2; i * n <= m; i++) {
		if ((m - i * n) % i == 0)ans = i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256