akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n = 5;
  vector<int> v(n);
  
  for(int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  
  int sum = 0;
  for(int i = 0; i < n; i++){
    sum += (v.at(i) + 9) / 10 * 10;
  }
  
  int ans = INT_MAX;
  for(int i = 0; i < n; i++){
    int tmp;
    tmp = sum - (v.at(i) + 9) / 10 * 10 + v.at(i);
    ans = min(ans, tmp);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
// #define MAX 1000003
class Dictionary{
    const int MAX = 1000003;
    vector<int> D;
    int get_key(char c) {
        if (c == 'A') return 1;
        if (c == 'C') return 2;
        if (c == 'G') return 3;
        return 4;
    }
    int keta(int N) {
        int ret = 1;
        for (int i = 0; i < N; i++) {
            ret *= 5;
        }
        return ret;
    }
    int make_key(string s){
        int key = 0;
        for (int i = 0; i < s.size(); i++) {
            key += get_key(s[i]) * keta(i);
        }
        return key;
    }
    int hash1(int key){
        return key % MAX;
    }
    int hash2(int key){
        return key % (MAX - 1);
    }
public:
    Dictionary(){
        D.resize(MAX);
        for (auto& d : D) d = 0;
    }
    void insert(string s){
        int key = make_key(s);
        int h = hash1(key);
        while (D[h]) h = (h + hash2(key)) % MAX;
        D[h] = key;
    }
    bool find(string s){
        int key = make_key(s);
        int h = hash1(key);
        while (D[h]) {
            if (key == D[h]) return true;
            h = (h + hash2(key)) % MAX;
        }
        return false;
    }
};

int main(){
    int n;
    cin >> n;
    Dictionary d;
    for (int i = 0; i < n; i++) {
        string command;
        string content;
        cin >> command >> content;
        if (command == "insert") {
            d.insert(content);
            continue;
        }
        cout << (d.find(content) ? "yes" : "no") << endl;
    }
    return 0;
}

Measured memory_bytes: 6800
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define rEP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;

int a, b, c, N,A,B,sum;
string s;
int main() {
    cin>>N;
    A=N;
    while(N>0){
        sum+=N%10;
        N/=10;
    }
    if(A%sum==0){
        p("Yes");
    }else p("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main(){
    long long int n;
    cin >> n;
    long long int res = 0;

    for(long long int a = 1; a < n; a++){
        res += (n - 1) / a;
    }

    /*for(long long int i = 1; i < n; i++){// c = i;   
        for(long long int j = 1; j*j <= n - i; j++){
            if((n - i)%j == 0){
                if(j == (n - i) / j){
                    res = res + 1;
                }else{
                    res = res + 2;
                }
            }
        }
    }*/
    cout << res << endl;
}

Measured memory_bytes: 3604
x = int(input())

b = -1
while True:
    b+=1
    amin = (x + b**5)**0.2
    apls = (x - b**5)**0.2

    if isinstance(amin, float):
        amin = round(amin,10)
        if amin.is_integer():
            print(int(amin),b)
            break
    
    if isinstance(apls,float):
        apls = round(apls,10)
        if apls.is_integer():
            print(int(apls),-1*b)
            break


Measured memory_bytes: 9428
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, M;
int A[100100];
pii P[100100];
int ans;

signed main(){
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        P[i] = mk(b, a);
    }
    sort(A, A + N, greater<int>() );
    sort(P, P + M, greater<pii >() );
    
    int j = 0;
    for(int i = 0; i < M; i++){
        while(A[j] > P[i].first && j < N){
            ans += A[j];
            j++;
        }
        if(N - j >= P[i].second){
            ans += P[i].first * P[i].second;
            N -= P[i].second;
        }
        else {
            ans += (N - j) * P[i].first;
            N = j;
            break;
        }
    }
    if(N - j > 0){
        for(int i = j; i < N; i++){
            ans += A[i];
        }
    }
    cout << ans << endl;

    return 0;
}
/*


*/

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}
ll dp[100001][101];
pll w[101];
void solve()
{
  //code begins from here//
  int n,k;
  cin>>n>>k;
  lop1(i,n) cin>>w[i].F>>w[i].S;
  lop(i,101) dp[0][i]=0;
  lop1(i,k)
  {
      lop1(j,n)
      {
        if(i-w[j].F>=0 ) maxn(dp[i][j],dp[i-w[j].F][j-1]+w[j].S);
        maxn(dp[i][j],dp[i][j-1]);

      }
      //cout<<endl;
  }
  ll ans=0;
  lop1(i,k) maxn(ans,dp[i][n]);
  cout<<ans<<endl;
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
   // cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 82224
import itertools
import math

n = int(input())
lis = [x for x in range(1,n+1)] 
xy = [list(map(int,input().split())) for i in range(n)]
permutations_lis = itertools.permutations(lis)
l = list(permutations_lis)
ans = 0

for onecase in l: 
  s = 0
  for j in range(n-1):
    s += math.sqrt((xy[onecase[j]-1][0]-xy[onecase[j+1]-1][0])**2 + (xy[onecase[j]-1][1]-xy[onecase[j+1]-1][1])**2)
  ans += s
  
print(ans/math.factorial(n))

Measured memory_bytes: 7972
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  vector<ll> a(3);
  REP(i, 3){
    cin >> a[i];
    if(a[i]%2 == 0){
      cout << 0 << endl;
      return 0;
    }
  }

  //以下，a[i]はすべて奇数
  sort(ALL(a));
  cout << a[0] * a[1] << endl;

}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int deg[125];
int unko[125];
int g[125][125];

int main(){
  int n,m;
  cin>>n>>m;
  int ans = 0;
  REP(i,n){
    cout<<"lst "<<i<<endl;
    int k;
    cin>>k;
    ans += k*(k-1);
    REP(j,k){
      int to;
      cin>>to;
    }
  }
  cout<<"ans "<<ans<<endl;
  return 0;
}

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

#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

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

  int x, a;
  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;


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

	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;

	int tmp;//残り容量
	int water,sugar;
	int maxw=-1,maxs=-1;
	double maxp=-1.0,p;
	for(int aa=0;aa<=f;aa+=a*100){
		for(int bb=0;bb <= f-aa;bb+=b*100){
			water = aa+bb;
			for(int cc=0;cc <= f-water && cc <= water/100*e;cc+=c){
				for(int dd=0;dd <= f-water-cc && cc+dd <= water/100*e;dd+=d){
					sugar = cc+dd;
					p = 100.0*sugar/(water+sugar);
					if(maxp < p){
						maxp = p;
						maxw = water;
						maxs = sugar;
					}
				}
			}
		}
	}
	cout << maxw+maxs << " " << maxs << "\n";
				
	return 0;
}

