akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll i,N,ans=0,x;
  cin>>N;
  while(N--){
    cin>>x;
    ans=gcd(ans,x);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 1e5+10;;
char s[maxd];
int a[maxd],n,k,q,m;
priority_queue<int> que;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        que.push(x);
    }
    while(m--)
    {
        int x = que.top();que.pop();
        que.push(x/2);
    }
    long long ans = 0ll;
    while(!que.empty()) 
    {
        ans += que.top();
        que.pop();
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

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

int main(){
  string s, t;
  cin >> s >> t;
  int ssz=s.size(), tsz=t.size();
  vector<int> sindex[26];
  rep(i, ssz){
    sindex[s[i]-'a'].push_back(i);
  }
  int num=0;
  ll ans=0;
  int ti=0;
  while(ti<tsz){
    auto it=lower_bound(sindex[t[ti]-'a'].begin(), sindex[t[ti]-'a'].end(), num);
    if(it==sindex[t[ti]-'a'].end() &&num!=0){
      ans+=ssz-num;
      num=0;
    } else if(it==sindex[t[ti]-'a'].end() &&num==0){
      cout << "-1" << endl;
      return 0;
    } else if(it!=sindex[t[ti]-'a'].end()){
      int tmp=num;
      ans+=*it+1-tmp;
      num+=*it+1-tmp;
      ti++;
    }

  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL N = 1000000007;

LL n,l,r;
LL a[5005],dp[5005];

int main(){
	memset(dp,0x3f,sizeof(dp));
	cin >> n >> r >> l;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		a[i] ++;
	}
	a[0] = 1; dp[0] = 0; a[n + 1] = n + 2;
	for(LL i = 1;i <= n + 1;i ++){
		LL sr = 0,sl = 0;
		for(LL j = i - 1;j >= 0;j --){
			if(a[j] < a[i]) dp[i] = min(dp[i],dp[j] + r * sr + l * sl);
			if(a[j] > a[i]) sr ++; if(a[j] < a[i]) sl ++;
		}
	}
	cout << dp[n + 1] << endl;
	return 0;
}

Measured memory_bytes: 384
f = []
input = int(input())
for i in range(input + 1):
    if i % 3 == 0 and i % 5 == 0:
        c = 'FizzBuzz'
    elif i % 5 == 0:
        c = 'Buzz'
    elif i % 3 == 0:
        c = 'Fizz'
    else:
        c = i
    f.append(c)
c1 = [num for num in f if isinstance(num, (int, float))]
print(sum(c1))

Measured memory_bytes: 37896
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    N = int(input())
    A = list(map(int, input().split()))

    A = [a - (i + 1) for i, a in enumerate(A)]
    A.sort()
    b = A[(N + 1) // 2 - 1]

    res = 0
    for a in A:
        res += abs(a - b)

    print(res)


if __name__ == '__main__':
    main()


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

int main(){
	int H,W;
	int i,j;

	while(1){
		cin >> H >> W;
		if(H==0 && W==0) break;

		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i+j) % 2 == 0){
					cout << "#";
				} else {
					cout << ".";
				}

			}
			cout << "\n";

		}
		
		cout << endl;

	}

	return 0;

}

