akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int F[110][12];
int P[110][12];

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

	cin >> N;
	rep(i, 0, N)rep(j, 0, 10)
	{
		cin >> F[i][j];
	}
	rep(i, 0, N)rep(j, 0, 11)
	{
		cin >> P[i][j];
	}

	int ans = -INF;
	rep(i, 1, 1 << 10)
	{
		int cnt[110] = { 0 };
		rep(j, 0, 10)
		{
			if ((i >> j) & 1)
			{
				rep(k, 0, N)
				{
					if (F[k][j] == 1)
					{
						cnt[k]++;
					}
				}
			}
		}
		int res = 0;
		rep(k, 0, N)
		{
			res += P[k][cnt[k]];
		}
		chmax(ans, res);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	vector<vector<int>> a(N);
	a[X - 1].push_back(Y - 1);
	a[Y - 1].push_back(X - 1);
	for (int i = 1; i < N; i++) {
		a[i - 1].push_back(i);
		a[i].push_back(i - 1);
	}
	vector<int> ans(N - 1);
	for (int i = 0; i < N - 1; i++) {
		priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> b;
		b.emplace(0, i);
		vector<bool> c(N);
		vector<int> d(N, INT_MAX);
		d[i] = 0;
		while (!b.empty()) {
			pair<int, int> e = b.top();
			b.pop();
			c[e.second] = true;
			for (int& j : a[e.second]) {
				if (c[j]) continue;
				if (e.first + 1 < d[j]) {
					d[j] = e.first + 1;
					b.emplace(d[j], j);
				}
			}
		}
		for (int j = i + 1; j < N; j++) ans[d[j] - 1]++;
	}
	for (int& i : ans) cout << i << endl;
}

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

#define fs first
#define sc second
#define mp make_pair
#define eb emplace_back
#define sz(s) ((int) s.size())
#define all(s) s.begin(), s.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef unsigned long long ull;

const ll linf = (ll) 1e18;

const int A = 26;
const int L = 17;
const int B = 315;
const int inf = (int) 1e9;
const int mod = (int) 1e9 + 7;

const int di[] = {-1, +0, +1, +0};
const int dj[] = {+0, +1, +0, -1};

const double pi = acos(-1.0);
const double eps = 1e-11;

int n;
int m;
int k;

inline bool read() {
	if (!(cin >> n >> m >> k)) {
		return false;
	}	
	return true;
}
inline void init() {

}
inline void solve() {
	for (int r = 0; r <= n; r++) {
		for (int c = 0; c <= m; c++) {
			if (r * (m - c) + c * n - c * r == k) {
				puts("Yes");
				return;
			}
		}
	}	
	puts("No");
}
int main() {
    #ifdef LOCAL
    	#define name ""
    	freopen(name".in", "r", stdin);
    	freopen(name".out", "w", stdout);
    #endif
    while (read()) {
    	init();
    	solve();
    }
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

typedef struct{
  int p,left,right;
}Node;

Node Tree[MAX];
int n,height;
int Depth[MAX];



int getDepth(int i){
  int depth=0;
  while(Tree[i].p>=0){
    i=Tree[i].p;
    depth++;
  }
  return depth;
}



main(){
  int i,ii,j,n;
  int  id,k,np,right,left;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    Tree[i].p=-1;
    Tree[i].left=-1;
    Tree[i].right=-1;
  }


  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&np);
      Tree[np].p=id;
      
      if(j==0)
	Tree[id].left=np;
      else if (j>=1)
	Tree[right].right=np;
      right=np;
    }
  }



  for(i=0;i<n;i++)
    Depth[i]=getDepth(i);
  
  
  for(i=0;i<n;i++){
    if(Tree[i].p==-1)
      printf("node %d: parent = %d, depth = %d, root, ",i,Tree[i].p,Depth[i]);
    else if(Tree[i].left==-1)
      printf("node %d: parent = %d, depth = %d, leaf, ",i,Tree[i].p,Depth[i]);
    else
      printf("node %d: parent = %d, depth = %d, internal node, ",i,Tree[i].p,Depth[i]);
    

    ii=i;

    printf("[");
    if(Tree[ii].left!=-1){
      printf("%d",Tree[ii].left);
      if(Tree[Tree[ii].left].right==-1) printf("]\n");
      else printf(",");
      
      ii=Tree[ii].left;
      
      
      while(Tree[ii].right!=-1){
	printf(" %d",Tree[ii].right);
	
	if(Tree[Tree[ii].right].right==-1)
	  printf("]\n");
	else printf(",");
	ii =Tree[ii].right;
      }
    }
    else  printf("]\n");
  }
    
    
  return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