Measured memory_bytes: 256
while True:
    try:
        lst = list(raw_input())
        joi = 0
        ioi = 0
        for i in range(len(lst)-2):
            if lst[i+1] == 'O' and lst[i+2] == 'I':
                if lst[i] == 'J':
                    joi += 1
                if lst[i] == 'I':
                    ioi += 1
        print joi
        print ioi
    except EOFError:
        break


Measured memory_bytes: 4468
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.



int main() {
  int N;
  cin >> N;
  long long a[N];
  for (int i = 0; i < N; ++i)
  {
    cin >> a[i];
  }
  long long cnt = 0;
  for (int i = 0; i < N; ++i)
  {
      
      for (int j = i+1; j < N; ++j)
      {
        if(a[j] == a[i])
          continue;

        for (int k = j+1; k < N; ++k)
        {
          if (a[k] == a[j] || a[k] == a[i])
            continue;

              if ( 
        a[i] + a[j] > a[k] 
        && a[i] + a[k] > a[j] 
        && a[k] + a[j] > a[i])
                cnt++;

        }
      }
  }

    cout << cnt << endl;
   return 0;

 }

Measured memory_bytes: 3632
n,m,q=map(int,input().split())
a=[]
for i in range(q):
    a.append(list(map(int,input().split())))

ans=[1 for i in range(n)]
nans=0

while ans!=[m for i in range(n)]:
    #print(ans)
    sum=0
    for i in range(q):
        if ans[a[i][1]-1]-ans[a[i][0]-1]==a[i][2]:
            sum+=a[i][3]
    #print(sum)
    nans=max(nans,sum)
    ans[-1]+=1
    while max(ans)>m:
        max_ind=ans.index(m+1)
        ans[max_ind-1]+=1
        ue=ans[max_ind-1]
        for i in range(max_ind,len(ans)):
            ans[i]=ue
