akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
map<int,int>mm;
int main()
{
    int flag = 0 ;
    int num = 1;
    int n;
    int a=  7 ;
    cin >> n;
    if(n%2==0){
        cout << -1 << endl;
        return 0;
    }
    while(a%n!=0){
        a=(a*10+7)%n;
        if(!mm[a])
            mm[a]++;
        else{
            flag = 1 ;
            break;
        }
        num++;
    }
    if(flag){
        cout << -1 << endl;
    }
    else
        cout << num <<endl;
    return 0;
}


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

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

    long a, b, k;
    cin >> a >> b >> k;
    if (a - k >= 0)
        a -= k;
    else if (a + b - k >= 0)
    {
        b -= k - a;
        a = 0;
    }
    else
    {
        a = 0;
        b = 0;
    }
    cout << a << ' ' << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
	string s1, s2;
	cin >> s1 >> s2;
	int cnt = 0;
	for (int i = 0; i < s1.size(); ++i) {
		if (s1[i] != s2[i])  ++cnt;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3916
use std::cmp::max;

// ref. 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:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [[usize;n];2]
    }

    let mut dp: Vec<Vec<usize>> = vec![vec![0;n+1];3];
    for i in 0..2{
        for n_ in 0..n{
            dp[i][n_+1] = max(dp[i][n_], dp[i][n_]+v[i][n_]);
            if i > 0{
                dp[i][n_+1] = max(dp[i][n_+1], dp[0][n_+1]+v[i][n_] )
            }
        };
    };
    println!("{}", dp[1][n]);
}


Measured memory_bytes: 4352
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque
import heapq
from itertools import combinations
import bisect

n=int(input())
l=[]
for i in range(n):
    l.append(list(input()))

p=0
q=0
for i in range(n):
    for j in l[i]:
        if j=='(':
            p+=1
        else:
            q+=1
if p!=q:
    print('No')
    exit()
pl=[]
ql=[]
ml=[]
for i in range(n):
    a=l[i]
    p=0
    q=0
    for j in a:
        if j=='(':
            p+=1
        else:
            q+=1
    if p>q:
        pl.append(a)
    elif p<q:
        ql.append(a)
    else:
        ml.append(a)
if pl:
    pp=[]
    for i in pl:
        d=0
        t=0
        for j in i:
            if j=='(':
                d+=1
            else:
                d-=1
            t=max(t,-d)
        pp.append([t,d])
    pp.sort(key=lambda x: x[0]*(10**6)-x[1])
    dd=0
    for a,b in pp:
        if dd<a:
            print('No')
            exit()
        dd+=b
if ml:
    pp=[]
    for i in ml:
        d=0
        t=0
        for j in i:
            if j=='(':
                d+=1
            else:
                d-=1
            t=max(t,-d)
        pp.append([t,d])
    #pp.sort(key=lambda x: x[0]*(10**6)-x[1])
    #d=0
    if not pl:
        dd=0
    for a,b in pp:
        if dd<a:
            print('No')
            exit()
        dd+=b

if ql:
    pp=[]
    for i in ql:
        d=0
        t=0
        for j in range(len(i)):
            if i[len(i)-1-j]==')':
                d+=1
            else:
                d-=1
            t=max(t,-d)
        pp.append([t,d])
    pp.sort(key=lambda x: x[0]*(10**6)-x[1])
    dd=0
    for a,b in pp:
        if dd<a:
            print('No')
            exit()
        dd+=b

if ml:
    pp=[]
    for i in ml:
        d=0
        t=0
        for j in range(len(i)):
            if i[len(i)-1-j]==')':
                d+=1
            else:
                d-=1
            t=max(t,-d)
        pp.append([t,d])
    #pp.sort(key=lambda x: x[0]*(10**6)-x[1])
    if not ql:
        dd=0
    for a,b in pp:
        if dd<a:
            print('No')
            exit()
        dd+=b

print('Yes')


Measured memory_bytes: 335524
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
using VP = vector<P>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int inf = 1e9;
constexpr ll  lnf = 1LL << 60;
constexpr int mod = 1e9+7;
template<class T> inline bool chmax(T& a, const T& b) { if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if(a>b) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}


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


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    vi H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    int ans = 0;
    int hMax = H[0];
    for (int i = 0; i < N; i++) {
        if(hMax <= H[i]) ans++;
        hMax = max(hMax, H[i]);
    }

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


Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
x=10**6
total=0
for i in range(n):
    if abs(x-a)>abs(t-h[i]*0.006-a):
        x=t-h[i]*0.006
        total=i+1
print(total)

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

const int N = 4005, M = 1e9+7;
int C[N][N];

int dp[N][N];
int st[N][N], en[N][N];

void pre() {
    for (int i=0; i<N; i++) C[i][0] = C[0][i] = 1;
    for (int i=1; i<N; i++)
        for (int j=1; j<N; j++)
            C[i][j] = (C[i-1][j] + C[i][j-1])%M;
}

