akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int n,s,t,p,m,inwd;
string inwds,inho;



string change(int ho,int mi){
  int tmin=60*ho+mi;
  if(360<=tmin&&tmin<360*3)return "Day";
  else return "Night";
}

bool check(int wd,int ho,int mi){
  if(inwd!=-1&& wd != inwd){
    return false;
  }
  if(inho!="All"&&inho!=change(ho,mi)){
    return false;
  }
  return true;
}

int countFuka(int wd,int ho,int mi){
  int res=0;

  for(int i=0;i<m;i++){
    int flg=true;

    if(!check(wd,ho,mi))flg=false;
    mi+=s;
    if(mi>=60){ho+=(mi/60);mi%=60;}
    if(ho>=24){wd+=(ho/24);ho%=24;}
    if(wd>=7)wd%=7;
    if(!check(wd,ho,mi))flg=false;
    mi+=(t-s);
    if(mi>=60){ho+=(mi/60);mi%=60;}
    if(ho>=24){wd+=(ho/24);ho%=24;}
    if(wd>=7)wd%=7;
    /*
    for(int j=0;j<t;j++){
      if(j<=s&&!check(wd,ho,mi))flg=false;
      mi++;
      if(mi==60){mi=0;ho++;}
      if(ho==24){ho=0;wd++;}
      if(wd==7){wd=0;}
    }
    */
    if(flg)res++;
  }

  return res;
}

int main(){
  while(cin>>s>>n>>t>>inwds>>inho>>p>>m){
    if(inwds=="None")break;
    if(inwds=="All")inwd=-1;
    if(inwds=="Mon")inwd=0;
    if(inwds=="Tue")inwd=1;
    if(inwds=="Wed")inwd=2;
    if(inwds=="Thu")inwd=3;
    if(inwds=="Fri")inwd=4;
    if(inwds=="Sat")inwd=5;
    if(inwds=="Sun")inwd=6;
    
    int maxm=0;
    int WD=inwd,H,M=0;
    if(WD==-1)WD=0;

    if(inho=="All")H=0;
    else if(inho=="Day")H=6;
    else H=18;

    for(int i=0;i<=t;i++){
      maxm=max(maxm, countFuka(WD,H,M) );
      M++;
      if(M==60){M=0;H++;}
      if(H==24){H=0;WD++;}
      if(WD==7)WD=0;
    }

    if(inho=="Night"){
      WD=inwd;
      if(WD==-1)WD=0;
      H=0;
      M=0;
      if(WD==-1)WD=0;
      for(int i=0;i<=t;i++){
	maxm=max(maxm, countFuka(WD,H,M) );
	M++;
	if(M==60){M=0;H++;}
	if(H==24){H=0;WD++;}
	if(WD==7)WD=0;
      }
    }

    
    //cout<<maxm<<endl;
    double rate = 1.0-1.0/(double)p;//hukasinaikakuritu
    double totalnochange,localnochange;
    localnochange=pow(rate,n);
    totalnochange=pow(localnochange,maxm);
    printf("%.10f\n",1.0-totalnochange);

    
  }
  return 0;
}

Measured memory_bytes: 1272
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<60);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
	init();
	ll N,A;cin>>N>>A;
	cout<<N*N-A<<endl;
}


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

#ifdef WINT_MIN
#define __MAI
#endif

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u) { if (u == 0)cout << 0; else { int s = 0, k = 0; for (; 0<u; u >>= 1, k++)s = (s << 1) | (u & 1); for (; 0<k--; s >>= 1)cout << (s & 1); } }template<typename T1, typename T2>
    ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace {
    std::chrono::system_clock::time_point t;
    void tic() { t = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - t)); }
    std::chrono::system_clock::time_point tle = TIME;
#ifdef __MAI
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
#else
#define safe_tle(k) ;
#endif
}

#ifndef __MAI 
namespace {
    class MaiScanner {
    public:
        template<typename T>
        void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        void ign() { getchar_unlocked(); }
        MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
    };
}
MaiScanner scanner;
#else
#define scanner cin
#endif

