akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
//#define endl "\n"

#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[n],b[n];rep(i,0,n-1)cin>>a[i]>>b[i];
    ll sum=0;
    ll ans=0;
    for(ll i=33;i>=0;i--){
        if(((k>>i)&1) == 0){
            continue;
        }
        ll t=sum+(1<<i)-1;
        ll tot=0;
        rep(i,0,n-1){
            if((t&a[i])==a[i]){
                tot+=b[i];
            }
        }
        ans=max(ans,tot);
        sum+=(1<<i);
    }
    ll tot=0;
    rep(i,0,n-1){
        if((k&a[i])==a[i]){
            tot+=b[i];
        }
    }
    ans=max(ans,tot);
    cout<<ans<<endl;
    
    return 0;
}





Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
ll d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int f(ll a){
  for(int i=2;i<=sqrt(a);i++)if(a%i<1)return 0;
  return 1;
}
int main(void){
  ll a,b;
  scanf("%lld %lld",&a,&b);
  ll g=gcd(max(a,b),min(a,b)),ans=0;
  for(ll i=1;i<=sqrt(g);i++){
    if(g%i<1){
      if(f(i))ans++;
      if(i*i-g)if(f(g/i))ans++;
    }
  }
  PRL(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string S, T; cin >> S >> T;
    cout << (S == T.substr(0, S.size()) ? "Yes" : "No") << "\n";
}

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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int g[10][10];

int main(){
	//IO();
	scanf("%d%d",&m,&n);
	for(int i=0;i<n;i++)
		scanf("%d",&x),m-=x;
	if (m>0)
		printf("No\n");
	else
		printf("Yes\n");

}


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

int N;
int a[3000];
int dp[3001][3001];

int rec(int l, int r) {
  if(l>r) return 0;
  if(dp[l][r] != 0xFFFFFFFFFFFFFFFF) return dp[l][r];
  if(l==r) return dp[l][r] = a[l];
  return dp[l][r] = max(a[l] - rec(l+1, r  ), a[r] - rec(l  , r-1));
}

signed main() {
  cin >> N;
  for(int i=0; i<N; i++) cin >> a[i];

  fill((int*)dp, (int*)dp+3001*3001, 0xFFFFFFFFFFFFFFFF);
  int sum = accumulate(a, a+N, 0LL);
  cout << rec(0, N-1) << endl;
}

Measured memory_bytes: 70784
from math import sqrt

x = int(input())

root = int(sqrt(sqrt(x)))

check = 0
for a in range(-1 * root, root * 2):
    for b in range(-1 * root, root * 2):
        if a * a * a * a * a - b * b * b * b * b == x:
            print(f"{a} {b}")
            check = 1
        if check == 1:
            break
    if check == 1:
        break

Measured memory_bytes: 9172
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<int>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,int b){return((a-1)/b+1);} 
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int main()
{
    FIO;
    ll n,t,x,y;
    string s;
    cin>>s;x=0,y=0;
    rep(i,0,3){
        if(s[i]=='S'){y=max(y,x);x=0;}
        else x++;
    }
    y=max(y,x);
    cout<<y;
    return 0;
}

Measured memory_bytes: 3604
import sys


try:
    sys.stdin = open(sys.path[0] + '/input.txt', 'r')
    sys.stdout = open(sys.path[0] + '/output.txt', 'w')
except FileNotFoundError:
    pass


n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = [i - 1 for i in arr]

p = 0
route = []
seen = set()

while True:
    route.append(p)
    seen.add(p)

    p = arr[p]
    if p in seen:
        break

loop_start = route.index(p)
loop_len = len(route) - loop_start

if k <= loop_start:
    print(route[k] + 1)
else:
    rem = (k - loop_start) % loop_len
    print(route[loop_start + rem] + 1)


Measured memory_bytes: 32272
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  if (is_sorted(all(a))) {
    cout << "YES" << '\n';
    return;
  }
  for (int i = 0; i < n - 1; i++)
  for (int j = i + 1; j < n; j++) {
    swap(a[i], a[j]);
    if (is_sorted(all(a))) {
      cout << "YES" << '\n';
      return;
    }
    swap(a[i], a[j]);
  }
  cout << "NO" << '\n';
  return;
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