int main() {
    pre();
    long long ans = 0;

    int n;
    cin>>n;

    for (int i=1; i<=n; i++) {
        int x, y;
        cin>>x>>y;
        ans -= C[x+x][y+y];

        st[N/2-x][N/2-y] ++;
        en[N/2+x][N/2+y] ++;
    }

    for (int i=1; i<N; i++) {
        for (int j=1; j<N; j++) {
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] + st[i][j])%M;
            ans = ans + 1LL * en[i][j] * dp[i][j];
        }
    }

    ans = (ans%M+M)%M;
    if (ans%2)  ans +=M;
    cout<<ans/2<<endl;
}






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

int main () {
  ll n, k, r, s, p, ans = 0;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  
  for (ll i = k-1; i < n; i++) {
    if (t[i-k] == t[i]) {
      t[i] = 'x';
    }
  }
  for (ll i = 0; i < n; i++) {
    if (t[i] == 'r') {
      ans += p;
    }
    if (t[i] == 's') {
      ans += r;
    }
    if (t[i] == 'p') {
      ans += s;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) {
      cout << "Bad" << '\n';
      return;
    }
  }
  cout << "Good" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

long double distance(pair<long double, long double> p1, pair<long double, long double> p2) {
	long double x = p1.first - p2.first;
	long double y = p1.second - p2.second;
	return sqrt(x*x + y*y);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	 
	int n;
	cin >> n;
	vector<pair<long double, long double>> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i].first >> v[i].second;
	}
	vector<int> perm(n);
	for(int i = 0; i < n; i++) {
		perm[i] = i;
	}
	long double sum = 0;
	long double count = 0;
	do {	
		for(int i = 1; i < perm.size(); i++) {
			sum += distance(v[perm[i]], v[perm[i-1]]);
		}
		count++;
	} while(next_permutation(perm.begin(), perm.end()));
	cout << fixed << setprecision(12) << sum/count << '\n';

	return 0;
}

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

constexpr int MAX_LEN = 6;
constexpr int MAX_N = 40;

struct edge {
	int to;
	string cost;
	edge(int to_, const string &cost_):to(to_), cost(cost_) {}
	edge(int to_, string &&cost_):to(to_), cost(move(cost_)) {}
};

void dfs(int v, const vector<vector<int>> &G, bitset<MAX_N> &visited) {
	visited[v] = true;
	for(const auto &to : G[v]) {
		if(!visited[to]) dfs(to, G, visited);
	}
}

