akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N; cin >> N;
  ll a[N];
  map<ll,ll> count;
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
    count[a[i]]++;
  }
  vector<ll> v;
  for (ll i = 0; i < N; i++) {
    if (count[a[i]] >= 2) v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  ll n = v.size();
  if (n == 0) {cout << 0 << endl; return 0;}
  
  if (count[v[n-1]] >= 4) {cout << v[n-1]*v[n-1] << endl;}
  else if (count[v[n-1]] < v.size()) {cout << v[n-1]*v[n-1-count[v[n-1]]];}
  else {cout << 0 << endl;}
}

Measured memory_bytes: 7296
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  double A, B, H, M;
  cin >> A >> B >> H >> M;

  double h = H * 30 + M * 0.5;
  double m = M * 6;
  double kakudo = abs(h - m);
  if (kakudo == 0) {
    cout << abs(A - B) << endl;
    return 0;
  }
  if (kakudo > 180) {
    kakudo = 360 - kakudo;
  }

  cout << sqrt(A * A +
               B * B -
               2.0 * A * B * cos(kakudo * (3.14159265358979323846 / 180)))
       << endl;

  return 0;
}


Measured memory_bytes: 4188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define in inline
#define get getchar()
in int read()
{
	int t=0; char ch=get;
	while (ch<'0' || ch>'9') ch=get;
	while (ch<='9' && ch>='0') t=t*10+ch-'0',ch=get;
	return t;
}
const int _=2e5+5;
ll n,maxb,maxr,minb,minr,maxx[_],minn[_];
struct yzx{
	ll x,y;
}a[_];
in ll cmp(yzx a,yzx b)
{
	return a.x<b.x;
}
int main()
{
	n=read();
	minr=minb=0x3f3f3f3f3f3f3f3f;
	for(re int i=1;i<=n;i++)
	{
		int x=read(),y=read();
		if(x>y)swap(x,y);
		a[i].x=x,a[i].y=y;
		minr=min(minr,a[i].x);
		maxr=max(maxr,a[i].x);
		maxb=max(maxb,a[i].y);
		minb=min(minb,a[i].y);
	}
	ll ans1=(maxb-minb)*(maxr-minr),ans2=0x3f3f3f3f3f3f3f3f;
	minb=minr;
	sort(a+1,a+n+1,cmp);
	maxx[1]=minn[1]=a[1].y;
	for (re int i=2;i<=n;i++)
	{
		maxx[i]=max(maxx[i-1],a[i].y);
		minn[i]=min(minn[i-1],a[i].y);
		if(i!=n) ans2=min(ans2,max(maxx[i],a[n].x)-min(minn[i],a[i+1].x));
	}
	ans2=ans2*(maxb-minb);
	cout<<min(ans1,ans2)<<endl;
	return 0;
}


Measured memory_bytes: 6528
import sys


def dfs(u):
    global time
    color[u] = "GRAY"
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] and color[v] == "WHITE":
            dfs(v)
    color[u] = "BLACK"
    time += 1
    f[u] = time


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    color = ["WHITE"] * n
    time = 0
    d = [-1] * n
    f = [-1] * n
    M = [[0] * n for i in range(n)]
    for inp in sys.stdin.readlines():
        inp = list(map(int, inp.split()))
        for i in inp[2:]:
            M[inp[0]-1][i-1] = 1
    for i in range(n):
        if d[i] == -1:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])

Measured memory_bytes: 7912
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int A,B,C,D,E,F;
bitset<3001> p1, p2;
pair<double,pii> bes = {-1,{0,0}};

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> A >> B >> C >> D >> E >> F;
	p1[0] = p2[0] = 1;
	F0R(i,3001) {
	    p1 |= (p1<<(100*A));
	    p1 |= (p1<<(100*B));
	}
	F0R(i,3001) {
	    p2 |= (p2<<C);
	    p2 |= (p2<<D);
	}
	FOR(i,1,3001) if (p1[i]) {
	    for (int j = 0; j*100 <= i*E && i+j <= F; ++j) {
	        if (p2[j]) bes = max(bes,{(double)j/(i+j),{i+j,j}});
	    }
	}
	cout << bes.s.f << " " << bes.s.s;
}

