akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;
ll k,l;

void mostFrequent(ll arr[],ll n){ 

    unordered_map<ll, ll> hash; 
   
	for (int i = 0; i < n; i++)
        hash[arr[i]]++;
    
    ll max_count = 0, res = -1; 
    for (auto i : hash) {
        if (max_count < i.second) { 
            res = i.first; 
            max_count = i.second; 
        }
    } 
    k=res;
    l=max_count;
} 

ll fi,fix,si,six;

void mostFrequent2(ll arr[],ll n, ll mx){ 

    unordered_map<ll, ll> hash; 
   
	for (int i = 0; i < n; i++){
		if(arr[i]!=mx)
        	hash[arr[i]]++;
	}
    
    ll max_count = 0, res = -1; 
    for (auto i : hash) {
        if (max_count < i.second) { 
            res = i.first; 
            max_count = i.second; 
        }
    } 
    k=res;
    l=max_count; 
    
} 


ll idx,f,fx,s,sx,idx1;

int main(){
	ll n;
	cin>>n;
	ll even[n/2],odd[n/2];
	for(ll i=0; i<n; i++){
		ll a;
		cin>>a;
		if(i%2==0) odd[idx++]=a;
		else even[idx1++]=a;
	}
	sort(odd,odd+idx);
	sort(even,even+idx1);
	
	mostFrequent(odd,n/2);
	f=k;
	fx=l;
	mostFrequent(even,n/2);
	s=k;
	sx=l;
	
	mostFrequent2(odd,n/2,f);
	fi=k;
	fix=l;
	mostFrequent2(even,n/2,s);
	si=k;
	six=l;
	
	if(f!=s){
		cout<<((n/2)-fx)+((n/2)-sx);
	}
	else{
		cout<<((n/2)-max(fix,six))+((n/2)-fx);
	}
}


Measured memory_bytes: 3108
// AOJ 2135 Reverse a Road
// 2018.2.26 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define QMAX 15000
typedef struct { short t, s, r; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && (que[l].t < que[i].t ||
		que[l].t == que[i].t && que[l].r < que[i].r)) min = l; else min = i;
	if (r < qsize && (que[r].t < que[min].t ||
		que[r].t == que[min].t && que[r].r < que[min].r)) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t, int r)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t, que[i].r = r;
	while (i > 0 && (que[min = PARENT(i)].t > que[i].t ||
		   que[min].t == que[i].t && que[min].r > que[i].r)) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

short hi[1002], *to[1002], *no[1002]; char *re[1002];
short dist[1002][1002][2];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int dijkstra(int *rno, int start, int goal)
{
	int i, s, t, r, e, k, f;

	memset(dist, 0x30, sizeof(dist));
	qsize = 0;
	enq(start, 0, 0);
	while (qsize) {
		s = que[0].s, t = que[0].t, r = que[0].r, deq();
		if (s == goal) { *rno = r; return t; }

		if (r == 0) {
			for (i = 0; i < hi[s]; i++) {
				e = to[s][i], k = no[s][i], f = re[s][i];
				if (f == 0) {
					if (dist[e][k][0] > t+1) dist[e][k][0] = t+1, enq(e, t+1, 0);
				} else {
					if (dist[s][k][1] > t+1) dist[s][k][1] = t+1, enq(e, t+1, k);
				}
			}
		} else {
			for (i = 0; i < hi[s]; i++) {
				e = to[s][i], k = no[s][i], f = re[s][i];
				if (f) continue;
				if (dist[e][k][1] > t+1) dist[e][k][1] = t+1, enq(e, t+1, r);
			}
		}
	}
	return -1;
}

int main()
{
	int N, S, T, M, a, b, i, j, k, ans;
	short *memo;

	while (N = in()) {
		N++, S = in(), T = in();
		M = in();

		memo = malloc(M << 2);
		memset(hi, 0, N << 1);
		j = 0, i = M; while (i--) {
			memo[j++] = a = in(), memo[j++] = b = in();
			hi[a]++, hi[b]++;
		}

		for (a = 0; a < N; a++) if (hi[a]) {
			to[a] = malloc(hi[a] << 1);
			no[a] = malloc(hi[a] << 1);
			re[a] = malloc(hi[a]);
		}
		memset(hi, 0, N << 1);
		j = 0; for (i = 1; i <= M; i++) {
			a = memo[j++], b = memo[j++];
			k = hi[a]++, to[a][k] = b, no[a][k] = i, re[a][k] = 0;
			k = hi[b]++, to[b][k] = a, no[b][k] = i, re[b][k] = 1;
		}
		free(memo);

		ans = dijkstra(&k, S, T);
		printf("%d %d\n", ans, k);
	}
	return 0;
}


Measured memory_bytes: 7172
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  int cnt = 0;
  rep(i,n) {
    if(a[i]<0) {
      cnt++;
      a[i] *= -1;
    }
  }

  ll ans = 0;
  sort(a.begin(),a.end());
  rep(i,n) ans += a[i];

  if(cnt%2 == 1) ans -= 2*a[0];
  
  cout << ans << endl;
}



