akhauriyash/Code-Regression huggingface dataset:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    R = INT()
    print(2*pi*R)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10044
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////
int main(){
    int n;
    ll X;
    cin >> n >> X;
    vector<ll> x(n);
    ll GCD;
    for (int i = 0;i < n;i++){
        cin >> x[i];
        if (i == 0) GCD = abs(X - x[i]);
        else {
            GCD = gcd(GCD,abs(x[i]-x[i-1]));
        }
    }
    cout << GCD << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  long N,sum=0;
  cin>>N;
  for(int i=1;i<=N;i++){
  	if(i%5!=0 && i%3!=0){
    	sum+=i;
  	}
  }
    cout<<sum;
}


Measured memory_bytes: 3632
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

left = 0
right = n - p -1

while right - left >=0:
    mid = (left + right) // 2
    if a[mid] + m < a[n - p]:
        left = mid + 1
    else:
        j = v - (mid + 1 + p - 1)
        if j <= 0:
            right = mid-1
        else:
            sum = 0
            for k in range(mid + 1, n - p + 1, 1):
                if m + a[mid] - a[k] < 0:
                    left = mid + 1
                    break
                sum += a[mid] + m - a[k]
                if sum >= j * m:
                    right = mid-1
                    break
                if k == n - p:
                    left = mid + 1

print(n-left)

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

using namespace std;

int solve(const string& s)
{
    int ones = 0, zeroes = 0;

    for (const auto c : s)
    {
        ones += (c == '1' ? 1 : 0);
        zeroes += (c == '0' ? 1 : 0);
    }

    auto ans = min(ones, zeroes) * 2;

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    auto ans = solve(s);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 512
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])


Measured memory_bytes: 111852
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[])=>{for(let i=0;i<a.length;i+=2)if(s==a[i])return a[i+1]};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};
const main = ()=>{
  let [...a]= desc(nrin(3));
  out(Number(''+a[0]+a[1])+a[2]);
}
main();

Measured memory_bytes: 11468
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define int long long
#define pb push_back
#define ppb pop_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define cfM 998244353
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define inf 10000000000000000
#define sp setprecision(9)
float pi=3.14159265;
int max(int b,int a)
{if(b>a)return b;else return a;}
int min(int b,int a)
{if(b<a)return b;else return a;}
int ab(int b)
{if(b<0) return (-1*b);else return(b);}
void print(vector<int>&v)
{
	fr(i,v.size())
	cout<<v[i]<<" ";
	cout<<endl;
}
void print(int arr[],int n)
{
	for(int i=0;i<n;i++)
		cout<<arr[i]<<" ";}
int32_t main()
{
	int n,m;
	cin>>n>>m;
	priority_queue<int> pq;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		pq.push(a);
	}while(m--)
	{
		int a=pq.top();
		a/=2;
		pq.push(a);
		pq.pop();
	}
	int sum=0;
	while(!pq.empty()){sum+=pq.top();pq.pop();}
	cout<<sum<<endl;


}

Measured memory_bytes: 1400
#include <cstdio>
#include <map>
#include <stack>
using namespace std;

typedef long long LL;
LL ans[100005];

int main() {
  int N, Q;
  stack<LL> s;
  scanf("%d%d", &N, &Q);
  s.push(N);
  for(int i=0;i<Q;i++) {
    LL x;
    scanf("%lld", &x);
    while (!s.empty() && x <= s.top()) s.pop();
    s.push(x);
  }
  
  map<LL, LL> rem;
  rem[s.top()] = 1; s.pop();
  while (s.size() > 0) {
    LL q = s.top(); s.pop();
    while (!rem.empty()) {
      auto it = rem.end();
      if((--it)->first <= q) break;
      LL v = it->first;
      LL p = it->second;
      rem.erase(it);
      rem[q] += (v / q) * p;
      if (v%q>0) rem[v%q] += p;
    }
  }
  
  for (auto &&it : rem)
    ans[it.first] += it.second;
  for (int i = N; i >= 1; i--) ans[i] += ans[i+1];
  for (int i = 1; i <= N; i++) printf("%lld\n", ans[i]);
  return 0;
}


Measured memory_bytes: 8704
N,L=map(int,input().split())

R=[0]*N

for kai in range(N):
    R[kai]=L+kai


