akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int main(){
    string s; cin >> s;
    rep(i,19){
        if(i==5||i==13) cout << " ";
        else cout << s[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
string s,t;
int main(){
	char c;
	cin>>s>>t;
	for(c='a';c<='z';c++)
	{
		if(s+c==t)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
int main(){
    char s[3][101];
    int p[3]={0,0,0},n=0,m;
    for(int i=0;i<3;i++)scanf("%s",s[i]);
    while(true){
        if(s[n][p[n]]=='\0'){
            printf("%c",'A'+n);
            return 0;
        }else{
            m=n;
            n=s[n][p[n]]-'a';
            p[m]++;
        }
    }
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int,input().split()))

last_ok_postion = 0 
count = 1

for i in range(1,N):
    if P[last_ok_postion] >= P[i]:
        m = min(P[last_ok_postion:i])
        if m >= P[i]:
            count += 1
            last_ok_postion = i
print(count)

Measured memory_bytes: 32252
#ABC061C

n,k=map(int,raw_input().split())
l=[]
for i in xrange(n):
 a,b=map(int,raw_input().split())
 l.append((a,b))
l.sort()
s=0
for i in xrange(n):
 s+=l[i][1]
 if s>=k:
  print l[i][0]
  break


Measured memory_bytes: 15808
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};

int main(){
  int n,k;
  cin >> n >> k;
  vector<long long> p(n),c(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
    p.at(i)--;
  }
  for(int i=0;i<n;i++){
    cin >> c.at(i);
  }
  long long ans = INF * INF * (-1);
  for(int i=0;i<n;i++){
    long long tmp = 0;
    int a = i;
    vector<long long> s;
    a = p.at(a);
    s.push_back(c.at(a));
    while(a != i){
      a = p.at(a);
      s.push_back(c.at(a));
    }
    int count = s.size();
    vector<long long> sum(count);
    sum.at(0) = s.at(0);
    for(int i=1;i<count;i++){
      sum.at(i) = sum.at(i-1) + s.at(i);
    }
    if(k <= count){
      vector<long long> unko = vector(sum.begin(),sum.begin()+k);
      sort(unko.begin(),unko.end());
      tmp = unko.back();
    }
    else if(sum.back() <= 0){
      vector<long long> unko = sum;
      sort(unko.begin(),unko.end());
      tmp = unko.back();
    }
    else{
      tmp += sum.back() * ((k/count)-1);
      int kk = k % count;
      vector<long long> unko(count+kk);
      for(int i=0;i<count;i++){
        unko.at(i) = sum.at(i);
      }
      for(int i=0;i<kk;i++){
        unko.at(count+i) = unko.at(count+i-1) + s.at(i);
      }
      sort(unko.begin(),unko.end());
      tmp += unko.back();
    }
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3800
k, t = map(int, input().split())
a = [[int(x), i] for i, x in enumerate(input().split())]
pc = -1
while(True):
    a.sort(reverse=True)
    for i in range(t):
        if a[i][0] > 0 and a[i][1] != pc:
            a[i][0] -= 1
            pc = a[i][1]
            break
    else: break
print(sum([x for x, _ in a]))


Measured memory_bytes: 3064
import java.util.*; 
public class Main {
    public static void main(String[] args)  {
      Scanner in = new Scanner(System.in);
           String s = in.next();
           Stack<Character> st = new Stack<Character>();
           for (int i =0;i<s.length();i++) {
        	   if (s.charAt(i) == 'B' && st.size()!=0) {
        		   st.pop();}
        	   else if (s.charAt(i) != 'B'){
        		   st.push(s.charAt(i));
        	   }
           }
           for (Character ch : st) {
			System.out.print(ch);
		}
           System.out.println();
           
    }
 
}

Measured memory_bytes: 26880
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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


vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}



int main(){
  
  ll n; cin >> n;
  
  map<ll,ll> table;
  
  for(ll i=1; i <= n; i++){
    auto vec = prime_factorize(i);
    
    for(auto p : vec){
      table[p.first] += p.second;
    }
  }
  
  ll ans = 1;
  
  for(auto p : table){
    ans *= p.second+1;
    ans = mod(ans);
  }
      
  
  /*ll ans = 1;
  
  for(ll i=2; i <= n; i++){
    ans *= n/i;
    ans = mod(ans);
  }*/
  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 3616
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

ll a[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    int n;
    cin >> n;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 0) return cout << "0\n", 0;
    }
    for (int i = 0; i < n; i++) {
        if (__builtin_mul_overflow(ans, a[i], &ans)) return cout << "-1\n", 0;
        if (ans > 1000000000000000000) return cout << "-1\n", 0;
    }
    cout << ans << '\n';
}

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

int main() {
    int h,w;
    cin >> h >> w;

    vector<vector<char>> s(h, vector<char>(w));
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> s.at(i).at(j);
        }
    }

    int ans=0;

    vector<pair<int,int>> vec = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (s.at(i).at(j) == '.') {
                vector<vector<int>> c(h, vector<int>(w, -1));
                queue<pair<int, int>> q;
                auto now = make_pair(i, j);
                q.push(now);
                c.at(i).at(j) = 0;
                while (!q.empty()) {
                    now = q.front();
                    q.pop();
                    for (auto v:vec) {
                        if (now.first + v.first >= 0 && now.first + v.first < h && now.second + v.second >= 0 && now.second + v.second < w) {
                            if (s.at(now.first + v.first).at(now.second + v.second) == '.') {
                                if (c.at(now.first + v.first).at(now.second + v.second) == -1) {
                                    c.at(now.first + v.first).at(now.second + v.second) = c.at(now.first).at(now.second) + 1;
                                    auto nxt = make_pair(now.first + v.first, now.second + v.second);
                                    q.push(nxt);
                                    if (c.at(now.first).at(now.second) + 1 > ans) ans = c.at(now.first).at(now.second) + 1;
                                }
                            }
                        }
                    }
                }
            }
        }    
    }

    cout << ans << endl;
}

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


