akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  
using namespace std;
  
#define MAX 15
#define INF 1e9
  
int N;
int path[1<<MAX][MAX];
double dp[1<<MAX][MAX];
double _time, d[MAX], B[MAX];
int n[MAX];
vector<int> ans;
  
double V(double w)
{
    return 2000. / (70. + w);
}
  
double dist(int a, int b)
{
    return abs(d[a] - d[b]);
}
  
double solve(int S, int prev, double b)
{
    if (N == __builtin_popcount(S)) return dp[S][prev] = 0.0;
    if (dp[S][prev] >= 0) return dp[S][prev];
    double res = INF;
    for (int i = 0; i < N; i++) {
	if (S >> i & 1) continue;
	double next = solve(S|(1<<i), i, b+B[i]) + dist(prev,i)/V(b);
	if (next < res) {
	    res = next;
	    path[S][prev] = i;
	}
    }
    return dp[S][prev] = res;
}
  
int main()
{
    cin >> N;
    for (int i = 0; i < N; i++) {
	cin >> n[i] >> d[i] >> B[i];
	B[i] *= 20;
    }
    _time = INF;
    for (int i = 0; i < 1<<N; i++) {
	for (int j = 0; j < N; j++) {
	    dp[i][j] = -1;
	}
    }
    for (int i = 0; i < N; i++) {
	double now = solve(1<<i, i, B[i]);
	if (now < _time) {
	    _time = now;
	    path[0][0] = i;
	}
    }
    int S = 0, p = 0;
    while (1) {
	if (N == __builtin_popcount(S)) break;
	ans.push_back(n[path[S][p]]);
	int T = S;
	S |= 1<<path[S][p];
	p = path[T][p];
    }
    for (int i = 0; i < N; i++) {
	if (i == N-1) {
	    cout << ans[i] << endl;
	} else {
	    cout << ans[i] << " ";
	}
    }
    return 0;
}

Measured memory_bytes: 8940
use proconio::*;

