akhauriyash/Code-Regression huggingface dataset:
import sys

def f(fl, i, j):
    return sum(1 for v in fl if v[0] == i and v[1] == j)


def first_last(N):
    for n in range(1, N + 1):
        last = n % 10

        while n >= 10:
            n, _ = divmod(n, 10)
        first = n
        yield first, last


def resolve(in_):
    N = int(next(in_).strip())
    fl = tuple(first_last(N))
    
    ans = sum(f(fl, i, j) * f(fl, j, i) for i in range(10) for j in range(10))
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23284
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

main()
{
	IOS
	
	int a, b;
	cin >> a >> b;
	
	cout << max(a + b, max(a - b, a * b));
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}



int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  ll x,k,d;
  cin >> x >> k>> d;
  ll t = abs(x)/d;
  if(t >= k){
	  cout << abs(x)-(k*d) << endl;
  }else{
	  ll r = abs(x)%d;
	  if((k-t)%2 == 0){
		  cout << r << endl;
	  }else{
		  cout << d-r <<endl;
	  }
  }
  return 0;
}


Measured memory_bytes: 3628
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
res = b[a[0]-1]
for i in range(1,n):
  res+=b[a[i]-1]
  if a[i]-a[i-1]==1:
    res+=c[a[i-1]-1]
print(res)

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,test=0,qcnt=0;
int cnt[70];
char ch[70],tans[70];

vector<int> getv(vector<int> v,int pl,int c){
	vector<int> ret(0);
	for(int i=0;i<pl;i++) ret.pb(v[i]);
	ret.pb(c);
	for(int i=pl;i<v.size();i++) ret.pb(v[i]);
	return ret;
}

int ask(vector<int> q){
	printf("? ");
	for(int i=0;i<q.size();i++) printf("%c",ch[q[i]]);
	printf("\n");
	fflush(stdout);
	if(test){
		int l=strlen(tans+1),ret=n;
		if(q.size()==128){
			for(int i=1;i<=l;i++) if(ch[q[i-1]]==tans[i]) ret--;
			cout<<ret<<endl;
			qcnt++;
			return ret;
		}
		else{
			int now=0;
			for(int i=1;i<=l;i++){
				if(now<q.size()&&tans[i]==ch[q[now]]) now++;
			}
			qcnt++;
			cout<<n-now<<endl;
			return n-now;
		}
	}
	return readint();
}

vector<int> solve(int l,int r){
	if(l==r){
		vector<int> ret(0);
		for(int i=1;i<=cnt[l];i++) ret.pb(l);
		return ret;
	}
	int mid=(l+r)/2;
	vector<int> ls=solve(l,mid),rs=solve(mid+1,r);
//	cout<<"merge "<<l<<' '<<mid<<' '<<mid+1<<' '<<r<<endl;
	if(!ls.size()) return rs;
	if(!rs.size()) return ls;
	int now=0,all=ls.size(),pl=0;
	vector<int> nw;
	while(now<rs.size()&&n-ask(nw=getv(ls,pl,rs[now]))==all+1) ls=nw,all++,now++,pl++;
	for(int i=0;i<ls.size()-1;i++){
		pl++;
		while(now<rs.size()&&n-ask(nw=getv(ls,pl,rs[now]))==all+1) ls=nw,all++,now++,pl++;
	}
	while(now<rs.size()) ls.pb(rs[now]),now++;
	return ls;
}

int main(){
	if(test) scanf("%s",tans+1);
	for(int i=0;i<26;i++) ch[i]='a'+i;
	for(int i=26;i<52;i++) ch[i]='A'+i-26;
	for(int i=52;i<62;i++) ch[i]='0'+i-52;
	n=128;
	for(int i=0;i<62;i++) cnt[i]=128-ask(vector<int>(128,i));
	n=0;
	for(int i=0;i<62;i++) n+=cnt[i];
	vector<int> ans=solve(0,62);
	printf("! ");
	for(int i=1;i<=n;i++) printf("%c",ch[ans[i-1]]);
	printf("\n");
	if(test) cout<<"qcnt "<<qcnt<<endl;
	return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>

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

using namespace std;

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

	while (1)
	{
		int n = 0, r = 0; cin >> n >> r;
		if (n == 0 && r == 0) { return 0; }
		int p = 0, c = 0;
		vector<int> bef(n + 5);
		vector<int> aft(n + 5);
		rep(i, n) 
		{
			bef[i] = n - i;
			aft[i] = n - i;
		}
		rep(i, r)
		{
			cin >> p >> c;
			rep(j, p - 1){	aft[c + j] = bef[j];	}
			rep(j, c)	{	aft[j] = bef[p - 1 + j];	}
			bef = aft;
		}
		printf("%d\n", bef[0]);
	}
	return 0;
}