string dijkstra(int s, int g, const vector<vector<edge>> &G, const bitset<MAX_N> &reach) {
	if(!reach[s]) return "NO";

	typedef pair<string, int> state;

	const int n = G.size();
	const int limit = n * MAX_LEN;

	vector<vector<string>> dist(n, vector<string>(limit + MAX_LEN + 1, "{"));
	dist[s][0] = "";

	priority_queue<state, vector<state>, greater<state>> que;
	que.push({"", s});

	while(!que.empty()) {
		const string d = que.top().first;
		const int v = que.top().second;
		const int l = d.size();
		que.pop();

		if(v == g) return d;
		if(l > limit) return "NO";
		if(dist[v][l] > d) continue;

		for(const auto &e : G[v]) {
			if(!reach[e.to]) continue;

			const string next_dist = d + e.cost;
			const int next_len = next_dist.size();
			if(dist[e.to][next_len] > next_dist) {
				que.push({next_dist, e.to});
				dist[e.to][next_len] = move(next_dist);
			}
		}
	}

	return "NO";
}

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

	for(int n, m, s, g; cin >> n >> m >> s >> g && n;) {
		vector<vector<edge>> G(n);
		vector<vector<int>> rG(n);

		while(m--) {
			int x, y;

			string lab;
			cin >> x >> y >> lab;
			G[x].emplace_back(y, move(lab));
			rG[y].emplace_back(x);
		}

		bitset<MAX_N> visited;
		dfs(g, rG, visited);
		cout << dijkstra(s, g, G, visited) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;

int n,m;
string s;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1=freopen("in","r",stdin);
    //stream2=freopen("out","w",stdout);
    if(stream1==NULL)return 0;
    //if(stream2==NULL)return 0;
#endif
    cin>>n;
    cout<<n/3<<endl;
#ifdef LOCAL_DEFINE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    fclose(stream1);
    //fclose(stream2);
#endif
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#define fin stdin
#define fout stdout

int main(){
    char ch = fgetc(fin);
    int n = 0, s = 0, e = 0, w = 0;
    while(ch != '\n'){
        if(ch == 'N') n = 1;
        else if(ch == 'S') s = 1;
        else if(ch == 'E') e = 1;
        else w = 1;
        ch = fgetc(fin);
    }

    if((n + s) % 2 == 0 && (e + w) % 2 == 0)
        fprintf(fout, "Yes\n");
    else fprintf(fout, "No\n");

    return 0;
}


Measured memory_bytes: 128
/* f */
#include <bits/stdc++.h>
#define N 3005

using namespace std;

const int mod = 998244353;

int n, S;
int a[N], f[N];

inline int read() {
	int x = 0; bool neg = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (neg = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return neg ? -x : x;
}

int main() {
	scanf("%d %d", &n, &S);
	for(int i = 1; i <= n; ++i)
		a[i] = read();
	
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(a[i] > S) continue;
		else if(a[i] == S) {
			ans = (ans + 1LL * i * (n - i + 1)) % mod;
		} else {
			ans = (ans + 1LL * f[S - a[i]] * (n - i + 1)) % mod;
			for(int j = S; j > a[i]; --j)
				(f[j] += f[j - a[i]]) %= mod;
			f[a[i]] = (f[a[i]] + i) % mod;
		}
	}
	
	printf("%d\n", ans);
	return 0;
}

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


int main(){
    int n;
    cin >> n;
    vector<int>dp(3);
    // dp[0] = max({dp[0],dp[1],dp[2]});
    for(int day = 0; day< n ;day++){
        vector<int> new_dp(3);
        vector<int> c(3);
        for(int i=0 ; i< 3 ;++i){
            scanf("%d", &c[i]);
        }
        for(int i= 0; i< 3; i++){
            for(int j= 0; j<3; j++){
                if(j != i){
                    new_dp[j] = max(new_dp[j], dp[i] + c[j]);
                }
            }
        }
        dp = new_dp;
       
    }

    cout << max({dp[0], dp[1], dp[2]});





        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1LL << 31;

struct UF{
  const int N = 1e5+10;
  vector<int> par;
  vector<int> depth;
  vector<int> diff;

  void init(int n){
    par.resize(n); depth.resize(n); diff.resize(n);
    for(int i = 0; i < n; i++){
      par[i] = i;
      depth[i] = 0;
      diff[i] = 0;
    }
  }

  //木の根を求める
  int find(int x){
    if(par[x] == x){
      return x;
    }
    else {
      int r = find(par[x]);
      diff[x] += diff[par[x]];
      return par[x] = r;
    }
  }

  int weight(int x){
    find(x); //経路圧縮
    return diff[x];
  }

  //xとyの属する集合を併合
  void unite(int x,int y,int w){
    w += weight(x) - weight(y);
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(depth[x] < depth[y]) swap(x,y),w = -w;
    if(depth[x] == depth[y]) depth[x]++;
    par[y] = x;
    diff[y] = w;
  }
}uf;

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

  int n,q; cin >> n >> q;
  uf.init(n);
  vector<int> v;
  for(int i = 0; i < q; i++){
    int k,x,y,z; cin >> k;
    if(k){
      cin >> x >> y;
      if(uf.find(x) != uf.find(y)) v.push_back(INF);
      else v.push_back(uf.weight(y) - uf.weight(x));
    }
    else {
      cin >> x >> y >> z;
      uf.unite(x,y,z);
    }
  }

  for(auto p : v){
    if(p == INF) cout << '?' << endl;
    else cout << p << endl;
  }

  return 0;
}



Measured memory_bytes: 6312
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int N, X[3009], Y[3009]; char c[3009], p[3009][3009]; vector<int>x, y;
set<int>DX[3009], DY[3009];

void dels(int px, int py) {
	DX[px].erase(py);
	DY[py].erase(px);
}

int solve(int pos) {
	for (int i = 0; i < N; i++) { DX[i].clear(); DY[i].clear(); }
	for (int i = 1; i <= N; i++) { DX[X[i]].insert(Y[i]); DY[Y[i]].insert(X[i]); }

	int cnt = 0, vx = X[pos], vy = Y[pos]; char dir = c[pos];

	while (true) {
		dels(vx, vy); dir = p[vx][vy]; cnt++;
		if (dir == '<' || dir == '>') {
			auto itr = DX[vx].lower_bound(vy);
			if (dir == '<') {
				if (itr == DX[vx].begin()) break;
				itr--;
			}
			if (itr == DX[vx].end()) break;
			vy = *itr;
		}
		else {
			auto itr = DY[vy].lower_bound(vx);
			if (dir == '^') {
				if (itr == DY[vy].begin()) break;
				itr--;
			}
			if (itr == DY[vy].end()) break;
			vx = *itr;
		}
	}
	return cnt;
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> c[i]; swap(X[i], Y[i]);
		x.push_back(X[i]);
		y.push_back(Y[i]);
	}
	sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
	sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end());
	
	for (int i = 1; i <= N; i++) {
		X[i] = lower_bound(x.begin(), x.end(), X[i]) - x.begin();
		Y[i] = lower_bound(y.begin(), y.end(), Y[i]) - y.begin();
		p[X[i]][Y[i]] = c[i];
	}
	int maxn = 0;
	for (int i = 1; i <= N; i++) {
		maxn = max(maxn, solve(i));
	}
	cout << maxn << endl;
	return 0;
}