fn run() {
    input! {
        n: usize,
        k: usize,
        s: usize,
        t: usize,
        a: [usize; n],
    }
    let a: Vec<usize> = a.into_iter().filter(|a| a & s == s && a | t == t).collect();
    if a.is_empty() || s & t != s {
        println!("0");
        return;
    }
    let mut dp = vec![std::collections::BTreeMap::new(); k + 1];
    dp[0].insert((!0usize, 0usize), 1u64);
    let mut memo = vec![];
    for a in a {
        for i in (0..k).rev() {
            memo.clear();
            for (&(and, or), &cnt) in dp[i].iter() {
                let and = a & and;
                let or = a | or;
                memo.push((and, or, cnt));
            }
            let dp = &mut dp[i + 1];
            for &(and, or, cnt) in memo.iter() {
                *dp.entry((and, or)).or_insert(0) += cnt;
            }
        }
    }
    let mut ans = 0;
    for dp in dp {
        ans += dp.get(&(s, t)).cloned().unwrap_or(0);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

int main(){
  string s;
  cin >> s;
  string t;
  cin >> t;
  cout << (s == t.substr(0,s.size()) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3628
//
// Created by watemus on 17.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;
constexpr ld PI = acos(-1);

vector<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

#ifdef LOCAL
#else
#endif


void run() {
    ld a, b, h, m;
    cin >> a >> b >> h >> m;
    ld angle_h = (h * 60 + m) / (60 * 12) * 2 * PI;
    ld angle_m = (m) / 60 * 2 * PI;
    ld x1 = a * cos(angle_h);
    ld y1 = a * sin(angle_h);
    ld x2 = b * cos(angle_m);
    ld y2 = b * sin(angle_m);
    cout << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << '\n';
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    cout << fixed << setprecision(20);
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

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

// 插入此處

int main() {
    int m, k;
    cin >> m >> k;
    int up = (1 << m) - 1;
    if (m == 1 && k == 1) {
        cout << -1 << endl;
    } else if (m == 1 && k == 0) {
        printf("0 0 1 1\n");
    } else if (k <= up) {
        for (int i = 0; i <= up; i++) {
            if (i != k) {
                printf("%d ", i);
            }
        }
        printf("%d ", k);
        for (int i = up; i >= 0; i--) {
            if (i != k) {
                printf("%d ", i);
            }
        }
        printf("%d\n", k);
    } else {
        cout << -1 << endl;
    }
}


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

using namespace std;

void test()
{
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;

    if(x1==0)
        cout<<1<<endl;
    else if(x2==0)
        cout<<2<<endl;
     else if(x3==0)
        cout<<3<<endl;
     else if(x4==0)
        cout<<4<<endl;
    else
        cout<<5<<endl;

}

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

    test();

    return 0;
}


Measured memory_bytes: 3600
S = input()
n = len(S)

ans = 0
for i in range(2**(n-1)):
    L = []
    for i,c in enumerate(bin(i)[2:].zfill(n)):
        if c == '1':
            L.append(i)
    L.append(n)
    S_ = []
    l_prev = 0
    for l in L:
        S_.append(int(S[l_prev:l]))
        l_prev = l
    ans += sum([int(s_) for s_ in S_])

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;

typedef long long int ll;
typedef pair<ll,ll> pp;
typedef long double ld;
typedef vector<pp> vpl;
//typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 200005;
const ll mod = 1000000007;
const long long int inf = 1e9;

#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);



ll cnt[N];

int main(){
	ll n;
	ll x;
	cin>>n;
	rep1(i,n){
		cin>>x;
		cnt[x]++;
	}
	rep1(i,n+1) cout<<cnt[i]<<endl;




		



		
	

		
}
	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

Measured memory_bytes: 5164
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 100;
const int MAX_H = 100;
const int MAX_N = MAX_W * MAX_H / 4;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

int w, h, n;
int sx, sy, gx, gy;
vpii orbs[MAX_N];
vi dp[2];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> w >> h;
    if (w == 0) break;

    for (int i = 0; i < MAX_N; i++) orbs[i].clear();
    n = 0;

    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++) {
	string s;
	cin >> s;

	if (s == "S") sx = x, sy = y;
	else if (s == "G") gx = x, gy = y;
	else if (s != ".") {
	  int d = atoi(s.c_str());
	  if (n < d) n = d;
	  orbs[d].push_back(pii(x, y));
	}
      }

    orbs[0].push_back(pii(sx, sy));
    orbs[n + 1].push_back(pii(gx, gy));

    int cur = 0, nxt = 1;
    dp[cur].assign(1, 0);

    for (int k = 0; k <= n; k++) {
      vpii& orbc = orbs[k];
      vpii& orbn = orbs[k + 1];
      int nc = orbc.size();
      int nn = orbn.size();

      dp[nxt].assign(nn, INF);

      for (int i = 0; i < nc; i++) {
	int dpi = dp[cur][i];
	int &xi = orbc[i].first, &yi = orbc[i].second;
	for (int j = 0; j < nn; j++) {
	  int &xj = orbn[j].first, &yj = orbn[j].second;
	  int d = dpi + abs(xi - xj) + abs(yi - yj);
	  if (dp[nxt][j] > d) dp[nxt][j] = d;
	}
      }

      cur ^= 1, nxt ^= 1;
    }

    cout << dp[cur][0] << endl;
  }

  return 0;
}

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

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

//  3
// 0 2
//  1

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

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

        if (n == 0) break;

        vector<P> v;
        v.push_back(P(0, 0));
        for (int i = 1; i < n; ++i) {
            int ni, di;
            cin >> ni >> di;
            v.push_back(P(v[ni].first + dx[di], v[ni].second + dy[di]));
        }

        int minx = 1000;
        int miny = 1000;
        int maxx = -1000;
        int maxy = -1000;
        for (P p : v) {
            int x = p.first, y = p.second;
            //cout << " -- " << x << " " << y << endl;
            if (x < minx) minx = x;
            if (x > maxx) maxx = x;
            if (y < miny) miny = y;
            if (y > maxy) maxy = y;
        }

        cout << maxx - minx + 1<< " " << maxy - miny + 1<< endl;
    }
}

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

int main(){
    ll N,K,S; cin >> N >> K >> S;
    for (ll i=0; i<K; i++){
        cout << S << " ";
    }
    if (S==1e9){
        for (ll i=K; i<N; i++){
        cout << S-1 << " ";
        }
    }else{
        for (ll i=K; i<N; i++){
            cout << S+1 << " ";
        }
    }   
}

Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

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

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

int chain[10002];

int no(int idx){
	int c = 1;
	int p = idx - 1;
	int q = idx + 1;
	int res = 0;
	while(chain[p] == chain[idx]){
		p--;
		c++;
	}
	while(chain[q] == chain[idx]){
		q++;
		c++;
	}
	while(c >= 4){
		res += c;
		c = 0;
		if(chain[q] != chain[p]) return res;
		if(chain[q] == chain[p] && chain[p] == -1) return res;

		int org = chain[p];
		while(chain[p] == org){
			p--;
			c++;
		}
		while(chain[q] == org){
			q++;
			c++;
		}
	}
	return res;
}

int main(void){
	int N;
	fill(chain, chain+10002, -1);
	while(cin >> N && N){
		int res = 0;
		REP(i, N){
			cin >> chain[i+1];
			chain[i+1]--;
		}
		REP(i, N){
			REP(j, 3){
				int tmp = chain[i+1];
				chain[i+1] = j;
				res = max(res, no(i+1));
				chain[i+1] = tmp;
			}
		}
		cout << N-res << endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ld n,m;
    cin>>n;
    ld b;
    cin>>b;
    m=n*b;
    int ans=(int)m;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int a[100][2];
set<pii> s;
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i][0],&a[i][1]);
		s.insert(mp(a[i][0],a[i][1]));
	}
	int mi=n;
	for(i=1;i<n;i++)
	{
		for(j=0;j<i;j++)
		{
			m=0;
			x=a[i][0]-a[j][0];
			y=a[i][1]-a[j][1];
			for(k=0;k<n;k++)
			{
				if(s.count(mp(a[k][0]+x,a[k][1]+y)))
				{
					m++;
				}
			}
			mi=min(n-m,mi);
		}
	}
	printf("%d",mi);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)