Measured memory_bytes: 1216
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};



int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    vector<lint> t(5);
    cin >> n >> t[0] >> t[1] >> t[2] >> t[3] >> t[4];
    lint ans = 0;
    lint min_str = 0;
    lint min_value = LINF;
    for (lint i=0; i<5; ++i){
        if(min_value > t[i]){
            min_value = t[i];
            min_str = i;
        }
    }
    // debugpair(min_str, min_value);
    if(n % min_value == 0){
        ans = n / min_value + 4;
    }
    else {
        ans = n / min_value + 5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// by The_One_Solver
#include<bits/stdc++.h>
using namespace std;
long long int n,v,k,c,a,b;
map<long long ,long long >mp;
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        mp[a]+=b;
    }
    for(int i=0;i<100001;i++)
    {
        k=k-mp[i];
        if(k<=0){cout<<i;break;}
    }


    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
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<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

ll dp[MAX+104];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);


    ll n,k;
    cin>>n>>k;
    rep(i,n)dp[i]=INF;
    Vec h(n);
    cin>>h;
    dp[0]=0;
    rep(i,n){
        REP(j,1,k+1){
            chmin(dp[i+j],abs(h[i+j]-h[i])+dp[i]);
        }
    }
    ll ans = dp[n-1];
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;

    vector<int> P(M);
    vector<int> Y(M);
    for (int i = 0; i < M; i++) {
        cin >> P[i] >> Y[i];
    }
    vector<pair<int, int>> PY(M);
    for (int i = 0; i < M; i++) {
        PY[i].first = P[i];
        PY[i].second = Y[i];
    }

    sort(PY.begin(), PY.end());
    vector<pair<int, int>> num(1);
    for (int i = 0; i < M; i++) {
        if (PY[i].first != num[num.size() - 1].first) {
            num.push_back(make_pair(PY[i].first, 1));
        }
        else {
            num[num.size() - 1].second++;
        }
    }

    map<int, int> mp;
    int res = 1;
    mp[PY[0].second] = 1;
    for (int i = 1; i < M; i++) {
        if (PY[i].first == PY[i - 1].first) {
            res++;
        }
        else {
            res = 1;
        }
        mp[PY[i].second] = res;
    }
  
    for (int i = 0; i < M; i++) {
        string A = to_string(P[i]);
        cout << string(6 - A.size(), '0') << A;
        string B = to_string(mp[Y[i]]);
        cout << string(6 - B.size(), '0') << B << endl;
    }
}

Measured memory_bytes: 8564
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
//using mint = modint1000000007;
//using mint = modint998244353;
//const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int n,m;
int main(){
    cin>>n>>m;
    dsu d(n);
    rep(i,m){
      int a,b;
      cin>>a>>b;
      --a;--b;
      d.merge(a,b);
    }
    int ans=d.groups().size()-1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9032
#include<iostream>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	
	char s[55][55];
	char t[55][55];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> s[i][j];
		}
	}

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			cin >> t[i][j];
		}
	}
	
	for (int a = 0; a < n - m + 1; a++) {
		for (int b = 0; b < n - m + 1; b++) {
			bool flag = true;
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					if (s[i + a][j + b] != t[i][j]) {
						flag = false;
						
					}
					
				}
			}	
			if (flag) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int N; //頂点の数
vector<vector<int>> G; //グラフ
vector<int> h; //入次数
vector<int> l_depth; //最大経路長
vector<int> ans; //トポロジカルソート結果を格納

