akhauriyash/Code-Regression huggingface dataset:
import Data.Bool

main = do
  [n,a,b,c,d]<-map read.words<$>getLine
  s<-getLine
  putStr $ bool "No" "Yes" $ solve n a b c d s

solve n a b c d s
  | c < d = ans
  | otherwise = ans && canJump (fromTo (b-1) (d+1) s)
  where
  ans = canMove (fromTo a c s) && canMove (fromTo c d s)
  canMove [] = True
  canMove ('#':'#':_) = False
  canMove (c:s) = canMove s
  fromTo a b = drop (a-1) . take b
  canJump [] = False
  canJump ('.':'.':'.':_) = True
  canJump (c:s) = canJump s


Measured memory_bytes: 13692
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

char a[1234][1234];
int dis[1234][2134];
int main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
	for(int j = 1; j <= m; j ++)
		dis[i][j] = 1e9;
	int x1, y1;
	int x2, y2;
	cin >> x1 >> y1;
	cin >> x2 >> y2;
	for(int i = 1; i <= n; i ++)
	for(int j = 1; j <= m; j ++)
		cin >> a[i][j];
	deque<pii> q;
	q.push_back(M(x1, y1));
	dis[x1][y1] = 0;
	while(q.size())
	{
		int x = q.front().F, y = q.front().S;
		q.pop_front();
		for(int dx = -1; dx <= 1; dx ++)
		for(int dy = -1; dy <= 1; dy ++)
		{
			if(abs(dx - dy) == 1 && a[x + dx][y + dy] == '.' && dis[x + dx][y + dy] > dis[x][y])
			{
				dis[x + dx][y + dy] = dis[x][y];
				q.push_front(M(x + dx, y + dy));
			}
		}
		for(int dx = x-2; dx <= x + 2; dx ++)
		for(int dy = y-2; dy <= y + 2; dy ++)
		{
			if(dx < 1 || dx > n || dy < 1 || dy > m || a[dx][dy] != '.' || dis[dx][dy] <= dis[x][y] + 1)
				continue;
			dis[dx][dy] = dis[x][y] + 1;
			q.push_back(M(dx, dy));
			
		}
	}
	if(dis[x2][y2] > 1e8)
		dis[x2][y2] = -1;
	cout << dis[x2][y2];




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

using namespace std;

const int maxn=510;

typedef long long ll;

string s;
map<string,int> mp;

