akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n , k;
  double ans = 0;
  cin>>n>>k;
  double dice;
  double coin;

  for(int i = 1; i <= n; i++ ){
    int j = 1;
    int temp;
    temp = i;
    while(k > temp){
      temp *= 2;
      j *= 2;
    }
    double dice = n;
    double coin = j;
    ans += (1.00000000000/dice)*(1.00000000000/coin);
    //cout<<"i ="<<i<<", dice = "<<dice<<", coin = "<<coin<<", ans = "<<ans<<endl;
  }
  cout << setprecision(10)<<ans << endl;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;



int main(void)
{
	//変数の宣言
	int n,m;
	int a,b;
	ll d[100];
	char s[100010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	int vec[100010];
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	char stemp[100010];
	
	//データの読み込み


//	scanf("%d",&n);
//	scanf_s("%d",&n);

	scanf("%s",&s);
//	scanf_s("%s",&s,100010);


/*	for(i=0;i<n;i++){
//		scanf("%d",&b[i]);
		scanf_s("%d",&b[i]);
	}*/


/*	for(i=0;i<3;i++){
//		scanf("%s",&s);
		scanf_s("%s",&s[i],100010);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();

	for(i=0;i<4;i++){
		vec[i]=s[i]-'0';
	}

	for(i=0;i<8;i++){
		ans=vec[0];
		for(j=0;j<3;j++){
			if(i&(1<<j)){
				ans += vec[j+1];
				s[j+10]='+';
			}else{
				ans -= vec[j+1];
				s[j+10]='-';
			}
		}
		if(ans==7){
			printf("%d%c%d%c%d%c%d=7",vec[0],s[10],vec[1],s[11],vec[2],s[12],vec[3]);
			return 0;
		}
	}




//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%lld",d[n]);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
*A, = map(int, input().split())
dp = [False] * (K+1)
for i in range(1, K+1):
    for a in A:
        if i - a < 0: break
        dp[i] |= not dp[i-a]
print('First' if dp[K] else 'Second')

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

int main(){
 int L,R,D;

 cin>>L>>R>>D;

  int cnt = 0;
 for(int i = L;i<=R;i++){
     if(i%D == 0) cnt++;
 }
 cout<<cnt<<endl;
 return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[6];
  int ans=0;
  for(int i=1;i<=5;i++)cin>>a[i];
  for(int i=1;i<=5;i++){
  	ans+=(a[i]/10)*10;
  }
  int t=0x3f3f3f3f;
  int p=0;
  for(int i=1;i<=5;i++){
  	int x=a[i]%10;
    if(x<t&&x){
   		t=x;
      	p=i;
    }
  }
  if(p)ans+=t;
  for(int i=1;i<=5;i++){
  	if(i==p)continue;
    if(a[i]%10)ans+=10;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

int powM(int x, int n, int mod_n=MOD_N) {
   int res = 1;
   while (n > 0) {
      if ((n & 1) == 1) (res *= x) %= mod_n;
      (x *= x) %= mod_n;
      n >>= 1;
   }
   return res;
}

signed main()
{
   int n, m; cin >> n >> m;
   cout << powM(n, m) << endl;

   return 0;
}



Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a + b == c || b + c == a || c + a == b) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1664
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<map>
#include<set>
#define ll long long
#define dou(s) atof(s.c_str())
#define lon(s) atoll(s.c_str())
#define str(n) to_string(n)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define fion(n) fixed<<setprecision(n)
#define endl "\n"
#define OR ||
#define AND &&
#define NOT !
#define line(s) getline(cin,s)
#define fdarst(a,n) (a[a.size()-1]>=n&&a[lower_bound(ALL(a),n)-a.begin()]==n?lower_bound(ALL(a),n)-a.begin():-1)
#define fist(s,t) ((int)s.find(t))
#define START int main(){cin.tie(0);ios::sync_with_stdio(false);
#define END }
using namespace std;
START
ll n; cin >> n;
vector<ll> a(n);
rep(i, 0, n)cin >> a[i];
sort(ALL(a));
ll m; cin >> m;
ll k, ans;
rep(o, 0, m) {
	cin >> k;
	if (fdarst(a, k) != -1)ans++;
}
cout << ans << endl;
END


Measured memory_bytes: 3188
n,m=map(int,input().split())
e=[tuple(map(int,input().split())) for _ in range(m)]
d=[0]+[-float('inf')]*(n-1)
for _ in range(n-1):
    for a,b,c in e:
        d[b-1]=max(d[b-1],d[a-1]+c)
r=d[n-1]
for _ in range(n-1):
    for a,b,c in e:
        d[b-1]=max(d[b-1],d[a-1]+c)
if d[n-1]==r:
    print(r)
else:
    print('inf')

Measured memory_bytes: 46808
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#define SIZE 105

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

int A[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	int ret=0;
	bool up=false;
	for(int i=1;i<n;i++)
	{
		if(!up&&A[i]==A[i-1])
		{
			ret++;
			up=true;
		}
		else up=false;
	}
	printf("%d\n",ret);
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int c[300] = {0};
	for(int i = 0; i < n; i++){
		c[(int)s[i]]++;
	}
	ll ans = 1;
	for(int i = 0; i < 300; i++)ans *= c[i]+1, ans %= 1000000007;
	cout << ans-1 << endl;
    return 0;
}

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

vector<pair<LL,LL>> v;
bool cmp(pair<LL,LL> a, pair<LL,LL> b){
    return (a.first-a.second) > (b.first-b.second);
}
LL sa[100010], sb[100010];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x, y, z;
    long long a, b, c, ans = 0;
    cin >> x >> y >> z;
    int n = x+y+z;
    for(int i=0; i<n; i++){
        cin >> a >> b >> c;
        v.push_back({a-c,b-c});
        ans += c;
    }
    sort(v.begin(),v.end(),cmp);
    priority_queue<LL> pa, pb;
    LL suma = 0, sumb = 0;
    for(int i=0; i<x; i++) pa.push(-v[i].first), suma += v[i].first;
    for(int i=0; i<y; i++) pb.push(-v[n-1-i].second), sumb += v[n-1-i].second;
    sa[x-1] = suma;
    sb[n-y] = sumb;
    for(int i=x; i<n; i++){
        if( v[i].first > -pa.top() ){
            suma += v[i].first + pa.top();
            pa.pop();
            pa.push(-v[i].first);
        }
        sa[i] = suma;
    }
    for(int i=n-1-y; i>=0; i--){
        if( v[i].second > -pb.top() ){
            sumb += v[i].second + pb.top();
            pb.pop();
            pb.push(-v[i].second);
        }
        sb[i] = sumb;
    }
    LL Max = -1e18;
    for(int i=x-1; i<n-y; i++){
        Max = max( Max, sa[i]+sb[i+1] );
    }
    cout << ans + Max << "\n";
    return 0;
}

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

class Bubble{
	int *p;
	int size;
public:
	Bubble();
	Bubble(const Bubble&);
	Bubble& operator=(const Bubble&);
	void input();
	void narabekae();
	int get_size()const{ return size; };
	~Bubble();
};

Bubble::Bubble(){
	int comp;
	cin>>comp;
	this->size = comp;
	p = new int[get_size()];
}

Bubble::Bubble(const Bubble& x){
	p = new int[x.get_size()];
}

Bubble& Bubble::operator=(const Bubble& x){
	if(this==&x) return *this;
	delete p;
	p = new int[x.get_size()];
	return *this;
}

Bubble::~Bubble(){
	delete [] p;
}

void Bubble::input(){
	for(int i=0;i<get_size();i++)
		cin>>*(p+i);
}

void Bubble::narabekae(){
	int flag = 1;
	int count = 0;
	while(flag){
		flag = 0;
		for(int j=get_size()-1;j!=0;j--){
			if(p[j-1]>p[j]){
				int temp = p[j-1];
				p[j-1] = p[j];
				p[j] = temp;
				flag = 1;
				count++;
			}
		}
	}

	for(int i=0;i<get_size();i++){
		if(i!=get_size()-1){
			cout<<p[i]<<" ";
		}else{
			cout<<p[i]<<endl;
		}
	}
	cout<<count<<endl;
}

int main(){

	Bubble test;
	test.input();
	test.narabekae();

	cin.get();
	cin.get();
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;
long long v[100001];
long long over;

int main(){

    long long n;
    cin >> n;

    long long val;
    for(long long i = 0; i < n; i++){
        cin >> val;
        if(val > 100000){
            over += 1;
        }
        else{
            v[val] ++;
        }
    }

    long long ans = 0;
    for(long long i = 0; i <= 100000; i++){
        if(v[i] > i){
            ans += v[i] - i;
            v[i] = 0;
        }
        if (v[i] < i) {
            ans += v[i];
            v[i] = 0;
        }
    }
    //*/
    cout << ans + over << endl;

}

Measured memory_bytes: 1024
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */
 
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
 
#define all(x) x.begin(), x.end()
#define MOD 1000000007
 
const long double PI = 3.141592653589793236L;
 
typedef long long int ll;
typedef long double ld;
 
using namespace std;
 
void solve()
{
    ll N;
    cin >> N;

    ll n = N;

    ll p = 2;
    ll count = 0;

    set<ll> primes;

    if(N % 2 == 0)
    {
        while(N % 2 == 0)
        {
            N /= p;
        }
        primes.insert(p);
    }


    for(ll i = 3; i * i <= N; i += 2)
    {
        if(N % i == 0)
        {
            primes.insert(i);
            while(N % i == 0)
            {
                N /= i;
            }
        }
    }

    if(N > 2)
    {
        primes.insert(N);
    }

    set<ll> S;

    N = n;

    for(ll x : primes)
    {
        ll p = x;
        while(p <= N)
        {
            S.insert(p);
            p *= x;
        }
    }

    for(ll x : S)
    {
        if(N % x == 0)
        {
            N /= x;
            count++;
        }
    }

    cout << count << endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int T = 1;
    //cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 3664
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }
    var min = 2L
    var max = 2L
    for (i in N - 1 downTo 0) {
        if (A[i] > min || min > max) {
            println("-1")
            return
        }
        max += A[i] - 1
        if (i == 0) break
        max = max / A[i - 1] * A[i - 1]
        min = ((min - 1) / A[i - 1] + 1) * A[i - 1]
    }
    println("$min $max")
}