int n, m;

string strs[60];

ll xx[100010]; // n
ll yy[100010]; // m

int main() {
    ll i, j, k;
    ll x, y, a, b;

    scanner >> n >> m;

    for (i = 0; i < n; ++i) {
        scanner >> xx[i];
    }
    for (i = 0; i < m; ++i) {
        scanner >> yy[i];
    }

    ll hhh = 0;
    for (y = 0; y < m - 1; ++y) {
        a = (1 + y)*(m - y - 1)*(yy[y + 1] - yy[y]) % E107;
        hhh = (a + hhh) % E107;
    }

    ll area = 0;
    for (x = 0; x < n - 1; ++x) {
        a = (1 + x)*(n - x - 1)*(xx[x + 1] - xx[x]) % E107;
        a = a*hhh%E107;
        area = (a + area) % E107;
    }

    cout << area << endl;


    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

double a(double A,double a,double B,double b,double x,double y)
{
if(A!=B){
return ((a-b)/(A-B))*(x-A)+a-y;
} else {
return x-A;
}
}

int main(void)
{
double x1,y1,x2,y2,x3,y3,xp,yp;
int i,j;

while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){


if((a(x1,y1,x2,y2,xp,yp)*a(x1,y1,x2,y2,x3,y3)<0)||(a(x3,y3,x2,y2,xp,yp)*a(x3,y3,x2,y2,x1,y1)<0)||(a(x1,y1,x3,y3,xp,yp)*a(x1,y1,x3,y3,x2,y2)<0)){
printf("NO\n");
} else {
printf("YES\n");
}
}



return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
const int MOD = 1000000007;
const int BASE = 27;
const int oo = 1e9;
const double EPS = 1e-9;
const int MX = 1e5+1;

ll f(ll a , ll b){
  if(a>b)swap(a,b);
  if(a == 0)return -b;
  ll rm = b/a;
  return 2*a*rm+f(a,b%a);
}

ll n , x;

int main() {
  cin >> n >> x;
  cout << (n+f(x,n-x)) << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn fmin(x: f64, y: f64) -> f64 {
  if x < y {
    x
  } else {
    y
  }
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    es: [(usize1, usize1); m],
  }
  let mut exp = vec![0.0; n];
  let mut adj = vec![vec![]; n];
  for &(s, t) in &es {
    adj[s].push(t);
  }
  let mut ans = 1.0 / 0.0;
  for b in 0 .. n {
    for i in (0 .. n - 1).rev() {
      let l = adj[i].len();
      exp[i] = 1.0 + if i == b && l > 1 {
        let mut next: Vec<_> = adj[i].iter().map(|&x| Total(exp[x])).collect();
        next.sort();
        next.iter().take(l - 1).map(|x| x.0).sum::<f64>() / (l - 1) as f64
      } else {
        adj[i].iter().map(|&x| exp[x]).sum::<f64>() / l as f64
      };
    }
    ans = fmin(ans, exp[0]);
  }

  puts!("{:.15}\n", ans);
}


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

int main() {

    int n;
    cin >> n;

    int a[201];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int res = 0;

    while (true) {
        bool kisuu = false;

        for (int i = 0; i < n; i++) {
            if(a[i] % 2 != 0) kisuu = true;
        }

        if (kisuu) break; 

        for (int i = 0; i < n; i++) {
            a[i] = a[i] / 2;
        }

        res ++;

    }
    
    cout << res << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>

int listsearch(int *s,int *t,int m,int n){
  int i,j=0,count=0;
  
  for(i=0;i<m;i++){
    s[n]=t[i];
    while(s[j]!=t[i]){
      j++;  
    }
    if(j!=n)count++;
    j=0;
  }
  return count;
}

int main(){

  int s[10000],t[500],i,n,m;

  scanf("%d",&n);

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

  scanf("%d",&m);
  for(i=0;i<m;i++)
    scanf("%d",&t[i]);
 
  printf("%d\n",listsearch(s,t,m,n));
  return 0;
  }



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  cout<<(n-2)/(k-1)+1<<endl;
  return 0;

}


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

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = max(a*c, max(a*d, max(b*c, b*d)));
    cout << ans << endl;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;



int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a,b;
    char ch;

    scanf("%d %c %d", &a, &ch , &b);
    if(ch=='+'){
        cout << a+b << endl;
    }else cout << a-b << endl;


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> L;
    for (auto i = 0; i < N; i++) {
        int Li;
        cin >> Li;
        L.push_back(Li);
    }
    sort(L.begin(), L.end());
    auto sum = accumulate(L.begin(), L.end() - 1, 0);
    cout << ((L.back() < sum) ? "Yes": "No") << endl;
    return 0;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

int main() {
    double n, m, d;
    cin >> n >> m >> d;

    if (d == 0) {
        double ans = 1 / n * (m - 1);
        printf("%.20f\n", ans);
    } else {
        double ans = 2.0 * (n - d) / n / n * (m - 1);
        printf("%.20f\n", ans);
    }


}





Measured memory_bytes: 256
import java.util.*;

public class Main {
	static class Count {
		int pos;
		int count;
		public Count(int pos, int count) {
			this.pos = pos;
			this.count = count;
		}
		public void add() {
			count++;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		int M = sc.nextInt();
		long[] t = new long[M];
		Count[] ycount = new Count[H];
		for(int i=0; i<H; i++)
			ycount[i] = new Count(i, 0);
		Count[] xcount = new Count[W];
		for(int i=0; i<W; i++)
			xcount[i] = new Count(i, 0);
		for(int i=0; i<M; i++) {
			int h = sc.nextInt()-1;
			int w = sc.nextInt()-1;
			t[i] = (long)h*W+w;

			ycount[h].add();
			xcount[w].add();
		}
		
		Arrays.sort(t);
		Arrays.sort(ycount, new Comparator<Count>() {
			public int compare(Count c1, Count c2) {
				return - Integer.compare(c1.count, c2.count); 
			}
		});
		Arrays.sort(xcount, new Comparator<Count>() {
			public int compare(Count c1, Count c2) {
				return - Integer.compare(c1.count, c2.count); 
			}
		});
		
		int ycand = 1;
		for(; ycand<H; ycand++)
			if(ycount[ycand].count < ycount[0].count)
				break;
		int xcand = 1;
		for(; xcand<W; xcand++)
			if(xcount[xcand].count < xcount[0].count)
				break;
		
		boolean found = false;
		for(int i=0; i<ycand; i++) {
			for(int j=0; j<xcand; j++) {
				if(Arrays.binarySearch(t, (long)ycount[i].pos * W + xcount[j].pos)<0) {
					found = true;
					break;
				}
			}
			if(found)
				break;
		}
		System.out.println(ycount[0].count + xcount[0].count + (found ? 0 : -1));
		
		sc.close();
	}
	
}



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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;


int main()
{
    int n, ans = 1;
    string s;
    cin >> n >> s;
    char tmp = s[0];
    for (int i = 1; i < n; i++) {
        if (tmp != s[i]) {
            ans++;
            tmp = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
	string s, ans;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s.at(i)!='B'){
			ans+=s.at(i);
		}
		if(s.at(i)=='B'){
			if(ans.size()>0) ans.pop_back();
		}
	}
	cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


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

    set<string> st;

    rep(i, s.size()) {
        rep(j, s.size()-i+1) {
            st.insert(s.substr(i, j));
            if(j > 5) break;
        }
    }

    // から文字列消すkesu
    st.erase("");
    int i = 1;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        if(i == k) {
            cout << *itr << endl;
            break;
        }
        i++;
    }

    return 0;
}


Measured memory_bytes: 2176
while True:
  try:
    a, l, x = map(int, input().split())
  except EOFError:
    break
  s1 = (l + l + x) / 2
  v1 = (s1 * (l / 2) * (l / 2) * (x / 2)) ** (1 / 2)
  s2 = (l + l + a) / 2
  v2 = (s2 * (s2 - l) * (s2 - l) * (s2 - a)) ** (1 / 2)
  print(v1 * 2 + v2)


Measured memory_bytes: 5664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int dp[5010][5010]={0};
int main(){
	int n,l;
	cin>>n>>l;
	int MOD=1000000007;
	vi x(n),a(n);
	rep(i,n)cin>>x[i];
	rep(i,n)cin>>a[i];
	rep(i,5010)dp[0][i]=1;
	rep(i,n){
		for(int j=x[i]+1;j<=l;j++){
			if(j==x[i]+1||a[i]&&(j-x[i]-1)%a[i]==0)dp[i+1][j]=(dp[i+1][j]+dp[i][j-1])%MOD;
			dp[i+1][j]=(dp[i+1][j]+dp[i+1][j-1])%MOD;
		}
	}
	cout<<dp[n][l]<<endl;
}

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

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);


