akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;

    vi l(n);
    rep(i, n) cin >> l[i];

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

    int a, b, c;

    ll cnt = 0;
    for (int i = 1; i < n - 1; i++) {
        for (int j = 0; j< i; j++) {
            for (int k = i + 1; k < n; k++) {
                b = l[i];
                a = l[j];
                c = l[k];

                if(c<a+b){
                    cnt++;
                }

            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  char b;
  cin >> b;
  if (b == 'A') P('T');
  else if (b == 'T') P('A');
  else if (b == 'G') P('C');
  else if (b == 'C') P('G');
  return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string> 
#include <iostream>
using namespace std;
int main() {
  
	string str;
	cin >> str;
	int count = str.length(); //タイルの個数
  	int num[count];
  	int change1 = 0; //変更した回数
  	int change2 = 0; //変更した回数
	for(int i=0; i<count; i++){
   		num[i] = (int)(str[i]-'0');
    }
  
  	for(int i=0; i<count; i++){
    	if(i%2 == 1 && num[i] == 0){
          	change1 ++;
        }
      	if(i%2 == 0 && num[i] == 1){
          	change1 ++;
        }
    }
  	
  	for(int i=0; i<count; i++){
    	if(i%2 == 1 && num[i] == 1){
          	change2 ++;
        }
      	if(i%2 == 0 && num[i] == 0){
          	change2 ++;
        }
    }
  
	if(change1 <= change2){
		printf("%d\n",change1);
    }else{
      printf("%d\n",change2);
    }
	return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, l;
  std::cin >> n >> l;

  int64_t ans = 0;
  for (int64_t i = l; i < l + n; i++) {
    ans += i;
  }
  if (0 <= l) {
    ans -= l;
  } else if (0 <= l + n - 1) {
    ans -= 0;
  } else {
    ans -= l + n - 1;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int count = 0;
        for(int i = 1; i <= n; i++){
            int num = sc.nextInt();
            if(i % 2 == 1 && num % 2 == 1)
                count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35908
#include<stdio.h>
#include <stdlib.h>
#define NIL -1

typedef struct{
  int id,depth,type,degree,height; //type:0,root,1,internal node, 2,leaf
  int parent;
  int left,right;
}treenode;
treenode a[25];
int H[25];
int findsiblings(int id){
  if(a[id].parent == NIL) return NIL;
  if(a[a[id].parent].left != id && a[a[id].parent].left != NIL)  return a[a[id].parent].left;
  if(a[a[id].parent].right != id && a[a[id].parent].right != NIL)  return a[a[id].parent].right;
  return NIL;
}
int ansdepth(int id){
  int cnt = 0;
  while(a[id].parent != NIL){
    cnt++;
    id = a[a[id].parent].id;
  }
  return cnt;
}
int ansheight(int id){
  int h1=0,h2=0;

  if(a[id].left!=NIL)
    h1=ansheight(a[id].left)+1;
  if(a[id].right!=NIL)
    h2=ansheight(a[id].right)+1;

  return H[id]=( h1>h2 ? h1 : h2 );
}
void preParse(int u){
  if(u == NIL) return;
  printf(" %d",u);
  preParse(a[u].left);
  preParse(a[u].right);
}

void inParse(int u){
  if(u == NIL) return;
  inParse(a[u].left);
  printf(" %d",u);
  inParse(a[u].right);
}

void postParse(int u){
  if(u == NIL) return;
  postParse(a[u].left);
  postParse(a[u].right);
  printf(" %d",u);
}
int main(){
  int n,d,i,j,k,id,l,r,root;
  int cnt = 1;
  scanf("%d",&n);
  for(i =0;i <n; i++) a[i].parent = NIL;
  for(i =0;i < n;i++){
    scanf("%d",&id);
    a[id].left = a[id].right;
    a[id].id = id;
    a[id].depth = 0;
    scanf("%d%d",&l,&r);
    a[id].left = l;
    a[id].right = r;
    if(l != NIL) a[l].parent = id;
    if(r != NIL) a[r].parent = id;
  }
  for(i =0;i < n;i++)  if(a[i].parent == NIL)  root = i;
  printf("Preorder\n");
  preParse(root);
  printf("\nInorder\n");
  inParse(root);
  printf("\nPostorder\n");
  postParse(root);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    long long X, K, Q;
    cin >> X >> K;
    vector<long long> r(K);
    REP (i, K) {
        cin >> r[i];
    }
    cin >> Q;
    vector<long long> t(Q), a(Q);
    long long max_a = INT_MIN, min_a = INT_MAX;
    REP (i, Q) {
        cin >> t[i] >> a[i];
        max_a = max(max_a, a[i]);
        min_a = min(min_a, a[i]);
    }

    //番兵を置く
    r.push_back(INT_MAX);
    t.push_back(INT_MAX);

    //上界、下界がどれだけ迫ってきているか
    long long up = 0, down = 0;

    //Aの量が増えている状態かどうか
    //最初はパーツAが上
    bool isRasing = false;

    //インデックス
    int r_index = 0, t_index = 0, before_time = 0;
    long long max_a_start = max_a, min_a_start = min_a;
    while (r_index != K || t_index != Q) {
        //printf("\nr[%d] = %lld, t[%d] = %lld, before_time = %lld\n", r_index, r[r_index], t_index, t[t_index], before_time);
        if (r[r_index] <= t[t_index]) {
            //rを処理
            if (isRasing) {
                max_a += r[r_index] - before_time;
                min_a += r[r_index] - before_time;

                if (X <= max_a) {
                    //上限がこれだけ落ちてきたとみなせる
                    down += max_a - X;
                    max_a = X;
                }
                min_a = min(min_a, X);
            } else {
                max_a -= r[r_index] - before_time;
                min_a -= r[r_index] - before_time;

                if (0 >= min_a) {
                    //下限がこれだけ上がってきた
                    up += -min_a;
                    min_a = 0;
                }
                max_a = max(max_a, 0LL);
            }

            isRasing = isRasing ? false : true;
            before_time = r[r_index++];
        } else {
            //tを処理
            if (isRasing) {
                max_a += t[t_index] - before_time;
                min_a += t[t_index] - before_time;

                if (X <= max_a) {
                    //上限がこれだけ落ちてきたとみなせる
                    down += max_a - X;
                    max_a = X;
                }
                min_a = min(min_a, X);
            } else {
                max_a -= t[t_index] - before_time;
                min_a -= t[t_index] - before_time;

                if (0 >= min_a) {
                    //下限がこれだけ上がってきた
                    up += -min_a;
                    min_a = 0;
                }
                max_a = max(max_a, 0LL);
            }
            if (max_a_start - a[t_index] <= down) {
                //上限との差が落ちている分よりも小さかったら上限と一致
                cout << max_a << endl;
            } else if (a[t_index] - min_a_start <= up) {
                //下限との差が上がっている分よりも小さかったら下限と一致
                cout << min_a << endl;
            } else {
                cout << max_a - (max_a_start - a[t_index] - down) << endl;
            }
            before_time = t[t_index++];
        }
        //printf("max_a = %lld, min_a = %lld, isRasing = %d\n", max_a, min_a, isRasing);
    }
}


Measured memory_bytes: 3552
#include<stdio.h>


int main() {
	int  room[4][3][10] = { 0 };	//room[b-tou][f-loor][r-oomnum] += v
	int i, j, k;
	int bmn, frn, rmn, dyn, DataN;

	scanf("%d", &DataN);

	for (i = 0; i < DataN; i++) {
		fflush(stdin);
		scanf("%d %d %d %d", &bmn, &frn, &rmn, &dyn);

		room[bmn-1][frn-1][rmn-1] += dyn;

	}


	for (i = 0; i < 4; i++) {			//mune
		for (j = 0; j < 3; j++) {		//floor
			for (k = 0; k < 10; k++) {	//romnum
				printf(" %d",room[i][j][k]);
			}
			printf("\n");
		}
		if (i == 3)break;
		for(j=0;j<20;j++)printf("#");
		printf("\n");
	}



	return 0;
}

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

using namespace std;

int main()
{
    long double A, B;
    cin >> A;
    cin >> B;
    if (A==B){
    cout << "EQUAL";

    } else if (A>B){
    cout <<"GREATER";
    }else if (A<B){
    cout << "LESS";
    }
    return 0;
}


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

int memo[100005];
set<int> edge[100005];

void dfs(int now)
{
	for (auto v:edge[now])
	{
		if (memo[v]==0)
		{
			memo[v]=memo[now];
			dfs(v);
		}
	}
}

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int x,y;
	for (int i = 0; i < m; ++i)
	{
		cin>>x>>y;
		edge[x].insert(y);
		edge[y].insert(x);
	}
	if (m+n/2<n-1)
	{
		cout<<"Impossible\n";
		return 0;
	}
	int cnt=0;
	for (int i = 0; i < n; ++i)
	{
		if (memo[i]==0)
		{
			++cnt;
			memo[i]=cnt;
			dfs(i);
		}
	}
	if (cnt==1)
	{
		cout<<"0\n";
		return 0;
	}
	long long mi[cnt+5];
	for (int i = 0; i < cnt+5; ++i)
	{
		mi[i]=(1LL<<50);
	}
	multiset<long long> r;
	for (int i = 0; i < n; ++i)
	{
		if (mi[memo[i]]==(1LL<<50))
		{
			mi[memo[i]]=a[i];
		}
		else if (mi[memo[i]]>a[i])
		{
			r.insert(mi[memo[i]]);
			mi[memo[i]]=a[i];
		}
		else
		{
			r.insert(a[i]);
		}
	}
	long long ans=0LL;
	for (int i = 1; i <= cnt; ++i)
	{
		ans+=mi[i];
	}
	cnt-=2;
	for (auto v:r)
	{
		if (cnt<=0)
		{
			break;
		}
		ans+=v;
		--cnt;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 19840
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(){
    int n; cin>>n;
    vector<string> w(n);
    for(int i=0;i<n;i++) cin>>w[i];
    bool ans=true;
    for(int i=1;i<n;i++){
        for(int j=0;j<i;j++){
            if(w[i]==w[j]) ans=false;
            //cout<<w[i]<<" "<<w[j]<<endl;
        }
    }
    //cout<<ans<<endl;
    for(int i=0;i<n-1;i++){
        if(w[i].back()!=w[i+1].front()) ans=false;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;


signed main()
{
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int w = x2 - x1;
  int h = y2 - y1;

  int k = max(abs(w), abs(h));

  int x3, y3, x4, y4;

  /*
  if (x1 == x2) {
    x3 = x2 - k;
    y3 = y2;
    x4 = x3;
    y4 = y1;
  }
  else {
    x3 = x2;
    y3 = y2 - k;
    x4 = x1;
    y4 = y3;
  }
  */

  x3 = x2 - h;
  y3 = y2 + w;
  x4 = x3 - w;
  y4 = y3 - h;

  printf("%d %d %d %d\n", x3, y3, x4, y4);

  return 0;
}



Measured memory_bytes: 256
n = int(input())
line = list(map(int,input().split()))
count = 1
up = False
down =False
for i in range(n - 1):
  if line[i] < line[i + 1]:
    up = True
  elif line[i] > line[i + 1]:
    down = True
  if up == down == True:
    count += 1
    up =False
    down =False
print(count)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) (c).size()
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)

#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=2e5+10;
const ll mod=1e9+7;

#pragma GCC Optimize("Ofast")

set<char>st;

int main(){
	string s;cin>>s;
	FOR(i,'a','z')
		st.insert(i);
	REP(i,sz(s))
		st.erase(s[i]);
	if(sz(st)!=0){
		cout<<s<<*st.begin();
		return 0;
	}
	ll pos=-1;
	REP(i,(sz(s)-1)){
		if(s[i]<s[i+1])
			pos=i;
	}
	if(pos==-1){
		cout<<-1;
		return 0;
	}
	char ch='z';
	FOR(i,pos,(sz(s)-1)){
		if(s[i]>s[pos])
			ch=min(ch,s[i]);
	}
	s[pos]=ch;
	FOR(i,0,pos)
		cout<<s[i];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.14159265358979323846
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

/*vector<int> parent, rak;

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rank[a]+=rank[b];
    }
}*/

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;

//vector<vector<ll>>v;
//vector<ll>vis,d;

int main() {
    IOS;
    cin>>n>>k;
    pll a[n];
    fo(i,n)cin>>a[i].ff>>a[i].ss;
    sort(a,a+n);
    fo(i,n){
        if(k>=a[i].ss){
            k-=a[i].ss;
            kv+=a[i].ss*a[i].ff;
        }
        else{
            kv+=k*a[i].ff;
            break;
        }
    }
    cout<<kv;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n); cin >> a;

  vi64 sums(n + 1);
  rep(i, n) sums[i + 1] = sums[i] + a[i];

  function<i64(int, int, int)> dist = [&](int l, int m, int r) {
    return abs((sums[r] - sums[m]) - (sums[m] - sums[l]));
  };

  assert(n >= 4);
  i64 ans = 1e18;
  int l = 0, r = 2;
  for (int i = 2; i + 2 <= n; i++) {
    while (l < i && dist(0, l, i) > dist(0, l + 1, i)) {
      l++;
    }
    while (r < n && dist(i, r, n) > dist(i, r + 1, n)) {
      r++;
    }
    pair<i64, i64> s = minmax({
      sums[l] - sums[0],
      sums[i] - sums[l],
      sums[r] - sums[i],
      sums[n] - sums[r],
    });
    amin(ans, s.second - s.first);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 2560
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    int n;
    cin >> n;
    int a[n];
    int ans[n];
    int sum = 0;
    int sum_odd = 0;
    for(int i = 0; i < n;i++) {
        cin >> a[i];
        sum += a[i];
        if(i % 2 == 1) sum_odd += a[i];
    }
    ans[0] = sum - 2*(sum_odd);
    cout << ans[0] << " ";
    for(int i = 0; i < n-1; i++){
        ans[i+1] = 2 * a[i] - ans[i];
        cout << ans[i+1] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2048
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列
#include <list>           //双方向連結リスト

using namespace std;

constexpr int MAX = 1046527;

constexpr int null = -1;

int64_t str_to_int(string str){
    int64_t tmp = 0;
    int64_t radix = 1;
    for(int i = str.size() - 1; i >= 0; --i){
        switch(str[i]){
            case 'A':
                tmp += radix;
                break;
            case 'T':
                tmp += 2 * radix;
                break;
            case 'C':
                tmp += 3 * radix;
                break;
            case 'G':
                tmp += 4 * radix;
                break;
        }
        radix *= 5;
    }
    return tmp;
}

int h(int64_t key, int skip = 0){
    return (key % MAX + skip * (1 + (key % (MAX -1)))) % MAX;
}


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

	int n;
    cin >> n;
    string tmp;
    vector<int64_t> d(MAX);
    std::fill(d.begin(), d.end(), null);
    cin.ignore();
    for(int i = 0; i < n; ++i){
        getline(cin, tmp);
        istringstream iss(tmp);
        vector<string> operation;
        while(getline(iss, tmp, ' ')){
            operation.emplace_back(tmp);
        }
        if(operation[0] == "insert"){
            int64_t key = str_to_int(operation[1]);
            for(int i = 0; i < MAX; ++i){
                if(d[h(key, i)] == null){
                    d[h(key, i)] = key;
                    break;
                }
            }
        }else if(operation[0] == "find"){
            int64_t key = str_to_int(operation[1]);
            for(int i = 0;; ++i){
                if(i >= MAX || d[h(key, i)] == null){
                    cout << "no\n";
                    break;
                }
                if(d[h(key, i)] == key){
                    cout << "yes\n";
                    break;
                }
            }
        }
    }
    
	return 0;
}


Measured memory_bytes: 10976
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <vector>
#include <map>
using namespace std;

typedef pair <long long, long long> pii;

const long long MAX_N = 2e5 + 10;
long long n, ans;
long long Arr[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (long long i = 0; i < n; i++)
		cin >> Arr[i];

	if (Arr[0]) {
		cout << "-1\n";
		return 0;
	}

	for (int i = 1; i < n; i++)
		if (Arr[i - 1] + 1 < Arr[i]) {
			cout << "-1\n";
			return 0;
		}

	long long tmp = 0;
	for (long long i = 1; i < n; i++) {
		tmp++;

		if (Arr[i] == 0) {
			tmp = 0;
			continue;
		}
		if (Arr[i] == 1) {
			ans++;
			tmp = 1;
			continue;
		}

		if (Arr[i] == tmp) {
			ans++;
			continue;
		}

		tmp = Arr[i];
		ans += Arr[i];
	}

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

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

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

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

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long X){
    Vi dp(X+1);
    dp[0]=1;
    REP(i,0,X){
        if(dp[i]==1 && i+100<=X) dp[i+100]=1;
        if(dp[i]==1 && i+101<=X) dp[i+101]=1;
        if(dp[i]==1 && i+102<=X) dp[i+102]=1;
        if(dp[i]==1 && i+103<=X) dp[i+103]=1;
        if(dp[i]==1 && i+104<=X) dp[i+104]=1;
        if(dp[i]==1 && i+105<=X) dp[i+105]=1;
    }
    cout<<dp[X]<<endl;
}

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


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

using namespace std;
int a[1010];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int flag=1;
    for(int i=0;i<n;i++){
        if(a[i]%2)continue;
        if(a[i]%3==0 || a[i]%5==0)continue;
        else flag=0;
    }
    if(flag==1)cout<<"APPROVED";
    else cout<<"DENIED";

    return 0;
}


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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll x;
	cin>>x;
	cout<<(x<30? "No\n":"Yes\n");
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""
 


Measured memory_bytes: 3532
#include <iostream>
#include <string>
#include <utility>
#include <queue>
using namespace std;
int main(void)
{
  int n, q, time, cnt_time = 0;
  string name;
  queue<pair<string, int> > que;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
  {
    cin >> name >> time;
    que.push(make_pair(name, time));
  }
  while (!que.empty())
  {
    pair<string, int> top = que.front();
    que.pop();
    if (top.second <= q)
    {
      cnt_time += top.second;
      cout << top.first << " " << cnt_time << endl;
    }
    else
    {
      cnt_time += q;
      que.push(make_pair(top.first, top.second - q));
    }
  }
  return 0;
}


Measured memory_bytes: 6164
#include <cstdio>
using namespace std;
int is_ok[20];
int main(int argc, char const *argv[])
{
	int l;
	scanf("%d",&l);
	int now = l;
	int cnt = 0,cur = 0;
	while(l)
	{
		if(l & 1)
		{
			is_ok[cnt] = 1;
			cur++;
		}
		l >>= 1;
		cnt++;
	}
	printf("%d %d\n",cnt,(cnt - 1) * 2 + cur - 1);
	int t = 1;
	l = now;
	for(int i = 1;i < cnt; ++i)
	{
		printf("%d %d %d\n%d %d %d\n",i,i + 1,0,i,i + 1,t);
		if(is_ok[i - 1])
		{
			printf("%d %d %d\n",i,cnt,l - t);
			l -= t;
		}
		t <<= 1;
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int cnt=0;
  string a[50][50][10];
  for(int i=0;i<50;i++)
    for(int j=0;j<50;j++)
      for(int k=0;k<10;k++)
	a[i][j][k]="";
  while(cin>>n,n!=0){
    //    vector<pair<string,int> > s;
    vector<vector<string> > anspo(50);
    for(int i=0;i<n;i++){
      string str;cin>>str;
      int w,l,d;cin>>w>>l>>d;
      //s.push_back(make_pair(str,w*3+d));
      anspo[w*3+d].push_back(str);
    }
    for(int i=49;i>=0;i--){
      for(int j=0;j<anspo[i].size();j++){
	a[cnt][i][j]=anspo[i][j];
      }
    }
    cnt++;
  }
  for(int i=0;i<cnt;i++){
    for(int j=49;j>=0;j--){
      for(int k=0;k<10;k++){
	if(a[i][j][k]!="")
	  cout<<a[i][j][k]<<","<<j<<endl;
      }
    }
    if(i!=cnt-1)
      cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3260
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)    for(int i=0;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    string s;
    cin>>s;
    int x=s[SZ(s)-1]-'0';
    if(x==2||x==4||x==5||x==7||x==9)cout<<"hon"<<nl;
    else if(x==3)cout<<"bon"<<nl;
    else cout<<"pon"<<nl;
    return 0;
}


Measured memory_bytes: 3632
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> Vi;
typedef pair<int,int> pii;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=1000+19;
const int oo=(1<<30)-1;

char s[N][N];
int sum[N][N];
int n,tmp,res=oo;

int cal(int X1,int Y1,int X2,int Y2){
	return sum[X2][Y2]-sum[X2][Y1-1]-sum[X1-1][Y2]+sum[X1-1][Y1-1];
}

int main(){
	n=IN();
	For(i,1,n+1) scanf("%s",s[i]+1);
	For(i,1,n+1) For(j,1,n+1){
		sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(s[i][j]=='#');
	}
	if (!sum[n][n]) return puts("-1"),0;
	For(i,1,n+1) if (cal(1,i,n,i)==n) tmp++;
	For(i,1,n+1){
		res=min(res,n-cal(i,1,i,n)+!cal(1,i,n,i)+n-tmp);
	}
	printf("%d\n",res);
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int ans=0;
unordered_map<int,int> dp;
int dfs(int node, vector<vector<int>> &adj)
{
    if(dp.count(node)>0)
        return dp[node];
    int len=1;
    int neigh=0;
    for(int i=0;i<adj[node].size();i++)
    {
        neigh=max(neigh,dfs(adj[node][i],adj));
    }
    len+=neigh;
    dp[node]=len;
    return dp[node];
}
int main()
{
    int v,e;
    cin>>v>>e;
    vector<vector<int>> adj(v+1);
    int a,b;
    for(int i=0;i<e;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
    }
    int ans=0;
    for(int i=1;i<=v;i++)
    {
        dfs(i,adj);
        // cout<<dp[i]<<" ";
        ans=max(ans,dp[i]);
    }
    // cout<<endl;
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 11940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);
ll get_digent(ll);


int main(){
  often();
  int l,n,sum=0;
  cin >> n >> l;
  sum = l*n + ((n+1)*n)/2 - n;
  if(l<0 && l+n-1>=0) cout << sum << endl;
  else if(l<0 && l+n-1<0) cout << sum - l - n + 1 << endl;
  else if(l>=0) cout << sum - l << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

ll get_digent(ll x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Tue Jun 26 02:16:19 2018
//
package main

import "fmt"

var N, K int
var arr []int

func cover(len int) int {
	if len == 1 {
		return 0
	}

	return ((len - 1) + K - 2) / (K - 1)
}

func main() {
	fmt.Scan(&N, &K)

	arr := make([]int, N)

	for i := range arr {
		fmt.Scan(&arr[i])
	}

	fmt.Println(cover(len(arr)))
}


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

char mark[4] = "dox";
string ss;

int check(){
    for(int h = 1; h <= 2; h++){
        for(int i = 0; i < 3; i++){
            int j;
            for(j = 0; j < 3; j++){
                if( ss[i*3+j] != mark[h] ) break;
            }
            if(j == 3) return h;
            for(j = 0; j < 3; j++){
                if( ss[j*3+i] != mark[h] ) break;
            }
            if(j == 3) return h;
        }
        int c;
        for(c = 0; c < 3; c++){
            if( ss[4*c] != mark[h] ) break;
        }
        if( c == 3 ) return h;
        for(c = 0; c < 3; c++){
            if( ss[2+2*c] != mark[h] ) break;
        }
        if( c == 3 ) return h;
    }
    return 0;
}

int main(){
    while( cin >> ss ){
        int r = check();
        cout << mark[ r ] << endl;
    }
    return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

ll memo[100] = {0};

ll calc(int i) {
  if (memo[i] != 0) return memo[i];
  return memo[i] = calc(i - 1) + calc(i - 2);
}

int main() {
  memo[0] = 2;
  memo[1] = 1;
  int n;
  cin >> n;
  p(calc(n));
}

Measured memory_bytes: 256
N, D = map(int, input().split())
X = [list(map(int, input().split())) for l in range(N)]
count = 0

for i in range(N):
  if (X[i][0])**2 + (X[i][1])**2 - D**2 <= 0:
    count = count + 1
    
print(count)


Measured memory_bytes: 45164
S = input()
x, y = map(int, input().split())
XY = [len(x) for x in S.split('T')]
moveX = XY[0::2] + [0]
moveY = XY[1::2] + [0]
def moves(t, move):
  if sum(move) >= t:
    pos = [0] * (sum(move) - t + 1)
    P = len(pos)
    pos[0] = 1
    for m in move:
      _pos = [x for x in pos]
      for i, p in enumerate(pos):
        if p and i + 2 * m < P:
          _pos[i + 2 * m] = 1
      pos = _pos
    return pos[-1]
  else:
    return False
print('Yes' if moves(x - moveX[0], moveX[1:]) and moves(y, moveY) else 'No')

Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  ll x,y;
  cin>>x>>y;
  ll ans=0;
  while(x<=y){
    ans++;
    x*=2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll a[n], b[n], c[n-1];
   for(ll i=0;i<n;i++)
       cin>>a[i];
   for(ll i=0;i<n;i++)
       cin>>b[i];
   
   for(ll i=0;i<n-1;i++)
       cin>>c[i];
   
   ll ans = 0;
   ll prev = -2;
   
   for(ll i=0;i<n;i++)  
   {
       ll curr = a[i]-1;
       ans+=b[curr];
       if(prev == curr-1)
            ans+=c[prev];
       prev = curr;        
   }
   
   cout<<ans;
   
   return 0;
}

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

#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
	int r, g;
	cin>>r>>g;
	cout << 2*g-r<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split())

def xor(p):
  if p%4 == 0:
    return p
  elif p%4 == 1:
    return 1
  elif p%4 == 2:
    return p+1
  elif p%4 == 3:
    return 0

if a==0:
  print(xor(b))
elif a == b:
  print(a)
else:
  s=max(xor(b),xor(a-1))
  t=min(xor(a-1),xor(b))
  data=[]
  while s>0:
    data.append(s%2)
    s=s//2
  for i in range(len(data)):
    if (data[i] == t%2):
      data[i] = 0
    else:
      data[i] = 1
    t = t//2
  sum=0
  for i in range(len(data)):
    sum+= data[i]*(2**i)
  print(sum)

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
x=[0]*N

for i,a in enumerate(A):
    if i%2==0:
        x[0]+=a
    else:
        x[0]-=a

for i in range(1,N):
    x[i]=2*A[i-1]-x[i-1]

print(' '.join([str(c) for c in x]))

Measured memory_bytes: 75364
#include <iostream>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <queue>
#include <stack>

using namespace std;

struct pos {
    pos() {x = 0;y = 0;}
    pos(int x, int y) {
        this->x = x;
        this->y = y;
    }
    int x, y;
};

const int INF = 1000000000;
const int mvx[] = {-1, 0, 1, 0};
const int mvy[] = {0, 1, 0, -1};

int map[1002][1002];
int mem[1002][1002];
pos cpos[10];

signed main() {
    int h,w,n;
    cin >> h >> w >> n;

    {
        int ccount = 0;
        for (int y = 1; y <= h; ++y) {
            string s;
            cin >> s;
            for (int x = 1; x <= w; ++x) {
                switch (s[x - 1]) {
                    case 'X':
                        map[x][y] = -1;
                        break;
                    case 'S':
                        cpos[0] = pos(x, y);
                        break;
                    case '.':
                        break;
                    default :
                        int hard = s[x - 1] - '0';
                        map[x][y] = INF + hard;
                        cpos[hard] = pos(x, y);
                }
            }
        }
    }

    for (int x = 0; x <= w + 1; ++x) {
        map[x][0] = -1;
        map[x][h + 1] = -1;
    }
    for (int y = 1; y <= h; ++y) {
        map[0][y] = -1;
        map[w + 1][y] = -1;
    }

    int cstep[9] = {0};
    for (int i = 0; i < n; ++i) {
        queue<pos> q;
        q.push(cpos[i]);
        int target = map[cpos[i + 1].x][cpos[i + 1].y];
        while (q.size()) {
            pos head = q.front();
            q.pop();
            int nextstep = mem[head.x][head.y] + 1;

            for (int k = 0; k < 4; ++k) {
                int tx = head.x + mvx[k], ty = head.y + mvy[k];

                if (map[tx][ty] == target) {
                    cstep[i] = nextstep;
                    goto end;
                }

                if (((map[tx][ty] != 0) && (map[tx][ty] < INF)) || (mem[tx][ty] != 0)) continue;

                q.push(pos(tx, ty));
                mem[tx][ty] = nextstep;
            }
        }
        end:;
        for (int x = 1; x <= w; ++x) {
            for (int y = 1; y <= h; ++y) {
                mem[x][y] = 0;
            }
        }
    }

    int result = 0;
    for (int i = 0; i < n; ++i) {
        result += cstep[i];
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 9068
# ABC056 B - Rain Flows into Dams
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

W,a,b = nl()

ans = 0
if b+W<a:
    ans = a-(b+W)
elif b+W>=a and b<=a+W:
    ans = 0
elif b>W+a:
    ans = b-(W+a)

print(ans)


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t k, x;
  std::cin >> k >> x;
  if (x <= 500 * k) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    x = []
    for i in range(1, n+1):
        s_, p_ = input().split()
        x += [[i, s_, int(p_)]]
        x = sorted(x, key=lambda x:(x[1],-x[2]))
    for i in range(n):
        print(x[i][0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int hm,num[100];
  int i,gu=0,ap=0;
  
  scanf("%d",&hm);
  for(i=0;i<hm;i++){
    scanf("%d",&num[i]);
  } //ここまで初期化
  
  for(i=0;i<hm;i++){
    if(num[i]%2==0){
      gu++;
      if(num[i]%3==0 || num[i]%5==0){
        ap++;
      }
    }
  }
  
  //printf("ぐ:%d 3,5:%d\n",gu,ap); //DEBUG
  
  if(gu==ap)
    printf("APPROVED");
  else
    printf("DENIED");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;
const ll inf = (ll) 9e18;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  vector<ll> asum(n+1);
  for (int i = 0; i < n; i++) asum[i+1] = asum[i] + a[i];

  auto find_2part = [&](int a, int b) {
    int left = a;
    int right = b;
    while (left + 1 < right) {
      int center = (left + right) / 2;
      ll lsum = asum[center] - asum[a];
      ll rsum = asum[b] - asum[center];
      if (lsum == rsum) return center;
      else if (lsum < rsum) left = center;
      else right = center;
    }
    ll leftsum = asum[left] - asum[a];
    ll rightsum = asum[b] - asum[right];
    if (leftsum > rightsum) return left;
    else return right;
  };

  ll ans = inf;
  for (int i = 2; i < n-1; i++) {
    int lp = find_2part(0, i);
    int rp = find_2part(i, n);
    vector<ll> s = {asum[lp] - asum[0], asum[i] - asum[lp], asum[rp] - asum[i], asum[n] - asum[rp]};
    sort(s.begin(), s.end());
    ll diff = s[3] - s[0];
    if (diff < ans) ans = diff;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, tail = 0, prev = -1, ret = 0;
    cin >> N;
    FOR(i, 0, N) {
        int h;
        cin >> h;
        if (h <= prev || i == 0)
            tail++;
        else
            tail = 1;
        prev = h;
        ret = max(ret, tail);
    }

    cout << --ret << endl;
    return 0;
};


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = 0
c = 0
for i in range(len(a)):
    if i == 0:
        c = a[i]
    elif c > a[i]:
        b += c - a[i]
    else:
        c = a[i]
print(b)

Measured memory_bytes: 32052
int main(void){
  int n,x,y,nx,ny,max,mx,my,tmp;

  scanf("%d",&n);
  while(n--){
    nx=ny=max=0;
    while(1){
      scanf("%d%d",&x,&y);
      if(!x && !y) break;

      nx+=x,ny+=y;
      tmp = nx*nx+ny*ny;
      if(max<tmp){
        max = tmp;
        mx=nx,my=ny;
      }
      else if(max==tmp && mx<nx){
        max = tmp;
        mx=nx,my=ny;
      }
    }
    printf("%d %d\n",mx,my);
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  vector<int> c(n-1),s(n-1),f(n-1),ans(n,0);
  for(int i=0;i<n-1;++i)cin>>c[i]>>s[i]>>f[i];
  for(int i=0;i<n-1;++i){
    for(int j=0;j+i<n-1;++j){
      ans[j] += (s[i+j]<=ans[j]?(f[i+j]-ans[j]%f[i+j])%f[i+j]:s[i+j]-ans[j]) + c[i+j];
    }
  }
  for(auto i:ans)cout<<i<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

signed main(){
    fastio
    int n;cin>>n;
    vector<string>a(n);
    for(int i=0;i<n;i++)    cin>>a[i];
    sort(a.begin(),a.end(),[&](string &a,string &b){
        return a<b;
    });
    int count=1,ma=1;
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1])    count++;
        else{
            ma=max(count,ma);
            count=1;
        }
    }
    ma=max(count,ma);
    count=1;
    set<string>s;
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1])    count++;
        else{
            if(count==ma){
                s.insert(a[i-1]);
            }
            count=1;
        }
    }
    if(count==ma)   s.insert(a[n-1]);
    for(auto x:s)   cout<<x<<"\n";
}


Measured memory_bytes: 22272