akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
#define int long long
signed main() {
    int N, A, B; cin >> N >> A >> B;
    vector<int>X(N);
    long long ans = 0;
    rep(i, N) {
        cin >> X[i];
        if(i!=0) {
            if ((X[i] - X[i - 1]) * A > B)ans += B;
            else ans += (X[i] - X[i - 1]) * A;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4000
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n,m,s,t;
vector<vector<ll>> edge;

void dijk(ll s,vector<ll> &dp){
    dp.resize(n);
    for(auto &i:dp){i=E;}
    dp[s]=0;
    priority_queue<pll,vector<pll>,greater<pll>> Q;
    Q.push({0,s});
    while(!Q.empty()){
        pll w=Q.top(); Q.pop();
        if(dp[w.S]!=w.F){continue;}
        for(auto &i:edge[w.S]){
            if(dp[i]>dp[w.S]+1){
                dp[i]=dp[w.S]+1;
                Q.push({dp[i],i});
            }
        }
    }
}


int main(){
    cin>>n>>m>>s>>t;
    edge.resize(n);
    for(int i=0;i<m;i++){
        ll u,v;
        cin>>u>>v;
        u--; v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    s--; t--;
    vector<ll> dp,dp2;
    dijk(s,dp);
    dijk(t,dp2);
    map<ll,ll> M,M2;
    for(auto &i:dp){M[i]++;}
    for(auto &i:dp2){M2[i]++;}
    ll ans=0;
    ll dist=dp[t];
    for(int i=0;i<n;i++){
        ans+=M[i]*M2[dist-i-2];
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 23916
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define FI first
#define SE second
#define PB(a) push_back(a)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
#define SZ(x) ((int)(x).size())
#define SO(x) sizeof((x)) / sizeof((x)[0])
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline int in() {int x; cin >> x; return x;}
inline lint IN() {lint x; cin >> x; return x;}
inline void co(int a[], int n) {REP(i, n) cout << a[i] << " "; cout << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	
	int n = in();
	REP(i,n/4+1){
		REP(j,n/7+1){
			//cout << i << ":" << j << "\n";
			if ((i*4+j*7) == n){
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	//cout << "Hello World" << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,c=0,n,p=0,g,j,r;
    int a[1000]= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cin>>n;
    /* for(i=1; i<g; i++)
                 for(j=0; j<g-i; j++)
                     if(a[j]>a[j+1])
                     {
                         r=a[j];
                         a[j] = a[j+1];
                         a[j+1]=r;

                     }









    cout<<a<<endl;*/




    for(i=0;; i++)
    {



        c++;
        if(c==n)
        {

            cout<<a[i]<<endl;
            break;
        }


    }







    return 0;
}


Measured memory_bytes: 256
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define int long long

using namespace std;

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

const int N = 600000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

pii adj[N];
int a[4][N], n, ind[N], rev[N], fen[N], L[N], R[N];

void add(int id, int x){
	for (id; id < N; id += (id) & (-id)) fen[id] += x;
}

int get(int id){
	int res = 0;
	for(; id > 0; id -= id & (-id)) res += fen[id];
	return res;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= 3; j++){
			for (int k = 1; k <= 3; k++){
				if (k == j) continue;
				if (adj[(i - 1) * 3 + j].F == 0) adj[(i - 1) * 3 + j].F = (i - 1) * 3 + k;
				else adj[(i - 1) * 3 + j].S = (i - 1) * 3 + k;
			}
		} 
	}
	for (int i = 1; i <= 3; i++){
		for( int j = 1; j <= n; j++) cin >> a[i][j];
	}
//	for (int i = 1; i <= 3; i++){
//		for (int j = 1; j <= n; j++) cout << a[i][j] << ' ';
//		cout << '\n';
//	}
//	cout << a[3][4] << '\n';
	for (int j = 1; j <= n; j++){
		vi Nw;
//		if (j == 4) cout << a[1][j] << ' ' << a[2][j] << ' ' << a[3][j] << '\n';
//		cout << a[3][4] << '\n';
		for (int i = 1; i <= 3; i++) Nw.pb(a[i][j]);
		vi NN;
		NN.pb(a[1][j]);
		NN.pb(adj[a[1][j]].F);
		NN.pb(adj[a[1][j]].S);
		sort(all(Nw));
		sort(all(NN));
//		cout << a[3][4] << '\n';
//		cout << j << '\n';
//		if (j == 4) for (int j = 0; j < 3; j++) cout << Nw[j] << ' ' << NN[j] << '\n';
		for( int i = 0; i < 3; i++) if (Nw[i] != NN[i]) return cout << "No", 0;
		if (a[2][j] != ((a[1][j] - 1) / 3) * 3 + 2) return cout << "No", 0;
		if (((a[1][j] - 1) / 3 + 1) % 2 != j % 2) return cout << "No", 0;
//		cout << a[3][4] << '\n';
		ind[(a[1][j] - 1) / 3 + 1] = j;
		rev[(a[1][j] - 1) / 3 + 1] = (a[1][j] != ((a[1][j] - 1) / 3 * 3 + 1));	
	}
	int inv = 0, cnt = 0;
	for (int i = 1; i <= n; i += 2){
		inv += get(n) - get(ind[i]);
		L[i] = get(n) - get(ind[i]);
		add(ind[i], 1);
	}
	memset(fen, 0, sizeof fen);
	for (int i = n - ((n - 1) % 2); i >= 1; i -= 2){
		R[i] = get(ind[i]);
		add(ind[i], 1);
	}	
	for (int i = 1; i <= n; i += 2){
		int sm = L[i] + R[i];
		cnt += (sm + rev[i]) % 2;
	}
	memset(fen, 0, sizeof fen);
	int inv2 = 0, cnt2 = 0;
	for (int i = 2; i <= n; i += 2){
		inv2 += get(n) - get(ind[i]);
		L[i] = get(n) - get(ind[i]);
		add(ind[i], 1);
	}
	memset(fen, 0, sizeof fen);
	for (int i = n - (n % 2); i >= 2; i -= 2){
		R[i] = get(ind[i]);
		add(ind[i], 1);
	}
	for (int i = 2; i <= n; i += 2){
		int sm = L[i] + R[i];
		cnt2 += (sm + rev[i]) % 2;
	}
	if ((inv % 2 == cnt2 % 2) && (inv2 % 2 == cnt % 2)) return cout << "Yes", 0;
	cout << "No";




	return 0;
}


Measured memory_bytes: 18488
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 3;
vector<int> g[MAXN];
vector<int> indeg(MAXN, 0);
vector<int> depth(MAXN, -1);

int ans = 0;
int dfs(int u, int d)
{
    if (depth[u] != -1)
        return depth[u];
    for (int v : g[u])
    {
        depth[u] = max(depth[u], 1 + dfs(v, d + 1));
    }
    return depth[u];
}

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int root = 0;
    int x, y;
    for (int i = 0; i < m; i++)
    {
        scanf("%d %d", &x, &y);
        indeg[y]++;
        g[x].push_back(y);
    }

    for (int i = 1; i <= n; i++)
        if (!indeg[i])
        {
            indeg[i]++;
            g[root].push_back(i);
        }

    // ans = dfs(0, 0);
    queue<pair<int, int>> q;
    q.push({root, 0});
    while (!q.empty())
    {
        int u = q.front().first;
        int d = q.front().second;
        q.pop();
        ans = max(ans, d);
        for (int v : g[u])
        {
            if (!(--indeg[v]))
            {
                q.push({v, 1 + d});
            }
        }
    }
    printf("%d\n", ans - 1);
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    
    cin >> a >> b >> c >> d;
    if((a + d - 1) /d < (c + b - 1) /b) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

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

    vector<double> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }

    vector<vector<double>> dp(n+1 ,vector<double>(n+1));
    dp[0][0] = 1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=i+1; j++){
            if(j >= 1) dp[i+1][j] += dp[i][j-1] * p[i];
            dp[i+1][j] += dp[i][j] * (1 - p[i]);
        }
    }

    double ans = 0;
    for(int i=n/2+1; i<=n; i++){
        ans += dp[n][i];
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

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

void PrintOutput(char* output)
{
    printf("%s", output);
}

void JudgeSafety(int sheepInput, int wolfInput)
{
    char output[10];
    
    if(wolfInput >= sheepInput)
    {
        strcpy(output, "unsafe");
    }
    else
    {
        strcpy(output, "safe");
    }
    
    printf("%s \n", output);
}
    
void ReadInput()
{
    int sheepInput, wolfInput;
    //printf("Enter the number of sheeps and wolves: \n");
    scanf("%d %d",&sheepInput, &wolfInput);
    JudgeSafety(sheepInput, wolfInput);
}

int main(int argc, const char * argv[])
{
    ReadInput();

    return 0;
}


Measured memory_bytes: 1668
#abc123b

l,ll,m=[],[],[]
for i in xrange(5):
 l.append(int(raw_input()))
for i in xrange(5):
 m.append(l[i]%10)
s=130
idx=0
for i in xrange(5):
 if m[i]!=0:
  if m[i]<s:
   idx=i
   s=m[i]
for i in xrange(5):
 ll.append((l[i]+9)//10*10)
print sum(ll)-ll[idx]+l[idx]


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N;
  IN(N);
  vll H(N);
  REP(i,N) IN(H[i]);

  bool flag = true;
  RREP(i,N-2){
    ll pos = i+1;
    if(H[pos]<H[pos-1]) H[pos-1]--;
    if(H[pos]<H[pos-1]) flag = false;
  }

  if(flag){
    OUT("Yes");
  }else{
    OUT("No");
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a[n];
    rep(i,n){
        a[i] = s[i] - '0';
        a[i]--;
    } 

    int two[n] = {};
    srep(i,1,n){
        two[i] = two[i-1];
        int cnt = 0;
        int ii = n - i;
        while(ii%2==0){
            two[i]++;
            ii /= 2;
        }
        ii = i;
        while(ii%2==0){
            two[i]--;
            ii /= 2;
        }
    }
    rep(i,n/2){
        two[n-1-i] = two[i];
    }
    rep(i,n){
        if(two[i] == 0) two[i] = 1;
        else two[i] = 0;
    }
    ll flag = 0;
    rep(i,n){
        if(a[i] == 1){
            flag += two[i];
            flag %= 2;
        }
    }

    if(flag){
        cout << 1 << endl;
        return 0;
    }

    rep(i,n){
        if(a[i] == 1){
            cout << 0 << endl;
            return 0;
        }
    }

    flag = 0;
    rep(i,n){
        if(a[i] == 2){
            flag += two[i];
            flag %= 2;
        }
    }

    if(flag){
        cout << 2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}




Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long

int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0}
#define fr(n) for(int i=1;i<=n;i++)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define dbg(x) {cout<<"ekhane"<<x<<endl;}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define M 100005
//////////////////////////////////////////

map<int,int>mp;

int main() {

    int n=Int;
    set<int>s1;
    int a[n+1];
    fr(n) {
    s1.insert(a[i]=Int);
    mp[a[i]]++;
    }

    int ans=0;

    set<int>::iterator it=s1.begin();

    while(it!=s1.end()){
        int d=mp[*it];
        if(d<*it) ans+=d;
        else ans+=(d-*it);
        it++;
    }
    printf("%d\n",ans);
    return 0;
}





Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)2147483647;

int main() {
    int N,K; cin >> N >> K;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int dp[N+1000];
    dp[0]=0;
    vector<int> h(N);
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        h[i]=x;
    }
  	for(int i=1;i<N+1000;i++){
      dp[i]=INF;
    }
    for(int i=0;i<N;i++){
      	for(int j=i+1;j<i+K+1;j++){
          dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }
    cout << dp[N-1] << endl;
    


}

/*



 */



Measured memory_bytes: 1024
n,k = map(int,input().split())
a = list(map(int,input().split()))
imos = [0]*(2*10**5+1)
for j in range(min(k,100)):
    imos = [0]*(2*10**5+1)
    for i in range(n):
        imos[max(i-a[i],0)] += 1
        imos[min(i+a[i]+1,2*10**5)] -= 1
    for i in range(1,n):
        imos[i] += imos[i-1]
    a = imos
print(*imos[:n])


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

int main(){

  int n, m, ans;

  cin>>n>>m;
  ans=m;
  for(int i=0;i<n;i++){
    int a, b;
    cin>>a>>b;
    m=m+a-b;
    if(m<0){
      ans=0;
      break;
    }
    ans=max(ans, m);
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k;
    cin >> k;
    if(k % 2 == 0) cout << pow(k / 2, 2) << endl; 
    if(k % 2 != 0) cout << k / 2 * (k / 2 + 1) << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
int n;
ll a[maxn];
bool cmp(ll a,ll b){
    return abs(a)>abs(b);
}
int main()
{
    scanf("%d",&n);
    ll ans=0;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+n+1,cmp);
    int cs=0;
    for(int i=1;i<n;i++){
        if(a[i]>0)ans+=a[i];
        else if(a[i]<0)ans+=abs(a[i]),cs++;
        else break;
    }
    if(a[n]>0){
        if(cs%2==0)ans+=a[n];
        else ans-=a[n];
    }
    if(a[n]<0){
        if(cs%2==0)ans+=a[n];
        if(cs%2==1)ans+=abs(a[n]);
    }
    printf("%lld\n",ans);

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
ll a[40001000];
//ll number[20],used[20];
int main()
{
    ll n,i,j,c=0,t=0,k;
    cin>> n >> k;
    for(i=0; i<k; i++)
        cin>> a[i];
    ll w = n;
    ll y = n;
    while(1)
    {
        c=0;t=0;
        for(i=0;i<k;i++)
        {
           // cout << w << " " << y << endl;
            if(w==a[i])
                c++;
            if(y==a[i])
                t++;
        }
       // cout << c << " " << t << endl;
        if(c==0 && t==0)
        {
            cout << y << endl; break;
        }
        else if(c==0){
            cout << w << endl; break;
            }
        else if(t==0){
            cout <<  y << endl; break;}
        w++;
        y--;
    }
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100005][2][2][2]={0};

ll n;

ll h[100005][4]={0};

ll rec(ll i,ll a,ll b,ll c)
{


    if(i>n)
        return 0;

     if(dp[i][a][b][c]!=0)
        return dp[i][a][b][c];
        ll  A,B,C;
        A=INT_MIN;
        B=INT_MIN;
        C=INT_MIN;

        if(a==1)
           A = rec(i+1, 0 , 1 , 1) + h[i][0];
        if(b==1)
           B = rec(i+1, 1, 0, 1) + h[i][1];
        if(c==1)
           C = rec(i+1, 1, 1, 0) + h[i][2];
        ll maxi = max(B,C);
        dp[i][a][b][c]=max(A,maxi);
        return dp[i][a][b][c];
}

int main()
{

    cin>>n;
    for(ll i=1;i<=n;i++)
        for(ll j=0;j<3;j++)
        cin>>h[i][j];

    ll ans = rec(1,1,1,1);
    cout<<ans;
}




Measured memory_bytes: 15872
import java.util.*;

public class Main {
	static long[] arrX;
	static long[] arrY;
	static int n;
	static int k;

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		arrX = new long[n];
		arrY = new long[n];
		for (int i = 0; i < n; i++) {
			arrX[i] = sc.nextLong();
			arrY[i] = sc.nextLong();
		}
		long min = Long.MAX_VALUE;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				for (int k = 0; k < n - 1; k++) {
					for (int l = k + 1; l < n; l++) {
						long sqr = Math.abs(arrX[i] - arrX[j]) * Math.abs(arrY[k] - arrY[l]);
						if (sqr > min) {
							continue;
						}
						if (isOver(Math.min(arrX[i], arrX[j]), Math.max(arrX[i], arrX[j]), Math.min(arrY[k], arrY[l]), Math.max(arrY[k], arrY[l]))) {
							min = sqr;
						}
					}
				}
			}
		}
		System.out.println(min);
	}
	
	static boolean isOver(long x1, long x2, long y1, long y2) {
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (arrX[i] >= x1 && arrX[i] <= x2 && arrY[i] >= y1 && arrY[i] <= y2) {
				count++;
			}
		}
		return (count >= k);
	}
	
}


Measured memory_bytes: 25300
# coding: utf-8
n = int(input())
p = list(map(int,input().split()))
count = 0
list_base = []
index = []
for i in range(n):
    list_base.append(i+1)

for i in range(n):
    if list_base[i] != p[i]:
        count += 1

if count == 2 or count == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=-1){
		double a=1.0,b=1.0,t,c,d;n-=2;
		while(n--){
			t=1.0/(a*a+b*b);
			t=(double)sqrt((double)t);
			c=a-b*t,d=b+a*t;
			a=c,b=d;
		}
		cout<<fixed<<setprecision(10)<<a<<endl;
		cout<<fixed<<setprecision(10)<<b<<endl;
	}
	return 0;
}

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

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

    bool can[N]; // canがtrueなら其番目の数は条件を満たす。
    for (int i = 0; i < N; i++) {
        can[i] = false;
    }

    int min = P[0]; // 各iに対してi番目以前の順列中の最小値を取る。

    for (int i = 0; i < N; i++) {
        if (P[i] <= min) {
            can[i] = true;
            min = P[i];
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (can[i]) ans ++;
    }

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

Measured memory_bytes: 1280
#include <stdio.h>


int main(void){
	int x1,y1,x2,y2,x3,y3,x4,y4;
	int vecx,vecy;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	vecx = x2-x1;
	vecy = y2-y1;
	x3 = x2 - vecy;
	y3 = y2 + vecx;
	x4 = x3 - vecx;
	y4 = y3 - vecy;
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int p, m;

	void run(){
		for(;;){
			p=sc.nextInt();
			m=sc.nextInt();
			if((p|m)==0){
				break;
			}
			solve();
		}
	}

	void solve(){
		long n1=0, d1=1;
		long n2=m, d2=1;
		for(long d=1; d<=m; d++){
			double left=1, right=m;
			for(int i=0; i<100; i++){
				double mid=(left+right)/2;
				if(mid*mid<p*d*d+EPS){
					left=mid;
				}else{
					right=mid;
				}
			}
			int n=(int)(left+EPS);
			if(n1*d<n*d1&&n*n<p*d*d){
				n1=n;
				d1=d;
			}
			if(++n<=m){
				if(p*d*d<n*n&&n*d2<n2*d){
					n2=n;
					d2=d;
				}
			}
		}
		long gcd=gcd(n1, d1);
		n1/=gcd;
		d1/=gcd;
		gcd=gcd(n2, d2);
		n2/=gcd;
		d2/=gcd;
		println(n2+"/"+d2+" "+n1+"/"+d1);
	}

	long gcd(long m, long n){
		for(; n!=0;){
			m=m%n;
			long t=m;
			m=n;
			n=t;
		}
		return m;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
while true do
    i = gets
    a = i.split[0].to_i
    b = i.split[2].to_i
    o = i.split[1]
    break if o == "?"
    print a + b, "\n" if o == "+"
    print a - b, "\n" if o == "-"
    print a * b, "\n" if o == "*"
    print a / b, "\n" if o == "/"
end


Measured memory_bytes: 6864
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

string FMT_F = "%.10f";

T RD(T = long)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD!string;

	long[2] cnt;
	foreach (c; S)
	{
		++cnt[[c].to!long];
	}

	writeln(min(cnt[0], cnt[1]) * 2);
	stdout.flush();
}

Measured memory_bytes: 3480
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s, t;
    while(cin >> s)
    {
        if(s == ".") break;
        cin >> t;
        if(s == t)
        {
            cout << "IDENTICAL" << endl;
            continue;
        }
        bool flag = true;
        vector<string> v, w;
        int left, right;
        while((left = s.find('"')) != -1)
        {
            right = s.find('"', left + 1);
            v.push_back(s.substr(left, right - left + 1));
            s.replace(left, right - left + 1, "#");
        }
        while((left = t.find('"')) != -1)
        {
            right = t.find('"', left + 1);
            w.push_back(t.substr(left, right - left + 1));
            t.replace(left, right - left + 1, "#");
        }
        int cnt = 0;
        for(int i = 0; i < min(v.size(), w.size()); i++) if(v[i] != w[i]) cnt++;
        if(cnt < 2 && s == t) cout << "CLOSE" << endl;
        else cout << "DIFFERENT" << endl;
    }
	return 0;
}




Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd

X = int(input())

maxi = 125
mini = -125

for a in range(mini, maxi):
    for b in range(mini, maxi):
        if a**5 - b**5 == X:
            print("{} {}".format(a, b))
            sys.exit()



Measured memory_bytes: 27056
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N];
int cnt[N];
int mini , maxi;
int main(){
	scanf("%d" , &n);
	mini = n;
	maxi = 0;
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
		++cnt[arr[i]];
		maxi = max(maxi , arr[i]);
		mini = min(mini , arr[i]);
	}
	if(maxi - mini > 1){
		printf("No\n");
		return 0;
	}
	if(maxi == mini){
		if(maxi == n - 1){
			printf("Yes\n");
			return 0;
		}
		if(maxi <= (n >> 1)){
			printf("Yes\n");
			return 0;
		}
		printf("No\n");
		return 0;
	}
	if(cnt[1] > 1){
		printf("No\n");
		return 0;
	}
	if(maxi == n - 1){
		if(cnt[maxi] > 2){
			printf("No\n");
			return 0;
		}
	}
	if(cnt[mini] >= maxi){
		printf("No\n");
		return 0;
	}
	if((maxi - cnt[mini]) * 2 <= cnt[maxi]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, l;
  cin >> n >> l;
  int a[n];
  int pi = 0;
  int mina = 10e9;
  
  for(int i = 0; i < n; i++) {
    a[i] = l + i;
    pi += a[i];
    mina = min(mina, abs(a[i]));
  }
  if(a[n - 1] < 0) {
    mina = -mina;
  }
  cout << pi - mina << endl;
}
  
  

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

int main(){
	
	ios::sync_with_stdio(false);
	
	int a,b, sum, min, mult;
	cin >> a >> b;
	
	sum = a + b;
	min = a - b;
	mult = a * b;

	cout << max( {sum, min, mult} ) << endl;

	return 0;
}

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

#define mk(a,b) make_pair(a,b)
#define se second
#define fi first

typedef pair<int,int> pii;

int N;
vector<int> G[100010];
char K[100010];
bool need[100010];
int ans = 0,MAX = 0;
int num[100010];

int judge(int v)//かかる
{
    if((num[v] % 2 && K[v] == 'B') || (num[v] % 2 == 0 && K[v] == 'W'))return 1;
    return 0;
}

pii unit(int v,int p)
{
    pii res = mk(0,v);
    for(int i = 0; i < G[v].size(); i++)
    {
        int w = G[v][i];
        if(w == p || !need[w])continue;
        res = max(res,unit(w,v));
    }
    res.fi += judge(v);
    return res;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 1; i <= N; i++)scanf(" %c",K + i);

    for(int i = 1; i <= N; i++)num[i] = G[i].size();

    memset(need,true,sizeof(need));
    for(int i = 1; i <= N; i++)if(need[i])
    {
        if(num[i] == 1 && K[i] == 'B')
        {
            num[i]--;
            need[i] = false;
            int now = G[i][0];
            num[now]--;
            while(K[now] == 'B' && need[now])
            {
                int cnt = 0,tmp;
                if(num[now] == 1)
                {
                    for(int j = 0; j < G[now].size(); j++)if(need[G[now][j]])tmp = j;
                    num[now]--;
                    need[now] = false;
                    now = G[now][tmp];
                    num[now]--;
                }
                else break;
            }
        }
    }

    int cnt = 0;
    int mem[2] = {0};
    for(int i = 1; i <= N; i++)if(need[i])
    {
        cnt++;
        if(mem[0] == 0)mem[0] = i;
        else if(mem[1] == 0)mem[1] = i;
        int edge = 0;
        for(int j = 0; j < G[i].size(); j++)if(need[G[i][j]])edge++;
        if((edge % 2 && K[i] == 'B') || (edge % 2 == 0 && K[i] == 'W'))ans++;
        num[i] = edge;
    }
    ans += (cnt - 1) * 2;

    if(cnt == 0)
    {
        printf("0\n");
        return 0;
    }

    if(cnt == 1)
    {
        printf("%d\n",ans);
        return 0;
    }

    if(cnt == 2)
    {
        ans -= (judge(mem[0]) + judge(mem[1])) * 2;
        printf("%d\n",ans);
        return 0;
    }

    int tmp;
    for(int i = 1; i <= N; i++)if(need[i])
    {
        tmp = unit(i,0).se;
        break;
    }

    ans -= unit(tmp,0).fi * 2;

    printf("%d\n",ans);
    return 0;
}




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

