akhauriyash/Code-Regression huggingface dataset:
#include <random>
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr ll mod = 998244353;
mt19937_64 rnd{random_device()()};

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  ll ans = 0;
  for (int p = 0; p < w - 1; p++) {
    vector<vector<int>> cost(h + 1, vector<int>(h + 1, inf));
    for(int i=0;i<=h;i++){
        cost[i][h] = cost[h][i] = 0;
    }
    /*
    for (int i = 0; i <= h; i++) {
      int cnt = 0;
      for (int j = 0; j <= h - i - 1; j++) {
        if (s[j][p] == s[i + j][p + 1]) cnt++;
      }
      cost[i][h] = cnt;

      cnt = 0;
      for (int j = 0; j <= h - i - 1; j++) {
        if (s[i + j][p] == s[j][p + 1]) cnt++;
      }
      cost[h][i] = cnt;
    }*/
    for (int i = h - 1; i >= 0; i--) {
      for (int j = h - 1; j >= 0; j--) {
        cost[i][j] =
            cost[i + 1][j + 1] + (s[h - i - 1][p] == s[h - j - 1][p + 1]);
      }
    }
    // cout << p << endl;
    // for (int i = 0; i <= h; i++) printv(cost[i]);
    vector<vector<int>> dp(h + 1, vector<int>(h + 1, inf));
    dp[0][0] = 0;
    for (int x = 0; x <= h; x++) {
      for (int y = 0; y <= h; y++) {
        if (x) {
          dp[x][y] = min(dp[x][y], dp[x - 1][y] + cost[x - 1][y]);
        }
        if (y) {
          dp[x][y] = min(dp[x][y], dp[x][y - 1] + cost[x][y - 1]);
        }
      }
    }
    ans += dp[h][h];
  }
  cout << ans << endl;
}


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

#include <iostream>
#include <vector>
// #include <map>
// #include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