kotoae=0
kotae=0
if(R[0]>0):
    for kai1 in range(N):
        kotoae=kotoae+R[kai1]
    print(kotoae-R[0])
elif(R[N-1]<0):
    for kai1 in range(N):
        kotae=kotae+R[kai1]
    print(kotae-R[N-1])
else:
    for kai in range(N):
        kotae=kotae+R[kai]
    print(kotae)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (998244353LL)

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int, int>> P(N);
    for (int n = 0; n < N; ++n) {
        int x, y;
        cin >> x >> y;
        P[n] = {x, y};
    }
    sort(P.begin(), P.end());
    vector<int> Ind(N);
    iota(Ind.begin(), Ind.end(), 1);
    sort(Ind.begin(), Ind.end(), [&](int l, int r){return P[l-1].second < P[r-1].second;});
    
    vector<vector<int>> A(4, vector<int>(N));
    vector<int> BIT(N+1);
    auto Add = [&](int n) {
        while (n <= N) {
            ++BIT[n];
            n += n&-n;
        }
    };
    auto Sum = [&](int n) {
        int s = 0;
        while (n > 0) {
            s += BIT[n];
            n -= n&-n;
        }
        return s;
    };
    for (int n = 0; n < N; ++n) {
        int nSum = Sum(Ind[n]);
        A[0][n] = n-nSum;
        A[1][n] = nSum;
        Add(Ind[n]);
    }
    BIT.assign(N+1, 0);
    for (int n = N-1; n >= 0; --n) {
        int nSum = Sum(Ind[n]);
        A[2][n] = nSum;
        A[3][n] = (N-1-n)-nSum;
        Add(Ind[n]);
    }
    
    vector<ll> Pow2(N+1);
    Pow2[0] = 1;
    for (int n = 1; n <= N; ++n) Pow2[n] = (Pow2[n-1]<<1) % MOD;
    ll Res = 0;
    for (int n = 0; n < N; ++n) {
        ll Tmp = Pow2[N] - 1;
        for (int k = 0; k < 4; ++k) {
            Tmp = (Tmp - Pow2[A[k][n]+A[(k+1)%4][n]]) % MOD;
            Tmp = (Tmp + Pow2[A[k][n]]) % MOD;
        }
        Res = (Res + Tmp) % MOD;
    }
    cout << (Res + MOD) % MOD << endl;

    return 0;
}


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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 (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;

inline int divCeil(int a, int b){
    return (a+b-1)/b;
}
int main(){
    int n,k;
    cin >> n >> k;
    int one; //1のindex
    rep(i,n){
        int x;
        cin >> x;
        if(x==1){
            one = i;
            break;
        }
    }
    int ans = divCeil(n-1,k-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int r=sc.nextInt();
		if(r<1200)
		{
			System.out.println("ABC");
		}
		else if(r<2800)
		{
			System.out.println("ARC");
		}
		else
		{
			System.out.println("AGC");
		}

	}

}

Measured memory_bytes: 21588
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    double a,b,h,m,ar,br,distr,ans;
    cin>>a>>b>>h>>m;
    ar=(h*60+m)/720*360;
    br=m/60*360;
    
    distr=min(ar-br,br-ar);
    
    ans=a*a+b*b-2*a*b*cos(distr*2.0*asin(1.0)/180.0);
    printf("%.16lf\n",sqrt(ans));
    return 0;
}


Measured memory_bytes: 4192
#include <stdio.h>
#include <stdlib.h>

int fibonacci(int);

int arr[45];
int main(){
  int n,i;
  scanf("%d",&n);
  if(n>44)exit(2);
  for(i=0;i<=n;i++) arr[i] = 0;
  printf("%d\n",fibonacci(n));
  return 0;
}

int fibonacci(int n){
  if(arr[n] != 0) return arr[n];
  if(n == 0 || n == 1) return arr[n] = 1;
  else return arr[n] = fibonacci(n-1)+fibonacci(n-2);
}



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

