akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(auto i=a;i<=b;++i)
#define LL long long
#define itrange(i,a,b) for(auto i=a;i!=b;++i)
#define rerange(i,a,b) for(auto i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
const int dev=1000000007;
int n;
string s1,s2;
bool flag;
LL ans;
void init(){
    cin>>n>>s1>>s2;
    ans=s1[0]==s2[0]?3:6;
    flag=s1[0]!=s2[0];
}
void solve(){
    range(i,flag?2:1,n-1){
        if(s1[i]==s2[i]){
            if(!flag)ans=(ans<<1)%dev;
            flag=false;
        }
        else{
            if(flag)ans=ans*3%dev;
            else ans=(ans<<1)%dev;
            ++i;flag=true;
        }
    }
    cout<<ans<<endl;
}
int main() {
    init();
    solve();
    return 0;
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int e, c, s;
	c = s = 0;
	while (cin >> e) {
		if (e == 5) c++;
		else if (e == 7) s++;
	}
	cout << ((c == 2) && (s == 1) ? "YES" : "NO") << ende;
  return 0;
}


Measured memory_bytes: 256
/*  ex3_3
    ruuu0048 */
#include <stdio.h>

int main(void){

    int number,base,count; //NとKと割り算をした回数の変数を宣言

    scanf("%d",&number); //変数にNの数を入力する
    scanf("%d",&base); //変数にKの数を入力する

    count = 0; //初期値は0にする

    while(number >= base) //Nの値の方がKの値以上のとき割り算ができる
    {
        number = number / base; //割り算をして、その商をnumberに代入する
        count += 1; //割り算した数を数える
    }
    
    printf("%d\n",count+1); //K進表記したときの桁数は割り算した回数に1を足したものなので、それを出力
    
    return 0; 
}


Measured memory_bytes: 128
n=int(input())
L=list(map(int,input().split()))	
a=0
b=0
for i in range(n):
  if L[i]%2==0 :
    a+=1
    if L[i]%3==0 or L[i]%5==0:
      b+=1
if a==b:
  print('APPROVED')
else:
  print('DENIED')
    

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
template <typename T>
struct BIT
{
    int n;
    vector<T> d;
    BIT(ll n = 0) : n(n), d(n + 1) {}
    void add(ll i, T x = 1)
    {
        for (i++; i <= n; i += i & -i)
        {
            d[i] += x;
        }
    }
    T sum(ll i)
    {
        T x = 0;
        for (i++; i; i -= i & -i)
        {
            x += d[i];
        }
        return x;
    }
    T sum(ll l, ll r)
    {
        return sum(r - 1) - sum(l - 1);
    }
};
int main()
{
    ll n, q;
    cin >> n >> q;
    vector<ll> c(n);
    vector<ll> v(n, -1);
    vector<ll> d[n];
    rep(i, n)
    {
        cin >> c[i];
        c[i]--;
        if (v[c[i]] != -1)
        {
            d[v[c[i]]].push_back(i);
        }
        v[c[i]] = i;
    }
    vector<P> qs[n];
    rep(i, q)
    {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;
        qs[l].push_back(P(r, i));
    }
    vector<ll> ans(q);
    BIT<ll> a(n);
    for (ll x = n - 1; x >= 0; x--)
    {
        rep(y, d[x].size())
        {
            a.add(d[x][y], 1);
        }
        rep(i, qs[x].size())
        {
            ll y = qs[x][i].first;
            ll num = qs[x][i].second;
            ans[num] = y - x + 1 - a.sum(y);
        }
    }
    rep(i, q)
    {
        printf("%lld\n", ans[i]);
    }
}

Measured memory_bytes: 71084
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const int inf = 1145141919810931;
typedef pair<int, int> P;
typedef pair<P, int>PP;
typedef pair<int, char>PC;
struct edge { int to, cost; };
vector<int>V[100005];
int dp[100005];
int memo(int now) {
	if (dp[now] != inf)return dp[now];
	int res;
	if (!V[now].size())res = 0;
	else {
		vector<int>x;
		rep(i, V[now].size()) {
			x.push_back(memo(V[now][i]));
		}
		sort(x.begin(), x.end());
		reverse(x.begin(), x.end());
		rep(i, x.size()) {
			x[i] += i + 1;
		}
		sort(x.begin(), x.end());
		res = x[x.size()-1];
	}
	return dp[now] = res;
}

signed main() {
	int n; cin >>  n;
	rep(i, n - 1) {
		int a; cin >> a;
		V[a - 1].push_back(i+1);
	}
	fill(dp, dp + n, inf);
	memo(0);
	cout << dp[0] << endl;
}

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