// read!
// ll vs. int!

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

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

    int counter = 0;
    if (S[0] == T[0]) ++counter;
    if (S[1] == T[1]) ++counter;
    if (S[2] == T[2]) ++counter;
    cout << counter << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
	int n,m,i,j,k;
	cin>>n>>m;
	vector<pair<int,int> > v[n];
	for (i=0;i<m;i++)
	{
		cin>>j>>k;
		v[j-1].push_back(make_pair(k,i));
	}
	for (i=0;i<n;i++)
	sort(v[i].begin(),v[i].end());
	int a[m][12];
	for (i=0;i<n;i++)
	{
		int l;
		for (j=0;j<v[i].size();j++)
		{
			l=i+1;
			for (k=5;k>=0;k--)
			{
				a[v[i][j].second][k]=l%10;
				l/=10;
			}
			l=j+1;
			for (k=11;k>=6;k--)
			{
				a[v[i][j].second][k]=l%10;
				l/=10;
			}
		}
	}
	for (i=0;i<m;i++)
	{
		for (j=0;j<12;j++)
		cout<<a[i][j];
		cout<<endl;
	}
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    ll a[100005];
    for(int i = 0; i < n; i++) cin >> a[i];
    ll bw[100005];
    ll b[100005];
    bw[0] = b[0] = 0;
    for(int i = 1; i <= n; i++){
        bw[i] = bw[i - 1] + max(a[i - 1], 0ll);
        b[i] = b[i - 1] + a[i - 1];
    }
    ll ans = 0;
    for(int i = 0; i <= n - k; i++){
        ans = max(ans, bw[i] + max(b[i + k] - b[i], 0ll) + bw[n] - bw[i + k]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5928
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const long long INF=1000000000000;
const int maxn=100005,m=2154;
int n,ans,flg,p[m];bool vis[m+5];
struct ltl{
	long long x;bool y;
	bool operator <(ltl b)const{return x<b.x;}
}a[maxn];
inline char nc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline long long read(){
	long long ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
inline void make_p(){
	for (int i=2;i<=m;i++){
		if(!vis[i]) p[++p[0]]=i;
		for (int j=1;j<=p[0];j++){
			if(i*p[j]>m) break;
			vis[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
}
inline long long mul(long long x,long long y){
	if(x>INF/y) return INF;else return x*y;
}
int main(){
	make_p();
	for (int T=read();T--;){
		long long now=read(),x=1,y=1;
		for (int i=1;i<=p[0];i++){
			int cnt=0;
			while(now%p[i]==0) cnt++,now/=p[i];
			if(cnt%3==1) x*=p[i],y=mul(y,p[i]*p[i]);
			if(cnt%3==2) x*=p[i]*p[i],y=mul(y,p[i]);
		}
		if(now^1){
			long long S=sqrt(now);
			if(S*S<now) S++;if(S*S>now) S--;
			if(S*S==now) x*=now,y*=S;else
			x*=now,y=mul(y,mul(now,now));
		}
		if(x==1) ans+=!flg,flg=1;else
		a[++n]=(ltl){min(x,y),x<=y};
	}
	sort(a+1,a+1+n);
	for (int i=1,j;i<=n;i=j){
		int cnt[2]={0,0};
		for (j=i;a[i].x==a[j].x&&j<=n;j++) cnt[a[j].y]++;
		ans+=max(cnt[0],cnt[1]);
	}
	printf("%d\n",ans);
	return 0;
}

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

bool visiting[1000], done[1000];
vector<int> path, adj[1000];

bool dfs(int i) {
    path.push_back(i);
    if (done[i]) return false;
    if (visiting[i]) return true;
    visiting[i] = true;
    for (int j : adj[i]) {
        if (dfs(j)) return true;
    }
    visiting[i] = false;
    path.pop_back();
    done[i] = true;
    return false;
}

int main() {
    int n, m; cin >> n >> m;
    bool edges[n][n] = {};
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        adj[a-1].push_back(b-1);
        edges[a-1][b-1] = true;
    }
    for (int i = 0; i < n; i++) {
        memset(visiting, 0, sizeof visiting);
        if (dfs(i)) break;
        path.clear();
    }
    if (path.empty()) { cout << "-1\n"; return 0; }
    int start = 0;
    for (int i = 0; i < path.size()-1; i++) if (path[i] == path.back()) start = i;
    path.erase(path.begin(), path.begin()+start+1);
    for (int a = 0; a < path.size(); a++)
        for (int b = 0; b < path.size(); b++) {
            if (a != b && a+1 != b && !(b == 0 && a == path.size()-1) && edges[path[a]][path[b]]) {
                if (a > b) {
                    path.erase(path.begin()+a+1, path.end());
                    path.erase(path.begin(), path.begin()+b);
                    a = b;
                } else {
                    path.erase(path.begin()+a+1, path.begin()+b);
                    b = a;
                }
            }
        }
    cout << path.size() << endl;
    for (int k : path) cout << k+1 << endl;
}


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

int main(){
    int N,M;
    int c=0;
    cin>>N>>M;

    if(N>1){
        c=c+N*(N-1)/2;
    }

    if(M>1){
        c=c+M*(M-1)/2;
    }

cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int ans = 1;
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    for(int i = 1; i < n; i++)
    {
        bool can = 1;
        for(int j = i - 1; j > -1; j--)
        {
            if(h[j] > h[i])
            {
                can = 0;
                break;
            }
        }
        if(can)
        {
            ans++;
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion
signed main() {
	string s,t;
	char tmp;
	 int Q,q,Rv=0;
	cin >> s >> Q;
	rep(i, Q) {
		cin >> q;
		if (q == 1)
			Rv++;
		else {
			cin >> q >> t;
			if (((Rv%2==0)&&(q == 1))||(Rv%2==1)&&(q==2)) {
				s.insert(0, t);
			}
			else
				s += t;
		}
	}
	if(Rv%2==1)
		reverse(s.begin(), s.end());
	cout << s;
}	

Measured memory_bytes: 900
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int a,b,c;
    double S,L,h;

    cin >> a >> b >> c;

    S = a*b*sin(c*M_PI/180)/2;
    L = a + b + sqrt(a*a+b*b-2*a*b*cos(c*M_PI/180));
    h = b*sin(c*M_PI/180);

    cout <<fixed<<setprecision(4)<<S<<endl;
    cout <<fixed<<setprecision(4)<<L<<endl;
    cout <<fixed<<setprecision(4)<<h<<endl;



    return 0;
}



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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

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

	map<int,int> hist;
	hist[0]=3;

	mint ans=1;
	rep(i,n){
		int a; scanf("%d",&a);
		ans*=hist[a];
		--hist[a];
		++hist[a+1];
	}
	printf("%d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 7;
const int MOD = 1e9 + 7;
int a[N],b[N];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a+1,a+n+1);
	int t=a[n/2];
	for(int i=1;i<=n;i++) {
		if(b[i]<=t) printf("%d\n",a[n/2+1]);
		else printf("%d\n",t);
	}
	return 0;
}

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

int main()
{
    int d, n;
    cin >> d >> n;
    for (int i = 1, count = 0;; i++)
    {
        int t = 0, tmp = i;
        while (tmp % 100 == 0)
        {
            t++;
            tmp /= 100;
        }
        if (t == d)
        {
            count++;
        }
        if (count == n)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int a[100009];
int main()
{
	int r=0;
	int sid=0;
	int l=0;
	string s;
	cin>>s;
	int si=s.size();
	for(int i=0;i<si;i++)
	{
		if(s[i]=='R')
		r++;
		if(s[i]=='R' && s[i+1]=='L')
		{
			a[i]+=r/2;
			a[i+1]+=r/2;
			if(r%2==1)
			a[i]++;
			r=0;
			sid=i;
		}
		if(s[i]=='L')
		l++;
		if(s[i]=='L' && s[i+1]!='L')
		{
			a[sid]+=l/2;
			a[sid+1]+=l/2;
			if(l%2==1)
			a[sid+1]++;
			l=0;
		}
		
	}
	for(int i=0;i<s.size();i++)
	cout<<a[i]<<" ";
	return 0;
}


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

int main() {
	int S;
	char month[10] = "NA";
	scanf("%d", &S);
	if (S / 100 > 0 && S / 100 < 13) {
		strcpy(month, "MMYY\0");
	}
	if (S % 100 > 0 && S % 100 < 13) {
		if (strcmp(month, "NA")) {
			strcpy(month, "AMBIGUOUS\0");
		}
		else {
			strcpy(month, "YYMM\0");
		}
	}
	printf("%s\n", month);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
playlist = {}
taiou = {}

for i in range(N):
    s_i, t_i = input().split()
    taiou[s_i] = i
    playlist[i] = int(t_i)

X = input()

cnt = 0
for j in range(taiou[X], N):
    cnt += playlist[j]

print(cnt - playlist[taiou[X]])

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int N, K;
    int x[100000];
    cin >> N >> K;
    REP(i, N) cin >> x[i];
    int min_val = 1e9;

    for(int i = 0; i < N - K + 1; i++) {
        if(x[i + K - 1] < 0) {
            min_val = min(min_val, - x[i]);
        } else if(x[i] > 0) {
            min_val = min(min_val, x[i + K - 1]);
        } else {
            min_val = min(min_val, - x[i] + x[i + K - 1] + min(- x[i], x[i + K - 1]));
        }
        // cout << i << ":" << i + K - 1 << " " << min_val << endl;
    }
    cout << min_val << endl;
    return 0;
}


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

using  ll =          long long;
using ull = unsigned long long;
const char en = '\n';
const ll INFL = 810000001919114514;
const int INF =         1919114514;

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


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

	ll v=1;
	FOR(i,1,n+1){
		v*=i;
		v%=1000000007;
	}

	cout<<v<<en;

	return 0;
}


Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
cnt = 0
for i in range(n):
#    print(i,A[i],A[A[i] - 1]-1)
    if i == A[A[i] - 1] - 1:
        cnt += 1
print(cnt // 2)


Measured memory_bytes: 14324
;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
(declaim (optimize (debug 0) (safety 0) (speed 3)))

(defvar len-hour (read))
(defvar len-min (read))
(defvar hour (read))
(defvar minu (read))

(let* ((angle (* 11 pi (+ (* 60 hour) minu) (/ 360))))
  (format t "~,20F" (sqrt (+ (* len-hour len-hour)
			     (* len-min len-min)
			     (* -2 len-hour len-min (cos angle))))))


Measured memory_bytes: 23876
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        //r(a, 0, "");
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        HashSet<String> map = new HashSet<>();
        while(N -- > 0) {
            String s = in.next();
            map.add(s);
        }
        System.out.println(map.size());
    }

}


Measured memory_bytes: 66828
#include <stdio.h>

int bubbleSort(int A[], int N)
{
  int flag = 1, j, tmp, count = 0;

  while(flag){
    flag = 0;
    for(j = N - 1; j > 0; j--){       //配列の末尾から順番に大きさを比較していく」
      if(A[j] < A[j-1]){
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        flag = 1;
        count++;
      }
    }
  }
  return count;
}

int main(void)
{
  int n, i, a[100], count;

  scanf("%d", &n);

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

  count = bubbleSort(a, n);

	/*for(i=0; i<n; i++){
		if(0<i){
			printf(" ");
		}
		printf("%d\n%d\n", a[i], count);
	}*/
  for(i = 0; i < n - 1; i++){
      printf("%d", a[i]);
      printf(" ");
  }

  printf("%d\n%d\n", a[n-1], count);    //上のループで最後に空白が入るのでn-1までにしてループの外に最後の出力をする


  return 0;
}



Measured memory_bytes: 2092
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	set := make(map[int]int, 0)
	for i := 0; i < N; i++ {
		set[nextInt(sc)]++
	}
	ans := 0
	ok := true
	for k, v := range set {
		if N%2 == 0 {
			if k%2 == 0 || v > 2 {
				ok = false
			}
		} else {
			if k%2 == 1 || v > 2 || (k == 0 && v > 1) {
				ok = false
			}
		}
	}
	if ok {
		ans = 1
		for i := 1; i <= N/2; i++ {
			ans = (ans * 2) % (int(1e9) + 7)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6784
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=0;i<n;i++) {
           String[] s=sc.next().split(":");
           double a=Double.parseDouble(s[0])*60;
           double b=Double.parseDouble(s[1])*11;
           double d=Math.min(Math.abs((a-b)/2),360-Math.abs((a-b)/2));
          // if(d>=180) d=360-d;
           System.out.println(d<30?"alert":d<90?"warning":"safe");
        }
    }
}


Measured memory_bytes: 29940
#include<iostream>
#include<set>
using namespace std;
int main()
{
    int n,k,d,a;
    set<int> s;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        s.insert(i);
    for(int i=0;i<k;i++){
        cin>>d;
        for(int j=0;j<d;j++){
            cin>>a;
            s.erase(a);
        }
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int input,date[100]={0},a=0,maxx=0;
	while(cin>>input){
		date[input]++;
		a++;
	}
	maxx=max(date[0],date[1]);
	for(int i=0;i<100;i++)maxx=max(maxx,date[i]);
	for(int i=0;i<100;i++)if(date[i]==maxx)cout<<i<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
string s;
int par[100005],ran[100005];
void init(){ for(int i=0;i<100005;i++)par[i]=i,ran[i]=0;}
int find(int x){
	if(x == par[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(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x) == find(y);}
int x[100005];
int main() {
	while(1){
		int n,m; scanf("%d%d",&n,&m);
		if(n+m==0) return 0;
		init();
		memset(x,0,sizeof(x)); int out = 0;
		for(int i=0;i<m;i++){
			int a,b; scanf("%d%d",&a,&b);
			if(same(a,b)) out = 1;
			unite(a,b);
			x[a]++; x[b]++;
			if(x[a]>2 || x[b]>2) out=1;
		}
		puts(out?"no":"yes");
	}
	return 0;
}

Measured memory_bytes: 2352
x = int(input())
a = [input() for i in range(x)]
y = int(input())
b = [input() for h in range(y)]

count_max = 0
for j in a:
  if (a.count(j) - b.count(j)) > count_max:
    count_max = a.count(j) - b.count(j)
print(count_max)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  string S;
  cin >> S;
  ll scnt = 0;
  ll dcnt = 0;
  ll ans = 0;
  char prev = ' ';
  // S += '<';
  for(char c : S) {
    if(c == '<' && prev == '>') {
      ll large = max(scnt, dcnt);
      ll small = min(scnt, dcnt);
      ans += (1 + large) * large / 2;
      ans += (small - 1) * small / 2;
      scnt = 0;
      dcnt = 0;
    }
    if(c == '<') {
      scnt++;
    }
    if(c == '>') {
      dcnt++;
    }
    prev = c;
  }
  ll large = max(scnt, dcnt);
  ll small = min(scnt, dcnt);
  ans += (1 + large) * large / 2;
  ans += (small - 1) * small / 2;
  cout << ans << endl;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    string s;
    cin>>s;
    int n = s.length();
    if (s[0]!='A') out("WA");

    bool saw = false;
    int x=-1;
    for (int i=2; i<n-1; i++) {
	if (s[i]=='C') {
	    if (saw) out("WA");
	    saw=true;
	    x=i;
	}
    }
    if (!saw) out("WA");


    for (int i=1; i<n; i++) {
	if (i==x) continue;
	if (s[i]>='A' && s[i]<='Z') out("WA");
    }

    out("AC");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a==1){
    if(b==2){
      printf("3");
    }else{
      printf("2");
    }
  }else if(a==2){
    if(b==1){
      printf("3");
    }else{
      printf("1");
    }
  }else{
    if(b==2){
      printf("1");
    }else{
      printf("2");
    }
  }
return 0;
}

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

int main(){
	int W,H,x,y,r;
	std::scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
		std::cout << "Yes" << std::endl;
	}else{
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;cin >>a >> b >> c;
    swap(a,b);swap(a,c);
    cout << a << " " << b << " " << c ;
    }

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

struct State{
    int h,w,dir;
};

int dh[]={-1,0,1,0};
int dw[]={0,1,0,-1};
string dmpi="NESW";

void out(State st){
    cout<<st.h<<" "<<st.w<<" "<<dmpi[st.dir]<<endl;
}

int solve(int H,int W,ll L){
    vector<string> f(H+2);
    for(int i=0;i<W+2;i++){
        f[0]+="#";
        f[H+1]+="#";
    }
    State ini={-1,-1,-1};
    for(int i=0;i<H;i++){
        cin>>f[i+1];
        f[i+1]="#"+f[i+1]+"#";
        assert(f[i+1].size()==W+2);
        for(int j=0;j<W+2;j++){
            if(f[i+1][j]=='N'){
                ini=State{i+1,j,0};
            }
            else if(f[i+1][j]=='E'){
                ini=State{i+1,j,1};
            }
            else if(f[i+1][j]=='S'){
                ini=State{i+1,j,2};
            }
            else if(f[i+1][j]=='W'){
                ini=State{i+1,j,3};
            }
        }
    }
    assert(ini.h!=-1);
    vector<vector<vector<int>>> dp(H+2,vector<vector<int>>(W+2,vector<int>(4,-1)));
    int lps=0;
    State st=ini;
    int cnt=0;
    queue<State> que;
    while(true){
        if(cnt==L){
            out(st);
            return 0;
        }
        if(dp[st.h][st.w][st.dir]!=-1){
            lps=cnt-dp[st.h][st.w][st.dir];
            break;
        }
        dp[st.h][st.w][st.dir]=cnt;
        if(f[st.h+dh[st.dir]][st.w+dw[st.dir]]=='#'){
            st.dir=(st.dir+1)%4;
            continue;
        }
        st.h+=dh[st.dir];
        st.w+=dw[st.dir];
        que.push(st);
        cnt++;
    }
    L-=cnt+1;
    vector<State> lpv;
    while(que.size()>lps) que.pop();
    while(!que.empty()) lpv.push_back(que.front()),que.pop();
    assert(lpv.size()==lps);
    L%=lps;
    assert(L<lpv.size());
    out(lpv[L]);
    return 0;
}
int main(){
    int H,W;
    ll L;
    while(cin>>H>>W>>L,H){
        solve(H,W,L);
    }
    return 0;
}


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


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

  int a;
  vector<int> num(N, 0);
  rep(i, N - 1) {
    cin >> a;
    num[a - 1]++;
  }

  rep(i, N) cout << num[i] << endl;
  return 0;
}


Measured memory_bytes: 4040
#include<stdio.h>

int main()
{
	int i=0,xi,yi,a,N;
	int wl,wr,hu,hd,W,H;
    scanf("%d %d %d",&W,&H,&N);
     wl=0,hd=0,wr=W,hu=H;
    for(i=0;i<N;i++)
    {
    	scanf("%d %d %d",&xi,&yi,&a);
    	if(a==1)
    	{
    		if(xi>=wl)
    		wl=xi;
		}
		else if(a==2)
		{
			if(xi<=wr)
			wr=xi;
		}
		else if(a==3)
		{
			if(yi>=hd)
			hd=yi;
			
		}
		else
		{
			if(yi<=hu)
			hu=yi;
		}
		
	}
	if((wl>=wr)||(hd>=hu))
	{
		printf("0");
	}
	else
	printf("%d",(hu-hd)*(wr-wl));
	return 0;
}


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

long long f(long long x)
{
  if (x <= 0) {
    return 0;
  }

  long long r = 0LL;
  for (long long b = 1LL; b <= x; b <<= 1) {
    if (b == 1LL) {
      long long y = x % 4;
      if (y == 1LL || y == 2LL) {
        r |= b;
      }
    } else {
      long long y = x % (b * 2);
      if (y >= b && (y-b+1) % 2 == 1LL) {
        r |= b;
      }
    }
  }
  return r;
}

int main()
{
  long long a, b;
  scanf("%lld%lld", &a, &b);
  long long ans = f(b)^f(a - 1);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

vector<vector<vector<double>>> dp(305,vector<vector<double>>(305,vector<double>(305,0.0)));
int n;

double rec(int i,int j,int k){
    if(dp[i][j][k]>0.0) return dp[i][j][k];
    if(i==0 && j==0 && k==0) return 0.0;
    double res=0.0+n;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res *= 1.0 / (i + j + k);
    dp[i][j][k] = res;
    return res;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(11);
    cin>>n;
    vector<double> a(n,0);
    rep(i,n) cin>>a.at(i);
    sort(all(a));
    int one,two,three;
    one =upper_bound(all(a),1)-lower_bound(all(a),1);
    two=upper_bound(all(a),2)-lower_bound(all(a),2);
    three=upper_bound(all(a),3)-lower_bound(all(a),3);
    double x=rec(one,two,three);
    cout<<x<<endl;
        
}

Measured memory_bytes: 225664
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 1e5 + 5;

int n, m, x, y, r[N], bz[N], st, en;
vector<int> e[N];
int dg(int x, int la) {
	ff(j, 0, e[x].size()) {
		int y = e[x][j];
		if(y == la || y == en) continue;
		if(y == st) return 1;
		if(!bz[y] && dg(y, x)) return 1;
	}
	return 0;
}

int main() {
	scanf("%d %d", &n, &m);
	fo(i, 1, m) {
		scanf("%d %d", &x, &y);
		r[x] ++, r[y] ++;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	int mr = 0, cnt = 0;
	fo(i, 1, n) {
		if(r[i] & 1) {
			pp("No\n"); return 0;
		}
		mr = max(mr, r[i]);
		if(r[i] == 4) cnt ++;
	}
	if(mr < 4 || (mr == 4 && cnt < 2)) {
		pp("No\n"); return 0;
	}
	if(mr > 4 || (mr == 4 && cnt > 2)) {
		pp("Yes\n"); return 0;
	}
	fo(i, 1, n) if(r[i] == 4) en = st, st = i;
	pp("%s\n", dg(st, 0) ? "Yes" : "No");
}

Measured memory_bytes: 7680
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
  
  string s; cin >> s;
  int n = (int)s.size();
  vector<vector<int>> dp(n + 1, vector<int> (13, 0));
  dp[0][0] = 1LL;
  int mod = 13;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 13; j++){
      
      if(s[i] == '?'){
        for(int k = 0; k < 10; k++){
          int val = j * 10 + k;
          val %= mod;
          dp[i + 1][val] += dp[i][j];
          dp[i + 1][val] %= 1000000007;
        }
      }else{
        int val = j * 10 + (int)(s[i] - '0');
        val %= mod;
        dp[i + 1][val] += dp[i][j];
        dp[i + 1][val] %= 1000000007;;
      }
    }
  }
  
  /*
  for(int i = 0; i <= n; i++){
    for(int j = 0; j < 13; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/

  cout << dp[n][5] << endl;
  return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int a,b,c; cin>>a>>b>>c;
  int k; cin>>k;
  rep(i,pow(3,k)){
    int d=a,e=b,f=c;
    int m=i;
    while(m>0){
      int x=m%3;
      m/=3;
      if(x==0)d*=2;
      if(x==1)e*=2;
      if(x==2)f*=2;
    }
    if(d<e&&e<f){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e10;


signed main() {
    int N, M;
    cin >> N >> M;
    V(P) keys(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        int s = 0;
        rep(j, b) {
            int c;
            cin >> c;
            --c;
            s |= 1<<c;
        }
        keys[i] = P(s, a);
    }

    vi dp(1<<N, INF);
    dp[0] = 0;

    //すべての宝箱の開閉の状態を走査する。
    rep(s, 1<<N) {

        //ある状態からi番目の鍵を購入した時の遷移先の状態の、最小コストを更新する。
        rep(i, M) {
            int t = s | keys[i].fi; //遷移先の状態
            int cost = dp[s] + keys[i].se; //i番目の鍵のコストを足したもの
            dp[t] = min(dp[t], cost); //遷移先のコスト
        }
    }

    int res = dp.back();
    if(res == INF) cout << -1 << endl;
    else cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
// AOJ 2152 Restrictive Filesystem
// 2018.2.24 bal4u

#include <stdio.h>

#define INF 1000000010

typedef struct { int fid, from, end; } T;
T tbl[5000]; int sz;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, j, cmd, id, sec, sno, from, end;

	while (n = in()) {
		tbl[0].fid = -1, tbl[0].from = 0, tbl[0].end = INF, sz = 1;

		while (n--) {
			cmd = getchar_unlocked(), getchar_unlocked();
			if (cmd == 'W') {
				id = in(), sec = in();
				for (i = 0; sec > 0; i++) {
					if (tbl[i].fid >= 0) continue;
					from = tbl[i].from, end = tbl[i].end;
					if (end-from+1 <= sec) {
						tbl[i].fid = id;
						sec -= end-from+1;
					} else {
						tbl[i].fid = id;
						tbl[i].from = from, tbl[i].end = from+sec-1;
						for (j = sz; j > i; j--) tbl[j] = tbl[j-1]; sz++;
						tbl[++i].fid = -1, tbl[i].from = from+sec, tbl[i].end = end;
						break;
					}
				}
			} else if (cmd == 'R') {
				sno = in();
				for (i = 0; i < sz; i++) {
					if (sno >= tbl[i].from && sno <= tbl[i].end) {
						printf("%d\n", tbl[i].fid);
						break;
					}
				}
			} else {		// cmd == 'D'
				id = in();
				for (i = 0; i < sz; i++) if (tbl[i].fid == id) tbl[i].fid = -1;
			}
		}
		putchar('\n');
	}
 	return 0;
}


Measured memory_bytes: 2100
#include<iostream>
using namespace std;
int next[200000]={0};
int prev[200000]={0};
int main (void)
{
    long n,n1,n2,p,c=0;
    long i,j,r;
    cin >> n >> n1 >> n2;
    for(i=0;i<n;i++)
    {
        prev[i] = (i-1+n)%n;
        next[i] = (i+1)%n;
    }
    for(i=0;i<n1;i++)
    {
        cin >> p;
	for(j=0;j<p;j++)
	{
            if(p%2==0)
	    {
		c=next[c];
	    }
	    else
	    {
		c=prev[c];
	    }
        }
	r=c;
        next[prev[c]]=next[c];
        prev[next[c]]=prev[c];
	c=next[c];
        prev[r]=-1;
        next[r]=-1;
    }
    for(i=0;i<n2;i++)
    {
        cin >> p;
        if(next[p]>=0)
        {
            cout << "1" << endl;
        }
        else
        {
            cout << "0" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4656
#include <string>
#include <stack>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
  string word;
  stack<int> S;
  while (cin >>word) { //入力がある限り読み込む
    if (word =="+") {
	  //数を二つpopして、和をpushする
	   int a = S.top();
	  S.pop();
	  int b = S.top();
	  S.pop();
	  S.push(b + a);
	  }
	else if (word =="-") {
	  //数を二つpopして、差をpushする
	  int a = S.top();
	  S.pop();
	  int b = S.top();
	  S.pop();
	  S.push(b - a);
	  }
	else if (word == "*") {
	  //数を二つpopして、席をpushする
	   int a = S.top();
	  S.pop();
	  int b = S.top();
	  S.pop();
	  S.push(b * a);
	  }
	else {
	  //wordを数値にしてpushする
	  int n = atoi(word.c_str());
	  S.push(n);
	  }
	 }
	//Sの先頭要素を表示する
	cout << S.top() << endl;
	}

Measured memory_bytes: 1204
#include <iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<cmath>
#include<unordered_map>
#include<vector>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
const int inf = (1e18)+7;
const int neginf = -1*((int)1e17 ) + 7 ;
const int mod = (int)1e9 +7;
int modularExponentiation(int x,int n,int M)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

int32_t main() {
    fastio
    int n;
    cin>>n;
    string s;
    cin>>s;
    int q;
    cin>>q;
    set<int> st[32];
    for(int i=0;i<n;++i)
    {
        st[s[i]-'a'].insert(i);
    }
    while(q--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int a;
            char ch;
            cin>>a>>ch;
            --a;
            st[s[a]-'a'].erase(a);
            s[a] = ch;
            
            st[s[a]-'a'].insert(a);
        }
        else
        {
            int x,y;
            cin>>x>>y;
            --x;
            --y;
            int ct = 0;
            for(char ch='a';ch<='z';++ch)
            {
               auto ans= st[ch-'a'].lower_bound(x);
                if(ans!=st[ch-'a'].end()&&(*ans)<=y)
                    ct++;
            }
            cout<<ct<<endl;
            
        }
    }
    
    
        
    
            
        
       
        
        
        
    
     
    
    
	return 0;
}

Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
int main(void){
   long long int H, W;
   cin >> H >> W;
    
   long long int ans;
   if (H == 1 || W == 1) {
       ans = 1;
   } else if (H * W % 2 == 0 ) {
       ans = H * W / 2;
   } else {
       ans = H * W / 2 + 1;
   }
   
   cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int N=100010;
int l[N],r[N],odd[N];
vector<int> g[N];
int col[N];
int n;
void dfs(int x,int fa){
	int la=-1,av=1;
	for (auto i:g[x]){
		if (i==fa) continue;
		dfs(i,x);
		if (odd[i]!=-1){
			av&=(la==-1||odd[i]==la);
			la=odd[i];
		}
	}
	if (!av){
		puts("No");
		exit(0);
	}
	l[x]=-1e9; r[x]=1e9; odd[x]=-1;
	for (auto i:g[x]){
		if (i==fa) continue;
		l[x]=max(l[x],l[i]-1);
		r[x]=min(r[x],r[i]+1);
		if (odd[i]!=-1) odd[x]=odd[i]^1;
	}
	if (l[x]>r[x]){
		puts("No");
		exit(0);
	}
	if (col[x]!=-1){
		if (odd[x]==-1){
			odd[x]=col[x]&1;
		}
		if ((col[x]&1)!=odd[x]){
			puts("No");
			exit(0);
		}
		if (l[x]>col[x]||r[x]<col[x]){
			puts("No");
			exit(0);
		}
		l[x]=r[x]=col[x];
	}
}
int m;
int val[N];
void color(int x,int fa){
	if (fa==0){
		for (int i=l[x]; i<=r[x]; ++i)
		if (odd[x]==-1||(i&1)==odd[x]){
			val[x]=i;
			break;
		}
	}
	else{
		if (l[x]<=val[fa]-1&&val[fa]-1<=r[x]) val[x]=val[fa]-1;
		else if (l[x]<=val[fa]+1&&val[fa]+1<=r[x]) val[x]=val[fa]+1;
	}
	for (auto i:g[x]){
		if (i==fa) continue;
		color(i,x);
	}
}
int main(){
	memset(col,-1,sizeof(col));
	scanf("%d",&n);
	for (int i=1; i<n; ++i){
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	scanf("%d",&m);
	for (int i=1; i<=m; ++i){
		int x,y;
		scanf("%d%d",&x,&y);
		col[x]=y;
	}
	dfs(1,0);
	puts("Yes");
	color(1,0);
	for (int i=1; i<=n; ++i) cout<<val[i]<<'\n';
}

Measured memory_bytes: 18884
// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

#include <bits/stdc++.h>
 
using namespace std;

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  pair<int, pair<int, int>>
#define pll   pair<ll, ll>

#define F  first
#define S  second
#define PB push_back
#define MP make_pair

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename T>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

// add templates here

template<class T>
void println(const vector<T> &data) {
    cout << to_string<vector<T>, T>(data) <<endl;
}

template<class T>
void println(const T &data) {
    cout << to_string((T)data) << endl;
}

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);
    
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string S;
    cin >> S;
    unordered_map<char, int> mp;
    for(char ch: S) {
        mp[ch]++;
    }
    if(mp.size() == 2) {
        cout << "Yes" << endl; 
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<double,int> PDI;
const double eps=1e-12;
const int INF=0x3f3f3f3f;
const LL inf=1e18;
const double pi=acos(-1.0);
const int mod=1e9+7;
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int v[55];
int main(){
//    freopen("in.txt","r",stdin);
//    freopen("outt.txt","w",stdout);
    int t;
    string s;
    cin>>s;
    LL n=SZ(s);
    LL ans=n*(n-1)/2+1;
//    cout<<ans<<endl;
    for(auto i:s){
        v[i-'a']++;
    }
    for(int i=0;i<26;i++){
        n=v[i];
        ans-=n*(n-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int n,m=0,a[40],b[40],c[41];
void solve(int l,int r){
  if(l>r)return;
  int x=a[m++];
  solve(l,c[x]-1);
  solve(c[x]+1,r);
  cout<<x<<(x==a[0]?"\n":" ");
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i],c[b[i]]=i;
  solve(0,n-1);
  return 0;
}



Measured memory_bytes: 3100