void topoBFS(){   
  queue<int> unchecked;
  for(int i=0; i<N; i++){
    if(h[i]==0){
      unchecked.push(i); //入次数が0の頂点をキューに入れる
      l_depth[i] = 0; //そのような頂点は深さが0
    }
  }
  while(!unchecked.empty()){
    int current = unchecked.front();
    unchecked.pop();
    ans.push_back(current); //キューから取り出したらすぐソート後のリストに加える

    for(int next: G[current]){ //「行ける」頂点について
      h[next]--; //入次数を減らす
      l_depth[next] = max(l_depth[next], l_depth[current]+1); //最長経路
      if(h[next]==0){ //入次数0になったらキューに追加
        unchecked.push(next);
      }
    }
  }
}

int main(){
  int n;
  cin>>n;
  vector<vector<int>> IDs(n, vector<int>(n, -1));
  N = n*(n-1)/2;
  G.resize(N);
  h.resize(N, 0);
  l_depth.resize(N, -1);
  
  int id = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      IDs[i][j] = id;
      IDs[j][i] = id;
      id++;
    }
  }

  int t, bufid, vsid;
  for(int i=0; i<n; i++){
    bufid = -1;
    for(int j=0; j<n-1; j++){
      cin>>t;t--;
      vsid = IDs[i][t];

      if(bufid != -1){
        G[bufid].push_back(vsid);
        h[vsid]++;
      }

      bufid = vsid;
    }
  }

  topoBFS();

  bool isDAG = ans.size()==N;
  if(isDAG){
    int l_max = *max_element(l_depth.begin(), l_depth.end());
    cout<<l_max+1<<endl;
  }else{
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 37624
#include<bits/stdc++.h>
using namespace std;
int A[10001];
int main(){
    int H,n;
	int temp;
	cin>>H>>n;
	for(int i=0;i<n;++i){
		cin>>temp;
		if(H>0){
			H-=temp;
			A[temp]++;
		}
	}
	if(H<=0)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    K = int(input())

    ans = []
    A = [[] for j in range(10)]
    for i in range(1, 10):
        A[0].append(i)

    for i in range(1, 10):
        for x in A[i - 1]:
            y = x % 10
            if y == 0:
                A[i].append(x * 10)
                A[i].append(x * 10 + 1)
            elif y == 9:
                A[i].append(x * 10 + 9)
                A[i].append(x * 10 + 8)
            else:
                A[i].append(x * 10 + y - 1)
                A[i].append(x * 10 + y)
                A[i].append(x * 10 + y + 1)

    ans = []
    for a in A:
        for b in a:
            ans.append(b)
    ans.sort()

    print(ans[K - 1])


if __name__ == '__main__':
    main()


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

int main(int argc, char const *argv[]) {
    vector<int> vc;
    while(true){
        int n;cin>>n;
        if(n==0)break;
        int max,min;
        int sum=0;
        for(int i=0;i<n;i++){
            int score;cin >> score;
            if(i==0){
                min = score;
                max = score;
            }
            if(max < score)max = score;
            if(min > score)min = score;
            sum+=score;
        }
        sum -= max;
        sum -= min;
        int avg = sum/(n-2);
        cout << avg << endl;
    }
    return 0;
}



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

int main(){
int p,q,r;
int min=0;
cin >>p >>q >>r;
if(p+q>=p+r)min=p+r;
  else min=p+q;
if(min>=q+r)min=q+r;

cout <<min <<endl;
    return 0;
}

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

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

    ll N ;
    vector<ll> A,B,C ;
    cin >> N;
    rep(i,N){
        ll inp;
        cin >> inp;
        A.pb(inp);
    }

    sort(all(A));

    ll l = 0, r = A.size()-1;
    while(l<r){
        B.pb(A[l]);
        B.pb(A[r]);
        C.pb(A[r]);
        C.pb(A[l]);
        l ++;
        r --;
        if(l==r){
            B.pb(A[l]);
            C.pb(A[l]);
            break;
        }
    }

    B.pb(B[0]);
    C.pb(C[0]);



    ll ansB = 0;
    ll minB = 1000000001;
    ll ansC = 0;
    ll minC = 1000000001;

    rep(i,N+1){
        if(i == 0) continue;
        ansB += abs(B[i]- B[i-1]);
        ansC += abs(C[i]- C[i-1]);

        minB = min(minB, abs(B[i]- B[i-1]));
        minC = min(minC, abs(C[i]- C[i-1]));
    }

    cout << max(ansB - minB, ansC - minC) << endl;

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


Measured memory_bytes: 3444
#include <stdio.h>
#include <stdlib.h>

int min(int a,int b){
	return a < b ? a : b;
}

int main(){
	int n,i,j,m,t,cup,ans;
	int *p,*a,*c,*tray;

	while(1){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0){
			break;
		}

		p = (int *)malloc(sizeof(int)*n);
		a = (int *)malloc(sizeof(int)*n);
		c = (int *)malloc(sizeof(int)*n);
		tray = (int *)malloc(sizeof(int)*n);

		for(i = 0;i < 3;i++){
			scanf("%d",&t);
			for(j = 0;j < t;j++){
				scanf("%d",&cup);
				tray[cup-1] = i;
			}
		}

		p[n-1] = 2;
		a[n-1] = tray[n-1];
		c[n-1] = 2-tray[n-1];

		for(i = n-2;i >= 0;i--){
			p[i] = 3*p[i+1]+2;
			switch(tray[i]){
			case 0:
				a[i] = a[i+1];
				c[i] = 2*p[i+1]+c[i+1]+2;
				break;
			case 1:
				a[i] = p[i+1]+c[i+1]+1;
				c[i] = p[i+1]+a[i+1]+1;
				break;
			case 2:
				a[i] = 2*p[i+1]+a[i+1]+2;
				c[i] = c[i+1];
				break;
			}
		}
		ans = min(a[0],c[0]);
		printf("%d\n",ans < m ? ans : -1);
	}

	return 0;
}

Measured memory_bytes: 596
n = int(input())
sss = [input() for _ in range(n)]
cnt_AC=0
cnt_WA=0
cnt_TLE=0
cnt_RE=0

for i in sss:
    if i == "AC":
        cnt_AC +=1
    if i == "WA":
        cnt_WA +=1
    if i == "TLE":
        cnt_TLE +=1
    if i == "RE":
        cnt_RE +=1

print("AC x", cnt_AC)
print("WA x", cnt_WA)
print("TLE x", cnt_TLE)
print("RE x", cnt_RE)

Measured memory_bytes: 16216
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s;
  cin>>s;
  ll N = s.size();
  ll p = 0;
  ll t = 0;
  ll ans = 0;
  ll a[N+1];
  for(int i = 0;i<N+1;i++){
    a[i] = -1;
  }
  
  for(ll i = 0;i<N-1;i++){
    if(s.at(i) == '>' && s.at(i+1) == '<'){
      a[i+1] = 0;
    }
  }
  
  if(s.at(N-1) == '>'){
    a[N] = 0;
    ll ppp = 1;
    a[N-1] = ppp;
    for(ll i = N-2;i>=0;i--){
      if(s.at(i) == '>'){
        ppp++;
        a[i] = ppp;
      }
      else{
        break;
      }
    }
  }
  if(s.at(0) == '<'){
    a[0] = 0;
    ll ppp = 1;
    a[1] = max(ppp,a[1]);
    for(ll i = 1;i<N;i++){
      if(s.at(i) == '<'){
        ppp++;
        a[i+1] = max(a[i+1],ppp);
      }
      else{
        break;
      }
    }
  }
  

  for(ll i = 1;i<N;i++){
    if(a[i] == 0){
      ll kkk = 1;
      for(ll k = i-1;k>=0;k--){
        if(s.at(k) == '>'){
          if(a[k] == -1){
            a[k] = kkk;
          }
          else{
            a[k] = max(a[k],kkk);
          }
          kkk++;
        }
        else{
          break;
        }
      }
      ll qqq = 1;
      for(ll k = i;k<N;k++){
        if(s.at(k) == '<'){
          if(a[k+1] == -1){
            a[k+1] = qqq;
          }
          else{
            a[k+1] = max(a[k+1],qqq);
          }
          qqq++;
        }
        else{
          break;
        }
      }
    }
  }
  for(ll i = 0;i<N+1;i++){
    ans += a[i];
  }

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

Measured memory_bytes: 4740
import java.util.*;
public class Main {
    static long lcm(long a, long b){
        return (a*b)/gcd(a,b);
    }
    static long gcd(long a, long b){
        if(a<b){
            long t = a;
            a =b;
            b=t;
        }
        if(b==0) return a;
        return gcd(b,a%b);
    }
    public static void main(String args[]) {
        
        
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long arr[] = new long[n];
        long ans =0;
        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
            ans+=arr[i]-1;
        }
        System.out.println(ans);
        
        /*
        Scanner sc= new Scanner(System.in);
        
        int n =sc.nextInt();
        long arr[] = new long[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
        }
        long ans = arr[0];
        for(int i=1;i<n;i++){
            ans = lcm(ans, arr[i]);
        }
        long temp = 0;
        for(int i=0;i<n;i++){
            temp+=(ans-1)%arr[i];
        }
        System.out.println(temp);*/
    }
}