typedef long long ll;
ll N, Q;
// w, c, d
vector<vector<tuple<ll, ll, ll>>> Adj;
const ll LEVEL = 20;
vector<vector<ll>> Anc;
vector<ll> Dist, Depth;
// query id, coefficient, x, y
vector<vector<tuple<ll, ll, ll, ll>>> Calc;
// (for each color) sum of lengths, number
vector<pair<ll, ll>> Info;
vector<ll> R;

void init_dfs(ll v, ll par, ll depth, ll dist) {
  Anc[0][v] = par;
  Depth[v] = depth;
  Dist[v] = dist;
  for (auto edge : Adj[v]) {
    ll w = get<0>(edge);
    if (w == par) continue;
    ll d = get<2>(edge);
    init_dfs(w, v, depth + 1, dist + d);
  }
}
ll lca(ll u, ll v) {
  if (Depth[u] > Depth[v]) swap(u, v);
  for (ll k = LEVEL - 1; k >= 0; --k) {
    if ((Depth[v] - Depth[u]) & (1 << k)) v = Anc[k][v];
  }
  if (u == v) return u;
  for (ll k = LEVEL - 1; k >= 0; --k) {
    if (Anc[k][u] != Anc[k][v]) {
      u = Anc[k][u];
      v = Anc[k][v];
    }
  }
  return Anc[0][u];
}
void dfs(ll v, ll par) {
  for (auto calc : Calc[v]) {
    ll i = get<0>(calc), coeff = get<1>(calc);
    ll x = get<2>(calc), y = get<3>(calc);
    R[i] += coeff * (Dist[v] - Info[x].first + y * Info[x].second);
  }
  for (auto edge : Adj[v]) {
    ll w = get<0>(edge);
    if (w == par) continue;
    ll c = get<1>(edge), d = get<2>(edge);
    Info[c].first += d;
    ++Info[c].second;
    dfs(w, v);
    Info[c].first -= d;
    --Info[c].second;
  }
}
int main() {
  cin >> N >> Q;
  Adj.resize(N);
  for (ll i = 0; i < N - 1; ++i) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    --a;
    --b;
    --c;
    Adj[a].push_back(make_tuple(b, c, d));
    Adj[b].push_back(make_tuple(a, c, d));
  }
  Anc.resize(LEVEL);
  for (auto &anc : Anc) anc.resize(N, -1);
  Depth.resize(N);
  Dist.resize(N);
  init_dfs(0, -1, 0, 0);
  for (ll k = 1; k < LEVEL; ++k) {
    for (ll v = 0; v < N; ++v) {
      if (Anc[k - 1][v] != -1) Anc[k][v] = Anc[k - 1][Anc[k - 1][v]];
    }
  }
  Calc.resize(N);
  for (ll i = 0; i < Q; ++i) {
    ll x, y, u, v;
    cin >> x >> y >> u >> v;
    --x;
    --u;
    --v;
    ll w = lca(u, v);
    Calc[u].push_back(make_tuple(i, 1, x, y));
    Calc[v].push_back(make_tuple(i, 1, x, y));
    Calc[w].push_back(make_tuple(i, -2, x, y));
  }
  Info.resize(N - 1);
  R.resize(Q);
  dfs(0, -1);
  for (ll r : R) cout << r << endl;
  return 0;
}


Measured memory_bytes: 49264
import numpy as np
N, M = map(int, input().split())
taiou = np.zeros((N,M))
for i in range(M):
    val =  input().split()
    for j in range(int(val[0])):
        v = int(val[j+1])
        taiou[v-1][i] = 1
p = np.array([int(v) for v in input().split()])
cnt = 0
for val in range(2**N):
    v = taiou*np.array([[int(i)] for i in bin(val)[2:].zfill(N)])
    if np.sum(np.sum(v,axis=0)%2==p)==M:
        cnt+=1
    
print(cnt)

Measured memory_bytes: 12448
N, K = gets.split.map(&:to_i)
S = gets

cur_n = "1";

num = 0

arr = []

max = 0

prev = false

S.length.times do |i|
  
  if S[i] != cur_n
    arr.push(num)
    num = 1
    cur_n = S[i]
  else
    num += 1
  end
end  


arr.length.times do |i|
  p_ = prev
  
  if(i % 2 == 0)
    if !prev 
      p_ = 0
      (K*2 + 1).times do |j|
        break if i + j >= arr.length
        p_ += arr[i + j].to_i
  
      end
    else
      
      if i + K * 2 - 1 < arr.length

        p_ += arr[i + K * 2 - 1]

        if i + K * 2 < arr.length
          p_ += arr[i + K * 2]
        end
      end
      
      p_ -= (arr[i - 2] + arr[i - 1])
    
    end

  max = p_ if p_ > max
  prev = p_

  else
    next  
  end