n, x = [int(_) for _ in input().split()]
x_list = [int(_) - x for _ in input().split()]

x_sorted = sorted(x_list)

x_gaps = [x_sorted[i+1] - x_sorted[i] for i in range(0, n-1)]

if len(x_gaps) == 0:
    print(abs(x_sorted[0]))
elif len(x_gaps) == 1:
    print(gcd(abs(x_list[0]), abs(x_list[1])))
else:
    result = x_sorted[0]
    for i in range(0, n-2):
        if i == 0:
            result = gcd(x_gaps[0], x_gaps[1])
        else:
            result = gcd(result, x_gaps[i+1])
    print(result)

Measured memory_bytes: 14100
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using ll = long long;
using ld = long double;
//typedef long long ll;

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

#define INF ((1LL << 31) - 1)
#define INFLL ((1LL << 62) - 1)
#define MOD (ll)(1e9+7)
#define EPS 1e-10
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define P "Yes"
#define NP "No"

template <typename T>
std::ostream& operator << (std::ostream& os, std::vector<T> v) {
  os << "[";
  for (int i = 0; i < int(v.size()); ++i) {
    cout << v[i] << (i == v.size() - 1 ? "]" : ", ");
  }
  return os;
}

int vx[4] = { -1, 0, 1, 0 }, vy[4] = { 0, -1, 0, 1 };
//int vx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, vy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

// [sx, se), [sy, ey)であることに注意
inline bool check(int sx, int ex, int sy, int ey, int x, int y) {
  return (sx <= x and x < ex and sy <= y and y < ey);
}

inline bool check(int ex, int ey, int x, int y) {
  return check(0, ex, 0, ey, x, y);
}

inline void init() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
}

void solve() {
  int a, b, c, n;
  std::string s, t;
  std::vector<int> x;

  cin >> n;
  x.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }

  std::sort(x.begin(), x.end(), std::greater<int>());

  int alice = 0, bob = 0;

  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      alice += x[i];
    }
    else {
      bob += x[i];
    }
  }

  cout << alice - bob << endl;

  return;
}

int main() {

  solve();

  return 0;
}

Measured memory_bytes: 256
import math
def int_ceil(src,range):
    return int(math.ceil(src/float(range)) * range)