int main()
{
  LL x, y;
  cin >> x >> y;
  if(x % y == 0){
    puts("-1");
    return 0;
  }
  LL g = __gcd(x, y);
  lldout((x * y) / g - x);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
    ll a;   cin >> a;
    ll res = a+a*a+a*a*a;
    cout << res << endl;
}

Measured memory_bytes: 3640
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,a,b,c,d,e;
cin>>s;
int n=s.size();
a=s;
reverse(a.begin(),a.end());

if(a==s){
    b.assign(s,0,(n-1)/2);
    c=b;
    reverse(c.begin(),c.end());
    ///cout<<c<<endl;
    if(c==b){
        d.assign(s,((n+3)/2)-1,n);
        e=d;
        reverse(e.begin(),e.end());
        ///cout<<e<<endl;
        if(e==d) printf("Yes\n");
        else printf("No\n");
    }
    else printf("No\n");
}
else printf("No\n");

}
   
        
 

Measured memory_bytes: 256
n,m = map(int,input().split())
if n<m:
  n,m = m,n
if n == m:
  s = 1
  for i in range(1,m+1):
    s = s*i%1000000007
  s = s*s*2%1000000007
elif n == m+1:
  s = 1
  for i in range(1,m+1):
    s = s*i%1000000007
  s = s*s*n%1000000007