end

puts max


Measured memory_bytes: 2808
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const input = lines.shift();
  const input2 = lines.shift();
  if (input.length + 1 === input2.length && input2.indexOf(input) === 0) {
    console.log("Yes");
  } else {
    console.log("No");
  }
});


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

int main() {
	int a,b,c,d;
  	cin>>a>>b>>c>>d;
  
  	int mymax=max(a,c);
  	int mymin=min(b,d);
  	cout<<max(0,mymin-mymax)<<endl;
  	
}


Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll a,b;
            cin>>a>>b;
            cout<<a*b<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
inline void in(int &k){
	int x=0;
	char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
	k=x;
}
int n,a[N],b[N];
int main(){
	in(n);
	for(int i=1;i<=n;i++) in(a[i]);
	for(int i=1;i<=n;i++) b[i]=a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		if(b[i]==a[n]) printf("%d\n",a[n-1]);
		else printf("%d\n",a[n]);
} 

Measured memory_bytes: 3200
void main() {
  problem();
}

void problem() {
  auto N = scan!int(3);

  void solve() {
    writeln([N[2], N[0], N[1]].to!(string[]).joiner(" "));
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 256
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る


   input = input.split("\n");
 
     var s = [];
for (var i = 0; i <3 ; i++){
 var r= (input[0].substr(i,1));
          s[i] = r;}
 // console.log(s);
 var count = 0;
       var t = [];
for (var i = 0; i <3 ; i++){
 var r= (input[1].substr(i,1));
          t[i] = r;}
 // console.log(t);
 
 for( var i =0;i <3;i++){
      if(s[i]==t[i]){count = count+1;}
                 }
 console.log(count);
}
 
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n,x,cnt=1,sum=0; cin >>n >>x;
  for(int i=0; i<n; i++){
    int l; cin >>l;
    sum+=l;
    if(sum<=x) cnt++;
    else break;
  }
  cout <<cnt;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  solve();
return 0;}

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

int main(){
  int N, a, b, c, d;
  cin >> N;
  
  a = N / 1000;
  b = (N % 1000) / 100;
  c = (N % 100) / 10;
  d = N % 10;
  
  if(a == b && b == c){
    cout << "Yes" << endl;
  }else if(b == c && c == d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    int a = (int)s.size(), b = (int)t.size();
    vector<vector<int>> dp(a+1, vector<int>(b+1, 0));
    rep(i, a) {
        rep(j, b) {
            dp[i+1][j+1] = max({dp[i+1][j], dp[i][j+1]});
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
        }
    }
    int i = a, j = b;
    string ans = "";
    while (i>0 && j>0) {
        int lu, l, u;
        lu = dp[i-1][j-1];
        l = dp[i][j-1];
        u = dp[i-1][j];
        if (lu == dp[i][j]-1 && s[i-1] == t[j-1]) {
            ans = s[i-1] + ans;
            i--; j--;
        } else {
            if (l > u) j--;
            else i--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#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 yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll I=1000000000000000001;
const int INF=1000000;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	cin>>n;
	int total=0;
	for(int i=1; i<n+1; i++){
		if(n-i<=i){
			cout<<total<<endl;
			return 0;
		}
		total++;
	}

	return 0;

}


Measured memory_bytes: 256
n=int(input())
if n==1:
  print(1)
else:
 x=[]
 y=[]
 for i in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)

 distance=[]
 for i in range(n):
  for k in range(n):
   if x[i]!=x[k] or y[i]!=y[k]:
    distance.append([x[i]-x[k],y[i]-y[k]])

 q=[]
 for i in range((n**2-n)):
  q.append(distance.count(distance[i]))

 print(n-max(q))

Measured memory_bytes: 3444
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int s1 = 0,s2 = 0;
	int cnt[256] = { 0 },newcnt = 0;
	char s[7];
	scanf("%s",s);
	for (int i = 0; i < 4; ++i)
	{
		++cnt[s[i]];
	}
	for (int i = 0; i < 256; ++i)
	{
		if(cnt[i] == 2)	++newcnt;
	}
	if(newcnt == 2)	puts("Yes");
	else puts("No");
	return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0; }
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0; }

using namespace std;

int main(void){
	int D,E;
	while(cin>>D>>E,D&&E) {
		double m = 10000;
		rep(i,D) {
			chmin(m, fabs(sqrt((i*i)+(D-i)*(D-i))-(double)E));
		}
		printf("%.10lf\n", m);
	}
        
	return 0;
}