def main():
    week = int(input())
    debt = 100000
    for i in range(week):
        risi = debt * 0.05
        debt = int_ceil(debt+ risi,1000)

    print(debt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5668
#include<stdio.h>
using namespace std;

int f[50]={1,1};

void Fibonacci(){
    for(int i=2;i<45;i++) f[i]=f[i-1]+f[i-2];
}

int main(){
    Fibonacci();
    int n;
    scanf("%d",&n);
    printf("%d\n",f[n]);
    return 0;
}

Measured memory_bytes: 2712
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main()
{
    string s, p;
    cin >> s >> p;
    int n = s.size();
    s = s + s;
    bool flag = false;
    for (int i = 0; i < n; i++)
    {
        if (s.substr(i, p.size()) == p)
            flag = true;
    }
    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3216
#include<stdio.h>
int main(void)
{
	int a,b,c,d,x,y,z;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	x=a+b+c+d;
	y=x/60;
	z=x%60;
	printf("%d\n",y);
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 2720
n = int(input())
a = list(map(int, input().split()))
 
m = [0]*n
m[0] = sum(a)
 
for i in range((n-1)//2):
	m[0] -= 2*(a[1+i*2])
 
for i in range(1,n):
	m[i] = 2*a[i-1] - m[i-1]
 
print(' '.join(map(str, m)))

Measured memory_bytes: 19100
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}


int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl();
        string s = ins();
        ll d1[n + 1], d2[n + 1];

        d1[0] = 0, d2[0] = 0;
        rep(i, n) {
            if (s[i] == '.') {
                d1[i + 1] = d1[i] + 1;
                d2[i + 1] = d2[i];
            } else {
                d2[i + 1] = d2[i] + 1;
                d1[i + 1] = d1[i];
            }
        }
        ll ans = ll_inf;
        for (int i = 1; i <= n + 1; ++i) ans = min(ans, d1[n] - d1[i - 1] + d2[i - 1]);
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


int main(){
  int h,a;cin>>h>>a;
  int res=h/a;
  if(h%a!=0)res++;
  cout << res << endl;
}

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

using namespace std;

typedef long long ll;
int main()
{
	ll n,k;
	cin >> n >> k;
	ll arr[n];
	for(int i = 0; i < n; i++){ cin >> arr[i]; --arr[i];}
	queue<int> q; q.push(0);
	int ans;
	int vis[n]; memset(vis,0,sizeof(vis));
	vector<int> v;
	ll m = k;
	int cycle;
	while(!q.empty() && k){
		int s = q.front(); q.pop();
		if(vis[s]){cycle = s; v.push_back(s); break;}
		vis[s] = 1;
		v.push_back(s);
		q.push(arr[s]);
		k--;
	}
	if(k){
		bool found = false;
		int cnt = 0;
		vector<int> temp;
		for(int x : v){
			if(x == cycle){found = true;}
			if(!found){cnt++; continue;}
			if(found) temp.push_back(x);
		}
		m -= cnt;
		temp.pop_back();
		m %= temp.size();
		ans = temp[m]+1;
	} 
	else ans = arr[v[v.size()-1]]+1;
	cout << ans;
}


Measured memory_bytes: 7096
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
const int mod=1000000007;
const int INF=1e18;


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long double n;
	cin>>n;
	cout<<setprecision(12)<<fixed<<(n/3)*(n/3)*(n/3)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
struct E{
  long long t,c;
  bool operator<(const E&a)const{return c>a.c;}
};
vector<E>G[1<<17];
long long z[1<<17];
int n,a,b,c,q,k,x,y,i,j;
void dijkstra(){
  priority_queue<E>Q;
  for(int i=0;i<1<<17;)z[i++]=1ll<<60;
  z[k]=0;
  Q.push(E{k,0});
  while(Q.size()){
    E p=Q.top();Q.pop();
    if(z[p.t]<p.c)continue;
    for(i=0;i<G[p.t].size();++i){
      E e=G[p.t][i];
      if(z[e.t]>p.c+e.c)z[e.t]=p.c+e.c,Q.push(E{e.t,z[e.t]});
    }
  }
}
main(){
  for(cin>>n;++i<n;G[a].push_back(E{b,c}),G[b].push_back(E{a,c}))scanf("%d%d%d",&a,&b,&c);
  for(cin>>q>>k,dijkstra();j++<q;printf("%lld\n",z[x]+z[y]))scanf("%d%d",&x,&y);
}


Measured memory_bytes: 12144
#include<stdio.h>
#include<string.h>


int main(){
 //long int   A, B,C, D;
 int A,B,C,D;

//scanf("%ld %ld %ld %ld", &A, &B, &C, &D);
scanf("%d%d%d%d", &A, &B, &C, &D);

 long int sum ;
  /*if(A+B >= D){
    sum = A;
  }else{
    sum = A-(D-A-B);
  }*/

  if(D - A>0){
    if(D-A-B>0){
      sum = A-(D-A-B);
    }else 
    sum= A;
  }else 
  sum= D;

    printf("%ld\n", sum);
  

return 0;
}

Measured memory_bytes: 1728
import bisect

N = int(input())
A = sorted(map(int, input().split()))
M = max(A)
cs = [0] #si=[0,i)の和 [a,b)の和=sb−sa
for i in A:
    cs.append(cs[-1] + i)
A.append(A[-1])
ans = 0
for i in range(N, 0, -1):
    if cs[i] * 2 >= A[i]:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 20488
n=gets.to_i
max1=0
max2=0
as=[]

n.times do
  ai=gets.to_i
  if max1<ai
    max1=ai
  elsif max2<ai
    max2=ai
  end
  as.push(ai)
end

as.each do |ai|
  puts ai==max1 ? max2:max1
end


Measured memory_bytes: 5172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c; cin >> a >> b >> c;
    if(a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

const int MAX_N = 1e7;

struct UnionFind{
    int N;
    int par[MAX_N];

    UnionFind(int N): N(N){
        for (int i=0;i<N;i++){
            par[i] = i;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        int rx = root(par[x]);
        par[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx==ry) return;
        par[rx] = ry;
    }

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    REP(i, N){
        cin >> p[i];
    }
    UnionFind uf(N);
    REP(i, M){
        int x, y;
        cin >> x >> y;
        uf.unite(x-1, y-1);
    }
    int res = 0;
    REP(i, N){
        res += uf.find(p[i]-1, i);
    }
    cout << res << endl;
    return 0;
}

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

void solve(long long N, long long K, std::vector<long long> x)
{
    int cost = 0;
    for (long long i = 0; i < N; i++)
    {
        if (x.at(i) < K - x.at(i))
        {
            cost += x.at(i) * 2;
        }
        else
        {
            cost += (K - x.at(i)) * 2;
        }
    }
    cout << cost << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> x(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &x[i]);
    }
    solve(N, K, std::move(x));
    return 0;
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int count=0;
  while(1){
    if(count%2==0){
      c-=b;
    }else{
      a-=d;
    }
    count++;
    if(a<=0){
      cout<<"No"<<endl;
      break;
    }
    if(c<=0){
      cout<<"Yes"<<endl;
      break;
    }
  }
}


Measured memory_bytes: 3672
#include<iostream>
using namespace std;
typedef long long int ll;

int mod = 1000000007;
char grid[10000][10000];

int solve(int h, int w)
{
  int dp[h][w];
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = grid[0][0] == '.' ? 1 : 0;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (j == 0)
      {
        if (grid[i][j] == '.')
          dp[i][j] = (i == 0 ? dp[0][0] : dp[i-1][j]);
        else
          dp[i][j] = 0;
        continue;
      }
      if (i == 0) 
      {
        dp[i][j] = 1;
        if (grid[i][j] == '.')
          dp[i][j] = (j == 0 ? dp[0][0] : dp[i][j-1]);
        else
          dp[i][j] = 0;
        continue;
      }
      if (grid[i][j] == '.')
      {
        dp[i][j] = (dp[i-1][j] % mod) + (dp[i][j-1] % mod) % mod;
      }
      else if (grid[i][j] = '#')
      {
        dp[i][j] = 0;
      }
    }
  }
  return dp[h-1][w-1] % mod;
}

int main()
{
  int h, w;
  cin >> h >> w;
  grid[h][w];
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      cin >> grid[i][j];
    }
  }
  int x = solve(h, w);
  cout << x << endl;
  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int x = n/k;
  int ans = 1;
  while(x) {
    x /= k;
    ans++;
  }
  cout << ans << endl;
}

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