const ll INF = 1e9;
const long long INFL = 1LL<<60;

constexpr int mod = 1000000007;

int main() {
  const int N = 13;
  string s;
  cin >> s;

  // 後ろから解くアルゴリズム
  // 1?2?3  0 -> 3 -> ?3 -> 2?3 -> ...

  vector<vector<ll>> dp(s.size() + 1, vector<ll>(N, 0));

  reverse(s.begin(), s.end());

  // 1行目を初期化する
  if (s[0] == '?') {
    for (int i = 0; i < 10; i++) dp[0][i] = 1;
  } else {
    dp[0][s[0] - '0'] = 1;
  }

  ll mul = 10;
  for (int i = 1; i < s.size(); i++) {
    char c = s[i];
    if (c == '?') {
      for (int k = 0; k < 10; k++) {
        for (int j = 0; j < N; j++) {
          dp[i][(k * mul + j) % N] += dp[i-1][j];
          dp[i][(k * mul + j) % N] %= mod;
        }
      }
    } else {
      int k = (int)(c - '0');
      for (int j = 0; j < N; j++) {
        dp[i][(k * mul + j) % N] += dp[i-1][j];
        dp[i][(k * mul + j) % N] %= mod;
      }
    }
    mul *= 10;
    mul %= N;
  }

  cout << dp[s.size()-1][5] << endl;

  return 0;
}


Measured memory_bytes: 16712
#include<stdio.h>
int P,C[6],p[6]={500,100,50,10,5,1},i,m,R,a,b;

int g(int n,int f)
{
	int r=0,t,i;
	for(i=0;i<=5;i++)
	{
		t=n/p[i];
		if(f&&C[i]<t)t=C[i];
		r+=t;
		n-=p[i]*t;
	}
	return n!=0?8000:r;
}

int main()
{
	for(;scanf("%d",&P),P;)
	{
		for(i=6,R=7000;i--;)
		{
			scanf("%d",&C[i]);
			m+=p[i]*C[i];
		}
		for(i=P;i<=P+1000;i++)
		{
			a=g(i,1);b=g(i-P,0);
			R=a+b>=0&&R<a+b?R:a+b;
		}
		printf("%d\n",R);
	}
	return 0;
}

