akhauriyash/Code-Regression huggingface dataset:
#coding:utf-8
#1_11_B 2015.4.20
class Dice:
    def __init__(self,ary):
        self.top , self.south , self.east , self.west , self.north ,self.bottom = ary

    def roll_n(self):
        self.top , self.south , self.bottom , self.north = self.south , self.bottom , self.north , self.top

    def roll_e(self):
        self.top , self.west , self.bottom , self.east = self.west , self.bottom , self.east , self.top

    def twist(self):
        self.north , self.west , self.south , self.east = self.east , self.north , self.west , self.south

dice = Dice(input().split())
for i in range(int(input())):
    top,south = input().split()
    while dice.top != top or dice.south != south:
        if dice.top == top:
            while dice.south != south:
                dice.twist()
        elif dice.south == south:
            while dice.top != top:
                dice.roll_e()
        else:
            dice.roll_n()
    print(dice.east)

Measured memory_bytes: 6728
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair
#define pb                  push_back

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

void solve(string s){
    char buf[1100], *p, *context;
    strcpy(buf, s.c_str());

    p = strtok_r(buf, " ,.", &context);
    if(!p){
        puts("");
        return;
    }
    bool flag = false;
    do {
        if(strlen(p) < 3 || strlen(p) > 6) continue;
        if(flag) printf(" %s", p);
        else  printf("%s", p);
        flag = true;
    } while((p = strtok_r(NULL, " ,.", &context)) != NULL);

    puts("");
}

int main(){
    string s;
    while(getline(cin, s)){
        solve(s);
    }
    return 0;
}

Measured memory_bytes: 1204
from sys import stdin

n, m = [int(x) for x in stdin.readline().rstrip().split()]

maxl = 1
minr = n
for i in range(m):
  l, r = [int(x) for x in stdin.readline().rstrip().split()]
  maxl = max(maxl, l)
  minr = min(minr, r)
  
ans = minr - maxl + 1

if ans < 0:
  ans = 0

print(ans)


Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;
 
