akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
	int k, s;
	int i, j, ans = 0;
	cin >> k >> s;
	for(i = 0; i <= k; ++i){
		for(j = 0; j <= k; ++j){
			int tmp = s - i - j;
			if(tmp <= k && tmp >= 0) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n[] = sc.nextLine().split("");
        int num[] = new int[4];

        for(int i=0; i<4; i++){
            num[i] = Integer.parseInt(n[i]);
        }

        for(int i=0; i<8; i++){
            int sum = num[0];
            String s = String.valueOf(num[0]);
            for(int j=0; j<3; j++){
                if((1&i>>j)==1){
                    sum += num[j+1];
                    s += "+" + num[j+1];
                }else{
                    sum -= num[j+1];
                    s += "-" + num[j+1];
                }
            }
            if(sum == 7){
                System.out.println(s + "=7");
                return;
            }
        }
    }
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> ip(N);
    for(unsigned long i{0}, p; i < N; ++i){
        cin >> p;
        ip[--p] = i;
    }
    unsigned long ans{0}, prev{N}, tmp{0};
    for(const auto& i : ip){
        if(i < prev)tmp = 0;
        prev = i;
        ans = max(ans, ++tmp);
    }
    cout << N - ans << endl;
    return 0;
}

Measured memory_bytes: 4836
package main

import "fmt"