sum=0
for i in range(q):
    if ans[a[i][1]-1]-ans[a[i][0]-1]==a[i][2]:
        sum+=a[i][3]
nans=max(nans,sum)

print(nans)

Measured memory_bytes: 68608
<?php
$mountains = array_fill(0,10,0);
$cnt = 0;
while(list($a)=fscanf(STDIN,"%d")){
    $mountains[$cnt] = $a;
    ++ $cnt;
}
rsort($mountains);
echo $mountains[0],PHP_EOL;
echo $mountains[1],PHP_EOL;
echo $mountains[2],PHP_EOL;

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

using namespace std;

#define int long long

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

    int n;
    cin >> n;
    int a, ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        ans += a - 1;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define int long long
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, P;
int A[50];

long long nCr(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  long long s = 1;
  for (int x=1; x<=k; x++) {
    s *= (n - x + 1);
    s /= x;
  }
  return s;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> P;
  int zero = 0, one = 0;
  rep(i, N) {
    cin >> A[i];
    A[i] %= 2;
    if (A[i] == 0) zero++;
    else one++;
  }
  long long ans = 0;
  for (int a=0; a<=zero; a++) {
    for (int b=0; b<=one; b++) {
      if (b%2 != P) continue;
      ans += 1LL * nCr(zero, a) * nCr(one, b);
    }
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int mod=1000000007;
    int n;
    cin>>n;
    long long a[n];
    long long
    b[61]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<=60;j++){
            if(a[i]%2)b[j]++;
            a[i]/=2;
        }
    }
    long long p=1,x=0;
    for(int i=0;i<=60;i++){
        b[i]*=n-b[i];
        b[i]%=mod;
        x+=b[i]*p;
        p*=2;
        x%=mod;
        p%=mod;
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;

int main(){
    string a;
    string b;
    string c;
    cin>>a;
    cin>>b;
    cin>>c;
    a=a.substr(0,1);
    b=b.substr(1,1);
    c=c.substr(2,1);
    cout<<a<<b<<c<<endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod  = 1e9+7;
const db eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf  = LLONG_MAX;
const ll minf = LLONG_MIN;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cerr << #x << " " << x << endl

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
    ll n,k,d;
    cin >> n >> k;

    ll cnt = n;
    vector<bool> v(n+1,false);

    for(ll i=0 ; i<k ; ++i)
    {
        cin >> d;
        for(ll j=0,tmp ; j<d ; ++j)
        {
            cin >> tmp;
            if(!v[tmp])
            {
                cnt--;
                v[tmp] = true;
            }
        }

    }

    cout << cnt;

    return 0;
} 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005],ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        int cnt=0;
        for(int j=i+1;j<=n;j++)
        {
            while(cnt<i&&a[cnt]+a[i]<=a[j]) cnt++;
            ans+=i-cnt;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(int argc, char const *argv[]) {
    int N,M;
    cin >> N >> M;
    int x[N];
    REP(i,N){
        x[i]=0;
    }
    REP(i,M){
        int a,b;
        cin >> a >> b;
        x[a-1]++;
        x[b-1]++;
    }
    REP(i,N){
        cout << x[i] << endl;
    }
    return 0;
}


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

int main()
{
    
    string s, t;
    getline( cin, s );
    getline( cin, t );
    int n1 = s.size();
    int n2 = t.size();
    
    if( s.substr(0,n1) == t.substr(0,n2-1) && n1 == n2 - 1 ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
      
    return 0;
}


Measured memory_bytes: 3628
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline int read() {
    int res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n, m, r[N * 2];
ll ans, buc[26];
char s[N * 2], t[N];

inline void manacher() {
    // create s
    s[n] = '!';
    for (int i = 1; i <= m; i++) {
        s[++n] = '#';
        s[++n] = t[i];
    }
    s[++n] = '#';
    s[n + 1] = '?';

    // main procedure of manacher
    int p = 0, mx = 0, x = 0;
    for (int i = 1; i <= n; i++) {
        if (mx > i) x = std::min(r[p * 2 - i], mx - i);
        else x = 1;
        while (s[i + x] == s[i - x]) x++;
        if (i + x > mx) mx = i + x, p = i;
        r[i] = x;
    }
}

int main() {
    scanf("%s", t + 1);
    m = strlen(t + 1);
    // manacher();
    ans = (ll)m * (m - 1) / 2 + 1;
    for (int i = 1; i <= m; i++) buc[t[i] - 'a']++;
    for (int i = 0; i < 26; i++) {
        ans -= (ll)buc[i] * (buc[i] - 1) / 2;
    }
    printf("%lld\n", ans);
    return 0;
}

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

a = []
max_lst = [0,0]
for _ in range(n):
    d = int(input())
    a.append(d)

    if d > max_lst[1]:
        tmp = max_lst[1]
        max_lst[1] = d 
        max_lst[0] = tmp
    
    elif d > max_lst[0]:
        max_lst[0] = d
        
max_lst = sorted(max_lst, reverse=True)

for i in a:
    if i != max_lst[0]:
        print(max_lst[0])
    else:
        print(max_lst[1])






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

const int MAX_N = 1e5 + 5;
int n, L, T;
int X[MAX_N];
int W[MAX_N];
int fin[MAX_N];
int shift;

void find() {
    for (int i = 0; i < n; i++) {
        if (W[i] == 1)
            shift = (shift + (X[i] + T) / L) % n;
        else
            shift = (((shift + (X[i] - T - L + 1) / L) % n) + n) % n;
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> L >> T;
    for (int i = 0; i < n; i++)
        cin >> X[i] >> W[i];

    for (int i = 0; i < n; i++) {
        if (W[i] == 1)
            fin[i] = (X[i] + T) % L;
        else
            fin[i] = ((X[i] - T) % L + L) % L;
    }

    sort(fin, fin + n);
    find();
    for (int i = shift; i < n; i++)
        cout << fin[i] << " ";
    for (int i = 0; i < shift; i ++)
        cout << fin[i] << " ";
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

const int maxV=114514;
struct edge{int end;int cost;};
typedef pair<int,int> P;
int V;
vector<int> d;
vector<edge> G[maxV];

void dijkstra(int s){
    d.clear();
    priority_queue<P,vector<P>,greater<P>> que;
    for(int i=0;i<maxV;i++){d.push_back(INF);}
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.end]>d[v]+e.cost){
                d[e.end] = d[v]+e.cost;
                que.push(P(d[e.end],e.end));
            }
        }
    }
}


signed main(void){
    int H,W;
    string S[104];
    cin >> H >> W;
    REP(i,H){
        cin >> S[i];
    }
    edge h;
    REP(i,H){
        REP(j,W){
            if(j!=W-1){
                h.end = 105*i + (j+1);
                h.cost = (S[i][j]==S[i][j+1])?0:1;
                G[105*i+j].push_back(h);
            }
            if(i!=H-1){
                h.end = 105*(i+1) + j;
                h.cost = (S[i][j]==S[i+1][j])?0:1;
                G[105*i+j].push_back(h);
            }
        }
    }
    h.end = 0;
    h.cost = (S[0][0]=='.')?0:1;
    G[11000].push_back(h);
    
    h.end = 11001;
    h.cost = (S[H-1][W-1]=='.')?0:1;
    G[105*(H-1)+(W-1)].push_back(h);
    
    dijkstra(11000);
    int K = d[11001];
    cout << K/2 << endl;
    
    return 0;
}



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

int main() {
    /* Input */
    vector<int> x(5);
    cin >> x.at(0) >> x.at(1) >> x.at(2) >> x.at(3) >> x.at(4);

    /* Main Logic */
    int ans = 0;
    rep (i, 5) {
        if (i+1 != x.at(i)) {
            ans = i + 1;
            break;
        }
    }
    
    /* Output */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
/*---------------Go Code GO---------------*/

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

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using Order_Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//(order) Set.order_of_key(); (pointer) Set.find_by_order();

#define PI acos(-1.0)
#define O_O                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define precision(a) fixed << setprecision(a)
#define endl '\n'
#define Flush cout << flush
#define LLMX 0x3fffffffffffffff

long long N;

int main()
{
    O_O;
    long long i, j, k, l, tst = 0, ans = 0, csno = 0;
    long long odd = 0, even = 0;

    cin >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> k;
        odd += (k % 2);
        even += (k % 2 == 0);
    }
    if (odd % 2 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3648
AC = []
WA  = []
TLE = []
RE = []
n = int(input())
for i in range(n):
    s = input()
    if s== 'AC':
        AC.append(s)
    elif s=='WA':
        WA.append(s)
    elif s=='TLE':
        TLE.append(s)
    else:
        RE.append(s)
print(f'AC x {len(AC)}')
print(f'WA x {len(WA)}')
print(f'TLE x {len(TLE)}')
print(f'RE x {len(RE)}')

Measured memory_bytes: 16280
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int N = ReadInt();
    int[] p = new int[N];
    for (int i = 0; i < N; i++) p[i] = ReadInt();
    Console.WriteLine(p.Sum() - p.Max()/2);
  }

  private static int ReadInt() { return int.Parse(Console.ReadLine()); }
  private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  private static long ReadLong() { return long.Parse(Console.ReadLine()); }
  private static char ReadChar() { return Console.ReadLine()[0]; }
  private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    int n, m, num=0;
    cin >> n;
    m = n;
    int ans=0;
    while(m > 0){
        m /= 10;
        num++;
    }

    switch(num){
    case 1:
        cout << n << endl;
        break;
    case 2:
        cout << 9 << endl;
        break;
    case 3:
        cout << 9 + n - 99 << endl;
        break;
    case 4:
        cout << 909 << endl;
        break;
    case 5:
        cout << 9 + 900 + n - 9999 << endl;
        break;
    default:
        cout << 90909 << endl;
    }

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


Measured memory_bytes: 256
s = list(input())

if s[0] == "A" and s[2:-1].count("C") == 1:
  s.remove("A")
  s.remove("C")
  for c in s:
    if c.isupper() == True:
      print("WA")
      exit()
    else:
      continue
  print("AC")

else:
  print("WA")

Measured memory_bytes: 38384
N = int(input())
A = list(map(int, input().split()))

dp = [0]*N

cum = A[0]
for i in range(N):
    if i == 0:
        dp[i] = 0
        continue
    if i == 1:
        dp[i] = max(A[0],A[1])
        continue
    if i%2==0: #奇数の時
        cum += A[i]
        dp[i] = max(dp[i-1],dp[i-2]+A[i])

    if i%2==1: #偶数の時
        dp[i] = max(dp[i-2]+A[i],cum)

ans = dp[-1]


print(ans)
#print(*ans, sep='\n')

Measured memory_bytes: 94136
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=110;
int i,j,k,n,m,ch,ff,ans;
int A[N],B[N];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
int main() {
	R(n);
	for (i=1;i<=n;i++) R(A[i]);
	for (i=1;i<=n;i++) R(B[i]);
	for (i=1;i<=n;i++) A[i]+=A[i-1];
	for (i=n;i;i--) B[i]+=B[i+1];
	for (i=1;i<=n;i++) ans=max(ans,A[i]+B[i]);
	W(ans);puts("");
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

X = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
y=0
cx=100
while cx<X:
    cx=math.floor(cx*1.01)
    y+=1
print(y)

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

int main() {
  int N;
  cin>>N;
  vector<int> H(N);
  for(int i=0;i<N;i++)
    cin>>H[i];
  int answer=0;
  int position=0;
  while(position<N-1){
    int r=0; //rはそこから動ける最大数
  	for(int i=position;i<N;i++){
    	if(H[i]>=H[i+1]){
          r++;
          
        }
    	else{
          position=i+1;
          if(answer<r)
            answer=r;
          break;
        }
        if(i==N-2){
          position=N-1;
          if(answer<r)
            answer=r;
          break;
        }
    }
  }
  cout<<answer;
}

Measured memory_bytes: 640
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int N=Readint()[0];
    int[] v = Readint();
    Array.Sort(v);
    double res=(v[0]+v[1])/Pow(2.0,N-1.0);
    int i=2;
    while(i<N){
      res += v[i]/Pow(2.0,N-i);
      i++;
    }
    WriteLine(res.ToString());
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}

Measured memory_bytes: 14036
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#define ll long long int
using namespace std;
int h[6], w[6];

int main() {
	int H, W, K, num, ans = 0;

	cin >> H >> W >> K;
	vector<string> c(H);

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

	for (int ibit = 0; ibit < (1 << H); ibit++){
		for (int jbit = 0; jbit < (1 << W); jbit++){
			num = 0;
			for (int i = 0; i < H; i++){
				for (int j = 0; j < W; j++){
					if ((ibit >> i) & 1)
						continue;
					if ((jbit >> j) & 1)
						continue;
					if (c[i][j] == '#'){
						num++;
					}
				}
			}
			if (num == K){
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main()
{
    string s;
    int ans = 0;
    int t = 0;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'S') ans++;
        else if (ans > 0 && s[i] == 'T') ans--;
        else t++;
    }

    cout << ans+t << endl;
}


Measured memory_bytes: 640
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	while (true) {
		int n = -1, a;
		cin >> n;
		if (n <= 0) break;
		int cnt[9] = {};
		for (int i = 0; i < n; ++i) {
			cin >> a;
			cnt[min(a / 400, 8)] += 1;
		}
		int cols = 0;
		for (int i = 0; i < 8; ++i) {
			cols += cnt[i] > 0;
		}
		cout << max(1, cols) << " " << (cols + cnt[8]) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p)  
{  
    long long int res = 1;      
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
        
        if (y & 1)  
            res = (res*x) % p;  
  
          
        y = y>>1;  
        x = (x*x) % p;  
    }  
    return res;  
}  
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	{
        long long int p=1e9+7;
        long long int n;
        cin>>n;
        
        long long int ans1=power(10,n,p);
        long long int ans2=2*power(9,n,p);
        long long int ans3=power(8,n,p);
        long long int res=(((ans1-ans2)%p + p )%p +ans3)%p;
        
       // long long int res= (ans1-ans2)%p;
        res=(res+p)%p;
        
        cout<<res<<endl;
            
            
	   
	}
	   
	   
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
jun = list(map(int, input().split()))
result = 0
for i in range(n - 2):
    if (jun[i] > jun[i+1] and jun[i+1] > jun[i+2]) or (jun[i] < jun[i+1] and jun[i+1] < jun[i+2]):
        result += 1
print(result)

Measured memory_bytes: 3060
from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)


n=int(input())
if n==2:
    print(1)
    exit()
ans=0
for x in range(1,n):
    if (n-x*x)>0:
        ans+=1
        ans+=(((n-1)-x*x)//x)*2
print(ans)


Measured memory_bytes: 9564
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI = 3.141592653589793;

const int M = 1e9 + 7;

void solve()
{
	int cur = 0, sum = 0, ans = 0 ;
	int n;
	cin >>n ;
	while(n--)
	{
		cin >> cur;
		ans += (cur * sum);
		ans %= M;
		sum += cur ;
		sum %= M;
	}
	cout << ans ;
}

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T = 1;
	while(T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			String S = sc.next();
		sc.close();


		StringBuffer sb = new StringBuffer(S);
		String T = sb.reverse().toString();

		//System.out.println(T);

		boolean flag = true;
		for(int i = 0 ; i < T.length() ; i++){
			if(i+5 <=T.length() && (T.substring(i, i+5).equals("maerd") ||T.substring(i, i+5).equals("esare"))){
				//System.out.println(T.substring(i, i+5));
				i +=4;

			}
			else if(i+6<=T.length() && T.substring(i, i+6).equals("resare")){
				//System.out.println(T.substring(i, i+6));
				i += 5;

			}
			else if(i+7<=T.length() && T.substring(i, i+7).equals("remaerd")){
				//System.out.println(T.substring(i, i+7));
				i += 6;

			}

			else{
				flag = false;
				break;
			}
		}

		if(flag){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 28528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Sample
{
  class Sample
  {
    static void Main()
    {
      
      var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
      
      int tai = p[0];
      int atk = p[1];

      
      
     for(int i=1;i <1000000;i++ ){

       if(tai - i*atk <= 0){
       Console.WriteLine(i);
         break;
       }
        
        
      }
      
      
		}
	}
}



Measured memory_bytes: 11092
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        int a = inp.nextInt();
        int b = inp.nextInt();
        int ans = a < 6 ? 0 : (a < 13 ? (b / 2) : b);
        System.out.println(ans);
    }
}


Measured memory_bytes: 22612
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d;
        if(b < c){
            if(a < b){
                System.out.printf("%d %d %d\n", a, b, c);
            } else if (a < c) {
                d = a;
                a = b;
                b = d;
                System.out.printf("%d %d %d\n", a, b, c);
            } else {
                d = a;
                a = b;
                b = c;
                c = d; 
                System.out.printf("%d %d %d\n", a, b, c);
            }
        } else if (a < c) {
            d = b;
            b = c;
            c = d;
            System.out.printf("%d %d %d\n", a, b, c);
        } else if (a > b) {
            d = a;
            a = c;
            c = d;
            System.out.printf("%d %d %d\n", a, b, c);
        } else {
            d = a;
            a = c;
            c = b;
            b = d;
            System.out.printf("%d %d %d\n", a, b, c);
        }
        scan.close();
        }
    }


Measured memory_bytes: 26140
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        list.add(input.nextInt());
        list.add(input.nextInt());
        list.add(input.nextInt());
        Collections.sort(list);
        
        StringBuilder sb = new StringBuilder();
        for (Integer n : list) {
            sb.append(n).append(" ");
        }
        System.out.println(sb.toString().trim());
    }
}