int main(){
  int n;
  cin >> n;
  vector<int> c(n),s(n),f(n);
  rep(i,n-1){
    cin >> c[i] >> s[i] >> f[i]; 
  }
  vector<int> ans(n,0);
  rep(i,n-1){
    int tmp=0;
    int j=i;
    tmp = s[j]+c[j];
    j++;
    while(j<n-1){
      if(tmp-s[j]>0){
        tmp = (tmp+f[j]-1)/f[j]*f[j];
      } else {
        tmp = s[j];
      }
      tmp += c[j];
      j++;
    }
    ans[i]=tmp;
  }

  rep(i,n){ cout << ans[i] << endl; }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int l,n,a,b,c;
int main(){
	cin>>l>>n;
	for(int i=0;i<n;i++){cin>>a>>b;c+=a*b;}
	if(c>=1)cout<<"1"<<endl<<"-1 "<<c<<endl;
	if(c==0)cout<<"0"<<endl;
	if(c<=-1)cout<<"1"<<endl<<"1 "<<-c<<endl;
	return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi acos(-1)
int main()
{
    ll c=0,c1=0,c2=0,c3=0;
ll t; cin>>t; while(t--){
string s;
    cin>>s;

    if(s=="AC")
    {
        c++;
    }
     if(s=="WA")
    {
        c1++;
    }
     if(s=="TLE")
    {
        c2++;
    }
     if(s=="RE")
    {
        c3++;
    }
}
   cout<<"AC x "<<c<<endl;
   cout<<"WA x "<<c1<<endl;
   cout<<"TLE x "<<c2<<endl;
   cout<<"RE x "<<c3<<endl;
}



Measured memory_bytes: 3632
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >>c;
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    set<char> st{a[i], b[i], c[i]};
    if(st.size() == 3) ans += 2;
    else if(st.size() == 2) ans += 1;
    else if(st.size() == 1) ans += 0;
  }

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


Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
A = [-int(i) for i in input().split()]
heapq.heapify(A)

for i in range(M):
    tmp_min = heapq.heappop(A)
    heapq.heappush(A, (-tmp_min//2)*(-1))
    

print(-sum(A))

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

int main(){
  int r0,w0,c,r;
  for(;;){
    cin>>r0>>w0>>c>>r;
    if(!r0&&!w0&&!c&&!r) break;
    
    int ans=w0*c-r0;
    if(ans<0) cout<<"0"<<endl;
    else if(ans%r==0) cout<<ans/r<<endl;
    else cout<<ans/r+1<<endl;
  }
}


Measured memory_bytes: 3072
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))

z = 0
for n in range(N):
    x = C
    A = list(map(int, input().split()))
    for a,b in zip(A,B):
        x += a*b

    if x>0 : z+=1

print(z)

Measured memory_bytes: 3060
def swap(A,i,j):
    A[i],A[j] = A[j],A[i]
    return A

def partition(A,p=0, r=None):
    if r is None:
        r = len(A)-1
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i += 1
            swap(A,i,j)
    swap(A,i+1,r)
    return i+1

if __name__ == "__main__":
    input()
    A = list(map(int, input().strip().split()))
    k = partition(A)
    B = list(map(str, A))
    B[k] = "[{}]".format(B[k])
    print(" ".join(B))

Measured memory_bytes: 18780
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,W,ar[N][2],dp[101][N];
ll findans(ll i,ll cur_w){
	if(i==n+1) return 0;

	if(dp[i][cur_w]!=-1){
		return dp[i][cur_w];
	}
	ll a=0,b=0;
	a=findans(i+1,cur_w);
	if(cur_w+ar[i][0]<=W)
		b=findans(i+1,cur_w+ar[i][0])+ar[i][1];
	return dp[i][cur_w]=max(a,b);
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l;
	cin>>n>>W;
	for(i=1;i<=n;i++){
		cin>>ar[i][0]>>ar[i][1];
	}
	memset(dp,-1,sizeof(dp));
	ll an=findans(1,0);
	cout<<an;
	return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

struct graph_t {
	int n;           // |V|, index begins with 0
	int m;           // |E|
	vector<P> edges; // E
	vector<ll> cost; // cost or distance
	vector<ll> cap;  // capacity
};

class Dijkstra {
private:
	struct node {
		int id; bool done; vi to; vll cost; int from; ll d;
		bool operator<(const node & another) const {
			return !(d != another.d ? d < another.d : id < another.id);
		}
	};
	vector<node> nodes;
	int n;
public:
	Dijkstra(graph_t G, int start) {
		n = G.n;
		nodes.resize(n);
		Loop(i, n) nodes[i] = { i, false, {}, {}, -1, INFLL };
		Loop(i, G.m) {
			nodes[G.edges[i].first].to.push_back(G.edges[i].second);
			nodes[G.edges[i].first].cost.push_back(G.cost[i]);
		}
		priority_queue<node> pq;
		nodes[start].d = 0;
		pq.push(nodes[start]);
		while (pq.size()) {
			node a = pq.top(); pq.pop();
			if (nodes[a.id].done) continue;
			nodes[a.id].done = true;
			Loop(j, a.to.size()) {
				node *b = &nodes[a.to[j]];
				if ((*b).done) continue;
				ll buf = a.d + a.cost[j];
				if (buf < (*b).d) {
					(*b).d = buf;
					(*b).from = a.id;
					pq.push(*b);
				}
			}
		}
	}
	vi get_path(int v) {
		int a = v;
		stack<int> stk;
		while (nodes[a].from != -1) {
			stk.push(nodes[a].from);
			a = nodes[a].from;
		}
		vi ret;
		while (stk.size()) {
			ret.push_back(stk.top());
			stk.pop();
		}
		return ret;
	}
	ll get_dist(int v) {
		return nodes[v].d;
	}
};

int main() {
	graph_t G;
	cin >> G.n >> G.m;
	int start; cin >> start;
	Loop(i, G.m) {
		int a, b, c; cin >> a >> b >> c;
		G.edges.push_back({ a, b });
		G.cost.push_back(c);
	}
	Dijkstra dijkstra(G, start);
	Loop(i, G.n) {
		ll ans = dijkstra.get_dist(i);
		if (ans == INFLL) cout << "INF" << endl;
		else cout << ans << endl;
	}
	return 0;
}

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

int main(){
  ll n,k;cin>>n>>k;
  vector<ll> v(n);
  rep(i,n){cin>>v.at(i);}
  sort(v.begin(),v.end());
  ll ans=v.at(k-1)-v.at(0);
  ll d;
  rep(i,n-k+1){
    d=v.at(i+k-1)-v.at(i);
    ans=min(ans,d);
    if(ans==0){break;}
  }
  cout<<ans;
}

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

typedef vector<int> VI;

#define REP(i, n) for (int i=0;i<n;++i)
#define ALL(A) A.begin(), A.end()
#define PB push_back


const int N = 109, M = 5040;
int a[105], d[105], pos[105];
int n, ans; int ne[M][10]; int dp[105][M];
vector<VI> P; VI p;

int main(){


#define conds P

    cin >> n; for(int i = 0;i < n;i++)cin >> d[i];
    for(int i = 0;i < n;i++) cin >> a[i];


    VI p; REP(i, 7) p.PB(i);
    do P.PB(p); while(next_permutation(ALL(p)));

    REP(i, M){
        vector<int> tmp1, tmp2;

        for(int j = 0;j < 8;j++){
            tmp1 = conds[i];
            for(int k = 0;k < 7;k++){
                if(tmp1[k] >= j)tmp1[k]++;
            }

            tmp2.clear();
            for(int k = 1;k <= 7;k++){
                tmp2.push_back(tmp1[k]);
                if(tmp2[k - 1] > tmp1[0])tmp2[k - 1]--;
            }

            ne[i][j] = lower_bound(ALL(P), tmp2) - P.begin();
        }
    }

    for(int  i = 0;i < n;i++){
        for(int j = 0;j < M;j++){
            for(int k = 0;k < 7;k++)pos[conds[j][k]] = k;
            int res = dp[i][j];
            for(int k = 0;k < 7;k++)
                if(i - 7 + k >= 0 && 7 - k <= d[i])res += a[i];
            for(int k = 0;k < 8;k++){
                dp[i + 1][ne[j][k]] = max(dp[i + 1][ne[j][k]], res);
                ans = max(ans, dp[i + 1][ne[j][k]]);
                if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= d[i])res -= a[i];
                if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= d[i - 7 + pos[k]])res += a[i - 7 + pos[k]];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3872
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

N = int(input())
c = Counter(map(int, input().split()))
ans = 0
for k, v in c.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)



Measured memory_bytes: 25812
# coding: utf-8
import time
import re
import math
import fractions

def main():
    N=int(input())
    D=[int(input()) for a in range(N)]
    print(len(set(D)))
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B



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

#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT                        \
  std::ios::sync_with_stdio(false); \
  std::cin.tie(0);
template <class T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  INIT;
  string s, t;
  cin >> s;
  cin >> t;
  int n = 0;
  REP(i, s.length()) {
    if (s[i] != t[i]) {
      n += 1;
    }
  }
  cout << n << endl;

  return 0;
}

Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
#define MOD 998244353
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

int main() {

    int r; cin >> r;
    int a = r * r;
    cout << a << endl;
}

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

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

    string s;
    cin>>s;

    if(s.size()==2)cout<<s;
    else for(int i=2;i>=0;i--)cout<<s[i];

    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using namespace std;

int main()
{
	int n,m;
	while(cin >> n >> m)
	{
		if(n == 0 && m == 0) break;
		
		vector<int> v;
		v.resize(n);

		rep(i,n) cin >> v[i];
		sort(v.begin(),v.end());
		
		int ans = 0;
		for(int i=n-1;i>=0;i -= m)
		{
			if(i-m+1 < 0)
			{
				for(int j=i;j>=0;j--)
				{
					ans += v[j];
				}
			}
			else
			{
				for(int j=i;j>(i-m+1);j--)
				{
					ans += v[j];
				}
			}
		}
		cout << ans << endl;

	}
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define ll long long
#define rgi register int
#define rgl register ll
#define maxn 1000005
#define mod 1000000003
#define inf 1000000007
namespace lib
{
	using namespace std;
	
	
	class fastio
	{
		private:
			#define _NUMLEN 111
			char _num[_NUMLEN],_ch;
			int _f,_head;
			bool _useSTD;
		public:
			inline void ioSTD()
			{
				_useSTD=1;
				ios::sync_with_stdio(false);
				cin.tie(0),cout.tie(0);
			}
			inline void gc(char & _c)
			{
				if(_useSTD)cin>>_c;
				else _c=getchar();
			}
			inline void pc(char _c)
			{
				if(_useSTD)cout<<_c;
				else putchar(_c);
			}
			template<typename _T> inline fastio & operator - (_T & _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_x=0;
					while(!isdigit(_ch)) _f|=_ch=='-',gc(_ch);
					while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),gc(_ch);
					_f&&(_x=-_x,_f=0);
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator + (_T _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_T _k;
					if(_x==0) {pc('0'),pc(' ');return *this;}
					if(_x<0) pc('-'),_x=-_x;
					while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
					while(_head>0) pc(_num[_head]),--_head;
					pc(' ');
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator >> (_T & _x) {cin>>_x;return *this;}
			template<typename _T> inline fastio & operator << (_T _x) {cout<<_x;return *this;}
			#define endln pc('\n')
		fastio() {_f=0,_head=0,_useSTD=0,_ch=' ';}
	}io;
	
	
	inline void fileio(string _r,string _w)
	{
		if(_r[0]!='-')freopen(_r.c_str(),"r",stdin);
		if(_w[0]!='-')freopen(_w.c_str(),"w",stdout);
	}
}using namespace lib;

ll gcd(ll a,ll b) {return a==0?b:gcd(b%a,a);}
signed main()
{
//	fileio("tt.in","tt.out");
//	io.ioSTD();
	ll a,b;
	io-a-b;
	io+(a*b/gcd(a,b));
	return 0;
}

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

int main(){
	int n,k;cin>>n>>k;
	ll ans=0;
	for(int i=k+1;i<=n;i++){
		ll a=(n-k)%i+1;
		ll b=i-k;
		a=min(a,b);
		ll c=(n-k)/i+1;
		ans+=c*a+(c-1)*(b-a);
		if(k==0)ans--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,x,y,z;
    scanf("%d %d",&A,&B);
    x=(A+B);
    y=(A-B);
    z=(A*B);
    if (x>=y&&x>=z)
    {
        printf("%d\n",x);
    }
    else if (y>=x&&y>=z)
        {
        printf("%d\n",y);
        }
    else
        {
        printf("%d\n",z);
        }
}

Measured memory_bytes: 1720
unittest
{
	assert( [ "5", "6", "8", "1", "2", "3" ].parse.expand.solve == 21 );
	assert( [ "6", "3", "1", "4", "1", "5", "9" ].parse.expand.solve == 25 );
	assert( [ "3", "5", "5", "1" ].parse.expand.solve == 8 );
	
	assert( [ "5", "6", "8", "1", "2", "5" ].parse.expand.solve == 21 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.to!( long );
	}
	return tuple( as );
}

auto solve( long[] as )
{
	as.sort();
	
	// 真ん中に1番小さいやつ、その外側に1,2番目に大きいやつ、その外側に2,3番目に小さいやつ…と並べたパターンを計算
	auto ans1 = solve2( as, true );
	
	// 真ん中に1番大きいやつ、その外側に1,2番目に小さいやつ、その外側に2,3番目に大きいやつ…と並べたパターンを計算
	auto ans2 = solve2( as, false );
	
	return max( ans1, ans2 );
}

auto solve2( long[] as, bool f )
{
	// 並べ替える
	auto bs = new long[ as.length ];
	auto ci = bs.length.signed / 2;
	if( f )
	{
		bs[ ci ] = as.front;
		as.popFront;
	}
	else
	{
		bs[ ci ] = as.back;
		as.popBack;
	}
	for( auto i = 1L;; i++ )
	{
		f = !f;
		if( f )
		{
			bs[ ci - i ] = as.front;
			as.popFront;
			if( as.empty ) break;
			bs[ ci + i ] = as.front;
			as.popFront;
			if( as.empty ) break;
		}
		else
		{
			bs[ ci - i ] = as.back;
			as.popBack;
			if( as.empty ) break;
			bs[ ci + i ] = as.back;
			as.popBack;
			if( as.empty ) break;
		}
	}
	
	// 差の合計を計算
	auto dt = 0L;
	auto p = bs.front;
	foreach( b; bs )
	{
		dt += ( p - b ).abs;
		p = b;
	}
	return dt;
}


Measured memory_bytes: 5372
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    c = input()
    print(chr(ord(c)+1))


if __name__=='__main__':
    main()

Measured memory_bytes: 5144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = vs[0];
            int b = vs[1];
            int ans = 0;
            int sum = 1;
            while (sum < b) {
                ans++;
                sum += a - 1;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> im(N + 1);
  // だめなやつを正の数にする
  for(int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    im[0]++;
    im[l - 1]--;
    im[r]++;
    im[N]--;
  }
  vector<int> R(N + 2);
  R[0] = 0;
  for(int i = 0; i < N + 1; i++) {
    R[i + 1] = R[i] + im[i];
  }

  int ans = 0;
  for(int i = 0; i < N + 2; i++) {
    if(R[i] == 0) { ans++; }
  }
  cout << ans - 2 << endl;

  return 0;
}

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

using namespace std;

vector<vector<int>> dp(100005, vector<int>(3, -1)), input;

//dp[n][i] stores the maximum points by choosing activity i on day n
long long int solve(int n, int i)
{
    if(dp[n][i] != -1)
        return(dp[n][i]);
    if(n == 1)
        return(dp[n][i] = input[n][i]);
    return(dp[n][i] = max(solve(n-1, (i+1)%3) + input[n][i], solve(n-1, (i+2)%3) + input[n][i]));
}

int main()
{
    int n, a, b, c;
    long long int ans;
    cin >> n;
    input.push_back({-1, -1, -1});
    for(int i=0;i<n;i++)
    {
        cin >> a >> b >> c;
        input.push_back({a, b, c});
    }
    ans = max(solve(n, 0), max(solve(n, 1), solve(n, 2)));
    cout << ans << endl;
    return(0);
}

Measured memory_bytes: 18992
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

using namespace std;

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

int Read()
{
	char c;
	c=getchar();

	int tsqua=0;

	while(c!=' '&&c!='\n')
	{
		tsqua=(((tsqua<<1)<<1)<<1)+(tsqua<<1)+(int)(c-'0');

		c=getchar();
	}

	return tsqua;
}

typedef long long ll;

int k,x;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>k>>x;
	
	for(int i=x-k+1;i<=x+k-1;i++)cout<<i<<' ';
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

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

using namespace std;

const int INF = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    int cnt[26];
    for(int i = 0; i < 26; i++){
        cnt[i] = 1;
    }
    for(auto&& i : str){
        cnt[i - 'a']++;
    }
    long long ans = 1;
    for(auto&& i : cnt){
        ans *= i;
        ans %= INF;
    }
    cout << ans - 1 << "\n";
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int solve(int y,int m,int d)
{
    int sum=((y-1)/3)*590;
    y=y%3;
    if(y==2){
      sum+=195;
      if(m%2==1) sum+=((m-1)/2)*39+d;
      else sum+=(m-2)/2*39+d+20;
       } 
    else if(y==1){
      if(m%2==1) sum+=((m-1)/2)*39+d;
      else  sum+=(m-2)/2*39+d+20;   
       } 
    else  {
      sum+=390+(m-1)*20+d;   
       } 
   return sum; 
} 

int main(){
  int n,y,m,d; 
  cin>>n;      //imput number of the test cases
  for(int i=0;i<n;i++){
  cin>>y>>m>>d;
  //cout<<solve(1000,1,1)<<"  "<<solve(1,1,1)<<endl;
  cout<<solve(1000,1,1)-solve(y,m,d)<<endl; 
  } 
  getchar();getchar(); 
  return 0; 
} 
  

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

ll MOD = 1e9 + 7;
ll bit[300010][60], bitcnt[300010][60];

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

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 60; j++) {
      if (A[i] & ((ll)1 << j)) bit[i][j] = 1;
    }
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 60; j++) {
      bitcnt[i][j] = bitcnt[i - 1][j] + bit[i - 1][j];
    }
  }

  ll ret = 0;
  for (ll i = 0; i < N - 1; i++) {
    ll c = 1;
    for (ll j = 0; j < 60; j++) {
      if (bit[i][j] == 1) {
        ret = (ret + c * (N - 1 - i - (bitcnt[N][j] - bitcnt[i + 1][j]))) % MOD;
      } else {
        ret = (ret + c * (bitcnt[N][j] - bitcnt[i + 1][j])) % MOD;
      }
      c = c * 2 % MOD;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 283904
N, M = map(int,input().split())
import math
def comb(n, r):
    if (n-r) >= 0:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
base = comb(N,2)
base2 = comb(M,2)
print(base+base2)

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i = 0; i < N; i++){
    cin >> l.at(i);
  }
  sort(ALL(l), greater<int>());
  int result = 0;
  for(int i = 0; i < K; i++){
    result += l.at(i);
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int cnt,last[205],a[205],b[205],x[205],vis[205],match[205],prime[10000005],isprime[10000005],s[10000005];
struct node{
	int to,next;
}e[1000005];
void add(int a,int b){
	e[++cnt].to=b;
	e[cnt].next=last[a];
	last[a]=cnt;
}
int dfs(int x){
	for (int i=last[x]; i; i=e[i].next){
		int V=e[i].to;
		if (!vis[V]){
			vis[V]=1;
			if (!match[V] || dfs(match[V])){
				match[V]=x;
				return 1;
			}
		}
	}
	return 0;
}
int abs1(int x){
	if (x<0) return -x;
	return x;
}
int main(){
	isprime[1]=1;
	for (int i=2; i<=10000000; i++){
		if (!isprime[i]) prime[++cnt]=i;
		for (int j=1; j<=cnt && i*prime[j]<=10000000; j++){
			isprime[i*prime[j]]=1;
			if (i%prime[j]==0) break;
		}
	}
	int n;
	scanf("%d",&n);
	for (int i=1; i<=n; i++){
		scanf("%d",&x[i]);
		s[x[i]]^=1;
	}
	int num=0,sum=0;
	for (int i=1; i<=10000001; i++)
		if (s[i]!=s[i-1]){
			if (i%2==1) a[++num]=i;
			else b[++sum]=i;
		}
	for (int i=1; i<=num; i++)
		for (int j=1; j<=sum; j++)
			if (!isprime[abs1(a[i]-b[j])]) add(i,j);
	int ss=0;
	for (int i=1; i<=num; i++){
		for (int j=1; j<=sum; j++) vis[j]=0;
		if (dfs(i)) ss++;
	}
	int ans=(num-ss)/2*2+(sum-ss)/2*2+ss+((num&1)!=(ss&1)?3:0);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 86144
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

/*二項定理ライブラリ*/
constexpr lint MOD = 1e9 + 7;
vector<lint> fac, facInv, inv;
void facInit(int nmax)
{
    fac = facInv = inv = vector<lint>(nmax + 1, 1);
    for (int i = 2; i <= nmax; i++)
    {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        facInv[i] = facInv[i-1] * inv[i] % MOD;
    }
}
lint nCr(int n, int r)
{
    if (n<r || r<0) return 0;
    if (n >= (int)fac.size()) facInit(n);
    return (fac[n] * facInv[r] % MOD) * facInv[n-r] % MOD;
}
lint nPr(int n, int r)
{
    if (n<r || r<0) return 0;
    if (n >= (int)fac.size()) facInit(n);
    return fac[n] * facInv[n-r] % MOD;
}
lint power(lint x, lint n, lint mod=MOD)
{
    lint ans = 1;
    while (n>0)
    {
        if (n & 1) (ans *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1;
    }
    return ans;
}
lint doublefac(lint n)
{
    if (n < 0) return 0;
    lint k = (n + 1) / 2;
    if (n & 1) return fac[k * 2] * power(facInv[2], k) % MOD * power(fac[k], MOD - 2) % MOD;
    else return fac[k] * power(facInv[2], k) % MOD;
}

int main() {
    int N, K;
    cin >> N >> K;
    facInit(N * 2);
    FOR(i, 1, K + 1) {
        cout << nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD << endl;
    }
    
    return 0;
}



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

int main(void){
   int D,T,S;
   cin >>D>>T>>S;
   
   int M=D/S;
   if(D%S!=0){
       M++;
   }
   
   if(M>T){
       cout<<"No"<<endl;
   }
   else{
       cout<<"Yes"<<endl;
   }
}


Measured memory_bytes: 3616
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD =998244353 ;
#define pb push_back
#define mp make_pair
#define endl '\n'
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}
int main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    int s,w;
    cin>>s>>w;
    if(s>w){
        cout<<"safe";
    }
    else{
        cout<<"unsafe";
    }
    return 0;
}

Measured memory_bytes: 3640
N=int(input())
P=[int(input()) for _ in range(N)]

def solve():
    O=[-1]*(N+1)
    for i,p in enumerate(P): O[p]=i

    n=0
    nn=0
    for i in range(1,N+1):
        if O[i-1]<O[i]: n+=1
        else: n=1
        nn=max(nn,n)

    return N-nn

print(solve())
'''
from itertools import permutations
for p in permutations(range(N)):
    P=list(map(lambda x:x+1,p))
    print(P,solve())
'''

Measured memory_bytes: 59992
#include<stdio.h>
int getgcd(int n, int m);

int main(void){
    long long int N;
    scanf("%lli",&N);
    long long int ans=0;
    long long int x=0;

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            for(int k=1;k<=N;k++){
            x = getgcd(getgcd(i, j), k);
            ans += x;
            }
        }
    }
    printf("%lli\n",ans);
    return 0;
}

int getgcd(int n, int m)
{
    int r;
    if (n > m) {
        int t = m;
        m = n;
        n = t;
    }
    while ((r = m % n) != 0) {
        m = n;
        n = r;
    }
    return n;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S = "Yes";
  if (N / 100 != 7){
    if (N % 100 / 10 != 7){
      if (N % 10 != 7){
        S = "No";
      }
    }
  }
  
  cout << S << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#define INF 1 << 28
using namespace std;

int x,y,b,p;

int solve(int i, int j){

  if(i > 6 || j > 6) return INF;
  if(i > 4 && j > 1) return min((int)(i*x*0.8+j*y*0.8),min(solve(i+1,j),solve(i,j+1)));
  else return min(i*x+j*y,min(solve(i+1,j),solve(i,j+1)));

}

int main(){

  int n;
  cin >> n;

  while(n--){
    cin >> x >> y >> b >> p;
    cout << solve(b,p) << endl;
  }

}

Measured memory_bytes: 1164
N = int(input())

infos = []
first_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    else:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
for cx in range(101):
    for cy in range(101):
        isValid = True
        H = h1 + abs(x1-cx) + abs(y1-cy)
        for x2, y2, h2 in infos:
            if h2 != max(H - abs(x2-cx) - abs(y2-cy), 0):
                isValid = False

        if isValid:
            ans = [cx, cy]

cx, cy = ans
H = h1 + abs(x1-cx) + abs(y1-cy)
print(cx, cy, H)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;

int main() 
{
    int n;
    cin >> n;
    int value[n], cost[n];
    ll res = 0;
    for (int i = 0; i < n; i++) cin >> value[i];
    for (int i = 0; i < n; i++) 
    {
        cin >> cost[i];
        if (value[i] - cost[i] >= 0) res += value[i] - cost[i];
    }

    cout << res << endl;
}


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

int main() {

  int N, M;
  cin >> N;
  int ans = 0;

  for (int i = 1; i <= N; i++) {
     int count = 0;
     int K = i;
     while(K%2==0) {
       K /= 2;
       count++;
     }
     if(count>=ans) {
        ans = count;
        M = i;
     }
  }

  cout << M << endl;

}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=min(arr1)+min(arr2)
for _ in range(m):
  x,y,c=map(int,input().split())
  tmp=arr1[x-1]+arr2[y-1]-c
  ans=min(ans,tmp)
print(ans)

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

int main() {
    string S, T; cin >> S >> T;
    int cnt = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] != T[i]) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3848
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;}

	if(a>b){
		cout<<"a > b"<<endl;}

	if(a==b){
		cout<<"a == b"<<endl;}

	return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<cstring>
using namespace std;
int search(int a){
    int b=a%10,c=a/10%10,d=a/100%10,e=a/1000;
    if((b==c && c==d) || (c==d && d==e))cout<<"Yes";
    else cout<<"No";
}
int main(){
    int a;
    cin>>a;
    search(a);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  
  if (L < R) {
    cout << "Right" << endl;
  }
  else if (L > R) {
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int& a : A) {
    cin >> a;
  }
  
  ll result = A[N - 1];
  int i = N - 1;
  while (i >= 0) {
    while (i > 0 && A[i - 1] + 1 == A[i]) {
      --i;
    }
    
    if (i == 0) {
      if (A[i] != 0) {
        cout << -1 << '\n';
        return 0;
      }
      
      break;
    }
    
    if (A[i - 1] + 1 < A[i]) {
      cout << -1 << '\n';
      return 0;
    }
    
    --i;
    result += A[i];
  }
  
  cout << result << '\n';
  
  return 0;
}


Measured memory_bytes: 1024
object Main {
  def main(args : Array[String]) {
    val NM = readLine().split(' ').map(_.toInt)
    var A = readLine().split(' ').map(_.toInt)
    A = A.sorted.reverse
	if((A.sum.toDouble / (4 * NM(1))) <= A(NM(1) - 1)) println("Yes")
    else println("No")
  }
}


Measured memory_bytes: 27196
#include<iostream>
#include<vector>
#include<string>
#include<stack>
using namespace std;
int main(){
        string s;
        stack<int> decline;
        stack<pair<int, int>> water;
        cin>>s;
        for(int i=0;i<s.size();i++){
                if(s[i]=='\\') decline.push(i);
                else if(s[i]=='/') {
                        if(decline.empty()) continue;
                        int start = decline.top(); decline.pop();
                        int watermass = i-start;
                        while(!water.empty()){
                                pair<int,int> tmp = water.top();
                                if(tmp.first>start){
                                        water.pop();
                                        watermass += tmp.second;
                                }else break;
                        }
                        water.push(make_pair(start, watermass));
                }
        }
        int watermass = 0;
        int n_water = water.size();
        vector<int> r;
        while(!water.empty()){
                r.push_back(water.top().second);
                watermass += water.top().second;
                water.pop();
        }
        cout<<watermass<<endl;
        cout<<n_water;
        for(int i=n_water-1;i>=0;i--){
                cout<<" "<<r[i];
        }
        cout<<endl;
        return 0;
}


Measured memory_bytes: 3276
import java.util.Scanner;

/**
 * Created by Admin on 2017-08-13.
 */

public class Main {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
     //**   System.out.println( "Podaj pozycje X potem pozycje punku A i B");

    int X = input.nextInt();
    int A = input.nextInt() ;
    int B = input.nextInt();
    if (Math.abs(X-A) < Math.abs(X-B))
            System.out.println("A");
    else {
        System.out.println("B");
    }
            }
        }
     