else:
  s = 0
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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; }

vector< vector<int> > Graph;
vector< int > value;









int main(int argc, const char * argv[]) {
    
  
    
    
    int x,y,z; cin >> x >> y >> z;
    
    cout << (x-z)/(y+z) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9 + 7;
pair<ll, ll>s4[4] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
pair<ll, ll>s8[8] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};

void judge() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    int x, y;
    cin >> x >> y;
    bool flag = false;
    for (int i = 0; i <= x; i++) {
        if (4 * i + 2 * (x - i) == y) {
            flag = true;
            break;
        }
    }
    if (flag) {
        cout << "Yes" << nl;
    } else {
        cout << "No" << nl;
    }

}

signed main() {
    judge();
    boost;
    solve();
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
priority_queue<ll>que;
P a[114514];
ll n,m,ans=0;
signed main(){
	cin>>n>>m;
	rep(i,n){
		cin>>a[i].first>>a[i].second;
		a[i].first=m-a[i].first;
	}
	sort(a,a+n,greater<P>());
	int p=0,q=0;
	for(int i=m;i>=0;i--){
		while(p<n&&a[p].first>=i){
			que.push(a[p].second);
			p++;
		}
		if(que.size()){
			q+=que.top();
			que.pop();
		}
	}
	cout<<q<<endl;
}


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

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

int a, b;
char op;

int main(){
	cin.tie(0);
	
	while(cin>>a>>op>>b,op!='?') {
	    switch(op) {
	        case '+':
	        cout<<a+b<<endl;
	        break;
	        case '-':
	        cout<<a-b<<endl;
	        break;
	        case '*':
	        cout<<a*b<<endl;
	        break;
	        case '/':
	        cout<<a/b<<endl;
	        break;
	    }
	}
	
	
	return 0;
}



Measured memory_bytes: 3100
using System;

namespace abc153a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            if (a == b && b != c && a!=c)
                Console.WriteLine("Yes");
             else if (a == c && a != b && b != c)
                    Console.WriteLine("Yes");
            else if (b == c && a != b && a != c)
                    Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
                


        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 100005

using namespace std;

int main()
{
    ll a,b;

    scanf("%lld %lld",&a,&b);

    if((a+b)%3==0||a%3==0||b%3==0)
        printf("Possible\n");

    else
        printf("Impossible\n");

    return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)1e6+5;

typedef long long ll;
ll MOD = (ll)1e9+7;
inline ll qpow(ll a, ll b) {return b? ((b&1)? a*qpow(a*a%MOD,b>>1)%MOD: qpow(a*a%MOD,b>>1))%MOD: 1;}
inline ll gcd(ll a, ll b) {return b? gcd(b, a%b): a;}

ll n,k;
ll dp[maxn];

ll num(ll x){
    if(dp[x])return dp[x];
    ll ret=qpow(k/x,n);
    for(int y=x+x;y<=k;y+=x)ret-=num(y),ret+=MOD,ret%=MOD;
    return dp[x]=ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    ll ans=0;
    for(int x=k;x>=1;x--){
        ans+=x*num(x)%MOD;ans%=MOD;
    }
    cout<<ans<<endl;
}
/* 
有一些性质是没用的
The necessary and sufficient condition of the greatest common divisor being a multiple of X is that all the A1, ..., AN are multiples of X. 
The number of such sequences is K/X^N .
The necessary and sufficient condition of it being exactly X is that “it is a multiple of X, but not 2X, 3X....”
倒着算即可 即容斥
 */

Measured memory_bytes: 4388
#include<iostream>
using namespace std;
int main(){
	for(;;){
		int n,sum=0;
		cin >>n;
		if(n == 0){break;}
		for(int i=5;i<=n;i*=5){
			sum+=n/i;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
  ll H,W; cin>>H>>W;
  vector<string> v(H); REP(i,H) cin>>v[i];
  ll cnt=0;
  REP(i,H) REP(j,W) if(v[i][j]=='#') cnt++;
  if(cnt==H+W-1) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
import heapq
L = []
heapq.heapify(L)

import sys
for a in sys.stdin:
    if a[0]=='i':
        heapq.heappush(L, -int(a[7:]))
    elif a[0:2]=='ex':
        e = heapq.heappop(L)
        print(-e)
    else:
        break


Measured memory_bytes: 45576
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors)
n = int(input())
ans = 0
for i in range(1,n+1,2):
    if make_divisors(i) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
from collections import deque

list = list(input())

queue = deque([]) 
queue2 = []
total = 0

for i in range(len(list)):
        if list[i] == '\\':
                queue.append(i)
        elif list[i] == '/' and len(queue) > 0:
                j = queue.pop()
                total += (i - j)
                temp = i - j
                while len(queue2) > 0 and queue2[len(queue2) - 1][0] > j:
                        temp += queue2[len(queue2) - 1][1]
                        queue2.pop()
                queue2.append([j, temp])
strResult = [str(len(queue2))]
for i in range(len(queue2)):
        strResult.append(str(queue2[i][1]))

print(total)
print(" ".join(strResult))


Measured memory_bytes: 6720
def gcd(n,m)
  if(n > m)
    nn = n
    mm = m
  else
    nn = m
    mm = n
  end
#  printf("%d\n",mm)
  if(nn % mm == 0)
    return mm
  else
    return gcd(mm,nn%mm)
  end
      
end

arr = gets.split.map(&:to_i)
a = arr[0]
b = arr[1]
c = arr[2]
d = arr[3]
#printf("%d\n",a)
#printf("%d\n",b)
#printf("%d\n",c)
#printf("%d\n",d)

gc = gcd(c,d)
lc = (c*d)/gc;

ac = (a-1)/c;
ad = (a-1)/d;
bc = b/c;
bd = b/d;
acd = (a-1)/lc;
bcd = b/lc;

ret = (b-a+1)-(bc-ac)-(bd-ad) + (bcd-acd)
#print(a+b)
printf("%d\n",ret)


Measured memory_bytes: 1788
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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 (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

uint64_t popcnt(uint64_t n) {
  uint64_t c = 0;
  c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555);
  c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333);
  c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f);
  c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff);
  c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff);
  c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff);
  return (c);
}