Measured memory_bytes: 17176
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

string pad(const int& num) {
  string t = to_string(num);
  string pad = "";
  if (t.size() < 6) {
    int diff = 6 - (int) t.size();
    for (int i = 0; i < diff; ++i) {
      pad += '0';
    }
  }
  return pad + t;
}

struct task{
  int year, id;
};

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

  int n, m; cin >> n >> m;
  vector<task> v[101010];
  for (int i = 0; i < m; ++i) {
    int p, y; cin >> p >> y;
    v[p].push_back({y, i + 1});
  }

  vector<string> ans(m + 1);

  for (int i = 1; i <= n; ++i) {
    if (v[i].empty()) continue;
    sort(v[i].begin(), v[i].end(), [](const task &x, const task &y){
      return x.year < y.year;
    });
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < (int)v[i].size(); ++j) {
      ans[v[i][j].id] = pad(i) + pad(j + 1);
    }
  }

  for (int i = 1; i <= m; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  ll K,N;
  cin>>K>>N;
  vector<ll>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  ll ans=LONG_MAX;
  for(int i=0;i<N-1;i++){
    ans=min(ans,K-(A[i+1]-A[i]));
  }
  ans=min(ans,K-(A[0]+K-A[N-1]));
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const int INF = (1LL<<30);
#else
const ll INF = (1LL<<60);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int x, y, w, h, used[505][505];
string s[505], r[505], b[505];

void dfs(int a, int b) {
  // cout << a << " " << b << endl;
  used[b][a] = true;
  if(y > b) x = a, y = b;
  else if(y == b && x < a) x = a, y = b;
  REP(i, 4) {
    int nx = a + dx[i], ny = b + dy[i];
    if(IN(0, w, nx) && IN(0, h, ny) && !used[ny][nx] && s[ny][nx] == '#') {
      dfs(nx, ny);
    }
  }
}

signed main(void)
{
  cin >> h >> w;
  REP(i, h) cin >> s[i];
  REP(i, h) REP(j, w) r[i] += '.', b[i] += '.';

  REP(i, h) REP(j, w) {
    if(j == 0) r[i][j] = '#';
    else if(j == w-1) b[i][j] = '#';
    else if(i%2) r[i][j] = '#';
    else b[i][j] = '#';
  }

  REP(i, h) REP(j, w) if(s[i][j] == '#') r[i][j] = b[i][j] = '#';

  REP(i, h) cout << r[i] << endl;
  cout << endl;
  REP(i, h) cout << b[i] << endl;

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
const ll INF = 1e18;
 
int main(){
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a), t(b);
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
  s.push_back(INF);
  t.push_back(INF);
  s.push_back(-INF);
  t.push_back(-INF);
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
 
  auto left = [&](const vector<ll> &v, ll key) {
    return v[upper_bound(v.begin(), v.end(), key) - v.begin() - 1];
  };
  auto right = [&](const vector<ll> &v, ll key) {
    return v[lower_bound(v.begin(), v.end(), key) - v.begin()];
  };
 
  while (q--) {
    ll x;
    cin >> x;
    ll res = INF;
    rep(i,2) {
      ll shrine = (i ? left(s,x) : right(s,x));
      rep(j,2) {
        ll temple = (j ? left(t,shrine) : right(t,shrine));
        res = min(res,abs(x - shrine) + abs(shrine - temple));
      }
    }
 
    rep(i,2) {
      ll temple = (i ? left(t,x) : right(t,x));
      rep(j,2) {
        ll shrine = (j ? left(s,temple) : right(s,temple));
        res = min(res,abs(x - temple) + abs(shrine - temple));
      }
    }
    cout << res << endl;
  }
  return 0;
} 

Measured memory_bytes: 2912
N = int(input())
mod = 10 ** 9 + 7

def is_valid(i, j, k, new):
    if (j, k, new) == (0, 1, 2) or (j, k, new) == (0, 2, 1) or (j, k, new) == (2, 0, 1):
        return False
    elif (i, k, new) == (0, 2, 1) or (i, j, k, new) == (0, 2, 1) or (i, j, k, new) == (0, 2, 1):
        return False
    elif (i, j, new) == (0, 2, 1) or (i, j, k, new) == (0, 2, 1) or (i, j, k, new) == (0, 2, 1):
        return False
    else:
        return True

dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N + 1)]
dp[0][3][3][3] = 1
for n in range(1, N + 1):
    for i in range(4):
        for j in range(4):
            for k in range(4):
                for new in range(4):
                    if is_valid(i, j, k, new):
                        dp[n][j][k][new] += dp[n - 1][i][j][k]
ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans = (ans + dp[N][i][j][k]) % mod
print(ans)

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

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
    Node y; // node to be deleted
    Node x; // child of y



}
*/

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL){
        root = z;
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inorder(Node u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if ( com[0] == 'f' ){
            scanf("%d", &x);
            //Node t = treeSearch(root, x);
            //if ( t != NIL ) printf("yes\n");
            //else printf("no\n");
        } else if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if ( com[0] == 'd' ){
            scanf("%d", &x);
            //treeDelete(treeSearch(root, x));
        }
    }

    return 0;
}