Measured memory_bytes: 21716
N = int(input())
H = list(map(int, input().split()))

x = H[0] - 1
for i in range(1, N):
    if not x <= H[i]:
        print('No')
        exit()

    if x <= H[i] - 1:
        x = H[i] - 1
    else:
        x = H[i]

print('Yes')


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

bool IsYoko(vector<vector<bool>> judge)
{
  	for(int j = 0; j<3;j++)
    {
      if(judge.at(j).at(0) && judge.at(j).at(1) && judge.at(j).at(2))
      {
        return true;
      }
    } 
  return false;
}

bool IsTate(vector<vector<bool>> judge)
{
  	for(int j = 0; j<3;j++)
    {
      if(judge.at(0).at(j) && judge.at(1).at(j) && judge.at(2).at(j))
      {
        return true;
      }
    } 
  return false;
}

bool IsNaname(vector<vector<bool>> judge)
{
  if(judge.at(0).at(0) && judge.at(1).at(1) && judge.at(2).at(2))
  {
    return true;
  }
  if(judge.at(2).at(0) && judge.at(1).at(1) && judge.at(0).at(2))
  {
    return true;
  }
  return false;
}

int main() {
  vector<vector<int>> bingo(3 , vector<int>(3));
  vector<vector<bool>> judge(3 , vector<bool>(3));
  
  for(int i = 0; i < 3; i++)
  {
    for(int j= 0; j< 3;j++)
    {
      cin >> bingo.at(i).at(j);
      judge.at(i).at(j) = false;
    }
  }
  int N =0;
  cin >> N;
  for(int i = 0;i< N; i++)
  {
    int b;
    cin >> b;
    for(int j = 0; j < 3;j++)
    {
      for(int k = 0; k< 3;k++)
      {
        if(b == bingo.at(j).at(k))
        {
          judge.at(j).at(k) = true;
        }
      }
    }
  }
  
  if(IsYoko(judge) == true || IsTate(judge) == true|| IsNaname(judge)== true)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int tcs;cin>>tcs;while(tcs--)
const int N=200007;
const int MOD=1e9+7;
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val



#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define printclock cerr<<"Time : "<<1000*(int)clock()/(int)CLOCKS_PER_SEC<<"ms\n"



int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
*/


int n,k;
cin>>n>>k;

vector<int> v(n+1);
for(int i=0;i<n;i++)
cin>>v[i];


for(int i=k;i<n;i++)
{
	if(v[i]>v[i-k])
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}



  




cout<<endl;
printclock;
}