int main() {
    int n,ans;
    cin >> n;
    ans = n%10;
    if (ans == 3)
        cout << "bon";
    else if ((ans%2 == 1 && ans >= 5) || (ans%2 == 0 && ans <= 4 && ans != 0))
        cout << "hon";
    else
        cout << "pon";
}


Measured memory_bytes: 3620
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K = li_input()
    A = li_input()
    D = []

    for i in range(N - K + 1):
        l,r = A[i],A[i+K-1]
        D.append(min(abs(l) + abs(r - l), abs(r) + abs(r - l)))

    print(min(D))


main()


Measured memory_bytes: 15844
num = int(input())
array = list(map(int, input().split()))
sum = 0
 
for i in range(num):
	if i == 0:
		sum += array[i]
	elif i < (num-1):
		if array[i] > array[i-1]:
			sum += array[i-1]
		else:
			sum += array[i]
	else:
		sum += array[i-1]
        
print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int k,n;
    cin>>n>>k;
    vi a(n);
    for(int i=0,tmp;i<n;i++)
    {
        cin>>a[i];
    }
    ll ans=0;
    sort(a.begin(),a.end());
    for(int i=0;i<n-k;i++) ans+=a[i];
    cout<<ans<<'\n';
}

Measured memory_bytes: 1024
#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() {

    int a;
    cin >> a ;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int H,W; cin >> H >> W;
    vector<vector<int>> HW(H);
    repp(i,0,H) {
        vector<int> w(W);
        repp(j,0,W) cin >> w[j];
        HW[i] = w;
    }
 
    queue<vector<int>> q;
    repp(i,0,H) {
        repp(j,0,W) {
            int J = i % 2 == 0 ? j : W-j-1; 
            int nextJ =i % 2 == 0 ? J + 1 : J -1;  
            if (HW[i][J] % 2 == 0) continue;
            
            vector<int> v;
            if (j < W - 1) {
                --HW[i][J];
                ++HW[i][nextJ];
                v.push_back(i+1);
                v.push_back(J+1);
                v.push_back(i+1);
                v.push_back(nextJ+1);
                q.push(v);
            } else if (i < H - 1) {
                --HW[i][J];
                ++HW[i+1][J];
                v.push_back(i+1);
                v.push_back(J+1);
                v.push_back(i+2);
                v.push_back(J+1);
                q.push(v);
            }
        }
    }
    int count = q.size();
    cout << count << endl;
    repp(i,0,count) {
        vector<int> v = q.front(); q.pop();
        repp(j,0,4) {
            if (j > 0) cout << " ";
            cout << v[j];
        }
        cout << endl;
    }
}

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

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;

		int* word = new int[N];
		for (int i = 0; i < N; i++) word[i] = i + 1; //まず0番目の単語を入れておく

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		long long ans = 0;
		map<int, int> bubblehist;

		for (int i = 0; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.find(word[i] - 1);

			if (it != bubblehist.end()){
				bubblenum = it->second + 1;
			}
			else {
				it = bubblehist.find(word[i] + 1);
				if (it != bubblehist.end()){
					bubblenum = it->second;
				}
				else{
					bubblenum = 0;
					for (int j = 0; j < i; j++){
						if (word[j] < word[i]) bubblenum++;
					}
				}
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			bubblehist.insert(it, p);
			for (map<int, int>::iterator it2 = bubblehist.upper_bound(word[i]); it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}

		delete[] word;
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++){
		cout << *it << endl;
	}

	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6860
N,A,B=map(int,input().split())
if (B-A)%2==0:
    ans =(B-A)//2
else:
    if A-1 > N-B:
        ans = N-B+1
        A+=ans
        ans+=(N-A)//2
    else:
        ans =A
        B-=ans
        ans+=(B-1)//2
print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int a[99],n;bool po=1,ne=1;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		po&=a[i]>=0;
		ne&=a[i]<=0;
	}
	cout<<(po||ne?n-1:2*n-1)<<endl;
	if(!po&&!ne)
	{
		int M=0,m=0,pi,ni;
		for(int i=0;i<n;i++)
		{
			if(M<=a[i])M=a[i],pi=i;
			else if(m>=a[i])m=a[i],ni=i;
		}
		if(M>-m)
		{
			for(int i=0;i<n;i++)cout<<pi+1<<" "<<i+1<<endl;
			po=1;
		}
		else
		{
			for(int i=0;i<n;i++)cout<<ni+1<<" "<<i+1<<endl;
			ne=1;
		}
	}
	if(po)
	{
		for(int i=1;i<n;i++)cout<<i<<" "<<i+1<<endl;
	}
	else if(ne)
	{
		for(int i=n;i>1;i--)cout<<i<<" "<<i-1<<endl;
	}
}