Measured memory_bytes: 4048
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    h,n=map(int,input().split())
    lis=np.array([list(map(int,input().split())) for _ in range(n)])
    dp=np.zeros(h+1,int)
    dp[0]=0
    for i in range(1,h+1):
        dp[i]=np.min(dp[np.maximum(i-lis[:,0],0)]+lis[:,1])
    print(dp[h])

if __name__=='__main__':
    main()

Measured memory_bytes: 12560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main(){
  ll n,c; cin>>n>>c;
  ll d[c+1][c+1]={};
  ll f[n+1][n+1]={};
  rep(i,c)rep(j,c) cin>>d[i][j];
  rep(i,n)rep(j,n){
    cin>>f[i][j];
    f[i][j]--;}
  ll a[3][100]={};
  rep(i,n){
    rep(j,n){
      a[(i+j+2)%3][f[i][j]]++;}
  }
  ll ca[3][100]={};
  rep(i,3){
    rep(j,c){
      ll cb = 0;
      rep(k,c){
        cb += d[k][j]*a[i][k];}
      ca[i][j] = cb;
    }
  }
  ll ans = INF;
  for(ll i=0; i<c; i++){
    for(ll j=0; j<c; j++){
      if(j==i)continue;
      for(ll k=0; k<c; k++){
        if(k==i||k==j)continue;
      ll  cc = ca[0][i] + ca[1][j] + ca[2][k];
        ans = min(ans , cc);
      }
    }
  }
  //rep(i,3)rep(j,c) cout << ca[i][j] << endl;
  cout << ans << endl;}
        
  
  


Measured memory_bytes: 5540
//#pragma GCC optimize(3)
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
typedef long long LL;
using namespace std;
#define MAXN 500005
#define eps (1e-11)
#define lyh 19260817
#define njj 19491001
const double pi = acos(-1.0);
#define P pair<int,int>
//#define int LL

char s[MAXN];

signed main() {
	scanf("%s", s);
	int len = strlen(s);
	if (s[0] == s[len - 1]) len++;
	if (len % 2) printf("First");
	else printf("Second");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,s,d,p;
    cin>>a>>b>>c;
    s=(a+b+c)/2;
    p=sqrt(s*(s-a)*(s-b)*(s-c));
    cout<<p<<endl;
    return 0;
}


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

using namespace std;