bool isP(string s) {
    int left = 0;
    int right = s.length() - 1;
    bool result = true;
    while (left <= right) {
        if (s[left] == s[right]) {
            left++;
            right--;
        } else {
            result = false;
            break;
        }
    }

    return result;
}
int main() {
    SS(string,s);
    bool ans =true;
    if(!isP(s))ans=false;
    if(!isP(s.substr(0,(s.length()-1)/2))) ans=false;
    debug(s.substr(0,(s.length()-1)/2));
    if(!isP(s.substr((s.length()+3)/2-1,s.length()-(s.length()+3)/2+1))) ans=false;
    debug(s.substr((s.length()+3)/2-1,s.length()-(s.length()+3)/2+1));
    Yes(ans);
}

Measured memory_bytes: 256
R = 0
G = 1
B = 2


def check(ns):
    return ns[G] > ns[R] and ns[B] > ns[G]

def solve(ns, k):
    if check(ns):
        return True
    if k == 0:
        return False
    for i in xrange(3):
        ms = ns[:]
        ms[i] *= 2
        if solve(ms, k - 1):
            return True
    return False


assert solve([7, 2, 5], 3) == True
assert solve([7, 4, 2], 3) == False


ns = map(int, raw_input().split())
k = int(raw_input())

print 'Yes' if solve(ns, k) else 'No'



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

#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double ld;

const ld pi=3.1415926535897932384626433;
const int mod = 1000000007;
const ll inf=3e18;

int main ()
{
   bolt;
   ll n,m;
   cin>>n>>m;
   set <ll> s;
   vector <ll> h(n+1,0);
   for (ll i=1;i<=n;i++)
   {
      cin>>h[i];
      s.insert(i);

   }
   for (ll i=0;i<m;i++)
   {
      ll a,b;
      cin>>a>>b;
      if (h[a]==h[b])
      {
         if (s.find(a)!=s.end())
            s.erase(a);
         if (s.find(b)!=s.end())
            s.erase(b);

         continue;
      }
      ll k=max(h[a],h[b]);
      if (h[a]!=k)
      {
         if (s.find(a)!=s.end())
            s.erase(a);

      }
      else
      {
         if (s.find(b)!=s.end())
            s.erase(b);
      }
   }
   cout<<s.size();
}


Measured memory_bytes: 8744
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main(){
int N,K;
cin >> N >> K;
double answer=0;
for(int i=1;i<=N;i++){
double tmp=1.0/N;//ちゃんと1ではなく1.0と書いて実数に合わせる。
int now=i;
while(now<K){
    now*=2;
    tmp/=2;
}
answer+=tmp;
}
cout << setprecision(12)<<answer <<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fp(i,k) for(i=0;i<k;i++)
#define fm(i,k) for(i=k;i>=0;i--)
#define fr(i,j,k) for(i=j;i<k;i++)
#define pb push_back
#define vll vector<ll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>)
ll arr[1000005];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll t,n,m,x,y,cnt1=0,f,cnt2=0,cnt3=0,i,j,k;
    cin>>n;
    if(n<=999 )cout<<"ABC\n";
    else cout<<"ABD\n";
    return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;



int main(int argc, char *argv[])
{
	int n, k;
	double ans = 0;

	//input
	cin >> n >> k;

	//calc
	for (int i = 1; i <= n; i++){
		if (k <= i){
			ans += (double)1.0 / n;
		}
		else{
			double current_probability = (double)1.0 / n;
			int current_point = i;

			while (current_point < k){
				current_point *= 2;
				current_probability /= 2;
			}

			ans += current_probability;
		}
	}

	//ans
	cout << std::setprecision(12) << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++){
    color[u]=WHITE;
    tt=0;
  }
  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}



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

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int side[7][7] = {
	{},
	{0, 0, 3, 5, 2, 4, 0},
	{0, 4, 0, 1, 6, 0, 3},
	{0, 2, 6, 0, 0, 1, 5},
	{0, 5, 1, 0, 0, 6, 2},
	{0, 3, 0, 6, 1, 0, 4},
	{0, 0, 4, 2, 5, 3, 0}
};

int height[21][21];
int cnt[7];
int field[21][21];