Measured memory_bytes: 600
/*
	*	Created By: 'Present_Sir'
	*	Created On: Friday 14 August 2020 12:52:24 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;


void solve(){
    int a;
    cin>>a;

    while( a>0){
        if( a%10 == 7 ){
            cout<<"Yes"<<endl;
            return;
        }
        a /= 10;
    }
    cout<<"No"<<endl;
}

int32_t main(){
    IOS;
    //int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}



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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
  -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

  int N;
  std::cin >> N;
  string C;
  std::cin >> C;

  int ans = 0;
  int i_back = N;
  REP(i, N) {
    if(C[i] == 'W') {
      while(i < i_back) {
        if(C[i_back] == 'R') {
          C[i_back] = 'W';
          ans++;
          break;
        }
        i_back--;
      }
    }
    if(i == i_back) break;
  }
  for(int i = i_back; i < N; i++) {
    if(C[i] == 'R') {
      ans++;
    }
  }
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,m,min=2500;
    cin>>n>>m;
    char c[n][m];
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>c[i][j];
        }
    }
    for(int i=1;i<n-1;++i){
        for(int j=1;j<n-i;++j){
            int cnt=0;
            for(int k=0;k<n;++k){
                for(int l=0;l<m;++l){
                    if(k<=i-1){
                        if(c[k][l]!='W'){
                            ++cnt;
                        }
                    }
                    else if(i-1<k&&k<=i+j-1){
                        if(c[k][l]!='B'){
                            ++cnt;
                        }
                    }
                    else{
                        if(c[k][l]!='R'){
                            ++cnt;
                        }
                    }
                }
            }
            if(min>cnt){
                min=cnt;
            }
        }
    }
    cout<<min<<endl;
}



Measured memory_bytes: 3108
#include <iostream>
using namespace std;
int red,green,blue,k;
int main(){
	cin>>red>>green>>blue>>k;
	for(int i=0;i<k;i++){
		if(green<=red) green*=2;
		else blue*=2;
		if(i==k) break;
	}
	if(blue>green&&green>red) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> a(h);
  pair<int, int> st;
  for (int i = 0; i < h; ++i) {
    cin >> a[i];
    for (int j = 0; j < w; ++j) {
      if (a[i][j] == 'S') {
        if (i == 0 || j == 0 || i == h - 1 || j == w - 1) {
          cout << 0 << endl;
          return 0;
        }
        st = {i, j};
      }
    }
  }
  vector<vector<int>> dist(h, vector<int>(w, -1));
  queue<pair<int, int>> q;
  q.emplace(st);
  dist[st.first][st.second] = 0;
  vector<int> dy{-1, 0, 1, 0};
  vector<int> dx{0, 1, 0, -1};
  int ans = 1e9;
  while (!q.empty()) {
    auto cur = q.front();
    q.pop();
    int y = cur.first, x = cur.second;
    if (dist[y][x] < k) {
      for (int k = 0; k < 4; ++k) {
        int ny = y + dy[k], nx = x + dx[k];
        if (ny >= 0 && ny < h && nx >= 0 && nx < w) {
          if (a[ny][nx] == '.' && dist[ny][nx] == -1) {
            dist[ny][nx] = dist[y][x] + 1;
            q.emplace(ny, nx);
          }
        }
      }
    }
    int mind = min({y, x, (h - 1) - y, (w - 1) - x});
    if (mind == 0) {
      ans = 0;
    } else {
      ans = min(ans, (mind - 1) / k + 1);
    }
    ans = min(ans, (min({y, x, (h - 1) - y, (w - 1) - x}) - 1) / k + 1);
  }
  cout << ans + 1 << endl;
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int h, w;
   cin >> h >> w;
   vector<string> s(h);
   rep(i, 0, h) cin >> s[i];

   vector<vector<int>> cnt(h, vector<int>(w));
   rep(i, 0, h) {
      vector<bool> done(w, false);
      rep(j, 0, w) {
         if (done[j]) continue;
         if (s[i][j] == '#') continue;
         int l = 0;
         while (j + l < w) {
            if (s[i][j + l] == '#') break;
            l++;
         }
         rep(k, 0, l) {
            cnt[i][j + k] += l;
            done[j + k] = true;
         }
      }
   }

   rep(j, 0, w) {
      vector<bool> done(h, false);
      rep(i, 0, h) {
         if (done[i]) continue;
         if (s[i][j] == '#') continue;
         int l = 0;
         while (i + l < h) {
            if (s[i + l][j] == '#') break;
            l++;
         }
         rep(k, 0, l) {
            cnt[i + k][j] += l;
            done[i + k] = true;
         }
      }
   }

   int ans = 0;
   rep(i, 0, h) rep(j, 0, w) ans = max(ans, cnt[i][j] - 1);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 23276
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 200050;
template<typename T>
inline void read(T&x)
{
	T f = 1,c = 0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
	x = f*c;
}
int n,fa[N],hed[N],cnt;
struct EG
{
	int to,nxt;
}e[N];
void ae(int f,int t)
{
	e[++cnt].to = t;
	e[cnt].nxt = hed[f];
	hed[f] = cnt;
}
bool cir[N];
int sta[N],tl;
void get_cir()
{
	int u = 1;
	while(!cir[u])cir[u]=1,u=fa[u];
	memset(cir,0,sizeof(cir));
	while(!cir[u])sta[++tl]=u,cir[u]=1,u=fa[u];
}
int sg[N];
int vis[N],tim;
void dfs(int u)
{
	for(int j=hed[u];j;j=e[j].nxt)
	{
		int to = e[j].to;
		if(!cir[to])dfs(to);
	}
	tim++;
	for(int j=hed[u];j;j=e[j].nxt)
	{
		int to = e[j].to;
		if(!cir[to])vis[sg[to]]=tim;
	}
	sg[u]=0;
	while(vis[sg[u]]==tim)sg[u]++;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(fa[i]);
		ae(fa[i],i);
	}
	get_cir();
	int mx = -1,mn = n+1;
	for(int i=1;i<=tl;i++)
		dfs(sta[i]),mx=max(mx,sg[sta[i]]),mn=min(mn,sg[sta[i]]);
	if(mx==mn&&(tl&1))puts("IMPOSSIBLE");
	else puts("POSSIBLE");
	return 0;
}


Measured memory_bytes: 4992
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  k <- readInt
  let list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
  print $ list !! (k - 1)


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

int main(){
    int N;
    cin >> N;
    int a[N];
    bool isvisited[N];

    for(int i=0; i<N; i++){
        cin >> a[i];
        isvisited[i]=false;
    } 

    int ii=0;
    int count=0;
    while(1){
        //cout << "while" << endl;
        if(isvisited[ii]){
            break;
        }else{
            isvisited[ii]= true;
            ii = a[ii]-1;
            //cout << "ii+1 " << ii+1 << endl;
            count++;
            if( ii== (2-1) ){
                cout << count << endl;
                return 0;
            }
        }

    }

    count=-1;
    cout << count << endl;    

    return 0;
}

Measured memory_bytes: 768
n = int(input())
def div(k):
    divider = []
    for i in range(1,int(k**0.5) + 1):
        if k % i == 0:
            divider.append(i)
            if k//i != i:
                divider.append(k//i)
    return len(divider)
sum = 0
for i in range(int(n/2 + 1/2)):
    if div(2*i + 1) == 8:
        sum += 1
print(sum)


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

int main()
{
    long long int a, b, c, k;
    cin>>a>>b>>c>>k;
    
    if(k%2==0)
    { cout<<a-b;}
    
    else if(k%2==1)
    { cout<<b-a; }
 
 else if(abs(a-b)>pow(10,18))
 { cout<<"Unfair";}
}

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

class Program
{
    static int OnEdge(decimal x, decimal y, decimal W, decimal H)
    {
        if (x == 0 || x == W || y == 0 || y == H)
            return 0;
        else
            return 1;
    }

    public static void Main()
    {
        var t = Console.ReadLine().Split(' ');
        decimal W = decimal.Parse(t[0]);
        decimal H = decimal.Parse(t[1]);
        decimal x = decimal.Parse(t[2]);
        decimal y = decimal.Parse(t[3]);

        decimal xp = W - x;
        decimal yp = H - y;

        if (xp == x && yp == y)
            Console.WriteLine($"{(W * H) / 2} 1");
        else
            Console.WriteLine($"{(W * H) / 2} 0");
    }
}

Measured memory_bytes: 13140
/*  UntilDeathDoesUsApart
    DO   NOT   GIVE   UP!
*/

