akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N, K;
  std::cin >> N >> K;

  ll num = 1LL;
  ll ans = 0LL;
  for (ll i = 1; i < 40; i++) {
    num *= K;
    if (num > N) {
      ans = i;
      break;
    }
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

main()

Measured memory_bytes: 4468
#include<bits/stdc++.h>
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define v(i) vector<i>
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORE(i,a,b) for(i=a;i<=b;i++)
#define FORV(i,a,b) for(i=a;i>b;i--)
#define FOREV(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define look(v) for(auto c:v) cout<<c<<" "; cout<<"\n";
#define dfdc int i,j,k,m,n,ct=0;string s;
#define ppl(a,st,end) for(i=st;i<=end;i++)cin>>a[i];
#define fz(a) memset(a,0,sizeof a);
#define dp_1(n) int dp[n];fz(dp);
#define dp_2(m,n) int dp[m][n];fz(dp);
#define arpt(a,s,e) for(i=s;i<=e;i++) cout<<a[i]<<" ";cout<<"\n";
#define tk int t;cin>>t;while(t--)
 
using namespace std;
 
typedef long long int ll;
 
int h,w;

int main(){
    fastio
  	cin>>h>>w;
  	vector<vector<char>> vec(h,vector<char>(w,'\0'));
  	int ch,cw,dh,dw;
  	cin>>ch>>cw;
  	cin>>dh>>dw;
  	for(int i=0;i<h;i++){
  		for(int j=0;j<w;j++){
  			cin>>vec[i][j];
  		}
  	}
  	priority_queue<pair<int,pair<int,int>>> q;
  	vector<vector<int>> d(h,vector<int>(w,-1));
  	vector<vector<bool>> vis(h,vector<bool>(w,false));
  	d[ch-1][cw-1] = 0;
  	q.push({0,{ch-1,cw-1}});
  	while(!q.empty()){
  		auto pp = q.top();
  		q.pop();
  		int dist = -pp.first;
  		int X = pp.second.first;
  		int Y = pp.second.second;
  		//cout<<X<<" "<<Y<<"\n";
  		if(!vis[X][Y]){
  		    vis[X][Y] = true;
	  		for(int i=X-2;i<=X+2;i++){
	  			for(int j=Y-2;j<=Y+2;j++){
	  				if(i>=0 && j>=0 && i<h && j<w && vec[i][j]!='#'){
	  					if(abs(i-X) + abs(j-Y)==1){
	  						if(d[i][j]!=-1){
	  							d[i][j] = min(d[i][j],dist);
	  						}
	  						else{
	  							d[i][j] = dist;
	  						}
	  						q.push({-d[i][j],{i,j}});
	  					}
	  					else{
	  						if(d[i][j]!=-1){
	  							d[i][j] = min(d[i][j],1+dist);
	  						}
	  						else{
	  							d[i][j] = 1+dist;
	  						}
	  						q.push({-d[i][j],{i,j}});	
	  					}
	  				}
	  			}
	  		}
  		}
  	}
  	cout<<d[dh-1][dw-1]<<"\n";
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    vector<int> n(3);
    for(int i = 0; i < 3; i++){
        cin >> n[i];
    }
    sort(all(n));
    int diff = n[2] - n[0] + n[2] - n[1];
    int ans = diff / 2;
    if(diff % 2 != 0) ans += 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 int N=ir.nextInt();
 int[] s=ir.nextIntArray(N);
 long[] sum=new long[2*N+1];
 sum[0]=0;
 for(int i=1;i<=2*N;i++) sum[i]=sum[i-1]+(long)s[(i-1)%N];
 long ans=0;
 int l=0;
 int m=1;
 int r=2;
 while(true){
  if(r>=N) break;
  long a=sum[l+N]-sum[r],b=sum[r]-sum[m],c=sum[m]-sum[l],res;
  if(a<=b&&a<=c){
   res=a;
   if(m>l+1) l++;
   else {
    m++; l++;
   }
  }
  else if(b<=a&&b<=c){
   res=b;
   r++;
  }
  else{
   res=c;
   if(r>m+1) m++;
   else{
    r++; m++;
   }
  }
  ans=Math.max(ans,res);
 }
 out.println(ans);
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
 
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
 public boolean hasNext(){skip(); return hasNextByte();}
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
}
}

Measured memory_bytes: 27740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int k, n;
ll px[55];
ll py[55];

ll mycal(vl& cand) {
	sort(all(cand));
	ll ret = 1e18;
	for(int i=0; i+k<=sz(cand); ++i) {
		ret = min(ret, cand[i+k-1] - cand[i]);
	}
	return ret;
}