Measured memory_bytes: 25580
#include<bits/stdc++.h>
using namespace std;
long long solve(){
  	int n;
	cin>>n;
  	long long A[n][n];
	long long dp[(1<<n)];
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>A[i][j];
	dp[0]=0;
	for(int i=1;i<1<<n;i++){
		dp[i]=0;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				for(int k=j+1;k<n;k++){
					if(i&(1<<k)) dp[i]+=A[j][k];
				}
			}
		}
	}
	for(int mask=1;mask<1<<n;mask++){
		for(int ss=mask;ss>0;ss=(ss-1)&mask){
			dp[mask]=max(dp[mask],dp[ss]+dp[mask^ss]);
		}
	}
	return dp[(1<<n)-1];
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<solve()<<"\n";
}

Measured memory_bytes: 4144
import math
n,a,b = map(int,input().split())
kyori = []
telepo = math.ceil(b / a)
counter = 0
ans = 0
x = list(map(int,input().split()))
for i in range(1,n):
    tmp = x[i] - x[i-1]
    if tmp >= telepo:
        counter +=1
    else:
        kyori.append(tmp)
for i in kyori:
    ans +=a*i
ans = ans + counter * b
print(ans)

Measured memory_bytes: 15020
n, m  = [int(i) for i in input().split()]
ab = []
b = []
for i in range(m):
    ab.append([int(i) for i in input().split()])