Measured memory_bytes: 8044
if __name__ == "__main__":
    N = int(input())
    ryokan= input().split(" ")
    total=1
    for x in range(1,N):
        flag=True
        for y in range(x):
            if int(ryokan[x])<int(ryokan[y]):
                flag=False
                break
        if flag:
            total+=1
                
    print(total)

Measured memory_bytes: 3060
import sys
N = int(input())
A = list(map(int, input().split()))
ans_lis = [1]

if 1 not in A:
    print(-1)
    sys.exit()

ans = 1
for i in range(N):
    if A[i] != 1:
        ans = ans + 1
    else:
        A = A[ans:len(A)]
        break
         
number = 1

for i in A:
    if number == (i-1) :
        ans_lis.append(i)
        number = i

print(N-(len(ans_lis)))

Measured memory_bytes: 26268
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;



bool card[12];
int a,b,c;

int main(){
	while(cin>>a>>b>>c){
		rep(i,12) card[i]=false;
		card[a]=card[b]=card[c]=true;
		rep(i,12){
			//cout<<i<<" "<<card[i]<<endl;
		}
		int sum=a+b;
		int co=0;
		for(int i=1;i<11;i++){
			if(!card[i]&&sum+i<=20){
				//cout<<i<<endl;
				co++;
			}
			//else if(sum+i>20) break;
		}
		//double ka=(double) co/17;
		//cout<<co<<endl;
		if(co>=4) cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}

Measured memory_bytes: 1120
using System;
class Program
{
    static void Main(string[] args)
    {
        // 整数の入力
        ulong K = ulong.Parse(Console.ReadLine());

        Console.WriteLine(50);

        string s = "";
        for (int i=0;i<50;i++){
            if (i != 0) s += " ";
            ulong a = (49 - (ulong)i +((K+49 -(ulong)i) / 50));
                s += a;
        }
         Console.WriteLine(s);


    }
}




Measured memory_bytes: 13140
import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();

		Arrays.sort(a);
		
		System.out.println(a[0]+" "+a[1]+" "+a[2]);
		
	}

}

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

using namespace std;

int main() {

	vector<int> dice(7, 0);
	vector<int> newdice(7, 0);
	cin >> dice[1] >> dice[2] >> dice[3]>> dice[4] >> dice[5] >> dice[6];

	string str;
	cin >> str;

	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'N') {
			newdice[1] = dice[2];
			newdice[2] = dice[6];
			newdice[3] = dice[3];
			newdice[4] = dice[4];
			newdice[5] = dice[1];
			newdice[6] = dice[5];
		}
		else if (str[i] == 'S') {
			newdice[1] = dice[5];
			newdice[2] = dice[1];
			newdice[3] = dice[3];
			newdice[4] = dice[4];
			newdice[5] = dice[6];
			newdice[6] = dice[2];
		}
		else if (str[i] == 'E') {
			newdice[1] = dice[4];
			newdice[2] = dice[2];
			newdice[3] = dice[1];
			newdice[4] = dice[6];
			newdice[5] = dice[5];
			newdice[6] = dice[3];
		}
		else if (str[i] == 'W') {
			newdice[1] = dice[3];
			newdice[2] = dice[2];
			newdice[3] = dice[6];
			newdice[4] = dice[1];
			newdice[5] = dice[5];
			newdice[6] = dice[4
];
		}

		for (int j = 1; j <= 6; j++) {
			dice[j] = newdice[j];
		}

	}

	cout << dice[1] << endl;
}


Measured memory_bytes: 3204
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        if (s.matches("^A?KIHA?BA?RA?$")) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23124
require 'matrix'
include Math

n = gets.to_i
rot = ->(v, θ) {
  t = θ / 180.0 * PI
  Matrix[[cos(t), -sin(t)], [sin(t), cos(t)]] * v
}
result = []

koch_curve = ->(p1, p2, level) {
  if level == n
    result << p1
    result << p2
  else
    l1 = (p2 - p1) / 3
    l2 = rot.(l1, 60)
    koch_curve.(p1, p3 = p1 + l1, level + 1)
    koch_curve.(p3, p4 = p3 + l2, level + 1)
    koch_curve.(p4, p5 = p3 + l1, level + 1)
    koch_curve.(p5, p2, level + 1)
  end
}

koch_curve.(Vector[0.0, 0.0], Vector[100.0, 0.0], 0)
([result[0]] + result + [result[-1]]).each_slice(2) do |a, _|
  printf "%.8f %.8f\n", a[0], a[1]
end


Measured memory_bytes: 7480
import sys

def main():
    line = sys.stdin.readline()
    n = int(line.rstrip())
    f = [None for i in range(n)]
    p = [None for i in range(n)]
    for i in range(n):
        line = sys.stdin.readline()
        f[i] = getFn([int(x) for x in line.rstrip().split(' ')])
        # print('f', i, f[i])
    for i in range(n):
        line = sys.stdin.readline()
        p[i] = [int(x) for x in line.rstrip().split(' ')]
    vMax = None
    for t in range(1, 1024):
        s = 0
        for i in range(n):
            common = countBit(f[i] & t)
            s += p[i][common]
        if vMax is None or vMax < s:
            vMax = s
    print(vMax)