Measured memory_bytes: 3080
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> grids(H, vector<int>(W, 0));
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < W; ++j) {
            grids[i][j] = (s[j] == '#') ? -1 : 0;
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (grids[i][j] == 0) {
                int n = 0;
                if (i > 0 && j > 0 && grids[i - 1][j - 1] == -1) {
                    ++n;
                }
                if (i > 0 && grids[i - 1][j] == -1) {
                    ++n;
                }
                if (i > 0 && j < W - 1 && grids[i - 1][j + 1] == -1) {
                    ++n;
                }
                if (j > 0 && grids[i][j - 1] == -1) {
                    ++n;
                }
                if (j < W - 1 && grids[i][j + 1] == -1) {
                    ++n;
                }
                if (i < H - 1 && j > 0 && grids[i + 1][j - 1] == -1) {
                    ++n;
                }
                if (i < H - 1 && grids[i + 1][j] == -1) {
                    ++n;
                }
                if (i < H - 1 && j < W - 1 && grids[i + 1][j + 1] == -1) {
                    ++n;
                }
                grids[i][j] = n;
            }
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (grids[i][j] == -1) {
                cout << "#";
            }
            else {
                cout << grids[i][j];
            }
        }
        cout << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3612
n = list(map(int,list(input())))
limit = 7
d = [ [] for i in range(len(n))]
op = [ [] for i in range(len(n))]

for i,val in enumerate(n):
	if i == 0:
		d[0].append(n[0])
		op[0].append("")
	else:
		for j in d[i-1]:
			d[i].append(j+val)
			d[i].append(j-val)
		for j in op[i-1]:
			op[i].append(j + "+")
			op[i].append(j + "-")


_op = op[len(n)-1][d[len(n)-1].index(limit)]

s = ""
for i,val in enumerate(n):
	s += str(val)
	if i == len(n)-1:
		break
	else:
		s += _op[i]
s += "="+str(limit)
print(s)

Measured memory_bytes: 3064
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let h=read::<i32>();
    let w=read::<i32>();
    for _ in 0..w+2{print!("#")}
    println!("");
    for _ in 0..h{println!("#{}#",read::<String>())}
    for _ in 0..w+2{print!("#")}
    println!("");
}


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

#define ll long long 

ll n,k;
const ll N = 100005;
//ll a[100005];
//ll dp[100005];
const ll Inf = 1e10;

ll ht[3][N];

ll dp[3][N];

ll maxhappiness(ll day, ll prevchoice){
	if(day == n)
      return 0;
  
  	if(dp[prevchoice][day] != -1){
    	return dp[prevchoice][day];
    }
 
  
  	int ans1,ans2;
  	ans1 = ans2 = 0LL;
  	
  	if(prevchoice == 0){
      ans1 = ht[1][day] + maxhappiness(day+1,1);
      ans2 = ht[2][day] + maxhappiness(day+1,2);
    }
  	else if(prevchoice == 1){
      ans1 = ht[0][day] + maxhappiness(day+1,0);
      ans2 = ht[2][day] + maxhappiness(day+1,2);
    }
  	else{
      ans1 = ht[0][day] + maxhappiness(day+1,0);
      ans2 = ht[1][day] + maxhappiness(day+1,1);
    }
  
  	return dp[prevchoice][day] = max(ans1,ans2);
}

int main(){
	cin >> n;
  	for(int i = 0; i < n; i++){
    	cin >> ht[0][i] >> ht[1][i] >> ht[2][i];
    }
  	for(int i = 0; i < n; i++){
    	dp[0][i] = dp[1][i] = dp[2][i] = -1;
    }
 	
  	auto ans1 = maxhappiness(0,0);
  	auto ans2 = maxhappiness(0,1);
  	auto ans3 = maxhappiness(0,2);
    //cout << ans1 << " " << ans2 << " " << ans3 << endl;
  	cout << max(ans1,max(ans2,ans3)) << endl;
    return 0;
}


Measured memory_bytes: 12892
#include <stdio.h>
const int MAX_V = 10000;//10000?????§????´???°??¨?????????