int main() {
  init();

  ll N, M, Q;
  cin >> N >> M >> Q;
  vl a(Q), b(Q), c(Q), d(Q);
  rep(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  ll ans = 0;

  rep(i, 1 << (N + M - 1)) {
    if (popcnt(i) != M - 1) continue;
    vi A(N, 1);
    int a0 = 1, k = 0;
    rep(j, N + M - 1) {
      if (i & (1 << j)) {
        a0++;
      } else {
        A[k++] = a0;
      }
    }
    ll p = 0;
    rep(j, Q) {
      if (A[b[j] - 1] - A[a[j] - 1] == c[j]) p += d[j];
    }
    chmax(ans, p);
  }

  out(ans);
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(void){
    int i, n;
    scanf("%d", &n);
    
    for(i = 1; i <=n ;i++){
        
        if(i % 3 == 0){
            printf(" %d", i);
        }else if(i % 10 == 3){
            printf(" %d", i);
        }else if(i / 10 > 0 && (i/10) % 10 == 3){
            printf(" %d", i);
        }else if(i / 100 > 0 && (i/100) % 10 == 3){
            printf(" %d", i);
        }else if(i / 1000 > 0 && (i/1000) % 10 == 3){
            printf(" %d", i);
        }else if(i / 10000 > 0 && (i/10000) % 10 == 3){
            printf(" %d", i);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

int n;
vector<int64> a;
vector<uint64> dp;

int main(){

	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	dp.resize(n + 1);
	dp[2] = abs(a[1] - a[0]);
	for (int i = 2; i < n; ++i){
		dp[i + 1] = min(dp[i] + abs(a[i] - a[i - 1]), dp[i - 1] + abs(a[i] - a[i - 2]));
	}
	
	cout << dp[n] << endl;
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	char c;
	int y = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> c;
		if (c == 'Y')
		{
			y = 1;
			break;
		}
	}
	if (y)
		cout << "Four" << endl;
	else
		cout << "Three" << endl;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
int a[105];
int cha[105];
int main()
{
    int n;
    int sum=0;
    int sum1=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    for(int i=1; i<=n; i++)
    {
        sum=sum-a[i];
        sum1=sum1+a[i];
        cha[i]=sum1-sum;
        if(cha[i]==0)
        {
            printf("0\n");
break;
        }
        if(cha[i]>0)
        {
            if(cha[i]>abs(cha[i-1])&&i>1)
            {
                printf("%d\n",-cha[i-1]);
            }
            else
            {
                printf("%d\n",cha[i]);
            }
            break;
        }
    }
}


Measured memory_bytes: 128
#include<stdio.h>

int count(int num);

int main() {
	int a, b, i;
	scanf("%d%d", &a, &b);
	for (i = 0; i < count(b); i++) {
		a *= 10;
	}
	a += b;
	i = 4;
	while ((b = i * i) != a) {
		i++;
		if (b > a) {
			a = 0;
			break;
		}
	}
	printf((a == 0) ? "No" : "Yes");
	return 0;
}

int count(int num) {
	if (num < 10) return 1;
	else return 1 + count(num / 10);
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC049A___居合を終え_青い絵を覆う
{
    class Program
    {


        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            bool isVowel = vowelArray.Contains(input);


            string output = "consonant";
            if (isVowel)
            {
                output = "vowel";
            }

            Console.WriteLine(output);
        }
        
        private static string[] vowelArray = {"a","e","i","o","u" };
    }
}


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

#define int long long
#define all(V) (V).begin(),(V).end()
#define umap unordered_map
#define uset unordered_set
#define br cout<<"\n";

const int MAXN=1e5+10, MOD=1e9+7;
int n,m;
vector<int> v;

int lis(){
	vector<int> dp;
	dp.push_back(v[0]);
	for(int i=1; i<n; i++){
		if(v[i]>dp.back()){
			dp.push_back(v[i]);
		}
		else{
			int idx = lower_bound(all(dp),v[i]) - dp.begin();
			dp[idx] = v[i];
		}
	}
	return dp.size();
}

signed main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("./input.txt","r",stdin);
	// 	freopen("./output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin>>n;
	v.resize(n);
	for(int i=0; i<n; i++){
		cin>>v[i];
	}
	cout<< lis(); br;

}


Measured memory_bytes: 4648
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, n; cin >> h >> n;
	rep(i, n) {
		int a; cin >> a;
		h -= a;
	}
	if (h <= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> bool chmin(T &a, T b) {
    if(a > b) {
        a = min(a, b);
        return true;
    }
    else return false;
}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
struct Elem {
    string name;
    int weight, limit;
};

int dp[1 << 11];
vector<string> vec[1 << 11];

signed main() {
    int N;
    while(cin >> N, N) {
        vector<Elem> elems;
        for(int i=0; i<N; i++) {
            string name; int weight, limit;
            cin >> name >> weight >> limit;
            elems.push_back(Elem{name, weight, limit});
        }

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

        for(int bit=0; bit<(1<<N); bit++) {
            int coeff = N - __builtin_popcount(bit);
            int sum = 0;
            for(int i=0; i<N; i++) {
                if(bit >> i & 1) sum += elems[i].weight;
            }
            for(int i=0; i<N; i++) {
                if((bit >> i & 1) or (sum > elems[i].limit)) continue;
                int nbit = bit | (1 << i);
                if(chmin(dp[nbit], dp[bit] + coeff * elems[i].weight)) {
                    vec[nbit] = vec[bit];
                    vec[nbit].push_back(elems[i].name);
                }
            }
        }

        vector<string> ans = vec[(1<<N) - 1];
        reverse(ans.begin(), ans.end());
        for(int i=0; i<ans.size(); i++) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x,int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/


int main()
{
	char S[5];
	char c1, c2;
	int n1, n2;
	bool ans;
	cin >> S;

	c1 = S[0];
	n1 = 1;
	n2 = 0;
	c2 = '.';
	for (int i = 1; i < 4; i++)
	{
		if (S[i] == c1)
		{
			n1++;
		}
		else if (S[i] == c2)
		{
			n2++;
		}
		else
		{
			if (c2 == '.')
			{
				c2 = S[i];
				n2++;
			}
		}
	}

	if (n1 == 2 && n2 == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        new Program();
    }

    Program()
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        if (t.Length != s.Length + 1)
        {
            Console.WriteLine("No");
        }
        else if (t.StartsWith(s))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 18252
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
   // freopen("input.txt", "r", stdin);
    SPEED
    int a, b;
    cin >> a >> b;
    cout << (a > 9 || b > 9 ? -1 : a * b);
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */

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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    int nn = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i]<0) nn++;
    }
    if(nn==0) nn=1;
    if(nn==n) nn=n-1;
    sort(a.begin(),a.end());

    int ans=0;
    for(int i = 0; i < nn; i++) {
        ans-=a[i];
    }
    for(int i = nn; i < n; i++) {
        ans+=a[i];
    }
    cout << ans << "\n";

    for(int i = nn; i < n-1 ; i++) {
        cout << a[0] << " " << a[i] << "\n";
        a[0]-=a[i];
    }
    for(int i = 0; i < nn; i++) {
        cout << a[n-1] << " " << a[i] << "\n";
        a[n-1]-=a[i];
    }

    return 0;
}

Measured memory_bytes: 3704
from itertools import permutations

N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = [int(x) for x in input().split()]

listP = list(permutations(range(N), N))
sum_d = 0
for p in listP:
    for i in range(1, N):
        sum_d += ((x[p[i]] - x[p[i - 1]]) ** 2 + (y[p[i]] - y[p[i - 1]]) ** 2) ** 0.5

print(sum_d / len(listP))

Measured memory_bytes: 8180