int main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	int n;
	cin>>n;
	ll ans=0;
	for(int i=0;i<n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		ans+=mp[s];
		mp[s]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11136
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,m=parseMap(split(readline()))
    println((n-1)*(m-1))
end
main()

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

int main() {
	int n; cin >> n;
	vector<int> a(n);

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

	int count = 0;
	int flag = 0;
	while(flag == 0) {
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 == 0) {
				a[i] = a[i] / 2;
			}
			else {
				flag = 1;
			}
		}
		if (flag == 0) count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
a, b, k = gets.split.map(&:to_i)
v = [a, b]
k.times do |i|
    if v[i % 2] % 2 == 1
        v[i % 2] -= 1
    end
    v[1 - i % 2] += v[i % 2] / 2
    v[i % 2] /= 2
end
puts v.join(' ')

Measured memory_bytes: 1788
#include<cstdio>
using namespace std;
const int maxn=25;
int N,A[maxn],B[maxn],C[maxn],ans=0;
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&A[i]);
	for(int i=1;i<=N;i++)
		scanf("%d",&B[i]);
	for(int i=1;i<N;i++)
		scanf("%d",&C[i]);
	A[0]=-50;
	for(int i=1;i<=N;i++){
		int now=A[i];
		ans+=B[now];
		if(A[i]-A[i-1]==1)
			ans+=C[A[i-1]];
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int total;
  int counter = 0;
  for (int a = 0; a <= A; a++){
    for (int b = 0; b <= B; b++){
      for (int c = 0; c <= C; c++){
        total = 500*a + 100*b + 50*c;
        if (total == X) ++counter;
      }
    }
  }
  cout << counter << endl;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  val Array(l, k) = readLine.trim.split(' ').map(_.toInt)
  println(
    count(l - 1, k) + count(l - k, k)
  )
  def count(l: Int, k: Int)(implicit memo: Array[Long] = Array.tabulate(l + 1){_ => -1}): Long = {
    if (l == 0) 1
    else if (l < 0) 0
    else {
      if (memo(l) < 0)
        (count(l - k - 1, k) + count(l - 2, k) + 1).also(memo(l) = _)
      else memo(l)
    }
  }
  implicit class ScopeFunc[T](private val value: T) {
    def let[A](func:T ⇒ A): A = func(value)
    def also(func:T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}



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

int main(void){
    int n,i,j,minj,tmp,count,k, c[101];
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> c[i];
    }
    i = 0;
    count = 0;
    for(i = 0; i < n; i++){
        minj = i;
        for(j = i; j < n; j++){if(c[j] < c[minj]) minj = j;}
        if(c[minj] == c[i]) continue;
        tmp = c[i];
        c[i] = c[minj];
        c[minj] = tmp; 
        count++;
    }
    for(k = 0; k < n; k++){
        cout << c[k];
        if(k == n - 1) {cout << endl;}
        else{ cout << " ";}
    }
    cout << count << endl;
}




Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
const int mod=1e9+7;

int f(int n,int p){
  if(n==0){return 1;}//cout<<1<<endl;
  int64_t x=f(n/2,p);x%=mod;
  x*=x;x%=mod;//二乗している
  if(n%2!=0){x*=p;}
  x%=mod;//cout<<x<<" "<<x%mod<<endl;
  //cout<<x<<endl;
  return x;
}

int choose(int n,int a){
  int64_t u=1,d=1;
  for(int i=0;i<a;i++){
    u*=n-i;u%=mod;
    d*=i+1;d%=mod;
  }//int z=mod;cout<<z<<endl;
  //cout<<u%mod*f(mod-2,d)%mod<<endl;
  //cout<<u<<" "<<d<<endl;
  return u*f(mod-2,d)%mod;
}

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int ALL=f(n,2)-1;
  ALL-=choose(n,a);if(ALL<0){ALL+=mod;}
  ALL-=choose(n,b);if(ALL<0){ALL+=mod;}
  cout<<ALL<<endl;
  return 0;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func printX(b byte, x int) {
	for i := 0; i < x; i++ {
		fmt.Printf("%s", string(b))
	}
}

func main() {
	var sx, sy int
	var tx, ty int
	fmt.Scan(&sx, &sy, &tx, &ty)
	dx := tx - sx
	dy := ty - sy

	for i := 0; i < 2; i++ {
		printX('L', i)
		printX('U', dy+i)
		printX('R', dx+i)
		printX('D', i)
		printX('R', i)
		printX('D', dy+i)
		printX('L', dx+i)
		printX('U', i)
	}

	fmt.Printf("\n")
}


Measured memory_bytes: 896
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int d, t, s;
  cin >> d >> t >> s;
  if (s * t >= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
N, a, b = map(int, input().split())
mod = 10 ** 9 + 7
res = pow(2, N, mod) - 1
ta = 1 
for i in range(a):
  ta *= N - i
  ta %= mod
for i in range(a):
  ta *= pow(i + 1, mod - 2, mod)
  ta %= mod
tb = 1
for i in range(b):
  tb *= N - i
  tb %= mod
for i in range(b):
  tb *= pow(i + 1, mod - 2, mod)
  tb %= mod
print((res - ta - tb) % mod)

Measured memory_bytes: 40304
#include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int dp[2][2][5001],data[9999];
int main(){
  int n;
  cin >> n;
  fill_n(**dp,2*2*5001,INF);
  dp[0][0][0] = 0;
  for(int i = 1 ; i < n ; i++ ){
    cin >> data[i];
  }
  for(int i = 0 ; i < n ; i++ ){
    for(int j = 0 ; j <= min(n/2,i) ; j++ ){
      //dp[index+1][next(A)][Acost+1] = min(NoCut:dp[index][A][cost],Cut:dp[index][B][Acost] + data[index]);
      dp[(i+1)&1][0][j+1] = min(dp[i&1][0][j],dp[i&1][1][j]+data[i]);
      //dp[index+1][next(B)][Acost] = min(NoCut:dp[index][B][Acost],Cut:dp[index][B][Acost] + data[index]);
      dp[(i+1)&1][1][j] = min(dp[i&1][1][j],dp[i&1][0][j]+data[i]);
    }
    dp[(i+1)&1][0][0] = INF;
  }
  cout << min(dp[(n/2)%2][0][n/2],dp[(n/2)%2][1][n/2]) << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int n,m;
char a;
int board[100010];
int dp[100010];

int main()
{
	cin>>n>>m;
	getchar();
	for(int i=0; i<=n; i++)
	{
		scanf("%c",&a);
		board[i]=a-'0';
	}
//	for(int i=0; i<=n; i++)
//	{
//		cout<<board[i];
//	}
//	cout<<endl;
	for(int i=n; i>=0;)
	{
		int r=1;
		for(r=1; r<=m; r++)
		{
			if(board[i-r]==0)
			{
				dp[i]=r;
				if(i-r==0)
				{
					break;
				}
			}
		}
//		cout<<i<<" "<<dp[i]<<endl;
		if(i-dp[i]==0)
		{
			break;
		}
		if(dp[i]==0)
		{
			cout<<-1;
			return 0;
		}
		i=i-dp[i];
	}
	for(int i=0; i<=n; i++)
	{
		if(dp[i]!=0)
		{
			printf("%d ",dp[i]);
		}
	}
}

Measured memory_bytes: 1152
l, r = map(int, input().split())
r_ = min(r, l + 2019) + 1
min_score = 2019
for i in range(l, r_):
    for j in range(i + 1, r_):
        score = (i * j) % 2019
        min_score = min(min_score, score)
print(min_score)


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

void solve(long long N, string S){
	string res = "";
	int now = 0;
	for (int i=0; i<N; i++) {
		res = res + S[i];
		if (S[i] == '(') now++;
		if (S[i] == ')') {
			if (now > 0) now--; else {
				res = "(" + res;
			}	
		}
	}

	now = 0;
	S = res;
	res = "";

	for (int i=S.size()-1; i>=0; i--) {
		res = S[i] + res;
		if (S[i] == ')') now++;
		if (S[i] == '(') {
			if (now > 0) now--; else {
				res = res + ")";
			}	
		}
	}

	cout << res << endl;
}

int main(){	
	long long N;
	string S;
	scanf("%lld",&N);
	cin >> S;
	solve(N, S);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long a[5]={},n,i;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        if(s=="AC")
            a[0]++;
        else if(s=="WA"){
            a[1]++;
        }
        else if(s=="TLE"){
            a[2]++;
        }
        else if(s=="RE"){
            a[3]++;
        }
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

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

    vector<string> s;

    rep(i,h){
        string tmp;
        cin >> tmp;
        s.pback(tmp);
    }

    int yoko[2000][2000] ={};
    int tate[2000][2000] ={};

    rep(i,h){
        int count = 0;
        rep(j,w){
            if(s[i][j] == '#'){
                count = 0;
            }else{
                count++;
            }
            yoko[i][j] = count;
        }
    }


    rep(i,h){
        int tmp;
        for(int j = w - 1; j >= 0; j--){
            if(yoko[i][j] == 0){
                tmp = 0;
            }else{
                tmp = max(tmp, yoko[i][j]);
                yoko[i][j] = tmp;
            }
        }
    }

    rep(j,w){
        int count = 0;
        rep(i,h){
            if(s[i][j] == '#'){
                count = 0;
            }else{
                count++;
            }
            tate[i][j] = count;
        }
    }

    rep(j,w){
        int tmp;
        for(int i = h - 1; i >= 0; i--){
            if(tate[i][j] == 0){
                tmp = 0;
            }else{
                tmp = max(tmp, tate[i][j]);
                tate[i][j] = tmp;
            }
        }
    }

    int ans = 0;

    rep(i,h){
        rep(j,w){
            ans = max(ans, yoko[i][j] + tate[i][j] - 1);
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 37632
N = int(input())
P = [0]
for i in range(N):
  P.append(int(input()))
Q = [0]*(N+1)
for i in range(1,N+1):
  Q[P[i]] = i
res = Q[1]
cnt = 0  
c = 1
for i in range(2,N+1):
  if res < Q[i]:
    c += 1
    res = Q[i]
    if i == N:
      cnt = max(cnt,c)
  else:
    cnt = max(cnt,c)
    c = 1
    res = Q[i]
ans = N-cnt
if N ==1:
  ans = 0    
print(ans)      

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

vl ans;
void dfs(ll x){
  ans.push_back(x);
  if(x > 3234566667) return;
  int a = x%10;
  dfs(x*10+a);
  if(a != 0) dfs(x*10+(a-1));
  if(a != 9) dfs(x*10+(a+1));
  return;
}

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

  ll k;
  cin >> k;

  REP(i,10){
    dfs(i);
  }
  sort(all(ans));
  //rep(i,k){
    //cout << ans[i] << endl;
  //}
  cout << ans[k-1] << endl;
}

Measured memory_bytes: 6512
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  const int N = 365, K = 26;
  vector<int> c(K);
  vector<vector<int>> s(N, vector<int>(K));
  cin >> c[0];
  for (int &x : c) cin >> x;
  for (auto &v : s) for (int &x : v) cin >> x;
  int score = 0;
  vector<int> last(K, -1);
  for (int i = 0; i < N; ++i) {
    int dec = 0;
    for (int j = 0; j < K; ++j) {
      dec += c[j] * (i - last[j]);
    }
    int t; cin >> t, --t;
    score += s[i][t] - dec + c[t] * (i - last[t]);
    last[t] = i;
    cout << score << '\n';
  }
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using ull = unsigned long long;
#define SHOW(x) std::cerr << #x << " = " << (x) << std::endl
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return os << "]";
}
int main()
{
    ull n;
    std::cin >> n;
    std::vector<ull> l(n);
    std::vector<ull> w(n);
    for (ull i = 0; i < n; i++) {
        std::string s;
        std::cin >> s;
        l[i] = s.size();
        w[i] = std::bitset<16>(s).to_ullong();
    }
    constexpr ull inf = 1ULL << 50;
    using P           = std::pair<ull, ull>;
    using PP          = std::pair<ull, P>;
    std::priority_queue<PP, std::vector<PP>, std::greater<PP>> Q;
    std::vector<std::vector<ull>> dist(1 << 16, std::vector<ull>(16, inf));
    for (ull i = 0; i < n; i++) {
        for (ull j = i + 1; j < n; j++) {
            ull li = l[i];
            ull wi = w[i];
            ull lj = l[j];
            ull wj = w[j];
            if (li < lj) { std::swap(wi, wj), std::swap(li, lj); }
            wj <<= (li - lj);
            ull mask = wi ^ wj;
            mask >>= (li - lj);
            if (mask == 0) {
                Q.push({lj, {wi - wj, li - lj}});
                dist[wi - wj][li - lj] = lj;
            }
        }
    }
    while (not Q.empty()) {
        const auto p = Q.top();
        Q.pop();
        const ull d = p.first;
        const ull x = p.second.first;
        const ull s = p.second.second;
        if (dist[x][s] < d) { continue; }
        for (ull i = 0; i < n; i++) {
            ull li = l[i];
            ull wi = w[i];
            ull lj = s;
            ull wj = x;
            if (li < lj) { std::swap(wi, wj), std::swap(li, lj); }
            wj <<= (li - lj);
            ull mask = wi ^ wj;
            mask >>= (li - lj);
            if (mask == 0) {
                if (dist[wi - wj][li - lj] <= d + lj) { continue; }
                dist[wi - wj][li - lj] = d + lj;
                Q.push({d + lj, {wi - wj, li - lj}});
            }
        }
    }
    std::cout << (dist[0][0] >= inf ? 0 : dist[0][0]) << std::endl;
    return 0;
}



Measured memory_bytes: 13760
// ~zaletaet~

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define bpc __builtin_popcountl
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
struct chash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + RANDOM);
  }
};

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const db EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int32_t main() {
  fre("");
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
  int n;
  cin >> n;
  vector<int> a(n);
  int Xor = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    Xor ^= a[i];
  }
  
  for (int i = 0; i < n; i++)
    cout << (Xor ^ a[i]) << ' ';
  
  return 0;
}