ab.sort()
op_sum = 1
left = ab[0][0]
right = ab[0][1]

for a, b in ab:
    if right <= a:
        op_sum += 1
        left = a
        right = b
    else:
        left = a
        right = min(right, b)

print(op_sum)

Measured memory_bytes: 21652
//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn main() {
    let mut scan = Scan::new();

    let L = scan.word::<usize>();
    let R = scan.word::<usize>();
    let d = scan.word::<usize>();

    let count = (R / d) - ((L - 1) / d);
    println!("{}", count);
}


Measured memory_bytes: 2168
#include <iostream>

using namespace std;

int main(void){
  int H, W;
  cin >> H >> W;
  
  int i, j;
  char a[H][W];
  for(i=0; i<H; i++)
    for(j=0; j<W; j++)
      cin >> a[i][j];

  //行方向に.(白文字)を見て，全てが.であれば，空白に置き換える
  for(i=0; i<H; i++){
    for(j=0; j<W; j++)
      if(a[i][j] == '#')
	break;
    if(j >= W)
      for(j=0; j<W; j++)
	a[i][j] = ' ';
  }

  //列方向に.(白文字)を見て，全てが.であれば，空白に置き換える
  for(i=0; i<W; i++){
    for(j=0; j<H; j++)
      if(a[j][i] == '#')
	break;
    if(j >= H){
      for(j=0; j<H; j++)
        a[j][i] = ' ';
    }
  }
  

  int count = 0;
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      if(a[i][j] != ' '){
	cout << a[i][j];
	count ++;
      }
    }
      if(count != 0)
	cout << endl;
    count = 0;
  }
      
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    int sum = 0;
    for(int i=1;i<N-1;i++){
        if((vec.at(i-1)<vec.at(i))&&(vec.at(i)<vec.at(i+1))){
            sum++;
        }
        else if((vec.at(i-1)>vec.at(i))&&(vec.at(i)>vec.at(i+1))){
            sum++;
        }
    }
    cout << sum << endl;
}

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	double a, b, h, m; cin >> a >> b >> h >> m;
	double hdo = pi*m/30, mdo = pi*(h+m/60)/6;
	double ans = sqrt(a*a + b*b - 2*a*b*cos(hdo-mdo));
	cout << fixed << setprecision(12) <<  ans << endl;
} 