int main() {
    ll N, A, B; cin >> N >> A >> B;
    vector<ll> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];

    ll ans = 0;
    for (int i = 0; i < N-1; i++)
    {
        ans += min((v[i+1] - v[i])*A, B);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;

ll A, B, N;
void input(){
	cin>>N>>A>>B;
	ll d = abs(A-B);
	if(d % 2 == 0) cout<< d/2;
	else{
      	ll k = min(A, B);
      	ll l = max(A, B);
		ll s = l - 1;
        ll p = (k + l - 1)/2;
        s = min(s, p);
		ll t = N - min(A, B);
      	ll q = (2 * N - k - l + 1)/2;
        t = min(t, q);
		cout<<min(s, t);
	}

}

void solve(){

}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 256
// Example program
#include <iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
vector<int> v;
int a;
int b;
int c;
cin>>a;
cin>>b;
cin>>c;

v.push_back(a);
v.push_back(b);
v.push_back(c);

sort(v.begin(),v.end());

cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;


 
}

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

int main(){

    int a;
    char buf[30];


    fgets(buf, sizeof(buf), stdin);

    a = atoi(buf);
    if ((a<=10) & (a>=1)){
        a = a+pow(a,2)+pow(a,3);
        printf("%d\n", a);
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

 ll n,m;
 cin>>n>>m;
 n--;
 m--;
 cout<<(n*(n+1))/2+(m*(m+1))/2<<endl;
return 0;
}



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

using namespace std;
template<class T>using vv = vector<vector<T>>;

#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0;i<(n);++i)

template<int MOD> struct MInt {
  long long val;
  MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator-() const { return MInt(-val); }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt operator/(const MInt& n) const { return MInt(val) /= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  MInt& operator/=(const MInt& n) { val = (*this * n.inv()).val; return *this; }
  bool operator==(const MInt& n) { return val == n.val; }
  bool operator!=(const MInt& n) { return val != n.val; }
  MInt inv() const {
    MInt pow = val, ans = 1;
    for (int p = MOD - 2; p > 0; p >>= 1) { if (p & 1) ans *= pow; pow *= pow; }
    return ans;
  }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
  friend istream& operator>>(istream& os, MInt& n) { os>>n.val; return os; }
};
const int MOD = 1e9+7;
using mint = MInt<MOD>;

struct Graph {
  vector<vector<int>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) { edge.resize(n, vector<int>()); }
  void addEdge(int from, int to) { edge[from].push_back(to); }
};
Graph G;

vv<mint> dp;
mint dfs(int s, int parent, bool filled) {
  // filledがtrueならsは黒で塗られている
  mint ans = 1;
  if (dp[s][filled] != 0)
    return dp[s][filled];

  for (const auto& to : G.edge[s]) {
    if (to == parent)
      continue;
    if (filled) ans *= dfs(to, s, false);
    else ans *= dfs(to, s, true) + dfs(to, s, false);
  }
  return dp[s][filled] = ans;
}
int main() {
  int in(N);

  G.resize(N);
  dp.resize(N, vector<mint>(2, 0));
  rep(i, N-1) {
    int in(a); int in(b);
    --a, --b;
    G.addEdge(a, b); G.addEdge(b, a);
  }

  cout << dfs(0, -1, true) + dfs(0, -1, false) << endl;
  return 0;
}


Measured memory_bytes: 19584
/*
auhtor:hbohra98
chandigarh univeristy
*/
#include<bits/stdc++.h>
#define ll long int
#define pb push_back
#define VP vector < pair < ll , ll > >
#define VI vector< ll >
#define VS vector< string >
#define mk make_pair

using namespace std;
int main(){

ll n,c=0;
cin>>n;
VI a,b;
for(ll i=0;i<n;i++){ll io;cin>>io;a.pb(io);}
bool bo=true;
ll max=a[n-1];
for(ll i=n-2;i>=0;i--){
  if(a[i]<max){max=a[i];continue;}
 if(a[i]>max)a[i]-=1;
 if(a[i]!=max){bo=false;break;}
}
if(bo)cout<<"Yes";
else cout<<"No";
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X;
	if(X>=30) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A = N % 1000;
  int B = N / 10;
  if (A % 111 == 0 || B % 111 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
	int n;int a[1000];int sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++) {
		if(a[i]!=i){
			sum++;
		}
	}
	if(sum>2)cout<<"NO";
	else cout<<"YES";
	return 0;
}

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

const int NUM = 15;

int main() {
	int a, b;
	std::cin >> a >> b;

	std::string result = "";

	if(a + b == NUM) {
		result = "+";
	} else if(a * b == NUM) {
		result = "*";
	} else {
		result = "x";
	}

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.toCharArray()
    val t = readLine()!!.toCharArray()

    for (i in 0..n) {
        var flg = true
        for (j in 0..n - i) {
            if (i + j >= n) break
            if (s[i + j] != t[j]) flg = false
        }
        if (flg) {
            println(n + i)
            return
        }
    }
}


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

int B[100000];

void Main()
{
  int N;
  cin >> N;
  rep(i, N-1) {
    cin >> B[i];
  }
  
  int sum = 0;
  rep(i,N) {
    if (i==0) sum += B[0];
    else if (i==N-1) sum += B[N-2];
    else sum += min(B[i-1],B[i]);
  }
  cout << sum << endl;
  return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
  return 0;
}

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

using namespace std;

decltype(0) main () {
  int n; cin >> n;
  vector<pair<int,int>> t (n);
  for (int i=0; i<n; i++) {
    cin >> t[i].first;
    t[i].second = i+1;
  }
  sort(t.begin(), t.end());
  for (auto &i : t) {
    cout << i.second << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i;
    cin>>n;
    ll a[n],b[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
        b[i]=min(b[i-1]+abs(a[i-1]-a[i]),b[i-2]+abs(a[i-2]-a[i]));
    cout<<b[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())

N = N % K

if (N == 0):
    print(N)
elif (N == K):
    print(0)
elif (K == 1):
    print(0)
else:
    while (N >= 0):
        if (N > abs(N - K)):
            N = abs(N - K)
        else:
            print(N)
            break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
int n, a[maxn], len[maxn], g[maxn];
ll k;
int od[maxn];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	for (int i = 1;i <= n;++i)
		cin >> a[i];
	int now = 1, t = 1;
	while (k--) {
		od[now] = t++;
		now = a[now];
		if (od[now]) 
			k %= (t - od[now]);
	}
	cout << now << '\n';


			
}



Measured memory_bytes: 5184
/*
    線形探索
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_A
*/
#include <bits/stdc++.h>
using namespace std;

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

    int n;
    cin >> n;
    int s[100001];
    int t[100001];

    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> t[i];
    }

    int count = 0;
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (t[i] == s[j]) {
                count++;
                break;
            }
        }
    }

    cout << count << endl;
}


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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int dp[41][401][401];
int a[40], b[40], c[40];
int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	fill((int*)dp, (int*)(dp + 41), 1 << 30);
	dp[0][0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 10 * i; j++) {
			for (int k = 0; k <= 10 * i; k++) {
				if (dp[i][j][k] == 1 << 30) continue;
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
			}
		}
	}
	int ans = 1 << 30;
	for (int i = 1; i <= 10 * N; i++) for (int j = 1; j <= 10 * N; j++) {
		if (i*Mb == j * Ma) ans = min(ans, dp[N][i][j]);
	}
	if (ans == 1 << 30) cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 25984