// uniform_int_distribution<int>(l, r)(rng) -> random in range [l, r]
// assert(condition) -> if (condition == false) Runtime Error
// order_of_key(x) -> number of elements smaller than x
// *find_by_order(k) -> k-th element in 0-based indexation
// gp_hash_table<T, U, chash> -> fast unordered_map
// m.count(x) <-> (m.find(x) != m.end())


Measured memory_bytes: 4032
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int N = 200'009;

int w[N];
int f[N];

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    --x;
    if (a.empty() || x != a.back()) {
      a.push_back(x);
    }
  }
  const int mod = 1'000'000'007;
  memset(w, 0, sizeof w);
  f[(int)a.size()] = 1;
  for (int i = (int)a.size() - 1; i >= 0; --i) {
    w[a[i]] = (w[a[i]] + f[i + 1]) % mod;
    f[i] = w[a[i]];
  }
  printf("%d\n", f[0]);
}


Measured memory_bytes: 2676
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

char buf[110][110];
int main(void) {
  int nRow, nCol;
  scanf("%d%d", &nRow, &nCol);
  REP(i, nRow) {
    scanf("%s", buf[i]);
  }
  REP(i, nRow) {
    bool need = false;
    REP(j, nCol) {
      if(buf[i][j] == '#') {
        need = true;
      }
    }
    if(!need) {
      continue;
    }

    REP(j, nCol) {
      need = false;
      REP(ii, nRow) {
        if(buf[ii][j] == '#') {
          need = true;
        }
      }
      if(need) {
        putchar(buf[i][j]);
      }
    }
    puts("");
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
  int D, E;
  while(1){
    cin>>D>>E;
    if(!D && !E) return 0;
    double dist, diff, min_diff = 100.0, d_x;
    for (int x=0;x<=D/2;x++){
      d_x = (double)x;
      dist = sqrt(pow(d_x, 2) + pow((D - d_x), 2));
      diff = abs(dist - E);
      if(min_diff > diff) min_diff = diff;
    }
    printf("%.10f\n", min_diff);
  }
}



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

int main()
{
    int a, b, h, m;

    double result, h_degrees, m_degrees;

    cin >> a >> b >> h >> m;

    m_degrees = (m/60.0)*360.0;
    h_degrees  = (h/12.0)*360 + (m/60.0)*30;

    result = a*a + b*b - 2*a*b*cos(abs(m_degrees - h_degrees)*(M_PI/180));

    printf("%.10lf\n",sqrt(result));
    //cout << (double)sqrt(result) << endl;
    return 0;
}

Measured memory_bytes: 4044
from collections import Counter


def nC2(n):
  return n * (n - 1) // 2


N = int(input())

strings = []

for _ in range(N):
  strings.append(''.join(sorted(input())))

counter = Counter(strings)  
                 
print(sum(nC2(n) for n in counter.values()))                                         
        

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
  	cin >> n;
  	vi d(n);
  	rep(i,n) cin >> d[i];
  	sort(all(d));
  	int m = n/2;
  	cout << d[m] - d[m-1] << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
typedef long long ll;
using namespace std;
int v[10001], w[10001];
ll cache[101][100001];

ll calc(int W, int n) {
	if(W < 0) {
		return INT_MIN;
	}
	
	if(n==0 || W==0) {
		return 0;
	}
	
	if(cache[n][W]!=-1) {
		return cache[n][W];
	}
	
	if(W < w[n-1]) {
		return cache[n][W] = calc(W, n-1);
	}
	
	cache[n][W] = max(calc(W-w[n-1], n-1) + v[n-1], calc(W, n-1));
	return cache[n][W];
}
int main() {
	int n,W;
	cin>>n>>W;   
	for (int i=0; i<n; i++) {
		cin>>w[i]>>v[i];
	}
	
	for (int i=0; i<=n; i++) {
		for (int j=0; j<=W; j++) {
			cache[i][j] = -1;
		}
	}
	
	cout << calc(W,n);
	return 0;
}

Measured memory_bytes: 79104
n, m=map(int, input().split())
x=list(map(int, input().split()))

if n>=m:
    print(0)
else:
    x.sort()
    dif=[]
    for i in range(m-1):
        dif.append(x[i+1]-x[i])
    
    dif.sort()
    S=sum(dif)
    remove=0
    
    for j in range(1, n):
        remove+=dif[-j]

    print(S-remove)

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

const int maxn = 770;

vector<pair<int, int>> ans;
bool edge[maxn][maxn];
vector<int> g[maxn];
int col[maxn];
int c[3];
bool f[maxn];
bool gg[maxn];

inline bool dfs(int u) {
	++ c[col[u]];
	for(auto v : g[u]) {
		if(col[v]) {
			if(col[u] == col[v]) return false;
			continue;
		}
		col[v] = 3 - col[u];
		if(!dfs(v)) return false;
	}
	return true;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	int u, v;
	while(m --) {
		cin >> u >> v;
		edge[u][v] = edge[v][u] = true;
	}
	for(int i = 1; i <= n; ++ i) for(int j = 1; j <= n; ++ j) if(i != j && !edge[i][j]) g[i].push_back(j);
	bool flag = true;
	for(int i = 1; i <= n; ++ i) {
		if(!col[i]) {
			c[1] = c[2] = 0;
			col[i] = 1;
			flag &= dfs(i);
			ans.emplace_back(c[1], c[2]);
		}
	}
	f[0] = true;
	for(auto cur : ans) {
		for(int i = 0; i <= n; ++ i) gg[i] = false;
		for(int i = 0; i <= n; ++ i) {
			if(i >= cur.first) gg[i] |= f[i - cur.first];
			if(i >= cur.second) gg[i] |= f[i - cur.second];
		}
		for(int i = 0; i <= n; ++ i) f[i] = gg[i];
	}
	long long ans = LLONG_MAX;
	for(int i = 0; i <= n; ++ i) {
		long long res;
		if(f[i]) {
			res = 1LL * i * (i - 1) / 2 + 1LL * (n - i) * (n - i - 1) / 2;
			ans = min(ans, res);
		}
	}
	if(!flag) ans = -1;
	cout << ans;
	return 0;
}


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

const int MAX = 26;
int H, W;
string A[MAX][MAX];

void input()
{
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}

void solve()
{
	int ans_i, ans_j;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == "snuke") {
				ans_i = i + 1;
				ans_j = j + 65; //大文字に変換
			}
		}
	}
	printf("%c%d\n", (char)ans_j,ans_i);

}