int main() {
	int n;
	while(cin >> n, n) {
		memset(height, 0, sizeof(height));
		memset(cnt, 0, sizeof(cnt));
		memset(field, 0, sizeof(field));
		rep(i,n) {
			int t, f;
			cin >> t >> f;
			int sx=5, sy=5;
			while(1) {
				const int dx[4] = {-1, 0, 1, 0};
				const int dy[4] = { 0,-1, 0, 1};
				int s[4] = {7-side[t][f], 7-f, side[t][f], f};
				bool can[4] = {};
				bool exist = false;
				rep(j,4) {
					can[j] = (height[sx][sy] > height[sx+dx[j]][sy+dy[j]] && s[j]>=4);
					if(can[j]) exist = true;
				}
				if(!exist) {
					height[sx][sy]++;
					cnt[field[sx][sy]]--;
					cnt[t]++;
					field[sx][sy] = t;
					break;
				}
				int mdir = -1;
				rep(j,4) {
					if(can[j]) {
						mdir = (mdir==-1 || s[mdir] < s[j] ? j : mdir);
					}
				}
				if(mdir == 1) {
					f = 7-t;
				} else if(mdir == 3) {
					f = t;
				}
				t = 7-s[mdir];
				sx += dx[mdir];
				sy += dy[mdir];
			}
		}
		cout << cnt[1];
		for(int i=2; i<=6; i++) {
			cout << " " << cnt[i];
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
	int start=0,check=0;
	string st,temp;
	string array[4]={"dream","dreamer","erase","eraser"};

	cin >>st;
	reverse(st.begin(),st.end());
	for(int i=0;i<4;i++)reverse(array[i].begin(),array[i].end());
	for(int i=0;i<(int)st.size();i++){
		temp+=st[i];
		if(start+4==i){
			if(temp==array[0]||temp==array[2]){
				start=i+1;
				temp="";
			}
		}
		else if(start+5==i&&temp==array[3]){
			start=i+1;
			temp="";
		}
		else if(start+6==i){
			if(temp==array[1]){
				start=i+1;
				temp="";
			}
			else check=1;
		}
	}
	if(check==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}

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

bool search(int A[], int n, int key){
    int i=0;
    A[n] = key;
    while(A[i] != key){
        i++;
    }
    return i!= n;
}
int main(){
    int i, n, q, key, sum=0;
    scanf("%d", &n);
    int a[n+1];
    for(i=0; i<n; i++) scanf("%d", &a[i]);
    
    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &key);
        if (search(a, n, key)) sum++;
    }
    printf("%d\n", sum);
}


Measured memory_bytes: 3232
N,X = map(int,input().split())
L_list = [0 for i in range(N)]

L = list(map(int,input().split()))

D = 0
count = 0

if D <= X :
    count += 1

for i in range(N):
    D_next = D + L[i]
    if(D_next <= X):
        count += 1
    D = D_next

print(count)

Measured memory_bytes: 38384
"use strict";

var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );

readable.on( 'data', function( chunk ) {
		var data = chunk.split( ' ' ).map(Number);
		var W = data[0];
		var H = data[1];
		var x = data[2];
		var y = data[3];
		var r = data[4];
		if( (0 <= x-r && 0 <= y-r) && (x+r <= W && y+r <= H) || (0 <= x-r && y+r <= H) && (x+r <= W && 0 <= y-r)  ) {
			console.log( "Yes" );
		} else {
			console.log( "No" );
		}

});