typedef long long ll;
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int main(){
    ll A,B,C,D,E,N;
    cin >> N >> A >> B >> C >> D >> E;
    ll s = min(min(min(A,B),min(C,D)),E);
    cout << ((N+s-1) / s) + 4 << endl;
    return 0;
}

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

int main(){
    long long N,Y;
    cin >> N >> Y;
    long long y = Y/1000;
    vector<int>vec(2);
    int usi = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
        int X = y-i*10-j*5; 
            if(X == (N-i-j)*1 && X >= 0){
            vec[0] = i;
            vec[1] = j;
            vec[2] = N-i-j;
            usi++;
            }     
        }
    }
    if(usi == 0)cout << "-1 -1 -1" << endl;
    else cout <<vec[0]<<" "<<vec[1]<<" "<<vec[2]<<endl;
}

Measured memory_bytes: 384
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		int a = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		string b = input[0];
		string c = input[1];
		// 文字列の入力
      for (int i = 0; i < a; i++)
{
    Console.Write(b[i]);
    Console.Write(c[i]);
}
		
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int n,m,t,i;
  cin >> n >> m;
  t=m/2;
  for(i=n;i<=t;i++)
    if(m%i==0){
      cout << (m/i) << endl;
      return 0;
    }
  cout << "1" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        H,W=map(int, input().split())
        grid=[list(input()) for i in range(H)]
        for h in range(H):
            for w in range(W):
                if grid[h][w]=='#':
                    for j,k in [0,1],[0,-1],[1,0],[-1,0]:
                        nh=h+j
                        nw=w+k
                        if nh<0 or nh>=H or nw<0 or nw>=W:
                            continue
                        else:
                            if grid[nh][nw]=='#':
                                break
                            else:
                                if [j,k]==[-1,0]:
                                    return 'No'
        return 'Yes'
    print(main())
resolve()

Measured memory_bytes: 39280
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



bool check[1001];
map<ll,ll> cnt;
vector<ll> prime;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N ; cin >> N ;
  check[0] = check[1] = true;
  rep(i,1001)rep(j,1001){
    if(i==1 || j==1) continue;
    if(i*j>1000) continue;
    check[i*j] = true;
  }

  rep(i,N+1)
    if(!check[i]) prime.pb(i);

  

  
  rep(i,N+1){
    if(i==0) continue;
    if(i==1) continue;
    ll num = i;
    rep(j,prime.size()){
      while((num%prime[j])==0){
	num /= prime[j];
	cnt[prime[j]] ++;
      }
    }
    
  }

  ll ans = 1;
  rep(i,prime.size()){
    ans *= (cnt[prime[i]]+1);
    ans %= 1000000007;
  }

  cout << ans << endl;

  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
import sys
H = [int(i) for i in input().split()]
if N == 1:
    print('Yes')
    sys.exit()
for i in range(1,N)[::-1]:
    if H[i]+1 < H[i-1]:
        print('No')
        sys.exit()
    elif H[i] < H[i-1]:
        H[i-1] -= 1
    else:
        continue
print('Yes')




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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,a,found;
    while(cin >> n >> a)
    {
        found = 0;
        for(int i = 0; i*500 <= n; i++)
            if(i*500 + a >= n)
                found = 1;
        cout << (found? "Yes" : "No") << '\n';
    }
    return 0;
} 

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

const int N = 2e5;

int n,k;
int li[N+5];
int ps[N+5];

priority_queue<int> maksi, pendmaksi, mini, pendmini;


int main(){
	scanf("%d%d",&n,&k);
	if(k==1){
		printf("1\n");
		return 0;
	}
	int cnt = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
		if(i<=k){
			maksi.push(li[i]);
			mini.push(-li[i]);
		}
		if(i>1){
			ps[i] = ps[i-1];
			if(li[i] > li[i-1]) ps[i]++;
		}
	}
	int ans = 1;
	int kena = 0;
	if(ps[k] == (k-1)){
		ans--;
		kena = 1;
	}
	for(int i=k+1;i<=n;i++){
		int buang = li[i-k];
		ans++;
		if(ps[i] - ps[i-k+1] == k-1){
			ans--;
			kena = 1;
		} else if(-mini.top() == buang && maksi.top() < li[i]){
			ans--;
//			printf("dari %d - %d\n",i-k+1,i);
		}
		pendmini.push(-buang);
		pendmaksi.push(buang);
		mini.push(-li[i]);
		maksi.push(li[i]);
		while(!pendmini.empty() && pendmini.top() == mini.top()){
			pendmini.pop();
			mini.pop();
		}
		
		while(!pendmaksi.empty() && pendmaksi.top() == maksi.top()){
			pendmaksi.pop();
			maksi.pop();
		}
	}