int main()
{
	input();
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {

    string S, T;
    int q;
    cin >> S >> T >> q;
    vector<int> s(S.length() + 1, 0), t(T.length() + 1, 0);
    rep(i,S.length()) s[i + 1] = S[i] == 'A' ? 1 : 2;
    rep(i,T.length()) t[i + 1] = T[i] == 'A' ? 1 : 2;

    vector<int> sum_S(S.length() + 1, 0), sum_T(T.length() + 1, 0);
    for (int i = 1; i <= S.length(); i++) sum_S[i] = sum_S[i - 1] + s[i];
    for (int i = 1; i <= T.length(); i++) sum_T[i] = sum_T[i - 1] + t[i];

    rep(i,q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int ms = sum_S[b] - sum_S[a - 1];
        int mt = sum_T[d] - sum_T[c - 1];
        if (ms % 3 == mt % 3) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 5112
////=====BIsmillahir Rahmanir Rahim =====////

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
         Comilla University

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define fi 2*acos(0.0)
#define ll  long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define edl printf("\n")
#define infinity 1e16
#define mod 1000000007
#define cn continue
#define csprint1 printf("Case %lld: ", cs++)
#define csprint2 printf("Case %lld:\n", cs++)
#define sf(a) scanf("%lld", &a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define all(v) v.begin(),v.end()
#define pfn(a) printf("%lld\n",a)
#define pfs(a) printf("%lld ",a)

using namespace __gnu_pbds;
using namespace std;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<pl> vpi;
typedef vector<pl> vpl;
typedef tree<pair<ll, int> , null_type, less<pair<ll, int> >, rb_tree_tag, tree_order_statistics_node_update> ost;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a <<","<< spc;
    err(++it, args...);
    cout<<edl;
}
///Bit manipulation

bool checkbit(int mask,int bit){return mask & (1<<bit);}
int setbit(int mask,int bit){ return mask | (1<<bit) ; }
int clearbit(int mask,int bit){return mask & ~(1<<bit);}
int togglebit(int mask,int bit){return mask ^ (1<<bit);}
int bitno(int mask) {return (int)__builtin_popcount(mask);}

/*----------------------Graph Moves----------------*/
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

///=====================================///

const int  maX=2e5+10;
ll dp[maX];
int main(){
    ll n,w;sff(n,w);
    ll ara[n],pro[n];
    for(ll i=0;i<n;i++)sff(ara[i],pro[i]);
    for(ll i=n-1;i>=0;i--){
        for(ll j=w;j>=0;j--){
            dp[j+ara[i]]=max(dp[j+ara[i]],pro[i]+dp[j]);
            //cout<<j+ara[i]<<"->"<<dp[j+ara[i]]<<spc;
        }
       // cout<<endl;
    }
    ll mx=0;
    for(ll i=0;i<=w;i++)mx=max(mx,dp[i]);
    //cout<<endl;
    pfn(mx);
return 0;
}


Measured memory_bytes: 5288
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var s = input[0];
	var w = toInt(input[1]);
	var n = s.length;
	var ans = '';
	for(var i = 0; i < n; i+=w){
		ans += s[i];
	}

	console.log(ans);
}

Measured memory_bytes: 21064
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
  int N;
  long long H;
  cin>>N>>H;
  long long a[100000],b[1000000];
  long long M=0;
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i];
    if(a[i]>M) M=a[i];
  }
  sort(b,b+N);
  long long answer=0;
  int j=N-1;
  while(H>0&&j>=0&&b[j]>M){
    H-=b[j];
    answer++;
    j--;
  }
  if(H>0) answer+=(H+M-1)/M;
  cout<<answer<<endl;
  
  return 0;
}

