akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

int main(){
	
	int len,n,sp=1,s=0,i;
	char in[201];
	if(scanf("%s",in) < 1){return -1;}

	while(1){
		len = strlen(in);
		len--;	
		in[len] = '\0';

		if(len%2 == 1){
			len--;
			in[len] = '\0';
		}
		for(i=0;i<len/2;i++){
			if(in[i] != in[i+len/2]){
				break;
			}
			if(i == len/2 - 1){
				printf("%d",(i+1)*2);
				return 0;
			}
		}
		if(len < 2){break;}
	}
	return -1;
}

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

int main(){
  int n;
  cin >> n;
  bool ok=false;
  int k=0;
  for(int i=1;i<1000;i++){
    if(i*(i-1)==2*n){
      ok=true;
      k=i;
    }
  }
  if(ok){
    cout << "Yes" << endl;
    cout << k << endl;
    int a[k][k-1];
    int c=1;
    for(int i=0;i<k;i++){
      for(int j=0;j<k-1;j++){
        if(i<=j){
          a[i][j]=c;
          c++;
        }
        else{
          a[i][j]=a[j][i-1];
        }
      }
    }
    for(int i=0;i<k;i++){
      cout << k-1 << " ";
      for(int j=0;j<k-1;j++){
        cout << a[i][j] << " ";
      } 
      cout << endl;
    }
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 2176
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int A; int B; int C;
    cin >> A >> B >> C;
    if (A + B < C)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic error "-std=c++14"

#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define ri register int

template<class T>
inline void in(T&);
template<class T>
inline void out(const T&);

typedef long long ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
using namespace std;

char s[1005],l;

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%s",s+1);
    l=strlen(s+1);bool f=1;
    for (ri i=1;i<=l/2;++i) if (s[i]!=s[l-i+1]) {f=0;break;}
    if (f==0) {puts("No");return 0;}
    for (ri i=1;i<=(l-1)/2;++i) if (s[i]!=s[(l-1)/2-i+1]) {f=0;break;}
    if (f==0) {puts("No");return 0;}
    for (ri i=(l+3)/2;i<=(l-(l+3)/2)/2;++i) if (s[i]!=s[(l-(l+3)/2)-i+1]) {f=0;break;}
    if (f==0) {puts("No");return 0;}
    puts("Yes");
    return 0;
}

template<class T>
void in(T &Re)
{
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch))
	{
        if (ch=='-')
		{
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch))
	{
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}