template<typename T,typename U>
ostream& operator<<(ostream &os,const pair<T,U> &p){
	os << "<" << p.first << ", " << p.second << ">";
	return os;
}
template<typename T>
ostream& operator<<(ostream &os,const vector<T> &a){
	os << "[";
	for(int i=0;i<a.size();i++){
		os << a[i];
		if((i+1)<a.size()) os << ", ";
	}
	os << "]";
	return os;
}
template<typename T,typename U>
ostream& operator<<(ostream &os,const map<T,U> &mp){
	os << "[";
	for(auto itr=mp.begin();itr!=mp.end();){
		cout << (*itr);
		itr++;
		if(itr!=mp.end()){
			cout << ", ";
		}
	}
	cout << "]";
	return os;
}
chrono::system_clock::time_point startt,endt;
double stop_watch(bool flag, string str=""){
	if(!flag){
		endt=chrono::system_clock::now();
		double time=static_cast<double>(chrono::duration_cast<chrono::microseconds>(endt-startt).count() /1000.0);
		cout << str << "time : " << time << " msec.\n";
		startt=chrono::system_clock::now();
		return time;
	}
	startt=chrono::system_clock::now();
	return 0;
}
template<typename T> class BIT{
public:
	int size;
	vector<T> arr;
	BIT(int n){
		size=n+5;
		arr.resize(size);
	}
	void add(int i,T v){
		for(int x=i+1;x<size;x+=(x&(-x))) arr[x]+=v;
	}
	T sum(int i){
		i=min(i,size-2);
		T res=0;
		for(int x=i+1;x>0;x-=(x&(-x))) res+=arr[x];
		return res;
	}
};
long long inversion_number(vector<int> &a){
	BIT<int> bit(100);
	int n=a.size();
	long long res=0;
	for(int i=n-1;i>=0;i--){
		res+=bit.sum(a[i]-1);
		bit.add(a[i],1);
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	
	long long res=1<<29;
	for(int i=0;i<(1<<n);i++){
		bool bo=true;
		vector<bool> ju(n);
		for(int j=0;j<n;j++){
			if((i>>j)&1) ju[j]=true;
		}
		int odd=0,eve=0;
		for(int j=0;j<n;j++){
			if(!ju[j]) continue;
			if(j&1) odd++;
			else eve++;
		}
		if(odd!=eve) continue;
		
		vector<pair<int,int>> gu,ki;
		for(int j=0;j<n;j++){
			if(!ju[j]){
				if(j&1) ki.push_back({a[j],j});
				else gu.push_back({a[j],j});
			}else{
				if(j&1) gu.push_back({b[j],j});
				else ki.push_back({b[j],j});
			}
		}
		
		sort(gu.begin(),gu.end());
		sort(ki.begin(),ki.end());
		vector<pair<int,int>> arr2(n);
		for(int j=0;j<n;j++){
			if(j&1) arr2[j]=ki[j/2];
			else arr2[j]=gu[j/2];
		}
		bool bo2=true;
		for(int j=0;j<n-1;j++){
			if(arr2[j].first>arr2[j+1].first) bo2=false;
		}
		if(!bo2) continue;
		vector<int> arr(n);
		for(int i=0;i<n;i++){
			arr[i]=arr2[i].second;
		}
		long long inve=inversion_number(arr);
		//cout << inve0 << " " << inve1 << " " << __builtin_popcount(i) << "\n";
		res=min(res,inve);
	}
	if(res>(1<<28)) cout << -1 << "\n";
	else cout << res << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void pushmodtoans(int i,int mod);
int ans[10000]={};

int main(void){
	int N;
	int mod;
	scanf("%d",&N);
	int w = N;
	int i = 0;
	
	if ( N ==0){
		printf("0");
		return 0;
	}
	//Nを-2で割ってあまりを出す。
	//Nが1になるまで繰り返す。
	while ( N!=1){
		if ( N%(-2) == -1){
			mod = N%(-2) +2;
			N = N/(-2);
			N +=1;
			pushmodtoans(i,mod);
			i++;
		}else{
			mod = N%(-2);
			N /=(-2);
			pushmodtoans(i,mod);
			i++;
		}
		//printf("%d を-2で割ったら\n%d・・・%d\n",w,N,mod);
		w = N;
	}
	//printf("i=%d",i);
	printf("%d",N);
	for(i;i>0;i--){
		printf("%d",ans[i-1]);
	}
	//後はこの余りを配列に詰めていくだけか？
	
	return 0;
}
	
void pushmodtoans(int i,int mod){
	ans[i]=mod;
	i++;
}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
	if (!f[j]) f[j] = i;
      }
    }
  }

  bool isPrime(int x) {return f[x] == x;}

  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }

  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
	res.back().second++;
      } else {
	res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

const int mod = 1e9 + 7;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  Sieve sieve(1e6);
  map<int, int> mp;
  rep(i, n) {
    auto f = sieve.factor(a[i]);
    for (auto p : f) {
      mp[p.first] = max(mp[p.first], p.second);
    }
  }

  mint lcm = 1;
  for (auto p : mp) {
    rep(i, p.second) {
      lcm *= p.first;
    }
  }

  mint ans;
  rep(i, n) {
    mint b = lcm / a[i];
    ans += b;
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 4984
def ascan; gets.split.map(&:to_i);end

ss = gets.chomp
tt = gets.chomp

n = ss.size
m = tt.size

def isok(s,t)
    !s.chars.zip(t.chars).map{|l,r| l == "?" || l==r}.include?(false)
end

(n-m).downto(0) do |i|
    if isok(ss[i...(i+m)], tt)
        puts ss[0...i].gsub('?','a')+tt+ss[(i+m)..-1].gsub('?','a')
        exit
    end
end

puts "UNRESTORABLE"

Measured memory_bytes: 1788
#include<stdio.h>

/*
int check(int n){
  int i;
  if(n<2)return 0;
  if(n==2)return 1;
  if(n%2==0)return 0;
  for(i=3;i<=n/i;i+=2)
    if(n%i==0)
      return 0;
  return 1;
}
*/

int check(int n){
  int i;
  if(n<2)return 0;
  if(n<4)return 1;
  if(n%2==0 || n%3==0)return 0;
  for(i=5;i*i<=n;i+=6)
    if(n%i==0 || n%(i+2)==0)
      return 0;
  return 1;
}

int main(){
  int i,n,ans=0,a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    ans+=check(a);
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(container) container.begin(), container.end()
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;

int main() {
  int n, max_len=0, sum_len=0;
  cin >> n;
  int l[n];
  rep(i, 0, n) {
    cin >> l[i];
    sum_len += l[i];
    if (max_len < l[i]) {
      max_len = l[i];
    }
  }
  if (max_len < sum_len - max_len) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  //cout << "お年玉をもらった人数は" << N <<endl;
  float result =0.0;
  float x[10];
  string hantei[10];
  double y = 10.0;
  double jou = pow (y,5.0);
  
  for (int i=0;i<N;i++){
    
    cin >> x[i];
    cin >> hantei[i];
    
    if (hantei[i] == string("JPY")){
      //cout << "JPY" <<"\n";
      result = result + x[i];
    }else{
      //cout << "BTC" <<"\n";
      result = result + x[i] * 3.8 * jou;
    }
  }
  cout << result <<"\n";
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String, Integer> mp = new HashMap<>();
		int N = sc.nextInt();
		String s[] = new String[N];
		for (int i = 0; i < N; i++) {
			s[i] = sc.next();
			if (mp.containsKey(s[i])) {
				mp.put(s[i], mp.get(s[i]) + 1);
			} else {
				mp.put(s[i], 1);
			}
		}

		int M = sc.nextInt();
		String t[] = new String[M];
		for (int i = 0; i < M; i++) {
			t[i] = sc.next();
			if (mp.containsKey(t[i])) {
				mp.put(t[i], mp.get(t[i]) - 1);
			}
		}
		sc.close();

		int max = 0;
		for (Integer val : mp.values()) {
			max = Math.max(max, val);
		}
		System.out.println(max);
	}
}


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

int main() {
  int N, x=1, ans=0;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  for(int i=0; i<N; i++){
    x = vec.at(x-1);
    ans++;
    if(x==2)
      break;
    if(i==N-1)
      ans = -1;
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

ll f(ll n)
{
    ll r=n%4;
    if(n<0) return 0;
    if(r==0) return n;
    else if(r==1) return 1;
    else if(r==2) return n+1;
    return 0;
}

int main(void)
{
    ll a,b;
    cin>>a>>b;
    cout<<(f(b)^f(a-1))<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;

#define INT_MAX 2147483647

int main( void ){

  int a, b , c;
  cin >> a >> b >> c;
  cout << (b/a < c ? b/a : c) << endl;

	return 0;

}



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

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

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    if(a==b) cout << c;
    if(b==c) cout << a;
    if(c==a) cout << b;
    cout << endl;;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 4000;
db dp[maxn];
db p[maxn];
int n;	
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 1;i <= n;++i)cin >> p[i];
	dp[0] = 1;
	for(int i = 1;i <= n;++i){
		for(int j = i;j >= 1;--j)
			dp[j] = dp[j-1] * p[i] + dp[j] * (1-p[i]);
		dp[0] = dp[0] * (1-p[i]);
	}
	db res = 0;
	for(int i = n - n/2;i <= n;++i)res += dp[i];
	printf("%.10f\n", res);
}

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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            Console.WriteLine(x >= 30 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 27320
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000

struct node { int t,next; }a[2010];

int f[1010][5010],head[1010],mn[1010],num[1010],n,tot;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void add(int x,int y) { a[++tot].t=y;a[tot].next=head[x];head[x]=tot; }

inline bool dfs(int x)
{
    if (!head[x]) { mn[x]=0;return true; }
    for (int i=head[x];i;i=a[i].next)
    {
    	int t=a[i].t;
    	if (!dfs(t)) return false;
	}
	int now=0;
	for (int i=0;i<=5000;i++) f[now][i]=inf;
	f[0][0]=0;
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		now++;
    	for (int i=0;i<=5000;i++) f[now][i]=inf;
        for (int i=0;i<=num[x];i++)
        {
            if (i>=num[t]) f[now][i]=min(f[now][i],f[now-1][i-num[t]]+mn[t]);
            if (i>=mn[t]) f[now][i]=min(f[now][i],f[now-1][i-mn[t]]+num[t]);
        }
	}
    int hh=inf;
    for (int i=0;i<=num[x];i++) hh=min(hh,f[now][i]);
    if (hh==inf) return false;
    mn[x]=hh;
    return true;
}

int main()
{
    n=rd();tot=0;
    for (int i=2;i<=n;i++) { int x=rd();add(x,i); }
    for (int i=1;i<=n;i++) num[i]=rd();
    puts(dfs(1)?"POSSIBLE":"IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 19840
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> v(n), c(n);
	rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];
	int ans = 0;
	rep(i, n) {
		if (v[i] >= c[i]) ans += v[i] - c[i];
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()
{
    int n;  cin >> n;
    double Res = 0;
    for(int i = 1;i<=n;i++){
        if(i & 1)  Res++;
    }
    cout << setprecision(10) << fixed << Res/n;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
lists=[0 for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    lists[a-1]+=1
    lists[b-1]+=1
flag=True
for i in range(n):
    if lists[i]%2!=0:
        flag=False
        break
if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3964
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    a,b,c,d = map(int, readline().split())
    ans = max(a*c, a*d, b*c, b*d)
    print(ans)
if __name__ == '__main__':
    main()


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

int main(){
  int e;

  while(cin>>e, e){
    int ans = INT_MAX;

    for(int z = 0; z * z * z <= e; z++){
      int zp = z * z * z;

      for(int y = 0; y * y + zp <= e; y++){
        int yp = y * y;
        int x = e - zp - yp;

        ans = min(ans, x + y + z);
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

ll n,m,a[1009],b[1009],ans=1;

int main(){
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    sort(a,a+n,greater<ll>());
    sort(b,b+m,greater<ll>());
    rep(i,n)if(a[i]==a[i+1]){
        cout<<"0\n";
        return 0;
    }
    rep(i,m)if(b[i]==b[i+1]){
        cout<<"0\n";
        return 0;
    }
    ll x=0,y=0,num;
    for(ll i=n*m;i;i--){
        if(a[x]==i&&b[y]==i)num=1;
        else if(a[x]==i)num=y;
        else if(b[y]==i)num=x;
        else num=x*y-n*m+i;
        (ans*=max(num,0ll))%=mod;
        if(a[x]==i)x++;
        if(b[y]==i)y++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def get_gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def get_lcm(a, b, gcd=0):
    if gcd == 0:
        return a * b // get_gcd(a, b)
    else:
        return a * b // gcd


A, B = map(int, input().split())

print(get_lcm(A, B))


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int A,B,T;
	cin >> A >> B >> T;

	int ans=0;
	for(int i=A;i<=T;i+=A)
		ans++;
	
	cout << ans*B << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
	char S[4];
  	scanf("%s", S);
  	
  	int cnt = 0;
  	for(int j = 0; j < 4; j++)
    {
  		for(int i = 0; i < 4; i++)
    	{
      		if(S[j] == S[i])
            {
              cnt++;
            }
    	}
      	if(cnt != 2)
        {
          	printf("No");
      		return 0;
        }
      	cnt = 0;
    }
  
	printf("Yes");
  	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    char mark;
    int a;
    int n;
    int i;
    int x[13][4] = {0};

    scanf("%d", &n);
    for (a = 1; a <= n; a++)
    {

        scanf(" %c", &mark);
        scanf("%d", &i);

        if ('S' == mark)
        {
            x[i - 1][1] = 1;
        }
        else if ('H' == mark)
        {
            x[i - 1][2] = 1;
        }
        else if ('C' == mark)
        {
            x[i - 1][3] = 1;
        }
        else if ('D' == mark)
        {
            x[i - 1][4] = 1;
        }
    }

    for (i = 0; i <= 12; i++)
        if (x[i][1] == 0)
        {
            printf("S %d\n", i + 1);
        }

    for (i = 0; i <= 12; i++)
        if (x[i][2] == 0)
        {
            printf("H %d\n", i + 1);
        }

    for (i = 0; i <= 12; i++)
        if (x[i][3] == 0)
        {
            printf("C %d\n", i + 1);
        }

    for (i = 0; i <= 12; i++)
        if (x[i][4] == 0)
        {
            printf("D %d\n", i + 1);
        }

    return 0;
}



Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int minx=a[1],cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]<=minx){
			cnt++;
			minx=a[i];
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N + 1):
    A[i] += A[i - 1]

for i in range(1, M + 1):
    B[i] += B[i - 1]

ans = 0

a = N
b = 0

while a >= 0 and b <= M:
    while a >= 0 and A[a] + B[b] > K:
        a -= 1

    while a >= 0 and b <= M and A[a] + B[b] <= K:
        ans = max(ans, a + b)
        b += 1

print(ans)

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

using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); i++)
#define ford(i,n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i,l,r) for (int i = int(l); i < int(r); i++)
#define all(a) a.begin(), a.end()
#define sz(a) int(a.size())
#define mp make_pair
#define pb push_back
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return a < 0 ? -a : a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;
const ld PI = acosl(ld(-1));

mt19937 mt(time(NULL));

const int N = 100 * 1000 + 13;
int n, m;
int a[N];

inline bool read()
{
	if (scanf ("%d%d", &n, &m) != 2)
		return false;
		
	forn (i, n)
		assert(scanf ("%d", &a[i]) == 1);

	return true;
}

vector<pt> q[N];
int sum[N];
int cnt[N];

inline void solve()
{
	forn (i, n)
		cnt[ a[i] ]++;
		
	forn (i, N)
	{
		q[i % m].pb(mp(cnt[i], i));
		sum[i % m] += cnt[i];
	}
	
	int ans = 0;
	forn (i, m)
	{
		int ri = m - i;
		if (ri == m)
			ri = 0;
			
		if (i > ri)
			break;
		
		if (i == ri)
		{
			int cnt = 0;
			forn (j, sz(q[i]))
			{
				if (q[i][j].x & 1)
				{
					q[i][j].x--;
					cnt++;
				}
				
				ans += q[i][j].x / 2;
			}
			
			ans += cnt / 2;
			
			continue;
		}

		int cnt1 = 0, cnt2 = 0;
		forn (j, sz(q[i]))
			if (q[i][j].x & 1)
			{
				q[i][j].x--;
				cnt1++;
			}
		forn (j, sz(q[ri]))
			if (q[ri][j].x & 1)
			{
				q[ri][j].x--;
				cnt2++;
			}
			
		int need = max(cnt1, cnt2);
		need = min(need, min(sum[i], sum[ri]));
 
		forn (it, need)
		{
			if (cnt1)
				cnt1--;
			else
			{
				while (!q[i].empty() && q[i].back().x == 0)
					q[i].pop_back();
				assert(!q[i].empty());
				q[i].back().x--;
				if (q[i].back().x == 0)
					q[i].pop_back();
			}
			
			if (cnt2)
				cnt2--;
			else
			{
				while (!q[ri].empty() && q[ri].back().x == 0)
					q[ri].pop_back();			
				assert(!q[ri].empty());
				q[ri].back().x--;
				if (q[ri].back().x == 0)
					q[ri].pop_back();
			}
 
			ans++;	
		}
		
		for (auto it: q[i])
			ans += it.x / 2;
		for (auto it: q[ri])
			ans += it.x / 2;
	}
	
	cout << ans << endl;
}

int main()
{
#ifdef SU2_PROJ
	assert(freopen("input.txt", "r", stdin));
	assert(freopen("output.txt", "w", stdout));
#endif

	cout << setprecision(25) << fixed;
	cerr << setprecision(10) << fixed;

	assert(read());
	solve();

#ifdef SU2_PROJ
	cerr << "TIME: " << clock() << endl;
#endif

	return 0;
}


Measured memory_bytes: 6912
N = int(input())
S_list = list(input())

ans = ""

# A is 65 in unicode
# Z is 90 in unicode
for i in S_list:
    if 90 < ord(i) + N:
        ans += chr(ord(i) + N - 26)
    else:
        ans += chr(ord(i) + N)

print(ans)


Measured memory_bytes: 9128
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	string s;
	cin >> s;
	string ans = s;
	int len = s.length();
	for (int i = 0; i < len; ++i) {
		if (s[i] == '?') {
			ans[i] = 'D';
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3924
n = input().split()
a = list(map(int, input().split() ))
count = 0

while(True):
    T = False
    for i in range(len(a)):
        if a[i]%2 != 0:
            T=True
        else:
            a[i] = a[i] / 2

    if T:
        break

    count+=1

print(count)


Measured memory_bytes: 9128
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0] as usize;
    let k = line[1];
    let mut a: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut f: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    a.sort_by(|a,b| b.cmp(a));
    f.sort();

    let mut l = -1i64;
    let mut r = 1_000_000_000_010i64;
    while r - l > 1 {
        let m = (l+r) / 2;

        let mut sum = 0i64;
        for i in 0..n {
            let tar = m / f[i];
            if tar < a[i] {
                sum += a[i] - tar;
                if sum > k {
                    break;
                }
            }
        }
        if sum <= k {
            r = m;
        } else {
            l = m;
        }
    }
    println!("{}", r);
}


Measured memory_bytes: 13420
#include <bits/stdc++.h>
using namespace std;
struct segment_tree{
  int N;
  vector<int> ST;
  segment_tree(int n){
    N = 1;
    while (N < n){
      N *= 2;
    }
    ST = vector<int>(N * 2 - 1, 0);
  }
  void update(int i, int x){
    i += N - 1;
    ST[i] = x;
    while (i > 0){
      i = (i - 1) / 2;
      ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
    }
  }
  int query(int L, int R, int i, int l, int r){
    if (r <= L || R <= l){
      return 0;
    } else if (L <= l && r <= R){
      return ST[i];
    } else {
      int m = (l + r) / 2;
      return query(L, R, i * 2 + 1, l, m) + query(L, R, i * 2 + 2, m, r);
    }
  }
  int query(int L, int R){
    return query(L, R, 0, 0, N);
  }
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<pair<string, int>> S(N);
  for (int i = 0; i < N; i++){
    cin >> S[i].first;
    S[i].second = i + 1;
  }
  sort(S.begin(), S.end());
  //id -> pos
  vector<int> pos(N + 1, -1);
  for (int i = 0; i < N; i++){
    pos[S[i].second] = i;
  }
  //string -> position
  map<string, int> mp;
  for (int i = 0; i < N; i++){
    mp[S[i].first] = i;
  }
  //Find range
  vector<int> R(N);
  for (int i = 0; i < N; i++){
    string T = S[i].first;
    T.back()++;
    auto itr = mp.lower_bound(T);
    itr--;
    R[i] = (*itr).second + 1;
  }
  //debug
  /*
  for (int i = 0; i < N; i++){
    cout << R[i] << endl;
  }
  */
  //point update range sum
  segment_tree ST(N);
  //queries
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int k, id;
    cin >> k >> id;
    int p = pos[id];
    //cout << "pos = " << p << endl;
    if (k == 1){
      ST.update(p, 1);
    }
    if (k == 2){
      ST.update(p, 0);
    }
    if (k == 3){
      if (ST.query(p, R[p]) == 0){
        cout << -1 << endl;
      } else {
        //binary search
        int tv = R[p];
        int fv = p - 1;
        while (tv - fv > 1){
          int mv = (tv + fv) / 2;
          if (ST.query(p, mv) != 0){
            tv = mv;
          } else {
            fv = mv;
          }
        }
        cout << S[fv].second << endl;
      }
    }
  }
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ll2;

const int MAX_V = 100010;
const ll LLINF = LLONG_MAX;


struct Edge { int src,dst; ll weight; };
struct Data {
  int cur;
  ll weight;
  bool operator < ( const Data &data ) const {
    if( weight != data.weight ) return weight > data.weight;
    return cur < data.cur;
  }
};

int V,E;
ll C,mindist[MAX_V];
vector<Edge> G[MAX_V],ebuffer;

void compute(){
  priority_queue<Data> Q;
  rep(i,V) mindist[i] = LLINF;
  Q.push((Data){0,0});
  mindist[0] = 0;
  while( !Q.empty() ){
    Data data = Q.top(); Q.pop();
    rep(i,(int)G[data.cur].size()){
      Edge &e = G[data.cur][i];
      if( mindist[e.dst] > data.weight + e.weight ) {
        mindist[e.dst] = data.weight + e.weight;
        Q.push((Data){e.dst,mindist[e.dst]});
      }
    }
  }

  ll edge_sum = 0;
  vector<ll2> edges;
  rep(i,E) {
    Edge &e = ebuffer[i];
    edges.push_back(ll2(max(mindist[e.src],mindist[e.dst]),e.weight));
    edge_sum += e.weight;
  }
  sort(edges.begin(),edges.end());
  ll answer = edge_sum;
  rep(i,(int)edges.size()){
    ll X = edges[i].first;
    while( i < (int)edges.size() && edges[i].first == X ) {
      edge_sum -= edges[i].second;
      ++i;
    }
    --i;
    answer = min(answer,C*X+edge_sum);
  }
  printf("%lld\n",answer);
}

int main(){
  scanf(" %d %d %lld",&V,&E,&C);
  rep(i,E){
    int A,B; ll D;
    scanf("%d %d %lld",&A,&B,&D);
    --A, --B;
    G[A].push_back((Edge){A,B,D});
    G[B].push_back((Edge){B,A,D});
    ebuffer.push_back((Edge){A,B,D});
  }
  compute();
  return 0;
}

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

int main(){
    long long a, b, c;
    cin >> a >> b >> c;

    long long d = c - a - b;

    if ( d > 0 && 4 * a * b < d * d ){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w,n;
char mp[30][30];
int vis[30][30],dis[30][30];
int f(int x,int y){
	return (x-1)*w+y;
}
bool ok(int x,int y){
	if(x==0||x>h||y==0||y>w||vis[x][y]||mp[x][y]=='#')
		return false;
	return true;
}
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
queue<int> qx,qy;
void bfs(){
	while(!qx.empty()){
		int xx=qx.front(),yy=qy.front();
		qx.pop();qy.pop();
		for(int o=0;o<4;o++){
			int xto=xx+dx[o],yto=yy+dy[o];
			if(ok(xto,yto)){
				dis[xto][yto]=min(dis[xto][yto],dis[xx][yy]+1);
				vis[xto][yto]=1;
				qx.push(xto);qy.push(yto);
			}
		}
	}
} 
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		scanf("%s",mp[i]+1);
	}
	int mx=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(mp[i][j]=='#'){
				continue;
			}
			memset(vis,0,sizeof(vis));
			memset(dis,0x3f3f3f3f,sizeof(dis));
			qx.push(i);qy.push(j);
			dis[i][j]=0;vis[i][j]=1;
			bfs();
			int mmx=-1;
			for(int p=1;p<=h;p++){
				for(int q=1;q<=w;q++){
					if(mp[p][q]=='#')continue;
					mmx=max(mmx,dis[p][q]);
				}
			}
			mx=max(mx,mmx);
		}
	}
	cout<<mx<<endl;
	return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> line(H+2);
    for (int i = 1; i <= H; i++) {
        cin >> line.at(i);
    }

    vector<vector<int>> grid(H+2, vector<int>(W+2, 0));
    for (int i = 1; i <= H; i++) {
        for (int j = 0; j < W ; j++) {
            if (line.at(i).at(j) == '#') {
                grid.at(i-1).at(j)++;
                grid.at(i-1).at(j+1)++;
                grid.at(i-1).at(j+2)++;
                grid.at(i).at(j)++;
                grid.at(i).at(j+2)++;
                grid.at(i+1).at(j)++;
                grid.at(i+1).at(j+1)++;
                grid.at(i+1).at(j+2)++;
            }
        }
    } 

    vector<string> ans(H+2);
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W ; j++) {
            if (line.at(i).at(j-1) == '.') {
                cout << grid.at(i).at(j);
            } else {
                cout << '#';
            }
        }
                    cout << endl;

    } 

}

Measured memory_bytes: 256
import sys
import numpy as np
from scipy.misc import comb
sys.setrecursionlimit(1000000)
 
n = int(input())

p = list(map(int, input().split()))

miss = 0

for i in range(n):
    if miss >= 3:
        print("NO")
        exit()
    if p[i] != i+1:
        miss += 1
    

print("YES")
exit()

Measured memory_bytes: 13664
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

A.sort()
# print(A)
ans = 0

acum = 0
for i in range(N-1):
    acum += A[i]
    if acum * 2 < A[i+1]:
        ans = 0
    else:
        ans += 1

print(ans + 1)

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

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    cin>>n;
    int phase=1;
    lli pref[n+5]={}, sum[n+5]={};
    vi pos;
    char ch='+';
    fol(i,1,n+1)
    {
        if(i>1)
        {
            cin>>ch;
            if(ch=='-') pos.pb(i);
        }
        cin>>pref[i];
        if(ch=='+') ans+=pref[i];
        else ans-=pref[i];
        sum[i]=ans;
        pref[i]+=pref[i-1];
    }
    cotra(pos)
    trace(pref,n+1)
    fol(i,0,sz(pos)-1)
    {
        lli curans=0;
        int cur=pos[i]-1, next=pos[i+1]-1;
        trace(cur,next)
        curans = sum[cur]-(pref[next]-pref[cur])+(pref[n]-pref[next]);
        ans=max(ans,curans);
    }
    
    cout<<ans<<endl;
    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
    end_routine();
    if(localsys) system("pause");
}


Measured memory_bytes: 2428
def actual(a, b, c, d):
    if abs(a - c) <= d:
        return 'Yes'

    if abs(a - b) <= d and abs(b - c) <= d:
        return 'Yes'

    return 'No'


a, b, c, d = map(int, input().split())
print(actual(a, b, c, d))

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

const ll MX = 1e18;


int main() {
    int n;
    cin >> n;
    ll ans = 1;
    bool ng = false;
    
    rep(i, n) {
        ll a;
        cin >> a;
        if (a == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (ng || MX  < a*__int128(ans)) { // オーバーフローするとき
            ng = true;
        }
        ans *= a;
    }
    if (ng) cout << -1 << endl;
    else cout << ans << endl;
    
    return 0;
}


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

using namespace std;

#define ll long long
#define ar array


int n,t;
int a[200000];

void solve(){
    
    cin >> n;

    int sum;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(i == 0) sum = a[0];
        else{
            sum = sum ^ a[i];
        }
    }
    

    for (int i = 0; i < n; i++)
    {
        cout << (sum ^ a[i]) << " ";
    }
    cout << endl;

}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 4304
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import Data.Maybe
import qualified Data.Set as S
import Data.Graph
import qualified Data.IntMap.Strict as IM 

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [n,m,x] <- r'
    books <- replicateM n $ do
        c:as <- r'
        return (c, as)
    --print books
    let takeVec = forM [1..n] (\_->[0,1])
    let r = minimum $ map (testAll x books) takeVec
    print $ if r > 10^8 then -1 else r

testAll :: Int -> [(Int,[Int])] -> [Int] -> Int
testAll x book tkv = let filtered = map snd $ filter ((==1).fst) $ zip tkv book in
    if test x filtered then sum $ map fst filtered else maxBound


test :: Int -> [(Int,[Int])] -> Bool
test x books = all (>= x) $ foldl (zipWith (+)) [0,0..] (map snd books) 




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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n;cin >> n;
  vi h(n);
  REP(i, n) cin >> h[i];

  vi dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  FOR(i, 2, n) {
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
  }

  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
def solve():
    N = int(input())
    S = [input() for _ in range(N)]
    a_count = 1 if S[0] == "A" else -1
    # if N == 1 and a_count == -1:
    #     return "NO"
    for i in range(1, N):
        if a_count >= 0:
            a_count += 1 if S[i] == "A" else -1
        else:
            return "NO"
    if a_count == 0:
        return "YES"
    else:
        return "NO"


if __name__ == "__main__":
    print(solve())



Measured memory_bytes: 5604
#include <iostream>

void show(int* A, int a_size)
{
	for (int i=0; i<a_size; i++) std::cout << A[i] << ", ";
	std::cout << std::endl;
}

void add(int* A, int i, int val, int n, int a_size)
{
	int index = 0;
	int l = 0;
	int r = n;
	while (index < a_size) {
		A[index] += val;
		if (i < (l+r)/2) {
			index = 2*index + 1; r = (l+r) / 2;
		}
		else {
			index = 2*index + 2; l = (l+r) / 2;
		}
	}
}

int getSum(int* A, int x, int y, int index, int l, int r)
{
	if (r<=x || l>y) return 0;
	else if (x<=l && r<=y+1) return A[index];
	else return getSum(A, x, y, 2*index+1, l, (l+r)/2) + getSum(A, x, y, 2*index+2, (l+r)/2, r);
}

int main ()
{
	int n; std::cin >> n;
	int size = 1;
	for (; size<n; size<<=1);
	int a_size = 2*size - 1;
	
	int* A = new int[a_size];
	for (int i=0; i<a_size; i++) A[i] = 0;
	
	int q; std::cin >> q;
	for (int i=0; i<q; i++) {
		int op, x, y;
		std::cin >> op >> x >> y;
		if (op==0) {
			add(A, x-1, y, size, a_size);
			// show(A, a_size);
		}
		else std::cout << getSum(A, x-1, y-1, 0, 0, size) << std::endl;
	}
	
	delete[] A;
	
	return 0;
}



Measured memory_bytes: 3888
#include <stdio.h>

#define NMAX 2000000
#define AIMAX 10000

int main(void)
{
	int i, n;
	int C[AIMAX+1]={0};
	short A[NMAX+1], B[NMAX+1];
	
	scanf("%d",&n);
	for(i=1; i<=n; i++) {
		scanf("%d",&A[i]);
		C[A[i]]++;
	}
	
	for (i=1; i<=AIMAX; i++) {
		C[i] += C[i-1];
	}
	
	for (i=n; i>0; i--) {
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}
	
	for (i=1; i<=n; i++) {
		if(i>1) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 8460
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
  double l;
  cin >> l;
  printf("%lf\n",l*l*l/27);
  return 0;

}


Measured memory_bytes: 256
using System;

class IntroductionC
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ');
        var a = int.Parse( input[0] );
        var b = int.Parse( input[1] );

        Console.WriteLine( "{0} {1}", a * b, ( a + b ) * 2 );
    }
}

Measured memory_bytes: 5620
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    int a, b;
    
    cin >> a >> b;
    
    if(b >= a)
        cout << a << endl;
    else
        cout << a - 1 << endl;
        
    return 0;
}

Measured memory_bytes: 256
from copy import deepcopy

N = int(input())
S = input()
M = [0 for i in range(N+1)]

for i in range(N):
    if S[i] != '#':
        M[0] += 1

mini = deepcopy(M[0])
    
for i in range(N):
    if S[i] == '#':
        M[i+1] = M[i] + 1
    else:
        M[i+1] = M[i] - 1
        if mini > M[i+1]:
            mini = deepcopy(M[i+1])

print(mini)

Measured memory_bytes: 12112