Measured memory_bytes: 19336
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	string S;
	cin >> N >> S;
	
	int l = 0, r = N - 1;
	int ans = 0;
	while (l < r) {
		while (l < r && S[l] == 'R') ++l;
		while (l < r && S[r] == 'W') --r;
		if (l < r) {
			++ans;
			++l;
			--r;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  ll X, Y, Z;
  cin >> X >> Y >> Z;
  int cnt=0;
  for(int i=1;i<X;i++){
    if(X+1>Z+(Y+Z)*i){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3600
d=input().split()
for _ in range(int(input())):
 t,f=[int(d.index(s))for s in input().split()]
 n=[(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])


Measured memory_bytes: 5608
#include<iostream>

using namespace std;

int main()
{
    int h,m,s,d;

    cin >> d;
    h=d/60/60;
    d-=3600*h;
    m=d/60;
    d-=60*m;
    s=d;

    cout <<h<<':'<<m<<':'<<s<<endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
const int INF = 1001001001;
vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachabletoN[2505];
bool ok[2505];
void dfs(int v)
{
    if (reachablefrom1[v]) return;
    reachablefrom1[v] = true;
    for (int u : to[v]) {
        dfs(u);
    }
}

void rdfs(int v)
{
    if (reachabletoN[v]) return;
    reachabletoN[v] = true;
    for (int u : rto[v]) {
        rdfs(u);
    }
}
int main(void)
{
    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edges;
    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        c -= p;
        c = -c;
        edges.emplace_back(a, b, c);
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    dfs(0);
    rdfs(n - 1);
    rep(i, n) ok[i] = reachablefrom1[i] & reachabletoN[i];
    {
        vector<int> d(n, INF);
        d[0]     = 0;
        bool upd = true;
        int step = 0;
        while (upd) {
            upd = false;

            rep(i, m)
            {
                int a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a]) continue;
                if (!ok[b]) continue;
                int newD = d[a] + c;
                if (newD < d[b]) {
                    upd  = true;
                    d[b] = newD;
                }
            }
            step++;
            if (step > n) {
                puts("-1");
                return 0;
            }
        }
        int ans = -d[n - 1];
        ans     = max(0, ans);
        cout << ans << endl;
    }
}



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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;
  vector<ll> x(n),y(n);
  rep(i,n){
    x[i] = a[i]+i+1;
    y[i] = -a[i]+i+1;
  }
  dump(x,y);

  ll ans = 0;
  map<ll,ll> cnti,cntj;
  rep(i,n){
    cnti[x[i]]++;
    cntj[y[i]]++;
  }
  rep(i,n){
    cntj[y[i]]--;
    ans += cntj[x[i]];
    cnti[x[i]]--;
  }
  cout<<(ans)<<endl;

}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(i, v) for(auto i =  v.begin(); i !=  v.end(); ++i)
#define RFOR(i, v) for(auto i = v.rbegin(); i != v.rend(); ++i)

template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> ostream & operator<<(ostream & os, const vector<T> & v) {
	os << "[";
	FOR(it, v) {
		if(it != v.begin()) { os << ", "; }
		os << *it;
	}
	os << "]";
	return os;
}
template<typename F, typename S> ostream & operator<<(ostream & os, const pair<F, S> & p) {
	os << "<" << p.FI << ", " << p.SE << ">";
	return os;
}

// ---- ----

int n, a[100000];
int b[100000];
const int MOD = 1000000007;

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) { b[ a[i] ]++; }
	
	bool flag = true;
	if(n % 2 == 0) {
		inc(i, n) {
			if(i % 2 == 0 && b[i] != 0) { flag = false; }
			if(i % 2 == 1 && b[i] != 2) { flag = false; }
		}
	} else {
		inc(i, n) {
			if(i % 2 == 1 && b[i] != 0) { flag = false; }
			if(i % 2 == 0) {
				if(i == 0 && b[i] != 1) { flag = false; }
				if(i != 0 && b[i] != 2) { flag = false; }
			}
		}
	}
	
	LL ans = (flag ? 1 : 0);
	inc(i, n) {
		if(b[i] != 0) { (ans *= b[i]) %= MOD; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
X, K, D = map(int,input().split())
X = abs(X)
if K * D >= X:
    if (K - X // D) % 2 == 0: print(abs(X - X // D * D))
    else: print(abs(X - (X // D + 1) * D))
else: print(abs(X - K * D))


Measured memory_bytes: 61856
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
2
5
5
'''


def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()
  l = []
  for i in range(0, n):
    l.append(IN_I())

  l2 = l.copy()
  l.sort()

  for i in l2:
    if i == l[-1]:
      print(l[-2])
    else:
      print(l[-1])

  return None


def B():
  return None


def C():
  return None


MAIN()


Measured memory_bytes: 15064
import math

input = map(float, raw_input().split(" "))
a = input[0]
b = input[1]
c = math.radians(input[2])

h = math.sin(c) * b
s = a * h / 2
l = math.pow((a - math.cos(c) * b) ** 2 + h ** 2, 0.5) + a + b

print "{0:.5f}".format(s)
print "{0:.5f}".format(l)
print "{0:.5f}".format(h)

Measured memory_bytes: 6752
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>

using namespace std;
using ll = long long;
using ld = long double;

namespace NyaGadget
{
	struct NyaStruct {
		ll times = 0;
		ll v = 0;
	};

	auto NyaSort = [](const NyaStruct& l, const NyaStruct& r)
	{	// 昇順は演算子>, 降順は演算子<, if順の優先でソートされる
		return l.v > r.v;
	};
}

#define all(collection) (collection).begin(), (collection).end()              // begin to end
#define divc(a, b) ceil((ld) a / (ld) b);                                     // div ceiling
#define rep(i, begin, end) for (ll i = begin; i < end; i++)                   // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)                  // repeat reverse
#define size(collection) ((ll) (collection).size())                           // collection size
/********** for each macro **********/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define forir(i, ...) if(ll i = size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, v) forir(i, auto& e: boost::adaptors::reverse(v))

using namespace NyaGadget;

int main(void)
{
	ll N, M; cin >> N >> M;

	vector<ll> A(N);
	each(i, e, A)
		cin >> e;

	vector<NyaStruct> B(M);
	each(i, e, B)
		cin >> e.times >> e.v;
	sort(all(A));
	sort(all(B), NyaSort);

	vector<ll> change;
	[&]
	{
		each(i, e, B)
		{
			rep(j, 0, e.times)
			{
				change.push_back(e.v);
				if (size(change) == N) return;
			}
		}
	}();

	each(i, e, change)
		if (A[i] < e) A[i] = e;

	cout << accumulate(all(A), 0LL);
	return 0;
}


Measured memory_bytes: 3832
#include <stdio.h>
#include <math.h>

int main(void){

    int days, number, i, sum, ans;
    int syukudai[100000] = {0};

    scanf("%d", &days);
    scanf("%d", &number);

    sum = 0;

    for(i = 0; i < number; i++){
        scanf("%d", &syukudai[i]);
        sum += syukudai[i];
    }

    ans = days - sum;

    if(ans < 0){
        printf("-1\n");
    }

    else printf("%d\n", ans);

    return 0;

}

Measured memory_bytes: 2124
#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, M;
    cin >> N >> M;
    vector<vector<int>> jobs(M);
    rep(i,N) {
        int A, B;
        cin >> A >> B;
        if (A > M) continue;
        jobs[M-A].push_back(B);
    }
    priority_queue<int> q;
    ll ans = 0;
    for (int i = M-1; i >= 0; --i) {
        for (int b: jobs[i]) {
            q.push(b);
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
n = int(input())
D = list(map(int,input().split()))
ma = max(D)
l = [0]*n
ans = 1

if D[0] != 0:
    print(0)
    exit()
    
for e in D:
    l[e] += 1

if l[0] != 1:
    print(0)
    exit()

for i in range(ma):
    ans = ans * l[i] ** l[i+1]
    ans = ans % 998244353
print(ans)

Measured memory_bytes: 13892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int s;
    int cnt=0;
    map<int,int>a;
    cin >> s;
    while(1){
        cnt ++;
        a[s]++;
        if(a[s]>1) break;
        if(s%2 == 0){
            s /= 2;
        }
        else{
            s = s*3+1;
        }
        
    }
    cout << cnt  << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>

using namespace std;

const int N = 1e6;
const int SQRTN = ceil(sqrt((double) N));
bool isPrime[N + 1];
int prefixsum[N + 1];

// Eratosthenes筛选法
void esieve(void)
{
    memset(isPrime, true, sizeof(isPrime));

    isPrime[0] = isPrime[1] = false;
    for(int i=2; i<=SQRTN; i++) {
        if(isPrime[i]) {
            for(int j=i*i; j<=N; j+=i)  //筛选
                isPrime[j] = false;
        }
    }
}

void maketable()
{
    prefixsum[0] = 0;
    for(int i = 1; i <= N; i++)
        prefixsum[i] = isPrime[i] ? prefixsum[i - 1] + 1 : prefixsum[i - 1];
}

int main()
{
    esieve();

    maketable();

    int n;
    while(~scanf("%d", &n))
        printf("%d\n", prefixsum[n]);

    return 0;
}



Measured memory_bytes: 8092
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void solve() {
   int n,m;
   cin >> n >>m;
   int l[m],r[m];
   int lmax = - INF,rmin = INF;
   rep(i,0,m){
       cin >> l[i] >> r[i];
       lmax = max(lmax,l[i]);
       rmin= min(rmin,r[i]);
   }

   if(lmax<=rmin){
       cout << rmin-lmax+1 << endl;
   }else{
       cout << 0 << endl;
   }
}
int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }
map<ll, int> pos;
int main() {
    int s;
    cin >> s;
    ll n = s;
    pos[n] = 1;
    for (int i = 2;; ++i) {
        if (n % 2 == 0)
            n /= 2;
        else
            n = 3 * n + 1;
        if (pos.find(n) != pos.end()) {
            cout << i << endl;
            return 0;
        }
        pos[n] = i;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int N;
    cin >> N;
    long long a[N];
    long long sunuke = 0;
    long long arai = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        arai += a[i];
    }
    long long ans = INFINITY;
    for(int i = 0; i < N-1; i++){
        sunuke += a[i];
        arai -= a[i];
        ans = min(abs(sunuke - arai), ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)


//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int c[3][3];

main(){
    rep(i,3)rep(j,3)cin>>c[i][j];
    rep(i,2){
        int p=c[0][i+1]-c[0][i],q=c[1][i+1]-c[1][i],r=c[2][i+1]-c[2][i];
        if(p!=q||q!=r){
            dump("No");
            return 0;
        }
    }
    dump("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n,m; cin>>n>>m;
    if(n==1 && m==1){
        cout<<1<<endl;
    }else if(n==2 && m==2){
        cout<<0<<endl;
    }else if((n==1 && m==2) || (n==2 && m==1)){
        cout<<0<<endl;
    }else if(n<2 || m<2){
        cout<<max(n,m)-2<<endl;
    }else{
        cout<<n*m - 2*(n+m-4) - 4<<endl;
    }
    return 0;
}

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

cnt = [0] * (n + 1)
for i in list(i for i in range(1, n + 1) if i % 2 == 1):
    for j in range(1, n + 1):
        if i % j == 0:
            cnt[i] += 1
            if cnt[i] == 8:
                break

print(cnt.count(8))


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

int main(){
	string s;
	int ans=0;
	cin>>s;
	int len=s.length();
	for(int i=0;i<=len/2-1;i++){
		if(s[i]!=s[len-i-1]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [[] for i in range(N)]
for i in range(N):
	S[i] += list(input())

res=""
for i in range(97,97+26):
	c = chr(i)
	curr = 50 
	for j in range(N):
		curr = min(curr,S[j].count(c))
	res += c*curr

print(res)

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

int main() {
  int n;
  cin>>n;
  ll vec[n],sum[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  sort(vec,vec+n);
  sum[0]=vec[0];
  for(int i=1;i<n;i++){
    sum[i]=sum[i-1]+vec[i];
  }
  for(int i=n-1;i>=0;i--){
    if(sum[i-1]*2<vec[i]){
      cout<<n-i<<endl;
      return 0;
    }
  }
  cout<<n<<endl;
  return 0;
}

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

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int>> bord(H,vector<int>(W));
    vector<tuple<int,int,int,int>> ans;

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

    for(int i=0; i<H; i++){
        for(int j=0; j<W-1;  j++){
            if(bord[i][j] % 2 != 0){
                bord[i][j]--;
                bord[i][j+1]++;
                ans.push_back(make_tuple(i,j,i,j+1));
            }
        }
    }

    int right = W-1; //各行の最後

    for(int i=0; i<H-1; i++){
        if(bord[i][right] % 2 != 0){
            bord[i][right]--;
            bord[i+1][right]++;
            ans.push_back(make_tuple(i,right,i+1,right));
        }
    }

    cout<<ans.size()<<endl;

    for(auto a : ans){
        cout<<get<0>(a)+1<<" "<<get<1>(a)+1<<" "\
        <<get<2>(a)+1<<" "<<get<3>(a)+1<<endl;
    }

    return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;

ll dp[N];

int main()
{
	int n, W;
	cin >> n >> W;
	for (int i = 0; i < n; i++)
	{
		int w, v;
		cin >> w >> v;
		for (int j = W; j >= w; j--)
			dp[j] = max(dp[j], dp[j-w] + v);
	}
	cout << dp[W];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = INF;
    for (int i = 1; i < n; ++i) {
        int x = 0;
        string s = to_string(i), t = to_string(n - i);
        for (auto &&c : s) x += c - '0';
        for (auto &&c : t) x += c - '0';
        ans = min(ans, x);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

ans0 = ans1 = 0
cs = 0
for i, ai in enumerate(a):
    cs += ai

    if i % 2 == 0:
        if cs < 1:
            ans0 += 1 - cs
            cs = 1
    else:
        if cs > -1:
            ans0 += cs + 1
            cs = -1

cs = 0
for i, ai in enumerate(a):
    cs += ai

    if i % 2 == 0:
        if cs > -1:
            ans1 += cs + 1
            cs = -1
    else:
        if cs < 1:
            ans1 += 1 - cs
            cs = 1

ans = min(ans0, ans1)
print(ans)


Measured memory_bytes: 14464
#include<stdio.h>
#define MAX 100000

int A[MAX+1];

int main(){

int n,i,j,x,p,swap,k;

  scanf("%d",&n);

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

  x=A[n];
  i=0;

  for(j=1;j<n;j++){
    if(A[j]<=x){
      i++;
      swap=A[i];
      A[i]=A[j];
      A[j]=swap;
    }
}
      swap=A[i+1];
      A[i+1]=A[n];
      A[n]=swap;

  for(k=1;k<=n;k++){
    if(k==n) printf("%d\n",A[k]);
    else if(k==i+1)printf("[%d] ",A[k]);
    else printf("%d ",A[k]);
  }

  return 0;
}


   

  

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

vector<int> mw={1,-1,0,0};
vector<int> mh={0,0,1,-1};

int main()
{
int w,h,W,H;scanf("%d %d",&w,&h);
vector<vector<int>> board(30,vector<int>(30,0));board[0][0]=1;
vector<vector<int>> hwall(30,vector<int>(29));
vector<vector<int>> vwall(29,vector<int>(30));
queue<pair<int,int>> que;
while(w!=0&&h!=0)
{
que.push(make_pair(0,0));
for(int i=0;i<h;i++)
{
for(int j=0;j<w-1;j++)scanf("%d",&hwall[i][j]);
if(i==h-1)continue;
for(int j=0;j<w;j++)scanf("%d",&vwall[i][j]);
}
while(!que.empty())
{
H=que.front().first;W=que.front().second;que.pop();
if(H==h-1&&W==w-1){while(!que.empty()){que.pop();}break;}
for(int i=0;i<4;i++)
{
if(W+mw[i]<0||W+mw[i]>w-1||H+mh[i]<0||H+mh[i]>h-1)continue;
if(i==0&&hwall[H][W]==1)continue;
else if(i==1&&hwall[H][W-1]==1)continue;
else if(i==2&&vwall[H][W]==1)continue;
else if(i==3&&vwall[H-1][W])continue;
if(board[H+mh[i]][W+mw[i]]!=0)continue;
board[H+mh[i]][W+mw[i]]=board[H][W]+1;
que.push(make_pair(H+mh[i],W+mw[i]));
}
}
printf("%d\n",board[h-1][w-1]);
for(int i=0;i<h;i++)for(int j=0;j<w;j++)board[i][j]=0;
board[0][0]=1;
scanf("%d %d",&w,&h);
}
}


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

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

    vector<int>X(N);
    int sum = 0;
    int P1,P2;
    int ans1 = 0;
    int ans2 = 0;

    for (int i=0; i<N; i++){
        cin >> X.at(i);
    }

    for (int i=0; i<N; i++){
        sum += X.at(i);
    }

    P1 = sum / N;
    P2 = P1 + 1;

    for (int i=0; i<N; i++){
        ans1 += (X.at(i)-P1)*(X.at(i)-P1);
        ans2 += (X.at(i)-P2)*(X.at(i)-P2);
    }

    if (ans1 <= ans2){
        cout << ans1 << endl;
    }
    else
    {
        cout << ans2 << endl;
    }
    
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int dif_x = tx - sx;
	int dif_y = ty - sy;

	string ans;
	for (int i = 0; i < dif_x; i++) {
		ans += 'R';
	}
	for (int i = 0; i < dif_y; i++) {
		ans += 'U';
	}

	for (int i = 0; i < dif_x; i++) {
		ans += 'L';
	}
	for (int i = 0; i < dif_y; i++) {
		ans += 'D';
	}

	ans += 'D';

	for (int i = 0; i <=dif_x; i++) {
		ans += 'R';
	}
	for (int i = 0; i <=dif_y; i++) {
		ans += 'U';
	}
	ans += 'L';
	ans += 'U';
	

	for (int i = 0; i <=dif_x; i++) {
		ans += 'L';
	}
	for (int i = 0; i <=dif_y; i++) {
		ans += 'D';
	}
	ans += 'R';

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include<math.h>

int main(){

char S[11];
int S_num[10];
int X,min=1000;
scanf("%s",S);
for (int i = 0; i < strlen(S); i++)
{
    S_num[i] = (int)S[i]-48;
}

for (int i = 0; i < strlen(S)-2; i++)
{
    int diff = 0;
    X = S_num[i]*100+S_num[i+1]*10+S_num[i+2];
    diff = abs(X-753);
    if(min>diff){min = diff;}
}

printf("%d",min);
return 0;
}

Measured memory_bytes: 1724
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;


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;}

const ll INF=1e9+7;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll st=a[0];
    bool up=false,dw=false,neu=true;
    ll ans=1;
    rep(i,n){
        if(i==0) continue;
        if(neu){
            if(a[i]>a[i-1]){
                neu=false;
                up=true;
            }
            else if(a[i]<a[i-1]){
                neu=false;
                dw=true;
            }
        }
        else if(dw){
            if(a[i]>a[i-1]){
                dw=false;
                neu=true;
                ans++;
            }
        }
        else if(up){
            if(a[i]<a[i-1]){
                up=false;
                neu=true;
                ans++;
            }
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3988
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::{HashSet, VecDeque};

fn main() {
    input!{
        n: usize,
        v: [[usize1; 2]; n - 1]
    }
    if n == 1 {
        println!("2");
        return;
    }
    let d = 1000000007;
    let mut nodes: Vec<HashSet<usize>> = vec![HashSet::new(); n];
    for i in 0..n - 1 {
        nodes[v[i][0]].insert(v[i][1]);
        nodes[v[i][1]].insert(v[i][0]);
    }
    let mut tab: Vec<Vec<usize>> = vec![vec![1, 1]; n];
    let mut ch: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut ts: Vec<usize> = Vec::new();
    let mut s: VecDeque<usize> = VecDeque::new();
    for i in 0..n {
        if nodes[i].len() == 1 {
            s.push_back(i);
        }
    }

    loop {
        let x = s.pop_front().unwrap();
        ts.push(x);
        if nodes[x].len() == 0 {
            break;
        }
        let y = *nodes[x].iter().nth(0).unwrap();
        nodes[y].remove(&x);
        ch[y].push(x);
        if nodes[y].len() == 1 {
            s.push_back(y);
        }
    }
    for i in ts.iter().clone().map(|x| *x) {
        for j in ch[i].iter().clone().map(|x| *x) {
            tab[i][0] = tab[i][0] * (tab[j][0] + tab[j][1]) % d;
            tab[i][1] = tab[i][1] * tab[j][0] % d;
        }
    }
    let l = *ts.last().unwrap();
    println!("{}", (tab[l][0] + tab[l][1]) % d);
}


Measured memory_bytes: 82172
import math
#import statistics
n=int(input())
a=list(map(int,input().split()))
mean=sum(a)/n
mean_one=math.ceil(mean)
mean_two=math.floor(mean)
#med=statistics.median(a)
#med=math.floor(med)
ans_one=0
for i in a:
    ans_one+=(i-mean_one)**2
ans_two=0
for i in a:
    ans_two+=(i-mean_two)**2
ans=min(ans_one,ans_two)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int N,Q;
	scanf("%d %d",&N,&Q);

	ll* table = new ll[N];

	for(int i = 0; i < N; i++)scanf("%lld",&table[i]);

	int left = 0,right = 0;

	ll S,ans,tmp_sum;

	for(int loop = 0; loop < Q; loop++){
		scanf("%lld",&S);

		ans = 0,tmp_sum = 0;
		left = 0,right = 0;

		while(true){
			while(true){
				tmp_sum += table[right];
				if(tmp_sum > S){
					break;
				}
				ans += (right-left+1);

				if(right == N-1){
					break;
				}
				right++;
			}

			if(tmp_sum <= S){
				break;
			}

			while(true){
				tmp_sum -= table[left];
				left++;
				if(tmp_sum <= S){
					ans += (right-left+1);
					break;
				}
			}
			if(right == N-1){
				break;
			}else{
				right += 1;
			}
		}

		printf("%lld\n",ans);
	}

	return 0;
}

Measured memory_bytes: 3988
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println( a / k != b / k ? "OK" : a % k == 0 ? "OK" : "NG");
	}
}

Measured memory_bytes: 35368
pub fn read_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let mut black = 0u64;
    let mut ans = 0u64;
    for c in read_str().chars() {
        if c == 'B' {
            black += 1;
        } else {
            ans += black;
        }
    }
    println!("{:?}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n;
set <int> st;

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    st.insert(x);
  }

  if (sz(st) == n) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 9600