Measured memory_bytes: 4764
while True:
    h, w = list(map(int, input().split()))
    if h == 0 and w == 0:
        break
    for i in range(h):
        s = ''
        if i % 2 == 0:
            for j in range(w):
                if j % 2 == 0:
                    s += '#'
                else:
                    s += '.'
            print(s)
        else:
            for j in range(w):
                if j % 2 == 0:
                    s += '.'
                else:
                    s += '#'
            print(s)
    print()



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int max_num = 1000000;
    vector<bool> isPrime(max_num+1, true);
    isPrime[0] = isPrime[1] = false;

    for (int i=0; i*i<=max_num; i++) {
        if (!isPrime[i]) continue;
        for (int j=i*i; j<=max_num; j+=i) {
            isPrime[j] = false;
        }
    }

    while(true) {
        int a, d, n; cin >> a >> d >> n;
        if (a+d+n == 0) break;

        while (n) {
            if (isPrime[a]) n--;
            if (n) a += d;
        }
        
        cout << a << endl;
    }
}


Measured memory_bytes: 3316
H,W,K = map(int, input().split())

edge = [["#" for _ in range(W+2)]]
center = [["#"] + list(input()) + ["#"] for i in range(H)] #提出用

c = edge + center + edge

N = H + W
ans = 0