//	printf(">> %d\n",kena);
	printf("%d\n",ans+kena);
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  int64_t ans=1;
  const int64_t mod=1e9+7;
  for(int i=1;i<=N;i++){
    ans*=i;
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
import sys

n = int(input())
A = [int(i.rstrip("\n")) for i in sys.stdin.readlines()]

def LIS():
    L = A[:1]
    for i in A[1:]:
        if L[-1] < i:
            L.append(i)
        else:
            j = bisect_left(L, i)
            L[j] = i
    return len(L)

print(LIS())

Measured memory_bytes: 18744
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
#define MO 1000000007
using namespace std;
int N,a[MAXN+5],d[MAXN+5],pre[MAXN+5];
int cnt[MAXN+5],f[MAXN+5];
bool vis[MAXN+5];
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&a[i]),d[a[i]]++;
	for(int i=1;i<=N;i++)
		if(d[i]>2)
		{
			printf("0\n");
			return 0;
		}
	for(int i=1;i<=N;i++)
		if(d[i]==2&&vis[i]==false)
		{
			int p=i;
			do
			{
				if(vis[p]==true)
				{
					printf("0\n");
					return 0;
				}
				vis[p]=true;
				pre[a[p]]=p;
				p=a[p];
			}while(p!=i);
		}
	int ans=1;
	for(int i=1;i<=N;i++)//处理基环内向树 
		if(d[i]==0)
		{
			int p=i,len1=0,len2=0;
			do
			{
				vis[p]=true;
				p=a[p];
				len1++;
			}while(vis[p]==false);
			do
			{
				p=pre[p];
				len2++;
			}while(d[p]==1);
			if(len1>len2)
			{
				printf("0\n");
				return 0;
			}
			if(len2>len1)
				ans=2LL*ans%MO;
		}
	for(int i=1;i<=N;i++)//处理单个的循环 
		if(vis[i]==false)
		{
			int len=0,p=i;
			do
			{
				p=a[p];
				vis[p]=true;
				len++;
			}while(p!=i);
			cnt[len]++;
		}
	for(int i=1;i<=N;i++)
		if(cnt[i])
		{
			int mul=1;
			if(i%2==1&&i!=1)
				mul=2;
			f[0]=1,f[1]=mul;
			for(int j=2;j<=cnt[i];j++)
				f[j]=(1LL*f[j-2]*(j-1)%MO*i%MO+1LL*f[j-1]*mul%MO)%MO;
			ans=1LL*ans*f[cnt[i]]%MO;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
n = int(raw_input())
d = {}
for i in xrange(n):
    L = raw_input().split()
    if L[0] == 'insert':
        d[hash(L[1])] = L[1]
    else:
        if d.has_key(hash(L[1])):
            print 'yes'
        else:
            print 'no'

Measured memory_bytes: 36236
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int N;
vector<long long> A;

long long solve() {
    if (A[0] != 0) return -1;
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i+1] - A[i] > 1) return -1;
        if (A[i+1] - A[i] != 1) res += A[i];
    }
    return res;
}

int main() {
    while (cin >> N) {
        A.resize(N+1, 0);
        for (int i = 0; i < N; ++i) cin >> A[i];
        cout << solve() << endl;
    }
}


















Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x=100000;
int a,b;
cin>>a>>b;
int ans=max(4-a,0*1ll)*x+max(4-b,0*1ll)*x+((a==1&&b==1)?4*x:0);
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>

using namespace std;
typedef long long ll;
int main() {
	ll n,sum = 0;
	int cnt500 = 0, cnt5 = 0;
	cin >> n;
	if (n == 0) {
		cout << 0;
		return 0;
	}
	cnt500 = n / 500;
	n %= 500;
	sum += cnt500 * 1000;
	cnt5 = n / 5;
	sum += cnt5 * 5;
	cout << sum;
	return 0;
}

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

