akhauriyash/Code-Regression huggingface dataset:
x = [input().split() for i in range(3)]
N = int(input())
b = [int(input()) for n in range(N)]
l = [[0]*3, [0]*3, [0]*3]
for val in b:
    for i in range(3):
        for j in range(3):
            if val == int(x[i][j]):
                l[i][j] = 1
if l[0][0] + l[0][1] + l[0][2] == 3:
    print('Yes')
elif l[1][0] + l[1][1] + l[1][2] == 3:
    print('Yes')
elif l[2][0] + l[2][1] + l[2][2] == 3:
    print('Yes')
elif l[0][0] + l[1][0] + l[2][0] == 3:
    print('Yes')
elif l[0][1] + l[1][1] + l[2][1] == 3:
    print('Yes')
elif l[0][2] + l[1][2] + l[2][2] == 3:
    print('Yes')
elif l[0][0] + l[1][1] + l[2][2] == 3:
    print('Yes')
elif l[0][2] + l[1][1] + l[2][0] == 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
def dis(A,B,d):
    res = 0.0
    for i in range(len(A)):
        res += abs(A[i]-B[i])**d
    return res**(1.0/d)

def main():
    n = int(input())
    A = list(map(float,input().split()))
    B = list(map(float,input().split()))
    print(dis(A,B,1.0))
    print(dis(A,B,2.0))
    print(dis(A,B,3.0))
    res = 0.0
    for i in range(n):res = max(res,abs(A[i]-B[i]))
    print(res)



if __name__ == '__main__':
    main()




Measured memory_bytes: 5660
#include <cassert>
#include <queue>
#include <set>
#include <cstring>
#include <numeric>
#include <iostream>
using namespace std;

bool alleq(string &s) {
    for (int i = 1; i < s.size(); i++) if (s[0] != s[i]) return false;
    return true;
}

bool checkadj(string &s) {
    for (int i = 1; i < s.size(); i++) if (s[i-1] == s[i]) return true;
    return false;
}

const int M = 998244353;

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

int bruteforce(string &s) {
    set<string> ss;
    ss.insert(s);
    queue<string> q;
    q.push(s);
    int ans = 0;
    while (!q.empty()) {
        string t = q.front();
        q.pop();
        ans++;
        for (int i = 1; i < t.size(); i++) {
            if (t[i-1] != t[i]) {
                char c = int('a') + 'b' + 'c' - t[i-1] - t[i];
                string u = t;
                u[i-1] = u[i] = c;
                if (ss.find(u) == ss.end()) {
                    ss.insert(u);
                    q.push(u);
                }
            }
        }
    }
    return ans;
}

int main() {
    string s; cin >> s;
    if (alleq(s)) {
        assert (bruteforce(s) == 1);
        cout << "1\n";
        return 0;
    }
    if (s.size() == 3 && s[0] != s[1] && s[1] != s[2] && s[2] != s[0]) {
        assert (bruteforce(s) == 3);
        cout << "3\n";
        return 0;
    }

    int dp[2][3][3] = {}, cur = 0, prev = 1;
    for (int j = 0; j < 3; j++) dp[prev][j][j] = 1;
    for (int i = 1; i < s.size(); i++) {
        memset(dp[cur], 0, sizeof(dp[cur]));
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
                for (int l = 0; l < 3; l++)
                    if (k != l) dp[cur][(j + l)%3][l] += dp[prev][j][k] % M;

        swap(prev, cur);
    }
    const int sum = accumulate(s.begin(), s.end(), 0) % 3;
    long long ans = modexp(3, s.size()-1, M);
    ans -= accumulate(dp[prev][sum], dp[prev][sum]+3, 0LL);
    if (!checkadj(s)) ans++;
    cout << (ans % M + M) % M << endl;
}
//     int ans2 = bruteforce(s);
//     if ((ans2 - ans) % M != 0)
//         cerr << "NG: " << s << " " << ans2 << endl;
//     else cerr << "OK\n";
// }


Measured memory_bytes: 4072
X,N,*P = map(int,open(0).read().split())
if P != []:
  P = sorted(list(P),reverse=True)
else:
  print(X)
  exit()

min_diff = 101
min_val = 101

for i in range(101,-1,-1):
  #print(i,min_val,min_val)
  if not i in P:
    if abs(X-i) <= min_diff and min_val >=i:
      min_diff = abs(X-i)
      min_val = i
  ans = min_val
print(ans)

Measured memory_bytes: 8972
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

vector<vector<int>> e;
int used[1000 * 2], match[1000 * 2];

