akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <utility>
#include <string>
#include <queue>

typedef std::pair<int,int> pos2d;

int solve(const std::vector<std::string> s, const pos2d start, pos2d &farthest)
{
    // 開始点から一番遠い場所を調べる
    const int h = s.size();
    const int w = s[0].length();

    std::vector<std::vector<int>> distMap(h, std::vector<int>(w, std::numeric_limits<int>::max()));
    std::queue<pos2d> q;

    distMap[start.second][start.first] = 0;
    q.push(start);

    while(q.size()) {
        const pos2d pos = q.front();
        const int x = pos.first;
        const int y = pos.second;
        const int dist = distMap[y][x];
        q.pop();

        if (x > 0 && s[y][x - 1] == '.' && distMap[y][x - 1] > dist + 1) {q.push(pos2d(x - 1, y)); distMap[y][x - 1] = dist + 1;}
        if (y > 0 && s[y - 1][x] == '.' && distMap[y - 1][x] > dist + 1) {q.push(pos2d(x, y - 1)); distMap[y - 1][x] = dist + 1;}
        if (x < w - 1 && s[y][x + 1] == '.' && distMap[y][x + 1] > dist + 1) {q.push(pos2d(x + 1, y)); distMap[y][x + 1] = dist + 1;}
        if (y < h - 1 && s[y + 1][x] == '.' && distMap[y + 1][x] > dist + 1) {q.push(pos2d(x, y + 1)); distMap[y + 1][x] = dist + 1;}
    }

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (s[y][x] == '#') {distMap[y][x] = -1;}
        }
    }

#ifdef _DEBUG_NO_OUT
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            std::cout << distMap[y][x] << " ";
        }
        std::cout << std::endl;
    }
#endif

    // search farthest dist
    pos2d posFarthest = start;
    int distFarthest = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            const int distXY = distMap[y][x];
            if (distXY > distFarthest) {
                distFarthest = distXY;
                posFarthest = pos2d(x, y);
            }
        }
    }

    farthest = posFarthest;

    return distFarthest;
}

int main(int argc, char *argv[])
{
    int h, w;
    std::vector<std::string> s;

    std::cin >> h >> w;

    s.resize(h);

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


    int maxDist = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (s[y][x] == '.') {
                pos2d initial(x, y);
                pos2d end;
                int dist = solve(s, initial, end);
                if (dist > maxDist) {maxDist = dist;}
            }
        }
    }

    std::cout << maxDist << std::endl;

    return 0;
}


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

map <long long int,long long int> cnt;
int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	long long int m,t;
	long long int res=0,sum=0;

	cin >> n >> m;

	cnt[0]++;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		sum = (sum%m) + (t%m);
		sum%=m;
		cnt[sum]++;
	}

	for(auto it : cnt)
	{
		res += (it.second-1)*(it.second)/2;
	}

	cout << res << '\n';

	return 0;	
}


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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  string S;
  cin >> S;
  long K;
  cin >> K;
  int n = S.size();
  int cnt = 0;
  char c;
  for (int i = 0; i < n; i++) {
    if (S[i] != '1') {
      c = S[i];
      break;
    }
    cnt++;
  }
  if (cnt < K) {
    cout << c << endl;
  } else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	var a, b, c, d, e int
	var f [5]int
	fmt.Fscan(fp, &a, &b, &c, &d, &e)
	f[0] = a % 10
	f[1] = b % 10
	f[2] = c % 10
	f[3] = d % 10
	f[4] = e % 10
	sum := wait(a) + wait(b) + wait(c) + wait(d) + wait(e)
	min := 10
	minI := -1
	for i := 0; i < 5; i++ {
		if f[i] < min && f[i] > 0 {
			min = f[i] % 10
			minI = i
		}
	}
	for i := 0; i < 5; i++ {
		if i == minI {
			sum += f[i]
			continue
		}
		if f[i] > 0 {
			sum += 10
		}
	}
	fmt.Println(sum)
}
func wait(time int) int {
	return time - time%10
}


Measured memory_bytes: 512
import sys, math

if(__name__ == "__main__"):
    N, K = map(int, input().strip().split() )
    AList = list( map(int, input().strip().split() ) )

    
    """
    i = K+1 , K+2 ,..., N
    score[i] = i * i-1 * ...* (i-K+1)
    score[i]/score[i-1] = i / (i-K)
    """
    for i in range(K, N):
        if(AList[i] > AList[i-K]):
            print("Yes")
        else:
            print("No")