int main() {

  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  cout << ceil((double) (N - 1) / (K - 1)) << endl;

  return 0;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define ll unsigned long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007
#define inf 9999999999999999ll
#include <bits/stdc++.h>
using namespace std;
ll fun(ll x)
{
    if(x==1)
        return 1;
    ll y=fun(x/2);
    return 2*y+1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h;
    cin>>h;
    cout<< fun(h)<<endl;
}


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

class D2
{
	struct P
	{
		public int i, j;
		public P(int _i, int _j) { i = _i; j = _j; }
		public bool IsInRange => 0 <= i && i < h && 0 <= j && j < w;
		public P[] Nexts() => new[] { new P(i, j - 1), new P(i, j + 1), new P(i - 1, j), new P(i + 1, j) };
	}

	static int h, w;

	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var z = Read();
		h = z[0]; w = z[1];
		var s = Read();
		var g = Read();
		var c = new int[h].Select(_ => Console.ReadLine()).ToArray();

		var sp = new P(s[0] - 1, s[1] - 1);
		var gp = new P(g[0] - 1, g[1] - 1);

		var d = new int[h, w];
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				d[i, j] = c[i][j] == '.' ? 1 << 30 : -1;
		var u = new bool[h, w];
		var pq = PQ<(P, int v)>.Create(_ => _.v);

		d[sp.i, sp.j] = 0;
		pq.Push((sp, 0));

		// Dijkstra
		while (pq.Any())
		{
			var (p, _) = pq.Pop();
			if (p.Equals(gp)) break;
			if (u[p.i, p.j]) continue;
			u[p.i, p.j] = true;

			foreach (var x in p.Nexts())
			{
				if (!x.IsInRange || d[x.i, x.j] <= d[p.i, p.j]) continue;
				d[x.i, x.j] = d[p.i, p.j];
				pq.Push((x, d[x.i, x.j]));
			}

			for (int i = -2; i <= 2; i++)
				for (int j = -2; j <= 2; j++)
				{
					var x = new P(p.i + i, p.j + j);
					if (!x.IsInRange || d[x.i, x.j] <= d[p.i, p.j] + 1) continue;
					d[x.i, x.j] = d[p.i, p.j] + 1;
					pq.Push((x, d[x.i, x.j]));
				}
		}
		var r = d[gp.i, gp.j];
		Console.WriteLine(r == 1 << 30 ? -1 : r);
	}
}

class PQ<T> : List<T>
{
	public static PQ<T> Create(T[] vs = null, bool desc = false)
	{
		var c = Comparer<T>.Default;
		return desc ?
			new PQ<T>(vs, (x, y) => c.Compare(y, x)) :
			new PQ<T>(vs, c.Compare);
	}

	public static PQ<T> Create<TKey>(Func<T, TKey> getKey, T[] vs = null, bool desc = false)
	{
		var c = Comparer<TKey>.Default;
		return desc ?
			new PQ<T>(vs, (x, y) => c.Compare(getKey(y), getKey(x))) :
			new PQ<T>(vs, (x, y) => c.Compare(getKey(x), getKey(y)));
	}

	Comparison<T> c;
	public T First => this[0];

	PQ(T[] vs, Comparison<T> _c)
	{
		c = _c;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j) { var o = this[i]; this[i] = this[j]; this[j] = o; }
	void UpHeap(int i) { for (int j; i > 0 && c(this[j = (i - 1) / 2], this[i]) > 0; Swap(i, i = j)) ; }
	void DownHeap(int i)
	{
		for (int j; (j = 2 * i + 1) < Count;)
		{
			if (j + 1 < Count && c(this[j], this[j + 1]) > 0) j++;
			if (c(this[i], this[j]) > 0) Swap(i, i = j); else break;
		}
	}

	public void Push(T v)
	{
		Add(v);
		UpHeap(Count - 1);
	}
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


Measured memory_bytes: 52324
N, K = map(int, input().split())
A = [int(i) - 1 for i in input().split()]

X = [-1] * N
i = 0
t = 0
while X[i] < 0:
    X[i] = t
    i = A[i]
    t += 1

X[i] + (K - X[i]) % (t - X[i])

if K <= X[i]:
    print(X.index(K) + 1)
else:
    print(X.index(X[i] + (K - X[i]) % (t - X[i]) ) + 1)


Measured memory_bytes: 92468
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  string s; cin >> s;
  ll ans = 0, A = 0;
  rep(i,s.size()-1){
    if(s[i] == 'A'){
      A++;
    }else{
      if(s[i] == 'B' && s[i+1] == 'C'){
        ans += A;
        i++;
      }else{
        A = 0;
      }
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3756
#include <stdio.h>

int N;
int insu[101];

int num(int m){
  int count = 0;
  for(int i = 0;i <= N;i++){
    if(insu[i] >= m-1) count++;
  }
  return count;
}

int main(void){
  int ans = 0;
  scanf("%d",&N);

  for(int i = 0;i <= 101;i++) insu[i] = 0;

  for(int i = 2;i <= N;i++){
    int sample = i;
    for(int j = 2;j <= i;j++){
      while(sample%j == 0){
        sample /= j;
        insu[j]++;
      }
    }
  }
  
  ans += num(75);
  ans += num(15)*(num(5)-1);
  ans += num(25)*(num(3)-1);
  ans += num(5)*(num(5)-1)*(num(3)-2)/2;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] defargs) {
        Scanner scanner = new Scanner(System.in);
    int[] integer = new int[3];
		for(int i = 0; i < 3; i++) 
		    integer[i] = scanner.nextInt();
	        Arrays.sort(integer);
		    System.out.println(integer[0] + " " + integer[1] + " " + integer[2]);
    }
}



Measured memory_bytes: 26208
<?php
list($X, $Y, $A, $B ,$C) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$red = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));
rsort($red);
$red = array_slice($red, 0, $X);