for i in range(2**(N)):
    bit_array = str(bin(i)[2:]).zfill((N))
    #print(bit_array)
    black = 0
    #bit_arrayをH,W分にそれぞれ分解
    H_bit = [0] + list(bit_array[0:H])
    W_bit = [0] + list(bit_array[H:])
    #print(H_bit,W_bit)

    for j in range(1,H+1):
        if H_bit[j] != "1":
            for k in range(1,W+1):
                if W_bit[k]!="1" and c[j][k]=="#":
                    black += 1
        if black > K:
            break
    
    if black == K:
        ans += 1

print(ans)

Measured memory_bytes: 9244
function main()
    n = parse(Int, readline())
    if n == 0
        println(0)
        return
    end
    ans = []
    while n != 0
        val = n % (-2)
        if n < 0
            n -= 1
        end
        n ÷= -2
        if val < 0
            val += 2
        end
        if val == 1
            push!(ans,'1')
        else
            push!(ans,'0')
        end
    end
    reverse!(ans)
    for val in ans
        print(val)
    end
    print("\n")
end

main()


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

int main() {
    int n;
    cin >> n;
    vector<int> v(n); for(auto& i: v) cin >> i;
    int wanted = 1;
    
    int ans = n;
    for(auto& i: v) {
        if(i == wanted) {
            ++wanted;
            --ans;
        }
    }
    if(ans == n) ans = -1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#49c
S = str(input()) #1≦|S|≦10**5
#Tが空文字列である状態から始め、以下の操作を好きな回数繰り返すことで S=Tとすることができるか判定してください。
#    Tの末尾に dream dreamer erase eraser のいずれかを追加する。

#末尾から見ていく
i = len(S) - 5
if i < 0:
    print("NO")
else:
    while i >= 0:
        end_5_char = S[i:i+5]

        #print(i,end_5_char)

        if end_5_char == "eamer":
            #print(i,S[i-2:i])
            if i < 2 or S[i-2:i] != "dr":
                print("NO")
                break
            else:
                i -= 2
        elif end_5_char == "raser":
            #print(i,S[i-1:i])
            if i < 1 or S[i-1:i] != "e":
                print("NO")
                break
            else:
                i -= 1
        elif end_5_char != "dream" and end_5_char != "erase":
            print("NO")
            break

        i -= 5
    else:
        print("YES")

Measured memory_bytes: 3188
#f dp
n = int(input())
a = list(map(int, input().split()))
DIM, PER = 0, 1
MIN, MAJ = 0, 1
# pick from 0~i
# j = DIM or PER if i is odd, MIN or MAJ otherwise
dp = [[None, None] for _ in range(n)]
dp[0] = [0, a[0]]
dp[1] = [0, max(a[0], a[1])]
for i in range(2, n):
    if i % 2 == 0:
        dp[i][MIN] = max(dp[i - 2][MIN] + a[i], dp[i - 1][PER])
        dp[i][MAJ] = dp[i - 2][MAJ] + a[i]
    else:
        dp[i][DIM] = max(dp[i - 2][DIM] + a[i], dp[i - 1][MIN])
        dp[i][PER] = max(dp[i - 2][PER] + a[i], dp[i - 1][MAJ])
if n % 2 == 0:
    print(dp[n - 1][PER])
else:
    print(dp[n - 1][MIN])

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((a+b) > (c+d)) cout << "Left\n";
    else if ((a+b) == (c+d)) cout << "Balanced\n";
    else cout << "Right\n";
}

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