ll solve(int k) {
	vi order(n);
	rep(i,0,n) {
		order[i] = i;
	}
	sort(all(order), [&](int i, int j) {
		return px[i] < px[j];
	});
	ll ret = 4e18;
	for(int i=0; i+k<=n; ++i) {
		int idx = order[i];
		int jdx = order[i+k-1];
		ll w = px[jdx] - px[idx];
		vl cand;
		rep(j,i,i+k) {
			cand.pb(py[order[j]]);
		}
		ll h = mycal(cand);
		ret = min(ret, h * w);
	}
	sort(all(order), [&](int i, int j) {
		return py[i] < py[j];
	});
	for(int i=0; i+k<=n; ++i) {
		int idx = order[i];
		int jdx = order[i+k-1];
		ll h = py[jdx] - py[idx];
		vl cand;
		rep(j,i,i+k) {
			cand.pb(px[order[j]]);
		}
		ll w = mycal(cand);
		ret = min(ret, h * w);
	}
	return ret;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n >> k;
	rep(i,0,n) {
		cin >> px[i] >> py[i];
	}
	ll ret = solve(k);
	rep(i,k+1,n+1) {
		ret = min(ret, solve(i));
	}
	cout << ret << '\n';
	return 0;
}


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

#define LL long long
#define mod 1000000007
const int N = 1e6 + 5;
LL fac[N];

LL power(LL x, LL y){return y ? power(x * x % mod, y / 2) * (y % 2 ? x : 1) % mod : 1;}

LL modInverse(LL n) {return power(n, mod-2);} 
 
LL nCr(LL n, LL r) { 
    if (n < 0 || r < 0 || r > n) return 0;  
    return (fac[n]* modInverse(fac[r]) % mod * modInverse(fac[n-r]) % mod) % mod; 
} 


int main() {
    ios::sync_with_stdio(0), cin.tie(0);
     
    fac[0] = 1LL; 
    for (LL i = 1; i < N; ++i) fac[i] = fac[i-1] * i % mod;

    LL n, ans = 0; cin >> n;
    for(LL i = 2; i <= n; i++) {
        ans += (((nCr(n, i) * ((power(2, i) + mod - 2) % mod)) % mod) * power(8, n-i)) % mod;;
        ans %= mod;
    }
    cout << ans;
}


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

bool prime (ll a) {
  if (a == 2) {
    return true;
  }
  if (a%2 == 0) {
    return false;
  }
  double b = sqrt(a);
  for (int i = 3; i <= b; i += 2) {
    if (a%i == 0) {
      return false;
    }
  }
  return true;
}

int main () {
  ll x;
  cin >> x;
  
  while (!prime(x)) {
    x ++;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a , cnt = 0;
    cin >> a ;
    int b ;
    cin >> b ;
    for (int i = 1 ; i <=  b ; i ++ )
    {

        int d ;
        cin >> d ;
        cnt += d ;
    }
    if ( a -  cnt < 0 )
    {
        cout <<  "-1" ;
    }
    else {
        cout << a - cnt ;
    }

}


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

int main() {
    string N;
    int K;
    cin >> N >> K;

    int L = N.length();
    vector<vector<ll>> dp0(L, vector<ll>(K + 1, 0)); // N未満が未確定
    vector<vector<ll>> dp1(L, vector<ll>(K + 1, 0));
    dp0[0][1] = 1;
    dp1[0][0] = 1;
    dp1[0][1] = N[0] - '0' - 1;
    for (int i = 1; i < L; i++) {
        for (int k = 0; k <= K; k++) {
            if (N[i] != '0') {
                if (k == 0) {
                    dp0[i][k] = 0;
                } else {
                    dp0[i][k] += dp0[i - 1][k - 1];
                }
            } else {
                dp0[i][k] += dp0[i - 1][k];
            }
            dp1[i][k] += dp1[i - 1][k];
            if (k != 0) {
                dp1[i][k] += dp1[i - 1][k - 1] * 9;
            }

            if (N[i] != '0') {
                dp1[i][k] += dp0[i - 1][k];
                if (k != 0) {
                    dp1[i][k] += dp0[i - 1][k - 1] * (N[i] - '0' - 1);
                }
            }
        }
    }

    cout << dp0[L - 1][K] + dp1[L - 1][K] << endl;
}


Measured memory_bytes: 256
import sys


read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
s_readline = sys.stdin.readline

S = list(map(int, s_readline().rstrip()))
N = len(S)


def solve():

    ans = 0
    for i in range(N - 1):
        if S[i + 1] == S[i]:
            S[i + 1] = not S[i + 1]
            ans += 1

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

int N, M;

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};