func main() {
	var S, T string
	fmt.Scan(&S, &T)
	for i := 0; i < len(S); i++ {
		if T == S[i:]+S[:i] {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

bool comp(pair<long long,long long> a,pair<long long,long long> b){
    return a.first<b.first;
}
int main() {
  long long n , c;
  cin >> n >> c;
  vector<pair<long long,long long>>v ;
  for(long long i=0;i<n;i++){
      long long x,y;
    cin>>x>>y;
    v.push_back({x,y});
  }
  sort(v.begin(),v.end(),comp);
  long long dp[n][c+1];
  long long w[n],val[n];
  for(long long i=0;i<n;i++){
      w[i] = v[i].first;
      val[i] = v[i].second;
  }
  for(long long j=0;j<=c;j++){
      if(w[0]<=j)
        dp[0][j] = val[0];
      else
        dp[0][j] = 0;
  }
  
  for(long long i=1;i<n;i++){
    for(long long j=0;j<=c;j++){
      
      if(w[i] <= j){
        dp[i][j] = max(dp[i-1][j] , dp[i-1][j-w[i]] +val[i]);
    	
      }else{
        dp[i][j] = dp[i-1][j];
    }
    }
  }
  cout<<dp[n-1][c]<<endl;
  
    return 0;
}

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

#define 中心() main()
#define 返 return
#define 入力(a) cin >> a
#define 出力(a) cout << a << endl
#define 再帰(s,t) for(整数 s = 0; s < 整数(t); s += 1)
#define 間帰(s,t,u) for(整数 s = t; s < 整数(u); s += 1)
#define 如果(a) if(a)
#define 場合(a) while(a)
#define 脱出 break
#define 真 true
#define 定数 const
#define 和 +
#define 差 -
#define 積 *
#define 余 %
#define 且 &&
#define 又 ||
#define 是 =
#define 是不是 ==
#define 不是 !=
#define 是大 >
#define 是小 <
#define 是以上 >=
#define 是以下 <=
#define 他 else
#define 測長(a) a.length()

using namespace std;

typedef int 整;
typedef void 無;
typedef long long 整数;
typedef vector<整数> 整数配列;
typedef vector<整数配列> 二次元整数配列;
typedef string 文字列;

整数 大(整数 a, 整数 b){返 max(a,b);}
整数 小(整数 a, 整数 b){返 min(a,b);}

文字列 文字;
整数 文字長;

無 入力関数()
{
    入力(文字);
}

無 解()
{
    文字長 是 測長(文字); 
    再帰(s,文字長)
    {
        如果(文字[s] 是不是 '1')
        {
            文字[s] 是 '9';
        }
        他
        {
            文字[s] 是 '1';
        }
    }
    
    出力(文字);
}

整 中心()
{
    入力関数();
    解();
    返 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
struct UnionFind{
    int n;
    set<int> dame;
    vi p;
    vi use;
    UnionFind(int N):n(N){
        p.resize(n);
        use.resize(n);
    	iota(all(p),0);
    	rep(i,n){
    	    int tmp;
    	    cin>>tmp;
    	    unite(i,tmp+i);
    	}
    }
    void unite(int a, int b){int c=root(a),d=root(b); if(c!=d) p[c]=d; else if(a!=b) dame.insert(root(a));}
    int root(int a){return p[a]=(p[a]==a?a:root(p[a]));}
    bool same(int a, int b){return root(a)==root(b);}
    void useable(){
        set<int> tmp;
        for(auto i :dame)tmp.insert(root(i));
        dame=tmp;
        rep(i,n){
            use[i]=dame.find(root(i))==dame.end();
        }
    }
};
int main(){
	int n;
	cin>>n;
	UnionFind uf(n);
	//rep(i,n)cout<<uf.p[i]<<",";cout<<endl;
	uf.useable();
    //for(auto i :uf.use)cout<<i<<",";cout<<endl;
    int i=1;
    vvi dp(2,vi(n,0));
    dp[0][0]=1;
    while(1){
        fill(all(dp[i%2]),0);
        rep(j,n){
            if(dp[1-i%2][j]){
                range(d,1,7){
                    if(j+d>=n)break;
                    if(uf.use[j+d]){
                        dp[i%2][uf.root(j+d)]=1;
                    }
                }
            }
        }
        if(dp[i%2][n-1]){
            cout<<i<<endl;
            break;
        }
        i++;
    }
	return 0;
}

Measured memory_bytes: 5436
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    return (a<b)?a:b;
}
int abso(int a)
{
    if(a<0)
    return a*(-1);
    return a;
}
int main()
{
    int n,k;
    cin>>n>>k;
    long long int a[n],b[n];
    unsigned long long int mini=10000000001;
    b[0]=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=mini;
    }
    b[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=min(i,k);j++)
        {
           b[i]=min(b[i],b[i-j]+abso(a[i]-a[i-j]));
        }
    }
    cout<<b[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int A=a-b,B=b-c,C=c-a;
  if (A<0){
    A*=-1;
  }
  if (B<0){
    B*=-1;
  }
  if (C<0){
    C*=-1;
  }
  if (C<=d||(A<=d&&B<=d)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * コンソールテスト用Main クラス
 *
 */
public class Main {

	/* コンストラクタ */
	Main() {
	//何もしない
	}

	/**
	 * 提出
	 *
	 */

	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = 0;
		int b = 0;
		int c = 0;

		a = scanner.nextInt();
		b = scanner.nextInt();
		c = scanner.nextInt();

		/* aとbで大小関係を比較 */
		if (a < b) {
			/* bとcで大小関係を比較 */
			if (b < c) {
				System.out.println ("Yes");
			} else {
				System.out.println ("No");
			}
		} else {
			System.out.println ("No");
		}
	}
}



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

using namespace std;

int main()
{
	int a, b;
	int count = 0;
	cin >> a >> b;
	for(int i = a; i <= b; i++)
	{
		int n = i;
		int m = n%10;
		n /= 10;
		int o = n%10;
		n /= 100;
		int p = n%10;
		n /= 10;
		int q = n%10;
		if((m == q) && (o == p))
		{
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

vector<int> to[200005];
int dp[200005];
vector<int> a, ans;

void dfs(int now,int p = -1){
  int j = lower_bound(dp,dp+200005,a[now])-dp;
  int old = dp[j];
  dp[j]=a[now];
  ans[now]=lower_bound(dp,dp+200005,INF) - dp - 1;
  for(auto next:to[now]){
    if(next==p)continue;
    dfs(next,now);
  }
  dp[j]=old;
}

int main(){
  int n;
  cin >> n;
  a = ans = vector<int>(n);
  rep(i,n)cin >> a[i];
  rep(i,n-1){
    int u,v;
    cin >> u >> v;
    u--,v--;
    to[u].push_back(v);
    to[v].push_back(u);
  }
  rep(i,200005)dp[i]=INF;
  dp[0]=-INF;
  dfs(0);
  rep(i,n)cout << ans[i] << endl;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int h, w; cin >> h >> w;

    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }

    int dh[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
    int dw[8] = {0, 1, 1, 1, 0, -1, -1, -1};

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '.') {
                int cnt = 0;

                for (int k = 0; k < 8; ++k) {
                    if (0 <= i+dh[k] && i+dh[k] < h && 0 <= j+dw[k] && j+dw[k] < w && s[i+dh[k]][j+dw[k]] == '#') {
                        ++cnt;
                    }
                }

                s[i][j] = cnt + '0';
            }
        }
    }

    for (int i = 0; i < h; ++i) {
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
const int MAXN=20005,MAXV=30001;

int ans[MAXN];
bool used[MAXV];
int gcd(int a,int b)
{return b==0?a:gcd(b,a%b);}

int main()
{
	int n,sum=0,i,j;
	scanf("%d",&n);
	for(i=1,j=1;j<n;i++)
		if(i%2==0||i%3==0)
		{
			ans[j++]=i;
			used[i]=true;
			sum+=i;
		}
	int r2=(sum-2)%2,r3=(sum-3)%3;
	for(i=1;j<=n;i++)
		if(!used[i]&&(i+r2)%2==0&&(i+r3)%3==0&&gcd(i,sum)!=1)
			ans[j++]=i;
	for(int i=1;i<n;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	int i = 1;

	while(1000 * i){
		if(1000 * i >= n)
			break;
		else
			i += 1;
	}

	cout << (1000 * i) - n;


}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

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

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

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

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1234567;
signed main(){
	int a,b,p,q,r;
	cin>>a>>b>>p>>q>>r;
	double d=a*p;
	d-=(q-p)*(b-a);
	double ans=d/(q+r)+b;
	cout<<ans<<endl;
}



Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  int n,k;
  cin >> n >> k;
  double p[n];
  double e[n];
  for(int i=0; i<n; i++){
    cin >> p[i];
    e[i] = (p[i]+1)/2;
  }
  double s[n-k+1];
  for(int i=0; i<k; i++){
    s[0] += e[i];
  }
  for(int i=k; i<n; i++){
    s[i-k+1] = s[i-k] + e[i]-e[i-k];
  }
  double ans = 0;
  for(int i=0; i<n-k+1; i++){
    ans = max(ans,s[i]);
  }
  cout << fixed << setprecision(10) << ans << endl;
}



Measured memory_bytes: 4992
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_d
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
ll dp[101][100004];
ll val[101];
ll wt[101];
int main() {
	fastIO
	ll n,W;
	cin>>n>>W;
	for(int i=1;i<=n;i++)
	{
		cin>>wt[i];
		cin>>val[i];
	}
	for(int i=0;i<=n;i++)
	{
		for(int w=0;w<=W;w++)
		{
			if(i==0||w==0)
			{
				dp[i][w]=0;
				continue;
			}
			dp[i][w]=dp[i-1][w];
			if(w-wt[i]>=0)
			dp[i][w]=max(dp[i-1][w],dp[i-1][w-wt[i]]+val[i]);
		}
	}
	cout<<dp[n][W]<<endl;
	return 0;
}

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

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

int main()
{
	int64_t a, counter = 0;
	cin >> a;
	for (int64_t i = 1; i <= a; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			counter += i;
		}
	}
	cout << counter << endl;
	return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

struct WeightedUnionFind{
	int size;
	vector<int> parent;
	vector<llint> weight;
	
	WeightedUnionFind(){}
	WeightedUnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		weight.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i, weight[i] = 0;
	}
	int root(int i){
		if(parent[i] == i) return i;
		int r = root(parent[i]);
		weight[i] = weight[parent[i]] + weight[i];
		return parent[i] = r;
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	llint get(int i, int j){ //i->jの重みを返す（非連結なら0を返す）
		if(!same(i, j)) return 0;
		return weight[j]-weight[i];
	}
	bool unite(int i, int j, llint x){ //i->jの重みをxに設定する。矛盾があればfalseを返す。
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j){
			return get(i, j) == x;
		}
		parent[root_i] = root_j;
		weight[root_i] = weight[j]-weight[i]-x;
		return true;
	}
};

llint n, m;
WeightedUnionFind uf(100005);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	llint l, r, d;
	for(int i = 1; i <= m; i++){
		cin >> l >> r >> d;
		if(!uf.unite(l, r, d)){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  ll sum = (N%2==1? N: N+1);
  vector<P> ans(0);
  for(int i = 1; i <= N-1; i++){
    for(int j = i+1; j <= N; j++){
      if(i+j == sum) continue;
      ans.push_back(P(i, j));
    }
  }
  cout << sz(ans) << endl;
  for(int i = 0; i < sz(ans); i++){
    cout << ans.at(i).first << ' ' << ans.at(i).second << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
#define INF 1e18

using namespace std;

void dfs(vector <vector<ll>> &adj, vector <vector<ll>> &dp, vector <bool> &vis, ll root){
    vis[root] = true;
    dp[root][0] = 1;
    dp[root][1] = 1;
    for(auto x: adj[root]){
        if(vis[x]) continue; 
        if(dp[x][0]<0 || dp[x][1]<0) dfs(adj, dp, vis, x);
        dp[root][0] = (dp[root][0]*dp[x][1])%M;
        dp[root][1] = (dp[root][1]*(dp[x][0]+dp[x][1])%M)%M;
    }
}

int main() {
    ios
    ll n; cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <vector<ll>> dp(n+1, vector<ll>(2, -1));
    vector <bool> vis(n+1, false);
    
    repi(i, n-1){
        ll u, v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(adj, dp, vis, 1);
    cout<<(dp[1][0]+dp[1][1])%M;
    return 0;
}


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

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    if (K < N) {
        cout << K * X + (N - K) * Y << endl;
    } else {
        cout << N * X << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
a = S.count("R") * S.count("G") * S.count("B")
c = 0
for i in range(N):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            c += 1
print(a - c)


Measured memory_bytes: 9096
#include <iostream>

using namespace std;

int main()
{
  int N;
  cin >> N;
  unsigned long long int power = 1;
  
  for (int i = 1; i <= N; ++i) {
    power *= i;
    power = power % (1000000007);
  }
  
  cout << power << endl;
  
  return 0;
}


Measured memory_bytes: 256
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")
}

use std::cmp::{max, min};

use std::collections::BTreeMap;
use std::collections::HashMap;
fn main() {
  let n = read::<i64>();
  let mut k = read::<i64>();
  let mut map: BTreeMap<i64, i64> = BTreeMap::new();

  for _ in 0..n {
    let a = read::<i64>();
    let b = read::<i64>();

    let current = map.entry(a).or_insert(0);
    *current += b;
  }

  // println!("{:?}", map);

  for (i, v) in map.iter() {
    k -= *v;
    if k <= 0 {
      println!("{}", *i);
      break;
    }
  }

}


Measured memory_bytes: 4352
N = int(input())
dic = {}
for i in range(N):
  a = input()
  dic[a] = dic.get(a, 0) + 1
M = int(input())
for i in range(M):
  b = input()
  dic[b] = dic.get(b, 0) - 1
d = sorted(dic.values(), reverse = True)
print(max(0, d[0]))

Measured memory_bytes: 62168
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[20],x;
	int n,i,y,z;
	scanf("%s",s);
	n=strlen(s);
	if(n%2!=0){
		y=n/2-1;
	}
	else{
		y=n/2;
	}
	n=n-1;
	for(i=0;i<y;i++) {
		z=n-i;
		x=s[i];
		s[i]=s[z];
		s[z]=x;
	}
	printf("%s\n",s);
	return 0;
}
	
	
	
	


Measured memory_bytes: 2028
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, dd, ans = 0;
	cin >> nn >> dd;
	for(int64 ii = 0;ii < nn;ii++)
	{
		int64 xx, yy;
		cin >> xx >> yy;
		if(xx * xx + yy * yy <= dd * dd)
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<set<int>>;
using _Graph = vector<vector<edge>>;


const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

// int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

  string S;
  cin >> S;
  string date = S.substr(0, 4) + S.substr(5, 2) + S.substr(8, 2);

  ll res = atoi(date.c_str());

  if(res <= 20190430)cout << "Heisei";
  else cout << "TBD";

  // cout << date;


}


/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long ans,l;
  string s;
  cin>>s;
  l=s.length();
  ans=l*(l-1)/2;
  for(char c='a';c<='z';++c){
    long k=count(s.begin(),s.end(),c);
    ans-=k*(k-1)/2;
  }
  cout<<++ans;
  return 0;
}

Measured memory_bytes: 640
import static java.lang.Integer.parseInt;
import static java.lang.System.out;
import java.io.File;
import java.util.Scanner;

public class Main extends BaseExe {

    public static void main(String[] args) {
        new Main().exeSysIn();
    }

    @Override
    protected void execute() throws Exception {
        String[] inDataes = nextLine().split(" ");
        int[] xy = { parseInt(inDataes[0]), parseInt(inDataes[1]) };
        out.print(xy[0] * xy[1] + " ");
        out.println(2 * (xy[0] + xy[1]));
    }
}

abstract class BaseExe {

    private Scanner scan;

    private String inData;

    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void exeCtrl(Scanner scan) throws Exception {
        this.scan = scan;
        execute();
    }

    protected abstract void execute() throws Exception;

    protected String nextLine() {
        return scan.nextLine();
    }

    protected boolean judgeInData() {
        return hasNextLine() && isNotEmptyInData();
    }

    protected boolean hasNextLine() {
        return scan.hasNextLine();
    }

    protected boolean isNotEmptyInData() {
        inData = nextLine();
        return !inData.isEmpty();
    }

    protected String getInData() throws Exception {
        if (inData.isEmpty())
            throw new Exception("inData is Empty.");
        return inData;
    }
}

Measured memory_bytes: 26132
num = int(input())
hen = sorted(list(map(int, input().split(" "))), reverse=True)
i = 0
a = []
while i < num-1:
    if hen[i] == hen[i+1]:
        a.append(hen[i])
        i += 2
    else:
        i += 1
if len(a) < 2:
    print(0)
else:
    print(a[0] * a[1])
    

Measured memory_bytes: 14252
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

ll n;
vector<ll>v;
ll f=0;

bool binary_j(ll mid){
  ll x=mid;
  for(ll i=0;i<n-1;i++){
    x=v[i]-x;
    if(x<0){
      return (i&1)==0 ?true:false;
    }
  }
  x=v[n-1]-x;
  if(x==mid){
    f=1;
    return true;
  }
  if(x<mid)return true;
  return false;
  //if(ans<=mid)return true;
  //if(ans>mid)return false;
}

ll binary_search(ll left,ll right){
  ll mid;
  while(left<right){
    mid = (left+right)/2;
    if(binary_j(mid)){
      right = mid;
    }
    else{
      left = mid+1;
    }
    if(f==1)return mid;
  }
  return left;
}

int main(){
  cin>>n;
  v.assign(n,0);
  f=0;
  for(ll i=0;i<n;i++){
    cin>>v[i];
  }
  ll x=binary_search(0,1e+9);
  cout<<x*2;
  x=v[0]-x;
  for(ll i=1;i<n;i++){
    cout<<" "<<x*2;
    x=v[i]-x;
  }
  cout<<endl;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#define Re register int

int N,W,w[105],v[105];
long long f[100005];

template <typename T> inline void read(T &var)
{
	T x=0; int w=0; char ch=0;
	while (!isdigit(ch)) w|=ch=='-',ch=getchar();
	while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	var=w?-x:x;
}
int main(int argc, char const *argv[])
{
	read(N),read(W);
	for (Re i=1; i<=N; ++i)
		read(w[i]),read(v[i]);
	for (Re i=1; i<=N; ++i)
		for (Re j=W; j>=w[i]; --j)
			f[j]=std::max(f[j],f[j-w[i]]+v[i]);
	printf("%lld\n",f[W]);
	return 0;
}

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

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

int main() {
    fast_io;
    long long n,m,k;
    cin>>n>>m>>k;

    vector<long long> a={0};
    vector<long long> b={0};

    for(long long i=0;i<n;i++) {
        long long num;
        cin>>num;
        a.push_back(num+a[i]);
    }

    for(long long i=0;i<m;i++) {
        long long num;
        cin>>num;
        b.push_back(num+b[i]);
    }

    for(long long i=0;i<a.size();i++) {
    }

    for(long long i=0;i<b.size();i++) {
    }

    long long ans=0;
    long long j=m;

    for(long long i=0;i<=n;i++) {
        if(a[i]>k) {
            break;
        }
        while(b[j]>(k-a[i])) {
            j--;
        }
        ans=max(ans,i+j);
    }

    cout<<ans<<endl;

}




Measured memory_bytes: 7956
#include <cstdio>
#include <utility>
using namespace std;

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

typedef long long int ll;

ll gcd(ll x, ll y){
	return y ? gcd(y,x%y):x;
}

int main(){
	int n;
	ll t,ans;
	ans=1;
	scanf("%d",&n);
	REP(i,n){
		scanf("%lld",&t);
		ans = t/gcd(ans,t)*ans;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      x: usize,
      a: usize,
    }
    if x < a {
        println!("{}", 0);
    } else {
        println!("{}", 10);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#else
#define gc() 1
#define max3(a,b,c) max(a,b,c)
#define min3(a,b,c) min(a,b,c)
#endif

typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
dy[8] = { 1,1,0,-1,-1,-1,0,1 };

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



#define MAXIN 100

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

	lint n[3]; cin >> n[0] >> n[1] >> n[2];
	sort(n, n + 3);
	co(n[2] -n[0]);

	gc();
}

Measured memory_bytes: 256
#include <iostream>
 
int main() {
    int r,c,i;
	std::cin >> r >> c;
    int list[101][101]={0};
    for(int a=0;a<r;a++){
        for(int b=0;b<c;b++){
            std::cin >> i;
            list[a][b]=i;
            list[a][c]=list[a][c]+i;
            list[r][b]=list[r][b]+i;
            list[r][c]=list[r][c]+i;
        }
    }
    for(int d=0;d<=r;d++){
        for( int e=0;e<=c;e++){
            if(e<c){
            std::cout << list[d][e] <<" ";
            }else{
            std::cout << list[d][e];}
        }
        std::cout << std::endl;
    }
	return 0;
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;
	double x, ans = 0.0;
	string u;

	cin >> N;
	rep(i, N) {
		cin >> x >> u;
		if (u == "JPY") ans += x;
		else ans += x * 380000.0;
	}

	printf("%.10lf\n", ans);

	return 0;
}


Measured memory_bytes: 256
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n = I()
act = [[0,0,0]] + LLI(n)
dp = [[-10**10,-10**10,-10**10] for _ in range(n+1)]
#dp[i][0]はi日目でA選ぶときの幸福度の最大値
#dp[i][1]はi日目でB選ぶときの幸福度の最大値
#dp[i][2]はi日目でC選ぶときの幸福度の最大値
#1-indexedで考えよう
dp[1] = act[1]
for i in range(2,n+1):
    dp[i][0] = max(dp[i-1][1] + act[i][0], dp[i-1][2] + act[i][0])
    dp[i][1] = max(dp[i-1][0] + act[i][1], dp[i-1][2] + act[i][1])
    dp[i][2] = max(dp[i-1][1] + act[i][2], dp[i-1][0] + act[i][2])
print(max(dp[n][0],dp[n][1],dp[n][2]))


Measured memory_bytes: 105296
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto a = readln.split.to!(int[]);

  int s = 0;
  foreach (i; 0 .. n) {
    a[i] *= n;
    s += a[i];
  }
  auto ave = s / n;
  int best_idx = 0;
  import std.math : abs;

  foreach (int i; 1 .. n) {
    if (abs(ave - a[best_idx]) > abs(ave - a[i])) {
      best_idx = i;
    }
  }
  writeln(best_idx);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  ll ma=0;
  rep(i,n) cin>>a[i], chmax(ma,a[i]);
  
  ll g=0;
  rep(i,n){
    g=gcd(g,a[i]);
  }
  
  if(k%g==0&&k<=ma) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  
}


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

int main(){
  int n;
  cin >> n;
  vector<int> list(n);
  int Bob = 0;
  int Alice = 0;
  for (int i=0; i<n; i++){
    cin >> list.at(i);
  }
  sort(list.begin(),list.end());
  reverse(list.begin(),list.end());
  for (int j=0; j<n; j++){
    if (j%2==0) Alice += list.at(j);
    else Bob += list.at(j);
  }
  cout << Alice-Bob << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N ;
	int amount = N;
	string word;
	cin >> word;
	for (size_t i = 0; i < N-1; i++)
	{
		if (word[i] == word[i+1])
		{
			amount--;
		}
	}
	cout << amount;

}

Measured memory_bytes: 512
#include <queue>
#include <iostream>
using namespace std;
const int INF=0x3f3f3f3f,maxn=804;
queue<int>q;
int a[maxn][maxn],n,m,k,vis[maxn][maxn],sx,sy,mina;
int lrud[5]={0,1,0,-1,0};
int Get(int x,int y)
{
	int X=(x+k-2)/k;
	X=min(X,(y+k-2)/k);
	X=min(X,(n-x+k-1)/k);
	X=min(X,(m-y+k-1)/k);
	return X;
}
void bfs()
{
	int i;
	vis[sx][sy]=0;
	q.push(sx);q.push(sy);
	while(!q.empty())
	{
		int x=q.front();q.pop();int y=q.front();q.pop();
	
		if(vis[x][y]==k)
			continue;
		for(i=1;i<=4;i++)
		{
			int gx=x+lrud[i-1];
			int gy=y+lrud[i];
			if(gx<1 || gy<1 || gx>n || gy>m || vis[x][y]+1>=vis[gx][gy] || a[gx][gy]==1)
				continue;
			vis[gx][gy]=vis[x][y]+1;
			q.push(gx);q.push(gy);

		}
	}
}
int main()
{
	int i,j,ans=0;
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			vis[i][j]=INF;
			char c;
			cin>>c;
			if(c=='.')
				a[i][j]=0;
			else
				if(c=='#')
					a[i][j]=1;
				else
				{
					sx=i,sy=j;
					a[i][j]=0;
				}
		}
	}
	mina=INF;
	bfs();
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(vis[i][j]!=INF)
			{	mina=min(mina,Get(i,j)+1);
			}
		}
	}
	cout<<mina;
	return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (int i = 0; i < S.size(); i++) {
        int rot = (S[i] - 'A' + N) % 26;
        S[i] = 'A' + rot;
    }

    cout << S << endl;
}


Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static final int mod = (int)1e9+7;
	
	public static void solve() {
		int x=s.nextInt();
		int y =s.nextInt();
		int max = (int)2e6+10;
		long[] fact = new long[max];
		long[] invfact= new long[max];
		fact[0]=1;
		invfact[0]=1;
		fact[1]=1;
		invfact[1]=1;
		for(int i=2;i<max;i++) {
			fact[i]=fact[i-1]*i;
			fact[i]%=mod;
			invfact[i]=(invfact[i-1]*ModInverse(i, mod))%mod;
		}
		long ways = 0;
		for (int twos = 0;twos < x/2+5;twos++) {
			int used = twos*2;
			int ones = x - used;
			if(ones>=0) {
				int used_y=twos;
				used_y+=ones*2;
				if(used_y==y) {
					long temp=fact[ones+twos];
					temp = temp*invfact[ones];
					temp %=mod;
					temp = temp * invfact[twos];
					temp%=mod;
					ways +=temp;
					ways%=mod;
				}
			}
		}
		out.println(ways);
	}

	public static class Triplet {
		long gcd;
		long x;
		long y;

		Triplet(long gcd, long x, long y) {
			this.gcd = gcd;
			this.x = x;
			this.y = y;
		}
	}

	public static Triplet ExtendedEuclideanAlgo(long a, long b) {
		if (a == 0) {
			return new Triplet(b, 0, 1);
		}
		Triplet ans = ExtendedEuclideanAlgo(b % a, a);
		long x = ans.y - (b / a) * ans.x;
		long y = ans.x;
		return new Triplet(ans.gcd, x, y);
	}

	public static long ModInverse(long a, long m) {
		Triplet ans = ExtendedEuclideanAlgo(a, m);
		if (ans.gcd != 1) {
			//System.out.println("Multiplicative inverse doesnot exist");
			return -1;
		} else {
			//m is added to handle negative x
			long result = (ans.x % m + m) % m;
			return result;
		}
	}
	
	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}


Measured memory_bytes: 258772
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
#define MOD 1e9+7
typedef pair<int,int> P;
typedef pair<int,P> PP;
struct edge{int to,cost;};

signed main(){
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    int sum=0;
    vector<int> p(n);
    vector<vector<edge> > g(n);
    for(int i=1;i<n;i++){
	 cin>>p[i];
	 p[i]--;
    }
    for(int i=1;i<n;i++){
	 int d;
	 cin>>d;
	 g[i].pb({p[i],d});
	 g[p[i]].pb({i,d});
	 sum+=d;
    }
    vector<int> used(n,0);
    vector<int> ev;
    int dsum=0;
    for(int i=0;i<n;i++){
	 if(g[i].size()==1){
	   used[i]=1;
	   dsum+=g[i][0].cost;
	   ev.pb(i);
	 }
    }
    for(int i=0;i<ev.size();i++){
	 int to=g[ev[i]][0].to;
	 for(int j=0;j<g[to].size();j++){
	   if(g[to][j].to==ev[i]){
		g[to].erase(g[to].begin()+j);
		break;
	   }
	 }
    }
  
    int s;
    for(int i=0;i<n;i++){
	 if(used[i])continue;
	 s=i;
	 break;
    }
    vector<int> d(n,-1);
    queue<P> que;
    que.push(P(s,0));
    while(que.size()){
	 int v=que.front().fi;
	 int cost=que.front().se;
	 que.pop();
	 if(d[v]!=-1)continue;
	 d[v]=cost;
	 for(int i=0;i<g[v].size();i++){
	   que.push(P(g[v][i].to,cost+g[v][i].cost));
	 }
    }
    int ma=0;
    for(int i=0;i<n;i++){
	 if(ma<d[i]){
	   ma=d[i];
	   s=i;
	 }
    }
    d=vector<int>(n,-1);
    que=queue<P>();
    que.push(P(s,0));
    while(que.size()){
	 int v=que.front().fi;
	 int cost=que.front().se;
	 que.pop();
	 if(d[v]!=-1)continue;
	 d[v]=cost;
	 for(int i=0;i<g[v].size();i++){
	   que.push(P(g[v][i].to,cost+g[v][i].cost));
	 }
    }
    ma=0;
    for(int i=0;i<n;i++)ma=max(ma,d[i]);
    //dbg(sum);  dbg(dsum);  dbg(ma);
    cout<<2*(sum-dsum)-ma+sum<<endl;
  }
  return 0;
}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    VSORT(a); VSORT(b); VSORT(c);
    ll ans = 0;
    rep(i, n) {
        auto itr_a = lower_bound(all(a), b[i]);
        auto itr_c = lower_bound(all(c), b[i]+1);
        ans += (itr_a - a.begin()) * (c.end() - itr_c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include <string.h>
#include<stdio.h>
#include <math.h>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;

	if (N == M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main() {
  string s ;
  cin >> s ;
  
  int c=0 ;
  
  if(s.at(0)=='o'){
    c++;
  }
  if(s.at(1)=='o'){
    c++;
  }
  if(s.at(2)=='o'){
    c++;
  }
  
  cout << 700+(100*c) << endl;
  
}



Measured memory_bytes: 256
import  math
n=int(input())
def dist(xi,yi,xj,yj):
    tmp= math.sqrt((xi-xj)**2+(yi-yj)**2)
    return tmp
tw=[]
for i in range(n):
    q,r=map(int,input().split())
    tw.append([q,r])
ans=0
for i in range(0,n-1):
    for j in range(i+1,n):
        f=dist(tw[i][0],tw[i][1],tw[j][0],tw[j][1])
        ans+=f
print(2*ans/n)

Measured memory_bytes: 3064