bool dfs(int v) {
	used[v] = true;
	for (auto u : e[v]) {
		int w = match[u];
		if (w < 0 || !used[w] && dfs(w)) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching(int N) {
	int ret = 0;
	memset(match, -1, sizeof(match));
	FOR(v, N) {
		if (match[v] < 0) {
			memset(used, 0, sizeof(used));
			if (dfs(v)) ret++;
		}
	}
	return ret;
}

int cost[100][100];

int main() {
	int n, m, l;
	while (cin >> n >> m >> l, n) {
		memset(cost, 0x3F, sizeof(cost));
		FOR(i, n) cost[i][i] = 0;
		FOR(i, m) {
			int u, v, d; cin >> u >> v >> d;
			cost[u][v] = cost[v][u] = d;
		}
		FOR(k, n) FOR(i, n) FOR(j, n) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);

		vector<Pii> vp(l);
		FOR(i, l) {
			cin >> vp[i].first >> vp[i].second;
		}
		e = vector<vector<int>>(2 * l);
		FOR(i, l) FOR(j, l) {
			if (i == j) continue;
			int from = vp[i].first, to = vp[j].first;
			if (vp[i].second + cost[from][to] <= vp[j].second) {
				e[i].push_back(l + j);
			}
		}

		cout << l - bipartite_matching(2 * l) << endl;
	}
}

Measured memory_bytes: 3900
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n;
string str;
int main()
{
    cin>>str;
    n=str.size();
    int ans=INF;
    for(int i=0;i<26;i++)
    {
        int last=-1,cur=0;
        for(int j=0;j<n;j++)
        {
            if(str[j]=='a'+i)
            {
                cur=max(cur,j-last-1);
                last=j;
            }
        }
        cur=max(cur,n-last-1);
        ans=min(ans,cur);
    }
    printf("%d\n",ans);
    return 0;
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct UnionFind {
  vector<int> data;

  UnionFind(int n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

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

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

int main(){
  ll n, m;cin>>n>>m;
  vector<ll> a(m), b(m);
  rep(i, m)cin>>a[i]>>b[i];
  UnionFind uf(n);
  ll unc=n*(n-1)/2;
  vector<ll>results;
  rrep(i, m){
    results.push_back(unc);
    if(!uf.same(a[i], b[i])){
      unc -= (ll)uf.size(a[i]) * (ll)uf.size(b[i]);
      uf.unite(a[i], b[i]);
    }
  }
  rrep(i, m)cout<<results[i]<<endl;

  return 0;
}


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

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

/* define class and method names */
#define TCC ParenthesisRemoval
#define TCM countWays


using namespace std;


typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;




/* testing process */
int main(){
	int N,M;
	cin>>N>>M;
	vi ans(N,0);
	for(int i=0;i<M;++i){
		int u,v;
		cin>>u>>v;
		if(u==v){
			ans[u-1]++;
			continue;
		}
		ans[u-1]++;
		ans[v-1]++;
	}
	for(auto k:ans) cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
n=int(input())
A=INPUT()
bool=False
for i in range(n):
    if A[i]==0:
        bool=True
        break
if bool:
    print(0)
else:
    ans=1
    for i in range(n):
        ans*=A[i]
        if ans>10**18:
            ans=-1
            break
    print(ans)


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

using namespace std;

int w, h;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
char rgb[] = "RGB";

struct Grid {
    int cnt;
    string stat;
};

bool check(string s) {
    int p = 1;
    while(s[p] == s[p - 1] && p < s.size()) ++p;
    return p == s.size();
}

void rep(string &stat, char from, char to, int x, int y) {

    stat[y * w + x] = to;

    for(int i = 0; i < 4; ++i) {
        int nx = x + dx[i];
        int ny = y + dy[i];

        if(nx >= 0 && nx < w && ny >= 0 && ny < h && stat[ny * w + nx] == from) {
            rep(stat, from, to, nx, ny);
        }
    }

    return;
}

int main() {

    char graph[10][10];

    while(cin >> w >> h, w | h) {

        string stat = "";

        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                cin >> graph[i][j];
                stat += graph[i][j];
            }
        }

        //queue<int>
        map<string, bool> mp;
        queue<Grid> q;

        q.push((Grid){0, stat});
        mp[stat] = true;

        while(!q.empty()) {

            Grid now = q.front(); q.pop();

            //cout << now.stat << endl;

            if(check(now.stat)) {
                cout << now.cnt << endl;
                break;
            }

            for(int i = 0; i < 3; ++i) {
                Grid next = (Grid){now.cnt + 1, now.stat};
                if(next.stat[0] != rgb[i]) {
                    rep(next.stat, next.stat[0], rgb[i], 0, 0);
                    if(mp.count(next.stat) == 0) {
                        mp[next.stat] = true;
                        q.push(next);
                    }
                }
            }

        }

    }

}



Measured memory_bytes: 4668
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

//sort(ALL(v),greater<int>());


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

	int N, K;
	cin >> N >> K;
	vector<int>a(N),b(N-K+1),c(N-K+1);
	rep(i, N)cin >> a[i];

	int ksum = 0;
	rep(i, K)ksum += a[i];
	REP(i, K, N) {
		b[i - K] = ksum;
		ksum += a[i];
		ksum -= a[i - K];
	}
	b[N - K] = ksum;

	int opt = 0;
	REP(i, K, N)if (0 < a[i])opt += a[i];
	REP(i, K, N) {
		c[i - K] = opt;
		if (0 < a[i])opt -= a[i];
		if (0 < a[i - K])opt += a[i - K];
	}
	c[N - K] = opt;

	int ans = -intmax;
	rep(i, N - K + 1)ans = max(ans, max(b[i],int(0)) + c[i]);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 998244353

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([][]int, k)
	for i := range as {
		sc.Scan()
		l, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		r, _ := strconv.Atoi(sc.Text())
		as[i] = []int{l, r}
	}
	dp := make([]int, n)
	dp[0] = 1
	var cp int
	for i := 0; i < n-1; i++ {
		cp += dp[i]
		for j := range as {
			l, r := as[j][0], as[j][1]
			if i+l < n {
				dp[i+l] += cp
				dp[i+l] %= mod
			}
			if i+r+1 < n {
				dp[i+r+1] -= cp
				dp[i+r+1] %= mod
			}
		}
	}
	ans := dp[n-1]
	ans %= mod
	if ans < 0 {
		ans += mod
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 3468
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int mod=1e9+7;
const int N=305;
int n,m,f[N][N][N];
struct node{
	int x,y;
};
vector<node>g[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int l=read(),r=read(),x=read();
		g[r].push_back((node){l,x});
	}
	f[0][0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<i;j++)
			for(int k=0;k<=j;k++)
			{
				f[i][j][k]=(f[i][j][k]+f[i-1][j][k])%mod;
				f[i][i-1][k]=(f[i][i-1][k]+f[i-1][j][k])%mod;
				f[i][i-1][j]=(f[i][i-1][j]+f[i-1][j][k])%mod;
				for(int p=0;p<g[i].size();p++)
				{
					node u=g[i][p];
					int gs=1+(j>=u.x)+(k>=u.x);
					if(gs!=u.y)f[i][j][k]=0;
				}
			}
	int ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<=i;j++)ans=(ans+f[n][i][j])%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 217344
#include<iostream>
using namespace std;
int main(){
    int a,b,c,n,i,j,sum=0;
    cin >> a >> b >> c;
    if(c<=b){
        sum = c + b;
        cout << sum;
        return 0;
    }
    //sum = b +(c-(c-(a+b)));
    if(c>(a+b)){
        sum = b + (c-(c-(a+b)));
        sum++;
    }else{
        sum = b + c;
    }
    cout << sum;
    return 0;
}


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

#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rrep(i, N) for (int i = (int)(N)-1; i >= 0; --i)
#define debug(x) cout << #x << "=" << x << endl;
constexpr int MOD=1000000007;
constexpr ll INF = (1LL << 61) - 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;}
template <typename T> void fail(T v){cout << v << endl;exit(0);}
//template

void solve(){
    int N;cin>>N;
    cout<<(1000-N%1000)%1000<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    solve();
    return 0;
}

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

int main(void) { 
  int num; 
  
  while(1){
      scanf("%d",&num);
      if(num == 0) {
          break;
      }
      
      int i;
      int divPlus = 1;
      
      int med = floor(sqrt(num));
      
      if(num == 1) {
          printf("deficient number\n");
      } else {
          for(i = 2; i <= med; i++){
              if(num%i == 0) {
                  divPlus+= i;
                  int quot = num / i;
                  if(i != quot) {
                      divPlus+= (num/i);
                  }
            }
          }
          if(divPlus == num) {
          printf("perfect number\n");
      }else if(divPlus < num) {
          printf("deficient number\n");
      } else {
          printf("abundant number\n");
        }
      }
      
  }
  
  return 0;
  
} 

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define prep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 1) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<mint> nums(K + 1);
  prep(i, K / 2) {
    mint mi(K / i);
    nums.at(i) = mi.pow(N);
  }
  for (int i = K / 2; i > 0; i--) {
    int j = 2;
    while (j * i < K + 1) {
      nums.at(i) -= nums.at(j * i);
      j++;
    }
  }
  mint ans(0);
  prep(i, K) { ans += nums.at(i) * i; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4048
line1 = input().split()
h,w = int(line1[0]), int(line1[1])

input_mass = []
for _ in range(h):
    s = input()
    t = [s[i] for i in range(len(s))]
    input_mass.append(t)

for high in range(h):
    for width in range(w):
        if input_mass[high][width] == '#':
            print('#',end='')
        else:
            count = 0
            for i in [high-1,high,high+1]:
                for j in [width-1,width,width+1]:
                    if 0<=i<h and 0<=j<w:
                        if input_mass[i][j] == '#':
                            count += 1
            print(count,end='')
    print()
    
    

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

double g_vec[101][2];

int compare(const void *a, const void *b) {
	if (*(double*)a > *(double*)b)
		return 1;
	if (*(double*)a < *(double*)b)
		return -1;
	return 0;
}

void input(int n, double p0[2], double p1[2]) {
	int i;

	for (i = 0; i < n; i++) {
		scanf(" %lf,%lf ", &g_vec[i][0], &g_vec[i][1]);
	}
	qsort(g_vec, n, sizeof(double)*2, compare);
	p0[0] = g_vec[0][0];
	p0[1] = g_vec[0][1];
	p1[0] = g_vec[n-1][0];
	p1[1] = g_vec[n-1][1];
	g_vec[0][0] = g_vec[0][1] = NAN;
}

int find(int n, double p[2], int max) {
	int i, midx;
	double dx, dy, rad, m;

	m = max ? -3.15 : 3.15;
	for (i = 0; i < n; i++) {
		if (isnan(g_vec[i][0]) || g_vec[i][0] < p[0]) {
			continue;
		}
		dx = g_vec[i][0] - p[0];
		dy = g_vec[i][1] - p[1];
		rad = atan2(dy, dx);
		if (max ? (rad > m) : (rad < m)) {
			m = rad;
			midx = i;
		}
	}
	return midx;
}

int solve(int n) {
	int i, a = n;
	double p[2], p0[2], p1[2];

	input(n, p0, p1);

	p[0] = p0[0];
	p[1] = p0[1];
	while (1) {
		i = find(n, p, 1);
		if (g_vec[i][0] == p1[0] && g_vec[i][1] == p1[1]) {
			break;
		}
		p[0] = g_vec[i][0];
		p[1] = g_vec[i][1];
		g_vec[i][0] = g_vec[i][1] = NAN;
		a--;
	}
	p[0] = p0[0];
	p[1] = p0[1];
	while (1) {
		i = find(n, p, 0);
		if (g_vec[i][0] == p1[0] && g_vec[i][1] == p1[1]) {
			break;
		}
		p[0] = g_vec[i][0];
		p[1] = g_vec[i][1];
		g_vec[i][0] = g_vec[i][1] = NAN;
		a--;
	}
#if 0
	printf("%lf,%lf\n", p0[0], p0[1]);
	printf("%lf,%lf\n", p1[0], p1[1]);
#endif
	return a - 2;
}

int main(void) {
	int n;

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

		printf("%d\n", solve(n));
	}
	return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

mt19937 mt_engine(chrono::steady_clock::now().time_since_epoch().count());
template <class T> enable_if_t<is_integral_v<T>, T> rng(T l, T r) {
  return uniform_int_distribution<T>(l, r - 1)(mt_engine);
}
template <class T> enable_if_t<is_floating_point_v<T>, T> rng(T l, T r) {
  return uniform_real_distribution<T>(l, r)(mt_engine);
}

struct stopwatch {
  clock_t t = clock();
  void restart() { t = clock(); }
  int elapsed() const { return (clock() - t) * 1000 / CLOCKS_PER_SEC; }
  void operator()(string s = "Time") const {
    cerr << s + ": " << elapsed() << " ms\n";
  }
} sw;

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmax = [](auto&& a, auto b) { return a < b ? a = b, 1 : 0; };

constexpr int n = 365, m = 26;
int c[m], s[n][m];

int type[n];
int score(int lim = n) {
  vector<int> last(m, -1);
  int res = 0;
  for (int i = 0; i < lim; ++i) {
    res += s[i][type[i]];
    last[type[i]] = i;
    for (int j = 0; j < m; ++j) {
      res -= c[j] * (i - last[j]);
    }
  }
  return res;
}

void solve() {
  vector<vector<pair<int, array<int, m>>>> v(n + 1);
  v[0].resize(1);
  v[0].back().second.fill(-1);
  for (int i = 0; i < n; ++i) {
    vector<pair<int, array<int, m>>> nxt;
    for (auto [sum, last] : v[i]) {
      int cost = 0;
      for (int j = 0; j < m; ++j) {
        cost += c[j] * (i - last[j]);
      }
      for (int j = 0; j < m; ++j) {
        int nsum = sum - cost;
        nsum += s[i][j];
        nsum += c[j] * (i - last[j]);
        auto nlast = last;
        nlast[j] = i;
        nxt.emplace_back(nsum, nlast);
      }
    }
    sort(rbegin(nxt), rend(nxt));
    set<array<int, m>> se;
    for (auto [sum, last] : nxt) {
      if (se.count(last)) break;
      se.insert(last);
      v[i + 1].emplace_back(sum, last);
      if (size(v[i + 1]) == 1000) break;
    }
  }
  auto [sum, last] = v[n][0];
  for (int i = n; i--; ) {
    type[i] = max_element(begin(last), end(last)) - begin(last);
    assert(last[type[i]] == i);
    sum -= s[i][type[i]];
    for (int j = 0; j < m; ++j) {
      sum += c[j] * (i - last[j]);
    }
    for (auto [nsum, nlast] : v[i]) {
      last[type[i]] = nlast[type[i]];
      if (nsum == sum and nlast == last) {
        last = nlast;
        break;
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int _n;
  cin >> _n;
  assert(_n == n);
  for (int j = 0; j < m; ++j) {
    cin >> c[j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
    }
  }
  solve();
  for (int i = 0; i < n; ++i) {
    cout << type[i] + 1 << '\n';
  }
  sw();
  cerr << score() << '\n';
}


Measured memory_bytes: 34788
#include<bits/stdc++.h>
#include<stdio.h>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=2e5+500;
const int inf=0x3f3f3f3f;
const int p=1e9+7;
int a,b;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    while(cin>>a>>b){
        cout<<6-a-b<<'\n';
    }
    return 0;

}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
ll qpow(ll a , ll b){
	ll sum = 1;
	while(b){
		if(b&1)sum = (sum * a)%mod;
		a = (a * a)%mod;
		b >>= 1;
	}
	return sum;
}
ll sum[maxn];
int a[maxn];
int main(){
	int n , k;cin >> n >> k;
	a[1] = 0;
	ll s = qpow(10 , 100);
	fo(i,2,n+1)a[i] = a[i-1]+1;
	sum[1] = a[1];
	fo(i,2,n+1){
		sum[i] = sum[i-1] + a[i];
	}
	ll ans = 0;
	fo(i,k,n+1){
		ans = (ans + sum[n+1] - sum[n+1-i] - sum[i] + 1 + mod)%mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#include <vector>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define MININF -1e18L
using namespace std;
typedef long long ll;
typedef pair<int, int> intint;

int main(void)
{
    int t,x;
    cin >> t >> x;
    double ans = (double)t / x;
    printf("%.10f\n", ans);
}

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

typedef long long ll;

int n;
ll k;


int main(){
	cin >> n >> k;
	vector<int> a(n+1);
	vector<int> mp(n+1);
	vector<int>mp1(n+1);
	vector<int> vis(n+1, 0);
	for(int i = 1; i<=n; i++){
		cin >> a[i];
	}
	int cur = 1;
	int h = 0;
	int cnt= 0;
	while(vis[cur] == 0){
		vis[cur] = 1;
		cnt++;
		mp1[cnt] = cur;
		cur = a[cur];
		h++;
	}
	fill(vis.begin(), vis.end(), 0);
	cnt = 0;
	while(vis[cur] == 0){
		vis[cur] = 1;
		cnt++;
		mp[cnt] = cur;
		cur = a[cur];
	}
	mp[0] = mp[cnt];
	int ans = k+1>h ? mp[(k - h + 1) % cnt] : mp1[k+1];
	cout << ans;
	
	return 0;
} 

Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  int res;
  
  cin >> N >> A;

  res = N - (N / 500)*500;
  
  if (res <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

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

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

typedef long long ll;

ll INF = 100000000000000;
ll MOD = 1e9+7;

using Graph = vector<vector<ll>>;

Graph G(100010);
ll table[100010];

int main(){
    ll N;cin >> N;
    vector<string> S(N);
    ll cnt = 0,case1 = 0,case2 = 0,case3 = 0;
    for(ll i = 0;i < N;i++){
        cin >> S[i];
        ll n = S[i].size();
        for(ll j = 0;j < n;j++){
            if(S[i].substr(j,2) == "AB")cnt++;
        }        
        if(S[i][0] == 'B' && S[i][n-1] == 'A'){
            case1++;
            continue;
        }
        if(S[i][0] == 'B' && S[i][n-1] != 'A')case2++;
        if(S[i][0] != 'B' && S[i][n-1] == 'A')case3++;
    }
    //cout << cnt << ' ' << case1 <<' '<<  case2 <<' '<< case3 << endl;
   if(case1 > 0){
       if(case2 > 0 || case3 > 0){
           cout << cnt + case1 + min(case2,case3) << endl;
           return 0;
       }
       cout << cnt + case1 - 1 + min(case2,case3) << endl;
   }else{
       cout << cnt + min(case2,case3) << endl;
   }
   
}



Measured memory_bytes: 3200
import sys
import math
import fractions

sys.setrecursionlimit(10000)
INF = float('inf')


def inp():
    return int(input())


def inl():
    return list(map(int, input().split()))


def inls():
    return input().split()


def Yesif(cond):
    print('Yes' if cond else 'No')


def YESIF(cond):
    print('YES' if cond else 'NO')


def yesif(cond):
    print('yes' if cond else 'no')


N = inp()
A = inl()

ans = set()
ans.add(A[1])
gcd = A[0]
for i, a in enumerate(A):
    if i == 0:
        continue

    news = set()
    for ss in ans:
        news.add(fractions.gcd(ss, a))
    ans = news

    new_gcd = fractions.gcd(gcd, a)
    if new_gcd < gcd:
        ans.add(gcd)
    gcd = new_gcd

print(max(ans))


Measured memory_bytes: 16104
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n;
  cin >> n;
  for (int x = 1; x <= n; x *= 2) {
    if ((n + 1) % x == 0 && odd((n + 1) / x)) {
      cout << x << endl;
      return 0;
    }
  }
  cout << n + 1 << endl;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m, s, g1, g2, b1, b2, c;
  long long int INF = 1e12;
  while(cin >> n >> m >> s >> g1 >> g2, n){
    --s;--g1;--g2;
    vector< vector<long long int> > G(n,vector<long long int>(n,INF));
    for(int i = 0; i < n; ++i) G[i][i] = 0;
    for(int i = 0; i < m; ++i){
      cin >> b1 >> b2 >> c;
      --b1;--b2;
      G[b1][b2] = c;
    }
    for(int k = 0; k < n; ++k)
      for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
          G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
    long long int ans = INF;
    for(int i = 0; i < n; ++i){
      ans = min(ans,G[s][i]+G[i][g1]+G[i][g2]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
int main() {
	ll N, M, X; cin >> N >> M >> X;
	ll A, a = 0, b = 0;
	rep(i, 0, M)
	{
		cin >> A;
		(X > A) ? b++ : a++;
	}
	cout << min(a, b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <queue>
#include <thread>
#include<bits/extc++.h>

using namespace __gnu_pbds;
#pragma GCC optimize("Ofast")

#define ll long long

#define gc (c = getchar())
#define gi(x) scanf("%d", &x)
#define gid(x, y) scanf("%d%d", &x, &y)
#define gll(x) scanf("%lld", &x)
#define glld(x, y) scanf("%lld%lld", &x, &y)
#define gllt(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define git(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pi(x) printf("%d\n", x)
#define pr(x) return !(printf("%lld\n", (long long)(x)))
#define pcs(ch, cs, x) printf("Case %c%d: %d\n", ch, cs, x)
#define pllcs(ch, cs, x) printf("Case %c%d: %lld\n", ch, cs, x)
#define pcsyn(ch, cs, st) printf("Case %c%d: %s\n", ch, cs, (st) ? "Yes" : "No")
#define pyn(st) printf("%s\n", (st) ? "yes" : "no")
#define pryn(st) return !(printf("%s\n", (st) ? "YES" : "NO"))
#define pll(x) printf("%lld\n", x)
#define plld(x, y) printf("%lld %lld\n", x, y)

#define mp(x, y) std::make_pair(x, y)
#define fcs(x) while (x--)
#define dbg(x) std::cerr << #x << " " << x << std::endl
#define fi freopen("in.txt", "r", stdin)
#define fo freopen("out.txt", "w", stdout)
#define siz(x) (int)x.size()
#define pb(x) push_back(x)

inline long long max(long long x, long long y) { return x > y ? x : y; }

inline long long min(long long x, long long y) { return x > y ? y : x; }

long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }


const int maxn = 2e5 + 5;
int fa[maxn];
void init(int n) {for (int i = 0; i <= n + 1; ++ i) fa[i] = i;}
int find(int x){ return fa[x] == x ? x : fa[x] = find(fa[x]);}
void join(int x, int y){
    int fx = find(x), fy = find(y);
    if (fx == fy) return;
    else fa[fy] = fx;
}
int main(){
    int n ,m;
    gid(n, m);
    init(n);
    for (int i = 1; i <= m; ++ i){
        int x, y;
        gid(x, y);
        join(x, y);
    }
    std::map<int, int> cnt;
    for (int i = 1; i <= n; ++ i){
        cnt[find(i)] ++;
    }
    int ret = 0;
    for (auto & it : cnt) ret = max(ret, it.second);
    pi(ret);
}


Measured memory_bytes: 13820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

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

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

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

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

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

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() { //abc087 D
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (uf.issame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
struct Node {
	int child[26];
	int ends;
};
Node trie[2000000];
int upto;
void add(int a, const char* str, int i) {
	if (!i) {
		trie[a].ends++;
		return;
	}
	int nx = str[i-1]-'a';
	if (!trie[a].child[nx]) {
		trie[a].child[nx] = ++upto;
	}
	add(trie[a].child[nx], str, i-1);
}
ll ans = 0;
map<int, int> remaining;
void dfs(int a, const char* str, int i) {
	if (!i) {
		return;
	}
	ans += trie[a].ends;

	int nx = str[i-1]-'a';
	remaining[nx]--;
	for (int j = 0; j < 26; j++) {
		if (j != nx && remaining[j]) ans += trie[trie[a].child[j]].ends;
	}
	dfs(trie[a].child[nx], str, i-1);
}

string s[200010];


int main() {
	scanf("%d", &n);
	++upto;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		add(1, s[i].c_str(), s[i].size());
	}
	for (int i = 0; i < n; i++) {
		remaining.clear();
		for (auto a : s[i]) remaining[a-'a']++;
		dfs(1, s[i].c_str(), s[i].size());
		//printf(" %lld\n", ans);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 205800
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(101):
    for j in range(101):
        H=[]
        for k in range(n):
            if l[k][2]>0:
                H.append(l[k][2]+abs(l[k][0]-i)+abs(l[k][1]-j))
            else:
                continue
        if len(set(H))==1:
            for k in range(n):
                if l[k][2]==0:
                    if H[0]-abs(l[k][0]-i)-abs(l[k][1]-j)>0:
                        break
            else:
                print(i,j,H[0])

Measured memory_bytes: 42732
def solve():
  N, K = map(int, input().split())
  _S = input()
  S = []
  b = _S[0]
  s = 0
  if b == '0': S.append(0)
  for _s in _S:
    if b == _s:
      s = s + 1
    else:
      b = _s
      S.append(s)
      s = 1
  S.append(s)
  if b == '0': S.append(0)

  num = min(len(S), 2 * K + 1)
  # n = sum(S[0:num if _S[0] == '1' else (num - 1)])
  n = sum(S[0:num])
  m = n
  # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):
  for i in range(0, len(S) - num, 2):
    n = n - sum(S[i:i+2])
    n = n + sum(S[i + num:i + num + 2])
    m = max(m, n)

  return m

print(solve())

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

int main(){
    long int N,d,ans=1,count=1;
    vector<int> a;

    cin >> N;//N問
    for (int i = 0; i < N; i++){
        cin >> d;
        a.push_back(d);
    }
    //sort(D.begin(),D.end());//昇順にソート

    //3のn乗から全ての項が奇数の場合を引く
    //a[i]が奇数のとき、b[i]が奇数になるのは1通り
    //a[i]が偶数のとき、b[i]が奇数になるのは2通り

    for (int i = 0; i < N; i++){
        ans *= 3;
    }
    for (int i = 0; i < N; i++){
        if (a[i]%2==1){
            count *= 1;
        }else{
            count *= 2;
        }
    }
//    cout << ans << endl;
//    cout << count << endl;
    cout << ans - count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll mat[205][205];
int n;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
//O(N^3)
//mat must be defined
ll calcdet(){
	for(int j=0;j<n;j++){
		int pivot=-1;
		for(int i=j;i<n;i++){
			if(mat[i][j]){
				pivot = i; break;
			}
		}
		if(pivot == -1) return 0;
		rep(k,n) swap(mat[j][k],mat[pivot][k]);
		ll rev = modpow(mat[j][j],mod-2);
		for(int i=j+1;i<n;i++){
			if(mat[i][j]){
				ll gg = mat[i][j]*rev%mod;
				for(int g=j;g<n;g++){
					mat[i][g] -= mat[j][g]*gg%mod;
					if(mat[i][g]<0) mat[i][g]+=mod;
				}
			}
		}
	}
	ll ret = 1;
	//for(int i=0;i<n;i++) {rep(j,n)cout<<mat[i][j]<<" "; cout<<endl;}
	for(int i=0;i<n;i++) ret=ret*mat[i][i]%mod;
	return (mod+ret)%mod;
}
int main(){
	int m;
	cin >> n >> m;
	vector<P>edge;
	rep(i,m){
		int a,b; cin >> a >> b;
		a--; b--;
		edge.pb(mp(a,b));
	}
	srand((unsigned)time(NULL));
	rep(q,30){
		rep(i,n) rep(j,n){
			mat[i][j] = 0;
		}
		rep(i,m){
		    int a = edge[i].fi, b = edge[i].sc;
			if(a && b){
				ll rnd = 1LL*rand()*rand()%mod;
				if(rnd == 0) rnd = 1;
				mat[a][b] = rnd;
				mat[b][a] = (mod-rnd)%mod;
			}
			else{
				ll rnd = 1LL*rand()*rand()%mod;
				int flag = rand();
				if(flag%2 == 0){
					mat[a][b] = mat[b][a] = rnd;
				}
				else{
					mat[a][b] = rnd;
					mat[b][a] = (mod-rnd)%mod;
				}
			}
		}
		if(calcdet()){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}


Measured memory_bytes: 3436
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int sort(const void * a, const void * b)
{
    if( *(long long int*)a - *(long long int*)b < 0 )
        return 1;
    if( *(long long int*)a - *(long long int*)b > 0 )
        return -1;
    return 0;
}

int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    long long x[n],y[n],z[n],score[n],ans=0,tmp=0;
    
    for (int i=0; i<n; i++){
        scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);
    }
    
    for (int i=0; i<n; i++){
        score[i]=x[i]+y[i]+z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    }
    tmp=0;
    
    for (int i=0; i<n; i++){
        score[i]=x[i]+y[i]-z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    }
    tmp=0;
    
    for (int i=0; i<n; i++){
        score[i]=x[i]-y[i]+z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    }
    tmp=0;
        
    for (int i=0; i<n; i++){
        score[i]=x[i]-y[i]-z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    }
    tmp=0;
    
    for (int i=0; i<n; i++){
        score[i]=0-x[i]+y[i]+z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    }
    tmp=0;

    for (int i=0; i<n; i++){
        score[i]=0-x[i]+y[i]-z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    }
    tmp=0;
    
    for (int i=0; i<n; i++){
        score[i]=0-x[i]-y[i]+z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    }
    tmp=0;
        
    for (int i=0; i<n; i++){
        score[i]=0-x[i]-y[i]-z[i];
    }
    qsort (score,n,sizeof(long long),sort);
    for (int i=0; i<m; i++){
        tmp+=score[i];
    }
    if(ans<tmp){
        ans=tmp;
    } 
    tmp=0;
    
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
int main(void){
    std::string weather[3];
    weather[0] = "Sunny";
    weather[1] = "Cloudy";
    weather[2] = "Rainy";
    std::string today;
    int forecast = 0;

    std::cin >> today;
    for(int i =0; i < 3; i++){
        if (today == weather[i]){
            forecast = i + 1;
        }
    }
    if(forecast > 2)
        forecast = 0;
    
    std::cout << weather[forecast] << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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


int main(){
    long int n, k;
    cin >> n >> k;
    long int a[n];
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    long int per[n];
    fill(per, per + n, -1);
    long int nx = 0;
    long int num = 0;
    long int a1;
    long int a2;
    while(true){
        if(per[nx] != -1){
            a1 = per[nx];
            a2 = num;
            break;
        }
        per[nx] = num;
        nx = a[nx];
        num++;
        if(num == k){
            cout << nx + 1 << endl;
            return 0;
        }
    }
    long int ans_n = (k - a1) % (a2 - a1);
    long int ans = nx;
    rep(i, ans_n){
        ans = a[ans];
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 6724
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include<stack>
#include<string>
#include<algorithm> 
#include <set>
#include<list>
#include <bit>
#include <bitset>
#include <cstdint>
#include <initializer_list>
using namespace std;
int main() {
    long long int N, K; cin >> N >> K;
    int ans = 0;
    while (1) {
        ans++;
        N /= K;
        if (N == 0)break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Trim();
            var o = s.ToCharArray().OrderBy(c => c).ToArray();

            if((o.Count(c => c == o[0]) == 2) && (o.Count(c => c == o[2]) == 2)){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13268
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    var ab = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }.sortedBy { it[1] }
    var count=0
    while(ab.isNotEmpty()){
        count++
        val r = ab[0][1]
        ab=ab.filter { it[0]>=r }
    }
    println(count)

}

Measured memory_bytes: 123528
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    double ans = 0;
    for(int j = 1; j<=n; j++){
        double add = 1.0/n;
        int i = j;
        while(i < k){
            i *= 2;
            add /= 2;
        }
        ans += add;
    }
    cout << std::fixed << std::setprecision(10) << ans << endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll n,a,x[50];
    cin>>n>>a;
    for(int i=0;i<n;i++) cin>>x[i];
    ll dp[51][51][2501]={};
    for(int i=0;i<=50;i++) dp[i][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=1;j<=n;j++){
            for(int k=0;k<=n*a;k++){
                if(k>=x[i]) dp[i+1][j][k]=dp[i][j][k]+dp[i][j-1][k-x[i]];
                else dp[i+1][j][k]=dp[i][j][k];
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 51072
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)

sorted_arr = arr.dup
sorted_arr.sort!

def binary_search(arr, n, key)
  left = 0
  right = n
  while left < right
    mid = (left + right) / 2
    if arr[mid] == key
      return mid
    elsif key < arr[mid]
      right = mid
    else
      left = mid + 1
    end
  end
  return false
end

(0..n-1).each do |i|
  key = arr[i]
  index = binary_search(sorted_arr, n, key)
  if index < n/2
    puts sorted_arr[n/2]
  else
    puts sorted_arr[n/2 - 1]
  end
end


Measured memory_bytes: 26260
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
#include<stack>

using namespace std;

#define st first
#define nd second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REV(a) reverse(a.begin(),a.end())
#define SORT(a) sort(a.begin(),a.end())
#define inf (int)1e9
#define linf (long long)1e18

typedef long long ll;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

ll n,x,b,c,d;
vector<pair<ll,ll> > a,g;
ll ans;
int main() {
	cin>>x>>b>>c>>d>>n;
	n*=4;
	a.push_back({1,x});
	a.push_back({2,b});
	a.push_back({4,c});
	a.push_back({8,d});
	g.push_back({x*8,0});
	g.push_back({b*4,1});
	g.push_back({c*2,2});
	g.push_back({d,3});
	SORT(g);
	FOR(i,0,4){
		ll x=g[i].second,y=a[x].first,z=a[x].second;
		ans+=n/y*z;
		n%=y;
	}
	cout<<ans<<endl;



  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long int n;
  cin >> n;
  int a = 0;
  int b = 0;
  for (int i = 0; i < n; i++) {
    long long int num;
    cin >> num;
    if (num%4==0){
      a++;
    }
    else if (num%2==0){
      b++;
    }
  }
 if (a+b/2 >= n/2)
    cout<<"Yes";
  else
    cout<<"No";

return 0;
}

Measured memory_bytes: 256