from bisect import bisect_left

n = int(input())
A = list(int(x) for x in input().split())
m = max(A)
A.remove(m)
A.sort()
index = bisect_left(A, m//2)
tmp = 10**18
ans = -1
for a in A[index-1:index+2]:
    if abs(a - m/2) < tmp:
        tmp = abs(a - m/2)
        ans = a
print(m, ans)

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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  ll a[n],b[n];
  for(i=0;i<n;i++)cin>>a[i]>>b[i];
  ll ma=0;
  for(i=0;i<n;i++){
    if(ma<a[i]){
      ma=a[i];
      cnt=i;
    }
  }
  cout<<a[cnt]+b[cnt];
}

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

using ll = long long;
using namespace std;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    for (int i = 0; i < h; i++) {
        for (int k = 0; k < w; k++) {
            cout << int((i < b && k < a) || (i >= b && k >= a));
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

string s;
LL ans = 0;

void dfs(int mask, int n){
    if(s.size() <= n+1){
        int sum = 0;
        int cnt = s[0] - '0';
        FOR(i, 1, s.size()){
            if(mask & (1 << (i-1))){
                sum += cnt;
                cnt = (int)(s[i] - '0');
            }else{
                cnt *= 10;
                cnt += (int)(s[i] - '0');
            }
        }
        ans += sum + cnt;
        return;
    }
    dfs(mask ^ (1 << n), n+1);
    dfs(mask, n+1);
    return;
}

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

    cin >> s;
    dfs(0, 0);
    cout << ans << endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import math
import numpy as np

n = int(input())
ans = np.inf
for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
        q = n//i
        tmp = i+q 
        if tmp <= ans:
            ans = tmp 
            i_ = i 
            q_ = q 

print(ans-2)


Measured memory_bytes: 14412
from bisect import bisect_left,bisect_right
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        bc=l[i]+l[j]
        idx=bisect_left(l,bc)
        ans+=idx-j-1
print(ans)





Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	int p[n];
	int one = 0,two=0,three=0;
	for(int i = 0; i < n; i++){
		cin >>p[i];
		if(p[i]<=a)one++;
		else if(p[i]<=b)two++;
		else three++;
	}
	cout << min(one, min(two,three)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define DEBUG_VEC2(v) rep(i,v.size())cout<<#v<<":"<<v[i]<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<int,int>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void yes(bool c) { if (c)print("Yes"); else print("No"); };

void solve() {
    int N; cin >> N;
    // vi a(N-1),b(N-1);
    vector<vi> to(N);
    vector<pi> order;
    int a,b;
    rep(i,N-1){
        // cin >> a[i] >> b[i];
        cin >> a >> b;
        a--;b--;
        to[a].pb(b);
        to[b].pb(a);
        order.pb(mp(a,b));
    }
    int k = 0;
    vi visited(N,0);
    vi last(N,0);

    // vector<vi> colors(N, vi(N,0));
    map<pi,int> colors;
    queue<int> q;
    q.push(0);
    visited[0] = 1;
    while(!q.empty()){
        int root = q.front();
        // DEBUG(root);
        q.pop();
        k = max(k,(int)to[root].size());
        // DEBUG(k);
        int color = 1;
        for(int leaf : to[root]){
            // DEBUG(leaf);
            if(visited[leaf]) continue;
            if(color==last[root]) color++;
            // colors[root][leaf] = color;
            // colors[leaf][root] = color;
            colors[mp(root,leaf)] = color;
            last[leaf] = color;
            color++;
            visited[leaf] = 1;
            q.push(leaf);
        }
    }
    print(k);
    rep(i,N-1){
        // print(colors[order[i].fi][order[i].sc]);
        print(colors[order[i]]);
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 13816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e8+8;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin>>n;
	double ans = 0;
	while(n--)
	{
		double d;
		string s;
		cin>>d>>s;
		if(s=="JPY")
			ans += d;
		else
			ans += 380000*d;
	}
	cout<<fixed<<setprecision(9)<<ans;
    return 0;
}

Measured memory_bytes: 256
#組込み関数頼み
import heapq
H=[]

while True:
    cmmd = input().split()
    if cmmd[0] == "insert":
        heapq.heappush(H,-int(cmmd[1]))
        #print(H)
    elif cmmd[0] == "extract":
        ext = heapq.heappop(H)
        print(-ext)
    else:
        break



Measured memory_bytes: 45316
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;

class Node {
public:
    vector<pair<int, int> > tos;
    int c;
    bool d;

    friend bool operator< (const Node &n1, const Node &n2) {
        return n1.c > n2.c;
    }
};

int n;
vector<Node> ns;

int dijkstra(int s, int t) {
    for (int i = 0; i < n; i++) {
        ns[i].c = -1;
        ns[i].d = false;
    }
    priority_queue<Node> q;
    ns[s].c = 0;
    q.push(ns[s]);
    while (!q.empty()) {
        Node node = q.top(); q.pop();
        if (node.d) {
            continue;
        }
        node.d = true;
        for (vector<pair<int, int> >::iterator it = node.tos.begin(); it != node.tos.end(); it++) {
            int to = it->first;
            int c = node.c + it->second;
            if (ns[to].c < 0 || c < ns[to].c) {
                ns[to].c = c;
                q.push(ns[to]);
            }
        }
    }
    return ns[t].c;
}

int main() {
    int m;
    while (cin >> n >> m, n|m) {
        string s, p, g;
        cin >> s >> p >> g;
        map<string, int> st;
        st[s] = 0;
        st[p] = 1;
        st[g] = 2;
        ns.clear();
        ns.resize(n);
        for (int i = 0, idx = 3; i < m; i++) {
            string a, b;
            int d, t;
            cin >> a >> b >> d >> t;
            if (st.find(a) == st.end()) {
                st[a] = idx++;
            }
            if (st.find(b) == st.end()) {
                st[b] = idx++;
            }
            int a_i = st[a];
            int b_i = st[b];
            int c = d / 40 + t;
            ns[a_i].tos.push_back(make_pair(b_i, c));
            ns[b_i].tos.push_back(make_pair(a_i, c));
        }
        cout << dijkstra(st[s], st[p]) + dijkstra(st[p], st[g]) << endl;
    }
}

Measured memory_bytes: 1748
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		String s = sc1.next();

		int l = s.length();

		int ansA = 0;
		int ansB = 0;

		//System.out.println(s);
		//System.out.println(ansstrA);
		//System.out.println(ansstrB);



		for ( int i = 0 ; i < l ; i++ ) {
			if (s.charAt(i) == Integer.toString(i % 2).charAt(0)) {
				ansB++;
			}
			else {
				ansA++;
			}
		}

		if ( ansA > ansB ) {
			System.out.println(ansB);
		}
		else {
			System.out.println(ansA);
		}

		sc1.close();

	}

}

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

using namespace std;

#define ll long long

int n;
string s;

void solve() {
  cin >> n >> s;
  for (int i = 0; i < s.length(); i++) {
    if ((s[i]+n) > 'Z') {
      s[i] = s[i]+(n-26);
    } else {
      s[i] = s[i]+n;
    }
  }
  cout << s << '\n';
}

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n, R[200000], max, min;
	cin >> n;
	for (int i = 0;i < n;i++)
		cin >> R[i];
	min = R[0];
	max = R[1] - R[0];
	for (int i = 1;i < n-1;i++) {
		if (R[i]<min) { min = R[i]; }
		if (R[i + 1] - min>max) {max = R[i + 1] - min;}
	}
	cout << max << endl;
}

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

int main()
{
  long a, b, x;
  cin >> a >> b >> x;
  
  long ax, bx;
  if (a == 0)
    ax = 0;
  else
    ax = (a - 1) / x + 1;
  
  bx = b / x + 1;
  
  cout << bx - ax << endl;
  return 0;
}

Measured memory_bytes: 256
Sa = list(input())
Sb = list(input())
Sc = list(input())

now = Sa.pop(0)
ans = ""

while True:
    if now == "a":
        if not Sa:
            ans = "A"
            break
        now = Sa.pop(0)
    elif now == "b":
        if not Sb:
            ans = "B"
            break
        now = Sb.pop(0)
    else:
        if not Sc:
            ans = "C"
            break
        now = Sc.pop(0)
print(ans)

Measured memory_bytes: 3064
import itertools

N, K = map(int, input().split()) # Nは建物の数、K色以上に塗る
A = list(map(int, input().split()))
N_index = list(range(1,N)) # 一番左は固定なので

min_cost = float('inf')
for target_indexes in itertools.combinations(N_index, K-1): # N_indexからK-1個選ぶ方法を全通り試す
    cost = 0
    copy_A = A.copy()
    for i in target_indexes:
        if copy_A[i] <= max(copy_A[:i]):
            diff = max(copy_A[:i]) - copy_A[i] # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする
            copy_A[i] += diff + 1
            cost += diff + 1

    min_cost = min(min_cost, cost)

print(min_cost)


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

int main()
{
    string s;
    cin >> s;
    ll a[s.size()]={0},i=0;
    while(i<s.size()){
        int r = 0, l = 0;
        int rp, lp;
        while(s[i]=='R'){r++; i++;}
        if(s[i]=='L'){lp = i; rp = lp-1;}
        while(s[i]=='L'){l++; i++;}
        a[rp] += (r+1)/2;
        a[lp] += r/2;
        a[lp] += (l+1)/2;
        a[rp] += l/2;
    }
    rep(i, s.size()) cout << a[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 4552
#include <bits/stdc++.h>
using namespace std;
long long a[200005],b[200005];
long long s1,s2;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n;i++)
	{
		s1+=a[i];
		s2+=b[i];
	}
	if(s1<s2)
	{
		cout<<"-1";
		return 0;
	}
	long long x=0,cnt=0;
	vector<long long>v;
	for(int i=0;i<n;i++)
	{
		if(a[i]<b[i])
		{
			x+=b[i]-a[i];
			cnt++;
		}
		else
			v.push_back(a[i]-b[i]);
	}
	sort(v.begin(),v.end(),greater<long long>());
	for(int i=0;i<v.size();i++)
	{
		if(x>0)
		{
			x-=v[i];
			cnt++;
		}
	}
	cout<<cnt;

	return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAXN = 100010;

struct Op{
  int t, vr, s, col;

  bool operator<(const Op& w) const{
    return mp(mp(t, vr), mp(s, col)) <
           mp(mp(w.t, w.vr), mp(w.s, w.col));
  }
};

int n, m, q;
vi fo[MAXN];
int col[MAXN], done[MAXN];

set<Op> ops;
vector<Op> exec[MAXN];
void AddOp(int t, int vr, int s, int col){
  if(done[vr] >= s) return;

  Op op{t, vr, s, col};

  while(!exec[vr].empty() &&
        exec[vr].back().s <= op.s){
    ops.erase(exec[vr].back());
    exec[vr].pop_back();
  }

  if(!exec[vr].empty() && exec[vr].back().t == op.t)
    return;

  ops.insert(op);
  exec[vr].pb(op);
}

int main(){
  memset(done, -1, sizeof done);

  scanf("%d%d", &n, &m);
  for(int i = 0;i < m;++i){
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    fo[a].pb(b), fo[b].pb(a);
  }

  scanf("%d", &q);
  for(int i = 0;i < q;++i){
    int v, d, c;
    scanf("%d%d%d", &v, &d, &c);
    --v;
    AddOp(i, v, d, c);
  }

  while(!ops.empty()){
    auto op = *ops.rbegin();
    ops.erase(op);
    exec[op.vr].pop_back();
    relaxMax(done[op.vr], op.s);
    if(!col[op.vr]) col[op.vr] = op.col;
    if(op.s > 0)
      for(int nxt : fo[op.vr])
        AddOp(op.t, nxt, op.s - 1, op.col);
  }

  for(int i = 0;i < n;++i)
    printf("%d\n", col[i]);

  return 0;
}


Measured memory_bytes: 22776
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}   

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		int i = 0;
		while(0 < 1){
			i++ ;
			int a = sc.nextInt();
			if(a == 0) break;
			else System.out.printf("Case %d: %d\n",i,a);
		}
		sc.close();
	}	
}