Measured memory_bytes: 4228
<?php

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d %d %d", $n, $x, $t);

$cycle = intdiv($n, $x);
if ($n % $x != 0) $cycle++;
echo $cycle * $t, PHP_EOL;


Measured memory_bytes: 16100
#include <bits/stdc++.h>
#define sqr3(x) ((x) * (x) * (x))
using namespace std;

typedef long long LL;

LL n, k, ans;

int main() {
	scanf("%lld%lld", &n, &k);
	LL p = n / k;
	if (k & 1) ans = sqr3(p);
	else {
		ans = sqr3(p);;
		p += n % k >= k >> 1 ? 1 : 0;
		ans += sqr3(p);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0)return a;

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

int main() {
	char c[5][5];
	rep(i, 3)rep(j, 3) cin >> c[i][j];

	string ccc;
	rep(i, 3) ccc += c[i][i];
	cout << ccc << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
void solve()
{
	ll a,b;
	cin>>a>>b;
	cout<<(a*b)/__gcd(a,b);
}   
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int n,a;
vector<int> x;
int dp[2505][55][55];

int rec(int sum, int k, int m) {
    assert(k <= m);
    if (sum < 0) return 0;
    int &res = dp[sum][k][m];
    if (res >= 0) return res;
    if (k == 0) res = (sum == 0);
    else {
        res = rec(sum-x[m-1],k-1,m-1);
        if (k <= m-1) res += rec(sum,k,m-1);
    }
    return res;
}


int32_t main() {
    cin >> n >> a;
    x.resize(n); cin >> x;
    int sum = 0;
    
    memset(dp, -1, sizeof(dp));
    rep1 (k,n) sum += rec(a*k,k,n);
    cout << sum << endl;
}


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

int main(void){

  char s[11];
  int a = 0;
  scanf("%d", &a);
  scanf("%s", s);

	if(a>=3200) printf("%s", s);
  	else  printf("red");

  //printf("%d", count);

  return 0;
}

  


    
  
  

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        if(A[i]%2==0){
            if(A[i]%3==0||A[i]%5==0){
                continue;
            }
            else{
                cout<<"DENIED";
                return 0;
            }
        }
    }
    cout<<"APPROVED";
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int,input().split()))
V = sum(A)
# print("V:",V)
c = 0
for a in A:
    # print("a:",a)
    if 4*M*a >= V:
        c += 1