int main() {
  string S; cin >> S;
  bool ans = true;
  for(int i = 0; i < S.size(); i++) {
    if(i % 2 == 0) {
      if(S[i] == 'L') ans = false;
    } else {
      if(S[i] == 'R') ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


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

int main(){
  char s[4]; cin>>s;
  int ans=0;
  for(int i=0;i<4;i++){
    if(s[i] == '+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        String temp[] = str.split(" ");
        int a = new Integer(temp[1]);
        int b = new Integer(temp[2]);
        int x = new Integer(temp[0]);
        if((-a + b)<= 0){
            System.out.println("delicious");
        }else if((-a + b) <= x){
            System.out.println("safe");
        }else{
            System.out.println("dangerous");
        }
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <map>

#define INPUT_MAX 10000
#define NUM_MAX 100000000


int main(int argc, const char * argv[]) {
  int x, y;
  int other, amari;
  int temp_amari;
  int divisor;
  divisor = 0;
  std::cin >> x >> y;
  if (x > y) {
    amari = x % y;
    other = y;
  } else {
    amari = y % x;
    other = x;
  }
  
  while (amari != 0) {
    temp_amari = other % amari;
    other = amari;
    amari = temp_amari; 
  }
  std::cout << other << std::endl;
  
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void)
{
	int i,n,a[100],s,w;
	scanf("%d",&n);
	s=0; w=0;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++){
		if(a[i]==0){
			s=0;
		}
		if(a[i]==1){
			s++;
			if(w<s){
				w=s;
			}
		}
	}
	printf("%d\n",w+1);
	return 0;
}


Measured memory_bytes: 2144
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    int A = a-x;
    int B = b-x;
    
    A = Math.abs(A);
    B = Math.abs(B);
    
    if(A>B){
	System.out.println("B");
    }else{
    System.out.println("A");
    }
      }
}

Measured memory_bytes: 35556
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define ll long long
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define binary(x) std::string binary = std::bitset<25>(x).to_string(); //to binary
#define inf 1000000007
#define mod 1000000007
#define pi pair<int,int>
#define lpi pair<int,int>
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define lvi vector<long long int>
#define pie 3.14159265358979323846
ll int MMM=inf;
int pw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%MMM)if(y&1)z=1ll*z*x%MMM;return z;}
using namespace std;
vi pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.pb(p);
}
bool sortbysecdesc(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    return a.first>b.first;
}
bool cmp(int x,int y){return x>y;}
int cost[100002];
int main()
{
	faltu;
	int n;
	cin>>n;
	int a[n+1][4];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	int dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			dp[i][j]=a[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}








Measured memory_bytes: 2944
#include <iostream>

using namespace std;

int main()
{

    int a, b, x;
    cin >> a >> b >> x;

    if (a <= x && a + b >= x)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ans,tmp,hoge,fuga,piyo,sum;
ll A[200100],B[200100],C[200100],D[200100];
string st,str;
char ch;
int main(){
  cin>>st>>str;
  for(int i=0;i<st.length();i++){
    if(st[i]!=str[i])ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3848
# frozen_string_literal: true

n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
sum = 0
0.upto(n - 1) do |i|
  c = [a[i], b[i]].min
  a[i] -= c
  b[i] -= c
  sum += c
  c = [a[i + 1], b[i]].min
  a[i + 1] -= c
  b[i] -= c
  sum += c
end

puts sum


Measured memory_bytes: 19468
$r=0..8
def f;$r.map{|i|(?1..?9).map{|d|$r.map{|j|$m[yield(i,j)+1]}.count(d)>1&&$r.map{|j|$m[x=yield(i,j)+1]==d&&$m[x-1]=?*}}}end
puts ("1\n"..gets).map{$m=$r.map{" "+gets}*""
f{|i,j|i*19+j*2}
f{|i,j|j*19+i*2}
f{|i,j|(i-i%3+j/3)*19+j%3*2+i%3*6}
$m}*?\n

Measured memory_bytes: 6116
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a,b,c;
    cin >>a>>b>>c;
    if(a+b==c||a+c==b||c+b==a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;


ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

ll dp[3000][3000];

int main() {

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

	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	dp[A - 1][B - 1] = 1;
	FOR(i, A, C) {
		dp[i][B - 1] = (dp[i - 1][B - 1] * B)%MOD;
	}
	FOR(i, B, D) {
		dp[A - 1][i] = (dp[A - 1][i - 1] * A)%MOD;
	}

	FOR(i, A, C)FOR(j, B, D) {
		dp[i][j] = ((dp[i - 1][j] * (j + 1))%MOD + (dp[i][j - 1] * (i + 1))%MOD-(dp[i-1][j-1]*i*j)%MOD) % MOD;
	}
	cout << (dp[C - 1][D - 1]+MOD)%MOD << endl;





	return 0;
}


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

struct Card { char suit, value;};

void bubble(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		for (int j = n -1; j >= i + 1; j--) {
			if (A[j].value < A[j-1].value) {
				swap(A[j], A[ j-1]);
			}
		}
	}
}

void selection(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (A[j].value < A[minj].value) {
				minj = j;
			}
		}
		swap(A[i], A[minj]);
	}

}

void print(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		if(i > 0) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

//To compare result of bubble and selection sort
bool isStable(struct Card C1[], struct Card C2[], int n) {
	for (int i = 0; i < n; i++) {
		if (C1[i].suit != C2[i].suit) {
			return false;
		}
	}
	return true;
}

int main() {
	Card C1[100], C2[100];
	int n;
	char ch;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> C1[i].suit >> C1[i].value;
	}

	for (int i = 0; i < n; i++) C2[i] = C1[i];

	bubble(C1, n);
	selection(C2, n);

	print(C1, n);
	cout << "Stable" << endl;
	print(C2, n);
	if (isStable(C1, C2, n)) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	return 0;


}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n, k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  setF(N);
  ll ans = 0;
  FOR(i, 0, min(n, k+1)) ans += comb(n, i)*comb(n-1, i)%MOD;
  cout << ans%MOD << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <utility>
#include <cmath>
#include <set>
#define eps 1e-8
#define inf 1e18

using namespace std;
typedef pair<int, int> P;

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
	P near(){
		P ret;
		int cx = ceil(x), fx = floor(x);
		if(fabs(cx-x) < eps) ret.first = cx;
		else if(fabs(fx-x) < eps) ret.first = fx;
		else return make_pair(-inf, -inf);
		
		int cy = ceil(y), fy = floor(y);
		if(fabs(cy-y) < eps) ret.second = cy;
		else if(fabs(fy-y) < eps) ret.second = fy;
		else return make_pair(-inf, -inf);
		
		return ret;
	}
};

int n;
int x[1005], y[1005];
vec2d p[1005];
set<P> S;

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	for(int i = 1; i <= n; i++) p[i] = vec2d(x[i], y[i]);
	for(int i = 1; i <= n; i++) S.insert(make_pair(x[i], y[i]));
	
	bool flag = false;
	for(int i = 2; i <= n; i++){
		if(fabs( (p[2]-p[1]).cross(p[i]-p[1]) ) > eps){
			flag = true;
			break;
		}
	}
	if(!flag){
		cout << "No" << endl;
		return 0;
	}
	
	for(int k = 1; k <= 3; k++){
		for(int i = 1; i <= n; i++){
			if(i == k) continue;
			vec2d v = p[i] - p[k];
			bool flag = true; int cnt = 0;
			for(int j = 1; j <= n; j++){
				vec2d u = p[k] - p[j];
				vec2d q = p[j] + v + (v/v.norm())*(2*u.dot(v/v.norm()));
				if(!S.count(q.near())){
					flag = false;
					break;
				}
				if(p[j].near() == q.near()) cnt++;
			}
			if(flag && cnt <= 2){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3188
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String s = sc.next();
		String t = sc.next();

		sc.close();

		String s2 = s + s;
		Map<Character, List<Integer>> m = new HashMap<>();
		for (char c = 'a'; c <= 'z'; c++) {
			m.put(c, new ArrayList<>());
		}
		for (int i = 0; i < s2.length(); i++) {
			char c = s2.charAt(i);
			m.get(c).add(i + 1);
		}

		long pos = 0;

		for (int i = 0; i < t.length(); i++) {
			char c = t.charAt(i);
			List<Integer> l = m.get(c);
			if (l.size() == 0) {
				out.println(-1);
				return;
			}
			int idx = upperBound(l, 0, l.size(), (int) (pos % s.length()));

			pos += (l.get(idx) - (int) (pos % s.length()));

		}

		out.println(pos);

	}

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

	@SuppressWarnings("unused")
	private static int upperBound(List<Integer> a, int st, int ed, int k) {
		if (st == ed - 1) {
			if (a.get(st) <= k) {
				return st + 1;
			} else {
				return st;
			}
		}

		int m = (ed - st) / 2 + st;
		if (a.get(m) <= k) {
			//右側
			return upperBound(a, m, ed, k);
		} else {
			//左側
			return upperBound(a, st, m, k);
		}
	}
}


Measured memory_bytes: 33276
#include <bits/stdc++.h>
using namespace std;
using ll = long long  ;
int main(){
	ll n ,sum=0  ;
	cin >> n ;
	int a[n] ;
	for(int i=0 ;i<n ;i++)
    {
       cin >> a[i] ;

    }
 sort (a+0 ,a+n) ;

 for(int i=0 ;i<n-1 ;i++)
 {
     sum+=a[i] ;
 }
    if(a[n-1] < sum )
    {
        cout <<"Yes" <<endl ;
    }
	else {cout << "No" <<endl ;}

	return 0 ;
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N; cin >> N;
  ll a[N];
  ll same = 0;
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == i+1) same++;
  }
  set<ll> s;
  ll p = 0;
  for (ll i = 0; i < N-1; i++) {
    if (a[i] == i+1 && a[i+1] == i+2 && !s.count(i) && !s.count(i+1)) {
      s.insert(i); s.insert(i+1);
      p++;
    }
  }
  cout << same-p << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;


int main()
{
    ll N,D;
    cin >> N >> D;
    int ans=0;
    for(int i=0; i<N; i++){
        ll x,y;
        cin >> x >> y;
        ll dis=x*x+y*y;
        if(dis<=D*D) ans++;
    }
    cout << ans << endl;




    return 0;
}

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

main(){
	int n; cin>>n;
	int cnt=0, ans;
	while(n--){
		int a,b; cin>>a>>b;
		if(a==b){
			cnt++;
		}
		else{
			ans = max(ans,cnt);
			cnt=0;
		}
	}
	ans = max(ans,cnt);
	if(ans>=3) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3608
/*input
10 4 8
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n,x,y;
	cin>>n>>x>>y;
	ll ans[n]={0};
	rep(i,1,n+1){
		rep(j,i+1,n+1){
			if((i<=x&&j>x&&j<y)){
				ans[(ll)min(j-i,y-j+1+x-i)]++;
			}
			else if((j>=y&&i>x&&i<y)){
				ans[(ll)min(j-i,j-y+1+i-x)]++;
			}
			else if(j<y&&i>x){
				ans[(ll)min(j-i,y-j+1+i-x)]++;
			}
			else if(i<=x&&j>=y){
				ans[j-y+1+x-i]++;
			}else{
				ans[j-i]++;
			}
		}
	}
	rep(i,1,n)cout<<ans[i]<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,m;
  string ans="No";
  cin >> n >> m;
  vector<string> a(n),b(m);
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=0;i<m;i++) cin >> b[i];
  for(long si=0;si<=n-m;si++) {
    for(long sj=0;sj<=n-m;sj++) {
      bool y=true;
      for(long i=0;i<m;i++) for(long j=0;j<m;j++) if(a[si+i][sj+j]!=b[i][j]) y=false;
      if(y) {
        ans="Yes";
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
	int x,y;
	while(1)
	{
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)
		break;
		if(x>=y)
		printf("%d %d\n", y, x);
		else if(x<y)
		printf("%d %d\n", x, y);
	}
	return 0;
}


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

#define MAX 100005

struct Item{
    long long w;
    int v;
}item[105];

long long N, W;
long long dp[105][MAX];
int m;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>N>>W;
    for(int i=0; i<N; i++){
        cin>>item[i].w>>item[i].v;
        if(item[i].w<=W){
                dp[i+1][item[i].v] = item[i].w;
                m = max(m, item[i].v);
        }
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<=MAX; j++){
            if(!dp[i][j])continue;

            m = max(m, j);
            if(!dp[i+1][j]) dp[i+1][j]=dp[i][j];
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);

            if(dp[i][j]+item[i].w>W)continue;

            m = max(m, j+item[i].v);
            if(!dp[i+1][j+item[i].v]){
                dp[i+1][j+item[i].v]=item[i].w+dp[i][j];
                continue;
            }
            dp[i+1][j+item[i].v] = min(dp[i+1][j+item[i].v], dp[i][j]+item[i].w);

        }
    }
    /*for(int i=0; i<=N; i++){
        for(int j=0; j<=30; j++)
            cout<<dp[i][j]<<" ";
        cout<<"\n";
    }*/
    cout<<m<<"\n";
    return 0;
}



Measured memory_bytes: 35332
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
struct product{
    int a,b,c;
};

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


int main(void){
    // Here your code !
    while(1){
        
        int items[301];vector<product> tests_ok,tests_ng;
        rep(i,301){
            items[i]=2;
        }
        int a,b,c;
        set<int> tmp;
        scanf("%d %d %d", &a,&b, &c);
        if(!a&&!b&&!c)return 0;
        int n;
        scanf("%d", &n);
        rep(i,n){
            int m,n,o,p;
            scanf("%d %d %d %d", &m, &n,&o,&p);
            if(p){
                tests_ok.push_back(product{m,n,o});
                tmp.insert(m);
                tmp.insert(n);
                tmp.insert(o);
            }else{
                tests_ng.push_back(product{m,n,o});
            }
        }
        for(auto i=tests_ok.begin(); i!=tests_ok.end(); ++i){
            items[i->a]=1;
            items[i->b]=1;
            items[i->c]=1;
        }
        for(auto i=tests_ng.begin(); i!=tests_ng.end(); ++i){
            bool A = items[i->a]==1;
            bool B = items[i->b]==1;
            bool C = items[i->c]==1;
            if(A&&B)items[i->c]=0;
            if(B&&C)items[i->a]=0;
            if(C&&A)items[i->b]=0;
        }
        rep(i,a+b+c+1){
            if(i==0)continue;
            printf("%d\n",items[i]);
            //if(items[i]==1)cout<<i<<"\t";
        }
        //cout<<"END"<<endl;
    //cout<<endl;
    //for(auto i=tmp.begin(); i!=tmp.end(); ++i)cout<<*i<<"\t";
    }
}


Measured memory_bytes: 3176
n = int(input())

g = [[-1] * 15 for _ in range(15)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        g[i][x] = y
ans = 0
for i in range(1 << n):
    d = [0] * n
    for j in range(n):
        if i >> j & 1:
            d[j] = 1

    cnt = 0
    ok = 1
    for j in range(n):
        if d[j]:
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = 0

    if ok:
        ans = max(ans, sum(d))
print(ans)


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

int main() { /* ここに書く */

  long long X,t,f,Ans;
  cin >> X;
  t = 0;
  f = 0;
  Ans = 0;
  
  t = X/500;
  X = X - (t*500);
  t = t*1000;
  f = X/5;
  f = f*5;
  
  Ans = t + f;
  
  cout << Ans <<endl;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
        k: usize1
    }
    let c1 = s.iter().take_while(|x| **x == '1').count();
    if k < c1 {
        println!("1");
    } else {
        println!("{}", s[c1]);
    }
}


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

int main(){
    int n,d;
    int i,j,k;
    int ans=0;
    cin >> n >> d;
    vector <vector<int>> x(n,vector<int>(d));
    
    rep(i,n){
    rep(j,d){
        cin >> x[i][j];
    }
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            int sum=0;
            bool tf=false;
            for(k=0;k<d;k++){
                int a=abs(x[i][k]-x[j][k]);
                sum+=a*a;
            }
            for(k=0;k<=sum;k++){
                if(k*k==sum) {
                    tf=true;
                }
            }
            if(tf) ans++;
        }
    }

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

Measured memory_bytes: 256