Measured memory_bytes: 67500
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
3 3
..#
#..
...
---+/
/+---test
10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................
---+/

void main(string[] args) {
  long H, W;
  readf(" %d %d ", &H, &W);

  auto M = new bool[][](H);
  foreach (ref m; M) {
    m = readln.chomp.map!(c => c == '.').array;
  }

  struct Point { long x, y, dep; }
  DList!Point q;
  q.insertBack(Point(0, 0, 1));

  auto visited = new bool[][](H, W);

  long wh = -1;
  while (!q.empty) {
    const pt = q.front;
    q.removeFront;

    if (pt.x < 0 || pt.y < 0 || pt.x >= W || pt.y >= H) continue;
    if (!M[pt.y][pt.x]) continue;
    if (visited[pt.y][pt.x]) continue;
    visited[pt.y][pt.x] = true;

    if (pt.x == W-1 && pt.y == H-1) {
      wh = pt.dep;
      break;
    }

    q.insertBack(Point(pt.x+1, pt.y, pt.dep+1));
    q.insertBack(Point(pt.x-1, pt.y, pt.dep+1));
    q.insertBack(Point(pt.x, pt.y+1, pt.dep+1));
    q.insertBack(Point(pt.x, pt.y-1, pt.dep+1));
  }

  if (wh == -1) {
    "-1".writeln;
  } else {
    (M.map!(x => x.count(true)).sum - wh).writeln;
  }
}