int main() {
	int n, m, l;
	vector<vector<int>> a, b;
	vector<vector<long>> c;
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		vector<int> v_tmp;
		for (int j = 0; j < m; j++) {
			int tmp;
			cin >> tmp;
			v_tmp.push_back(tmp);
		}
		a.push_back(v_tmp);
	}
	for (int i = 0; i < m; i++) {
		vector<int> v_tmp;
		for (int j = 0; j < l; j++) {
			int tmp;
			cin >> tmp;
			v_tmp.push_back(tmp);
		}
		b.push_back(v_tmp);
	}

	for (int i = 0; i < n; i++) {
		vector<long> v_tmp;
		for (int j = 0; j < l; j++) {
			long sum = 0;
			for (int k = 0; k < m; k++) {
				sum += a[i][k] * b[k][j];
			}
			v_tmp.push_back(sum);
		}
		c.push_back(v_tmp);
	}

	for (auto itr = c.begin(); itr != c.end(); ++itr) {
		for (auto itr2 = (*itr).begin(); itr2 != (*itr).end(); ++itr2) {
			if (itr2 != (*itr).begin()) {
				cout << " ";
			}
			cout << *itr2;
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3260
# https://atcoder.jp/contests/abc114/submissions/6262572

from itertools import product
N = input()
n = int(N)
ans = 0
for i in range(3, len(N)+1):
    for s in product(["3","5","7"],repeat=i):
        if int("".join(s)) <= n and "3" in s and "5" in s and "7" in s:
            ans += 1
print(ans)


Measured memory_bytes: 3060
import Control.Applicative
import Data.Array
import Data.Maybe

main = do
    [n,w] <- map read . words <$> getLine
    vws <- map (map read . words) . lines <$> getContents
    print $ solve w vws

solve :: Int -> [[Int]] -> Int
solve mw vws = maximum . elems $ foldl f initial vws
    where
        initial = listArray (0,mw) $ repeat 0
        f xs [v,w] = array (0,mw) [(i,val) | 
            i <- [0..mw],
            let val = if i < w 
                        then xs ! i
                        else let v1 = xs ! i
                                 v2 = v + xs ! (i-w)
                              in max v1 v2
            ]

Measured memory_bytes: 108488
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

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

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

  string s;
  cin >> s;

  int a = 10 * (s[0] - '0') + (s[1] - '0');
  int b = 10 * (s[2] - '0') + (s[3] - '0');

  bool yymm = false, mmyy = false;
  if(b >= 1 && b <= 12) yymm = true;
  if(a >= 1 && a <= 12) mmyy = true;

  if(yymm & mmyy) cout << "AMBIGUOUS" << endl;
  else if(yymm) cout << "YYMM" << endl;
  else if(mmyy) cout << "MMYY" << endl;
  else cout << "NA" << endl;

  return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct mint {
    const int mod = 1000000007;
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint& operator=(const mint a) { x = a.x; return *this; }
    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(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    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; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    ll p = (n + 999) / 1000;
    mint a;
    a = p * 1000 - n;
    cout << a.x << endl;
    return 0;
}


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

struct Edge
{
    int to, cost;
};

vector<bool> visited;
vector<vector<Edge> > g;
vector<int> dist;

// 'N'を頂点数として...
void DFS_for_TreeDiameter(int now, int from, vector<vector<Edge> > &G, int &maxDist, int &maxDistPos){
    visited[now] = true;
    if (dist[now] > maxDist){
        maxDist = dist[now];
        maxDistPos = now;
    }
    for (int i = 0; i < G[now].size(); i++){
        int To = G[now][i].to;
        if (To == from){
            continue;
        }
        dist[To] = dist[now] + G[now][i].cost;
        DFS_for_TreeDiameter(To, now, G, maxDist, maxDistPos);
    }
}


struct treeDiameterInfo
{
    int start, end, maxDist;
};

//始点、終点、最大距離を返す
treeDiameterInfo Implement(int N, vector<vector<Edge> > &G){
    int st = 0, fin = 0, maxDistPos = 0, maxDist = 0;
    visited.assign(N, false);
    dist.assign(N, 0);
    //始点情報を入手
    DFS_for_TreeDiameter(st, -1, G, maxDist, maxDistPos);
    //
    st = maxDistPos;
    //cout << "maxDistPos : " << maxDistPos << endl;
    maxDist = 0;
    maxDistPos = 0;
    visited.assign(N, false);
    dist.assign(N, 0);
    //終点情報を入手
    DFS_for_TreeDiameter(st, -1, G, maxDist, maxDistPos);
    
    treeDiameterInfo res;
    res.start = st, res.end = maxDistPos, res.maxDist = maxDist;
    return res;
}

int main(){
    int N; cin >> N;
    g.resize(N);
    dist.assign(N, 0);
    visited.assign(N, false);
    for (int i = 0; i < N-1; i++){
        int s, t, w; cin >> s >> t >> w;
        Edge e; e.to = t; e.cost = w;
        g[s].push_back(e);
        //無向グラフ
        e.to = s;
        g[t].push_back(e);
    }
    treeDiameterInfo result = Implement(N, g);
    cout << result.maxDist << endl;
}








Measured memory_bytes: 16524
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
ll h,w,n;
ll c[150][150];
vector<ll>a;
ll now=0,cnt=0;
void search(ll x,ll y){
 c[x][y]=now+1;
 cnt++;
 if(cnt==a[now]){
  now++;
  cnt=0;
 }
 
 if(x%2==0){
  if(y==w-1){
   if(x+1==h)return;
   search(x+1,y);
  }
  else search(x,y+1);
 }
 else {
  if(y==0){
   if(x+1==h)return;
   search(x+1,y);
  }
  else search(x,y-1);
 }
}

int main(){
 cin>>h>>w>>n;
 ll b;
 rep(i,0,n){
  cin>>b;
  push(a,b);
 }
 search(0,0);
 rep(i,0,h){
  rep(j,0,w){
   cout<<c[i][j]<<" ";
  }
  pnn;
 }
 return 0;}

Measured memory_bytes: 3832
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
const int mod = 1e9+7;
ll mod_pow(ll a, ll b){
    if(!a)return a;
    ll res = 1;
    while(b){
        if(b&1)res = res * a % mod;
        a = a * a % mod;
        b>>=1;
    }
    return res;
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> dp(k + 1);
    ll ans = 0;
    for(int i = k; i >= 1; i--){
        //dp[i] = (k/i)^n - dp[i*2]
        dp[i] = mod_pow(k / i, n);
        for(int j = 2 * i; j <= k; j+=i){
            dp[i] -= dp[j];
            if(dp[i] < 0)dp[i] += mod;
        }
        ans += dp[i] * i;
        ans %= mod;
    }
    cout << ans << endl;
    
}


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

constexpr char white = '.';

struct Cell {
    int x, y;
    int cost;
    bool is_white;
    bool in_queue;
    bool closed;
};

static Cell *take_lowest_one(vector<Cell *> &q) {
    auto cost = q.front()->cost;
    auto index = 0;
    for (int i = 1; i < q.size(); ++i) {
        if (q[i]->cost < cost) {
            cost = q[i]->cost;
            index = i;
        }
    }
    auto res = q[index];
    if (index != q.size() - 1)
        q[index] = q.back();
    q.pop_back();
    return res;
}

int main() {
    int h, w;
    cin >> h >> w;
    constexpr int huge = 1'000'000'000;
    auto grid = vector<vector<Cell>>(h, vector<Cell>(w));
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            char c;
            cin >> c;
            grid[y][x].x = x;
            grid[y][x].y = y;
            grid[y][x].cost = huge;
            grid[y][x].is_white = (c == white);
            grid[y][x].in_queue = false;
            grid[y][x].closed = false;
        }
    }

    auto x_start = 0, y_start = 0;
    auto x_goal = w - 1, y_goal = h - 1;

    grid[y_start][x_start].cost = (grid[y_start][x_start].is_white ? 0 : 1);
    if (grid[y_start][x_start].is_white == false) {
        for (auto &row : grid)
            for (auto &cell : row)
                cell.is_white = !cell.is_white;
    }

    auto openset = vector<Cell *>();
    openset.reserve(w * h);
    openset.push_back(&grid[y_start][x_start]);

    auto flipped = 0;
    while (!openset.empty()) {
        auto *p = take_lowest_one(openset);
        p->closed = true;
        if (p->x == x_goal && p->y == y_goal) {
            flipped = p->cost;
            break;
        }

        const int x_move[2] = {1, 0};
        const int y_move[2] = {0, 1};
        for (int i = 0; i < 2; i++) {
            int x = p->x + x_move[i];
            int y = p->y + y_move[i];
            if (x >= w || y >= h)
                continue;
            auto *q = &grid[y][x];
            if (q->closed)
                continue;
            int cost = p->cost + (q->is_white == p->is_white ? 0 : 1);
            if (q->in_queue) {
                q->cost = min(q->cost, cost);
            } else {
                q->cost = cost;
                openset.push_back(q);
                q->in_queue = true;
            }
        }
    }

    cout << (flipped + 1) / 2;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int ans=MAX;
  REP(i,1,n) {
    int x=i,y=n-i;
    int sum=0;
    while(x) {
      sum+=x%10;
      x/=10;
    }
    while(y) {
      sum+=y%10;
      y/=10;
    }
    ans=min(ans,sum);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

long long a, b;
int main() {
	cin >> a >> b;
	if (a + b >= 10)cout << "error" << endl;
	else cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int valid(int mask){
    int res = 0;
    for(int i=0;i<15;i++) if(mask&(1<<i)) res ^= i+1;
    return res == 0;
}

int main(){
    int N; cin >> N;
    vector<int> v(N, 0);
    for(int i=0;i<N-1;i++){
        int a, b, c; cin >> a >> b >> c;
        v[a] ^= c;
        v[b] ^= c;
    }
    int res = 0;
    vector<int> cnt(15, 0);
    for(auto& t : v){
        if(t == 0) continue;
        cnt[t-1]++;
    }
    for(auto& t : cnt){
        res += t/2;
        t %= 2;
    }
    vector<int> dp(1<<15, 0);
    for(int i=1;i<(1<<15);i++){
        if(!valid(i)) continue;
        for(int j=i;j;j=i&(j-1)){
            if(j != i && valid(j)){
                dp[i] = max(dp[i], dp[j] + dp[i^j] + 1);
            }
        }
    }
    int c = 0;
    int m = 0;
    for(int i=0;i<15;i++){
        if(!cnt[i]) continue;
        m |= (1<<i);
        c++;
    }
    if(m) res += c - 1 - dp[m];
    cout << res << endl;
}

Measured memory_bytes: 768
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{  ll n;
 cin>>n;
 double a[n],p=0;
 for(ll i=0;i<n;i++)
 { cin>>a[i];
   p+=1/a[i];
 }
 printf("%.8lf\n",1/p);
}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int aa[7];

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--; c--;
    aa[a]++;
    aa[b]++;
    aa[c]++;
    if(aa[4]==2&&aa[6]==1)cout <<"YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int a = s.find("A");
    reverse(s.begin(), s.end());
    int b = s.find("Z");

    cout << s.length()-b - a << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
 
 
int main(){
  string S;
  cin>>S;
  deque<char>ans;
  int x=S.size();
  for(int i=0;i<x;i++){
  ans.push_back(S[i]);
  }
  
  int Q;
  cin >>Q;
  
  int t,f,flag;
  char ch;
  
  for(int i=0;i<Q;i++){
  	cin >>t;
    
    if(t==1){
    	flag=1-flag;
    }
    
    if(t==2){
    	cin >> f>>ch;
      
      if(flag==0){
        
      	 if(f==1){
          	ans.push_front(ch);
         }
         if(f==2){
        	ans.push_back(ch); 
         }      
      }
      if(flag==1){
      	 if(f==2){
          	ans.push_front(ch);
         }
         if(f==1){
        	ans.push_back(ch); 
         }      
      }
    
    } 
  }
  
  //以下で表記
	if(flag==0){
  while(!ans.empty()){
  	cout<<ans.front();
  	ans.pop_front();
  }
    }
	if(flag==1){
  while(!ans.empty()){
  	cout<<ans.back();
  	ans.pop_back();
  }
    }
  cout<<endl;
  
  
}


Measured memory_bytes: 896
from queue import Queue

N = int(input())
ab = [tuple(map(int, input().split())) for _ in range(N - 1)]

color = [0] * (N-1)
used_color =  [set() for _ in range(N)]

adj = [set() for _ in range(N)]
for i, (a, b) in enumerate(ab):
    adj[a - 1].add((i, b - 1))
    adj[b - 1].add((i, a - 1))

root = max(range(N), key=lambda x: len(adj[x]))

q = [root]

while q:
    node1 = q.pop()
    c=1
    for i, node2 in adj[node1]:
        while c  in used_color[node1]:
            c += 1
        color[i]=c
        used_color[node1].add(c)
        used_color[node2].add(c)
        adj[node2].remove((i, node1))
        q.append(node2)

print(len(used_color[root]))
for c in color:
    print(c)


Measured memory_bytes: 90256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0 ; i < n; i++)
int ans = 1000000000;
int n, m, x;
vector<int> c(12);
vector<vector<int>> a(12, vector<int>(12));

void bfs(int num, int flag, int min_val, int sum_val, vector<int> sum) {
    //cout << min_val << endl;
    //cout << "num: " << num << " flag: " << flag << endl;
    if(min_val >= x) {
        //cout << sum_val << " " << endl;
        ans = min(ans, sum_val);
        return;
    }
    if(num >= n) return; 
    if(flag == 1) {
        sum_val += c[num];
        rep(i, m) {
            sum[i] += a[num][i];
            //cout << sum[i] << " ";
        }
        min_val = sum[0];
        rep(i, m) {
            min_val = min(min_val, sum[i]);
        }
        //cout << endl;
        //cout << min_val << endl;
    }
    bfs(num+1, 0, min_val, sum_val, sum);
    bfs(num+1, 1, min_val, sum_val, sum);
    return;
}

int main() {
    cin >> n >> m >> x;
    int mn = x-1;
    rep(i, n) {
        cin >> c[i];
        rep(j, m) {
            cin >> a[i][j];
            //mn = min(a[i][j], mn);
        }
    }
    vector<int> sum(m, 0);
    bfs(0, 0, mn, 0, sum);
    bfs(0, 1, mn, 0, sum);
    if(ans == 1000000000) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

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

int main() {
  ll N,P;
  cin >> N >> P;
  double d = 1/double(N);
  if (N == 1) {
    cout << P << endl;
    return 0;
  }
  
  ll M = ceil(powl(P,d));
  ll g = 1;
  for (ll i = 2; i <= M; i++) {
    if (P % ll(powl(i,N)) == 0) g = i;
  }
  cout << g << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;

const int N = 100111;
const int inf = 1e10;
int n;
int l,r;
int a[N];
int b[N];
signed main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    int x = a[1];
    for (int i=2;i<=n;i++){
        if (i % 2 == 0){
            x = x - a[i];
        }
        else {
            x = x + a[i];
        }
    }
    b[1] = x;
    for (int i=1;i<=n;i++){
        b[i+1] = (a[i] - b[i]/2) * 2;
    }
    for (int i=1;i<=n;i++){
        cout << b[i] << " ";
    }


    return 0;
}


Measured memory_bytes: 2944
// IN THE NAME OF RIGHT
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main(){
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
	cout<<"Yes"<<endl;
	}else{
	cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  vector<vector<int> > a(3, vector<int>(3)); REP(i, 3) REP(j, 3) cin >> a[i][j];
  int n; cin >> n;
  vector<vector<bool> > hit(3, vector<bool>(3, false));
  while (n--) {
    int b; cin >> b;
    REP(i, 3) REP(j, 3) {
      if (a[i][j] == b) hit[i][j] = true;
    }
  }
  REP(i, 3) {
    bool ok = true;
    REP(j, 3) ok &= hit[i][j];
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  REP(j, 3) {
    bool ok = true;
    REP(i, 3) ok &= hit[i][j];
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  {
    bool ok = true;
    REP(i, 3) ok &= hit[i][i];
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  {
    bool ok = true;
    REP(i, 3) ok &= hit[2 - i][i];
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
bool pan[1000010];
int f[1000010];
char a[3];
int n,m,ai,aj,kl;
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d %s",&kl,a);
		if(a[0]=='W')
		if(!pan[kl])
		++f[kl];
		if(a[0]=='A')
		if(!pan[kl])
		pan[kl]=1;
	}
	for(int i=1;i<=n;i++)
	if(pan[i])
	{
		++ai;
		aj+=f[i];
	}
	printf("%d %d",ai,aj);
}

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

int main() {
  string s;
  cin >> s;
  unordered_set<char> u;
  rep(i, s.size()) u.insert(s[i]);
  if(u.size() == 4 || (u.size() == 2 && ((u.count('W') && u.count('E')) || (u.count('N') && u.count('S'))))) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) cin >> a[i], sum += a[i];
  ans = LINF;
  rep(i, n - 1) {
    cnt += a[i];
    sum -= a[i];
    ans = min(ans, abs(cnt - sum));
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll N, K;
	ll A[200200];
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int i = K; i < N; i++){
		if(A[i-K] < A[i]){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    set<int> a;
    set<int> blacklist;
    for(int i = 0; i< n; i++) {
        int p; cin >> p;
        if(a.count(p) == 1) blacklist.insert(p);
        a.insert(p); 
    }

    int ans = 0;
    set<int> b;
    for(int i : a){
        if(blacklist.count(i) == 1){
        } else if(b.size() == 0) {
            ans++;
        } else {
            bool flag = true;
            for(int j = 1; j*j <= i; j++){
                if(i%j == 0){
                    if(b.count(j) == 1 || b.count(i/j) == 1){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag) ans++;
        }
        b.insert(i);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 22364
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A, B, C = [int(x) for x in input().split()]

    cnt = 0
    while True:
        if cnt > 10 ** 5:
            print(-1)
            return

        if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
            print(cnt)
            return

        A, B, C = B // 2 + C // 2, A // 2 + C // 2, A // 2 + B // 2
        cnt += 1
       

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n, m = map(int, input().split())

mat_A = []
vec_b = []

for j in range(n):
    mat_A.append(list(map(int, input().split())))
for i in range(m):
    vec_b.append(int(input()))

for j in range(n):
    tmp = 0
    for i in range(m):
        tmp += mat_A[j][i] * vec_b[i]
    print(tmp)

Measured memory_bytes: 6012
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static void exec(Scanner in, PrintWriter out) {
		in.nextInt();
		int Q = in.nextInt();
		String S = in.next();
		int[] t = new int[S.length()];
		for (int i = 0; i < t.length - 1; i += 1) {
			if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') {
				t[i + 1] = t[i] + 1;
			} else {
				t[i + 1] = t[i];
			}
		}
		for (int i = 0; i < Q; i += 1) {
			int l = in.nextInt();
			int r = in.nextInt();
			out.println(t[r - 1] - t[l - 1]);
		}
	}

	public static void main(String[] args) {
		PrintWriter w = new PrintWriter(System.out);
		exec(new Scanner(System.in), w);
		w.flush();
	}
}


Measured memory_bytes: 66240
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <climits>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

int main()
{
	char c1[3];
	char c2[3];
	cin >> c1 >> c2;
	rep(i, 3){
	if(c1[i] != c2[2-i]){
		cout << "NO" << endl;
	return 0;}
	}

	cout << "YES" <<endl;
}



Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
ary = gets.split.map(&:to_i)
hash = {}
ary.each do |i| 
    hash[i] = hash[i].to_i + 1
end
n = hash.size - K
if n <= 0
    puts 0
else
    cnt = 0
    hash.sort{|a, b| a[1] <=> b[1]}.each do |k, v|
        if n > 0
            cnt += v
            n -= 1
        else
            break
        end
    end
    puts cnt
end

Measured memory_bytes: 40944
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long[] teiin = new long[5];
		long min  = 10000000000000000L;
		for (int i = 0; i < 5; i++) {
			teiin[i] = sc.nextLong();
			if (teiin[i] < min) {
				min = teiin[i];
			}
		}
		System.out.println((n + min - 1) / min + 4);
	}
}

Measured memory_bytes: 23124
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
import itertools
l=[]
ans=[]
for i in range(n):
	l.append(i+1)
for v in itertools.permutations(l,n):
	ans.append(list(v))
for i in range(len(ans)):
	if p==ans[i]:
		pp=i
	if q==ans[i]:
		qq=i
print(abs(pp-qq))


Measured memory_bytes: 10228
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;
// 変数初期化
vector<ll> bsv; // binary_search用のvector
ll a,b,c,n,m;
typedef pair<ll, ll> Pll;
vector<Pll> facts; // 素因数分解の結果格納用(基数:乗数)
vector<vector<ll> > bit_search_v; //nit全探索の結果格納用

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (bsv[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(int key) {
    int ng = -1;
    int ok = (ll)bsv.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    // OK(key以上となる)のindex番号を返す
    return ok;
}

// 最大公約数
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

// 最小公倍数
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

//　素因数分解
void prime_fact(ll target){
    ll base=2, exp=0;
    while (base*base<=target) {
        while (target%base==0) {
            target /= base; exp++;
        }
        if (exp>0) {
            facts.push_back(make_pair(base, exp));
        }
        base++; exp=0;
    }
    if (target>1) facts.push_back(make_pair(target,1));
}
// prime_factの結果の確認用
void print_facts(){
    for (int i=0; i<facts.size(); i++) {
        cout << facts[i].first << " " << facts[i].second << endl;
    }
}

// bit全探索
void bit_search(ll target){
    for (ll i=0; i<(1<<target); ++i) {
        if (i==0) continue;
        vector<ll> v;
        for (ll j=0; j<target; ++j) {
            if (i&(1<<j)) v.push_back(j);
            if (i&(1<<j)) cout << i << "  :  " << j << endl;
        }
        bit_search_v.push_back(v);
    }
}
// bit全探索の結果確認用
void print_bit_search(){
    for (ll i=0; i<bit_search_v.size(); ++i) {
        for (ll j=0; j<bit_search_v[i].size(); ++j) {
            cout << bit_search_v[i][j] << " ";
        }
        cout << endl;
    }
}



int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll s;
    cin >> s;
    ll tmp=100; 
    ll ans = 0;
    while(tmp < s){
        tmp*= 1.01;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3172
#include<iostream>
using namespace std;
int main()
{
	int m1,m2,d1,d2;
	cin>>m1>>d1>>m2>>d2;
	if(m1==m2)
	{
		cout<<0;
	}
	if(m2>m1)
	{
		cout<<1;
	}
}

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

typedef long long ll;

#define MOD 1000000007
#define INF LLONG_MAX
#define decimDigits(n) fixed << setprecision(n)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(it, arr) for(auto it = begin(arr); it != end(arr); it++)

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

int main(){

    ll W, H, N, x, y, a, x_max, x_min, y_max, y_min;

    cin >> W >> H >> N;

    x_max = W;
    x_min = 0;
    y_max = H;
    y_min = 0;

    rep(i, N){
        cin >> x >> y >> a;
        if(a == 1)
            x_min = max(x_min, x);
        else if(a == 2)
            x_max = min(x_max, x);
        else if(a == 3)
            y_min = max(y_min, y);
        else
            y_max = min(y_max, y);
    }

    cout << (x_max - x_min > 0 && y_max - y_min > 0 ? (x_max - x_min) * (y_max - y_min) : 0) << endl;

    return 0;
}

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

int main()
{
    int a,b; cin >> a >> b;
    cout << (a+b+1)/2 << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,s,d;
	scanf("%d",&a);
	while(a!=0){
	s=0;
		while(a!=1){
			if(a%2==0){
				a=a/2;
				s++;
			}
			else{
				a=a*3+1;
				s++;
			}
		}
		printf("%d\n",s);
	scanf("%d",&a);
	}
	return 0;
}

Measured memory_bytes: 1032
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
const int Maxn=300000;
int h,w,n;
struct Node{
	int x,y;
}a[Maxn+5];
set<pair<int,int> > st;
int s_x[Maxn+5],s_y[Maxn+5];
int lis_x[Maxn+5],len_x;
int lis_y[Maxn+5],len_y;
int main(){
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
		s_x[a[i].x]++;
		s_y[a[i].y]++;
		st.insert(make_pair(a[i].x,a[i].y));
	}
	int max_x=-1,num_x;
	int max_y=-1,num_y;
	for(int i=1;i<=h;i++){
		if(s_x[i]>max_x){
			max_x=s_x[i];
			num_x=0;
		}
		if(s_x[i]==max_x){
			num_x++;
		}
	}
	for(int i=1;i<=w;i++){
		if(s_y[i]>max_y){
			max_y=s_y[i];
			num_y=0;
		}
		if(s_y[i]==max_y){
			num_y++;
		}
	}
	if(1ll*num_x*num_y>n){
		printf("%d\n",max_x+max_y);
		return 0;
	}
	for(int i=1;i<=h;i++){
		if(s_x[i]==max_x){
			lis_x[++len_x]=i;
		}
	}
	for(int i=1;i<=w;i++){
		if(s_y[i]==max_y){
			lis_y[++len_y]=i;
		}
	}
	bool flag=0;
	for(int i=1;i<=len_x;i++){
		for(int j=1;j<=len_y;j++){
			if(st.count(make_pair(lis_x[i],lis_y[j]))==0){
				flag=1;
				break;
			}
		}
		if(flag){
			break;
		}
	}
	if(flag){
		printf("%d\n",max_x+max_y);
	}
	else{
		printf("%d\n",max_x+max_y-1);
	}
	return 0;
}


Measured memory_bytes: 22288
import sys
input = sys.stdin.readline
def main():
  n,m,k=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  cd=[list(map(int,input().split())) for _ in range(k)]
  gf=[[]for _ in range(n)]
  for a,b in ab:
    gf[a-1].append(b-1)
    gf[b-1].append(a-1)
  gb=[[]for _ in range(n)]
  for c,d in cd:
    gb[c-1].append(d-1)
    gb[d-1].append(c-1)
  seen=[0]*n
  ans=[0]*n
  for i in range(n):
    c=set([i])
    if seen[i]==0:
      todo=[i]
      while todo:
        e=todo.pop()
        l=gf[e]
        for li in l:
          if seen[li]==0:
            todo.append(li)
            seen[li]=1
            c.add(li)
      base=len(c)-1
      for ci in c:
        ans[ci]=base
        for fb in gb[ci]+gf[ci]:
          if fb in c:
            ans[ci]-=1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()


Measured memory_bytes: 91572
#include <stdio.h>

int main(void)
{
    int N, i, j;

    int count=0, C[10][10];

    scanf("%d",&N);


    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            C[i][j]=0;
        }

    }

    
    for(i=1;i<=N;i++){
        int x=i;
        while(x>=10) x/=10;
        C[x][i%10]++;//10で割っていった数=1番上の桁の数:10で割った余り=1の位の数
    }


    //C_ij := #{1 ≤ k ≤ N|k の先頭の桁の数は i に等しく、末尾の桁の数は j に等しい }
    for(i=0; i<=9; i++){
        for(j=0; j<=9; j++){
            count += C[i][j] * C[j][i];
        }
    }

    printf("%d\n",count);

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int w[] = new int[10];
		int k[] = new int[10];
		for(int i=0;i<10;i++) w[i] = sc.nextInt();
		for(int i=0;i<10;i++) k[i] = sc.nextInt();
		sort(w); sort(k);
		System.out.println( (w[7] + w[8] + w[9]) + " " + (k[7] + k[8] + k[9]) );
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
import numpy as np
import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

limit = np.array(
  [a, b, c, d, e], dtype=np.int64)
min_limit = limit.min()

wait = math.ceil(n/min_limit)

print(4+wait)

Measured memory_bytes: 12424
#include<stdio.h>
int main(void)
{
	int N,max=0;
	scanf("%d", &N);
	int i = 1;
	while (true) {
		if (i* i <= N && (i + 1) * (i + 1) > N) {
				printf("%d", i*i);
				return 0;
			}
		i++;
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
char s[3001],t[3001];
int f[3001][3001]={0};
void fun(int i,int j)
{
	//printf("%d %d\n",i,j);
	if(i<0||j<0)
		return;
	if(s[i]!=t[j])
	{
		if(f[i+1][j]>f[i][j+1])
			fun(i,j-1);
		else
			fun(i-1,j);
	}
	else
		fun(i-1,j-1);
	if(s[i]==t[j])
		printf("%c",s[i]);
}
int main()
{
	int n,m,i,j;
	scanf("%s\n%s",s,t);
	n=strlen(s);
	m=strlen(t);
//	for(i=1;i<=m;i++)
//		printf("%d ",f[0][i]);
//	printf("\n");
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(s[i-1]==t[j-1])
				f[i][j]=f[i-1][j-1]+1;
			else
				f[i][j]=max(f[i-1][j],f[i][j-1]);
			//printf("%d ",f[i][j]);
		}
		//printf("\n");		
	}
	fun(n-1,m-1);
	return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807

bool prime_check(int A)
{
  if( A < 2) return 0;
  for (int i = 2; i <= sqrt(A); i++)
  {
    if(A%i == 0)return 0;
  }
  return 1;
}
void solve()
{
  int N;
  cin>>N;
  vector<int> vec(N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }

  vector<int> max_vec(N,-1);

  int max_v;
  max_v = -1 * I32_MAX -1;
  int min_v = I32_MAX;
  for (int i = 0; i < N; i++)
  {
    max_v = max(max_v, vec[i] - min_v);
    min_v = min(min_v,vec[i]);
  }

  cout<<max_v<<endl;
  
  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 4324
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct in {
    int n; in() {} in(int n_) : n(n_){}
    template <class T> operator T() { T ret; cin >> ret; return ret; }
    template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jan 18 21:00:11 JST 2020
 **/

signed main() {
    int a = in(), b = in(), c = in();
    int x = max(a, b);
    cout << (c + x - 1) / x << endl;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
        if(B - A >= K) {
            System.out.print("OK");
            return;
        }

        for(int i = A; i < B + 1; i++) {
            if(i % K == 0) {
                System.out.print("OK");
                return;
            }
        }
        System.out.print("NG");
    }
}


Measured memory_bytes: 35768
#include<stdio.h>
int main(void){
  int i,cnt,num1,num2,num3,temp=0;
  scanf("%d",&cnt);
  for(i=0; i<cnt; i++){
    scanf("%d %d %d",&num1,&num2,&num3);
    if(((num1*num1)==((num2*num2)+(num3*num3))) || ((num2*num2)==((num1*num1)+(num3*num3))) || ((num3*num3)==((num1*num1)+(num2*num2)))){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 580
import java.io.*;
import java.text.*;
import java.util.*;

public class Main {

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        int t = 1;
        while (t > 0) {
            s.solve();
            t--;
        }
        out.close();
    }

    static class InputReader {

        public BufferedReader br;
        public StringTokenizer token;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
            token = null;
        }

        public String sn() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int ni() {
            return Integer.parseInt(sn());
        }

        public String snl() throws IOException {
            return br.readLine();
        }

        public long nlo() {
            return Long.parseLong(sn());
        }

        public double nd() {
            return Double.parseDouble(sn());
        }

        public int[] na(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.ni();
            return a;
        }

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00000000");
        long maxi = Integer.MAX_VALUE;
        long mod = (long) (1e9 + 7);

        void solve() {
            int n = sc.ni();
            int m = sc.ni();
            char c[][] = new char[n][m];
            for (int i = 0; i < n; i++)
                c[i] = sc.sn().toCharArray();
            long dp[][] = new long[n][m];
            dp[0][0] = 1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    int x = i - 1;
                    int y = j - 1;
                    if (valid(x, j, n, m, c))
                        dp[i][j] = (dp[i][j] + dp[x][j]) % mod;
                    if (valid(i, y, n, m, c))
                        dp[i][j] = (dp[i][j] + dp[i][y]) % mod;
                }
            }
            out.println((dp[n - 1][m - 1] + mod) % mod);
        }

        boolean valid(int i, int j, int n, int m, char c[][]) {
            return i >= 0 && j >= 0 && i < n && j < m && c[i][j] != '#';
        }
    }
}


Measured memory_bytes: 39224