int main(){
int prime [MAX_V+1];
	int i, k, v, n;
	for(i = 2; i <= MAX_V; i++){
		prime[i] = 1;
	}
	for(i = 2; i*i <= MAX_V; i++){//??¨?????????????????????????????¨????????????
		if(prime[i] == 1){
			for(k = 2*i; k <= MAX_V; k += i){
				prime[k] = 0;//?´???°????????°????´???°??§??????
			}
		}
	}
	while(1){
		scanf("%d", &n);
		if(n == 0) break;
		for(i = n; n >= 5; i--){
			if(prime[i] == 1 && prime[i-2] == 1){
				printf("%d %d\n", i-2, i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1064
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
map<int,int> mp;
int count(int n) 
{ 
    return (int)((-1 + sqrt(1 + 8 * n)) / 2); 
} 
void primeFactorize(int n)
{
    int cnt=0;
    while(n%2==0)
    {
        n/=2;
        cnt++;
    }
    mp[2]=cnt;
    cnt=0;
    for(int i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        {
             cnt=0;
            while(n%i==0)
            {
                n/=i;
                cnt++;
            }
            mp[i]=cnt;
        }
    }
    if(n>1)
        mp[n]=1;
}
void solve()
{
    int n;
    cin>>n;
    int ans=0;
    primeFactorize(n);
    for(auto i:mp)
        //cout<<i.F<<" "<<i.S<<"\n";
        ans+=count(i.S);
    cout<<ans<<"\n";

}
int32_t main()
{
    //clock_t tStart = clock();
    // #ifndef ONLINE_JUDGE
    // _READ
    // #endif
    _FAST    
    int t;
    t=1;
    while(t--)
        solve();
    
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/


Measured memory_bytes: 3700
while True:
    n = int(input())
    if n == 0:
        break
    dic = {}
    for i in range(n):
        x, y = input().split()
        dic[x] = y

    n = int(input())
    a = []
    for i in range(n):
        c = input().strip()
        if c in dic.keys():
            a.append(dic[c])
        else:
            a.append(c)

    print(''.join(a))




Measured memory_bytes: 6568
import java.util.Scanner;


class Main {

	public static void main(String[] args) {   

		Scanner scanner = new Scanner(System.in);

		String str =scanner.nextLine();
		int q = Integer.parseInt(scanner.nextLine());


		char[] cha; 
		cha=new char[str.length()];

		char[] cha2;
		cha2=new char[str.length()];

		char[] cha3;
		cha3=new char[str.length()];



		for(int i=0;i < str.length();i++){//

			cha[i]=str.charAt(i);
		}



		for(int i=0;i<q;i++){

			String order =scanner.next();

			if(order.equals("print")){

				int a= Integer.parseInt(scanner.next());
				int b= Integer.parseInt(scanner.next());
				for(int r=a;r<b+1;r++){

					System.out.print(String.valueOf(cha[r]));
					if(r == b){
						System.out.println("");
					}
				}
			}


			else if(order.equals("reverse")){
				int counter=0;
				int a1=Integer.parseInt(scanner.next());
				int b1=Integer.parseInt(scanner.next());
				counter=b1;
				for(int t=0;t<str.length();t++){
					cha2[t]=cha[t];
				}
				for(int t=a1;t<b1+1;t++){

					cha2[t]=cha[counter];;
					counter = counter-1;
				}
				for(int t=0;t < str.length();t++){
					cha[t]=cha2[t];
				}
			}


			else if(order.equals("replace")){
                int counter2=0;
				int a2=Integer.parseInt(scanner.next());
				int b2=Integer.parseInt(scanner.next());
				String p=scanner.next();
				for(int k=0;k<p.length();k++){
					cha3[k]=p.charAt(k);
				}
				
				for(int k=a2;k<b2+1;k++){
					cha[k]=cha3[counter2];
					counter2=counter2+1;
				}
			}


		}
		scanner.close();
	}
}



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

int n;

vector<int> shuffle(vector<int> card, int cut){
	int i, a, b;
	vector<int> tmp;
	if(cut == 0){
		a=0;
		b=n/2;
		for(i=0;i<card.size();i++){
			if((i+1)%2 == 1){
				tmp.push_back(card[a++]);
			}else{
				tmp.push_back(card[b++]);
			}
		}
	}else{
		for(i=cut;i<card.size();i++){
			tmp.push_back(card[i]);
		}
		for(i=0;i<cut;i++){
			tmp.push_back(card[i]);
		}
	}
	return tmp;
}

int main(){
	int m, i, cut;
	cin>>n;
	n = n*2;
	vector<int> card(n);
	for(i=0;i<n;i++){
		card[i] = i+1;
	}
	cin>>m;
	for(i=0;i<m;i++){
		cin>>cut;
		card = shuffle(card, cut);
	}
	for(i=0;i<card.size();i++){
		cout<<card[i]<<endl;
	}
	return 0;
}

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

#define           sf        scanf
#define           pf        printf
#define           mx        200005
#define           read      freopen("in.txt", "r", stdin)
#define           optimize  ios::sync_base_stdio(0);cin.tie(0);

using namespace std;

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if(a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;


    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int x = saori.saori_hayami();
		long num = 0;
		long ans = 1;
		for(int i = 1;i < x;i++){
			for(int j = 2;j < x;j++){
				num = (int)Math.pow(i,j);
				if(num <= x){
					ans = Math.max(ans, num);
				}
			}
		}
		System.out.println(ans);
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

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


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

  int n, x, y;
  cin >> n >> x >> y;
  x--; y--;
  vl d(n);
  rep(i,n){
    d[i] = min(abs(x-i), abs(y-i));
  }
  map<ll, ll> mp;
  rep(i,n-1){
    for(ll j = i+1; j < n; j++){
      int dist = min(j-i, d[i]+d[j]+1);
      mp[dist]++;
    }
  }
  REP(i,n){
    cout << mp[i] << endl;
  }
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;

vector<ll>A(X), B(Y), C(Z);

REP(i, X) cin >> A.at(i);
REP(i, Y) cin >> B.at(i);
REP(i, Z) cin >> C.at(i);

vector<ll>AB_sum;
REP(i, X)REP(j, Y) AB_sum.push_back(A.at(i) + B.at(j));
 
sort(all(AB_sum));
reverse(all(AB_sum));

vector<ll>ans;
REP(i, min(K, (int)AB_sum.size()))REP(j, Z) ans.push_back(AB_sum.at(i) + C.at(j));

sort(all(ans));
reverse(all(ans));

REP(i, K) print(ans.at(i));

 }

Measured memory_bytes: 43368
from math import sqrt

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

result = 0
for i in range(n):
    for j in range(n):
        if i != j:
            result += sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)

print(result/n)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll N=1000000007;
ll power(ll a,ll b,ll mod)
{
    ll result=1;
    while(b>0)
    {
        if(b%2==1)
            result=(result*a)%mod;
        a=(a*a)%mod;
        b=b/2;
    }
    return result;
}
ll d,x,y;
void extendedEuclid(ll a,ll b)
{
    if(b==0)
    {
        d=a; x=1; y=0;
    }
    else
    {
        extendedEuclid(b,a%b);
        ll temp=x; x=y; y=temp-(a/b)*y;
    }
}
ll modInverse(ll a,ll m)
{
    extendedEuclid(a,m);
    return (x%m+m)%m;
}
ll lcm(ll a,ll b)
{
    if(a==0||b==0)
        return 0;
    else
        return (a*b)/(__gcd(a,b));
}
void sieve(ll n)
{
    bool isPrime[n+1];
    isPrime[0]=false; isPrime[1]=false;
    for(ll i=2;i<=n;i++)
        isPrime[i]=true;
    for(ll i=2;i*i<=n;i++)
    {
        if(isPrime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
                isPrime[i]=false;
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i,j;
    cin>>n;
    j=n%10;
    if(j==2||j==4||j==5||j==7||j==9)
        cout<<"hon";
    else if(j==0||j==1||j==6||j==8)
        cout<<"pon";
    else
        cout<<"bon";
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Integer aInteger = 0;
		Integer bInteger = 0;
		Integer sum;
		Integer min = Integer.MAX_VALUE;
		Integer digitsSum  = new Integer(scanner.next());

		for(int i = 1; i < digitsSum;i++) {
			sum = 0;
			aInteger = i;
			bInteger = digitsSum - aInteger;
			while(aInteger != 0) {
				sum += aInteger % 10;
				aInteger /= 10;
			}
			while(bInteger != 0) {
				sum += bInteger % 10;
				bInteger /= 10;
			}
			if (min>sum) {
				min = sum;
			}
		}
		System.out.println(min);
		scanner.close();
	}
}

Measured memory_bytes: 32920
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(sx, sy);
  GI2(tx, ty);
  cout << "U";
  FOR(i, ty - sy - 1) cout << "U";
  FOR(i, tx - sx - 1) cout << "R";
  cout << "RD";
  FOR(i, ty - sy - 1) cout << "D";
  FOR(i, tx - sx - 1) cout << "L";
  cout << "LL";
  FOR(i, ty - sy + 1) cout << "U";
  FOR(i, tx - sx + 1) cout << "R";
  cout << "DR";
  FOR(i, ty - sy + 1) cout << "D";
  FOR(i, tx - sx + 1) cout << "L";
  cout << "U" << endl;
  return 0;
}

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


int main(){
	int n ;
	multiset<int> se;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;++i){
		cin >> v[i];
	}
	
	for(int i=0;i<n;++i){
		multiset<int>::iterator it = se.lower_bound(v[i]);
		if(it== se.begin()){
			se.insert(v[i]);
		}else{
			--it;
			se.erase(it);
			se.insert(v[i]);
		}		
	}
	cout << se.size() <<endl;
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 5376
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

n = int(input())
a = list(map(int, input().split()))

a.sort()
#b = [a[i+1]-a[i] for i in range(n-1)]
c = a[0]
for i in range(1, n):
    c = gcd(c, a[i])

print(c)

Measured memory_bytes: 14252
[n, k], [*a] = [[*map(int, t.split())] for t in open(0)]
count = 0
visited = dict()
tmp = 1
while count < k:
    visited[tmp] = count
    count += 1
    tmp = a[tmp - 1]
    if tmp in visited:
        break
if count < k:
    k = (k - count) % (count - visited[tmp])
    for _ in range(k):
        tmp = a[tmp - 1]
print(tmp)

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    int i=0; int j=0;
    int l=0;
    while(i<n && j<n){
        if(l%2==0){
            cout<<a[i];
            i++;
        }
        else{
            cout<<b[j];
            j++;
        }
        l++;
    }
    cout<<b[n-1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  int ans = 1000;

  vi a(n);
  rep(i, n) cin >> a[i];

  rep(i, n-1) {
    if (a[i] >= a[i+1]) continue;

    int tmp = ans / a[i];
    ans = tmp * a[i+1] + (ans % a[i]);
  }

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


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

using ll=long long;

ll begin_end[10][10]={};
void solve(ll N){
  for(int i=1;i<=N;i++){
    int end=i%10;
    if(end==0)continue;
    int j=i;
    while(j>=10)j/=10;
    int begin=j;
    begin_end[begin][end]++;
  }
  ll count=0;
  for(int b=1;b<=9;b++){
    for(int e=1;e<=9;e++){
      count+=begin_end[b][e]*begin_end[e][b];
    }
  }
  cout<<count<<endl;
}

int main(){
  ll N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import deque

# N: ノードの数
# Q: 数値をノードに付与する回数
N, Q = list(map(int, input().split()))

links =  [[] for _ in range(N)]
values = [0 for _ in range(N)]

for i in range(N - 1):
    edge1, edge2 = [x - 1 for x in list(map(int, input().split()))]
    links[edge1].append(edge2)
    links[edge2].append(edge1)

for i in range(Q):
    node, val = list(map(int, input().split()))
    values[node - 1] += val

# 値の計算
stack = deque()
stack.append((0, -1))
while stack:
    node = stack.pop()

    for linked_node in links[node[0]]:
        if linked_node == node[1]:  # link が親ノード向けでなければ
            continue

        values[linked_node] += values[node[0]]
        stack.append((linked_node, node[0]))

print(*values)

Measured memory_bytes: 74768
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll n, a, b, c;
vl L;
vl v;  // v[i] : i番目の竹を使わないとき0、長さaの竹の素材にするとき1、長さbの竹の素材にするとき2、長さcの竹の素材にするとき3
ll ans = INF;

void check() {
    ll now = 0;
    ll lenA = 0, lenB = 0, lenC = 0;
    ll cntA = 0, cntB = 0, cntC = 0;
    rep(i, n) {
        if(v[i] == 1) {
            cntA++;
            if(cntA >= 2) {
                now += 10;
            }
            lenA += L[i];
        }
        else if(v[i] == 2) {
            cntB++;
            if(cntB >= 2) {
                now += 10;        
            }
            lenB += L[i];
        }
        else if(v[i] == 3) {
            cntC++;
            if(cntC >= 2) {
                now += 10;
            }
            lenC += L[i];
        }
    }
    if(cntA == 0 || cntB == 0 || cntC == 0) {
        return;
    }
    now += abs(lenA - a) + abs(lenB - b) + abs(lenC - c);
    chmin(ans, now);
}

void dfs(ll depth) {
    if(depth == n) {
        check();
        return;
    }
    rep(i, 4) {
        v[depth] = i;  
        dfs(depth+1);
    }
}

int main() {
    
    cin >> n >> a >> b >> c;

    L.resize(n);
    rep(i, n) {
        cin >> L[i];
    }

    v.resize(n);
    dfs(0);
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = [int(x) for x in input().split()]
    AB = [[int(x) for x in input().split()] for _ in range(M)]

    A = [[] for j in range(N + 1)]
    ans = [0] * (N + 1)

    u = UnionFind(N)

    for a, b in AB:
        A[a].append(b)
        A[b].append(a)
        u.union(a - 1, b - 1)

    if u.group_count() > 1:
        print("No")
        return

    q = collections.deque()
    v = set()

    q.append(1)
    v.add(1)
    while q:
        c = q.popleft()

        for n in A[c]:
            if n not in v:
                v.add(n)
                q.append(n)
                ans[n] = c

    print("Yes")
    for i in range(2, N + 1):
        print(ans[i])


if __name__ == '__main__':
    main()


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

using pint = pair<int,int>;//「人」と「0 or 1」正しいかどうか

int N;
vector<vector<pint>> v; // pairが入った配列を用意

//整数bitに対応する「決め打ち」（この人が正直者だ！）が整合しているか判定
bool judge(int bit){
  //i人目の証言を検証する
  for(int i =0; i<N; i++){
    if( !(bit & (1<< i))){
      continue; //i人目のフラグが立っていない==「不親切」だったら、証言は全て無意味
    }
    //それぞれ確認
    for(pint xy : v[i]){
      int x = xy.first;//x番目の人が
      int y = xy.second;//y=1:正直 y=0:不親切
      
      if(y == 1 && !(bit & (1<<x) )){
        return false;
      }
      if(y == 0 && (bit & (1 << x)) ){
        return false;
      }
    }
  }
  return true;
}


int main(){
  //入力　N人,A個の証言(xiの人がy=1or0である)
  cin >> N;
  v.resize(N);
  for(int i=0; i<N; i++){
    int A; cin>>A;
    v[i].resize(A);
    for(int j =0; j < A; j++){
      cin >> v[i][j].first >> v[i][j].second;//vはpairの配列
      v[i][j].first--;//0スタートに
    }
  }
  
  int res = 0;
  for(int bit =0; bit < (1<<N); bit++){ //bit回目の試行　N桁目のフラグが立つまで
    
    //矛盾check 
    if(judge(bit)){
      int count = 0;//矛盾してないのならば、bitに含まれる数=立っているフラグ数を数える
      for(int i = 0; i < N ; i++){
        if(bit & (1 << i)) count++;//i桁のフラグが立っているときカウント++
      }
      res = max(res, count );//カウント数と他のjudgeを通り抜けたカウント数を比較し、大きいほうを保存
    }
  }
  cout << res << endl;//最大値を出力
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    // 標準入力からデータを読み込む準備
    Scanner sc = new Scanner(System.in);
    // 最初の文字の固まりを整数値と想定して読み込む
    for (int i = 1; ; i++) {
        int x = sc.nextInt();
        if(x == 0) {
            break;
        }
    else{
        System.out.println("Case "+ i + ": "+ x);
        }
    }
}
}



Measured memory_bytes: 41464
import sys
# from collections import defaultdict, deque
# import math
# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

def nt(n):
    if n == "1":
        return "0"
    else:
        return "1"

def check(seed, n, s):
    ans = seed
    for i in range(1, n):
        a, b = ans[-1], ans[-2]
        if int(s[i]) ^ int(b) == 0:
            ans.append(a)
        else:
            ans.append(nt(a))

    if ans[-1] != ans[0]:
        return []
    else:
        del(ans[-1])
        # print(ans)
        if int(s[0]) ^ int(ans[0]) == 0:
            if ans[-1] != ans[1]:
                return []
        else:
            if ans[-1] == ans[1]:
                return []

    return "".join(ans).replace("1", "S").replace("0", "W")

def solve():
    n = getN()
    S = getS()
    S = S.replace("o", "1").replace("x", "0")
    for seed in  [["1","1"], ["1","0"], ["0","1"], ["0","0"]]:
        ans = check(seed, n, S)
        if ans:
            print(ans)
            return

    print(-1)
    return

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()


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


int main() {
    string S; cin >> S;
    int first_two = (S[0] - '0') * 10 + S[1] - '0';
    int second_two = (S[2] - '0') * 10 + S[3] - '0';
    if ((first_two == 0 && second_two == 0) || (first_two == 0 && second_two > 12) || (first_two > 12 && second_two == 0) || (first_two > 12 && second_two > 12)) {
        cout << "NA" << endl;
    } else if ((first_two == 0 && second_two > 0 && second_two < 13) || (first_two > 12 && second_two > 0 && second_two < 13)) {
        cout << "YYMM" << endl;
    } else if ((second_two == 0 && first_two > 0 && first_two < 13) || (second_two > 12 && first_two > 0 && first_two < 13)) {
        cout << "MMYY" << endl;
    } else {
        cout << "AMBIGUOUS" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  if (n/100 < (n/10) % 10)
    printf("%d\n",(n/100+1)*111);
  else if (n/100 > (n/10) % 10)
    printf("%d\n", (n/100)*111);
  else if (n/100 == (n/10) % 10) {
    if ((n/10) % 10 >= n % 10)
      printf("%d\n",(n/100)*111);
    else
      printf("%d\n", ((n/100)+1)*111);
    }
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)


int main(){
    string x,y;
    cin>>x>>y;


    if(x>y){
        cout<<">"<<endl;
    } else if(y>x){
        cout<<"<"<<endl;
    }else{
        cout<<"="<<endl;
    }

    return 0;

}


Measured memory_bytes: 256