Measured memory_bytes: 892
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    String str=sc.next();
    char[] c=str.toCharArray();
    int W[]=new int[n+1];
    int E[]=new int[n+1];
    int min=3*100000;

    for(int i=0;i<=n;i++){
      W[i]=0;
      E[i]=0;
    }


    for(int i=0;i<n;i++){
      W[i+1]=W[i];
      if(c[i]=='W') W[i+1]++;
      E[i+1]=E[i];
      if(c[i]=='E') E[i+1]++;
    }

    for(int i=0;i<n;i++){
      int count=W[i]+E[n]-E[i+1];
      min=Math.min(min,count);
    }


    System.out.println(min);
  }
}


Measured memory_bytes: 30764
R,G,B,N = map(int,input().split())

ans = 0
for r in range(3010):
  red = r * R
  if N < red:
    break
  
  for g in range(3010):
    green = g * G
    blue = N - red - green
    if blue < 0:
      break
    if blue % B == 0:
      ans += 1
      
print(ans)


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

int main(){
	vector<string> s(3);
	char cur;
	vector<char> ans={'a','b','c'};
	cin >> s[0] >> s[1] >> s[2];
	int i;
	for(i=0; i<3; i++){
		reverse(s[i].begin(),s[i].end());
	}
	i=0;
	while(true){
		if(s[i]==""){
			cout << char(ans[i]-32); return 0;
		}else{
			cur=s[i][s[i].size()-1];
			s[i].pop_back();
			i=cur-'a';
		}
	}
}

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