Measured memory_bytes: 59660
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int Cost[3][30];
signed main() {
	int n, c;
	cin >> n >> c;
	int Grid[n][n], Color[c][c];
	map<int, int> mp[3];
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> Color[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> Grid[i][j];
			if ((i + j) % 3 == 0) {
				mp[0][Grid[i][j]]++;
			}
			if ((i + j) % 3 == 1) {
				mp[1][Grid[i][j]]++;
			}
			if ((i + j) % 3 == 2) {
				mp[2][Grid[i][j]]++;
			}
		}
	}
	// 剰余の場合分けのmpの中身
	// cout << endl;
	// for (int i = 0; i < 3; i++) {
	// 	for (auto e : mp[i]) {
	// 		cout << e.first << " " << e.second << endl;
	// 	}
	// 	cout << endl;
	// }

	int Cost[3][30] = {{}};
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < c; j++) {
			for (auto e : mp[i]) {
				Cost[i][j] += (e.second * (Color[e.first - 1][j]));
				// cout << "e.first:" << e.first << " e.second:" << e.second << " i:" << i << " j:" << j << " Color[e.first][j]:" << Color[e.first - 1][j] << " Cost[i][j]:" << Cost[i][j] << " e.second * (Color[e.first - 1][j]):" << e.second * (Color[e.first - 1][j]) << endl;
			}
		}
	}
	int Ans = INF;
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			for (int k = 0; k < c; k++) {
				if (i != j && j != k && i != k) {
					Ans = min(Ans, Cost[0][i] + Cost[1][j] + Cost[2][k]);
					// cout << "i:" << i << " j:" << j << " k:" << k << " ";
					// cout << Cost[0][i] << " " << Cost[1][j] << " " << Cost[2][k] << endl;
				}
			}
		}
	}
	cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <string.h>
