akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  cin >> n;
  string ss[9] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs"
                   ,"tuv", "wxyz"};
  while(n--) {
    string s;
    cin >> s;
    char n = '*';
    int ct = 0;
    REP(i,s.size()) {
//      printf("%c, %d\n", n, ct);
      if (s[i] == '0') {
        if (ct > 0) {
          cout << ss[n-'1'][(ct-1) % ss[n-'1'].size()];
        }
        ct = 0; n = '*';
      } else if (s[i] != n) {
        n = s[i];
        ct = 1;
      } else {
        ++ct;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,a,b,cj,dp[200000];
vector<ll> v[200000];
void dfs(ll n,ll a,ll b){
    dp[n]+=a;
    for(ll x:v[n]){
        if(x==b)continue;
        dfs(x,dp[n],n);
    }
    return ;
}
int main(void){
    cin>>n>>k;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<k;i++){
        cin>>a>>b;
        a--;
        dp[a]+=b;
        //dfs(a,b);
    }
    dfs(0,0,-1);
    for(int i=0;i<n;i++){
        cout<<dp[i]<<" ";
    }
    cout<<endl;
}


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

const int MAX = 10;
const int MOD = 1000000007;

const double PI = acos(-1);
const double Rad2Deg = 180.0 / PI;
const double Deg2Rad = PI / 180.0;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int A, B;
    cin >> A >> B;
    int d = A - 2 * B;
    if (d <= 0) cout << "0" << endl;
    else cout << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 505;
int ans[N*N];
int x[N];

void no() {
    cout<<"No"<<endl;
    exit(0);
}

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

    vector<pair<int, int>> vp;

    int n;
    cin>>n;
    for (int i=1; i<=n; i++) {
        cin>>x[i];
        vp.push_back({x[i], i});
        ans[x[i]] = i;
    }

    sort(vp.begin(), vp.end());
    int ptr = 1;
    for (int i=0; i<n; i++) {
        int pos = vp[i].first;
        int x = vp[i].second;

        for (int i=1; i<x; i++) {
            while(ans[ptr])    ptr++;
            if (ptr > pos)     no();
            ans[ptr] = x;
        }
    }

    reverse(vp.begin(), vp.end());
    ptr = n*n;
    for (int i=0; i<n; i++) {
        int pos = vp[i].first;
        int x = vp[i].second;

        for (int i=1; i<=n-x; i++) {
            while(ans[ptr])    ptr--;
            if (ptr < pos)     no();
            ans[ptr] = x;
        }
    }

    cout<<"Yes"<<endl;
    for (int i=1; i<=n*n; i++)  cout<<ans[i]<<" ";
}


Measured memory_bytes: 4636
// AOJ 1243 Weather Forecast
// 2018/1/21

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n, ans;
int date[367];
int cd[4];
char mk[367][10][8][8][8][8];
int pos[12] = {0,1,2,3,0,4,5,6,0,7,8,9};
int mv[9][2] = {{0,0},{0,1},{0,-1},{1,0},{-1,0},{0,2},{0,-2},{2,0},{-2,0}};

char check(int k, int x, int y, int *cd)
{
	int a = ((x - 1) << 2) + y;
	if ((date[k] & (1<< a  ))  || (date[k] & (1<<(a+4))) ||
		(date[k] & (1<<(a+1))) || (date[k] & (1<<(a+5)))) return 0;
	if (mk[k][pos[a]][cd[0]][cd[1]][cd[2]][cd[3]]) return 0;
    return 1;
}

void dfs(int k, int x, int y, int *cd)
{
	int i, j, t, x2, y2;
	int a[5];

	if (k == n) { ans = 1; return; }
	for (i = 0; i < 9; i++) {
		if (!k && i) break;
		t = k + 1, x2 = x + mv[i][0], y2 = y + mv[i][1];
		if (x2 < 1 || x2 > 3 || y2 < 1 || y2 > 3) continue;
		for (j = 0; j < 4; j++) a[j] = cd[j] + 1;
		if (x2 == 1 && y2 == 1) a[0] = 0;
		if (x2 == 1 && y2 == 3) a[1] = 0;
		if (x2 == 3 && y2 == 1) a[2] = 0;
		if (x2 == 3 && y2 == 3) a[3] = 0;
		if (a[0] >= 7 || a[1] >= 7 || a[2] >= 7 || a[3] >= 7) continue;

		if (check(t, x2, y2, a)) {
			mk[t][pos[((x2-1)<<2)+y2]][a[0]][a[1]][a[2]][a[3]] = 1;
			dfs(t, x2, y2, a);
		}
	}
}

int main ()
{
	int i, j;
	char buf[40], *p;

	while (fgets(buf, 10, stdin) && *buf != '0') {
		n = atoi(buf);

		memset(date, 0, sizeof(date));
		for (i = 1; i <= n; i++) {
			fgets(p=buf, 40, stdin);
			for (j = 1; j <= 16; j++) {
				while (*p < '0') p++;
				date[i] |= (*p++ & 0xf) << j;
			}
		}

		memset(mk, 0, sizeof(mk));
		memset(cd, 0, sizeof(cd));
		ans = 0;
		dfs(0, 2, 2, cd);
		putchar('0'+ans), putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 16384
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
int table[30][100];
#define INF 10000
int solve(vector<int> &cyc,vector<int>& day){
  rep(i,day.size())rep(j,cyc.size())table[j][i]=INF;
  table[0][0]=0;
  REP(i,1,day.size()){
    table[0][i]=min(table[0][i-1]+1,table[cyc.size()-1][i-1]);
    REP(j,1,cyc.size()){
      table[0][i]=min(table[0][i],table[j][i-1]+1);//take caffein
      if (day[i]>=cyc[j]){
	table[j][i]=table[j-1][i-1];
      }

    }
  }

  /*
  rep(i,cyc.size()){
    rep(j,day.size())cout <<table[i][j]<<" ";
    cout << endl;
  }
  */

  int ret=INF;
  rep(i,cyc.size())ret=min(ret,table[i][day.size()-1]);
  return ret;
}

main(){
  int n,m;
  while(cin>>n && n){
    vector<int> cyc,day(100,24);
    rep(i,n){
      int t;cin>>t;cyc.push_back(t);
    }
    
    cin>>m;
    rep(i,m){
      int d,time;cin>>d>>time;
      day[d-1]=min(day[d-1],time);
    }
    cout << solve(cyc,day)<<endl;
  }
  return false;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        struct EC : IComparable<EC>
        {
            public int vertex;
            public int edgeCount;

            public int CompareTo(EC e)
            {
                return edgeCount.CompareTo(e.edgeCount);
            }
        }

        struct Element
        {
            public int destVertex;
            public int distance;
        }


        static int N;
        static int[] v;
        static List<int>[] e;

        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());

            v = new int[N];
            EC[] c = new EC[N];
            
            e = new List<int>[N];
            for (int i = 0; i < N; i++)
            {
                e[i] = new List<int>();
                c[i].vertex = i;
            }

            for (int i = 0; i < N; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < N; j++)
                {
                    if(s[j] == '1')
                    {
                        e[i].Add(j);
                        c[i].edgeCount++;
                    }
                }
            }
            //Array.Sort(c);

            //int edgeC = c[0].edgeCount;

            int ans = -1;
            //for (int i = 0; i < N && edgeC == c[i].edgeCount; i++)
            for (int i = 0; i < N; i++)
            {
                int ans0 = solveOne(c[i].vertex);
                if(ans0 < 0)
                {
                    Console.WriteLine(-1);
                    return;
                }

                ans = Math.Max(ans, ans0);
            }

            Console.WriteLine(ans);
        }


        static int solveOne(int start)
        {
            for (int i = 0; i < N; i++)
            {
                v[i] = int.MaxValue;
            }

            Queue<Element> q = new Queue<Element>();

            Element ele = new Element();
            ele.destVertex = start;
            ele.distance = 1;
            q.Enqueue(ele);

            while (q.Count > 0)
            {
                ele = q.Dequeue();

                if (v[ele.destVertex] > ele.distance)
                {
                    v[ele.destVertex] = ele.distance;

                    foreach (int dest in e[ele.destVertex])
                    {
                        Element to = new Element();
                        to.destVertex = dest;
                        to.distance = ele.distance + 1;

                        q.Enqueue(to);
                    }
                }
            }

            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                ans = Math.Max(ans, v[i]);

                foreach (int dest in e[i])
                {
                    if (Math.Abs(v[i] - v[dest]) != 1)
                    {
                        return -1;
                    }
                }
            }

            return ans;
        }
    }
}