#include <bits/stdc++.h>

using namespace std;

#define inc(a)           a.begin(), a.end()
#define dec(a)           a.rbegin(), a.rend()
#define Unique(n)        (n).erase(unique(in(n)), (n).end())
#define to(i, a, n)      for(int i=a; i<n; i++)
#define fr(i, a, n)      for(int i=a; i>=n; i--)
#define read(arr, l, r)  for(int i=l; i<r; cin >> arr[i++])
#define prnt(arr, l, r)  for(int i=l; i<r; cout << arr[i++] << " \n"[i==r])

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    string s; cin >> s;
    if(s=="ABC") cout << "ARC";
    else cout << "ABC";

    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    int max = a;
    if (max < b) {
      max = b;
    }
    if (max < c) {
      max = c;
    }
    System.out.println(a + b + c + max * ((1 << k) - 1));
  }

}


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

using namespace std;
using ll = long long;

int main() {
    int n,m = 0;
    cin >> n >> m;
    bool flag = true;
    int s[m];
    char c[m];
    string num = "";

    for(int i = 0; i < m ; i++){
        cin >> s[i] >> c[i];
    }

    for(int i = 0;i < 1000;i++){
        flag = true;
        num = to_string(i);
        if(num.size() != n){
            flag = false;
            continue;
        }
        for(int j = 0; j < m ;j++){
            if(num[s[j] - 1] != c[j]){
                flag = false;
                break;
            }
        }
        if(flag == true){
            break;
        }
    }

    if(flag){
        for(int i = 0;i < n ; i++){
            cout << num[i];
        }
    }else{
        cout << -1;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int idx = 1, cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == idx) {
            cnt++;
            idx++;
        }
    }
    if (cnt == 0)
        OUT(-1);
    else
        OUT(n - cnt);
}