int main() {
    cin >> N >> M;
    UnionFind uf(N);
    rep(i,M) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        uf.unite(a,b);
    }
    int res = 0;
    rep(i,N) {
        chmax(res, uf.size(i));
    }
    cout << res << endl;
}

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

int main(){
    long long k, n;

    cin >> k >> n;

    long long a[n+1];

    for(long long i = 1; i <= n; i++){
        cin >> a[i];
    }

    long long distance[n+1];

    for(long long i = 1; i <= n; i++){
        if(i == n){
            distance[i] = k - a[i] + a[1];
        }
        else{
            distance[i] = a[i+1] - a[i];
        }
    }

    long long maxv = 0;

    for(long long i = 1; i <= n; i++){
        maxv = max(distance[i], maxv);
    }

    printf("%lld\n", k-maxv);

    return 0;


}

Measured memory_bytes: 6876
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int a=sc.nextInt();
  int i;
  for(i=0;Math.pow(2,i+1)<=a;i++){}
    System.out.println((int)Math.pow(2,i));
}
}

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

using namespace std;

bool func(vector<int> v, int T){
	for(int i = 0;i < v.size();i++){
		if(v[i] > T){
			return true;
		}
	}
	return false;
}


int main(){
	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<int>> S(H, vector<int>(W));
	for(int i = 0;i < H;i++){
		string s;
		cin >> s;
		for(int j = 0;j < W;j++){
			if(s[j] == '1') S[i][j] = 1;
		}
	}

	int ans = 2000;
	for(int k = 0;k < pow(2, H-1);k++){
		int count = 0;
		int k_ = k;
		while(k_ > 0){
			if(k_ % 2 == 1){
				count++;
			}
			k_ /= 2;
		}

		vector<int> white(H);
		for(int w = 0;w < W;w++){
			int k_ = k;
			int ind = 0;
			vector<int> retu(H);
			for(int h = 0;h < H;h++){
				retu[ind] += S[h][w];
				if(k_ % 2 == 1){
					ind++;
				}
				k_ /= 2;
			}
			for(int i = 0;i < H;i++){
				white[i] += retu[i];
			}
			if(func(white, K)){
				if(func(retu, K)){
					count = 2000;
					break;
				}
				count++;
				for(int i = 0;i < H;i++){
					white[i] = retu[i];
				}
			}
		}
		ans = min(ans, count);
	}

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

Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    ld x = n / 3.0;
    cout << fixed << setprecision(9) << x * x * x;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<pair<int, int> > w;
  for(int i=0;i<m;i++){
    int a, b; cin >> a >> b;
    w.push_back(make_pair(a, b));
  }
  sort(w.begin(), w.end());
  pair<int, int> prev = make_pair(w[0].first, w[0].second);
  int cnt = 1;
  for(int i=1;i<m;i++){
    int pl = prev.first, pr = prev.second;
    // cout << pl << " " << pr << endl;
    int l = w[i].first, r = w[i].second;
    if(pr >= l && (max(pl, l) != min(pr, r))){
      prev = make_pair(max(pl, l), min(pr, r));
    }else{
      // pr < l
      cnt++;
      prev = make_pair(l, r);
    }
  }
  // cout << prev.first << " " << prev.second << endl;
  cout << cnt << endl;
}