Measured memory_bytes: 256
using System;

namespace ALDS1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string number = Console.ReadLine();
            int[] numbers = new int[N];
            for (int i = 0; i < N; i++)
                numbers[i] = int.Parse(number.Split(' ')[i]);

            for (int k = 0; k < N; k++)
            {
                if (k == N - 1)
                {
                    Console.WriteLine("{0}", numbers[k]);
                    break;
                }
                Console.Write("{0} ", numbers[k]);
            }

            for (int i = 1; i < N; i++)
            {
                int v = numbers[i];
                int j = i - 1;
                while (j >= 0 && numbers[j] > v)
                {
                    numbers[j + 1] = numbers[j];
                    j--;
                }
                numbers[j + 1] = v;

                for (int k = 0; k < N; k++)
                {
                    if (k == N - 1)
                    {
                        Console.WriteLine("{0}", numbers[k]);
                        break;
                    }
                    Console.Write("{0} ", numbers[k]);
                }
            }
        }
    }
}



Measured memory_bytes: 17912
#include<bits/stdc++.h>
     
    using namespace std;
     
    typedef long long int64;
     
     
    int main()
    {
      string A;
      cin >> A;
     
      int sum[26] = {};
      for(auto &c : A) sum[c - 'a']++;
      int64 ret = 1LL * A.size() * (A.size() - 1) / 2;
      for(int i = 0; i < 26; i++) ret -= 1LL * sum[i] * (sum[i] - 1) / 2;
      cout << ret + 1 << endl;
    }


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] c = new int[n];
		int[][] a = new int[n][m];
		for(int i = 0; i < n; i++){
		    c[i] = sc.nextInt();
		    for(int j = 0; j < m; j++){
		        a[i][j] = sc.nextInt();
		    }
		}
		
		// 計算
		int result = Integer.MAX_VALUE;
		for(int i = 0; i < (1<<n); i++){
		    int[] r = new int[m];
		    int cost = 0;
		    for(int j = 0; j < n; j++){
		        if(((i>>j)&1) == 1){
		            cost += c[j];
		            for(int k = 0; k < m; k++){
		                r[k] += a[j][k];
		            }
		        }
		    }
		    boolean flg = true;
		    for(int j = 0; j < m; j++){
		        if(r[j] < x) flg = false;
		    }
		    if(flg) result = min(result, cost);
		}
		if(result == Integer.MAX_VALUE) result = -1;
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + key % (M - 1); }