Measured memory_bytes: 4780
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> dp0(N);
  vector<int> dp1(N);
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    if (i != 0) {
      tmp = dp0[i - 1] + tmp;
    }
    dp0[i] = tmp;
  }
  int tmp;
  cin >> tmp;
  dp1[0] = tmp + dp0[0];

  for (int i = 1; i < N; ++i) {
    int tmp;
    cin >> tmp;
    tmp = max(dp0[i], dp1[i - 1]) + tmp;
    dp1[i] = tmp;
  }
  cout << dp1[N - 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
int dp[3005][3005][4];
main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int r, c, k;
	cin>>r>>c>>k;
	int val[r][c];
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			val[i][j]=0;
		}
	}
	for(int i=0; i<k; i++){
		int x, y, w;
		cin>>x>>y>>w;
		x--;
		y--;
		val[x][y]=w;
	}
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			for(int k=0; k<=3; k++){
				if(k==0){
					if(i==0 && j==0){
						continue;
					}
					if(i==0){
						dp[i][j][0]=dp[i][j-1][0];
						continue;
					}
					if(j==0){
						dp[i][j][0]=dp[i-1][j][3];
						continue;
					}
					else{
						dp[i][j][k]=max(dp[i-1][j][3], dp[i][j-1][0]);
					}
				}
				else{
					if(i==0 && j==0){
						dp[i][j][k]=val[i][j];
						continue;
					}
					if(i==0){
						dp[i][j][k]=max(dp[i][j-1][k], val[i][j]+dp[i][j-1][k-1]);
						continue;
					}
					if(j==0){
						dp[i][j][k]=val[i][j]+dp[i-1][j][3];
						continue;
					}
					dp[i][j][k]=max(val[i][j]+dp[i][j-1][k-1], val[i][j]+dp[i-1][j][3]);
					dp[i][j][k]=max(dp[i-1][j][3], dp[i][j][k]);
					dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k]);
				}
			}
		}
	}
	cout<<dp[r-1][c-1][3];
	return 0;
}

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