template<class T>
void out(const T &Wr)
{
    if (Wr<0)
	{
        putchar('-');
        out(-Wr);
    }
	else
	{
        if (Wr<10)
		{
            putchar(Wr+'0');
        }
		else
		{
            out(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = 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; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

ll calc_figures(ll x) {
  ll ans = 0;
  while (x != 0) {
    ans++;
    x /= 10;
  }
  return ans;
}

vector<ll> enum_divisor(ll m) {
  vector<ll> divisors;
  for (ll i = 1; i*i <= m; ++i) {
    if (m % i != 0) continue;
    divisors.push_back(i);
    if (i * i != m) divisors.push_back(m / i);
  }
  return divisors;
}

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

  ll n;
  cin >> n;

  ll ans = INFLL;
  auto divisors = enum_divisor(n);
  for (auto& v : divisors) {
    chmin(ans, max(calc_figures(v), calc_figures(n/v)));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

signed main(void) {
    int i,j;
    int n,k,q;
    cin>>n>>k>>q;
    vi a(n),t(n);
    rep(i,n)cin>>a[i],t[i]=a[i];
    sort(all(t));
    int ans = INF;
    rep(i,n){
        int l=0,r;
        int tmp = 0;
        vi p,pp;
        rep(r,n){
            if(a[r] >= t[i]){
                p.push_back(a[r]);
            }else{
                int num = r-l-k;
                if(num >= 0){
                    sort(all(p));
                    rep(j,num+1)pp.push_back(p[j]);
                }
                p.clear();
                l=r+1;
            }
        }
        int num = r-l-k;
        if(num >= 0){
            sort(all(p));
            rep(j,num+1)pp.push_back(p[j]);
        }
        if(pp.size() >= q){
            sort(all(pp));
            int sum = 0;
            ans = min(ans, pp[q-1]-t[i]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int i,j,k;
  int m,n;
  cin>>m>>n;
  bool a[20][20]={};
  while(n--){
    int p,q;
    cin>>p>>q;
    --p;
    --q;
    a[p][q]=true;
    for(i=0;i<m;++i)
      a[p][i]|=a[q][i];
  }
  bool b[20]={};
  for(i=0;i<m;++i){
    for(j=0;j<m;++j){
      if(b[j])continue;
      for(k=0;k<m&&(b[k]||!a[k][j]);++k);
      if(k>=m)break;
    }
    b[j]=true;
    cout<<j+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  cout << count_if(h.begin(), h.end(), [&](int x) {return x >= k;}) << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

class UnionFind {
	vector<int> data;
	int root(int a) {
		return data[a] < 0 ? a : data[a] = root(data[a]);
	}
public:
	UnionFind(int n) : data(n, -1) {}
	bool Find(int a, int b) {
		return root(a) == root(b);
	}
	void Union(int a, int b) {
		int ra = root(a), rb = root(b);
		if (ra == rb) return;
		if (data[ra] < data[rb]) {
			data[ra] += data[rb];
			data[rb] = a;
		}
		else {
			data[rb] += data[ra];
			data[ra] = b;
		}
	}
};

class MinimumSpanningTree {
	struct edge { int u, v, cost; };
	int V;
	vector<edge> es;
public:
	MinimumSpanningTree(int _V) : V(_V) {}

	void add(int a, int b, int c) {
		es.push_back((edge) { a, b, c });
	}

	int Kruskal() {
		int res = 0;
		UnionFind uf(V);
		sort(es.begin(), es.end(), [](const edge& e1, const edge& e2) { return e1.cost < e2.cost; });
		for (auto &e : es) {
			if (!uf.Find(e.u, e.v)) {
				uf.Union(e.u, e.v);
				res += e.cost;
			}
		}
		return res;
	}

};

int main()
{
	int V, E;
	cin >> V >> E;
	MinimumSpanningTree mst(V);
	for (int i = 0, u, v, cost; i < E; i++) {
		cin >> u >> v >> cost;
		mst.add(u, v, cost);
	}
	cout << mst.Kruskal() << endl;
	return 0;
}

Measured memory_bytes: 4568
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;


int main()
{
    int64_t H, W;
    std::cin >> H >> W;

    boost::multi_array<int, 2> mat(boost::extents[H][W]);

    int cc = 0;
    for (auto p = mat.data(); p < (mat.origin() + mat.num_elements()); ++p) {
        char t;
        int v;
        std::cin >> t;
        if (t == '.') {
            v = 0;
            cc++;
        }
        else {
            // 壁
            v = -1;
        }
        *p = v;
    }

    auto f = [&mat, H, W](auto x0, auto y0) -> int {
        using axis_t = decltype(x0);
        // using value_t = decltype(mat.data());

        std::queue<std::pair<axis_t, axis_t>> q;

        // setup initilal position
        q.push({x0, y0});

        // 距離計測初期条件
        mat[x0][y0] = 1;

        while (!q.empty()) {

            axis_t x, y;

            std::tie(x, y) = q.front();
            q.pop();

            // 途中の終了条件
            if (x == W-1 && y == H-1) {
                return mat[y][x];
            }

            // 四方に動くパターン
            constexpr std::pair<int, int> dirs4[] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
            // 八方
            //constexpr std::pair<int, int> dirs8[] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1},
            //                                         {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
            for (auto dir: dirs4) {
                auto xx = x + dir.first;
                auto yy = y + dir.second;
                if (0 <= xx && xx < W && 0 <= yy && yy < H) {
                    if (mat[yy][xx] == 0 /* 移動可能条件 */) {
                        q.push({xx, yy});
                        // 移動済みマーク兼距離記録
                        mat[yy][xx] = mat[y][x] + 1;
                    }
                }
            }
        } // while()

        // 終了条件にマッチせず探索終了
        return -1;
    };

    auto c = f(0, 0);

    if (c == -1) {
        std::cout << -1 << std::endl;
    }
    else {
        std::cout << cc - c << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#import <Foundation/Foundation.h>
#include <stdio.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        int a,b;
        NSString *output_str;
        scanf("%d %d", &a, &b);
        if (!(a%2 && b%2)) {
            output_str = @"No";
        }
        else {
            output_str = @"Yes";
        }
        
        NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
        [fileHandle writeData:[output_str dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle closeFile];
    }
    return 0;
}


Measured memory_bytes: 4156
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};
use std::collections::HashSet;

fn main() {
    let mut uniq = HashSet::new();
    let n: usize = read();
    for _ in 0..n {
        let s: String = read();
        uniq.insert(s);
    }


    println!("{}", uniq.len());
}


Measured memory_bytes: 15344
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let mut succeeded = true;
    let mut t = 0;
    let mut x = 0;
    let mut y = 0;

    for _ in 0..n {
        let ti: u32 = read();
        let xi: i32 = read();
        let yi: i32 = read();

        if !succeeded { 
            continue
        }

        let dist: u32 = ((xi - x).abs() + (yi - y).abs()) as u32;
        let time: u32 = ti - t;

        if dist <= time && dist % 2 == time % 2 {
            t = ti;
            x = xi;
            y = yi;
        } else {
            succeeded = false;
        }
    }
    println!("{}", if succeeded { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
  long int i,j,n,m,k;
  vector <long int > arr,dp;
  cin>>n;
  for(i=0 ; i<n ; i++)
  {
      cin>>j;
      arr.pb(j);
  }
  dp.pb(abs(arr[1]-arr[0]));
  if(n>2)
  dp.pb(abs(arr[2]-arr[0]));
  for(i=3 ; i<n ; i++){
      m=dp[i-1]+abs(arr[i]-arr[i-1]);
      k=dp[i-2]+abs(arr[i]-arr[i-2]);
    //  cout<<m<<"  "<<k<<endl;
  dp.pb(min(dp[i-2]+abs(arr[i]-arr[i-1]),dp[i-3]+abs(arr[i]-arr[i-2])));}
//   for(i=0 ; i<n-1 ; i++)
//   cout<<dp[i]<<" ";
//   cout<<endl;
  cout<<dp[n-2];
}


Measured memory_bytes: 5556
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    long long n, m;
    scanf("%lld %lld", &n, &m);
    long long ans = min(n, m / 2);
    n -= ans;
    m -= ans * 2;
    ans += m / 4;
    printf("%lld\n", ans);
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c) cout << 1 << endl;
    else if(a == b || b == c || c == a) cout << 2 << endl;
    else cout << 3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll x;
  cin>>x; x;
  ll y;
  cin>>y; y;
	auto get=
		[&](int x){ return max(0,4-x)*100000ll;};
	cout<<get(x)+get(y)+(x==1&&y==1?400000:0)<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int [][]a = new int [3][3];
		
		for(int i = 0 ;i < 3; i++) {
			for(int j = 0 ; j < 3 ;j++) {
				a[i][j] = Integer.parseInt(sc.next());
			}
		} 
		
		int n = Integer.parseInt(sc.next());
		
		int []b = new int [n];
		
		for(int i = 0 ; i< n ;i++) {
			b[i] = Integer.parseInt(sc.next());
		}
		
		boolean [][]ans = new boolean [3][3];
		
		for(int i = 0 ;i < n ;i++) {
			for(int j = 0 ; j < 3 ;j++) {
				for(int k = 0 ; k < 3 ; k++) {
					if(b[i] == a[j][k]) {
						ans[j][k] = true;
					}
				}
			}
		}
		boolean flag = false;
		
		for(int i = 0 ; i < 3 ;i++) {
			if(ans[i][0]&&ans[i][1]&&ans[i][2]) {
				flag = true;
			}
			if(ans[0][i]&&ans[1][i]&&ans[2][i]) {
				flag = true;
			}
		}
		
		if(ans[0][0]&&ans[1][1]&&ans[2][2]) {
			flag = true;
		}
		if(ans[0][2]&&ans[1][1]&&ans[2][0]) {
			flag = true;
		}
		
		if(flag) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}

}


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

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

    ll n;
    cin >> n;
    vector<ll> x(n + 1);
    rep(i, n + 1) cin >> x[i];
    sort(x.begin(), x.end());
    vector<ll> y(n);
    rep(i,n)y[i] = x[i + 1] - x[i];
    ll ans = y[0];
    rep(i, n) ans = __gcd(ans, y[i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = [int(i) for i in input().split()]
counter = 0
flag = True

while flag:
    flag = False
    i = 0
    for j in range(N-1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            counter += 1
            flag = True
    i += 1
A = [str(i) for i in A]
print(' '.join(A))
print(counter)



Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#define MAX 500005
using namespace std;

long long a[MAX], b[MAX], d[MAX];

int main() {
	int n; long long dist;
	cin >> n >> dist;
	a[0] = dist;
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
		if (d[i] <= a[i-1]) {
			a[i] = a[i - 1] - d[i];
		}
		else if (d[i] >= 2 * a[i-1]) {
			a[i] = a[i - 1];
		}
		else { a[i] = d[i] - a[i - 1]; }
	}
	b[n] = 1;
	for (int i = n-1; i >= 1; i--) {
		if (d[i+1] < 2 * b[i + 1]) {
			b[i] = b[i + 1] + d[i+1];
		}
		else { b[i] = b[i + 1]; }
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int que;
		cin >> que;
		if (a[que-1] < b[que]) { cout << "NO" << endl; }
		else { cout << "YES" << endl; }
	}
}

Measured memory_bytes: 13696
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=5050;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define eps 1e-8
int n,maxd;
ll c[N+10][N+10],s[N+10][N+10];

int read()
{
    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;
}

ll qpow(ll x,int y,int p)
{
	ll ans=1;
	while (y)
	{
		if (y&1) ans=ans*x%p;
		x=x*x%p;y>>=1;
	}
	return ans;
}

int main()
{
	n=read();maxd=read();
	rep(i,0,N)
	{
		s[i][0]=1;
		rep(j,1,i) s[i][j]=(s[i-1][j-1]+s[i-1][j]*(j+1))%maxd;
	}
	rep(i,0,N)
	{
		c[i][0]=1;
		rep(j,1,i) c[i][j]=(c[i-1][j-1]+c[i-1][j])%maxd;
	}
	ll ans=0;
	rep(i,0,n)
	{
		ll now=0,kd=qpow(2,qpow(2,n-i,maxd-1),maxd);
		rep(j,0,i)
		{
			ll tmp=qpow(2,(n-i)*j,maxd);
			now=(now+kd*tmp%maxd*s[i][j])%maxd;
		}
		now=now*c[n][i]%maxd;
		if (i&1) now=maxd-now;
		ans=(ans+now)%maxd;
	}
	printf("%lld",ans);
	return 0;
}
			
			


Measured memory_bytes: 398080
a,b,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(m)]
ans = min(a) + min(b)
for x,y,c in xyc:
  x-=1
  y-=1
  tmp = a[x] + b[y] - c
  ans = min(tmp,ans)
print(ans)

Measured memory_bytes: 82156
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n;

int main()
{
	cin>>n;
	if(n%2==0) printf("%.10lf\n",0.5);
	else printf("%.10lf\n",(double(n/2+1))/(double(n)));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main() {
  string s;
  cin >> s;
  int n=s.size();
  cout << s[0] << n-2 << s[n-1] << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
char s[111];
const int inf=1e9+7;
int main()
{
    int n;scanf("%s%d",s,&n);
    int k=strlen(s);
    int bef=1,r=0,x=0;ll res=0;
    rep(i,1,k)
    {
        if(s[i]==s[i-1])bef++;
        else {
            if(bef==i)r+=bef,res+=bef/2;
            else x+=bef/2;
            bef=1;
        }
    }
    if(bef==k)printf("%lld\n",(k*1ll*n)/2);
    else {
        r+=bef,res+=bef/2;
        res+=x*1ll*n;
        if(s[0]==s[k-1])
            res+=r/2*1ll*(n-1);
        else res+=(bef/2+(r-bef)/2)*1ll*(n-1);
        printf("%lld\n",res);
    }
}

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

void swap(int *x,int *y) {
    
    int tmp;
    
    tmp = *x;
    *x = *y;
    *y = tmp;
    
}

void call(int n) {
    int i = 1;
    
    while (1) {
        
        if (++i > n) {
            break;
        }
        
        if (i % 3 == 0) {
            printf(" %d",i);
            continue;
        }
        
        if (i % 10 == 3) {
            printf(" %d",i);
            continue;
        }
        
        int x = i;
        
        while (x > 0) {
            
            x /= 10;
            
            if (x%10 == 3) {
                printf(" %d",i);
                break;
            }
        }
        
    }
}

int main(int argc, const char * argv[]) {
    
    int n;
    
    scanf("%d",&n);
    call(n);
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#define int long long

using namespace std;

signed main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<set<int>> pos(26, set<int>());
    for(unsigned i = 0; i < S.size(); i++){
        pos[S[i] - 'a'].insert(i);
    }
    for(auto i = 0LL; i < Q; i++) {
        int q;
        cin >> q;
        if(q == 1){
            int i;
            string c;
            cin >> i >> c;
            i--;
            pos[S[i] - 'a'].erase(i);
            S[i] = c[0];
            pos[S[i] - 'a'].insert(i);
        } else {
            int ans = 0, l, r;
            cin >> l >> r;
            l--;
            r--;
            for(auto i = pos.begin(); i != pos.end(); i++) {
                auto idx = i->lower_bound(l);
                if(idx != i->end() && *idx <= r)
                    ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string.h>
#include <cassert>
#include <string.h>
#include <tuple>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<=b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pair_t;
#define MOD 1000000007

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();
///(10-(n%10))%10  10-(1桁目)取得 12->8 20->0

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て


int gcd(int a,int b);
size_t length(const std::string& str) {
	return str.length();
}
bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

int main() {
	int N,K,h;

	double ans=0;
	cin>>N>>K;
	rep(i,N){
		cin>>h;
		if(h>=K)
			ans++;

	}

	cout<<ans<<endl;

	return 0;

}


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


Measured memory_bytes: 256
n = int(input())
a = [0] +list(map(int, input().split()))+[0]
money = [0]
for i in range(n+1):
  money.append(abs(a[i]-a[i+1]))

ans = sum(money)
for i in range(n):
  print(ans-sum(money[i+1:i+3])+abs(a[i]-a[i+2]))

Measured memory_bytes: 14044
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  long N, x;
 
  cin >> N >> x;
 
  long prev, curr, count = 0;
 
  cin >> curr;
  if(curr > x){
    count += curr - x;
    curr = x;
  }
 
  prev = curr;
 
  for(int i = 1; i < N; i++){
    cin >> curr;
    if(prev + curr > x){
      count += prev + curr - x;
      curr = curr - (prev + curr - x);
    }
 
    prev = curr;
  }
  cout << count << endl;
 
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
win_t=t.replace('r','P').replace('p','S').replace('s','R')

ans=''
cnt=0

for i in range(n):
  if i<k:
    ans+=win_t[i]
    continue
  if win_t[i]!=ans[i-k]:
    cnt+=1
    ans+=win_t[i]
  else:
    ans+='x'
    
print(ans.count('P')*p+ans.count('S')*s+ans.count('R')*r)

Measured memory_bytes: 3444
n, x = map(int, input().split())

burger = [1]*(n+1)
patty = [1]*(n+1)

stopped = 0
for i in range(1,n+1):
	burger[i] = 2*burger[i-1]+3
	patty[i] = 2*patty[i-1]+1
	
def solve(n, x):
	if x == 0:
		return 0
	elif x == burger[n]:
		return patty[n]
	elif x == burger[n-1]+1:
		return patty[n-1]
	elif x == burger[n-1]+2:
		return patty[n-1]+1
	elif x < burger[n-1]+2:
		return solve(n-1, x-1)
	elif x > burger[n-1]+2:
		return solve(n-1, x-burger[n-1]-2)+patty[n-1]+1

print(solve(n, x))

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

using namespace std;

#define ll long long

signed main() {
	string s;
	cin >> s;
	bool f = s[0] == s[1] || s[1] == s[2] || s[2] == s[3];
	cout << (f ? "Bad" : "Good") << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
sel = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if not j == k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j]+sel[i][k])

print(max(dp[N]))

Measured memory_bytes: 74092
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int MAX=100005;
vector<int> llist[MAX*2];
int n,m,color[MAX*2],appear[MAX],zero,two,one;
long long int ans;
int bfs(int u)
{
	vector<int> used;
	int vertex=0;
	bool flag=false;
	queue<int> q;
	used.push_back(u);
	q.push(u);
	color[u]=1;
	while(!q.empty())
	{
		int v=q.front();
		int r=v;
		q.pop();
		if(v>n){
			r=v-n;
		}
		appear[r]++;
		if(appear[r]==2) flag=true;
		else vertex++;
		for(int i=0;i<llist[v].size();++i){
			int temp=llist[v][i];
			if(color[temp]==0){
				q.push(temp);
				used.push_back(temp);
				color[temp]=1;
			}
		}	
		
	}
	for(int i=0;i<used.size();++i){
		int temp=used[i];
		if(temp>n) temp-=n;
		color[temp]=1;
	}
	if(vertex==1){
		zero++;
		return 0;	
	} 
	if(flag){
		one++;
		return 1;
	}
	two++;
	return 2;
}
int main()
{
	int a,b;
	int sum;
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		cin>>a>>b;
		llist[a+n].push_back(b);
		llist[b+n].push_back(a);
		llist[a].push_back(n+b);
		llist[b].push_back(n+a);
	}
	for(int i=1;i<=n;++i){
		if(color[i]==0){
			int type=bfs(i);
//			cout<<type<<endl;
			if(type==0){
				ans+=(2*(long long int)(n-zero+1)-1);
//				cout<<"shit1"<<endl;
			}
			else if(type==1){
				ans+=2*((long long int)two+(long long int)(one-1))+(long long int)type;
//				cout<<"shit2"<<endl;
			}
			else{
				ans+=2*((long long int)(two-1)*2+(long long int)one)+(long long int)type;
//				cout<<"shit3"<<endl;
			}
//			cout<<i<<" "<<ans<<" "<<two<<" "<<one<<endl;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15736
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int is_palin(string s){
	string t=s;
	reverse(t.begin(),t.end());
	return (t==s ? 1 : 0);
}

int32_t main(){
	fastio;
	int L;
	cin>>L;
	double sla = 1.0*L/3.0;
	double res = 1.0*sla*sla*sla;
	cout<<setprecision(8)<<fixed;
	cout<<res<<endl;
}

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

int main(){
    string s; cin >> s;
    deque<char> str;
    for (char x : s){
        str.push_back(x);
    }
    bool reversed = false;
    int q; cin >> q;
    while(q--){
        int t; cin >> t;
        if (t == 1){
            reversed = !reversed;
        }
        else{
            int f; cin >> f;
            char c; cin >> c;
            if (reversed){
                f = 3 - f;
            }
            if (f == 1){
                str.push_front(c);
            }
            else{
                str.push_back(c);
            }
        }
    }
    if (reversed){
        reverse(str.begin(), str.end());
    }
    for (char & x : str){
        cout << x;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

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



	
int main() {	
	
	ll u, v, N;
	cin >> N >> u >> v;

	vector<ll> g[MAX];

	repn(i, N-1) {
		ll A, B;
		cin >> A >> B;
		g[A].push_back(B);
		g[B].push_back(A);
	}

	ll a[MAX];
	ll t[MAX];
	repn(i, N) {
		a[i] = -1;
		t[i] = -1;
	}

	queue<ll> q;

	a[v] = 0;
	q.push(v);
	while (!q.empty()) {
		ll w = q.front();
		q.pop();
		rep(i, g[w].size()) {
			ll x = g[w][i];


			if (a[x] == -1) { a[x] = a[w] + 1; q.push(x); }
		}
	}

	t[u] = 0;
	q.push(u);
	while (!q.empty()) {
		ll w = q.front();
		q.pop();
		rep(i, g[w].size()) {
			ll x = g[w][i];
			if (t[x] == -1) { t[x] = t[w] + 1;  q.push(x); }
		}
	}

	ll ans = 0;

	repn(i, N) {
		if (t[i] < a[i]) { 
			ans = max(ans, a[i] - 1);
		}
	}

	cout << ans;

	system("PAUSE");


}

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

const int N=1e5+100;
int n;
char s[N];
int x[N];
int sp[N];
/*sheep: 0,wolf: 1
o: 0,x: 1*/

int main(){
	scanf("%d%s",&n,s);
	for(int i=1;i<=n;i++) x[i]=s[i-1]=='o'?0:1;
	for(int k=0;k<4;k++){
		sp[1]=k&1;
		sp[2]=k>>1&1;
		for(int i=3;i<=n;i++) sp[i]=sp[i-1]^x[i-1]^sp[i-2];
		if(sp[n]^x[n]^sp[n-1]!=sp[1]||sp[1]^x[1]^sp[n]!=sp[2]) continue;
		else {
			for(int i=1;i<=n;i++) printf("%c",sp[i]?'W':'S');
			puts("");
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
const int N=3e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
int n,m;
int dp[N][N][2];
void input()
{
	n=read<int>(),m=read<int>();
}
const int mo=1e9+7;
void add(int &x,int y)
{
	x+=y;x-=(x>=mo?mo:0);
}
void work()
{
	For(i,1,n)dp[0][i][0]=1;
	dp[0][0][1]=1;
	For(i,0,m-1)For(j,0,n)For(k,0,1)if(dp[i][j][k])
	{
		if(j)add(dp[i+1][j][k|(j==1)],dp[i][j][k]);
		if(j)add(dp[i+1][j-1][k|(j==1)],dp[i][j][k]);
		if(n-j)add(dp[i+1][j][k],dp[i][j][k]);
		if(n-j)add(dp[i+1][j+1][k],dp[i][j][k]);
	}
	int ans=0;
	For(i,0,n)add(ans,dp[m][i][1]);
	write(ans,'\n');
}
int main()
{
	//file();
	input();
	work();
	return 0;
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

int arr[100001];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    int n, c, k;
    cin >> n >> c >> k;

    vector<int> t;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        t.push_back(a);
    }

    sort(t.begin(), t.end());

    int cur = 0, lowest = 0, cnt = 0;

    for(auto i : t){
        if(lowest == 0)
            lowest = i;
        if(lowest + k >= i && cur < c){
            ++cur;
        } else {
            ++cnt;
            cur = 1;
            lowest = i;
        }
    }

    if(cur >= 1)
        ++cnt;

    cout << cnt;

    return 0;
}


Measured memory_bytes: 892
#include<iostream>
	#include<string>
    int main()
    {
      std::string s,t;
      int count=0;
      std::cin>>s>>t;
      for(int i=0;i<s.length();i++)
      {
        if(s[i]!=t[i])
          count++;
      }
      
      std::cout<<count<<std::endl;
      return 0;
    }

Measured memory_bytes: 3928
n, m = map(int, input().split())
s = input()
ans = True
res = []
now = n + 1
for i in range(n, 0, -1):
    flag = 0
    if i > now:
        continue
    for j in range(max(0, i - m), i):
        if s[j] == '0':
            flag = 1
            res.append(i - j)
            now = j
            break
    if flag == 0:
        ans = False
        break
if ans == False:
    print(-1)
else:
    for i in range(len(res) - 1, -1, -1):
        print(res[i], end=' ')

Measured memory_bytes: 4848
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong(); 
    long B = sc.nextLong();
    long a = A;
    long b = B;
    long r = 1;
    for (;r!=0;){
      r = a % b;
      a = b;
      b = r;
    }
    long ans = A * B / a;
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;
	vll a(n);
	rep(i,n)cin >> a[i];

	int ans = 0;
	int maxi = 0;
	rep(i,n){
		if(a[i] < maxi)ans += maxi - a[i];
		else maxi = a[i];
	}
	cout << ans << endl;


	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://abc174.contest.atcoder.jp/tasks/abc174_b
// rm -r -f test;oj d https://atcoder.jp/contests/abc176/tasks/abc176_a

Measured memory_bytes: 4836
from itertools import permutations

n,m = map(int,input().split())
v = [set() for _ in range(n)]
for i in range(m):
    ai,bi = map(int,input().split())
    v[ai-1].add(bi-1)
    v[bi-1].add(ai-1)

ans = 0
for ci in permutations(range(n)):
    if not ci[0]:
        for i in range(n-1):
            if not (ci[i+1] in v[ci[i]]):
                break
        else:
            ans += 1
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main (){
  int n;
  cin >> n;
  n %= 10;
  if(n == 3){
	cout << "bon" << endl;
  }
  else if(n == 0 || n == 1 || n == 6 || n == 8){
    cout << "pon" << endl;
  }
  else {cout << "hon" <<endl;}
}

Measured memory_bytes: 3636
N = gets.chomp.to_i
A = [nil] + gets.chomp.split(" ").map(&:to_i)

mid_i = N / 2 + 1
result = {}
(N).downto(mid_i) do |i|
  result[i] = A[i]
end

indexes = (1..(mid_i - 1)).map do |i|
  (2..(N / i)).map { |v| v * i }
end

(mid_i - 1).downto(1) do |i|
  v = indexes[i-1].map {|j| result[j] }.inject(&:+) % 2
  result[i] = (A[i] ^ v)
end
n = result.values.inject(&:+)
puts n
puts result.select { |k, v| v == 1 }.keys.join(" ") if n > 0


Measured memory_bytes: 88324
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(i=a;i<=n;i++)
#define ll long long
#define test(a) cout << "*" << a << endl
int main(){
  int i,j;
  int N;
  string W[101];
  bool exist = true;
  
  cin >> N;
  rep(i,1,N){
    if(exist == false)
      break;
    cin >> W[i];
    rep(j,0,i-1){
      if(W[i]==W[j]){
        exist = false;
        break;
      }
    }
  }
  
  rep(i,1,N-1){
    if(exist == false)
      break;  
    if(W[i][W[i].size()-1] != W[i+1][0]){
      exist = false;
      break;
    }
  } 
  if(exist == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    double D;
    cin >> N >> D;

    int ans = 0;
    rep(i, N) {
        double X, Y;
        cin >> X >> Y;
        double d = sqrt(X * X + Y * Y);
        if (D >= d) ans++;
    }

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

Measured memory_bytes: 3704
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
using namespace std;

main(){
  int n,i,j;
  string a,str;
  while(cin >> a){

    for(i=0;i<101;i++){
      if(a[i] == '\0') break;

      else if(a[i] == '@'){
	str = a[i+1];
	n = atoi(str.c_str());
	for(j=0;j<n;j++){
	  cout << a[i+2];
	}
	i+=2;
      }

      else cout << a[i];
    }

    cout << endl;
  }
  return 0;
}

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

int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    a--;
    p.at(i)=a;
  }
  vector<int> Z(N,-1);
  vector<int> q(N);
  int b=0;
  Z.at(0)=0;
  int64_t c=1;
  q.at(0)=0;
  while(true){
    if(Z.at(p.at(b))==-1){
      Z.at(p.at(b))=c;
      q.at(c)=p.at(b);
      b=p.at(b);
      c++;
    }
    else{
      break;
    }
  }
  if(K<c){
    cout<<q.at(K)+1<<endl;
  }
  else{
    cout<<q.at((K-c)%(c-Z.at(p.at(b)))+Z.at(p.at(b)))+1<<endl;
  }
  
    
    
    
}





Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define MAX_N 100000
using namespace std;
int n;
struct Card {
	int value;
	char mark;
	bool operator!=(const Card& card) {
		return value != card.value || mark != card.mark;
	}
};
Card A[MAX_N], S[MAX_N];


int Partition(int p, int r) {
	int x = A[r].value, i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j].value <= x) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

void QuickSort(int p, int r) {
	if (p < r) {
		int q = Partition(p, r);
		QuickSort(p, q - 1);
		QuickSort(q + 1, r);
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i].mark >> A[i].value;
		S[i] = A[i];
	}
	stable_sort(S, S + n, [](const Card& l, const Card& r) { return l.value < r.value; });
	QuickSort(0, n - 1);
	bool st = true;
	for (int i = 0; i < n; i++) {
		if (A[i] != S[i]) {
			st = false;
			break;
		}
	}
	cout << (st ? "Stable" : "Not stable") << endl;
	for_each(A, A + n, [](const Card& c) {
		cout << c.mark << ' ' << c.value << endl;
	});
	return 0;
}



Measured memory_bytes: 4612
from collections import deque

s = deque()
s.extend(list(input()))
q = int(input())

reverse_status = False

for i in range(q):
  query = list(map(format, input().split()))
  if int(query[0]) == 1:
    if reverse_status:
      reverse_status = False
    else:
      reverse_status = True
  else:
    if int(query[1]) == 1:
      if reverse_status:
        s.append(query[2])
      else:
        s.appendleft(query[2])
    else:
      if reverse_status:
        s.appendleft(query[2])
      else:
        s.append(query[2])

if reverse_status:
  s.reverse()
print(''.join(s))


Measured memory_bytes: 75548
/*Writer : Md. Shafiur Rahman Dipu  */

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

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define pi 2*acos(0.00)
#define INF 2e18

long long poW(long long base, long long power) {
    long long result = 1;
    while(power > 0) {
        if(power & 1) {
            result = (result*base) ;
        }
        base = (base * base);
        power = power / 2;
    }
    return result;
}


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

const int mx = 100005;

vector<int> v[mx];
int n,m;
bool visited[mx];
int cc[mx];

int dfs(int s)
{
    //cout << s << " ";
    if(visited[s]){
        return cc[s]+1;
    }

    visited[s] = true;
    for(int i=0; i<v[s].size(); i++){
        cc[s] = max(cc[s],dfs(v[s][i]));
    }

    //cout << s << " " << cc[s] << endl;
    return cc[s]+1;

}


int main()
{
    #ifdef dipu
    //freopen("inp.txt","r",stdin);
    #endif

    cin >> n >> m;
    int x,y;
    for(int i=0; i<m; i++){
        cin >> x >> y;
        v[x].push_back(y);
    }
    memset(visited,false,sizeof visited);
    memset(cc,0,sizeof cc);
    int res = 0;
    for(int i=1; i<=n; i++){
        res = max(res,dfs(i)-1);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 8192