$green = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));
rsort($green);
$green = array_slice($green, 0, $Y);

$white = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));
rsort($white);

$apples = array_merge($red, $green, $white);
rsort($apples);

echo array_sum(array_slice($apples, 0, $X + $Y));

Measured memory_bytes: 39424
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);
	static int count = 0;
	public static void main(String[] args){

		for(;;){
			int n = scan.nextInt();
			int s = scan.nextInt();
			if(n == 0 && s == 0)break;
			count = 0;
			solve(0, n, s);
			System.out.printf("%d\n", count);
		}
	}

	private static void solve(int p, int n, int s){
		if(p > s || n == 0 || p > 9)return;
		if(n == 1 && p == s)count++;
		solve(p+1, n-1, s-p);
		solve(p+1, n, s);
	}
}

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

using namespace std;

int main(){

	int n,m;
	while(cin>>n>>m && !(n==0&&m==0)){
		vector<int> vec;
		for(int i = 0; i < n+m; i++){
			int tmp;
			cin >> tmp;
			vec.push_back(tmp);
		}
		sort(vec.begin(),vec.end());

		int prvCar=vec[0];
		int empTime=vec[0];
		for(int i = 1; i < vec.size(); i++){
			empTime=max(empTime,vec[i]-prvCar);
			prvCar=vec[i];
		}
		cout << empTime << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 2000000000
#define MAX 100001
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(int, n);
    VEC(int, a, n);
    int ans = 0;
    REP(i, n) ans += i+1 == a[a[i]-1] && i+1 <  a[i];
    OUTL(ans); 
RET;}


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

int main(){
int N;
scanf("%d",&N);
vector<int> A(N);
for(int i=0; i<N; i++){
	scanf("%d",&A[i]);
}
auto sortA = A;
sort(sortA.begin(), sortA.end());

int count = 0;
for(int i=0; i<N;i++){
	if(A[i]!=sortA[i]){
		count++;
	}
}
if(count<=2){
	printf("YES\n");
}else{
	printf("NO\n");
}

	return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
const int N=100;
struct A{int x,y;}a[N],b[N];
int ab(int x){return max(x,-x);}
int dis(int x,int y){
    return ab(a[x].x-b[y].x)+ab(a[x].y-b[y].y);
}
int main(){
    int n,m,i,j,k;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)
        scanf("%d %d",&a[i].x,&a[i].y);
    for(j=1;j<=m;j++)
        scanf("%d %d",&b[j].x,&b[j].y);
    for(i=1;i<=n;i++){
        k=1;
        for(j=2;j<=m;j++)
            if(dis(i,k)>dis(i,j)) k=j;
        printf("%d\n",k);
    }
    return 0;
}


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

const int MAXN=1e5+10;

int arr[MAXN],pref[MAXN],suf[MAXN],N,best;

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

int main()
{
cin>>N;
  for(int i=1;i<=N;i++)
  {
	cin>>arr[i];
	pref[i]=gcd(pref[i-1],arr[i]);
  }

  for(int i=N;i>=1;i--) 
    suf[i]=gcd(suf[i+1],arr[i]);
  for(int i=1;i<=N;i++) 
    best=max(best,gcd(pref[i-1],suf[i+1]) );
cout<<best<<endl;
return 0;
}

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

int main(){
  string s;
  bool judge = 1;
  cin >> s;
  if(s.size()%2 !=  0){
    judge = 0;
  }
  else{
    for(int i = 0;i < s.size();i++){
      if(((i%2 == 0)&&(s[i] != 'h'))||((i%2 == 1)&&(s[i] != 'i'))){
	judge = 0;
	break;
      }
    }
  }

  if(judge){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}
  


Measured memory_bytes: 256
import heapq
from collections import deque
n,m = map(int,input().split())
A = []
for _ in range(n):
    a,b = map(int,input().split())
    A.append((a,-b))
A.sort()
A = deque(A)
hq = []
ans = 0
for i in range(1,m+1):
    while A:
        if A[0][0] ==i:
            tmp = A.popleft()
            heapq.heappush(hq,tmp[1])
        else:
            break
    if len(hq) == 0:
        continue
    else:
        ans += heapq.heappop(hq)
print(-ans)
        

Measured memory_bytes: 88128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include<iomanip>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
ll n, pos, neg;
int main()
{
   int n,k,res;
   cin>>n>>k;
   int cnt=0;
   for(int i=1;i<=n;i++)
   {
       cin>>res;
       if(res>=k) cnt++;
   }
   cout<<cnt;
}


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

/*
以下の方法はA = 2, B = 5, C = 5の時10となり, 想定解の0にならない.
int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    ll max_len = max(A, max(B, C)), rest;
    if (max_len == A) rest = B * C;
    else if (max_len == B) rest = C * A;
    else rest = A * B;
    cout << (max_len % 2) * rest << endl;
    return 0;
}
*/

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) cout << 0 << endl;
    else cout << min(B * C, min(C * A, A * B)) << endl;
    return 0;
}

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




