#define INF (1<<29)
 
using namespace std;
 
int main(void){
  
  int n,m,p,a,b,x,y,z,in;
  double dp[(1<<8)][31],graph[31][31];
  vector<int>t;
  
  while(cin >> n >> m >> p >> a >> b){
    if(!(n|m|p|a|b))break;
    
    t.clear();
    
    fill(graph[0],graph[31],-1);
    fill(dp[0],dp[(1<<8)],INF);

    for(int i=0;i<n;i++){
      cin >> in;
      t.push_back(in);
    }
    
    for(int i=0;i<p;i++){
      cin >> x >> y >> z;
      graph[x][y]=graph[y][x]=z;
    }
    
    dp[0][a]=0;
    double res=INF;
    for(int S=0;S<(1<<8);S++){
      res=min(res,dp[S][b]);
      for(int v=1;v<=m;v++){
	for(int i=0;i<n;i++){
	  if(!(S>>i & 1)){
	    for(int u=1;u<=m;u++){
	      if(graph[v][u]<0)continue;
		dp[S|(1<<i)][u]=min(dp[S|(1<<i)][u],dp[S][v]+graph[v][u]/t[i]);
	    }
	  }
	}
      }
    }
    if(res==INF)printf("Impossible\n");
    else printf("%.3f\n",res);
  }
  
  return 0;
}