def getFn(f):
    s = 0
    for b in f:
        s = (s << 1) | b
    return s

def countBit(c):
    s = 0
    while c > 0:
        if c & 1 == 1:
            s += 1
        c >>= 1
    return s

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   const compare = (a, b)=>{ 
   return a - b;  
   }
   xs.sort(compare);
   if(xs[0]==1 && xs[1]==2){
   console.log(3);
   }else if(xs[0]==2 && xs[1]==3){
   console.log(1);
   }else{
   console.log(2);
   }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 21064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

vector<vector<pair<int, long long int> > > tree(100001);
vector<long long int> pathlenfromk(100001, -1);

void dijkstra(int s)
{
	priority_queue<pair<long long int, int> > qu;
	qu.push(make_pair(0, s));
	while(!qu.empty()){
		long long int nowlen = -(qu.top()).first;
		int now = (qu.top()).second;
		qu.pop();
		if(pathlenfromk[now] >= 0) continue;
		pathlenfromk[now] = nowlen;
		for(int i = 0; i < tree[now].size(); i++){
			int next = tree[now][i].first;
			long long int c = tree[now][i].second;
			if(pathlenfromk[next] >= 0) continue;
			qu.push(make_pair(-(nowlen + c), next));
		}
	}
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		int a, b;
		long long int c;
		cin >> a >> b >> c;
		tree[a].push_back(make_pair(b, c));
		tree[b].push_back(make_pair(a, c));
	}
	int q, k;
	cin >> q >> k;
	dijkstra(k);
	for(int i = 0; i < q; i++){
		int x, y;
		cin >> x >> y;
		cout << pathlenfromk[x] + pathlenfromk[y] << endl;
	}
	return 0;
}

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