Measured memory_bytes: 28820
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()
#print(T)
if C==1:
    print(N)
    exit()
ans=0
i=0
j=1
tmp=1
while True:
    #print(i,j)
    if j-i==C:
        if j==N:
            ans+=1
            break
        ans+=1
        i=j
        j=i+1
        tmp=1
    if j>=N:
        ans+=1
        break
    if i!=N-1:
        if T[j]-T[i]>K:
            ans+=1
            i=j
            j=i+1
            tmp=1
            continue
        else:
            j+=1
            tmp+=1
print(ans)

Measured memory_bytes: 13296
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  int a , b , c , d;
  cin >> a >> b >> c >> d;
  int k = b - a;
  int l = c - b;
  int t = c - a;
  if(k < 0)k = a - b;
  if(l < 0)l = b - c;
  if(t < 0)t = a - c;
  if(t <= d)cout << "Yes" << endl;
  else if(k <= d && l <= d)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
// WeirdBugsButOkay

# include <bits/stdc++.h>

# define ll long long
# define ld long double
# define pii pair <int,int>
# define pll pair <ll,ll>
# define mp make_pair
# define pb push_back
# define ff first
# define ss second
# define endl '\n'

using namespace std;

ll pow3(ll a, ll b, ll m = 1000000007)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}