# print("c=",c)
if c >= M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    public void solve(Stdin stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int a1 = stdin.nextInt();
        int a2 = stdin.nextInt();
        int a3 = stdin.nextInt();
        if (a1 + a2 + a3 <= 21) {
            stdout.println("win");
        } else {
            stdout.println("bust");
        }
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        Stdin stdin = new Stdin();
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }

    public static class Stdin {
        private Deque<String> queue;
        private BufferedReader stdin;
        private Pattern delimiter;

        public Stdin() {
            queue = new ArrayDeque<>();
            stdin = new BufferedReader(new InputStreamReader(System.in));
            delimiter = Pattern.compile(" ");
        }

        public String next() throws IOException {
            if (queue.isEmpty()) {
                delimiter.splitAsStream(stdin.readLine()).forEach(queue::addLast);
            }
            return queue.removeFirst();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 26580
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

const int dx[] = { -1, 0, 0, 1 }, dy[] = { 0, -1, 1, 0 };
//[const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }

int w, h;
vector<vi> p, len, fld;
typedef tuple<vector<vi>, int, int> Data;
map<Data, int> mp;

bool check(int x,int y,int l)
{
	REP(i, l)REP(j, l)
	{
		int tx = x + i, ty = y + j;
		if (!valid(tx, ty, h, w)) return false;
		if (!p[tx][ty]) return false;
	}
	return true;
}

int dfs(int x, int y)
{
	Data tmp = make_tuple(fld, x, y);
	if (mp.count(tmp)) return mp[tmp];
	//if (mp.count(fld)) return mp[fld];
	int res = INF;
	if (y == w) res = dfs(x + 1, 0);
	else if (x == h) return 0;
	else if (!p[x][y]) res = dfs(x, y + 1);
	else if (!fld[x][y])
	{
		vector<pii> v;
		int l = len[x][y];
		REP(i, l)REP(j, l)
		{
			int tx = x + i, ty = y + j;
			if (!fld[tx][ty]) v.emplace_back(tx, ty);
		}
		if (v.size())
		{
			REP(i, v.size())
			{
				fld[v[i].first][v[i].second] = 1;
			}
			res = dfs(x, y + 1) + 1;
			REP(i, v.size())
			{
				fld[v[i].first][v[i].second] = 0;
			}
		}
	}
	else
	{
		chmin(res, dfs(x, y + 1));
		vector<pii> v;
		int l = len[x][y];
		REP(i, l)REP(j, l)
		{
			int tx = x + i, ty = y + j;
			if (!fld[tx][ty]) v.emplace_back(tx, ty);
		}
		if (v.size())
		{
			REP(i, v.size())
			{
				fld[v[i].first][v[i].second] = 1;
			}
			chmin(res, dfs(x, y + 1) + 1);
			REP(i, v.size())
			{
				fld[v[i].first][v[i].second] = 0;
			}
		}
	}
	//REP(i, h)
	//{
	//	REP(j, w) cout << fld[i][j] << " ";
	//	cout  << endl;
	//}
	return mp[tmp] = res;
	//return mp[fld] = res;
	//return res;
}

int main()
{
	cin.sync_with_stdio(false);
	while (cin >> w >> h, w)
	{
		p.clear(), len.clear(), fld.clear(), mp.clear();
		p.resize(h, vi(w)), len.resize(h, vi(w)), fld.resize(h, vi(w));
		REP(i,h)REP(j,w)
		{
			cin >> p[i][j];
			if (!p[i][j]) fld[i][j] = 1;
		}
		REP(i, h)REP(j, w)
		{
			if (!p[i][j]) continue;
			for (int k = min(h, w); k >= 0; k--)
			{
				if (check(i, j, k))
				{
					len[i][j] = k;
					break;
				}
			}
		}
		
		cout << dfs(0, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 11200
def main():
    N = int(input())
 
    if (N < 0 or N > 100):
        return 0
    array_len = len([N for i in range(1, N+1) if(i%2==1)])
    result = array_len / N
    return result
    
if __name__ == "__main__":
    print(main())

Measured memory_bytes: 2940
#include <stdio.h>
#define N 100000

int search(int array[],int x,int n){
  int i = 0;
  array[n] = x;
  while(array[i] != x) i++;
  return i != n;
}


int main(){
  int S[N],key;
  int n,q;
  int i;
  int count = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search(S,key,n)!=NULL)count++;
  }

  printf("%d\n",count);
  
  return 0;
}




Measured memory_bytes: 2108
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int D = sc.nextInt();
      String result = "";
      
      // バトル
      while(A > 0 && C > 0){
        C = C - B;
        if(C <= 0){
          result = "Yes";
          break;
        }
        A = A - D;
        if(A <= 0){
          result = "No";
        }
      }
      
      // 出力
      System.out.println(result);
    }
}

Measured memory_bytes: 35788
#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
using namespace std;
ll cnt[300005];
bool vis[300005];
int main() {
    int n;
    cin >> n;
    vector<ll> nn;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        cnt[a]++;
        if (!vis[a]) {
            vis[a] = 1;
            nn.push_back(a);
        }
    }
    for (int i = 0; i < nn.size(); i++) {
        nn[i] = cnt[nn[i]];
    }
    sort(nn.begin(), nn.end());
    vector<ll> pre;
    pre.push_back(nn[0]);
    for (int i = 1; i < nn.size(); i++) {
        pre.push_back(pre.back() + nn[i]);
    }
    cout << n << '\n';
    for (ll i = 2; i <= n; i++) {
        ll l = 0, r = 1LL*n / i;
        while (l != r) {
            ll m = l + r + 1 >> 1;
            ll p = lower_bound(nn.begin(),nn.end(), m) - nn.begin();
            ll sum=0;
            if (p)sum = pre[p - 1];
            ll x = nn.size() - p;
            if (x + sum / m >= i) {
                if (l == m)break;
                l = m;
            }
            else if (r == m)break;
            else r = m;
        }
        cout << l << '\n';
    }
    return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;

    int m = 0;
    int pro = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'I')         pro++;
        else if(s[i] == 'D')    pro--;
        m = max(pro, m);
    }
    
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
defmodule Main do
  def main do
    s =
      IO.read(:line)
      |> String.trim
    if s == "RSR" do
    	IO.puts(1)
    else
		s |> to_char_list |> Enum.filter(fn x -> x == ?R end) |> length |> IO.puts
        end
  end