Measured memory_bytes: 1024
import heapq
T = int(input())
for _ in range(T):
    N = int(input())
    KLR = [list(map(int, input().split())) for i in range(N)]
    ans = 0
    for i in range(N):
        ans += min(KLR[i][1], KLR[i][2])
    KX = [(K, L-R) for K, L, R in KLR if L-R >= 0]
    KX.sort()
    hq = []
    id = 0
    for i in range(1, N+1):
        while(id < len(KX) and KX[id][0] == i):
            heapq.heappush(hq, KX[id][1])
            id += 1
        while(len(hq) > i):
            heapq.heappop(hq)
        # print(hq)
    ans += sum(hq)
    L = len(KX)
    KX = [(N-K, R-L) for K, L, R in KLR if R-L > 0]
    KX.sort()
    hq = []

    id = 0
    for i in range(N):
        while(id < len(KX) and KX[id][0] == i):
            heapq.heappush(hq, KX[id][1])
            id += 1
        while(len(hq) > i):
            heapq.heappop(hq)
        # print(hq)

    ans += sum(hq)

    print(ans)


Measured memory_bytes: 71808
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007

using namespace std;

int main()
{
    IOS
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    ll dp[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    for(int i=1;i<=n;i++)
        dp[i]=LLONG_MAX;
    dp[n]=0;
    for(int i=n;i>1;i--)
    {
        int lim=max(0,i-k);
        for(int j=i-1;j>=lim;j--)
            dp[j]=min(dp[j],abs(arr[i]-arr[j])+dp[i]);
    }
    cout<<dp[1];
    return 0;
}


Measured memory_bytes: 1408
def main():
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        S.append(input())

    mv = [[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
    for i in range(H):
        t = ""
        for j in range(W):
            if S[i][j] == "#":
                t += "#"
            else:
                count = 0
                for di, dj in mv:
                    if 0<=i+di < H and 0 <= j+dj < W:
                        if S[i+di][j+dj] == "#":
                            count += 1
                t += str(count)
        print(t)

if __name__ == '__main__':
    main()

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> r(n, 0);
    for (size_t i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        r[a - 1]++;
        r[b - 1]++;
        /* code */
    }
    for (size_t i = 0; i < n; i++)
    {
        cout << r[i] << endl;
    }

    return 0;
}

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

const int MAX = 55;
int a[MAX], b[MAX];
bool visit[MAX];
int no;
vector<vector<int> > edge(MAX);

void dfs(int n) {
  visit[n] = true;

  for (int i = 0; i < edge[n].size(); i++) {
    if ((n == a[no] && edge[n][i] == b[no]) || (n == b[no] && edge[n][i] == a[no])) continue;
    if (!visit[edge[n][i]]) dfs(edge[n][i]);
  }
}

int main() {
  // 入力
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    edge[a[i]].push_back(b[i]);
    edge[b[i]].push_back(a[i]);
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    no = i;
    fill(visit, visit + N, false);
    dfs(0);
    for (int j = 0; j < N; j++) {
      if (!visit[j]) {
        ans++;
        break;
      }
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

public class AtCoderA
{
    static void Main()
    {
        int a;
        int b;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            a = int.Parse(words[0]);
            b = int.Parse(words[1]);
        }

        Console.WriteLine(Math.Max(Math.Max(a + b, a - b), a * b));
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define mod 1000000007
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;
void solve()
{
	int n;
	cin>>n;
	if(n>=30)cout<<"Yes"<<endl;
	else cout<<"No";
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int t=1;
   // cin>>t;
   // seive();
    while(t--)
	solve();
    return 0;
}

Measured memory_bytes: 3604
def find(target):
    if parent[target] < 0:
        return target
    else:
        parent[target] = find(parent[target])
        return parent[target]

def is_same(x, y):
    return find(x) == find(y)

def union(x, y):
    root_x = find(x)
    root_y = find(y)
    if root_x == root_y:
        return
    if parent[root_x] > parent[root_y]:
        root_x, root_y = root_y, root_x
    parent[root_x] += parent[root_y]
    parent[root_y] = root_x

# 今回これ使わないけど、どこに誰がいるのかはこれでわかる
def members(n, x):
    root = find(x)
    return [i for i in range(n) if find(i) == root]

def get_size(x):
    return -parent[find(x)]

def get_root():
    return [i for i, root in enumerate(parent) if root < 0]
n, m = map(int, input().split())
parent = [-1 for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    union(a, b)
ans = 0
for i in range(n):
    ans = max(ans, get_size(i))
print(ans)

Measured memory_bytes: 14436
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut ans = 0;
    let mut prev = 0;
    for _ in 0..n {
        let h = read::<usize>();
        if h >= prev {
            ans += 1;
        }
        prev = std::cmp::max(prev, h);
    }
    println!("{}", ans);
}


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

#define For(i, j, k) for(int i = j; i <= k; i++)

const int N = 1e5 + 10;

int cnt[N], n;

int main(){
	
	scanf("%d", &n);
	For(i, 1, n){
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}

	int pos = 0;
	For(i, 1, n) if(cnt[i]){
		pos = i;
		if(cnt[i] + cnt[i + 1] != n){
			puts("No");
			return 0;
		}
		break;
	}

	if(!cnt[pos + 1]){
		puts(pos == n - 1 || pos <= n / 2 ? "Yes" : "No");
	}
	else{
		if(cnt[pos + 1] <= 1) puts("No");
		else{
			int x = cnt[pos];
			if(pos + 1 - x <= cnt[pos + 1] / 2 && pos + 1 - x >= 1) puts("Yes");
			else puts("No");
		}
	}

	return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define endl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

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

/*追加部分*/



/*main関数*/

int main() {
FASTIO;
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    int ans = 0;
    
    while(true){
        for(int i = 0; i < n; i++){
            if(a[i]%2 != 0){
                goto BREAK;
            }
        }
        for(int i = 0; i < n; i++){
            a[i] /= 2;
        }

        ans++;
    }

BREAK:
    
    cout << ans << endl;

return 0;
}

Measured memory_bytes: 3688
using System;
using System.Linq;

public class Test
{
	public static void Main(){
var p = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
p = p.Concat(Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray()).ToArray();
p = p.Concat(Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray()).ToArray();
int[] c = new int[5];
Array.ForEach(p,i=>c[i]++);
Array.Sort(c,(i,j)=>j-i);
Console.WriteLine(c[0]==2&&c[1]==2&&c[2]==1&&c[3]==1?"YES":"NO");
}
}

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

struct Node{//binary tree's node
    int key;
    Node *parent, *left, *right;
};

Node *root, *NUL;

void insert(int node){
    //Now Searching...
    Node *nowNode = root;//start with root
    Node *nowParent = NUL;//root node's parent node is NULL
    while(nowNode!=NUL){
        if(nowNode->key<node){
            nowParent = nowNode;
            nowNode = nowParent -> right;
        }else{
            nowParent = nowNode;
            nowNode = nowNode -> left;
        }
    }
    //Now Creating new Node
    Node *newNode = new Node();
    newNode->key = node;
    newNode->left = newNode->right = NUL;
    //Now Inserting
    if(nowParent==NUL){//empty tree's root node
        root = newNode;
    }else if(node<nowParent->key){
        nowParent->left = newNode;
    }else{
        nowParent->right = newNode;
    }
}

void preOrder(Node *nowNode){
    if(nowNode==NUL) return;
    cout<<" "<<nowNode->key;
    preOrder(nowNode->left);
    preOrder(nowNode->right);
}

void inOrder(Node *nowNode){
    if(nowNode==NUL) return;
    inOrder(nowNode->left);
    cout<<" "<<nowNode->key;
    inOrder(nowNode->right);
}

int main(){
    root = NUL;//initial root
    int ope;
    cin>>ope;
    for(int i=0; i<ope; i++){
        string op;
        cin>>op;
        if(op=="print"){
            inOrder(root);
            cout<<endl;
            preOrder(root);
            cout<<endl;
        }else{
            int toInsert;
            cin>>toInsert;
            insert(toInsert);
        }
    }
    return 0;
}



Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int m,n;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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 gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}


int main() {
	int A,B,C; cin>>A>>B>>C;
	cout<<C<<" "<<A<<" "<<B<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

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

int main() {
    int n;
    cin >> n;
    bool ok = false;
    rep(i, n) {
        ll a;
        cin >> a;
        if (a&1) ok = true;
    }
    if (ok) cout << "first" << endl;
    else    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int a,b,q;cin>>a>>b>>q;
  vector<ll> s(a+2),t(b+2);
  s[0]=t[0]=-1e13;
  s[a+1]=t[b+1]=1e13;
  rep(i,a)cin>>s[i+1];
  rep(i,b)cin>>t[i+1];
  rep(i,q){
    ll x;cin>>x;
    ll sum=1e40;
    rep(j,8){
      auto dist0it=(j&1?lower_bound(all(s),x):lower_bound(all(t),x));
      if(j&2)--dist0it;
      ll dist0=*dist0it;
      auto dist1it=(j&1?lower_bound(all(t),x):lower_bound(all(s),x));
      if(j&4)--dist1it;
      ll dist1=*dist1it;
      chmin(sum,abs(x-dist0)+abs(dist0-dist1));
    }
    cout<<sum<<endl;
  }
}





Measured memory_bytes: 2944
N = int(input())
cnt = [0]*4
for i in range(N):
  x = input()
  if x == 'AC':
    cnt[0]+=1
  elif x == 'WA':
    cnt[1]+=1
  elif x == 'TLE':
    cnt[2]+=1
  else:
    cnt[3]+=1
print('AC x {}'.format(cnt[0]))
print('WA x {}'.format(cnt[1]))
print('TLE x {}'.format(cnt[2]))
print('RE x {}'.format(cnt[3]))

Measured memory_bytes: 9152
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), 0)
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, _ := strconv.Atoi(readString())
	return i
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}
func main() {
	N := readInt()
	M := readInt()
	Q := readInt()
	var data [510][510]int
	for i := 0; i < M; i++ {
		l, r := readInt(), readInt()
		data[l][r]++
	}

	for i := N; i >= 1; i-- {
		for j := 1; j <= N; j++ {
			data[i][j] += data[i+1][j]
			data[i][j] += data[i][j-1]
			data[i][j] -= data[i+1][j-1]
		}
	}
	var buf bytes.Buffer
	for i := 0; i < Q; i++ {
		p, q := readInt(), readInt()
		buf.WriteString(strconv.Itoa(data[p][q]))
		buf.WriteString("\n")
	}
	fmt.Println(buf.String())
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
int n,h[N],dp[N];

int dfs(int i){
   if(i>n) return 1e9;
   if(i==n) return 0;
   int &ans = dp[i];
   if(ans != -1) return ans;
   return ans = min(dfs(i+2)+abs(h[i+2]-h[i]),dfs(i+1)+abs(h[i+1]-h[i]));
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   // #ifndef ONLINE_JUDGE
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   // #endif
   cin >> n;
   f(i,1,n+1){
      cin >> h[i];
   }
   h[n+2] = h[n+1] = 1e9;
   f(i,0,n+10) dp[i]=-1;
   cout << dfs(1) << '\n';   
   return 0;
} 

Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];			
		for(int i = 0;i<N;i++) {
			 a[i] = sc.nextInt();			
		}
		Arrays.sort(a);
		int sum =0;
		sum = a[a.length/2]-a[a.length/2-1];
		System.out.print(sum);
	}
}


Measured memory_bytes: 50952
from queue import Queue

inf = 10 ** 20

def bfs(H, W, s):
    d = [[inf for i in range(W)] for j in range(H)]
    q = Queue()

    d[0][0] = 1
    q.put([0, 0])

    dx = (0, -1, 1, 0)
    dy = (-1, 0, 0, 1)

    while not q.empty():
        p = q.get()
        x = p[0]
        y = p[1]
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if(nx >= 0 and nx < H and ny >= 0 and ny < W):
                if(s[nx][ny] == '.' and d[x][y] + 1 < d[nx][ny]):
                    d[nx][ny] = d[x][y] + 1
                    q.put([nx, ny])

    return d[H-1][W-1]

H, W = map(int, input().split())
s = []
wnum = 0
for i in range(H):
    s.append(input())
    for j in range(W):
        if(s[i][j] == "."):
            wnum += 1
d = bfs(H, W, s)
if(d == inf):
    print("-1")
else:
    print(wnum - d)


Measured memory_bytes: 4208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		double d = sc.nextInt();
		double t = sc.nextInt();
		double s = sc.nextInt();

		System.out.println(t*s >= d ? "Yes" : "No");
	}

}