void solve()
{
    ll n;
    cin >> n;
    pll a[n + 1];
    for(ll i = 1; i <= n; i++)
    {
        cin >> a[i].ff;
        a[i].ss = i;
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    //for(ll i = 1; i <= n; i++)
        //cout << a[i].ff << " " << a[i].ss << endl;
    ll dp[n + 1][n + 1];
    for(ll i = 0; i <= n; i++)
        for(ll j = 0; j <= n; j++)
            dp[i][j] = 0;
    for(ll i = 1; i <= n; i++)
    {
        dp[i][0] = max(dp[i - 1][0] + abs(a[i].ss - i) * a[i].ff, dp[i][0]);
        dp[0][i] = max(dp[0][i - 1] + abs(a[i].ss - (n - i + 1)) * a[i].ff, dp[0][i]);
        for(ll j = 1; j < i; j++)
            dp[i - j][j] = max(dp[i - j - 1][j] + abs(a[i].ss - (i - j)) * a[i].ff, dp[i - j][j - 1] + abs(a[i].ss - (n + 1 - j)) * a[i].ff); 
    }
    //for(ll i = 0; i <= n; i++)
    //{
        //for(ll j = 0; j <= n; j++)
            //cout << dp[i][j] << " ";
        //cout << endl;
    //}
    ll ans = 0;
    for(ll i = 0; i <= n; i++)
        ans = max(ans, dp[i][n - i]);
    cout << ans << endl;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q = 1;
    //cin >> q;
    for(ll i = 0; i < q; i++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 34960
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll a; string b; cin >> a >> b;
	ll t = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
	ll ans = a * t / 100;
	cout << ans << endl;
}

Measured memory_bytes: 3628
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))

