akhauriyash/Code-Regression huggingface dataset:
//https://www.geeksforgeeks.org/check-graphs-cycle-odd-length/
#include<bits/stdc++.h>
using namespace std;

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}

ll V;
bool graph[200][200];


bool containsOdd(int src) {
	int colorArr[V];
	for (int i = 0; i < V; ++i)
		colorArr[i] = -1;

	colorArr[src] = 1;

	queue <int> q;
	q.push(src);

	while (!q.empty())
	{
		// Dequeue a vertex from queue
		int u = q.front();
		q.pop();

		// Return true if there is a self-loop
		if (graph[u][u])
		return true;

		// Find all non-colored adjacent vertices
		for (int v = 0; v < V; ++v)
		{
			// An edge from u to v exists and destination
			// v is not colored
			if (graph[u][v] && colorArr[v] == -1)
			{
				// Assign alternate color to this adjacent
				// v of u
				colorArr[v] = 1 - colorArr[u];
				q.push(v);
			}

			// An edge from u to v exists and destination
			// v is colored with same color as u
			else if (graph[u][v] && colorArr[v] == colorArr[u])
				return true;
		}
	}

	// If we reach here, then all adjacent
	// vertices can be colored with alternate
	// color
	return false;
}


ll fw(){
    ll n = V;
    ll d[200][200];
    rep(i,n){
        rep(j,n){
            if(graph[i][j]){
                d[i][j] = 1;
            }else {
                d[i][j] = INF;
            }
        }
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (d[i][k] < INF && d[k][j] < INF)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    ll ans = 0;
    rep(i,n){
        rep(j,n){
            if(d[i][j] != INF && i!=j){
                ans = max (ans, d[i][j]);
            }
        }
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    V = n;
    string s;
    rep(i,n){
        cin>>s;
        rep(j,n){
            if(s[j] == '1'){
                graph[i][j] = true;
            } else {
                graph[i][j] = false;
            }
        }
    }

    if(containsOdd(0)){
        cout<<-1<<endl;
    } else {
        cout<<fw()+1<<endl;;
    }

    timer();
    return 0;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	string s;cin>>s;
	cout<<s.substr(0,3)<<endl;
}

Measured memory_bytes: 3596
N, M = [int(v) for v in input().split()]
stores = [[int(v) for v in input().split()] for _ in range(N)]

stores.sort(key=lambda x: x[0])

nokori = M
res = 0
for s in stores:
    cnt = nokori if nokori - s[1] < 0 else s[1]
    res += cnt * s[0]
    nokori -= cnt
    if nokori <= 0: break
print(res)


Measured memory_bytes: 22756
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    
    string s;
    cin>>s;
    
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 3172
X, K, D = [int(s) for s in input().split()]


if abs(X) >= D * K:
    print((abs(X) - D * K))
else:
    if (K - (abs(X) // D)) % 2 == 0:
        print(abs(X) % D)
    else:
        print(D - (abs(X) % D))


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int h,w;
	vector<int> alp(26,0);

	cin >> h >> w;
	for(int i = 0; i < h; i++){
		string s;
		cin >> s;
		for(auto x: s)
			alp[x-'a']++;
	}
	sort(BE(alp));

	vector<int> hv,wv,res;
	for(int i = 0; i < h/2; i++)
		hv.push_back(2);
	if(h&1)
		hv.push_back(1);

	for(int j = 0; j < w/2; j++)
		wv.push_back(2);
	if(w&1)
		wv.push_back(1);

	for(auto x : hv)
		for(auto y : wv)
			res.push_back(x*y);

	sort(BE(res));
	vector<int> use;
	for(auto x : alp){
		for(int i = 0; i < x/4; i++)
			use.push_back(4);
		if(x%4)
			use.push_back(x%4);
	}
	sort(BE(use));

	bool check = true;
	int index = 0;
	for(auto x : res){
		if(use[index] < x)
			check = false;
		else{
			use[index] -= x;
			if(use[index] == 0)
				index++;
		}
	}

	if(check)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  vector<pair<int,bool>> nums(60000);
  rep(i,60000) nums[i] = make_pair(i,true);
  nums[0].second = nums[1].second = false;
  vector<int> prime;
  for(int i=2;i*i<=60000;i++){
    if(nums[i].second==false)continue;
    for(int j=i+i;j<60000;j+=i){
      nums[j].second = false;
    }
  }
  rep(i,60000){
    if(nums[i].second)prime.pb(i);
  }
  vector<int> okprime;
  for(auto p:prime){
    if(p%5==1 && p<=55555) okprime.pb(p);
  }
  int N;
  cin >> N;
  rep(i,N){
    if(i!=0) cout << " ";
    cout<< okprime[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 768
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    string str;

    while(cin >> n >> str)
    {
		if(n >= str.size()) cout << str << '\n';
		else
		{
			for(ll i = 0; i < n; i++) cout << str[i];
			cout << "..." << '\n';
		}
    }

}




Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define mk make_pair
#define pb push_back

int W, H, N;
pair<int, int> C[100100];
int ma[100100];

signed main()
{
    cin >> W >> H >> N;
    for(int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        C[i] = mk(a, b);
    }
    for(int i = 0; i < N; i++){
        ma[C[i].first] = max(ma[C[i].first], C[i].second);
    }
    for(int i = W - 1; i >= 0; i--){
        ma[i] = max(ma[i], ma[i + 1]);
    }
    int ans = 1000000009;
    for(int i = 0; i < W; i++){
        ans = min(ans, i + ma[i + 1]);
    }
    cout << ans << endl;

    return 0;
}




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

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

using ll = long long;

bool isOk(char c){
 if(c=='A') return true;
 if(c=='C') return true;
 if(c=='G') return true;
 if(c=='T') return true;
 return false;
}

int main() {
	string s;
 cin>>s;
 int n = s.size();
 int maxx = 0;
 int now = 0;
 rep(i,n) {
  if(isOk(s[i])) {
   now++;
  } else {
   if(maxx < now) maxx = now;
   now = 0;
  }
 }
 if(maxx < now) maxx = now;
 cout<<maxx<<endl;
	return 0;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
	int n;
	cin >> n;
	cout << fixed << setprecision(10) << (float)((n + n % 2) / 2) / n;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc159/tasks/abc159_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

bool judge(string s) {
    bool ret = true;
    REP(i, s.length() / 2) {
        if (s[i] != s[s.length() - i - 1]) {
            ret = false;
            break;
        }
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    bool flag = judge(s);
    bool flag1 = judge(s.substr(0, (s.length() - 1) / 2));
    bool flag2 = judge(s.substr((s.length() + 3) / 2 - 1));
    if (flag && flag1 && flag2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int n; cin >> n;
  string s; cin >> s;
  for(int i=0; i<s.size(); i++) {
    char x = 'A' + (s[i]-'A' + n) % 26;
    cout << x;
  }
  cout << endl;

  return 0;
}

// EOF


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[] a = new int[m];
      int[] dp = new int[n+3];
      Set<Integer> set = new HashSet<Integer>();
      for(int i = 0;i < m;i++){
        a[i] = sc.nextInt();
        set.add(a[i]);
      }
      dp[0] = 0;
      if(set.contains(1)){
        dp[1]=0;
      }else dp[1]=1;
      if(set.contains(2)){
      	dp[2]=0;
      }else dp[2] = dp[1]+1;
      for(int i = 3;i <= n;i++){
      	if(set.contains(i)) dp[i]=0;
        else dp[i]=(dp[i-1]+dp[i-2])%1000000007;
      }
      System.out.println(dp[n]);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}

Measured memory_bytes: 63072
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

int array[100];

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    REP(i, n) { scanf("%d", array+i); }
    sort(array, array+n);
    int ans = 0, sum = 0;
    REP(i, n) { sum += array[i]; ans += sum; }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;


//std::vector<std::set<int>> g;
int main(){
    int n;
    std::cin >> n;
    VEC(int,a,n);
    int mi=INF;
    int ans=-INF;
    rep(i,n){
        chmax(ans,a[i]-mi);
        chmin(mi,a[i]);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3688
N,D = map(int,input().split())
X=[]
Y=[]
count = 0
for i in range(N):
    a,b = map(float,input().split())
    X.append(a)
    Y.append(b)
for i in range(N):
    if (X[i]**2+Y[i]**2)**(1/2) <= D:
        count += 1

print(count)


Measured memory_bytes: 24840
#include<iostream>
#include<cstdio>
#include<queue>
#define gc getchar()
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(u) for(int i=hd[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
using namespace std;
typedef long long ll;
const int N=550,M=100100,iNF=1000010000;
const ll INF=1e18;
int n,m,S,T,X,fl,mxf;
int lc[N],rc[N],uc[N],dc[N],hd[N],in[N],vi[N];
ll mxw,ans,di[N];
char o;
queue<int>qu;
struct vec{int x,y;ll w;}p[N];
struct lim{char o;int t,c;}q[N];
struct edge{int n,v,c;ll w;}e[M];
void add_(int u,int v,ll w,int c){e[++fl]=(edge){hd[u],v,c,w};hd[u]=fl;}
void adde(int u,int v,ll w,int c){add_(u,v,w,c);add_(v,u,-w,0);}
bool SPFA(){
	FOR(i,S,T) di[i]=-INF;
	di[T]=0;qu.push(T);
	while(qu.size()){
		int u=qu.front();qu.pop();in[u]=0;
		REP(u)if(e[i^1].c && di[v]<di[u]-e[i].w){
			di[v]=di[u]-e[i].w;
			if(!in[v]) qu.push(v),in[v]=1;
		}
	}
	return di[S]>-INF;
}
int dfs(int u,int E){
	vi[u]=1;
	if(u==T) return E;
	int F=0;
	REP(u)if(c && !vi[v] && di[v]==di[u]-e[i].w){
		int t=dfs(v,min(E,c));
		mxw+=e[i].w*t;
		F+=t;e[i^1].c+=t;
		E-=t;e[i^0].c-=t;
		if(!E) break;
	}return F;
}
void work(int k){
	FOR(i,0,k+1) lc[i]=dc[i]=1,rc[i]=uc[i]=X;
	FOR(i,1,m){
		int t=q[i].t,c=q[i].c;
		if(q[i].o=='R'||q[i].o=='U') c=k-c+1;
		if(q[i].o=='L' && 1<=c && c<=k) lc[c]=max(lc[c],t+1);
		if(q[i].o=='R' && 1<=c && c<=k) rc[c]=min(rc[c],t-1);
		if(q[i].o=='D' && 1<=c && c<=k) dc[c]=max(dc[c],t+1);
		if(q[i].o=='U' && 1<=c && c<=k) uc[c]=min(uc[c],t-1);
	}
	S=1;T=2*(k+X+1);fl=1;
	FOR(i,S,T) hd[i]=0;
	FOR(i,1,k) lc[i]=max(lc[i],lc[i-1]),dc[i]=max(dc[i],dc[i-1]);
	ROF(i,k,1) rc[i]=min(rc[i],rc[i+1]),uc[i]=min(uc[i],uc[i+1]);
	FOR(i,1,k){
		adde(S,i<<1|0,0,1);
		adde(i<<1|1,T,0,1);
		FOR(j,lc[i],rc[i]) adde(i<<1|0,(j+k)<<1|0,0,1);
		FOR(j,dc[i],uc[i]) adde((j+k)<<1|1,i<<1|1,0,1);
	}
	FOR(i,1,n) adde((p[i].x+k)<<1|0,(p[i].y+k)<<1|1,p[i].w,1);
	mxw=mxf=0;
	//FOR(x,S,T){cout<<x<<':';REP(x) cout<<v<<' ';cout<<'\n';}
	while(SPFA()){
		do{
			FOR(i,S,T) vi[i]=0;
			mxf+=dfs(S,iNF);
		}while(vi[T]);
	}
	if(mxf==k) ans=max(ans,mxw);
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d%d%lld",&p[i].x,&p[i].y,&p[i].w);
	FOR(i,1,n) X=max(X,max(p[i].x,p[i].y));
	scanf("%d",&m);
	FOR(i,1,m){
		for(o=gc;o!='L'&&o!='R'&&o!='D'&&o!='U';o=gc);
		q[i].o=o;scanf("%d%d",&q[i].t,&q[i].c),q[i].c++;
	}
	FOR(i,1,n) work(i);
	cout<<ans<<'\n';
}

Measured memory_bytes: 896
N, M, K = map(int, input().split())
ans=0
mod = 10**9+7 #出力の制限
max = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, max + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
for d in range(1,N):
    ans += d*(N-d)*M**2 % mod
for d in range(1,M):
    ans += d*(M-d)*N**2 % mod
ans = ans*cmb(N*M-2, K-2, mod) % mod
print(ans)

Measured memory_bytes: 27168
N = int(input())
a = [int(_) for _ in input().split()]

cnt = 0
cnt2 = 0

for i in range(N):
    if a[i] % 2 == 0 and a[i] % 4 != 0:
        cnt2 += 1
    if a[i] % 4 == 0:
        cnt += 1

t = max(0, N -1- 2* cnt)
if t == 0: print('Yes') 
if t>0:
    if cnt2 >= t+1: print('Yes')
    else:
        print('No')

Measured memory_bytes: 14252
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
using namespace std;

#define EPS 1e-8

typedef double D;
typedef complex<D> P;
typedef const P &rP;
typedef vector<P> vP;

D dot(rP a, rP b){
	return real(a) * real(b) + imag(a) * imag(b);
}

D cross(rP a, rP b){
	return real(a) * imag(b) - imag(a) * real(b);
}

int ccw(rP a, P b, P c){
	b -= a;
	c -= a;
	D cr = cross(b, c);
	if(cr > EPS){ return 1; }
	if(cr < -EPS){ return -1; }
	if(dot(b, c) < -EPS){ return 2; }
	if(norm(b) < norm(c)){ return -2; }
	return 0;
}

P crosspoint(rP pa1, rP pa2, rP pb1, rP pb2){
	D t = cross(pb1 - pa1, pb1 - pb2) / cross(pa2 - pa1, pb1 - pb2);
	return pa1 + t * (pa2 - pa1);
}

void convex_cut(vP &plg, rP a, rP b) {
	vP ret;
	for (int i = 0; i < plg.size(); ++i) {
		rP c = plg[i];
		rP d = plg[(i + 1) % plg.size()];

		if (ccw(a, b, c) != -1){ ret.push_back(c); }
		if (ccw(a, b, c) * ccw(a, b, d) < 0){
			ret.push_back(crosspoint(a, b, c, d));
		}
	}
	plg.swap(ret);
}

int solve(int n){
	vP seg(n + 1);
	D x, y;
	for(int i = 0; i < n; ++i){
		scanf("%lf%lf", &x, &y);
		seg[i] = P(x, y);
	}
	seg[n] = seg[0];

	vP plg(4);
	plg[0] = P(1.1e4, 1.1e4);
	plg[1] = P(1.1e4, -1.1e4);
	plg[2] = -plg[0];
	plg[3] = -plg[1];

	for(int i = 0; i < n; ++i){
		convex_cut(plg, seg[i], seg[i + 1]);
		if(plg.size() < 3){ return 0; }
	}
	return 1;
}

int main(){
	int n;
	while(scanf("%d", &n), n){
		printf("%d\n", solve(n));
	}
}

Measured memory_bytes: 1224
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll N, M;
vector<ll> fromS;
unordered_set<ll> toG;

int main() {
	cin >> N >> M;
	repi(i, 0, M) {
		ll a, b;
		cin >> a >> b;
		if (a == 1) fromS.push_back(b);
		if (b == N) toG.insert(a);
	}
	repi(i, 0, fromS.size()) {
		if (toG.find(fromS[i]) != toG.end()) {
			wrln("POSSIBLE");
			return 0;
		}
	}
	wrln("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 5148
#include<stdio.h>
#define WHITE 1
#define BLACK 0
#define GLAY 3
#define N 102
int g[N][N],d[N],f[N],color[N],k[N];
int time,u,v,n;
 
void DFSVisit(int u){
  int i;
  color[u] = GLAY;
  d[u] = ++time;
  for(i = 0;i < k[u];i++){
    if(color[g[u][i]] ==  WHITE){
      DFSVisit(g[u][i]);
       }
       }
  color[u] = BLACK;
  f[u] = ++time;
}
 
void DFS(){
  int i;
  for(i = 1;i <=n; i++){
    color[i] = WHITE;
  }
    time = 0;
  for(i = 0; i < n;i++){
    if(color[i] == WHITE){
        DFSVisit(i);
    }
  }
  }
 
int main(){
  int i,j,l;
  scanf("%d",&n);
 
  for(i = 0;i < n; i++){
    scanf("%d",&u);
    scanf("%d",&l);
    k[u] = l;
    for(j = 0;j < k[u];j++){
      scanf("%d",&v);
      g[u][j] = v;
    }
  }
 
 
      DFS();
    for(i = 1; i <=n;i++){
      printf("%d %d %d\n", i,d[i],f[i]);
    }
    return 0;
  }

Measured memory_bytes: 636
#include <stdio.h>

int main(void)
{
    int a[3];
    int i, j;
    int tmp;

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

    for(i = 0; i < 2; i++){
        for(j = 0; j < 2; j++){
            if(a[j] > a[j + 1]){
                tmp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = tmp;
            }
        }
    }

    printf("%d %d %d\n", a[0], a[1], a[2]);

    return 0;
}


Measured memory_bytes: 2136
#include<stdio.h>
int main(void) {
        int n, a, b;
        scanf("%d %d %d", &n, &a, &b);

        int res1, res2;
        if(a<=b) res1 = a;
        else res1 = b;

        if(n-a-b>=0) res2 = 0;
        else res2 = a+b-n;
        printf("%d %d", res1, res2);
        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>


using namespace std;

int main(){
    int N,M,Q;
    cin>>N>>M>>Q;
    int p[Q];
    int q[Q];
    int A[N+1][N+1];
    int c[N+1];
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            A[i][j]=0;
        }
    }
    for(int i=1;i<=N;i++)c[i]=0;
    for(int i=0;i<M;i++){
        int l,r;
        cin>>l>>r;
        if(l==r){
            c[l]++;
        }
        A[1][r]++;
        A[l+1][r]--;
        A[r][1]++;
        A[r][l+1]--;
    }
    for(int i=0;i<Q;i++){
        cin>>p[i]>>q[i];
    }

    for(int i=1;i<=N;i++){
        for(int j=2;j<=N;j++){
            A[i][j]+=A[i][j-1];
        }
    }
    for(int i=2;i<=N;i++){
        for(int j=1;j<=N;j++){
            A[i][j]+=A[i-1][j];
        }
    }
    for(int i=1;i<=N;i++){
        A[i][i]-=c[i];
    }
    
    // for(int i=1;i<=N;i++){
    //     for(int j=1;j<=N;j++){
    //         cout<<A[i][j];
    //     }
    //     cout<<endl;
    // }
    
    for(int i=0;i<Q;i++){
        cout<<A[p[i]][q[i]]<<endl;
    }

    return 0;
}


Measured memory_bytes: 2688
a, b, c, x, y = map(int, input().split())

ans = 0
if c < (a + b) / 2:
    if x < y:
        ans += x * 2 * c
        if b < c * 2:
            ans += (y - x) * b
        else:
            ans += (y - x) * c * 2
    else:
        ans += y * 2 * c
        if a < c * 2:
            ans += (x - y) * a
        else:
            ans += (x - y) * c * 2
elif c * 2 < a:
    ans += x * c * 2
    if y > x:
        ans += (y - x) * b
elif c * 2 < b:
    ans += y * c * 2
    if x > y:
        ans += (x - y) * a
else:
    ans += x * a + y * b
print(ans)


Measured memory_bytes: 38384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 2000100;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


int main(void){
  COMinit();
  ll N;
  cin >> N;
  ll ans = 0;
  ll ad = 0;
  for(ll score = 1; score <= N-1; score++){
    ans += score * (fac[score] % MOD * fac[N-1-score] % MOD * comb(score-1, N-1-score) % MOD - ad);
    ans %= MOD;
    ad += fac[score] % MOD * fac[N-1-score] % MOD * comb(score-1, N-1-score) % MOD - ad;
    while(ans < 0) ans += MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 47104
while true
    n = gets.to_i
    break if n == 0
    arr = Array.new(n + 1, 0)
    n.times{
        line = gets.chomp.split.map(&:to_i)
        line << line.inject(:+)
        (n + 1).times{|i|
            print sprintf("%5d", line[i])
            arr[i] += line[i]
        }
        puts
    }
    (n + 1).times{|i| print sprintf("%5d", arr[i])}
    puts
end


Measured memory_bytes: 6884
//
// Created by Alan on 10/6/2017.
//
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t, num;
    string s;
    vector<int> vi;
    cin >> t;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    getline(cin, s);

    stringstream iss(s);

    while ( iss >> num ) {
        vi.push_back(num);
    }
    //for (int j = 0; j < t; j++) {
        //cout << vi[j] << " ";
    //}
    auto it = max_element(begin(vi), end(vi)); // c++11
    auto it2 = min_element(begin(vi), end(vi)); // c++11
    int max = *it;
    int min = *it2;
    //cout << max << endl;
    //cout << min << endl;
    int dis = max - min;
    cout << dis;

    //cout << *std::max_element(begin(vi), end(vi)) << '\n';
    //cout << *std::min_element(begin(vi), end(vi)) << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cmath>

#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;

class node {
public:
	int key;
	node *left, *right, *parent;
	node() :key(0), left(NULL), right(NULL), parent(NULL) {};
	node(int n) :key(n), left(NULL), right(NULL), parent(NULL) {};
};

class tree {
public:
	node *root;
	tree() :root(NULL) {};
	tree(node *n) :root(n) {};
	void insert(int n) {
		node N(n);
		this->insert(N);
	};
	void insert(node n) {
		node *y = NULL;
		node *x = root;
		while (x != NULL) {
			y = x;
			if (n.key<x->key) x = x->left;
			else x = x->right;
		}
		n.parent = y;
		if (y == NULL) root = new node(n);
		else if (n.key < y->key) y->left = new node(n);
		else y->right = new node(n);
	};
	bool find(int n) {
		if (root->key == n) return true;
		if (root->key > n) {
			tree t1(root->left);
			if (t1.root != NULL) return t1.find(n);
			else return false;
		}
		if (root->key < n) {
			tree t1(root->right);
			if (t1.root != NULL) return t1.find(n);
			else return false;
		}
	}
	void Pre() {
		tree t1(root->left), t2(root->right);
		cout << " " << root->key;
		if (t1.root != NULL) t1.Pre();
		if (t2.root != NULL) t2.Pre();
	};
	void Ino() {
		tree t1(root->left), t2(root->right);
		if (t1.root != NULL) t1.Ino();
		cout << " " << root->key;
		if (t2.root != NULL) t2.Ino();
	};
	void Pos() {
		tree t1(root->left), t2(root->right);
		if (t1.root != NULL) t1.Pos();
		if (t2.root != NULL) t2.Pos();
		cout << " " << root->key;
	};
};

int main() {
	int n, nd;
	string str;
	tree T;
	cin >> n;
	REP(i, n) {
		cin >> str;
		if (str == "insert") {
			cin >> nd;
			T.insert(nd);
		}
		else if (str == "find") {
			cin >> nd;
			cout << (T.find(nd) ? "yes" : "no") << endl;
		}
		else {
			T.Ino();cout << endl;
			T.Pre();cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 21792
#!python3

# input
S = input()


def judge(x):
    y = x[::-1]
    if x == y:
        return True
    else:
        return False


def main():
    n = len(S)
    a = S[:(n-1)//2]
    b = S[(n+3)//2 - 1:]

    if judge(S) and judge(a) and judge(b):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define int long long

signed main(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << ((a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) ? "YES" : "NO");

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[51];
long long s[51];
long long fun(int l,long long x)
{
	if(x==0)
		return 0;
	else if(l==0)
		return 1;
	else if(x>=a[l])
		return s[l];
	long long sum=0,t2;
	int t1;
	t1=l;
	t2=x;
	x--;
	sum+=fun(l-1,min(a[l-1],x));
	x-=a[l-1];
	if(x>0)
	{
		x--;
		sum++;
	}
	if(x>0)
		sum+=fun(l-1,min(a[l-1],x));
	//printf("%d %lld %lld\n",t1,t2,sum);
	return sum;
}
int main()
{
	int n,i;
	long long x;
	scanf("%d %lld",&n,&x);
	s[0]=a[0]=1;
	for(i=1;i<=n;i++)
	{
		s[i]=s[i-1]*2+1;
		a[i]=a[i-1]*2+3;
		//printf("%d %lld %lld\n",i,a[i],s[i]);
	}
	printf("%lld",fun(n,x));
	return 0;
}

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


import numpy as np

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

    va = np.array(A)
    vb = np.array(A[1:] + [A[0] + K])

    vv = vb - va

    print(K - max(vv))


if __name__ == '__main__':
    main()

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  string s;
  cin >> n >> s;

  vector<int> b_cnts(n + 1, 0), w_cnts(n + 1, 0);
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '.') {
      w_cnts[i + 1] = w_cnts[i] + 1;
      b_cnts[i + 1] = b_cnts[i];
    } else {
      b_cnts[i + 1] = b_cnts[i] + 1;
      w_cnts[i + 1] = w_cnts[i];
    }
  }

  int ans = s.size();
  for (int i = 0; i < s.size() + 1; ++i) {
    ans = min(ans, b_cnts[i] + (w_cnts.back() - w_cnts[i]));
  }

  cout << ans << '\n';
}

Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

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

	T.pop_back();

	if (S == T) cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 3648
N, T = [int(i) for i in input().split()]
ans = 1500
for i in range(N):
    c1, c2 = [int(j) for j in input().split()]

    if c2 <= T:
        ans = min(c1,ans)

if ans == 1500:
    ans = "TLE"
print(ans)


Measured memory_bytes: 2940
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
typedef long long int LL;
const int inf=1e9+10;
int main()
{
    LL A,B,C,K;
    scanf("%lld%lld%lld%lld",&A,&B,&C,&K);
    if(A>=K)
    {
        printf("%lld\n",K);
        return 0;
    }
    else if(A+B>=K)
    {
        printf("%lld\n",A);
        return 0;
    }
    else if(A+B+C>=K)
    {
        printf("%lld\n",A-K+A+B);
        return 0;
    }
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
  ll n;
  string str;
  vector<ll> count(27);
  ll i;
  for(i = 0; i < 27; i++){
    count[i] = 0;
  }
  cin >> n >> str;
  for(i = 0; i < n; i++){
    count[str[i] - 'a'] += 1;
  }
  
  ll result = 1;
  for(i = 0; i < 27; i++){
    result *= count[i] + 1;
    result = result % (1000000000 + 7);
  }  
  cout << (result - 1) % (1000000000 + 7) << endl;
 
  return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;



signed main(){
	int H, W;
	cin >> H >> W;
	vector<string>s(H);
	cin >> s;
	auto f = [&]() {
		vector<vector<int>>dp(660, vector<int>(660));
		vector<vector<int>>d(660, vector<int>(660));
		int mid = 330;
		REP(i, H) {
			REP(j, W) {
				if(s[i][j] == '#') {
					//dp[i + j][i - j + mid]++;
					d[i + j][i - j + mid]++;
				}
			}
		}
		REP(i, 660) {
			REP(j, 659) {
				dp[i][j + 1] += dp[i][j] + d[i][j];
			}
		}
		int ans = 0;
		int triple = 0;
		REP(i, 660) {
			REP(j, 660) {
				FOR(k, j + 1, 660) {
					if(d[i][j] && d[i][k]) {
						int diff = abs(j - k);
						if(diff % 2) continue;
						//out(i, j, k);
						if(i - diff >= 0) {
							ans += dp[i - diff][k + 1] - dp[i - diff][j];
							triple += d[i - diff][k] + d[i - diff][j];
						}
						if(i + diff < 660) {
							ans += dp[i + diff][k + 1] - dp[i + diff][j];
							triple += d[i + diff][k] + d[i + diff][j];
						}
					}
				}
			}
		}
		return make_pair(ans, triple);
	};

	int ans = 0, triples = 0;
	REP(_, 2) {
		auto[val, triple] = f();
		ans += val;
		triples += triple;
		vector<string>tmp(W);
		REP(j, W) {
			RREP(i, H) tmp[j] += s[i][j];
		}
		swap(H, W);
		s = tmp;
	}
	out(ans - triples / 2);
}

Measured memory_bytes: 10400
from bisect import*
from itertools import*
n,*L=map(int,open(0).read().split())
L.sort()
ans=0
for x,y in combinations(L,2):
	low=abs(x-y)
	high=x+y
	ans+=bisect_left(L,high)-bisect(L,low)
	if low<x<high:
		ans-=1
	if low<y<high:
		ans-=1
print(ans//3)

Measured memory_bytes: 48988
#include<bits/stdc++.h>
#include <string> 
using namespace std;
#include <string> 
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);
typedef long long ll;
#define MAX 1000000000
const int maxn=1000010;
string ma="";

int LCS(string s,string t,int i,int j)
{
    if(i==0||j==0){
        return 0;
    }
    if(s[i-1]==t[j-1]){
        return LCS(s,t,i-1,j-1)+1;
    }
    return max(LCS(s,t,i-1,j),LCS(s,t,i,j-1));
}

int main()
{
	fast;
    int i,j;
	string s,t;
    getline(cin,s);
    getline(cin,t);
    int x=s.length();
    int y=t.length();
    string str="";
    int dp[x+1][y+1];
    for(i=0;i<=x;i++)
    {
        for(j=0;j<=y;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    i=x;
    j=y;
    while(dp[i][j]!=0){
           if(s[i-1]==t[j-1]){
                str.push_back(s[i-1]);
                i=i-1;
                j=j-1;}
            else if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    reverse(str.begin(),str.end());
    cout<<str<<endl;
	return 0;
}


Measured memory_bytes: 35456
#include<stdio.h>

int main(){
long long k,a,b,sum=0;
scanf("%lld%lld%lld",&k,&a,&b);
if(k<=a){
printf("%lld",k+1);return 0;}
if(a+2<b){
sum=((k-a+1)/2)*b+(k-a+1)%2-a*((k-a-1)/2);
}
else sum=k+1;
printf("%lld",sum);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int p;
		cin>>p;
		if(p%2==0)
		{
			if(p%3&&p%5)
			{
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
	return 0;
}

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

int h, w;
string s[15];
int pos[15];
int rpos[15];
int cnt;

bool matching(int i, int j) {
  for (int hi = 0; hi < h; hi++) {
    if (s[rpos[hi]][i] != s[rpos[h - 1 - hi]][j]) {
      return false;
    }
  }
  return true;
}

bool check() {
  vector<bool> matched(12, false);
  bool single = w % 2 == 1 ? false : true;
  for (int wi = 0; wi < w; wi++) {
    if (matched[wi]) continue;
    bool m = false;
    for (int wj = wi + 1; wj < w; wj++) {
      if (matching(wi, wj)) {
        m = true;
        matched[wj] = true;
        break;
      }
    }
    if (!m) {
      if (single) return false;
      for (int hi = 0; hi < h / 2; hi++) {
        if (s[rpos[hi]][wi] != s[rpos[h - 1 - hi]][wi]) return false;
      }
      single = true;
    }
  }
  return true;
}

bool traverse(int x) {
  if (x * 2 == h) {
    return check();
  }
  for (int hi = 0; hi < h; hi++) {
    if (pos[hi] == -1) {
      pos[hi] = x;
      rpos[x] = hi;
      if (x * 2 + 1 == h) {
        bool result = check();
        pos[hi] = -1;
        return result;
      } else {
        for (int hj = hi + 1; hj < h; hj++) {
          if (pos[hj] == -1) {
            pos[hj] = h - 1 - x;
            rpos[h - 1 - x] = hj;
            bool result = traverse(x + 1);
            pos[hj] = -1;
            if (result) {
              pos[hi] = -1;
              return true;
            }
          }
        }
        pos[hi] = -1;
        return false;
      }
    }
  }
}

int main() {
  cin >> h >> w;
  for (int hi = 0; hi < h; hi++) {
    cin >> s[hi];
  }
  memset(pos, -1, sizeof(pos));
  bool answer = traverse(0);
  if (h % 2 == 1) {
    for (int hi = 0; hi < h - 1; hi++) {
      swap(s[hi], s[h - 1]);
      answer |= traverse(0);
      if (answer) break;
    }
  }
  cout << (answer ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 100000+10;
const LL mod = 1000000007;
struct Node {
    int l,r;
    bool operator < (const Node &a)const {
        return (r-l+1)<(a.r-a.l+1);
    }
}s[maxn+(maxn<<1)];
vector<int>g[maxn];
int c[maxn];
int n,m;
void add(int l,int r) {

    while(l<=m) {
        ++c[l];
        l+=l&(-l);
    }
    while(r<=m) {
        --c[r];
        r+=r&(-r);
    }
    return ;
}
int query(int i) {

    int res=0;
    while(i) {
        res+=c[i];
        i-=i&(-i);
    }
    return res;
}
int main() {

    M(c,0);
    scanf("%d%d",&n,&m);
    for (int i=0;i<=m;++i) {
        g[i].clear();
    }
    for (int i=1;i<=n;++i) {
        scanf("%d%d",&s[i].l,&s[i].r);
        int len=s[i].r-s[i].l+1;
        g[len].pb(i);
    }
    for(int i=1;i<=m;++i) {
        int ans=0;
        for (int j=0;j<g[i-1].size();++j) {
            int &pos=g[i-1][j];
            add(s[pos].l,s[pos].r+1);
        }
        for (int j=i;j<=m;j+=i) {
            ans+=query(j);
        }
        n-=g[i-1].size();
        printf("%d\n",ans+n);
    }
    return 0;
}

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

int main() {
  vector<int> dishes(5);

  for (int i = 0; i < 5; i++) {
    cin >> dishes.at(i);
  }
  
  int index = 0;
  int amari = dishes.at(0) % 10;
  for (int i = 1; i < 5; i++) {
    if ((dishes.at(i) % 10) == 0) continue;
    if ((dishes.at(i) % 10) < amari) {
      index = i;
      amari = dishes.at(i) % 10;
    }
  }

  int time = 0;
  for (int i = 0; i < 5; i++) {
    if (i == index) time += dishes.at(i);
    else if ((dishes.at(i) % 10) == 0) {
      time += dishes.at(i);
    } else {
      time += ((dishes.at(i) / 10) + 1) * 10;
    }
  }

  cout << time << endl;
}
/*
29
20
7
35
120
 */


Measured memory_bytes: 256
# C - いっしょ / Be Together

# 平均値は平方誤差を最小化する

N = int(input())
a = list(map(int, input().split()))

ans = float("inf")
for x in [sum(a)//N, -(-sum(a)//N)]:
    tmp = 0
    for idx in range(N):
        tmp += (a[idx]-x)**2
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  string key = "keyence";
  if (s.substr(0, key.size()) == key || s.substr(s.size() - key.size(), key.size()) == key)
  {
    cout << "YES" << endl;
    return 0;
  }
  int j = 0;
  for (int i = 0; i < s.size() && (s[i] == key[j] && j < 7); ++i)
  {
    j++;
  }

  if (s.substr(s.size() - key.size() + j, key.size() - j) == key.substr(j, key.size() - j))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

ll N;
vector<ll> divisor(ll n) {
	vector<ll> res;
	for(ll i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

ll check(ll n) {
	ll res = 0;
	while(n > 0) {
		res++;
		n /= 10;
	}
	return res;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;

	vector<ll> yakusuu = divisor(N);
	ll min_v = 1e18;
	rep(i, 0, yakusuu.size()) {
		ll A = yakusuu[i];
		ll B = N / A;
		ll digit_A = check(A);
		ll digit_B = check(B);
		min_v = min(min_v, max(digit_A, digit_B));
	}
	cout << min_v << endl;

}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K,C;
string S;

int A[202020];
vector<int> L,R;



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>C>>S;
	C++;
	L.push_back(-1<<20);
	FOR(i,N) if(S[i]=='o') {
		if(L.back()+C<=i) L.push_back(i);
	}
	R.push_back(-1<<20);
	for(i=N-1;i>=0;i--) if(S[i]=='o') {
		if(i+C<=-R.back()) R.push_back(-i);
	}
	FORR(r,R) r=-r;
	reverse(ALL(R));
	
	
	FOR(i,N) if(S[i]=='o') {
		x=lower_bound(ALL(L),i)-L.begin()-1;
		y=L[x];
		j=lower_bound(ALL(R),max(y+C,i+1))-R.begin();
		j=R.size()-1-j;
		if(x+j<K) cout<<i+1<<endl;
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3468
import numpy as np
from sys import stdin


def main():
    h = next_int()
    w = next_int()

    c = np.array([input() for _ in range(h)])

    for i in range(h):
        for j in range(2):
            print(c[i])


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 21020
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  int64_t answer = A[0] / 2;
  A[0] %= 2;
  for(int i = 1; i < N; ++i) {
    if(A[i-1] == 1 && 0 < A[i]) {
      ++answer;
      --A[i];
    }
    answer += int64_t(A[i] / 2);
    A[i] %= 2;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a=0,b=0,c=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(A%4==0)
      a++;
    else if(A%2==0)
      b++;
    else
      c++;
  }
  if(c<=a)
    cout<<"Yes"<<endl;
  else if(c==a+1 && b==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

const int mn=1e5+8;
vector<pii > p;
multiset<int> s;

int main()
{
	int n,a;
	long long ans=0;
	scanf("%d",&n);
	s.insert(n+1);s.insert(n+1);
	s.insert(0),s.insert(0);
	for(int i=1;i<=n;++i) {scanf("%d",&a);p.push_back(make_pair(a,i));}
	sort(p.begin(),p.end());
	reverse(p.begin(),p.end());
	for(int i=1;i<=n;++i) {
		pii now=p[i-1];
		int id=now.second,val=now.first;
		if(i>1) {
			int prepre=*----s.lower_bound(id);
			int pre=*--s.lower_bound(id);
			int nxt=*s.lower_bound(id);
			int nxtnxt=*++s.lower_bound(id);
			ans+=1ll*val*(1ll*(id-pre)*(nxtnxt-nxt)+1ll*(nxt-id)*(pre-prepre));
		}
		s.insert(id);
	}
	cout<<ans;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int N;
  cin >> N;
  double ans;
  if (N % 2 == 0)
    ans = (N / 2.0) / N;
  else
    ans = (N / 2.0 + 0.5) / N;
  cout << ans << endl;
}


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

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<long> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    long cnt = 0;

    for (int i = 0; i < n; i++) {
        long a_ok = -1;
        long ng = n;
        while (abs(a_ok - ng) > 1) {
            long mid = (a_ok + ng) / 2;
            if (a[mid] < b[i]) {
                a_ok = mid;
            } else {
                ng = mid;
            }
        }
        a_ok++;

        long c_ok = -1;
        ng = n;
        while (abs(c_ok - ng) > 1) {
            long mid = (c_ok + ng) / 2;
            if (c[mid] <= b[i]) {
                c_ok = mid;
            } else {
                ng = mid;
            }
        }
        c_ok = n - c_ok - 1;

        cnt += a_ok * c_ok;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 2560