int main() {
  string N;
  cin >> N;
 if(N[0] == N[1] && N[1] == N[2] || N[1] == N[2] && N[2] == N[3]){
    cout << "Yes" << endl;
  }else{
    cout << " No" << endl;
  }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#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 ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int h,w;
char s[22][22];

ll s_y, s_x, g_y, g_x;  // スタート，ゴールの座標
ll y, x, depth;  // キューから取り出した座標
//vector<string> vec;  // 座標を受け取る配列

struct Corr {
    ll y;
    ll x;
    ll depth;
};
//char s[50][50]={};
queue<Corr> q;
ll answer=-1;
 
int y_vec[] = {0, 0, -1, +1};  // 進む方向の簡便化，テクニックとして覚えておく．
int x_vec[] = {-1, +1, 0, 0};  // ループで回すことで上下左右に移動できるようになっている
 
ll bfs() {
    while (!q.empty()) {
        Corr now = q.front(); q.pop();  // キューの先頭を取り出す
        y = now.y, x = now.x, depth = now.depth;  // 行，列が y, x になっているので注意
        if(s[y][x]=='.')s[y][x]='x';
        answer = max(depth,answer);

        // 停止条件：現在の座標がゴールなら深さを返す
        //if (y == g_y && x == g_x) return depth;
 
        // 上下左右 4 方向を探索．進むことができればキューに格納する．
        for (ll i = 0; i < 4; ++i) {
            Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
            if (s[next.y][next.x] == '.') {
                s[next.y][next.x] = 'x';  // 同じ場所を探索しないようにする
                q.push(next);
            }
        }
    }
    return 0;
}
int main(){
    cin >> h >> w;
    char S[22][22];
    REP(i,22){
        REP(j,22){
            S[i][j]='#';
        }
    }
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            cin >> S[i][j];
        }
    }

    

    FOR(i,1,h+1){
        FOR(j,1,w+1){
            REP(k,22){
                REP(t,22){
                    s[k][t] = S[k][t];
                }
            }

            if(s[i][j]=='#')continue;
            Corr start= {i,j,0};
            q.push(start);
            int x = bfs();
            //cout << i << " " << j << " " << x << endl;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Console;

class Program
{
    public static void Main()
    {
        int N = 'z'-'a'+1;

        string s = ReadLine();
        string t = ReadLine();
        string ss = s + s;

        int [,] lut = new int[s.Length, N];
        for (char c = 'a'; c <= 'z'; c++)
        {
            int j = 0;
            for (int i = ss.Length - 1; i >= 0; i--)
            {
                if (ss[i] == c)
                {
                    j = 1;
                }
                else
                {
                    if (j > 0){ j++; }
                }
                if (i < s.Length){ lut[i, c-'a'] = j; }
            }
        }

        long ct = 0;
        for(int i = 0; i < t.Length; i++)
        {
            char c = t[i];
            int k = lut[ct % s.Length, c-'a'];
            if (k == 0){ WriteLine(-1); return; }
            ct += k;
        }
        WriteLine(ct);
    }
}

Measured memory_bytes: 22240
N = int(input())

# Nがk角形の対角線の本数+kであればYes、そうでなければNo(のはず・・・)
yess = {1:2}
for i in range(3, 500):
  n = i * (i-3) // 2 + i
  yess[n] = i

if N not in yess:
  print('No')
  exit()

print('Yes')
if N == 1:
  print(2)
  print(1, 1)
  print(1, 1)
  exit()

# k個の頂点の総当たり
k = yess[N]
ss = [set() for _ in range(k)]
n = 1
for i in range(k):
  for j in range(i+1, k):
    ss[i].add(n)
    ss[j].add(n)
    n += 1

print(k)
for s in ss:
  print(len(s), ' '.join(map(str, s)))

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

int main(){
  string S;
  int N;
  cin >> N;
  cin>>S;
  int count=0;
  while(S.size()){
    if(S.substr(0,3)=="ABC"){
      S=S.substr(3);
      count++;
      continue;
    }
    S=S.substr(1);
  }
  
  cout << count << endl;
}

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

int main() {
  int a,b,c,d=0;
  cin>>a>>b>>c>>d;
  bool ans=false;
  
  while(a>0&&b>0){
    c-=b;
    if(c<=0){
      ans=true;
      break;
    }
    a-=d;
    if(a<=0){
      ans=false;
      break;
    }
  }
  
  if(ans){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>

int roads[50];

int main() {
	int n, m;
	std::cin >> n >> m;
	
	for (int i = 0; i < m; ++i) {
		int a, b;
		std::cin >> a >> b;
		--a, --b;

		++roads[a];
		++roads[b];
	}

	for (int i = 0; i < n; ++i)
		std::cout << roads[i] << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[810];
int main(){
    int n;
    cin>>n;
    for(int j=0;j<n*2;j++){
        cin>>a[j];
    }
    int sum=0;
    sort(a,a+n*2);
    reverse(a,a+n*2);
    for(int i=1;i<n*2;i+=2){
        sum+=a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import sys

def resolve(buget,num):
    return ((((2*buget)/num)-num+1)/2)

for buget in sys.stdin:
    buget = int(buget)
    if buget == 0 :
        break

    num = 1
    answer_floor = 1
    answer_num = 1
    answer = 0
    while (num*num)/2 < buget :
        #num を増やしていって、aの解が整数になるかをチェックする
        answer = resolve(buget,num)
        if answer.is_integer():
            answer_floor = answer
            answer_num = num
        num = num + 1
    print(str(int(answer_floor)) + " " + str(answer_num))



Measured memory_bytes: 5728
n,k = map(int,input().split())
a = list(map(int, input().split()))
ans = float("inf")
for i in range(0,n-k+1):
    if a[i] <= 0 and a[i+k-1] <= 0:
        ans = min(ans,abs(a[i]))
    elif a[i] <= 0 and 0 <= a[i+k-1]:
        ans = min(ans,2*abs(a[i])+a[i+k-1],abs(a[i])+2*a[i+k-1])
    elif 0 <= a[i]:
        ans = min(ans,a[i+k-1])
if ans == float("inf"):
    print(0)
else:
    print(ans)


Measured memory_bytes: 14480
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

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

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int n;
	cin>>n;
	int p[20]={};
	fori(n){cin>>p[i];}
	sort(p,p+n,greater<int>());
	int c=0;
	c+=p[0]/2;
	fori(n-1){
		c+=p[i+1];
	}
	cout<<c;
}

Measured memory_bytes: 256
n = int(input())
s = []
B_A = []
__A = []
B__ = []
abin = []

for i in range(n):
    si = input()
    s.append(si)
    c = 0
    if si[0] == "B":
        if si[len(si)-1] == "A":
            B_A.append(i)
        else:
            B__.append(i)
    else:
        if si[len(si)-1] == "A":
            __A.append(i)
    for j in range(1,len(si)):
        if si[j]== "B" and si[j-1] == "A":
            c += 1
    abin.append(c)

a = len(__A)
b = len(B__)
ab = len(B_A)
ans = sum(abin)

if ab > 0:
    renketu = ab
    if a > 0:
        renketu += 1
        a -= 1
    if b > 0:
        renketu += 1
        b -= 1
    renketu -= 1
else:
    renketu = 0

renketu += min(a,b)
    

print(ans + renketu)


Measured memory_bytes: 4340
N = int(input())
S = input()
h = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
m = {}
for i in range(26):
  c = h[i]
  m[c] = i
L2 = []
for c in S:
  i = m[c]
  i2 = (i+N)%26
  c2 = h[i2]
  L2.append(c2)
print("".join(L2))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
#define test int testcase; cin>>testcase; while(testcase--)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deci(n) fixed << setprecision(n)
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define F first
#define S second
#define mp make_pair
#define pb push_back
int main()
{
    ll k,a,b,flag=0;
    cin>>k;
    cin>>a>>b;
    REP(i,a,b)
    {
        if(i%k==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"OK"<<endl;
    else
    cout<<"NG"<<endl;
}

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

int main(void){
	int n;

	cin >> n;

	for (int i = 1; i < n + 1; i++){
		if (i % 3 == 0){
			cout << " " << i;
		}
		else{
			int x = i;
			while (x != 0){
				if (x % 10 == 3){
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1164
from collections import deque

n,m = map(int,input().split())
g = [list() for _ in range(n+1)]
en = [0]*(n+1)
for _ in range(m):
  u,v = map(int,input().split())
  g[u].append(v)
  en[v] += 1
q = deque(i for i in range(1,n+1) if en[i] == 0)
done = list()
while q:
  v = q.popleft()
  for x in g[v]:
    en[x] -= 1
    if not en[x]:
      q.append(x)
  done.append(v)
print(-1 if len(done) == n else 0)

Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
	ios::sync_with_stdio(false);

	ll n , a, b;
	cin >> n >> a >> b;
	vector<ll> x;
	ll ans = 0;
	ll old; cin >> old;
	for(ll i = 1; i < n; i++)
	{
		ll t;
		cin >> t;
		if ((t-old) * a > b)
		{
			ans += b;
		}
		else
		{
			ans += ((t-old) * a);
		}
		old = t;
	}
	
	cout << ans << endl;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  double a[10];
  while (cin >> a[0]){
    double sum = a[0];
    FOR(i, 1, 10){
      a[i] = 0;
      if (i % 2 == 1) a[i] = a[i - 1] * 2;
      else a[i] = a[i - 1] / 3;
      sum += a[i];
    }
    printf("%.8f\n", sum);
  }
}

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i = 0; i < n; i++){
   cin >> a[i];
   b[i] = a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for(int i = 0; i < n; i++){
    if(a[0] == b[i]) cout << a[1] << endl;
    else{
      cout << a[0] << endl;
    }
  }
}


Measured memory_bytes: 3200
#!/usr/bin/env python3
# 整数の入力
n = int(input())

#素因数分解
def PrimeFactorization(n):
    ret = []
    for i in range(2, int(n ** 0.5)+1):
        if n % i != 0:
            continue
        
        exp = 0
        while n % i == 0:
            exp += 1
            ret.append(i**exp)
            n //= i

    if n != 1:
        ret.append(n)

    ret.sort()
    return ret

a = PrimeFactorization(n)
ans = 0
for i in a:
    if n % i == 0:
        ans += 1
        n //= i

print(ans)

Measured memory_bytes: 9484
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
string s;

int main(){
    cin >> n;
    int cnt = 0;
    int BA = 0, _A = 0, B_ = 0;
    REP(i, n){
        cin >> s;
        REP(j, (int)s.size() - 1){
            if(s.substr(j, 2) == "AB")cnt++;
        }
        if(s[0] == 'B' && s[(int)s.size() - 1] == 'A')BA++;
        else if(s[0] == 'B') B_++;
        else if(s[(int)s.size() - 1] == 'A')_A++;
    }
    cout << cnt + (BA > 0 ? BA - 1 : 0) + (BA > 0 ? (_A > 0) + (B_ > 0) : 0) + max(0, (BA == 0 ? min(_A, B_) : min(_A - 1, B_ - 1))) << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] A = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                A[i] = sc.nextInt();
            }

            int[] C = new int[N + 1];

            long ans = 1;

            for (int i = 1; i <= N; i++) {
                if (A[i] > 0) {
                    int c = C[A[i] - 1] - C[A[i]];

                    ans = ans * c % 1000000007L;
                }

                C[A[i]]++;
            }

            if ( C[0] > 3) {
                System.out.println(0);
                return;
            }

            if (C[0] == 1) {
                ans = ans * 3 % 1000000007L;
            } else {
                ans = ans * 6 % 1000000007L;
            }

            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 50456
n, a, b = gets.split.map(&:to_i)
h = n.times.map {gets.to_i}.sort_by{|e| -e}

l = 1
r = (h[0] + b - 1) / b

while l != r
    m = (l + r) / 2

    t = 0
    h.each do |e|
        break if e <= b * m
        t += (e - m * b + a - b - 1) / (a - b)
        break if t > m
    end

    if t > m
        l = m + 1
    else
        r = m
    end
end

p l

Measured memory_bytes: 18368
#include <iostream>
#include <string>
#include <deque>
using namespace std;

int main() {

    int W, H;

	cin >> H >> W;
    int dist[H][W];
    deque<int> xvec;
    deque<int> yvec;

	for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < W; ++j) {
            if (s[j] == '#') {
                dist[i][j] = 0;
                xvec.push_back(j);
                yvec.push_back(i);
            } else {
                dist[i][j] = -1;
            }
            //cout << dist[i][j] << endl;
        }
	}

	int max_dist_count = 0;
    while (xvec.size() != 0) {
        int y = yvec.front();
        yvec.pop_front();
        int x = xvec.front();
        xvec.pop_front();
        int dist_count = dist[y][x] + 1;
        if (x < W - 1 && dist[y][x+1] == -1) {
            dist[y][x+1] = dist_count;
            yvec.push_back(y);
            xvec.push_back(x+1);
            max_dist_count = dist_count;
        }
        if (y < H - 1 && dist[y+1][x] == -1) {
            dist[y+1][x] = dist_count;
            yvec.push_back(y+1);
            xvec.push_back(x);
            max_dist_count = dist_count;
        }
        if (0 < x && dist[y][x-1] == -1) {
            dist[y][x-1] = dist_count;
            yvec.push_back(y);
            xvec.push_back(x-1);
            max_dist_count = dist_count;
        }
        if (0 < y && dist[y-1][x] == -1) {
            dist[y-1][x] = dist_count;
            yvec.push_back(y-1);
            xvec.push_back(x);
            max_dist_count = dist_count;
        }
    }

	cout << max_dist_count;
}

Measured memory_bytes: 12416
import sys
x,n = map(int,input().split())
l = list(map(int,input().split()))
not_l,ans = [],[]
if not x in l:
	print(x)
	sys.exit()
l = sorted(l)
for i in range(0,max(l)+3):
	if not i in l:
		not_l.append(i)
for j in range(len(not_l)):
	ans.append([not_l[j],abs(not_l[j]-x)])
ans.sort(key=lambda x:x[1])
print(ans[0][0])

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  double m=0;
  vector<double> x(n);
  for(int i=0;i<n;i++){
    cin >> x.at(i);
    double y=1/x.at(i);
    m += y;
  }
  cout << 1/m << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
ll ans;
void check(ll i)
{
    ll r = ceil(n / i);
    ll l = floor(n / (i + 1));
    while (l < r)
    {
        ll m = (l + r) / 2;
        if (i == n % m)
        {
            ans += m;
            return;
        }
        if (i < n % m)
        {
            l = m + 1;
        }
        else
        {
            r = m - 1;
        }
    }
}

int main()
{
    cin >> n;
    for (ll i = 1; i < ceil(sqrt(n)); i++)
    {
        check(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = s[k-1]-'A'+'a';
    cout << s << endl;
    return 0;
}




Measured memory_bytes: 256
from collections import deque
n,m = map(int,input().split())
g = [list() for _ in range(n+1)]
a,b = map(int,input().split())
l,r = a,b
s = set([a,b])
q = deque()
q.append(a)
q.append(b)
g[a].append(b)
g[b].append(a)
for _ in range(m-1):
  a,b = map(int,input().split())
  g[a].append(b)
  g[b].append(a)
f = 1
while f:
  f = 0
  for x in g[l]:
    if x in s:
      continue
    q.appendleft(x)
    l = x
    s.add(x)
    f = 1
    break
f = 1
while f:
  f = 0
  for x in g[r]:
    if x in s:
      continue
    q.append(x)
    r = x
    s.add(x)
    f = 1
    break
print(len(q))
print(" ".join(map(str,q))) 

Measured memory_bytes: 33676
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    string s=stin();
    ll n=s.length();
    string t="";
    rep(i,n){
        if(s[i]!='x')t+=s[i];
    }
    rep(i,t.length()/2){
        if(t[i]!=t[t.length()-1-i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    int ans=0;
        ll l=0,r=n-1;
        int id=0;
        while(id<=t.length()/2){
            int cnt_l=0,cnt_r=0;
            while(s[l]=='x'){
                cnt_l++;
                l++;
            }
            while(s[r]=='x'){
                cnt_r++;
                r--;
            }
            ans+=abs(cnt_r-cnt_l);
            l++;
            r--;
            id++;
          if(t.length()%2==0&id==t.length()/2)break;
       }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

def main():
	N = int(input())
	S = input().rstrip()
	T = input().rstrip()

	#N,A,B = map(int,input().split())
	
	for i in range(N):
		if S[i:]==T[:N-i]:
			res = N+i
			break
	else:
		res = 2*N
	
	print(res)
	
main()


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

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define UNIQUE(v) do{ (v).erase( unique(begin(v), end(v)), end(v) ); } while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int main() {
	ios_base::sync_with_stdio(false);
	int R, G, B, N; cin >> R >> G >> B >> N;
	ll ans = 0;
	repr(r, 0, 3000) repr(g, 0, 3000) {
		int rem = N - r * R - g * G;
		if (rem < 0) continue;
		if (rem % B == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import math
a,b,c = map(int,input().split())
S = []
S += a*b*math.sin(math.radians(c))/2,
S += math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(c))) + a + b,
S += 2*S[0]/a,
print(*S, sep = "\n")


Measured memory_bytes: 5716
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

int main()
{
        cin>>N>>M>>K>>X>>Y;
        Int ans=1e13;
        for(int i=0;i<=100000;++i){
            Int As=max(0LL,X-i);
            Int Bs=max(0LL,Y-i);
            ans=min(ans,i*2*K+As*N+Bs*M);
        }
        cout<<ans<<"\n";
}

Measured memory_bytes: 27064