Measured memory_bytes: 100588
/*
Author : N_o_o_B
Created : April 22 2020 21:49:57 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int a[5];
    fori(i,5){
        cin >> a[i];
    }
    int best = mod;
    do{
        int t=0;
        for(int i=0;i<5;i++){
            
            while(t%10) t++;
            t += a[i];
        }
        best = min(best,t);
    }while(next_permutation(a,a+5));
    cout << best << endl;

    time_taken();
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll inf = 1e9 + 5;
typedef pair<int, bool> pib;

int main() {
    int n; cin >> n;
    vector<int> dp (3);
    for (int d = 0; d < n; d++){
        vector<int> curdp (3);
        vector<int> curval (3);
        for (int i = 0; i < 3; i++){
            cin >> curval[i];
        }
        for (int i = 0; i < 3; i++){
            for (int j = 0; j < 3; j++){
                if (i != j){
                    curdp[j] = max(curdp[j], dp[i] + curval[j]);
                }
            }
        }
        dp = curdp;
    }
    cout << max({dp[0], dp[1], dp[2]});
}



Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
  int N;
  cin >> N;
  map<int, int> chk;
  int a;
  for(int i = 0; i < N; i++){
    cin >> a;
    ++chk[a];
  }

  long long Amax = 0, Bmax = 0;
  for(auto x: chk){
    if(x.second>=4&&x.first>=Amax){
      Amax = Bmax = x.first;
    }else if(x.second>=2){
      if(x.first>=Amax) Bmax = Amax, Amax = x.first;
      else if(Bmax < x.first) Bmax = x.first;
    }
  }

  long long Ans = Amax*Bmax;
  printf("%lld\n",Ans);
  return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[600][600];

int main(){
  stack<char> vec;
  cin >> s;
  rep(i,0,s.sz){
    if(s[i] == 'S')vec.push(s[i]);
    else{
      if(vec.empty() || vec.top() == s[i])vec.push(s[i]);
      else{
        if(vec.empty())continue;
         if(vec.top() == 'S')vec.pop();
      }
    }
  }
  print(vec.sz);
  return 0;
}

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

const int N = 100009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

int n, k, r, s, p;
string t;

int x(char tk)
{
	if (tk == 'r')
		return 0;
	else if (tk == 's')
		return 1;
	else if (tk == 'p')
		return 2;
	return 3;
}

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin >> n >> k >> r >> s >> p >> t;
	t = '#' + t;
	for (int i = 0; i < N; i++)
		t += '#';
	vector<int> see[k];
	for (int i = 1; i <= k; i++)
	{
		for (int j = i; j <= n; j += k)
		{
			see[i - 1].push_back(x(t[j]));
		}
	}
	int ans = 0;
	for (int i = 1; i <= k; i++)
	{
		for (int j = 0; j < sz(see[i - 1]);)
		{
			int ri = j;
			while (ri < sz(see[i - 1]) && see[i - 1][ri] == see[i - 1][j])
			{
				ri++;
			}
			int num = (ri - j);
			if (see[i - 1][j] == 0)
			{
				ans += p * ((num + 1) / 2);
			}
			else if (see[i - 1][j] == 1)
			{
				ans += r * ((num + 1) / 2);
			}
			else
			{
				ans += s * ((num + 1) / 2);
			}
			j = ri;
		}
	}

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

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

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int[] a=new int[3];
			for(int i=0;i<3;i++) a[i]=sc.nextInt();
			Arrays.sort(a);
			if(a[0]==5 && a[1]==5 && a[2]==7) System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 8788
#include<iostream>
using namespace std;
main(){
	double xy[4][2],p[2],tmp[2];
	int n;
	cin>>n;
	for(int loop=0;loop<n;++loop){
		for(int i=0;i<4;++i){
			for(int j=0;j<2;++j){
				cin>>xy[i][j];
			}
		}
		for(int i=0;i<2;++i){
			tmp[0]=xy[i*2][1]-xy[i*2+1][1];
			tmp[1]=xy[i*2][0]-xy[i*2+1][0];
			p[i]=tmp[0]/tmp[1];
			//cout<<xy[i*2][0]<<" "<<xy[i*2+1][0]<<endl;
		}
		if(p[1]==p[0])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1224
#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 main() {
    string s;
    cin >> s;
    string ans = "Yes";
    for (int i = 1; i <= s.size(); i++) {
        if (i%2 != 0) {
            if (s[i-1] == 'L') ans = "No";
        }
        if (i%2 == 0) {
            if (s[i-1] == 'R') ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		str = br.readLine().split(" ");
		ArrayList<Integer> b = new ArrayList<Integer>();
		for(int i = 0; i < n; i++){
			int a = Integer.parseInt(str[i]);
			if(b.isEmpty() || a != b.get(b.size() - 1)) b.add(a);
		}
		for(int i = 0; i < b.size(); i++){
			System.out.print(b.get(i));
			if(i != b.size() - 1) System.out.print(" ");
		}
		System.out.print("\n");
	}
}



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

using namespace std;

int main(void)
{
	string sa,sb,sc; cin>>sa>>sb>>sc;
	int a,b,c; a = 0; b = 0; c = 0;
	int who = 1;
	while(1){
		if(who == 1){
			// A_tern;
			if(a == sa.size()){
				cout<<"A"<<endl;
				return 0;
			}
			else{
				if(sa[a] == 'a') who = 1;
				else if(sa[a] == 'b') who = 2;
				else who = 3;
				a++;
			}
		}
		else if(who == 2){
			//B_tern
			if(b == sb.size()){
				cout<<"B"<<endl;
				return 0;
			}
			else{
				if(sb[b] == 'a') who = 1;
				else if(sb[b] == 'b') who = 2;
				else who = 3;
				b++;
			}
		}
		else{
			//C_tern
			if(c == sc.size()){
				cout<<"C"<<endl;
				return 0;
			}
			else{
				if(sc[c] == 'a') who = 1;
				else if(sc[c] == 'b') who = 2;
				else who = 3;
				c++;
			}
		}
	}
	return 0;
}



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

int main() {
  int n; //カードの枚数
  cin >> n;
  vector<int> card(n);
  
  for(int i = 0;i < n;i++){
      cin >> card.at(i);
  }
  
  sort(card.begin(),card.end());
  reverse(card.begin(),card.end());
  
  int alice = 0;
  int bob = 0;
  
  for(int i = 0;i < n;i++){
      if(i % 2 == 0){
          alice += card.at(i);
      }else{
          bob += card.at(i);
      }
  }
  
  cout << alice - bob << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
#define N 1000
int main(){
int i,j,k,n,v,A[N];

scanf("%d",&n);
for(i=0;i<n;i++){
  scanf("%d",&A[i]);
}

for(i=0;i<n;i++){
  v = A[i];
  j = i-1;
  while(j>=0 && A[j] > v){
    A[j+1] = A[j];
    j--;
  }
  A[j+1] = v;
  for(k=0;k<n;k++){
    if(k!=n-1) printf("%d ",A[k]);
    else printf("%d\n",A[k]);
  }
}
return 0;
}



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

int main(){
    string s; cin >> s;
    int a, b;
    int ans = 1000;
    for(int i = 0; i < s.size() -2; i++){
        a = (s[i] - '0')*100 + (s[i+1] - '0')*10 + (s[i+2] - '0');
        b = abs(a - 753);
        ans = min(b, ans);
    }
    cout << ans << endl;
}


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

using int64 = long long;
using uint64 = unsigned long long;

const int64 mod = 1e9 + 7;

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

    int n, m;
    std::cin >> n >> m;

    std::vector<int64> x(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i];
        x[i] = (x[i] % mod + mod) % mod;
    }

    std::vector<int64> y(m);
    for (int i = 0; i < m; i++) {
        std::cin >> y[i];
        y[i] = (y[i] % mod + mod) % mod;
    }

    int64 X = 0, sumx = 0,
          Y = 0, sumy = 0;
    for (int i = 1; i < n; i++) {
        (sumx += x[i - 1]) %= mod;
        (X += x[i] * i - sumx + mod) %= mod;
    }

    for (int i = 1; i < m; i++) {
        (sumy += y[i - 1]) %= mod;
        (Y += y[i] * i - sumy + mod) %= mod;
    }

    std::cout << (X * Y) % mod << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int64 n;
    cin >> n;
    int64 res = n + 3;
    for (int64 i = 1; i * i <= n; i++)
    if (n % i == 0){
        res = min(res, i + n / i);
    }
    cout << res - 2;
    return 0;
}


Measured memory_bytes: 256
import sys

N, x = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

ans = 0
tmp_sum = A[0]
for i in range(N-1):
    if A[i] + A[i+1] > x:
        diff = A[i] + A[i+1] - x
        ans += diff
        # 明示的に書かれていないが、A[i] > diff - A[i+i]  はないはず
        A[i+1] = 0 if A[i+1] < diff else A[i+1] - diff

print(ans)

Measured memory_bytes: 63856
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
using namespace std;

const vector<pair<
	pair<int,int>,
	vector<vector<int>>
>>pattern={
	{{9,2},{
		{1,1,1},
		{1,1,1},
		{1,1,1},
	}},
	{{13,3},{
		{0,0,1,0,0},
		{0,1,1,1,0},
		{1,1,1,1,1},
		{0,1,1,1,0},
		{0,0,1,0,0},
	}},
	{{5,1},{
		{0,1,0},
		{1,1,1},
		{0,1,0},
	}},
};

vector<vector<int>>m(10);
vector<pair<pair<int,int>,int>>v;
void dfs(int pat,int y,int x,int N,int d,int s){
	if(d==N){
		if(s==0){
			for(auto &e:v)printf("%d %d %d\n",e.first.first,e.first.second,e.second);
			exit(0);
		}
	}
	if(s<(N-d)*5 || (N-d)*13<s)return;
	for(;pat<pattern.size();pat++,y=x=0)if(pattern[pat].first.first<=s){
		for(;y<=10-pattern[pat].second.size();y++,x=0){
			for(;x<=10-pattern[pat].second[0].size();x++){
				for(int dy=0;dy<pattern[pat].second.size();dy++){
					for(int dx=0;dx<pattern[pat].second[0].size();dx++){
						if(m[y+dy][x+dx]<pattern[pat].second[dy][dx])goto fail;
					}
				}
				for(int dy=0;dy<pattern[pat].second.size();dy++){
					for(int dx=0;dx<pattern[pat].second[0].size();dx++){
						m[y+dy][x+dx]-=pattern[pat].second[dy][dx];
					}
				}
				v[d]=make_pair(
					make_pair(x+pattern[pat].second[0].size()/2,y+pattern[pat].second.size()/2),
					pattern[pat].first.second
				);
				dfs(pat,y,x,N,d+1,s-pattern[pat].first.first);
				for(int dy=0;dy<pattern[pat].second.size();dy++){
					for(int dx=0;dx<pattern[pat].second[0].size();dx++){
						m[y+dy][x+dx]+=pattern[pat].second[dy][dx];
					}
				}
				fail:;
			}
		}
	}
}

int main(){
	int N,y,x,s=0,z;
	scanf("%d",&N);
	for(y=0;y<10;y++){
		m[y].resize(10);
		for(x=0;x<10;x++)scanf("%d",&m[y][x]),s+=m[y][x];
	}
	v.resize(N);
	dfs(0,0,0,N,0,s);
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[200001]={};
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  int max=a[1]-a[0];
  int min=a[0];
  for(int i=1;i<n;i++){
      if(a[i]-min>max)max=a[i]-min;
      if(min>a[i])min=a[i];
  }
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 1948
#include<stdio.h>
int A[1000000], n;

int binarySearch(int key){
  int left = 0;
  int right =  n;
  int mid;

  while(left<right){
    mid = (left +right)/ 2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid +1;//右半分を操作
    else if(key<A[mid])right = mid;//左半分を操作
  }
  return 0;
}

int main(){
  int i ,q,key, sum =0;

  scanf("%d",&n);//要素数を入力
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &key);
    if(binarySearch(key)) sum++;
  }
  printf("%d\n",sum);

  return 0;

  }





Measured memory_bytes: 2172
//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#include <set> 
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 100000000000000
#define endl "\n"
#define precise(x) fixed << setprecision(x) 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int MOD =1000000007;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 ll mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}
 //ll power(ll x, ll y) 
//{ 
  //  ll temp; 
    //if( y == 0) 
     //   return 1; 
    //temp = power(x, y/2); 
    //temp=temp%MOD;
    //if (y%2 == 0) 
     //   return (temp%MOD)*(temp%MOD); 
    //else
      //  return (x%MOD)*(temp%MOD)*(temp%MOD); 
//} 
 
 
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=2e5+100;
 

int main()
{
	ios_base::sync_with_stdio(0);
   cin.tie(0);
    cout.tie(0);
     ll t;
   //cin>>t;
   
   t=1;	
   while(t--)
    {
        ll i1,i2,k,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,m,n;
        ll x,y,z;
        ll total=0,cnt=0;
        ll flag=0;
        y=0;
        ll res,res1,ans,res2,q;
        ans=0;
        res1=0,res=0;
        ll s1,s2,s3;
        s2=0;
        ll flag1=0;
        s1=0;
        ll k1,k2,k3;
        k1=0,k2=0;
        ll d,required,days,h,w;
        //cin>>h>>c>>required;
         cin >> n>>k;
          ll a[n+1];
          for(i=1;i<=n;i++) cin>>a[i];
          
          ll dp[n+1][k+1];
          dp[0][0]=1;
          for(i=1;i<=k;i++) dp[0][i]=0;
          
          for(i=1;i<=n;i++)
          {
          	 vector<ll> sum(k+1);
          	 sum[0]=dp[i-1][0];
          	 for(j=1;j<=k;j++)
          	 {
          	 	sum[j]=(sum[j-1]+dp[i-1][j])%MOD;
			   }
			   for(j=0;j<=k;j++)
			   {
			   	  if(j<=a[i])
			   	  {
			   	  	 dp[i][j]=sum[j];
					 }
					 else
					 {
					 	x=j-a[i]-1;
					 	dp[i][j]=(sum[j]-sum[x]+MOD)%MOD;
					 }
			   }
			   sum.clear();
		  }
		  cout<<dp[n][k]<<endl;
    
     }
    
}
	

Measured memory_bytes: 79984
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

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

typedef long long ll;
typedef pair<ll, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
ll A[100000], B[100000];

P D[100000];
void solve(){
	rep(i, N){
		D[i] = P(A[i] + B[i], i);
	}
	sort(D, D + N, greater<P>());
	ll ans = 0;
	rep(i, N){
		if(i % 2 == 0)
		ans += A[D[i].second];
		else
		ans -= B[D[i].second];
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> A[i] >> B[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 3328
using System;

namespace ITP1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input);

            for (int j=1; j<=n; j++)
            {
                int a = j % 3;

                if (a == 0)
                    Console.Write(" {0}", j);
                else
                {
                    int b = j;
                    while (b > 0)
                    {
                        if (b % 10 == 3)
                        {
                            Console.Write(" {0}", j);
                            break;
                        }
                        else
                        {
                            b /= 10;
                        }
                    }
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9332
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;


int main() {
    int N;
    cin >> N;

    int max = 0;
    int res = 0;
    for (int n = 0; n < N; n++) {
        int H;
        cin >> H;

        if (H >= max) {
            res++;
            max = H;
        }
    }

    cout << res << endl;


    return 0;
}


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

int main() {
    int a, b, c, d;

    cin >> a >> b >> c >> d;
    if (a >= d) {
        cout << d << endl;
    }
    else if (a + b >= d) {
        cout << a << endl;
    }
    else {
        
        cout << a-(d - a - b) << endl;
    }

    return 0;
}

Measured memory_bytes: 3656
N=int(input())
X=[]
Y=[]
for i in range(N):
  x,y=map(int,input().split())
  X +=[x]
  Y +=[y]
L=0#全点同士の距離の合計
for i in range(N-1):
  for j in range(i+1,N):
    L+= (((X[i]-X[j])**2)+((Y[i]-Y[j])**2))**0.5
    
print(L*2/N)

Measured memory_bytes: 3188
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)
#define pb push_back
 
using namespace std;
const int N=305,M=4510005,mod=1000000007;
int n,m,id[N][N][N],tp,f[2][M],vis[M],nw,tot,ans;
struct data{int l,x;};
vector <data> vt[N];
 
int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}
 
void inc(int x,int y)
{
	if(vis[x]!=nw) f[tp][x]=0,vis[x]=nw;
	f[tp][x]=(f[tp][x]+y)%mod;
}
 
int main()
{
	n=getint(),m=getint();
	rep(i,1,m)
	{
		int l=getint(),r=getint(),x=getint();
		vt[r].pb((data){l,x});
	}
	memset(vis,-1,sizeof(vis));
	rep(i,0,n) rep(j,0,max(0,i-1)) rep(k,0,max(0,j-1)) id[i][j][k]=++tot;
	f[0][id[0][0][0]]=1,vis[id[0][0][0]]=0;
	rep(i,1,n)
	{
		tp^=1,nw=i;
		rep(x,i-1,i-1)
			rep(y,0,max(0,x-1))
				rep(z,0,max(0,y-1))
					if(vis[id[x][y][z]]==i-1)
					{
						int tmp=f[tp^1][id[x][y][z]];
						inc(id[i][y][z],tmp);
						inc(id[i][x][z],tmp);
						inc(id[i][x][y],tmp);
					}
		rep(x,i,i)
			rep(y,0,max(0,x-1))
				rep(z,0,max(0,y-1))
				{
					int sz=vt[i].size();
					bool jdg=0;
					rep(j,0,sz-1)
					{
						int l=vt[i][j].l;
						int t=(x>=l)+(y>=l)+(z>=l);
						if(t!=vt[i][j].x) {jdg=1; break;}
					}
					if(jdg) vis[id[x][y][z]]=-1;
				}
	}
	rep(i,1,tot) if(vis[i]==n) ans=(ans+f[tp][i])%mod;
	printf("%d\n",ans);			
	return 0;
}

Measured memory_bytes: 162432
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long N){
    cout<<RUP(N,2)<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const n: number = tmp[0].split(" ").map(int => parseInt(int))[0];
    const p: number[] = tmp[1].split(" ").slice(0, n).map(int => parseInt(int));
    const pCopy: number[] = [].concat(p);
    pCopy.sort((a, b) => a - b);
    let count: number = 0;
    for (let i = 0; i < n; i++) {
      if (p[i] != pCopy[i]) {
        count++;
      }
    }
    return `${count == 0 || count == 2 ? "YES" : "NO"}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};



int main(){
  int N;
  cin >> N;
  double a[N];
  rep(i,N){
    cin >> a[i];
  }
  double sum = 0;
  double pro;
  rep(i,N){
    sum += 1/a[i];
  }
  printf("%.10lf\n",1/sum);
}



Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n; long long x, a[1009], b[1009], c[1009], d[1009], e[1000009], f[1000009], g[1000009], cnt[1000009];
int main() {
	scanf("%d%lld", &n, &x);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
	for (int i = 0; i < n; i++) scanf("%lld", &c[i]);
	for (int i = 0; i < n; i++) scanf("%lld", &d[i]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			e[i * n + j] = a[i] + b[j];
			f[i * n + j] = c[i] + d[j];
		}
	}
	sort(e, e + n * n);
	sort(f, f + n * n);
	int p = 0, s = 0;
	for (int i = 1; i <= n * n; i++) {
		if (i == n * n || f[i - 1] != f[i]) {
			g[s] = f[i - 1];
			cnt[s++] = i - p;
			p = i;
		}
	}
	int r = s - 1; long long ret = 0;
	for (int i = 0; i < n * n; i++) {
		while (e[i] + g[r] > x) r--;
		if (e[i] + g[r] == x) ret += cnt[r];
	}
	printf("%lld\n", ret);
	return 0;
}

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

using namespace std;

#define int long long

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

typedef vector<int> VI;
typedef pair<int, int> PII;

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

int N;
string S;

bool s[200000];

signed main(){

    cin >> S;
    N = S.size();

    REP(i, N){
        s[i] = S[i] - '0';
    }

    int ans = 0;
    int now = 0;

    REP(i, N){
        if(i % 2 == 0){
            if(s[i] == 0){
                now++;
            }
        }
        else{
            if(s[i] == 1){
                now++;
            }
        }
    }

    ans = now;
    now = 0;

    REP(i, N){
        if(i % 2 == 0){
            if(s[i] == 1){
                now++;
            }
        }
        else{
            if(s[i] == 0){
                now++;
            }
        }
    }

    cout << min(ans, now) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007


int main() {
  int N,X;
  cin >> N >> X;
  int a,m=10000;

  rep(i,N){
    cin >> a;
    X -= a;
    m = min(m,a);
  }

  int ans = N;
  while(X >= m){
    X -= m;
    ans++;
  }

  cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll r;
    cin >> r;
    out(3*r*r);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
ll gcd(ll a,ll b){
  ll r = a%b;
  while(r > 0){
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
vector<bool> prime(1111111,true);
void make_prime(){
  prime[0]=prime[1]=false;
  for(ll i=0;i<1111111;i++){
    if(prime[i]==false)continue;
    for(ll j=2*i;j<1111111;j+=i){
      prime[j]=false;
    }
  }
}

ll cnt[1111111]={};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  ll g = 0;
  make_prime();
  vi pri;
  bool fl = true;
  for(int i=2;i<=sqrt(1111111);i++)
    if(prime[i])pri.pb(i);
  for(auto &a:A){
    cin>>a;
    if(g == 0)g = a;
    else g = gcd(g,a);
    for(auto p:pri){
      if(a%p == 0){
	cnt[p]++;
	while(a%p == 0)a/=p;
	if(cnt[p]==2){
	  fl = false;
	}
      }
    }
    if(a > 1){
      cnt[a]++;
      if(cnt[a]==2)fl=false;
    }
  }

  if(g > 1){cout<<"not coprime"<<endl;return 0;}
  if(fl)cout<<"pairwise coprime"<<endl;
  else cout<<"setwise coprime"<<endl;
  return 0;
}


Measured memory_bytes: 18940
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define lowbit(x) ((x) & -(x))
#define gr(a, b) ((a) > (b) ? 1 : (a) == (b) ? 0 : -1)
using namespace std;

int n;
int a[100010];
int c[200010];
char check(const int &x);
void insert(const int &x);
int query(const int &x);

int main() {
	scanf("%d", &n);
	int l = 1000000000, r = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		l = min(l, a[i]), r = max(r, a[i]);
	}
	
	while (l <= r) {
		int m = l + r >> 1;
		if (check(m))
			l = m + 1;
		else
			r = m - 1;
	}
	printf("%d\n", r);
	return 0;
}

char check(const int &x) {
	int sum = 0;
	long long tot = 0;
	memset(c, 0, sizeof(c));
	insert(0);
	for (int i = 0; i < n; ++i) {
		sum += a[i] >= x ? 1 : -1;
		tot += query(sum);
		insert(sum);
	}
	return tot << 2 >= 1ll * n * (n + 1);
}

void insert(const int &x) {
	for (int i = x + n + 1; i <= (n << 1 ^ 1); i += lowbit(i))
		++c[i];
}

int query(const int &x) {
	int ret = 0;
	for (int i = x + n + 1; i > 0; i -= lowbit(i))
		ret += c[i];
	return ret;
}



Measured memory_bytes: 4996
//00
#include<iostream>

using namespace std;

int m,n;
int ice[90][90];

int dfs(int y,int x){
  if(0<=y&&y<m&&0<=x&&x<n&&ice[y][x]){
    ice[y][x]=0;
    int r=0;
    for(int i=0;i<4;i++){
      static const int d[]={0,1,0,-1,0};
      r=max(r,dfs(y+d[i],x+d[i+1]));
    }
    ice[y][x]=1;
    return r+1;
  }else{
    return 0;
  }
}
    
int main(){
  while(cin>>m>>n,m|n){
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	cin>>ice[i][j];
      }
    }
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	ans=max(ans,dfs(i,j));
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
m = a[0]
ans = a[0]
if a[0]%2 == 0:
    b = a[0]//2
    for i in range(n):
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)

else:
    b = a[0]//2 + 0.5
    for i in range(n):
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)


Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
long long inf = pow(10, 9);

int n, a[81];
int main(){
    cin >> n;
    rep(i, n) cin >> a[i];
    long long res = 1000;
    rep(i, n - 1){
        if(a[i] < a[i + 1]) res += (res / a[i]) * (a[i + 1] - a[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 3644