Measured memory_bytes: 1400
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {  // O( log(a) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }  // O( log(a) )
bool isPrime(ll n) {                                  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) flag = false;
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a, b;
  vector<ll> sa, sb;
  for (int i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
    if (i == 0)
      sa.push_back(tmp);
    else
      sa.push_back(sa.back() + tmp);
  }
  for (int i = 0; i < m; i++) {
    ll tmp;
    cin >> tmp;
    b.push_back(tmp);
    if (i == 0)
      sb.push_back(tmp);
    else
      sb.push_back(sb.back() + tmp);
  }

  int ans = 0;
  int iOver = distance(sa.begin(), upper_bound(sa.begin(), sa.end(), k));
  for (int i = -1; i < iOver; i++) {
    int tmp;
    ll time_a;
    if (i == -1) {
      time_a = 0;
      tmp = 0;
    } else {
      time_a = sa.at(i);
      tmp = i + 1;
    }
    tmp += distance(sb.begin(), upper_bound(sb.begin(), sb.end(), k - time_a));
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

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

int main(){
  int n;string s;cin>>n>>s;
  bool f=0;
  REP(i,2) REP(j,2){
    string ans="";
    REP(k,n+1){
      if(k==0){
        if(i==0) ans.push_back('S');
        else ans.push_back('W');
      }else if(k==1){
        if(j==0) ans.push_back('S');
        else ans.push_back('W');
      }else{
        if(s.at(k-1)=='o'){
          if(ans.at(k-1)=='S') ans.push_back(ans.at(k-2));
          else{
            if(ans.at(k-2)=='S') ans.push_back('W');
            else ans.push_back('S');
          }
        }else{
          if(ans.at(k-1)=='S'){
            if(ans.at(k-2)=='S') ans.push_back('W');
            else ans.push_back('S');
          }else ans.push_back(ans.at(k-2));
        }
      }
    }
    if(ans.at(0)==ans.at(n)){
      if(ans.at(0)=='S'&&s.at(0)=='o'&&ans.at(n-1)==ans.at(1)) f=1;
      if(ans.at(0)=='S'&&s.at(0)=='x'&&ans.at(n-1)!=ans.at(1)) f=1;
      if(ans.at(0)=='W'&&s.at(0)=='o'&&ans.at(n-1)!=ans.at(1)) f=1;
      if(ans.at(0)=='W'&&s.at(0)=='x'&&ans.at(n-1)==ans.at(1)) f=1;
    }
    if(f){
      ans.pop_back();
      cout<<ans;
      return 0;
    }
  }
  cout<<("-1");
}

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

#define pb push_back
#define eb emplace_back

using namespace std;

using vi = vector<int>;
using ll = long long;

int main(){
    ios :: sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    n%=500;

    if(m>=n){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}


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

const int MOD = 1000000007;
int main() {
int n,m;
cin >> n >>m;
vector <int> dp(n+1,0);

rep(i,m)
{int a;
 cin >>a;
 dp[a]=-1;
 }

dp[0]=1;

if(dp[1]==-1)
dp[1]=0;
else
{
  dp[1]=1;
}//これを書いていたつもりが書いていなかった。という実装ミスに気がつくのに時間がかかった




for (int i = 2; i <= n; i++)
{
  if(dp[i]==-1)
  {dp[i]=0;}
  else
  {
  dp[i]=(dp[i-2]+dp[i-1]);
  }
  dp[i]%=MOD;
}
/*
rep(i,n+1)
{
  cout<<"dp["<<i<<"] = "<<dp[i]<<endl;
}*/


cout << dp[n] << endl;
return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,ans=1;
    cin >> n;
     for(int i=1;i<=n;i++){
         ans *= i;
         ans %= (int)mod;
     }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

int main(){
    int n;
    ll k;
    cin >> n >> k;

    vector<ll> a(n);
    loop(i,n) cin >> a[i];

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

    bool isLessThanK = false;
    ll result = 0;

    for(int i = 39; i >= 0; i--){
        // kより大きくなるかも→桁が0なら0,1なら比較
        // kより絶対に小さい→0と1を選べる
        if(isLessThanK){
            int count = 0;
            loop(j,n){
                count += a[j] >> i & 1;
            }
            if(count * 2 > n){
                result <<= 1;
                result += count;
            }else{
                result <<= 1;
                result += n - count;
            }
        }else{
            int count = 0;
            loop(j,n){
                count += a[j] >> i & 1;
            }
            if(k >> i & 1){
                if(count * 2 > n){
                    result <<= 1;
                    result += count;
                    isLessThanK = true;
                }else{
                    result <<= 1;
                    result += n - count;
                }
            }else{
                result <<= 1;
                result += count;
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 4048
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(3, 0);
  vector<bool> flag(3, true);
  bool check = true;
  int k, c;

  rep(i, M){
    cin >> k >> c;
    if (flag[k-1]) {
      flag[k-1] = false;
      a[k-1] = c;
    } else if (a[k-1] == c){// これは大丈夫
      continue;
    } else {
      check = false;
    }
  }

  
  // cout << check << endl;
  if (check){
    if (a[0] == 0) {
      if (N==1) {
        cout << a[0] << endl;
         return 0;
      } else if (flag[0]){
        a[0] = 1;
      } else {// 0から始まっちゃうとき
        cout << -1 << endl;
        return 0;
      }
   }
    rep(i, N){
      cout << a[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 1e5 + 7;

pair<int, int> dp[N][3];

bool in(pair<int, int> v, int x) {
	return v.first <= x && x <= v.second;
}

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

	int n, x, y, z;
	cin >> n >> x >> y >> z;
	dp[0][0] = {x, x};
	dp[0][1] = {y, y};
	dp[0][2] = {z, z};
	vector<int> a = {x, y, z};
	string ans;
	vector<string> kek(n);
	for (auto &s : kek) cin >> s;
	for (int i = 0; i < n; i++) {
		string s = kek[i];
		if (s == "AB") {
			if (x < y) {
				x++;
				y--;
				ans.push_back('A');
			} else if (x > y) {
				x--;
				y++;
				ans.push_back('B');
			} else {
				if (i + 1 < n && kek[i + 1] == "BC") {
					x--;
					y++;
					ans.push_back('B');
				} else {
					x++;
					y--;
					ans.push_back('A');
				}
			}
		} else if (s == "BC") {
			if (y < z) {
				y++;
				z--;
				ans.push_back('B');
			} else if (y > z) {
				y--;
				z++;
				ans.push_back('C');
			} else {
				if (i + 1 < n && kek[i + 1] == "AB") {
					y++;
					z--;
					ans.push_back('B');
				} else {
					y--;
					z++;
					ans.push_back('C');
				}
			}
		} else {
			if (x < z) {
				x++;
				z--;
				ans.push_back('A');
			} else if (x > z) {
				x--;
				z++;
				ans.push_back('C');
			} else {
				if (i + 1 < n && kek[i + 1] == "AB") {
					x++;
					z--;
					ans.push_back('A');
				} else {
					x--;
					z++;
					ans.push_back('C');
				}
			}
		}
		if (x < 0 || y < 0 || z < 0) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	for (auto t : ans) {
		cout << t << '\n';
	}
}


Measured memory_bytes: 6592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const ll inf = 1e18;
ll ans[maxn];
int main() {
    int n,x,y;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int pos = min(j-i,min(abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1));
            ans[pos]++;
        }
    }
    for(int i=1;i<=n-1;i++)
        cout<<ans[i]<<endl;
    return 0;
}



Measured memory_bytes: 256
"""
N, M = map(int, input().split( ))
a = []
for i in range(2):
    a.append(map(int, input().split( )))
print (a) 
# [[a11, a12, a13, ..., a1M]
#  [a21, a22, a23, ..., a2M]
#  ...
#  [aN1, aN2, aN3, ..., aNM]]
"""

result = 1001
A = input().split()
N = int(A[0])
T = int(A[1])
e =[]
e = [[i for i in input().split()] for i in range(N)] 

for i in range(N):
    if int(e[i][1]) <= T:
        temp = int(e[i][0])
        if result >int(e[i][0]): 
            result = int(e[i][0])

if result ==1001:
    result ="TLE"

print(result) 
#print(e[0][0])
#print(T)

Measured memory_bytes: 3064
import numpy as np
k, n = map(int, input().split())
a = np.array(list(map(int, input().split())))
a1 = np.zeros(1, dtype=int)
a1 = np.append(a1, a)
a2 = a
a2 = np.append(a2, a[0]+k)
print(k - max(a2[1:] - a1[1:]))

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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  string s; cin>>s;
  string ans="";
  rep(i,s.size())
  {
    if(s[i]=='B'&&ans=="") continue;
    else if(s[i]=='B') ans.pop_back();
    else ans+=s[i];
  }
  print(ans);

  return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="YES",no="NO";

int main() {
  int n;
  cin>>n;
  set<int> s;
  rep(i,n){
      int a;
      cin>>a;
      s.insert(a);
  }
  if((int)s.size()==n) cout<<yes<<endl;
  else cout<<no<<endl;

}


Measured memory_bytes: 12924
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int[] array = new int[5];
		int result = 0;
		
		for (int i = A; i <= B; i++) {
			int n = i;
			int c = 0;
			while (n > 0) {
				array[c] = n % 10;
				n /= 10;
				c++;
			}
			
			if (array[0] == array[4] && array[1] == array[3]) {
				result++;
			}
			
		}

		out.println(result);
		out.flush();
	}
}

Measured memory_bytes: 36204
#include <bits/stdc++.h>
#define var auto
using ll = long long;
const char newl = '\n';
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if(a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if(a < b) a = b;}

using namespace std;

bool solve(){
    int n;
    cin >> n;
    if (n == 0) return false;
    vector<string> a(n);
    vector<string> b(n);
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    string s, t;
    cin >> s >> t;
    if (s == t){
        cout << 0 << endl;
        return true;
    }
    unordered_set<string> se{t};
    vector<string> prev{t};
    for (int ctr = 1; ; ctr++){
        if (prev.size() == 0){
            cout << -1 << endl;
            return true;
        }
        vector<string> next{};
        for (auto&& curstr : prev){
            //cout << curstr << endl;
            for (int i = 0; i < n; i++){
                //generate next strings
                vector<string> beforereplace{curstr};
                for (int j = 0; j <= ((int)curstr.size()) - ((int)b[i].size()); j++){
                    if (curstr.substr(j, b[i].size()) == b[i]){
                        var tmp = beforereplace;
                        for (auto&& str : beforereplace){
                            if (str[j] == '#') continue;
                            var tmpstr = str;
                            for (int k = j; k < j + b[i].size(); k++){
                                tmpstr[k] = '#';
                            }
                            tmp.push_back(tmpstr);
                        }
                        beforereplace = move(tmp);
                    }
                }

                for (auto&& str : beforereplace){
                    for (int j = 0; j < str.size(); j++){
                        if (str[j] == '#') {
                            str.replace(j, b[i].size(), a[i]);
                            j += a[i].size() - 1;
                        }
                    }

                    string verify = "";
                    for (int j = 0; j < str.size(); j++){
                        if (j + a[i].size() <= str.size() && str.substr(j, a[i].size()) == a[i]){
                            verify += b[i];
                            j += a[i].size() - 1;
                        }
                        else verify += str[j];
                    }

                    if (verify != curstr) {
                        goto end;
                    }
                    if (str == s) {
                        cout << ctr << endl;
                        return true;
                    }
                    if (se.insert(str).second) next.push_back(str);
                    end:;
                }
            }
        }
        prev = move(next);
    }
}


signed main(){
    while (solve());
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	double long A = 0.0; 
	cin >> A;
	A = A / 10.0;
	double long B; cin >> B;
	B = B / 10.0;
	int64 ans = (A * B) * 100;
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    int N,M;
    cin>>N>>M;
    int A[100];
    int sum = 0;
    rep(i,N) {
        cin>>A[i];
        sum+=A[i];
    }
    int num = 0;
    rep(i,N){
        if(4*M*A[i] >= sum) num++;
    }   
    if(num>=M) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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


int main(){
    int n;
    cin >> n;

    pair <ll,ll> p[n];

    rep(i,n){
        ll x;
        ll l;
        cin >> x >> l;
        p[i]=make_pair(x+l,x-l);
    }

    sort(p,p+n);

    int ans=1; int t=p[0].first;
    for(int i=1;i<n;i++){
        if(t<=p[i].second){
            ans++;
            t=p[i].first;
        }
    }

    printf("%d\n",ans);
}

Measured memory_bytes: 1792
#include <iostream>
 
using namespace std;
const int MAXN = 100000;
int arr[MAXN], N;
 
int main() {
	cin >> N;
 
	for (int i = 0; i < N; ++i) {
		cin >> arr[i];
	}
	
	bool hl;
	int result = 0;
	if (N == 1) {
		cout << "1";
		return 0;
	}
	
	for (int i = 1; i < N; ++i) {		
		if (arr[i] == arr[i-1]) {
			if (i == N-1) {
				result += 1;
				break;
			}	
			continue;
		} else if (arr[i] >= arr[i-1]) {
			result += 1;
			while (arr[i] >= arr[i-1] && i != N) {
				i++;
			}
			if (i == N-1) {
				result += 1;
				break;
			}
			continue;
		} else if (arr[i] <= arr[i-1]) {
			result += 1;
			while (arr[i] <= arr[i-1] && i != N) {
				i++;
			}
			if (i == N-1) {
				result += 1;
				break;
			}
			continue;
		}
	}
	cout << result;
	return 0;
}

Measured memory_bytes: 640
input()
A=tuple(map(int,input().split()))
B=tuple(map(int,input().split()))

def solve(A,B):
    if sum(A)<sum(B):
        return -1
    ans=0
    s=0
    L=[]
    for a,b in zip(A,B):
        d=a-b
        if d<0:
            ans+=1
            s-=d
        else:
            L.append(d)
    if ans==0:
        return 0
    L.sort()
    t=0
    while t<s:
        t+=L.pop()
        ans+=1
    return ans

print(solve(A,B))

Measured memory_bytes: 86064
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var line = Console.ReadLine();
        var N = int.Parse(Console.ReadLine());
        HashSet<string> subStrings = new HashSet<string>();
        for (int i = 0; i < line.Length; i++)
        {
            string str = "";
            for (int j = i; j < Math.Min(i+N,line.Length); j++)
            {
                str = string.Concat(str, line[j].ToString());
                subStrings.Add(str);
            }
        }
        Console.WriteLine(string.Join("\n",subStrings.OrderBy(x=>x).ToArray()[N-1]));
    }
}

Measured memory_bytes: 13664
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll a, b, c, d, A, B, C, D;
  cin >> a >> b >> c >> d;
  
  A = a * c;
  B = a * d;
  C = b * c;
  D = b * d;
  
  if(A >= B && A >= C && A >= D){
    cout << A;
  }
  else if(B >= A && B >= C && B >= D){
    cout << B;
  }
  else if(C >= B && C >= A && C >= D){
    cout << C;
  }
  else{
    cout << D;
  }
}

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

int a, b;

int main() {
	cin >> a >> b;
	if (a <= 0 && 0 <= b) { cout << "Zero" << endl; return 0; }
	if (a > 0) { cout << "Positive" << endl; return 0; }
	int cnt = min(b, -1) - a + 1;
	if (cnt % 2) { cout << "Negative" << endl; return 0; }
	cout << "Positive" << endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int main(){
  int h,w,k,sx,sy;
  cin>>h>>w>>k;
  string s[h];
  r(i,h)cin>>s[i];
  r(i,h)r(j,w)if(s[i][j]=='S')sy=i,sx=j;
  int a[h][w]={},used[h][w],uused[h][w];
  memset(uused,0,sizeof(uused));
  memset(used,0,sizeof(used));
  vector<pair<int,int> >v;v.push_back(mk(sy,sx));
  vector<pair<int,int> >v1;v1.push_back(mk(sy,sx));
  if(sy==0||sx==0||sy==h-1||sx==w-1){cout<<0<<endl;goto L;}
  uused[sy][sx]=1;
  for(int o=1;o<1000;o++){
    queue<pair<pair<int,int>,int> >qq;
    r(tt,v.size())qq.push(mk(mk(v[tt].fi,v[tt].se),0));
    while(!qq.empty()){
      pair<pair<int,int>,int>p=qq.front();qq.pop();
      if(p.fi.fi==0||p.fi.fi==h-1||p.fi.se==0||p.fi.se==w-1){
        cout<<o<<endl;
        goto L;
      }
      if(p.se>=k)continue;
      r(i,4){
        int x=p.fi.se+dx[i],y=p.fi.fi+dy[i];
        if(x>=0&&y>=0&&y<h&&x<w)
          if(!uused[y][x]){
            if(s[y][x]=='.'){
              if(!a[y][x]){
                 uused[y][x]=1;
                 a[y][x]=o;
                 v.push_back(mk(y,x));
                 qq.push(mk(mk(y,x),p.se+1));
               }
               else{
                uused[y][x]=1;
                a[y][x]=o;
                //push_back(mk(y,x));
                 qq.push(mk(mk(y,x),p.se));
               }
            }
          }
      }
    }
    queue<pair<pair<int,int>,int> >q;
    r(tt,v.size())q.push(mk(mk(v[tt].fi,v[tt].se),0));
    used[sy][sx]=1;
    while(!q.empty()){
      pair<pair<int,int>,int>p=q.front();q.pop();
      if(p.second>=k)continue;
      r(i,4){
        int x=p.fi.se+dx[i],y=p.fi.fi+dy[i];
        if(x>=0&&y>=0&&y<h&&x<w)
          if(!used[y][x]&&!uused[y][x]){
            if(s[y][x]=='.'){
              used[y][x]=1;
              q.push(mk(mk(y,x),p.se+1));
            }
            else{
              used[y][x]=1;
              s[y][x]='.';
              q.push(mk(mk(y,x),p.se+1));
            }
          }
      }
    }//r(i,h)cout<<s[i]<<endl;
  }
  L:;
}

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

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;

    if (S == "SUN")
    {
        cout << 7 << endl;
    }
    else if (S == "MON")
    {
        cout << 6 << endl;
    }
    else if (S == "TUE")
    {
        cout << 5 << endl;
    }
    else if (S == "WED")
    {
        cout << 4 << endl;
    }
    else if (S == "THU")
    {
        cout << 3 << endl;
    }
    else if (S == "FRI")
    {
        cout << 2 << endl;
    }
    else if (S == "SAT")
    {
        cout << 1 << endl;
    }
}

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

int main() {
	string s, t;
	cin >> s >> t;
	int ans = 1000;
	rep (i, (int)(s.size() - t.size()) + 1) {
		int cnt = 0;
		rep(j, (int)t.size()) {
			if (s[i + j] != t[j]) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
import math
D,G=map(int,input().split())
PC=[list(map(int,input().split())) for i in range(D)]
zenkan=[]
def saiki(A):
    if len(A)==D:
        ans=0
        count=0
        toita=[]
        for i in range(D):
            if A[i]==1:
                ans+=PC[i][0]*(i+1)*100+PC[i][1]
                count+=PC[i][0]
                toita.append(i)
        zenkan.append([ans,count,toita])
        return ans
    for i in range(2):
        A.append(i)
        saiki(A)
        A.pop()
saiki([])
ans=[]
zenkan.sort()
for i in range(len(zenkan)):
    cost=zenkan[i][1]
    hituyo=G-zenkan[i][0]
    if zenkan[i][0]>=G:
        ans.append(cost)
        continue
    cost_kari=[]
    for j in range(D):
        if j not in zenkan[i][2]:
            if PC[j][0]*100*(j+1)>=hituyo:
                cost_kari.append(math.ceil(hituyo/(100*(j+1))))
            #print(math.ceil(hituyo/100*(j+1)),j)
    cost_kari.sort()
    if len(cost_kari)!=0:
        ans.append(cost+cost_kari[0])
    elif hituyo<=0:
        ans.append(cost)
    #print(cost_kari)
#print(zenkan)
#print(ans)
print(min(ans))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ll r;
    ll d;
    ll x;
    cin >> r >> d >> x;
    for(int i=0;i<10;i++){
        x = r*x - d;
        cout << x << endl;
    } 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

class Solution {
public:
	/* time: O(1), space: O(1) */
	int powerSocket(int a, int b) {
		const int needs = (b - 1), unit = (a - 1);
		return (needs + (unit - 1)) / unit;
	}
};

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

	Solution sol;
	int ans = sol.powerSocket(a, b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main()
{
	string s;
	cin >> s;
	int num[4];
	rep(i,4) num[i] = s[i]-'0';
	rep(bit,1<<3){
		string mem;
		int sum = num[0];
		rep(i,3){
			if(bit & 1<<i){
				sum = sum + num[i+1];
				mem.pb('+');
			}else{
				sum = sum - num[i+1];
				mem.pb('-');
			}
		}
		//cout << sum << endl;
		if(sum == 7){
			printf("%d%c%d%c%d%c%d=7\n", num[0],mem[0],num[1],mem[1],num[2],mem[2],num[3]);
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int N, L;
	cin >> N >> L;
	if (L <= 0 && 1 - L <= N)
	{
		cout << N * L + N * (N - 1) / 2 << endl;
	}
	else if (L > 0)
	{
		cout << (N - 1) * L + N * (N - 1) / 2 << endl;
	}
	else
	{
		cout << (N - 1) * (L - 1) + N * (N - 1) / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    double[][][] DP;

    DP.length = 301;
    foreach (ref dp1; DP) {
        dp1.length = 301;
        foreach (ref dp2; dp1) dp2.length = 301;
    }

    auto N = readln.chomp.to!int;

    auto n = N.to!double;
    double solve(int a, int b, int c) {
        if (!a && !b && !c) return 0;
        if (!isNaN(DP[a][b][c])) return DP[a][b][c];

        double r = 0;
        if (a) r += solve(a-1, b+1, c) * a;
        if (b) r += solve(a, b-1, c+1) * b;
        if (c) r += solve(a, b, c-1) * c;
        return DP[a][b][c] = (r + n) / (a + b + c);
    }

    int three, two, one;
    foreach (a; readln.split.to!(int[])) {
        switch (a) {
            case 1:
                ++one;
                break;
            case 2:
                ++two;
                break;
            case 3:
                ++three;
                break;
            default:
        }
    }

    writefln("%.12f", solve(three, two, one));
}

Measured memory_bytes: 367612
from collections import deque

n, m = map(int, input().split())

graph = [[] for _ in range(n + 1)]

for i in range(m):
  a, b = map(int, input().split())
  graph[a].append(b)
  graph[b].append(a)

dist = [-1] * (n + 1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)

while d:
  v = d.popleft()
  for i in graph[v]:
    if dist[i] != -1:
      continue
    dist[i] = v
    d.append(i)

ans = dist[2:]
print("Yes")
print(*ans, sep="\n")


Measured memory_bytes: 36440