count = 0

for i in range(n - 1):
    minx = i
    for j in range(i + 1,n):
        if x[j] < x[minx]:
            minx = j
        
    if not i == minx:
        x[i],x[minx]=x[minx],x[i]
        count += 1

x = list(map(str,x))
print (" ".join(x))
print(count)

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

n = int(input())

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

m = p[0]

l = []

for x in p:
    m = min(m, x)
    l.append(m)

s = 0

for i in range(n):
    if p[i] == l[i]:
        s += 1

print(s)

Measured memory_bytes: 80464
#include<bits/stdc++.h>
using namespace std;
int j;
string s;
int main()
{
	getline(cin,s);
	int len=s.size();
	for(int i=0;i<s.size();i++)
	{
		if(s[i]==',')  cout<<" ";
		else cout<<s[i];
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.



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

    vector< pair <long long int,long long int> > vect;
    long long a,b;
    for (int i = 0; i < m; ++i)
    {
      cin>>a>>b;
      vect.push_back( make_pair(a,b) );
    }


    long long int grp[n+1];
    vector<int> lst[n+1];
    for (int i = 1; i <= n; ++i)
    {
      grp[i] = i;
      lst[i].push_back(i);
    }


    long long int sze[n+1];
    for (int i = 0; i <= n; ++i)
    {
      sze[i] = 1;
      
    }

    long long int ini;
    ini = (n*(n-1))/2;

    long long int evl[m+1];
    evl[m] = ini;

long long int mx, mn;
    for (int i = m-1; i >= 1; --i)
    {
      if (grp[vect[i].first] != grp[vect[i].second])
      {
  
        evl[i] = evl[i+1] - sze[grp[vect[i].first]]*sze[grp[vect[i].second]];

        mx = (sze[grp[vect[i].first]] >= sze[grp[vect[i].second]]) ? grp[vect[i].first]:grp[vect[i].second];
        mn = (sze[grp[vect[i].first]] < sze[grp[vect[i].second]]) ? grp[vect[i].first]:grp[vect[i].second];
        for (int j = 0; j < lst[mn].size(); ++j)
        {   
            grp[lst[mn][j]] = mx;
            lst[mx].push_back(lst[mn][j]);
        }

        sze[mx] = sze[mx] + sze[mn];


      }

      else{

          evl[i] = evl[i+1];
      }
    }

    for (int i = 1; i <= m; ++i)
    {
      cout << evl[i]<<endl;
    }
    


   

}

Measured memory_bytes: 14832
#include<stdio.h>
 
int main(){
    int i/*,flag*/;
    float x[4],y[4],a;
 
    while(1){
 
        for(i = 0/*,flag = 0*/;i < 4;i++){
            if(scanf("%f%f",&x[i],&y[i]) == EOF){
                /*
                flag = 1;
                break;
                */
                return 0;
            }
        }
        /*
        if(flag){
            flag = 0;
            break;
        }
        */
        /*
        if(x[0] == x[1] && y[2] == y[3]){
            puts("YES");
        }else if(x[2] == x[3] && y[0] == y[1]){
            puts("YES");
        }else if(x[0] == x[1] || x[2] == x[3]){
            puts("NO");
        }else{
            */
            a = (y[1] - y[0]) * (y[3] - y[2]) + (x[1] - x[0]) * (x[3] - x[2]);
            if(a==0){
                puts("YES");
            }else{
                puts("NO");
            }
        //}
    }

    return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<queue>
#include<utility>
#include<set>
using namespace std;
using ll = long long;

int main(){
    ll n,point;
    string str;
    vector<int> a;
    map<pair<string,int>,int> mp;
    cin >> n;
    priority_queue<pair<string,int>> p;
    for(ll i=0;i<n;i++){
        cin >> str >> point;
        p.push(make_pair(str,point*-1));
        mp[make_pair(str,point)] = i+1;
    }
    for(int i=0;i<n;i++){
        auto q = p.top();
        p.pop();
        q.second*=-1;
        a.push_back(mp[q]);
    }
    for(int i=n-1;i>=0;i--){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

/* main */

int main(int argc, char **argv) {
  int d1, d2, i, max_d, max_p, n, p;

  while (1) {
    scanf("%d", &n);
    if (n == 0) break;

    max_d = max_p = -1;

    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &p, &d1, &d2);

      if (max_d < d1 + d2) {
        max_d = d1 + d2;
        max_p = p;
      }
    }

    printf("%d %d\n", max_p, max_d);
  }

  return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    cin >> N;
    ll out = 0;
    if(N%2==0){
        ll n = N;
        n = N/10;
        out += n;
        while(n>0){
            n /= 5;
            out += n;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int>A(N + 1);
  vector<int>B(N + 1);
  vector<int>C(N + 1);
  for (int i = 1; i <= N; i ++) cin >> A[i];
  for (int i = 1; i <= N; i ++) cin >> B[i];
  for (int i = 1; i < N; i ++) cin >> C[i];
  int ans = 0;
  int pre = -1;
  for (int i = 1; i <= N; i ++) {
    ans += B[A[i]];
    if (pre == A[i] - 1) ans += C[A[i] - 1];
    pre = A[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
int main(){
   int a,b,c;
   scanf("%d %d %d\n",&a,&b,&c);
   if(a==b && a==5 && c==7||a==5 && a==c && b==7 ||a==7 && b==c && b==5)
     printf("YES");
   else
     printf("NO");
}

Measured memory_bytes: 128
// ABC179A - 

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	string S;
	cin >> S;

	if (S[S.length()-1] == 's') {
		cout << S + "es" << endl;
	} else {
		cout << S + "s" << endl;
	}

	return 0;
}


Measured memory_bytes: 3632
import collections

n = int(input())

strs = [ input() for _ in range(n) ]

cntr = collections.Counter(strs)

maxvalue = 0
ans = []
for st, num in cntr.most_common():
    if maxvalue <= num:
        ans.append(st)
        maxvalue = num
    else:
        break

for s in sorted(ans):
    print(s)


Measured memory_bytes: 45040
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;



int main() {

    int h =0;
    int n =0;
    cin >> h >> n;

    vector<int> a(n);

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

    int sum =0;
    for(int i=0;i < n;i++){

        sum = sum + a[i];
    }

    if(sum >= h){
        cout <<"Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;

}
   

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#include<string>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main()
{
    ll N, K;   cin >> N >> K;
    vector<ll> p(N), c(N), cycle(N);
    vector<int> rot(N);
    ll m[N][min(N,K)];
    // cycle[i] i番目からはじめて周回したときに稼ぐ点数
    // rot[i] i番目からはじめて周回するまでの回数
    // m[i][j] iからはじめてj回して何点持っているか
    for(int i=0; i<N; i++)  cin >> p[i];
    for(int i=0; i<N; i++)  cin >> c[i];

    ll tmp, ans;
    int now, r;
    ans = -MOD;
    for(int i=0; i<N; i++){
        now = i;
        tmp = 0;
        for(int j=0; j<min(K,N); j++){
            now = p[now] - 1;
            tmp += c[now];
            r = j;
            m[i][j] = tmp;
            if(now == i)    break;  //周回したら終了
        }
        cycle[i] = tmp;
        rot[i] = r+1;
    }
    ans = -MOD;
    for(int i=0; i<N; i++){
        for(int j=0; j<rot[i]; j++){
            tmp = m[i][j];
            if(cycle[i] > 0 && K-j-1>0)    tmp += (K-j-1)/rot[i]*cycle[i];
            ans = max(ans,tmp);
        }
    }
    cout << ans;
}

Measured memory_bytes: 199028
using System;

namespace B____Painting_Balls_with_AtCoDeer
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var k = int.Parse (input[1]);
            Console.WriteLine (k * Math.Pow (k - 1, n - 1));
        }
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int pay = 1000;
		int ans = 0;
		for (int i = 1;i <= 10 ;i++ ) {
			if (pay >=N) {
				ans = pay - N;
				break;
			}
			pay+=1000;
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 35616
#include<bits/stdc++.h>
using namespace std;
int x,y;
int main()
{
	cin>>x>>y;
	if(x>=3)
	{
		if(x%3==0)
		{
			cout<<"Possible"<<endl;
			return 0;
		}
	}
	if(y>=3)
	{
		if(y%3==0)
		{
			cout<<"Possible"<<endl;
			return 0;
		}
	}
	if((x+y)>=3)
	{
		if((x+y)%3==0)
		{
			cout<<"Possible"<<endl;
			return 0;
		}
	}
	if((x+y)<3)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Impossible"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
char buf[20000];sz;
inline int rd()
{
	int ret=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		ret=ret*10+k-'0';
	}
	return ret;
}
int d[3001],d2[3001];
const int mod=998244353;
main()
{
	read(0,buf,20000);
	int N=rd();
	int S=rd();
	int ans=0;
	for(int i=0;i<N;i++)
	{
		++d[S];
		int A=rd();
		for(int j=0;j<=S-A;j++)d2[j]=d[j+A];
		for(int j=0;j<=S-A;j++)
		{
			d[j]+=d2[j];
			d[j]-=mod*(d[j]>=mod);
		}
		ans+=d[0];
		ans-=mod*(ans>=mod);
	}
	printf("%d",ans);
}

Measured memory_bytes: 256