#include <ctype.h>

void b_rot(char s[]){
	int i;
	char buf=s[0];
	size_t last = strlen(s)-1;
	for(i=0;i<last;i++){
		s[i] = s[i+1];
	}
	s[i] = buf;
}

int main(){
	char s[200];
	char s_cp[200];
	int i,j,num,block[100];
	while(1){
		scanf("%s",s);
		if(!strcmp(s,"-"))break;
		scanf("%d",&num);
		for(i=0;i<num;i++){
			scanf("%d",&(block[i]));
		}
		for(i=0;i<num;i++){
			for(j=0;j<block[i];j++){
				b_rot(s);
			}
		}
		printf("%s\n",s);
	}
	return 0;
}

Measured memory_bytes: 588
let (a, b, h, m) = Scanf.sscanf (read_line ()) "%d %d %d %d" @@ fun a b h m -> (a, b, h, m)

let pi = 3.14159265358

let () =
  let t = 2. *. (float h /. 12. +. float m /. 60. /.12.) in
  let s = 2. *. (float m /. 60.) in
  let diff = ref (t -. s) in
  if !diff < 0. then diff := -1. *. !diff;
  let c2 = (float @@ a * a) +. (float @@ b * b) -. (float @@ 2 * a * b) *. cos (!diff *. pi) in
  print_float @@ sqrt c2;