int main () {
    string s, t;
    cin >> s >> t;

    int result = 1001;
    for (int i = 0; i <= s.size() - t.size(); i++) {
        int count = 0;
        for (int j = 0; j < t.size(); j++) {
            if (t[j] != s[i + j]) {
                count++;
            }
        }
        result = min (result, count);
    }

    cout << result << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
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;}
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }

  sort(a.begin(),a.end());
  int f=0;
  for(int i=1;i<n;i++){
    int x=a[i];
    int y=a[i-1];
    if(x==y){
      f=1;
    }
  }

  if(f==0)cout<<"YES";
  else cout<<"NO";

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n,m,R;
    cin >> n >> m >> R;
    vector<int>r(R);
    rep(i,R)cin >> r[i], r[i]--;
    sort(r.begin(),r.end());
    int a[300][300]={};
    
    rep(i,n){
        rep(j,n){
            a[i][j] = 10000000;
        }
    }
    int aa,bb,cc;
    rep(i,m){
        cin >> aa >> bb >> cc;
        aa--;
        bb--;
        a[aa][bb] = cc;
        a[bb][aa] = cc;
        
    }
    rep(i,n)a[i][i] = 0;
    rep(k,n)rep(i,n)rep(j,n){
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
    }
    int ans = INT_MAX;
    do{
        int temp = 0;
        rep(i,R-1){
            temp += a[r[i]][r[i+1]];
        }
        ans = min(ans, temp);
    }while(next_permutation(r.begin(),r.end()));
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int n;cin>>n;
  	vector<int> m(n);
  
  	for(int i=0;i<n;i++){
      cin>>m.at(i);
    }
  
  	sort(m.begin(),m.end());
  	int count=1;
  
  	for(int i=0;i<n-1;i++){
      if(m.at(i)!=m.at(i+1)){
    		count++;  	
      }
    }
  	cout<<count<<endl;
}


Measured memory_bytes: 256
# =map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
ans=[0 for _ in range(8)]
cnt=0
res=0
for i in a:
    if 0<i<400:
        ans[0]+=1
    elif 400<=i<800:
        ans[1]+=1
    elif 800<=i<1200:
        ans[2]+=1
    elif 1200<=i<1600:
        ans[3]+=1
    elif 1600<=i<2000:
        ans[4]+=1
    elif 2000<=i<2400:
        ans[5]+=1
    elif 2400<=i<2800:
        ans[6]+=1
    elif 2800<=i<3200:
        ans[7]+=1
    elif 3200<=i:
        cnt+=1
for i in ans:
    if i==0:
        res+=1
x=8-res
# if x+cnt<9:
#     y=cnt+x
# else:
#     y=8
y=cnt+x
if x==0:
    x=1
print(x,y)
# print(ans)
   

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int main(void) {
  ll r, D, x;
  cin >> r >> D >> x;
  REP(i, 10) {
    x = r * x - D;
    cout << x << endl;
  }
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll x;
    cin>>x;
    vector<ll> vec(2001,0);
    for(int i=1;i<=2000;i++){
    	vec[i] = (pow(i-1000,5));
    }
    int a;
    int b;
    for(int i=1001;i<=2000;i++){
    	for(int j=1;j<=2000;j++){
    		if(vec[i] - vec[j]==x){
    			a = i-1000;
    			b = j-1000;
    			break;
    		}
    	}
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 4100
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;
using ull = long long;
ll c(ll a, ll b) {
	b = min(a - b, b); ll r = 1;
	for (int i = 1; i <= b; i++)
		r = r * (a - b + i) / i;
	return r;
}
int main() {
	int n, p, a, odd = 0, eve = 0;
	scanf("%d %d", &n, &p);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a & 1)
			odd++;
		else
			eve++;
	}
	ull ans;
	if (p) {
		ull p_odd = 0, p_eve = 0;
		for (int i = 1; i <= odd; i += 2)
			p_odd += c(odd, i);
		for (int i = 1; i <= eve; i++)
			p_eve += c(eve, i);
		ans = p_odd * (p_eve + 1);
	} else {
		ull p_odd = 0, p_eve = 0;
		for (int i = 2; i <= odd; i += 2)
			p_odd += c(odd, i);
		for (int i = 1; i <= eve; i++)
			p_eve += c(eve, i);
		ans = (p_odd + 1) * (p_eve + 1);
	}
	printf("%llu\n", ans);
}

Measured memory_bytes: 128
N = int(input())
dic = {}
L = list(map(int, input().split()))
L.sort()
s = 0
for i in range(0, len (L)):
    for j in range(i+1 , len (L)):
        for k in range ( j+1 ,len(L)):
            if L[i]+L[j] > L[k] and L[i] != L[j] and L[j] != L[k] and L[i] != L[k] :
                s+=1
print (s)
                        



Measured memory_bytes: 8996
n = int(input())
a = list(map(int, input().split()))