bool check(vector<ll> path, vector<vector<ll>> &graph){
    if(path[0] != 0)return false;

    bool flag = true;
    for( int i = 0; i < (int)path.size() - 1; i++ ){
        if( graph[ path[i+1] ][ path[i] ] == 0 ) flag = false;
    }

    return flag;
}

int main() {
    ll ans = 0LL, N, M; cin >> N >> M;
    vector<vector<ll>> graph(N,vector<ll>(N,0));

    for( int i = 0; i < M; i++ ){
        ll a, b; cin >> a >> b; a--; b--;
        graph[a][b] = 1;
        graph[b][a] = 1;
    }

    vector<ll> path(N);
    for( int i = 0; i < N; i++ ){
        path[i] = i;
    }

    do{
        if( check(path,graph) ) ans++;
    }while(  next_permutation( path.begin(), path.end() )  );

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    int x[105],y[105];
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];
    int maxx = *max_element(x,x+n);
    int miny = *min_element(y,y+m);
    if (maxx >= miny) puts("War");
    else{
        bool ok = 0;
        rep(i,maxx+1,miny+1){
            if (X < i && i <= Y) ok = 1;
        }
        if (ok) puts("No War");
        else puts("War");
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a, b, max;
    scanf("%d %d",&a, &b);

    for (int i = a; 0 < i; i--){
        if(-1000000 <= b-i+1){
            printf("%d ", b-i+1);
        }
    }

    for(int i = 1; i < a; i++){
        if(b+i <= 1000000){
            printf("%d ", b + i);
        }
    }

    return 0;
}

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

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

Measured memory_bytes: 256