Measured memory_bytes: 27052
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		
		Scanner scan = new Scanner(System.in);
		ArrayList<Queue<Integer>> que = new ArrayList<>();
		
		int n = scan.nextInt();
		for(int i=0; i<n; i++) {
			que.add(new ArrayDeque<Integer>());
		}
		
		int count = scan.nextInt();
		
		for(int i=0; i<count; i++) {
			int query = scan.nextInt();
			int a = scan.nextInt();

			switch(query) {
			
			case 0:
				int b = scan.nextInt();
				que.get(a).offer(b);
				break;
				
			case 1:
				if(!que.get(a).isEmpty())
				System.out.println(que.get(a).element());
				break;
				
			case 2:
				if(!que.get(a).isEmpty())
				que.get(a).poll();
				break;
			}
		}
	}
}



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

int main(){
    int a,b,c,cnt=0;
    cin >> a >> b >> c;
    for(int i=a;i<=b;i++){
        if(c%i==0) cnt++;
    }
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 3108
def main():
  import sys
  input = sys.stdin.readline

  n=int(input())
  t=list(map(int,input().split()))
  m=int(input())
  px=[list(map(int,input().split())) for _ in range(m)]
  
  for i in range(m):
    print(sum(t)-t[px[i][0]-1]+px[i][1])
  
if __name__ == '__main__':
    main()

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

using ll = long long int;
using P = pair<ll, ll>;
using P3 = pair<int, P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};