Measured memory_bytes: 25220
#include<bits/stdc++.h>
using namespace std;
main(){
  while(1){
    int n,l,s,cnt=0;
    bool check=true;
    int keta[4]={0};
    cin>>n;
    if(n==0){
      break;
    }
    keta[0]=(n)%10;
    keta[1]=(n/10)%10;
    keta[2]=(n/100)%10;
    keta[3]=(n/1000)%10;
    if(keta[0]==keta[1]&&keta[1]==keta[2]&&keta[2]==keta[3]){
      cout<<"NA"<<endl;
    }
    else{
      while(n!=6174){
	sort(keta,keta+4);
	s=keta[0]*1000+keta[1]*100+keta[2]*10+keta[3];
	l=keta[0]+keta[1]*10+keta[2]*100+keta[3]*1000;
	n=l-s;
	keta[0]=(n)%10;
	keta[1]=(n/10)%10;
	keta[2]=(n/100)%10;
	keta[3]=(n/1000)%10;
	cnt++;
      }
      cout<<cnt<<endl;
    }
  }
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
using graph=vector<vector<int>>;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    string s; cin>>s;
    int count=0;
    rep(i,3){
        if(s[i]=='R') count++;
    }

    if(count==2){
        if(s[1]=='S') count=1;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3636
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	A
# CreatedDate:  2020-09-19 20:49:13 +0900
# LastModified: 2020-09-19 21:00:48 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    S = input()
    if S[-1] == 's':
        print(S+'es')
    else:
        print(S+'s')


if __name__ == "__main__":
    main()


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

 
int main() {
  int n,m,s=0, cnt = 0;
  cin >> n >> m;
  vector<int> a(n);
  
  rep(i, n) cin >> a[i];
  rep(i, n) s += a[i];
  
  double o = (double)s/(4*m);
  rep(i, n) {
    if (a[i] >= o) cnt++;
  }

  
  if (cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
    
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
n = a[-1]
mid = a[-1] // 2
i = bisect_left(a[:-1], mid)

if i >= len(a) - 1:
    r = a[i - 1]
elif i == 0 or a[i] == mid:
    r = a[i]
elif a[i] - mid <= mid - a[i - 1]:
    r = a[i]
else:
    r = a[i - 1]

print(n, r)

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int b[n];
    b[0] = a[0];
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        b[i] =  max(a[i], b[i - 1]);
        ans += b[i] - a[i];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5112