Measured memory_bytes: 33072
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int MAX_N=100000;

int main(){
    ll n;
    ll a[MAX_N+5];
    ll b[MAX_N];
    cin >> n;
    rep(i,n+1){
        cin >>a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    ll ans=0;
    rep(i,n){
        if (a[i]>=b[i]){
            ans+=b[i];
        } else if(a[i+1]>=b[i]-a[i]){
            ans+=b[i];
            a[i+1]-=b[i]-a[i];
        } else{
            ans+=a[i]+a[i+1];
            a[i+1]=0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 2e5+10;

//head

int n;
ll k;
int a[N], f[N];

bool able(ll u) {
  ll cn = 0;
  rep(i, n) {
    ll p = u/f[i];
    cn += max(0LL, a[i]-p);
  }
  return cn <= k;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    cin >> f[i];
  }

  sort(a, a+n);
  sort(f, f+n, greater<int>());

  ll lb = -1, mid, ub = 1e13;
  while(ub-lb != 1) {
    mid = (lb+ub)>>1;
    if(able(mid)) ub = mid;
    else lb = mid;
  }

  cout << ub << endl;
}

Measured memory_bytes: 5180
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int k; cin >> k;
    rep(i,k){
        cout << "ACL";
    }
}




Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    int ans = 0;
    for(int i=1;i<N;i++) if(A[i-1] < A[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3544
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int n,ans;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  cin >> n;
  for(int i=1;i*i<=n;i++){
    if( n%i==0 ){

      int q = ( n/i ) - 1;
      if( q &&  n/q == n%q ){
        ans+=q;
      }
      q = i-1;
      if(q && n/q == n%q ){
        ans+=q;
      }

    }
  }
  cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c; cin >>a >> b >> c;
    set<int> s;
    s.insert(a),s.insert(b),s.insert(c);
    if (s.size()==2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main() {
  string n,m;
  cin >> n >> m;
  sort(n.begin(),n.end());
  sort(m.rbegin(),m.rend());
  cout << ((n<m)?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
	int K, X,i;
	scanf("%d %d", &K,&X);
	for (i = X - K + 1; i <= X + K - 1; i++) {
		printf("%d ", i);
	}
	return 0;
}


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

int main(){
  string s;cin >> s;
  string ans;cin >> ans;
  rep(i,s.length()){
    if(s[i] == '0')ans = ans + '0';
    else if(s[i] == '1')ans = ans + '1';
    else if(s[i] == 'B'){if(ans.length()!=0){ans.erase(ans.length()-1);}}
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2==0){
        cout << a-b << endl;
    }else{
        cout << b-a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
using namespace std;
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  vector<int> ans(n, 0);
  int numr = 0;
  int numl = 0;
  int indr = 0;
  REP(i, n)
  {
    numr = 0;
    numl = 0;
    while (s[i] == 'R')
    {
      numr++;
      i++;
    }
    indr = i;
    while (s[i] == 'L')
    {
      numl++;
      i++;
    }
    int tval = max(numr, numl);
    if ((numr - numl) % 2 == 0)
    {
      ans[indr - 1] = (numr + numl) / 2;
      ans[indr] = (numr + numl) / 2;
    }
    else
    {
      if ((tval == numr && tval % 2 == 0) || (tval == numl && tval % 2 != 0))
      {
        ans[indr - 1] = (numr + numl) / 2;
        ans[indr] = (numr + numl) / 2 + 1;
      }
      else
      {
        ans[indr - 1] = (numr + numl) / 2 + 1;
        ans[indr] = (numr + numl) / 2;
      }
    }
    i--;
  }
  REP(i, n)
  {
    cout << ans[i] << " ";
  }
  cout << endl;
}


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

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

count = 0

for i in range(N-1, -1, -1):
    if A[i+1] <= B[i]:
        count += A[i+1]
        B[i] -= A[i+1]
        A[i+1] = 0
    else:
        count += B[i]
        A[i+1] -= B[i]
        B[i] = 0

    if A[i] <= B[i]:
        count += A[i]
        B[i] -= A[i]
        A[i] = 0
    else:
        count += B[i]
        A[i] -= B[i]
        B[i] = 0

print(count)

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

#define int long long
#define INT int
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

signed main()
{
    int x;
    cin >> x;

    int m = 100;
    int ans = 0;

    while (1)
    {
        m += m * 0.01;
        ans++;
        if (x <= m)
        {
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    C = input().rstrip()

    l = 0
    r = N - 1
    ans = 0
    while True:
        if C[l] == "W" and C[r] == "R":
            ans += 1
            l += 1
            r -= 1
        elif C[l] == "R" and C[r] == "R":
            l += 1
        elif C[l] == "W" and C[r] == "W":
            r -= 1
        else:
            l += 1
            r -= 1

        if not l < r:
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9508
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <array>
#include <numeric>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    print(N*(N-1)/2);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define N 10000

int isPrime(int);

int main(){
  int A[N],n,i,kazu=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<n;i++){
    if(isPrime(A[i]))
      kazu++;
  }
  printf("%d\n",kazu);

  return 0;
}

int isPrime(int x){
  int i;

  if(x==2) return 1;
  if(x<2 || x%2==0) return 0;
  
  i=3;
  while(i <= (int)sqrt(x)){
    if(x%i==0) return 0;
    i += 2;
  }

  return 1;
}

Measured memory_bytes: 628
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      for(int k = j + 1; k < n; k++) {
        if(a[i] == a[j] || a[j] == a[k] || a[k] == a[i]) {
          continue;
        }
        vector<ll> tmp;
        tmp.push_back(a[i]);
        tmp.push_back(a[j]);
        tmp.push_back(a[k]);
        sort(tmp.begin(), tmp.end());
        if(tmp[0] + tmp[1] > tmp[2]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
N = int(input())
w = []
for i in range(N):
    w.append(input())
# [a1, a2, a3, ..., aN]
p = 0
for i in range(N):
  for j in range(i+1,N):
    if w[i] == w[j]:
      p = 1
      break
v = []
    
for i in range(N):
  v.append([])

for j in range(N):
  for s in list(w[j]):
    v[j].append(s)

for k in range(N):
  if k != 0:
    if v[k - 1][len(v[k - 1]) - 1] != v[k][0]:
      p = 1
      break

if p == 0:
  print("Yes")
else:
  print("No")

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

using namespace std;

void solve() {
    int r, g, b, k;
    cin >> r >> g >> b >> k;

    int i = 0;
    for (; i < k; ++i) {
        if (g <= r) {
            g *= 2;
        } else if (b <= g) {
            b *= 2;
        }
        if (b > g && g > r) {
            cout << "Yes\n";
            return;
        }
    }

    cout << "No\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}


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

vector<int> v[200005];
vector<int> sum;
void dfs(int n, int p = -1)
{
	for(int nv : v[n])
	{
		if (nv == p) continue;
		sum[nv] += sum[n];
		dfs(nv, n);
	}
}

signed main(void)
{
	int n, q;
	cin >> n >> q;

	sum.resize(n, 0);
	rep(i, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	rep(i, q)
	{
		int p, x;
		cin >> p >> x;
		p--;
		sum[p] += x;
	}
	dfs(0);
	rep(i, n)
		printf("%d%c", sum[i], i == n - 1 ? '\n': ' ');
	return 0;
}


Measured memory_bytes: 23424
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Console.ReadLine();
            var N = S.Length - 1;
            var answer = 0L;
            for (var bit = 0; bit < 1 << N; bit++)
            {
                var current = 0L;
                var localBit = 0;
                for (var i = 0; i <= N; i++)
                {
                    current += (S[N - i] - '0') * (long)Math.Pow(10, localBit++);
                    if ((bit >> i & 1) == 1) localBit = 0;
                }
                answer += current;
            }

            Console.WriteLine(answer);
        }
    }
}


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

void dfs(string s, char mx, int N)
{

    if(s.size() == N){
        cout << s << endl;
        return;
    }
    for (char c = 'a'; c <= mx + 1; ++c){
        string t = s;
        t += c;
        dfs(t, max(mx, c), N);
    }

        return;
}

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

    dfs("",'a' - 1, N);

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  int N,M; cin>>N>>M;
  if(N%2){
    rep(i,M){
      cout<<i+1<<" "<<N-i<<endl;
    }
  }else{
    rep(i,M/2+M%2){
      cout<<i+1<<" "<<N-i<<endl;
    }
    for(int i=M/2+M%2;i<M;i++){
      cout<<i+1<<" "<<N-i-1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val S = rd.readString()
    val N = S.length
    val Num = S.toInt()
    if (Num < 357) {
        println(0)
        return
    }

    val A = intArrayOf(3,5,7)

    fun is357(X: Int): Boolean {
        var x = X
        var three = false
        var five = false
        var seven = false
        while (x>0) {
            when(x%10) {
                3-> {three = true}
                5-> {five = true}
                7-> {seven = true}
            }
            x /= 10
        }
        return three and five and seven
    }

    var ans = 0
    fun dfs(n: Int, res: Int) {
        if (n>=N) {
            if (res<=Num && is357(res)) ans++
            return
        }

        if (is357(res)) ans++

        for (i in 0 until 3) {
            dfs(n+1,res*10 + A[i])
        }
    }

    dfs(0, 0)

    println(ans)
}


//val rd = debug.Reader("abc", "114", "c", "sample-2")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 35332
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CMultiplication3 {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll a; cin >> a;
      string b; cin >> b;
      reverse(all(b));
      int d = 0;
      int base = 1;
      for(auto c: b) {
        if (c != '.') {
          d += (c - '0')*base;
          base *= 10;
        }
      }

      ll ret = (a*d)/100;
      cout << ret << endl;

    }
};

signed main() {
  CMultiplication3 solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3656
#include"bits/stdc++.h"
using ll=long long; 
using ld=long double; 
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif
  string s,t; cin>>s>>t; int n=s.size(); int m=t.size(); int ans=INT_MAX; 
  for(int i=0;i<=n-m;i++)
  {
    int i1=i; int res=0; 
    for(int j=0;j<=m-1;j++){ if(s[i1]!=t[j]) res++; i1++; }
      ans=min(ans,res); 
  }
  cout<<ans<<"\n"; 
  return 0; 
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
  int c[6]={1,5,10,50,100,500};
  int n;
  int sum=0;
  for(int i=0;i<6;i++){
    cin>> n;
    sum+=n*c[i];
  }
  if(sum>=1000){
    cout<< "1"<< endl;
  } else {
    cout<< "0"<< endl;
  }
}

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

void factorization(long long n,map<long long ,long long>& mp){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n /= i;
        }
      }
      if(!(n == 1)) mp[n]++;
}

int main() {
  ll x,ans;
  cin>>x;
  while(true){
    map<ll,ll> mp;
    factorization(x,mp);
    if(mp.count(x)){
      ans=x;
      break;
    }
    x++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long long ll;
typedef unsigned long long ull;
const int MN = 1e5+500;
int x;
bitset<MN> good;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> x;
    for (int i = 2; i*i<MN;i++) {
        if (!good[i]) {
            for (int j = i+i;j<MN;j+=i) {
                good[j] = 1;
            }
        }
    }
    for (int i =x; i<MN;i++) {
        if (!good[i]) {
            cout << i << "\n";
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

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

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == 12) {
    m1 = 1;
  } else {
    m1++;
  }
  cout << (d2 == 1 ? 1 : 0) << endl;
  return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
a = [input() for _ in range(H)]

row = [False]*H
col = [False]*W

for i in range(H):
  for j in range(W):
    if a[i][j] == "#":
      row[i] = True
      col[j] = True

for i in range(H):
  if row[i]:
    for j in range(W):
      if col[j]:
        print(a[i][j],end = '')
    print()


Measured memory_bytes: 42712
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
bool eq(double a, double b) { return fabs(a - b) < EPS; }

struct point
{
	double x, y;
	point(double x = 0, double y = 0) :x(x), y(y) {};

	point operator + (point p) { return point(x + p.x, y + p.y); }
	point operator - (point p) { return point(x - p.x, y - p.y); }
	point operator * (double s) { return point(x * s, y * s); }
	point operator / (double s) { return point(x / s, y / s); }

	double norm() { return x*x + y*y; }
	double abs() { return sqrt(norm()); }

	bool operator < (const point &p) const
	{
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const point &p) const
	{
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

};

double dot(point a, point b)
{
	return a.x*b.x + a.y*b.y;
}

double cross(point a, point b)
{
	return a.x*b.y - a.y*b.x;
}

int ccw(point a, point b, point c)
{
	b = b - a; c = c - a;
	if (cross(b, c) > EPS) return 1;//???????¨????????????????a,b,c??¨?????¶
	if (cross(b, c) < -EPS) return -1;//???????¨????????????????a,c,b??¨?????¶
	if (dot(b, c) < 0) return 2;//??´?????????c,a,b??????????????¶
	if (b.norm() < c.norm()) return -2;//??´?????????a,b,c??????????????¶
	return 0;//??´?????????a,c,b??????????????¶
}

struct line
{
	point a, b;
	line(double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0) :a(point(x1, y1)), b(point(x2, y2)) {};

	point univec() { return (b - a) / (b - a).norm(); }
};

point cross_point(line s1, line s2)
{
	point base = s2.b - s2.a;
	double d1 = abs(cross(base, s1.a - s2.a));
	double d2 = abs(cross(base, s1.b - s2.a));
	double t = d1 / (d1 + d2);
	return s1.a + (s1.b - s1.a)*t;
}
int main()
{
	int q;
	cin >> q;
	while (q--)
	{
		int a[8];
		REP(i, 8) cin >> a[i];
		line s(a[0], a[1], a[2], a[3]);
		line t(a[4], a[5], a[6], a[7]);
		point ans = cross_point(s, t);
		cout << D10 << ans.x << " " << ans.y << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
import java.util.*;
import java.util.stream.IntStream;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.CountDownLatch;

public class Main{
    
    static final int SLEEP_TIME = 17;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        final CountDownLatch start = new CountDownLatch(n+1);
        final CountDownLatch end = new CountDownLatch(n+1);
        final Count c = new Count();
        
        for(int i=0; i<n; i++){
            int num = Integer.parseInt(sc.next());
            new Thread(new Runnable(){
                public void run(){
                    try{
                        start.countDown();
                        start.await();
                        TimeUnit.MILLISECONDS.sleep(num*SLEEP_TIME);
                        synchronized(c){
                            c.flagUp();
                        }
                    }catch(InterruptedException e){
                        //e.printStackTrace();
                    }finally{
                        end.countDown();
                    }
                }
            }).start();
        }
        
        new Thread(new Runnable(){
            public void run(){
                try{
                    start.countDown();
                    start.await();
                    for(int i=0; i<104; i++){
                        c.countUp();
                        TimeUnit.MILLISECONDS.sleep(SLEEP_TIME);
                    }
                }catch(InterruptedException e){
                    //e.printStackTrace();
                }finally{
                    end.countDown();
                }
            }
        }).start();
        
        
        try{
            end.await();
        }catch(InterruptedException e){
            e.printStackTrace();
        }
        
        System.out.println(c.getResult());
    }
}

class Count{
    int cnt;
    boolean flag;
    
    public Count(){
        cnt = 0;
        flag = false;
    }
    
    public void flagUp(){
        flag = true;
    }
    
    public void countUp(){
        if(flag){
            cnt++;
            flag = false;
        }
    }
    
    public int getResult(){
        return cnt;
    }
}


Measured memory_bytes: 42700
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,q;
    while(1){
        cin>>n>>q;
        if(n+q==0)break;
        string s[1000];
        int a[1000],b[1000];
        for(int i=0;i<n;i++)cin>>s[i]>>a[i]>>b[i];
        while(q--){
            string ans1="Unknown";
            int ans2,c;
            cin>>c;
            for(int i=0;i<n;i++){
                if(b[i]-a[i]+1<=c&&c<=b[i]){
                    ans1=s[i];
                    ans2=c-(b[i]-a[i]);
                }
            }
            if(ans1=="Unknown"){
                cout<<ans1<<endl;
            }else{
                cout<<ans1<<" "<<ans2<<endl;
            }
        }
    }
}

Measured memory_bytes: 3216
#include<stdio.h>
int main(void)
{
    int count[4][3][10];
    int n,b,f,r,v;
    int i,j,k;

    for(i=0;i<4;i++){             //棟
        for(j=0;j<3;j++){         //階
            for(k=0;k<10;k++){    //部屋
                count[i][j][k]=0;
            }
        }
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        count[b-1][f-1][r-1]+=v;
    }

    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            printf(" %d",count[0][j][k]);
        }
        printf("\n");
    }
    for(i=0;i<20;i++){
        printf("#");
    }
    printf("\n");
    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            printf(" %d",count[1][j][k]);
        }
        printf("\n");
    }
    for(i=0;i<20;i++){
        printf("#");
    }
    printf("\n");
    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            printf(" %d",count[2][j][k]);
        }
        printf("\n");
    }
    for(i=0;i<20;i++){
        printf("#");
    }
    printf("\n");
    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            printf(" %d",count[3][j][k]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
double f[3000][3000],a[3000];
int main()
{
	double ans=0;
	int n,i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%lf",&a[i]);
	f[0][0]=1;
	for(i=1;i<=n;i++)
		f[i][0]=f[i-1][0]*(1-a[i]);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=i;j++)
		{
			f[i][j]=f[i-1][j]*(1-a[i])+f[i-1][j-1]*a[i];
		}
	}
	for(i=(n+1)/2;i<=n;i++)
		ans+=f[n][i];
	printf("%.10lf",ans);
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const ll INF = (1LL<<50);
const int N = 100005;

char v[1005][1005];
int dp[1005][1005];
int dx[] = {0,1};
int dy[] = {1,0};
int main(){
	fastio;
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> v[i][j];
	dp[0][0] = 1;
	for(int x = 0; x < n; x++){
		for(int y = 0; y < m; y++){
			for(int k = 0; k < 2; k++){
				int newx = x + dx[k], newy = y + dy[k];
				if(newx < n and newy < m and v[newx][newy] == '.'){
					dp[newx][newy] = (dp[newx][newy] + dp[x][y])%mod;
				}
			}
		}
	}
	cout << dp[n-1][m-1] << '\n';
	return 0;
}


Measured memory_bytes: 8432
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110 
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a[N],ans[N];
signed main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=n;i>=1;i--)
		for (int j=i;j>=1;j--)
		if (a[j]==j)
		{
			for (int k=j;k<i;k++) a[k]=a[k+1];
			ans[i]=j;
			break;
		}
	for (int i=1;i<=n;i++) if (!ans[i]) {cout<<-1;return 0;}
	for (int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//对于第i个位置上的a[i] 需要满足其之后有i-a[i]个比它小的数被放进去 
//

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

int main(){
  float l;
  cin >> l;
  double ans = 1;
  for(int i = 0;i < 3;i++){
    ans *= l/3;
    // printf("%lf\n",ans);
  }
  printf("%lf\n",ans);

  return 0;
}
  


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

const char dc[] = "^v<>";

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

int res = 0;
int pass[50][50];
int used[50][50][4];

void touch(int x, int y) {
	res += !pass[x][y];
	pass[x][y] = 1;
}

int prev_d(int d) {
	return d == 0 ? 3 : d == 1 ? 2 : d == 2 ? 0 : 1;
}

int next_d(int d) {
	return d == 0 ? 2 : d == 1 ? 3 : d == 2 ? 1 : 0;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<string> S(N);
	int gx = 0, gy = 0, sx = 0, sy = 0, sd = 0;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		for (int j = 0; j < M; j++) {
			if (S[i][j] == 'G') {
				gx = i;
				gy = j;
			}
			else if (S[i][j] != '.' && S[i][j] != '#') {
				sx = i;
				sy = j;
				sd = find(dc, dc + 4, S[i][j]) - dc;
			}
		}
	}
	int x = sx, y = sy, d = sd;
	touch(sx, sy);
	while ((x != gx || y != gy) && !used[x][y][d]) {
		used[x][y][d] = 1;
		int tx = x + dx[0][d], ty = y + dy[0][d];
		if (0 <= tx && tx < N && 0 <= ty && ty < M && S[tx][ty] != '#') {
			int ttx = x + dx[1][d], tty = y + dy[1][d];
			if (0 <= ttx && ttx < N && 0 <= tty && tty < M && S[ttx][tty] != '#') {
				touch(tx, ty);
				if (tx == gx && ty == gy) {
					x = tx, y = ty;
					break;
				}
				touch(ttx, tty);
				d = prev_d(d);
				x = ttx;
				y = tty;
			}
			else {
				touch(tx, ty);
				x = tx;
				y = ty;
			}
		}
		else {
			d = next_d(d);
		}
	}
	cout << (x == gx && y == gy ? res : -1) << endl;
	return 0;
}



Measured memory_bytes: 3272
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var p = readLine()!!.split(" ").map { it.toInt()}
    var pCopy = p.map { it }.sortedBy { it }
    var bo = 0
    for (i in 0 until n){
        if (p[i] != pCopy[i]) bo++
    }
    if (bo == 2 || bo == 0) println("YES")
    else println("NO")
}

Measured memory_bytes: 37904
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
typedef long long int lli;

typedef struct{
    lli c;
    lli num;
}su;
int c_comp(const void*a,const void*b){return ((su*)a)->c-((su*)b)->c;}
int num_comp(const void*a,const void*b){return ((su*)a)->num-((su*)b)->num;}
int lli_comp(const void*a,const void*b){return *(lli*)a-*(lli*)b;}
int main(void)
{
    lli n;
    lli a[200000];
    su list[200000];

    scanf("%lld",&n);
    for(lli i=0;i<n;i++){
        scanf("%lld",&list[i].c);
        list[i].num=i;
        a[i]=list[i].c;
    }
    lli cnt=0;

    lli pivot=1;
    for(lli i=0;i<n;i++){
        if(a[i]==pivot){
            pivot++;
        }
        else{
            a[i]=-1;
            cnt++;
        }
    }
    //for(lli i=0;i<n;i++)printf("%lld\n",a[i]);
    lli ai=1;
    int flg=0;
    for(lli i=0;i<n;i++){
        if(a[i]==-1)continue;
        if(a[i]==ai){
            ai++;
            flg=1;
        }
        else{
            printf("-1\n");
            return 0;
        }
    }
    if(flg==0){
        printf("-1\n");
        return 0;
    }
    printf("%lld\n",cnt);
    return 0;
}
//oo

Measured memory_bytes: 4864
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define pb push_back
#define sz(x) x.size()
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>(x);
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define log(x) cout<<#x<<" : "<<x<<endl;
#define logp(x) cout<<#x<<" : ("<<x.fi<<", "<<x.se<<")"<<endl;
#define logi(a, i) cout<<#a<<'['<<i<<']'<<" : "<<a[i]<<endl;
#define loga(a, n) cout<<#a<<" -> "; rep(z, n) cout<<z<<": "<<a[z]<<", "; cout<<endl;
#define logv(a) loga(a, a.size())
#define out(x) cout<<x<<endl
#define outp(x) cout<<x.fi<<' '<<x.se<<endl
#define outa(a, n) rep(z, n) cout<<a[z]<<' '; cout<<endl;
#define outv(a) outa(a, a.size())
#define sim template<class t
typedef long long ll;
typedef long double LD;
sim> void maxi(t &x, t y) {if(x<y) x=y;}
sim> void mini(t &x, t y) {if(x>y) x=y;}
using namespace std;

#define N 1000005

int cnt[N];

//without mod
ll my_pow(ll a, ll p) {
    if(!p) return 1ll;
    ll ans = my_pow(a, p/2);
    ans *= ans;
    if(p&1) ans *= a;
    return ans;
}


int main() {
	ios::sync_with_stdio(0); cout<<setprecision(10)<<fixed;
    IN(n);
    ll p; cin>>p;
    for(ll i=2; i<=sqrt(p); i++) {
        if(!(p%i)) {
            while(!(p%i)) {
                p/=i;
                cnt[i]++;
            }
        }
    }
    ll ans=n==1?p:1;
    /* logi(cnt, 3); */
    F(N) {
        ll to = cnt[i]/n;
        /* if(to) log(i); */
        ans *= my_pow(i, to);
    }
    out(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 998244353;

ll Pow(ll a, ll b) {
    ll x = 1, y = a;
    while (b) {
        if (b % 2) (x *= y) %= MOD;
        (y *= y) %= MOD;
        b /= 2;
    }
    return x;
}

ll Inv(ll x) {
    return Pow(x, MOD - 2);
}


const int N = 3e5 + 10;
ll fact[N], tcaf[N];

void precalc() {
    fact[0] = 1;
    forn(i, 1, N)
        fact[i] = i * fact[i - 1] % MOD;
    tcaf[N - 1] = Inv(fact[N - 1]);
    ford(i, 0, N - 1)
        tcaf[i] = tcaf[i + 1] * (i + 1) % MOD;
}

ll binom(int n, int k) {
    return fact[n] * tcaf[k] % MOD * tcaf[n - k] % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    precalc();
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    for(ll x = 0; x <= n; ++x) {
        ll y = (k - a * x) / b;
        if (a * x + b * y != k) continue;
        if (y < 0 || y > n) continue;
        ans += binom(n, x) * binom(n, y);
        ans %= MOD;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4992