Measured memory_bytes: 4336
#include <stdio.h>
#include <string.h>
 
#define M 1046527
#define L 14
 
char H[M][L];
 
int char2int(char c) {
  switch (c) {
    case 'A': return 1;
    case 'C': return 2;
    case 'G': return 3;
    case 'T': return 4;
    default: return 0;
  }
}
 
long long getKey(char str[]) {
  long long ret = 0, p = 1;
  int i;
  for(i = 0; str[i] != '\0'; i++) {
    ret += p * char2int(str[i]);
    p *= 5;
  }
  return ret;
}
 
int h1(int key) {
  return key % M;
}
 
int h2(int key) {
  return 1 + (key % (M - 1));
}
 
int find(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}
 
int insert(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}
 
int main(void) {
  int i, n;
  char str[L], cmd[9];
  for(i = 0; i < M; i++) {
    /* initialize hash */
    H[i][0] = '\0';
  }
 
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s %s", cmd, str);
 
    if(cmd[0] == 'i') {
      insert(str);
    } else {
      if(find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    /*int a,b,c,d,f;
    cin>>a>>b>>c>>d>>f;
    int ar[10];
    ar[a]=1;
    ar[b]=2;
    ar[c]=3;
    ar[d]=4;
    ar[f]=5;
    cout<<ar[0]<<endl;*/
    /*int x,y;
    cin>>x>>y;
    if(y>=x*2&&y<=x*4&&y%2==0)cout<<"Yes\n";
    else cout<<"No\n";*/
    /*int x,n,p;
    cin>>x>>n;
    mii m;
    for(int i=0;i<n;i++){
        cin>>p;
        m[p]=1;
    }
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    int a=x;
    for(int i=1;i<=1000;i++){
        if(m[a]==0){
            cout<<a<<endl;
            return 0;
        }
        if(m[x]==0){
            cout<<x<<endl;
            return 0;
        }
        a--;
        x++;
    }*/
    int n,a,maxx=0;
    cin>>n;
    si st;
    si :: iterator it;
    mii m;
    for(int i=0;i<n;i++){
        cin>>a;
        st.insert(a);
        maxx=max(maxx,a);
        m[a]++;
    }
    int ans=0;
    for(it=st.begin();it!=st.end();it++){
        int b=*it;
        if(m[b]==1)ans++;
        for(int j=b;j<=maxx;j+=b){
            m[j]=0;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 57540
#ABC-138-C
N = int(input())
V = list(map(int, input().split()))

sorted_V = sorted(V)
value = 0
product_value = (sorted_V[0] + sorted_V[1]) / 2

for i in range(2, N):
    product_value = (product_value + sorted_V[i]) / 2

print(product_value)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, p, A=0, W=0;
  string S;
  
  cin >> N >> M;
  vector<int> cA(N);
  vector<int> cW(N);
  
  for(int i=0; i<M; i++){
    
    cin >> p >> S;
    
    if(S=="AC" && cA.at(p-1)==0){
      A++;
      W += cW.at(p-1);
      cA.at(p-1) = 1;
    }else if(cA.at(p-1)==0)
      cW.at(p-1)++;
    // W+=1;

  }
  
  cout << A << " " << W << endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args)  {
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        set.add(3);
        String line;
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            while((line = br.readLine()) != null) {
                int num = Integer.parseInt(line);
                set.remove(num);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(set.iterator().next());
    }
}

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

int main()
{
  int N;
  while (cin >> N && N != 0) {
    vector<pair<int,int> > squares(N);
    squares[0] = make_pair(0, 0);
    int max_height = 0, min_height = 0, max_width = 0, min_width = 0;
    for (int i = 1; i < N; i++) {
      int n, d;
      cin >> n >> d;
      squares[i] = squares[n];
      switch (d) {
        case 0:
          squares[i].second--;
          min_width = min(min_width, squares[i].second);
          break;
        case 1:
          squares[i].first--;
          min_height = min(min_height, squares[i].first);
          break;
        case 2:
          squares[i].second++;
          max_width = max(max_width, squares[i].second);
          break;
        case 3:
          squares[i].first++;
          max_height = max(max_height, squares[i].first);
          break;
      }
    }
    cout << (max_width - min_width + 1) << ' ' << (max_height - min_height + 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,j,n) for (int i = j; i < (n); ++i)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
typedef long long ll;
typedef vector<int> vi;


int main(){
    int n;
    cin >> n;
    vi L(n);
    rep(i,n){
        cin >> L[i];
    }
    SORT(L);
    int ans = 0;
    rep(b,n){
        rep(a,b){
            int ab = L[a] + L[b];
            int r = lower_bound(L.begin(),L.end(),ab) - L.begin();
            int l = b+1;
            ans += r-l;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&m);
  if(2*n<=m && 4*n>=m & m%2==0) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}



Measured memory_bytes: 1660
fun main(args: Array<String>){
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val num = IntArray(N+1){ 1 }
    val isRed = BooleanArray(N+1){ false }
    isRed[1] = true
    repeat(M){
        val (X, Y) = readLine()!!.split(" ").map { it.toInt() }
        num[X]--
        num[Y]++
        if(isRed[X]){
            isRed[Y] = true
        }
        if(num[X] == 0){
            isRed[X] = false
        }
    }
    println(isRed.filter { it }.count())
}

Measured memory_bytes: 56568
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = s; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    vector<bool> check(n, false);
    REP(i, n) cin >> as[i];
    int nb = 0, cnt=0;
    int ret = -1; 
    while (true) {
        check[nb] = true;
        nb = as[nb]-1;
        ++cnt;
        if (nb == 1) {
            ret = cnt;
            break;
        }
        if (check[nb]) break;
    } 
    cout << ret << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a,b,c,tmp;
    cin >> a >> b >> c;
    if (a < b) {
      tmp = a;
      a = b;
      b = tmp;
    }
    if (a < c) {
      tmp = a;
      a = c;
      c = tmp;
    }
    if (a*a == b*b + c*c) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, a;
  cin >> n >> a;
  
  if(a%2!=0){
    cout << "No" << endl;
    return 0;
  }
  
  if(n*2<=a&&n*4>=a){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		
		long ans = 0;
		for (int i = 0; i < 1 << (N - 1); i++) {
			int last = 0;
			for (int j = 0; j < N - 1; j++) {
				if ((1 & i >> j) == 1) {
					ans += Long.parseLong(S.substring(last, j + 1));
					last = j + 1;	
				}
			}
			ans += Long.parseLong(S.substring(last, N));
		}
		System.out.println(ans);
	}
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int a, p;

int main(void) {
  // Here your code !
  scanf("%d %d", &a, &p);

  p += a * 3;

  printf("%d\n", p / 2);

  return 0;
}


Measured memory_bytes: 256
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<int> a(N),b(N-1);
    rep(i,N-1) cin >> b[i];
    a[0] = b[0];
    a[N-1] = b[N-2];
    for(int i=1;i<N-1;i++){
        a[i] = min(b[i],b[i-1]);
    }
    int ans = 0;
    rep(i,N) ans += a[i];
    cout << ans << nn;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';
 
typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

inline ll add(ll a, ll b){
  return ((a % mod) + (b % mod)) % mod;
}
inline ll sub(ll a, ll b){
  return ((a % mod) - (b % mod) + mod) % mod;
}
inline ll mul(ll a, ll b){
  return ((a % mod) * (b % mod)) % mod;
}
inline ll modexpo(ll a, ll b){
  ll res = 1;
  while(b){
    if(b & 1){
      res = mul(res, a);
    }
    a = mul(a, a);b /= 2;
  }
  return res;
}
inline ll divide(ll a, ll b){
  return mul(a, modexpo(b, mod - 2));
}
 
clock_t time_p = clock();
 
void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}
  
int main(){
  fastio

  ll n, i, j, k, ans = 0;
  cin>> n;
  ll a[n];
  forn(0, n, i){
    cin >> a[i];
  }

  forn(0, n, i){
    ll now = 0;
    forn(i + 1, n, j){
      if(a[j] > a[j - 1])
        break;
    }
    ll len = j - i;
    ans = max(ans, len);
    i = j - 1;
  }

  cout << ans - 1 << '\n';
 
  ktj();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<cmath>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
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; }


int main(){
    int N,K;
    cin>>N>>K;
    int ans=0;
    vector<int>d(K);
    set<int>A;
    rep(i,K){
        int count;
        cin>>count;
        rep(l,count){
            cin>>d.at(i);
            A.insert(d.at(i));
        }
        
    }

    cout<<N-A.size();
}

Measured memory_bytes: 3580
#pragma warning(disable:4996)


#include<iostream>
#include<algorithm>
//#include<unordered_map>
#include<fstream>
#include<iomanip>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#define INF 0x3f3f3f3f
#define inf 0x7FFFFFFF
#define MOD 1000000007
#define pii pair<ll,ll>
#define eps 1e-8
#define equals(a,b) (fabs(a-b)<eps)
#define bug puts("bug")
#define re  register
#define fi first
#define se second
const int maxn = 1e7+ 5;
const double Inf = 10000.0;
const double PI = acos(-1.0);
typedef  long long ll;
using namespace std;

int n;
ll d[maxn], minn[maxn], prime[maxn];
bool is[maxn];
int tot;

void init() {
	d[1] = 1;
	for (int i = 2; i <= n; i++)
	{
		if (is[i] == 0) prime[++tot] = i, d[i] = 2, minn[i] = 1;
		for (re int j = 1; prime[j] * i <= n && j <= tot; j++)
		{
			is[i * prime[j]] = 1;
			if (i % prime[j] == 0)
			{
				minn[i * prime[j]] = minn[i] + 1;
				d[i * prime[j]] = d[i] / (minn[i] + 1) * (minn[prime[j] * i] + 1);
				break;
			}
			minn[i * prime[j]] = 1;
			d[i * prime[j]] = d[i] * 2;
		}
	}
}

int main() {
	scanf("%d", &n);
	init();
	ll res = 0;
	for (int i = 1; i <= n; i++) {
		res += i * d[i];
	}
	printf("%lld", res);
}

Measured memory_bytes: 175028
//Optimisation Flags
#pragma GCC optimize ("O3")
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC optimize("Ofast")

#include   <bits/stdc++.h>
//#include   <ext/pb_ds/assoc_container.hpp>
//#include   <ext/pb_ds/tree_policy.hpp>
#include   <algorithm>
#include   <queue>
#include   <list>
#include   <map>
#include   <math.h>
#include   <numeric>
using      namespace        std;
#define    endl             '\n'
#define    FAST             ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define    ipfile           ifstream cin ("input.txt");std::cin.rdbuf(std::cin.rdbuf())
#define    pb(x)            push_back(x)
#define    int              long long int
#define    itn              unsigned long long int
#define    db               long double
#define    vll              vector<int>
#define    all(v)           v.begin(),v.end()
#define    rall(v)          v.rbegin(),v.rend()
#define    GCD(m,n)         __gcd(m,n)
#define    LCM(m,n)         m*(n/GCD(m,n))
#define    REVVEC(v)        reverse(v.begin(),v.end())
#define    REVARR(a)        reverse(a,a+n)
#define    maxc(v)          max_element(all(v))
#define    minc(v)          min_element(all(v))
#define    inputarr(a,n)    for(int xxx=0;xxx<n;++xxx) cin>>a[xxx]
#define    outputarr(a,n)   for(int xxx=0;xxx<n;xxx++) cout<<a[xxx]<<" "
#define    rep(i,m, n)      for(int i = m; i < (n); ++i)
#define    sp               setprecison(10)
#define    sz(a)            (int)a.size()
#define    erase(vec,val)   vec.erase(std::remove(vec.begin(), vec.end(), val), vec.end()); //deleting specific value element in vector
#define    PI               (db)3.141592653589793238462643383279502884197169399375105820974944
#define    inf              (int)1000000000
#define    mod              (int)1000000007
#define    mem(a,b)          memset(a,b,sizeof(a));
#define    w(x)              int T;cin>>T;while(T -- > 0)
#define    ff                first
#define    ss                second
#define    pqueue            priority_queue< int >
#define    pdqueue           priority_queue< int,vll ,greater< int > >

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

clock_t time_p = clock();

void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}


void solveTC(){

        int w,s;
        cin>>s>>w;

        if(w>=s)
            cout<<"unsafe\n";
        else
            cout<<"safe\n";

}

int32_t main()
{

    FAST

 //   w(x){

        solveTC();

  //  }

    time();

    return 0;

}

Measured memory_bytes: 3796
/*
* @Author: Kabid
* @Date:   2020-04-26 18:01:07
* @Last Modified by:   Kabid
* @Last Modified time: 2020-04-26 18:10:44
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>

#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');

int t;       //test cases
int i=1,j;	 //iterators
int n,k,p;   //variables
int w,s;
int a,b,c,d;
int main(){
	in(a) in(b) in(c) in(d)
	while(i++){
		if(i%2==0){
			c-=b;
			if(c<=0){
				puts("Yes");
				break;
			}
		}
		else{
			a-=d;
			if(a<=0){
				puts("No");
				break;
			}
		}
	}	
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    if(a1 < b1){
        swap(a1, b1);
        swap(a2, b2);
    }
    if(t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2){
        cout << "infinity" << endl;
        return 0;
    }
    if(t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2){
        cout << 0 << endl;
        return 0;
    }
    ll mdif = t1 * a1 - t1 * b1;
    ll ldif = (t1 * b1 + t2 * b2) - (t1 * a1 + t2 * a2);
    if(mdif % ldif == 0) cout << mdif / ldif * 2 << endl;
    else cout << (mdif / ldif) * 2 + 1 << endl;
}

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

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

    std::vector<std::vector<int>> a(2, std::vector<int> (n));
    int r, c;
    for(int i = 0; i < 2; ++i){
        for(int j = 0; j < n; ++j){
            std::cin >> a.at(i).at(j);
        }
    }

    std::vector<int> candies(n, 0);
    for(int i = 0; i < n; ++i){
        candies.at(i) += std::accumulate(a.at(0).begin(), a.at(0).end() - i, 0);
        candies.at(i) += std::accumulate(a.at(1).end() - (i + 1), a.at(1).end(), 0);
    }

    std::cout << *max_element(candies.begin(), candies.end()) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
//頂点の数n
int d[201][201];
void wf(int n){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            if(d[i][k]==INF)continue;
            for(int j=0;j<n;j++){
                if(d[k][j]==INF)continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main(void){
    int n,m,r;
    cin>>n>>m>>r;
    for(int i=0;i<201;i++){
        for(int j=0;j<201;j++){
            if(i==j)d[i][j]=0;
            else d[i][j]=INF;
        }
    }
    vector<int>town(r);
    for(int i=0;i<r;i++){
        cin>>town[i];
        town[i]--;
    }
    sort(town.begin(),town.end());
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    wf(n);
    ll ans=INF;
    do{
        ll tmp=0;
        for(int i=0;i<=r-2;i++){
            tmp+=d[town[i]][town[i+1]];
        }
        ans=min(ans,tmp);
    }while(next_permutation(town.begin(),town.end()));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[100005],b[100005];
int vis[100005];
struct node{
    int id,a,b,c;
    node(int id=0,int a=0,int b=0,int c=0):id(id),a(a),b(b),c(c){}
    friend bool operator < (node a,node b){
        if(a.c==b.c){
            return max(a.a,a.b)<max(b.a,b.b);
        }return a.c<b.c;
    }
};

int main(){
    priority_queue<node> q;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",a+i,b+i);
        q.push(node(i,a[i],b[i],abs(a[i]+b[i])));
    }
    int cnt=n;
    ll ans=0;
    int now=0;
    while(cnt--){
        if(!now){
            ans+=q.top().a;q.pop();
        }
        else{
            ans-=q.top().b;q.pop();
        }
        now^=1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2932
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] s = br.readLine().split(" ");
		int[] arr = new int[n + 1];
		long[] rsum = new long[n + 1];
		long[][] dp = new long[n + 1][n + 1];
		
		for (int i = 1; i <= n; i++) {
			arr[i] = Integer.parseInt(s[i - 1]);
			dp[i][i] = arr[i];
		}			

		for (int i = 2; i <= n; i++) {
			for (int j = i - 1; j > 0; j--) {
				dp[i][j] = Math.max(arr[j] - dp[i][j+1], arr[i] - dp[i-1][j]);
				
//				System.out.print("[" + i + " " + j + "](" + dp[i][j][0] + " " + dp[i][j][1] + ") ");
			}
//			System.out.println();
		}

		System.out.println(dp[n][1]);
	}

}

//use for actual values OR use system of linear equation
//long first = dp[i][j + 1][1] + arr[j];
//long last = dp[i - 1][j][1] + arr[i];
//
//if (first > last) {
//	dp[i][j][0] = first;
//	dp[i][j][1] = rsum[i] - rsum[j - 1] - first;
//} else {
//	dp[i][j][0] = last;
//	dp[i][j][1] = rsum[i] - rsum[j - 1] - last;
//}


Measured memory_bytes: 128720
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int X;
  cin>>X;
  if(X==7 or X==5 or X==3)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

using namespace std;

#define pb push_back
#define NL endl
#define pi 2.0*acos(0.0)
#define mod 1e9+7
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

set<ll>cset[30];

int main(){
    fastIO;
    ll n,q,a,b,c,pos,ans = 0;
    string s;
    char d,curr;
    cin>>n>>s>>q;
    FOR(i,0,n){
        cset[s[i] - 'a'].insert(i+1);
    }
    FOR(i,0,26){
        cset[i].insert(1e18);
    }
    while(q--){
        cin>>a;
        if(a == 1){
            cin>>b>>d;
            curr = s[b-1];
            cset[curr - 'a'].erase(b);
            cset[d - 'a'].insert(b);
            s[b - 1] = d;
        }
        else{
            cin>>b>>c;
            ans = 0;
            FOR(i,0,26){
                if(cset[i].size()){
                    auto lower = cset[i].lower_bound(b);
                    if(*lower == 1e18){}
                    else{
                        ll val = *lower;
                        if(val >= b && val <= c) ans++;
                    }
                }
            }
            cout<<ans<<endl;
        }
    }
}


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

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int f(int u, vector<vector<int> > &G, vector<int> &dp) {
	if(dp[u] != -1) return dp[u];
	int x = 0;
	for(int v: G[u]) {
		x = max(f(v, G, dp) + 1, x);
	}
	dp[u] = x;
	return x;
}

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<int> > G(n + 1);
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
	}
	vector<int> dp(n + 1, -1);
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		ans = max(ans, f(i, G, dp));
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	solve();
	
	return 0;
}


Measured memory_bytes: 11704
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<string.h>

using namespace std;

struct Node {
	int key;
	Node* prev;
	Node* next;
};

Node* nil;

Node* listsearch(int x) {
	Node* cur = nil->next;

	while (cur != nil && cur  -> key != x) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node*)malloc(sizeof(Node));
	nil->prev = nil;
	nil->next = nil;
}

void printList() {
	Node* cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil) { break; }
		if (isf++ > 0) { printf(" "); }
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if (t == nil) { return; }
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listsearch(key));
}

void insert(int key) {
	Node* x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	x->prev = nil;
	nil->next = x;
}

int main() {
	int key, n, i;
	
	char com[20];


	scanf("%d", &n);
	init();

	for (int i = 0; i < n; ++i) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); }
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') { deleteFirst(); }
				else if (com[6] == 'L') { deleteLast(); }
			}
			else {
				deleteKey(key);
			}
		}
	}
	printList();
}


Measured memory_bytes: 34452