int find(char str[]){
  int i = 0, j, sum;

  sum = getKey(str);
  while(1) {
    j = (h1(sum) + i * h2(sum)) % M;
    if(strcmp(H[j], str) == 0) return 1;
    else if(H[j][0] == '\0') return 0;
    i++;
  }
}

int insert(char str[]){
  int i = 0, j, sum;

  sum = getKey(str);
  while (1) {
    j = (h1(sum) + i * h2(sum)) % M;
    if(H[j][0] == '\0') {
      strcpy(H[j], str);
      return j;
    }
    else if(strcmp(H[j], str) == 0) return j;
    i++;
  }
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      insert(str);
    }
    else {
      if (find(str)){
        printf("yes\n");
      }
      else {
        printf("no\n");
      }
    }
  }

  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple < int, int, int >
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >
#define pis pair < int, string >

#define vi vector < int >
#define vd vector < double >
#define vld vector < ld >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >
#define vpis vector < pis >

#define pb push_back
#define mt make_tuple
#define gt0 get < 0 >
#define gt1 get < 1 >
#define gt2 get < 2 >

#define pi acos(-1)

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;

ll a[maxn];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    fast;

    int n;

    cin >> n;

    ll sum = 0;

    for(int i = 0; i < n; i++) cin >> a[i], sum += a[i], sum %= mod;

    ll ans = 0;

    for(int i = 0; i < n; i++){
        sum -= a[i];

        if(sum < 0) sum += mod;

        ans += a[i] * sum;
        ans %= mod;
    }

    if(ans < 0) ans += mod;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5168