bool solve(){
    int n;
    cin >> n;
    if(n == 0) return false;
    vector<vector<int> > a(2,vector<int>(n+1)), d(2,vector<int>(n,INF));
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin >> a[i][j];
        }
        for(int j=0;j<n;j++){
            if(a[i][j]==1 && a[i][j+1]!=1){
                a[i][j] = 0;
            }
        }
    }
    d[0][0] = d[1][0] = 0;
    deque<P> que;
    que.push_back(P(0,0));
    que.push_back(P(1,0));
    while(!que.empty()){
        P p = que.front();
        que.pop_front();
        int i = p.first, j = p.second;
        if(a[i][j] == 0){
            for(int x=0;x<=2&&j+x<n;x++){
                if(d[i^1][j+x] > d[i][j]+1){
                    d[i^1][j+x] = d[i][j]+1;
                    que.push_back(P(i^1,j+x));
                }
            }
        }
        else if(a[i][j]==1){
            if(d[i][j+1] <= d[i][j]) continue;
            d[i][j+1] = d[i][j];
            que.push_front(P(i,j+1));
        }
        else{
            if(j==0 || d[i][j-1] <= d[i][j]) continue;
            d[i][j-1] = d[i][j];
            que.push_front(P(i,j-1));
        }
    }
    int ans = INF;
    for(int i=0;i<2;i++){
        if(a[i][n-1] == 2) continue;
        ans = min(ans, d[i][n-1]);
    }
    if(ans < INF){
        cout << ans << endl;
    }else{
        cout << "NA" << endl;
    }
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 3076