Measured memory_bytes: 3108
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCoder {
    class Program {
        static void Main (string[] args) {

            string[] line = Console.ReadLine().Trim().Split(' ');
            int a = int.Parse(line[0]);
            int b = int.Parse(line[1]);
            string ans = string.Empty;
            
            if (a ==1 && b==1)
            {
                ans = "Draw";
            }
            else if (a==1)
            {
                ans = "Alice";
            }
            else if  (b==1)
            {
                ans = "Bob";
            }
            else if (a > b)
            {
                ans = "Alice";
            }
            else if (b > a)
            {
                ans = "Bob";
            }
            else
            {
                ans="Draw";
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>

int main(){
  std::string str;
  std::cin>>str;
  if(str=="SUN"){
    std::cout<<7<<std::endl;
  }
  if(str=="MON"){
    std::cout<<6<<std::endl;
  }
  if(str=="TUE"){
    std::cout<<5<<std::endl;
  }
  if(str=="WED"){
    std::cout<<4<<std::endl;
  }
  if(str=="THU"){
    std::cout<<3<<std::endl;
  }
  if(str=="FRI"){
    std::cout<<2<<std::endl;
  }
  if(str=="SAT"){
    std::cout<<1<<std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) {//最大公約数
    if(a<b){
        ll tmp = a;
        a = b;
        b = tmp; 
    }
    if (b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {//最小公倍数
    return a * b / gcd(a, b);
}

int main(){
    int p,q,r;
    cin >> p >> q >> r;
    int ans;
    ans = min(p+q,p+r);
    ans = min(ans,q+r);
    cout << ans << endl;    
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec


using namespace std;

int main() {
    ll n;
    cin >> n;
    cout << n / 2 + (n & 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll d;
    cin >> d;
    vector<ll> contest_variety(26,0);
    vector<ll> c(26,0);
    rep(i,26){
        cin >> c[i];
    }
    vector<vector<ll>> calender(d,vector<ll> (26,0));
    rep(i,d){
        rep(j,26){
            cin >> calender[i][j];
        }
    }
    vector<ll> choose(d);
    rep(i,d) {
        cin >> choose[i];
        choose[i]--;
    }
    vector<ll> tmp_minus(26,0);
    ll m;
    cin >> m;
    rep(i,m) {
        ll a, q;
        cin >> a >> q;
        choose[a - 1] = q - 1;
        ll ans = 0;
        contest_variety.assign(26,0);
        rep(i, d) {
            ans += calender[i][choose[i]];
            contest_variety[choose[i]] = i + 1;
            rep(j, 26) {
                ans -= c[j] * (i + 1 - contest_variety[j]);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
    int n;
  	cin >> n;
  	if(n<2){
        cout<<"Yes";   
    	return 0;
    }
  	int h[n];
  	int array[n];
  	for(int i=0;i<n;i++){
      cin>>h[i];
    }
  
  	for(int i=n-1;i>0;i--){
      if(h[i-1]>h[i]){
        h[i-1]-=1;
      }
    }
    for(int i=n-1;i>0;i--){
      if(h[i-1]>h[i]){
        cout<<"No";
        return 0;
      }
    }
  	cout<<"Yes";
    return 0;
}


Measured memory_bytes: 640
/*
	Templates start.
	Powered by c++11.
	Author : Alex_Wei.
*/

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

// IO templates.

char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
#ifdef __WIN64
	#define gc getchar()
#else
	#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#endif
#define pc(x) (*O++=x)
#define flush() fwrite(obuf,O-obuf,1,stdout)

inline int read(){
	int x=0,sign=0; char s=getchar();
	while(!isdigit(s))sign|=s=='-',s=getchar();
	while(isdigit(s))x=(x<<1)+(x<<3)+(s-'0'),s=getchar();
	return sign?-x:x;
}
void print(int x) {if(x>9)print(x/10); pc(x%10+'0');}

#define ll long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define mem(x,v) memset(x,v,sizeof(x))

/*
	Templates end.
	Please give me more points.
*/

const int N=2e5+5;

int k,n,a[N],ans;

int main(){
	cin>>k>>n;
	for(int i=1;i<=n;i++)cin>>a[i],ans=max(ans,(i==1?0:a[i]-a[i-1]));
	cout<<k-max(ans,k+a[1]-a[n])<<endl;
	return 0; 
}

Measured memory_bytes: 1024
import math
def ip():return int(input())
def inp():return map(int,input().split())
def inpstr():return map(str,input().split())
def linp():return list(map(int,input().split()))
def linpstr():return list(map(str,input().split()))

a,b=inp()
ans=0
if a<b:a,b=b,a
ans+=a
a=a-1
if a<b:a,b=b,a
ans+=a
print(ans)


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define minit(a, b) memset(a, b, sizeof(a))
#define size_of(a) (int)(a).size()

typedef long long lint;

struct Edge {
	int to; lint dst;
	Edge (int to_, lint dst_) : to(to_), dst(dst_) {}
	bool operator > (const Edge& e) const { return dst > e.dst; }
};

void minUpdate(lint& a, lint b) { a = min(a, b); }

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;

int n, m, c, s, g;
int p[22], q[22][55], r[22][55];
vector< vector< Edge > > edges;

lint cost[22][111][111], dist[22][111][111], price[22][20010];
lint minCost[111];

int djk() {
	fill(minCost, minCost + 111, lINF);
	priority_queue< Edge, vector< Edge >, greater< Edge > > que;
	que.push(Edge(s, 0));
	minCost[s] = 0;
	
	while (!que.empty()) {
		Edge e = que.top(); que.pop();
		int u = e.to, dst = e.dst;
		
		if (minCost[u] < dst) continue;
		
		for_(ci,0,c) {
			for_(v,0,n) {
				if (cost[ci][u][v] == iINF) continue;
				
				int nx_cost = dst + cost[ci][u][v];
				if (minCost[v] > nx_cost) {
					minCost[v] = nx_cost;
					que.push(Edge(v, nx_cost));
				}
			}
		}
	}
	
	return (minCost[g] == lINF) ? -1 : minCost[g];
}

void solve() {
	for_(ci,0,c) {
		for_(k,0,n) for_(i,0,n) for_(j,0,n) {
			minUpdate(dist[ci][i][j], dist[ci][i][k] + dist[ci][k][j]);
		}
	}
	
	for_(ci, 0, c) {
		for_(u,0,n) for_(v,0,n) {
			if (dist[ci][u][v] == iINF) {
				cost[ci][u][v] = iINF;
				continue;
			}
			
			assert(dist[ci][u][v] <= 20000);
			cost[ci][u][v] = price[ci][dist[ci][u][v]];
		}
	}
	
	cout << djk() << endl;
}

int main() {
	while (cin >> n >> m >> c >> s >> g, n) {
		--s; --g;
		
		for_(i,0,22) for_(j,0,111) for_(k,0,111) dist[i][j][k] = iINF;
		
		edges.assign(n, vector< Edge >());
		
		for_(i,0,m) {
			int x, y, cmp; lint dst;
			cin >> x >> y >> dst >> cmp;
			--x; --y; --cmp;
			edges[x].push_back(Edge(y, dst));
			edges[y].push_back(Edge(x, dst));
			dist[cmp][x][y] = dist[cmp][y][x] = min(dist[cmp][y][x], dst);
		}
		
		for_(ci,0,c) cin >> p[ci];
		
		minit(price, 0);
		
		for_(ci,0,c) {
			for_(j,0,p[ci]-1) cin >> q[ci][j];
			for_(j,0,p[ci]) cin >> r[ci][j];
			q[ci][p[ci]-1] = 20005;
			
			int cur = 1;			
			for_(j,0,p[ci]) {
				int qj = q[ci][j];
				while (cur <= q[ci][j]) {
					price[ci][cur] = price[ci][cur - 1] + r[ci][j];
					++cur;
				}
			}
		}
		
		solve();
	}
}

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 3) {
        if (s.at(i) == 'R') ans = 1;
    }
    if (s.at(0) == 'R' && s.at(1) == 'R') {
        ans = 2;
    }
    if (s.at(1) == 'R' && s.at(2) == 'R') {
        ans = 2;
    }
    if (s.at(0) == 'R' && s.at(1) == 'R' && s.at(2) == 'R') {
        ans = 3;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int main ( )
{
	int a[50]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    rep(i, 100) rep(j, 100) {
        if (7 * i + 4 * j == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



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

ll mov[13][4] = {
	{2,-1,-1,-1},
	{2,5,-1,-1},
	{0,1,3,6},
	{2,7,-1,-1},
	{5,-1,-1,-1},
	{1,4,6,9},
	{2,5,7,10},
	{3,6,8,11},
	{7,-1,-1,-1},
	{5,10,-1,-1},
	{6,9,11,12},
	{7,10,-1,-1},
	{10,-1,-1,-1},
};

ll sw(ll l, int i, int j) {
	int a, b;
	a = (l >> (4 * i)) & 0xfL;
	b = (l >> (4 * j)) & 0xfL;

	l &= ~(0xfL << (4*i));
	l &= ~(0xfL << (4*j));

	l |= (ll)b << (4 * i);
	l |= (ll)a << (4 * j);

	return l;
}

int main() {
	while(1) {
		ll in = 0;
		for(int i = 0; i < 13; i++) {
			int tmpin;
			cin >> tmpin;
			if(tmpin < 0)
				return 0;
			in |= ((ll)tmpin << (4*i));
		}

		queue<ll> q;
		set<ll> s;
		q.push(in);
		s.insert(in);
		int ans = -1;
		// debug
		int failcount = 0;
		for(int i = 0; i <= 20; i++) {
			queue<ll> next;
			while(!q.empty()) {
				ll l = q.front(); q.pop();
				if(l == 0xba9876543210) {
					ans = i;
					goto OUTPUT_ANSWER;
				}
				else {
					int cnt = 0;
					for(int j = 0; j < 13; j++) {
						ll t = 0xba9876543210;
						if(((l >> 4*j) & 0xfL) != ((t >> 4*j) & 0xfL)) {
							cnt++;
						}
					}
					if(cnt > 20 - i + 3)
						continue;
				}

				for(int j = 0; j < 13; j++) {
					if(((l >> (4*j)) & 0xfL) == 0) {
						for(int k = 0; k < 4; k++) {
							ll p;
							if(mov[j][k] < 0)
								break;
							p = sw(l, j, mov[j][k]);
							if(s.find(p) == s.end()) {
								s.insert(p);
								next.push(p);
							}
							else {
								failcount++;
							}
						}
					}
				}
			}
			q = next;
		}

OUTPUT_ANSWER:;
		if(ans < 0)
			cout << "NA" << endl;
		else
			cout << ans << endl;
//		cout << failcount << endl;
	}
}

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

int main() {
  int X,N;
  cin>>X>>N;
  if(N==0){
    cout<<X<<endl;
  }
  if(N!=0){
    vector<int> P(N);
    for(int i=0;i<N;i++){
      int p;
      cin>>p;
      P.at(i)=p;
    }
    
    int a=X;
    int b=X;
    int c=0;
    
    while(c==0){
      int A=a;
      int B=b;
      
      for(int j=0;j<N;j++){
        if(P.at(j)==a){
          a++;
          break;
        }
      }
      for(int k=0;k<N;k++){
        if(P.at(k)==b){
          b-=1;
          break;
        }
      }
      if(B==b){
        cout<<B<<endl;
        c++;
      }
      else if(A==a){
        cout<<A<<endl;
        c++;
      }
    }      
  }
}

Measured memory_bytes: 3628
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
long long geko[200000] = {};
int main() {
	int n;
	cin >> n;
	vector<int> a, b, c;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	REP(i, n) {
		int tmp;
		cin >> tmp;
		b.push_back(tmp);
	}
	REP(i, n) {
		int tmp;
		cin >> tmp;
		c.push_back(tmp);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	int itring = 0;
	for (int i = 0;i < n;++i) {
		while (itring != n&&b[i] >= c[itring]) {
			itring++;
		}
		geko[i] = n - itring;
	}
	for (int i = n - 2;i >= 0;--i) {
		geko[i] += geko[i + 1];
	}
	long long ans = 0;
	itring = 0;
	for (int i = 0;i < n;++i) {
		while (itring != n&&a[i] >= b[itring]) {
			itring++;
		}
		ans += geko[itring];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2296
import sys

R, G, B, N = map(int, sys.stdin.readline().split())

r_max = N // R
g_max = N // G

ans = 0
for r in range(r_max+1):
    for g in range(g_max+1):
        res = N - r * R - g * G
        if 0 <= res and res % B == 0:
            # print(r, g, res // B)
            ans += 1

print(ans)

Measured memory_bytes: 67844
<?php
    
    //文字列を配列にしたものとそのままのものを同時に扱っていく
    $line = trim(fgets(STDIN));
    
    $num = intval(trim(fgets(STDIN)));
    
    $front=1;
    
    for($i=0;$i<$num;$i++){
        $array = array_map(null,explode(" ",trim(fgets(STDIN))));
        if($array[0] == "1"){
            if($front==1){
                $front=0;
            }else{
                $front=1;
            }
        }elseif($array[0] == "2"){
            if($array[1] == "1"){
                if($front == 1){
                    $line = $array[2].$line;
                }else{
                    $line = $line.$array[2];
                }
            }elseif($array[1] == "2"){
                if($front == 0){
                    $line = $array[2].$line;
                }else{
                    $line = $line.$array[2];
                }
            }
        }
        // echo $line."\n";
    }

    if($front==1){
        echo $line;
    }else{
        echo strrev($line);
    }

    
?>

Measured memory_bytes: 17200
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

H, W, D = map(int, raw_input().split())
m = [0] * (H * W + 1)
for i in range(H):
    A = map(int, raw_input().split())
    for j in range(W):
        m[A[j]] = (i, j)

DP = [[0] for i in range(D)]

for i in range(D, H * W):
    x1, y1 = m[i + 1]
    x2, y2 = m[i + 1 - D]
    dist = abs(x1 - x2) + abs(y1 - y2)
    ls = DP[i % D]
    ls.append(ls[-1] + dist)

Q = input()

for i in range(Q):
    L, R = map(int, raw_input().split())
    ls = DP[(R - 1) % D]
    print ls[(R - 1) / D] - ls[(L - 1) / D]

Measured memory_bytes: 23588
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int main(){
    int n;
    scanf("%d", &n);
    pii p[2*n];
    rep(i, n*2){
        int a;
        scanf("%d", &a);
        if(i < n) p[i] = make_pair(a, 0);
        else p[i] = make_pair(a, 1);
    }
    sort(p, p+2*n);
    lint pc = 0;
    lint pw = 0;
    lint ans = 1;
    lint mod = 1e9 + 7;
    rep(i, 2*n){
        if(p[i].se){
            if(pc) ans = ans * (pc--) % mod;
            else ++pw;
        }
        else{
            if(pw) ans = ans * (pw--) % mod;
            else ++pc;
        }
    }
    printf("%lld\n", ans);
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)



int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    
    ll g = n/(a+b);
    ll c = n%(a+b);
    
    ll ans = g*a;
    ans += min(c,a);
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int mod = 1000000007;

int euc(int nn, int mm){
    int n = nn; int m = mm;
    int k = n % m;
    if (k == 0) return min(n,m);
    while (k != 0){
        n = m;
        m = k;
        k = n % m;
    }
    return m;
}

int main(){
    int n; cin >> n;
    n++;
    ll ans = 0;
    repp(i,n,1)repp(j,n,1)repp(k,n,1) ans += euc(euc(i,j),k);
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

// Union-Find木
template <typename T>
struct UnionFind {
  int n;
  vector<T> rank;

 private:
  vector<T> par;

 public:
  explicit UnionFind(int n) {
    this->n = n;
    par = vector<T>(n, 0);
    iota(par.begin(), par.end(), 0);
    rank = vector<T>(n, 0);
  }
  // 木の根を求める
  T root(T x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  // x と y が同じ集合に属するか調べる
  bool same(T x, T y) {
    return root(x) == root(y);
  }
  // x と y が属する集合を併合する
  void unite(T x, T y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  // 所属する集合の番号を返す
  vector<int> get_group() {
    vector<int> g(n, 0);
    for (int i = 0; i < n; i++) {
      g[i] = root(i);
    }
    return g;
  }
  // 連結成分の数を数える
  int groups() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      // グループには根が自分と同じものが一つずつある
      if (par[i] == i) ans++;
    }
    return ans;
  }
};

// カウンター
template <typename T>
struct Counter {
  map<T, ull> cnt;
  void add(T key) {
    if (cnt.count(key)) {
      cnt[key]++;
    } else {
      cnt[key] = 1;
    }
  }
  void add(vector<T> keys) {
    for (auto key : keys) {
      add(key);
    }
  }
  ll get(T key) {
    if (cnt.count(key)) {
      return cnt[key];
    } else {
      return 0;
    }
  }
  pair<T, ull> max() {
    T key;
    ull mx = 0;
    for (auto kv : cnt) {
      if (kv.second > mx) {
        mx = kv.second;
        key = kv.first;
      }
    }
    return make_pair(key, mx);
  }
  typename map<T, ll>::iterator begin() {
    return cnt.begin();
  }
  typename map<T, ll>::iterator end() {
    return cnt.end();
  }
  typename map<T, ll>::reverse_iterator rbegin() {
    return cnt.rbegin();
  }
  typename map<T, ll>::reverse_iterator rend() {
    return cnt.rend();
  }
};

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

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

  UnionFind<int> road(N);
  UnionFind<int> rail(N);

  REP(i, K) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    road.unite(p, q);
  }
  REP(i, L) {
    int r, s;
    cin >> r >> s;
    r--;
    s--;
    rail.unite(r, s);
  }

  Counter<pair<int, int>> c;
  vector<int> roadg = road.get_group();
  vector<int> railg = rail.get_group();
  REP(i, N) {
    c.add(make_pair(roadg[i], railg[i]));
  }
  REP(i, N) {
    cout << c.get(make_pair(roadg[i], railg[i]));
    if (i < N - 1) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{
    ll n;
    cin>>n;
    ll a[n+1];
    a[0]=0;
    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]!=i)
        {
            cnt++;
        }
    }
    if(cnt!=2 && cnt!=0)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
    return 0;
}











Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<string, map<int, int> > data;
    for(int i = 1; i <= n; ++i){
        string s;
        int p;
        cin >> s >> p;
        auto itr = data.find(s);
        if(itr == data.end()){
            map<int, int> tmp_p;
            tmp_p[p] = i;
            data[s] = tmp_p;
        }else{
            itr->second[p] = i;
        }
    }
    for(auto itr = data.begin(); itr != data.end(); ++itr){
        for(auto itr2 = itr->second.rbegin(); itr2 != itr->second.rend(); ++itr2){
            cout << itr2->second << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int n, k;
int a[100001];
vector <int> ans;
 
int main () {
	cin >> n >> k;
	int pos  = 0;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
		if (i > 1 && a[i] + a[i - 1] >= k) {
			pos = i - 1;
		}
	}
	if (!pos) {
		cout << "Impossible";
		return 0;
	}
	cout << "Possible\n"; 
	for (int i = 1;i < pos;i ++) ans.push_back (i);
	for (int i = n - 1;i > pos;i --) ans.push_back (i);
	ans.push_back (pos);
	for (auto to : ans) cout << to << "\n";
	return 0;
}

Measured memory_bytes: 1784
r={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
import sys
for e in sys.stdin:
 a=0
 n=[r[c]for c in e.strip()]
 for i in range(len(n)):
  if i+1<len(n)and n[i]<n[i+1]:a-=n[i]
  else:a+=n[i]
 print(a)


Measured memory_bytes: 5572
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <numeric>
#include <tuple>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);

lint n, d;
lint h, w;

int main(){
//////////////////////////////////////////////////////

    cin >> n >> d;
    //vector<lint> s(n);
    //fpair<lint,lint> p = make_pair(1,2);
    //tuple<lint,lint,lint> t  = make_tuple(1,2,3);






    //昇順ソート
    //sort(all(a));

   

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();


    //////////////////////////////////////////////////////
    // DP

//     // 無限大の値
//     const uint64_t INF = (uint64_t)1 << 60;
//     //const int64_t NINF = -1 * ((int64_t)1 << 60 );
 
//     // DP テーブル
//     uint64_t dp[100010];

//     //DPテーブル初期化（最小化用）
//     for (int i = 0; i < 100010; ++i)
//     {
//         //dp[i] = INF;
//         dp[i] = 0;
//     } 

//     // 初期条件
//     dp[0] = 0;

//     // ループ
//     for (int i = 1; i <= n; ++i) {
//         //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
//         //if (i < 2)continue;
//         //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));



//         // chmax ( dp [i] , dp[i - 1]);
//         // chmax ( dp [i] , dp[i - 1] + input[i]);
//         // cout << "dp[" << i <<"] = " << dp[i] << endl;

//     }



// //////////////////////////////////////////////////////

     cout << (n+(d*2+1)-1)/(d*2+1) << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
template<class T> inline bool chmin(T& a, T b)
{
    if (a > b) 
    {
        a = b;
        return true;
    }
    return false;
}

//最大化関数
template<class T> inline bool chmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// //合計
// template<class T> lint sum(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0);
// }


// //平均
// template<class T> double ave(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using namespace std;

typedef long long ll;

int main() {
	/*string s;
	cin >> s;
	rep(i, 4) {
		int a = 0;
		rep(j, 4) { 
			if (s[i] == s[j])a++;
		}
		if (a != 2) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";*/

	/*int n;
	cin >> n;
	vector<int>p(n + 1);
	int i;
	for (i = 1; i < n + 1; i++)cin >> p[i];
	int ans = 0;
	for (i = 2; i < n; i++) {
		if (p[i] != min({ p[i - 1],p[i],p[i + 1] }) && p[i] != max({ p[i - 1],p[i],p[i + 1] }))ans++;
	}
	cout << ans;*/


	/*int N;
	cin >> N;
	vector<int>d(N);
	int i;
	rep(i, N)cin >> d[i];
	sort(all(d));
	cout << d[N / 2] - d[N / 2 - 1];*/

	int N, K;
	cin >> N >> K;
	vector<vector<int>>c(2005, vector<int>(2005));
	c[0][0] = 1;
	int i, j;
	for (i = 1; i < 2005; i++)for (j = 0; j <= i; j++) {
		if (j == 0 || j == i)c[i][j] = 1;
		else {
			c[i][j] += c[i - 1][j - 1] + c[i - 1][j];
			c[i][j] %= mod;
		}
	}
	ll a, b;
	for (i = 1; i <= K; i++) {
		ll ans = 0;
		if (i <= N - K + 1) {
			a = c[N - K + 1][i];
			b = c[K - 1][i - 1];
			ans = a * b % mod;
		}
		cout << ans << "\n";
	}
	
	
	return 0;
}

Measured memory_bytes: 16000
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
    vll a; a.push_back(A);a.push_back(B);a.push_back(C);
    sort(ALL(a));
    if(A==B && B==C && A==C){
        cout<<YES<<endl;
    }
    else cout<<NO<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi") print("Yes");
  else print("No");
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
void read(long long &x)
{
    char ch;
	bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); if(ok)x=-x;
}
#define rg register
const int maxn=110;
long long a,b,x,y,l,r,ans,ll,rr;
int aa[maxn],bb[maxn],lena,lenb,len,k;
int main()
{
    read(a);
	read(b);
	x=a;
	y=b;
    while(a) aa[++lena]=a&1,a>>=1;
    while(b) bb[++lenb]=b&1,b>>=1;
    for(rg int i=max(lena,lenb);i;i--)
	{
        if(aa[i]!=bb[i]) {len=i;break;}
        x-=1ll*aa[i]<<(i-1);
        y-=1ll*bb[i]<<(i-1);
    } 
    for(rg int i=len-1;i;i--) if(bb[i]) {k=i;break;}
    l=x,r=(1ll<<(len-1))+(1ll<<k)-1;
    ll=(1ll<<(len-1))+x,rr=(1ll<<len)-1;
    if(ll>r)ans=r-l+1+rr-ll+1;
    else ans=rr-l+1;
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int
void dfs(ll i, vector< bool > &vis, unordered_map< ll, ll > &mymap, vector< ll > adj[], ll n, vector< ll > &a)
{
	vis[i]=true;
	ll j;
	mymap[i]++;
	mymap[a[i]]++;
	for(j=0;j<adj[i].size();j++)
	{
		if(vis[adj[i][j]]==false)
		dfs(adj[i][j], vis, mymap,adj, n,a);
	}
}
int main()
{
	ll i,j,k,n,t,m,p;
	cin>>n>>m;
	vector< ll > a;
	a.push_back(0);
	for(i=1;i<=n;i++)
	{
		cin>>k;
		a.push_back(k);
	}
    vector< ll > adj[n+1];
    for(i=0;i<m;i++)
    {
    	cin>>j>>k;
    	adj[j].push_back(k);
    	adj[k].push_back(j);
    }
    vector< bool > vis(n+1,false);
    k=0;
    for(j=1;j<=n;j++)
    {
    	if(vis[j]==false)
    	{
    		unordered_map< ll, ll > mymap;
    		dfs(j,vis, mymap, adj, n,a);
    		unordered_map< ll, ll > :: iterator itr;
    		itr=mymap.begin();
    		while(itr!=mymap.end())
    		{
    			if(itr->second==2)
    			k++;
    			itr++;
    		}
    	}
    }
    cout<<k<<endl;
	return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int N;
  cin >> N;
  vector<int> isA(1000001, 0), is_prime(1000001, 1);
  for(int n = 0; n < N; ++n) {
    int a;
    cin >> a;
    ++isA[a];
  }
  bool setwise = true, pairwise = true;
  for(int p = 2; p <= 1000000; ++p) {
    if(not is_prime[p]) {
      continue;
    }
    int cnt = 0;
    for(int q = p; q <= 1000000; q += p) {
      is_prime[q] = 0;
      cnt += isA[q];
    }
    if(cnt == N) {
      setwise = false;
    }
    if(cnt >= 2) {
      pairwise = false;
    }
  }
  if(pairwise) {
    cout << "pairwise coprime\n";
  } else if(setwise) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
}


Measured memory_bytes: 11128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=45,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,h[N][N];
ll ans,f[N][N][N],g[N][N][N];
char ch[N];
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=read()*2;
	for (int i=1;i<=n;i++){
		scanf(" %s",ch+1);
		f[i][i][i]=1;
		for (int j=1;j<=n;j++) 
		if ((h[i][j]=ch[j]-'0')&&(i<j)) g[i][i][j]=1;;
	}
	for (int L=3;L<=n;L+=2)
	for (int i=1;i+L-1<=n;i++){
		int j=i+L-1;
		for (int l=i;l<j;l+=2)
		for (int r=l+2;r<=j;r+=2){
			ll s=0;
			for (int y=r;y<=j;y++) s+=g[i][l][y]*f[r][j][y];
			for (int t=l+1;t<r;t++) f[i][j][t]+=s*f[l+1][r-1][t];
		}
		for (int x=i;x<=j;x++)
		for(int y=j+1;y<=n;y++)
		if (h[x][y]) g[i][j][y]+=f[i][j][x];
	}
	ans=0;
	for (int i=2;i<=n;i++)
	if (h[1][i]) ans+=f[2][n][i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          998244353
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<class T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in();
    string s; cin >> s;
    vector<ll>black(n + 1, 0), white(n + 1, 0);
    REP(i, n) {
        if (s[i] == '#')++black[i];
        else ++white[i];
    }
    REP(i, n) {
        black[i + 1] += black[i];
        white[n - i - 1] += white[n - i];
    }
    ll ans = white[0];
    REP(i, n) {
        ans = min(ans, black[i] + white[i + 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
#define N 1000 + 5
#define INF 0x3f3f3f3f

int n, mxid, Op[N];
LL A[N];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
	{
		scanf("%lld", A + i);
		mxid = (!mxid || A[mxid] < A[i]) ? i : mxid;
	}
	if (A[mxid] <= 0)
	{
		printf("%lld\n", A[mxid]);
		printf("%d\n", n - 1);
		for (int i = n; i > mxid; i --)
			printf("%d\n", i);
		for (int i = 1; i < mxid; i ++)
			puts("1");
		return 0;
	}
	while (n > 1)
	{
		LL odd = 0, even = 0;
		for (int i = 1; i <= n; i += 2)
			odd += max(A[i], 0LL);
		for (int i = 2; i <= n; i += 2)
			even += max(A[i], 0LL);
		if (odd >= even)
		{
			if (n % 2 == 0 || A[n] <= 0)
				Op[++ Op[0]] = n --;
			else if (A[n - 2] > 0)
				Op[++ Op[0]] = n - 1, A[n - 2] += A[n], n -= 2;
			else if (n > 3)
				Op[++ Op[0]] = n - 2, A[n - 3] += A[n - 1], A[n - 2] = A[n], n -= 2;
			else Op[++ Op[0]] = n - 2, A[n - 2] = A[n - 1], A[n - 1] = A[n], n --;
		}
		else
		{
			if (n % 2 == 1 || A[n] <= 0)
				Op[++ Op[0]] = n --;
			else if (n == 2)
				Op[++ Op[0]] = n - 1, A[n - 1] = A[n], n --;
			else if (A[n - 2] > 0)
				Op[++ Op[0]] = n - 1, A[n - 2] += A[n], n -= 2;
			else Op[++ Op[0]] = n - 2, A[n - 3] += A[n - 1], A[n - 2] = A[n], n -= 2;
		}
	}
	printf("%lld\n", A[1]);
	for (int i = 0; i <= Op[0]; i ++)
		printf("%d\n", Op[i]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main( void ) {
	int h, w, d, dSq;

	for ( ; scanf( "%d %d", &h, &w ), h; printf( "%d %d\n", h, w ) ) {
		for ( d = dSq = h * h + w * w; ; d++ )
			for ( h = d == dSq ? h + 1 : 1; h * h * 2 < d; h++ ) {
				w = sqrt( d - h * h );

				if ( w * w == d - h * h )
					goto contin;
			}

		contin: ;
	}

	return 0;
}

Measured memory_bytes: 600
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########
    

def warshall_floyd(G):
    # G[i][j]: iからjへの最短距離
    N = len(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])
    return G

def main():
    # https://atcoder.jp/contests/abc016/tasks/abc016_3
    N, M, R = l_inpl()
    r = list(map(int, input().split()))
    r = [ ri - 1 for ri in r ]

    # 隣接行列 G, 存在しない辺はINF
    G = [[INF] * N for _ in range(N)]

    # 自身に向かうコストは0
    for i in range(N):
        G[i][i] = 0

    for _ in range(M):
        a, b, c = l_inpl()
        a, b = a-1, b-1
        G[a][b] = c
        G[b][a] = c

    G = warshall_floyd(G)

    ans = INF
    for l in permutations(r):
        tmp = 0
        for i in range(len(l)-1):
            tmp += G[l[i]][l[i+1]]
        ans = min(tmp, ans)

    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 47960
#define _USE_NATH_DEFINES
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int n, l;
	cin >> n >> l;
	string s[n];
	for (int i = 0; i < n; ++i) cin >> s[i];

	sort(s, s + n);

	for (int i = 0; i < n; ++i) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}



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

namespace AtTest.C_Challenge
{
    class ABC_094
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] xs = ReadInts();
            var xSub = new int[n];
            for (int i = 0; i < n; i++)
            {
                xSub[i] = xs[i];
            }
            Array.Sort(xSub);
            int medMin = xSub[n / 2 - 1];
            int medMax = xSub[n / 2];
            for (int i = 0; i < n; i++)
            {
                if (xs[i] <= medMin)
                {
                    Console.WriteLine(medMax);
                }
                else
                {
                    Console.WriteLine(medMin);
                }
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)

signed main(){
  int A,B,N,M,count=0,count2=0,count3=0;
  str S,T;
  int C='A'-'a';
  cin>>S;
  vstr W(N);
  rep(0,S.size()){
    REP(0,S.size()){
      if(S.at(i)==S.at(j))count+=1;
    }
  }
  if(count==S.size())cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}


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

int main(){
    int time;
    string res=""; 
    cin >> time;

    res += to_string(time/3600);
    res += ":";
    res += to_string(time%3600/60);
    
    res += ":";
    res += to_string(time%3600%60);
    cout << res << endl;
}


Measured memory_bytes: 3232
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define NMAX 9
#define MMAX 30

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int A[MMAX],B[MMAX];
int C,N,M,W,H,ans = 0;
string S;
vector<int > con[NMAX],rest;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void dfs(int a){
	if(rest.empty()){
		ans++;
	}
	for (int i = 0; i < con[a].size(); ++i)
	{
		if(find(rest.begin(), rest.end(),con[a][i]) != rest.end()){
			rest.erase(find(rest.begin(), rest.end(),con[a][i]));
			dfs(con[a][i]);
			rest.push_back(con[a][i]);
		}
	}
}

void solve(){
	for (int i = 1; i < N; ++i)
	{
		rest.push_back(i+1);
	}
	dfs(1);
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	
	cin >> N >> M;
	for (int i = 0; i < M; ++i)
	{
		cin >> A[i] >> B[i];
		con[A[i]].push_back(B[i]);
		con[B[i]].push_back(A[i]);
	}

	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256