Measured memory_bytes: 1308
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    Int N, K; cin >> N >> K;
    vector<Int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<Int> tentou_rep(N);
    vector<Int> tentou(N);

    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (A[i] > A[j]) tentou[i]++;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            if (A[i] > A[j]) tentou_rep[i]++;
        }
    }

    Int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (tentou[i] * K) % MOD;
        ans %= MOD;
        ans += (tentou_rep[i] * ((((K-1)*K)/2) % MOD) % MOD);
        ans %= MOD;
    }
    cout << ans << endl;

}

Measured memory_bytes: 888
//agc041_a.cpp
//Sun Mar  1 11:23:10 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll n,a,b;
	cin >> n >> a >> b;

	if (abs(b-a)%2==0){
		cout << abs(b-a)/2 << endl;
	}else {
		ll goone = (max(a,b)-min(a,b)-1)/2+min(a,b);
		ll golast = ((n-min(a,b))-(n-max(a,b)+1))/2+(n-max(a,b)+1);
		cout << min(goone,golast) << endl;
	}
}

Measured memory_bytes: 256
s = input()

ans1 = 0
ans2 = 0
for i, title in enumerate(s):
    if i % 2 == 0 and title != "0":
        ans1 += 1
    if i % 2 == 1 and title != "1":
        ans1 += 1
    if i % 2 == 1 and title != "0":
        ans2 += 1
    if i % 2 == 0 and title != "1":
        ans2 += 1

print(min(ans1, ans2))



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

int main(){
    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }
    else if(a >= 6){
        cout << b / 2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val s = next().toCharArray().sorted()
    val t = next().toCharArray().sortedDescending()
    println(if (s.joinToString("") < t.joinToString("")) "Yes" else "No")
}

Measured memory_bytes: 35864
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll H, N;
  cin >> H >> N;
  ll A, tot = 0;
  rep(i, N){
    cin >> A;

    tot += A;
  }

  if(H <= tot)
    cout << "Yes\n";
  else
    cout << "No\n";
    
  return 0;
}


Measured memory_bytes: 3688