ans = [0] * n

sign = True
for i in range(n):
    if sign:
        ans[0] += a[i]
    else:
        ans[0] -= a[i]
    sign = not sign

for i in range(1, n):
    ans[i] = 2 * a[i-1] - ans[i-1]

print(*ans, sep=' ')

Measured memory_bytes: 90144
#include<stdio.h>

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

  long int a[n];
  for(int i=0;i<n;i++){
    scanf("%ld", &a[i]);
  }

  long int ans=0;
  long int sum=0;
  for(int i=0;i<n;i++){
    sum += a[i];
  }

  long int amari;
  for(int i=0;i<n-1;i++){
    sum -= a[i];
    amari = sum % 1000000007;
    ans += a[i] * amari;
    ans = ans % 1000000007;
  }
  
  printf("%ld\n", ans);

  return 0;
}


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

int main() 
{
    int N;
    cin >> N;
    int d[N];
    for(int i=0;i<N;i++) {
        cin >> d[i];
    }
    sort(d,d+N); 
    int mid = N/2;
    int ans = d[mid] - d[mid-1];
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn=1e9;
void read(int &xxxxx){scanf("%d",&xxxxx);}

int main()
{
    int n;cin>>n;
    cout<<((n==3 ||n==5 || n==7)?"YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long h = scanner.nextLong();
        long w = scanner.nextLong();

        if (h==1 || w==1){
            System.out.println(1);
        }
        
        else if ((h*w)%2==0){
            System.out.println((h*w)/2);
        }
        else
            //((h*w)%2!=0)
            {
                System.out.println(((h*w)/2)+1);
            }
    }
}

Measured memory_bytes: 22996
x, y = map(int, input().split())

A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2, ]

if x in A and y in A:
    print('Yes')
elif x in B and y in B:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9100
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left

N = int(input())
A = []
for _ in range(N):
    x = int(input())
    idx = bisect_left(A, x)
    if idx == 0:
        A.insert(idx, x)
    elif A[idx-1] == x:
        A.insert(idx, x)
    else:
        A[idx-1] = x
#    print(A,x)
print(len(A))


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

int n, a[110];
const int INF = 0x3f3f3f3f;

int main()
{
    cin >> n;
    int mmax = -INF, mmin = INF;
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
        mmax = max(mmax, a[i]);
        mmin = min(mmin, a[i]);
    }
    int ans = INF;
    for (int i = mmin; i <= mmax; ++ i) {
        int tmp = 0;
        for (int j = 0; j < n; ++ j) {
            tmp += (a[j]-i) * (a[j]-i);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] != "#":
            s = 0

            ist = -1
            ien = 2
            jst = -1
            jen = 2

            if h == 0:
                ist = 0
            if h == H - 1:
                ien = 1
            if w == 0:
                jst = 0
            if w == W - 1:
                jen = 1

            for i in range(ist, ien):
                for j in range(jst, jen):
                    if S[h + i][w + j] == "#":
                        s += 1

            S[h][w] = str(s)

for s in S:
    st = "".join(s)
    print(st)

Measured memory_bytes: 9224
#include<stdio.h>
#include<string.h>

int main()
{
	char s[128];
	gets(s);
	int len;
	len=strlen(s);
	int l,r;
	l=0;r=(len-1)/2-1;
	while (l<r)
		if (s[l]==s[r]) 
		{
			++l;--r;
		}
		else break;
	if (l<r) 
	{ 
		printf("No"); 
		return 0;
	}
	l=(len+3)/2-1;r=len-1;
	while (l<r)
		if (s[l]==s[r]) 
		{
			++l;--r;
		}
		else break;
	if (l<r) 
	{ 
		printf("No"); 
		return 0;
	}
	l=0;r=len-1;
	while (l<r)
		if (s[l]==s[r]) 
		{
			++l;--r;
		}
		else break;
	if (l<r) 
	{ 
		printf("No"); 
		return 0;
	}
	printf("Yes");
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;
const int mod = 1000000007;
 
int main(){
  int n; ll k;
  cin >> n >> k;
  
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    a[i]--;
  }
  
  int f = n; int s = 0;
  vector<int> to(n+1), old(n+1 ,-1);
  to[0] = 0, old[0] =0;
  rep(i, n+1){
    if(i==0) continue;
    to[i] = a[to[i-1]];
    if(old[to[i]] != -1){
      f = i, s = old[to[i]];
      break;
    }
    old[to[i]] = i;
  }  

  int num;
  if(k < s) num = k;
  else num = s + (k - s) % (f - s);
  cout << to[num]+1 << endl;
    
  return 0;
}

Measured memory_bytes: 5640
s=input()
n=len(s)
score=0
g=p=0
for i in range(n):
	if g>p:
		if s[i]=="g":
			p+=1
			score+=1
		else:
			p+=1
	else:
		if s[i]=="g":
			g+=1
		else:
			g+=1
			score-=1
print(score)

	

Measured memory_bytes: 3316