end


Measured memory_bytes: 30756
# -*- coding: utf-8 -*-
from collections import defaultdict
n = int(input())
restaurants = defaultdict(list)
for i in range(n):
    parse = input().split()
    restaurants[parse[0]].append((i + 1, int(parse[1])))

for key in sorted(restaurants):
    for idx, score in sorted(restaurants[key], key=lambda x: x[1], reverse=True):
        print(idx)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define int long long
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) max_element(x.begin(),x.end())
#define MIN(x) min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
//fixed<<setprecision(15);

signed main(){
    int n,m; cin >> n>> m;
    vvint g(n,vint(n,0));
    rep(i,m){
        int a,b; cin >> a >> b; a--; b--;
        g[a][b]=1;
        g[b][a]=1;
    }
    vint order(n);
    rep(i,n) order[i]=i;

    int res=0;
    do{
        if(order[0]!=0) break;
        bool can=true;
        rep(i,n-1){
            if(g[order[i]][order[i+1]]!=1) can=false;
        }
        if(can) res++;
    }while(next_permutation(all(order)));
    COUT(res);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define int long long
    #define endl '\n'
    #define modulo 1000000007
    using namespace std;
    int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int visited[100001];
        vector<vector<int>>lolz(100001);
        void DFS(int n){
        if(visited[n])
        return;
        visited[n]=1;
        for(int i=0;i<lolz[n].size();i++){
        DFS(lolz[n][i]);
        }
        }
    int32_t main()
    {
    iostream::sync_with_stdio(0);
    cin.tie(0);
    int n,m,counter=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    lolz[a-1].push_back(b-1);
    lolz[b-1].push_back(a-1);
    }
    for(int i=0;i<n;i++){
    if(!visited[i]){
    DFS(i);
    counter++;
    }
    }
    cout<<counter;
    return 0;
}


Measured memory_bytes: 9600
import sys
n=int(input())
d=list(map(int,input().split()))

if(d[0]!=0 or d.count(0)>1):
    print(0)
    sys.exit()

MOD=998244353
max_d=max(d)
c=[0 for _ in range(max_d+1)]
for i in range(n):
    c[d[i]]+=1

ans=1
for i in range(max_d):
    ans*=c[i] ** c[i+1]
print(ans%MOD)


Measured memory_bytes: 14020
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, Q;
	in >> N >> Q;
	std::vector<LL>A(N), X(Q);
	rep(i, N) in >> A[i];
	rep(i, Q) in >> X[i];

	std::vector<LL>imos1(N + 1), imos2(N + 1);
	rep(i, N)
	{
		imos1[i + 1] = imos1[i] + A[i];
		imos2[i + 1] += imos2[i];
		if (N % 2 != i % 2) imos2[i + 1] += A[i];
	}

	rep(i, Q)
	{
		LL it1 = std::upper_bound(A.begin(), A.end(), X[i]) - A.begin();
		LL left = it1 - 1, right = N;
		if (left >= N - 1)
		{
			out << imos2[N] << std::endl;
			continue;
		}

		while (right - left > 1)
		{
			LL mid = (left + right) / 2;
			LL dis = A[mid] - X[i];
			LL it2 = std::lower_bound(A.begin(), A.end(), X[i] - dis) - A.begin();
			LL cnt = mid - it2 + 1;
			if (N - cnt <= mid) right = mid;
			else left = mid;
		}

		++left;
		LL cnt = N - left;
		out << (imos1[N] - imos1[left]) + imos2[std::max(left - cnt, 0LL)] << std::endl;
	}
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi 1
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_N 40005

int a, b, x;

int main()
{
  cin >> x >> a >> b;
  if(abs(x - a) < abs(x - b)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
  return 0;
}


Measured memory_bytes: 256