akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll X,Y;
    cin >> X >>Y;
    if(X > 0 && Y > 0){
        if(X < Y)cout << Y - X << endl;
        else cout << X - Y + 2 << endl;
    }
    else if(X < 0 && Y < 0){
        if(X < Y)cout << Y - X << endl;
        else cout << X - Y + 2 << endl;
    }
    else if(X > 0 && Y < 0){
        if(abs(X) > abs(Y))cout << abs(X) - abs(Y) + 1 << endl;
        else if(abs(Y) > abs(X))cout << abs(Y) - abs(X) + 1 << endl;
        else{
            cout << 1 << endl;
        }
    }
    else if(X < 0 && Y > 0){
        if(abs(X) > abs(Y))cout << abs(X) - abs(Y) + 1 << endl;
        else if(abs(Y) > abs(X))cout << abs(Y) - abs(X) + 1 << endl;
        else cout << 1 << endl;
    }
    else if(X == 0 && Y < 0)cout << abs(Y) + 1 << endl;
    else if(X == 0 && Y > 0)cout << Y << endl;
    else if(Y == 0 && X < 0)cout << abs(X) << endl;
    else if(Y == 0 && X > 0)cout << X + 1 << endl;
    else{
        if(abs(X) > abs(Y))cout << abs(X) - abs(Y) + 1 << endl;
        else if(abs(X) > abs(Y))cout << abs(X) - abs(Y) + 1 << endl;
        else cout << 1 << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
S = input()

s = []
p = []
P = []

alf = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

s = list(S)

for i in s:
    o = alf.index(i)
    o += N
    if o > 25:
        o = o - 25
        o -= 1
        p.append(str(alf[o]))
        P = ','.join(p)
        P = P.replace(',',"")
    else:
        p.append(str(alf[o]))
        P = ','.join(p)
        P = P.replace(',',"")

print(P)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a <= b){
    cout << a << "\n";
    return 0;
  }
  cout << a - 1 << "\n";
}
    
  

Measured memory_bytes: 3616
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<list>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

#define ll __int64
#define P pair<ll,ll>
//#define __int64 long long

int h,w;
string t[1000];
bool s[1000][1000];
int main(){	
	cin>>h>>w;
	rep(i,h)cin>>t[i];
	bool ok=1;

	rep(i,h){
		rep(j,w-1){
			if(t[i][j]=='#'&&t[i][j+1]=='#')s[i][j]=s[i][j+1]=1;
		}
	}		

	rep(i,h-1){
		rep(j,w){
			if(t[i][j]=='#'&&t[i+1][j]=='#')s[i][j]=s[i+1][j]=1;
		}
	}		

	rep(i,h){
		rep(j,w)if(t[i][j]=='#'&&!s[i][j])ok=0;
	}
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); (i)++)
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

struct Edge {
   int to, cost;
};

const ll INF = 1e18;
int N, M;
vec<vec<Edge>> G;

void dfs(int pos, vec<ll> &dist) {
   for (Edge e : G[pos]) {
      if (dist[e.to] == INF) {
         dist[e.to] = dist[pos] + e.cost;
         dfs(e.to, dist);
      }
   }
}

int main() {
   cin >> N >> M;
   G = vec<vec<Edge>>(N);
   rep (i, 0, M) {
      int l, r, d;
      cin >> l >> r >> d;
      l--, r--;
      G[l].push_back(Edge{r, d});
      G[r].push_back(Edge{l, -d});
   }

   vec<ll> dist(N, INF);
   rep (i, 0, N) {
      if (dist[i] == INF) {
         dist[i] = 0;
         dfs(i, dist);
      }
   }

   rep (i, 0, N) {
      for (Edge e : G[i]) {
         if (dist[e.to] - dist[i] != e.cost) {
            puts("No");
            return 0;
         }
      }
   }
   puts("Yes");

   return 0;
}

Measured memory_bytes: 12416
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL M, K;
	in >> M >> K;

	if (K >= (1LL << M) || (M == 1 && K > 0))
	{
		out << -1 << std::endl;
		return 0;
	}

	std::vector<LL>a;
	for (LL i = (1LL << M) - 1; i >= 0; --i)
	{
		if (i != K) a.push_back(i);
	}
	a.push_back(K);
	if (K == 0) a.push_back(K);
	for (LL i = 0; i <= (1LL << M) - 1; ++i)
	{
		if (i != K) a.push_back(i);
	}
	if (K > 0) a.push_back(K);

	rep(i, a.size()) out << a[i] << (i + 1 < a.size() ? " " : "\n");
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  LL a, b, c, k;
  cin >> a >> b >> c >> k;
  LL sum = min(a, k);
  k = max(0LL, k - a);
  if (k > 0) {
    k = max(0LL, k - b);
  }
  if (k > 0) {
    sum -= k;
  }

  cout << sum << "\n";

  return 0;
}

Measured memory_bytes: 3652
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007  ;
#define endl '\n'
#define pb push_back
#define mp make_pair

//Check for signed int overflow
// use __builtin_popcount(num) to calculate no.of setbits in num
//s.lower_bound() works in O(logn) whereas lower_bound(s.begin(),s.end(),x) works in O(n)
//      if(!lazy)
//         solve 1600+(rating) problems in codeforces.
//      else
//         solve 1400+(rating) problems in codeforces.

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n){
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p)%MOD;
    if (n % 2)
        return (p * a)%MOD;
    else
        return p%MOD;
}

/*vector<bool>is_prime(1000001,true);
void sieve(){
    is_prime[0]=is_prime[1]=false;
    is_prime[2]=true;
    for(int i=2;i*i<=1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                is_prime[j]=false;
            }
        }
    }
}*/


int32_t main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(nullptr);
    ll test=1;
    /*cin>>test;*/
    while(test--) {
        ll n;
        cin>>n;
        vector<ll>v(n);
        for(ll i=0;i<n;i++){
            cin>>v[i];
        }
        sort(v.rbegin(),v.rend());
        ll req=n-1;
        ll ans=v[0];
        req--;
        for(ll i=1;i<n;i++){
            if(req>=2){
                ans+=2*v[i];
                req-=2;
            }
            else if(req==1){
                ans+=v[i];
                req--;
            }
            else{
                break;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 4764
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

int main()
{
	fastIOS();

	int a, b, c;
	cin >> a >> b >> c;

	int kid0 = max(max(a, b), c);
	int kid1 = (a + b + c) - kid0;
	if (kid0 == kid1)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int s_size = s.size();
  string s_out = "";
  for(int i=0;i<s_size/2+s_size%2;i++){
    s_out += s[i*2];
  }
  cout << s_out << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
  int n, q, temp, i, j;
  int a[2001] = {1};
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &temp);
    for(j=2000-temp;j>=0;j--){
      if(a[j]) a[j + temp] = 1;
    }
  }
 
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &temp);
    if(a[temp]) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
        



Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 2 * 2018;

int n, i, j;
char c[maxN];
int v[maxN];
int wh[2][maxN];

int data[maxN];
int dp[maxN][maxN];

int zrs(int x) {
    return (x ^ (x - 1)) & x;
}

void add(int pos, int val) {
    while (pos <= 2 * n) {
        data[pos] += val;
        pos += zrs(pos);
    }
}

int sum(int pos) {
    int ans = 0;
    while (pos > 0) {
        ans += data[pos];
        pos -= zrs(pos);
    }
    return ans;
}

int main()
{
  //  freopen("test.in","r",stdin);
    
    scanf("%d\n", &n);
    for (i = 1; i <= 2 * n; i++) {
        scanf("%c %d\n", &c[i], &v[i]);

        if (c[i] == 'W') {
            wh[0][v[i]] = i;
        } else {
            wh[1][v[i]] = i;
        }
    }
    
    for (i = 0; i <= n; i++)
        for (j = 0; j <= n; j++)
            dp[i][j] = 10 * n * n;
    dp[0][0] = 0;

    for (i = 0; i <= n; i++) {
        if (i > 0) add(wh[0][i], +1);
        for (j = 0; j <= n; j++) {
            
            if (j > 0)
                add(wh[1][j], +1);

            if (i < n)
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + wh[0][i + 1] - 1 -
                sum(wh[0][i + 1]));

            if (j < n)
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + wh[1][j + 1] - 1 -
                sum(wh[1][j + 1]));
        }

        for (j = 1; j <= n; j++) 
            add(wh[1][j], -1);
    }

    /*for (i = 0; i <= n; i++, cerr << '\n') {
        for (j = 0; j <= n; j++)
            cerr << dp[i][j] << ' ';
    }*/

    printf("%d", dp[n][n]);

    return 0;
}


Measured memory_bytes: 32640
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int N;
	ll T;
	cin >> N >> T;
	vector<ll> t(N);
	ll ans = 0;
	rep(i,N) {
		cin >> t[i];
		if(i==0) continue;
		ans += min(T, t[i]-t[i-1]);
	}
	ans += T;
	cout << ans << endl;


  return 0;
}


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

/// Returns true if x is even, false otherwise.
bool get_is_even(int x) {
    return x % 2 == 0;
}

/// Returns true if all the elements are true, false otherwise.
bool get_is_all(vector<bool> bools) {
    for (bool b: bools) {
        if (!b) {
            return false;
        }
    }

    return true;
}

/// Returns true if all the elements are even, false otherwise.
bool get_is_all_even(vector<int> ints) {
    vector<bool> bools;
    transform(ints.begin(), ints.end(), back_inserter(bools), get_is_even);
    return get_is_all(bools);
}

int get_divided(int x) {
    return x / 2;
}

int N, A;
vector<vector<int>> ass;

int main() {
    cin >> N;
    vector<int> as;

    for (int i = 1; i <= N; ++i) {
        cin >> A;
        as.push_back(A);
    }

    ass.push_back(as);

    while (get_is_all_even(as)) {
        vector<int> next;
        transform(as.begin(), as.end(), back_inserter(next), get_divided);
        as = next;
        ass.push_back(as);
    }

    cout << ass.size() - 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

    void yes(bool fl = true){
            if(fl) cout << "YES\n";
            else cout << "Yes\n";
    }
    void no(bool fl = true){
        if(fl) cout << "NO\n";
        else cout << "No\n";
    }  

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;
        

        
        




        


        void solve(){
            cin >> x;

            
            for(int i=-200;i<=200;i++){
                for(int j=-200;j<=200;j++){
                    if(pow(i,5) - pow(j,5) == x){
                        cout << i << " " << j;
                        return;
                    }
                }
            }
    
           
        }
    
   

        int main(){
        ios_base::sync_with_stdio(false);
        
        int cases = 1;
        //cin >> cases;

        while(cases--){ 
            solve();
        }

        return 0;

        }

Measured memory_bytes: 4080
lst=[input()for i in range(5)]
lst.sort(key=lambda x:str(int(x[-1])+9)[-1])
ans=0
for i in lst[1:]:
    if int(i[-1])!=0:
        if len(i)!=1:
            tmp=str(int(i[:-1])+1)+"0"
            ans+=int(tmp)
        elif len(i)==1:
            ans+=10
    elif int(i[-1])==0:
        ans+=int(i)

print(ans+int(lst[0]))

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vl count(n);
  rep(i,n-1){
    ll a;cin>>a;
    count[a-1]++;
  }
  rep(i,n)cout<<count[i]<<endl;
}
    

Measured memory_bytes: 4772
// test
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<long> A(n);
	vector<long> B(n);
	long long sumA, sumB;
	sumA = sumB = 0;
	for (int i = 0; i < n; i++) {
		cin >> A.at(i);
		sumA += A.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> B.at(i);
		sumB += B.at(i);
	}
	long move = sumB - sumA;
	long sum = 0;
	for (int i = 0; i < n; i++) {
		if (A.at(i) < B.at(i)) {
			sum += (B.at(i) - A.at(i) + 1) / 2;
		}
	}
	if (move >= sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}




Measured memory_bytes: 384
import math

L = int(input())

N = math.floor(math.log2(L)) + 1

edge = []
for i in range(N - 1):
  edge.append((i + 1, i + 2, 0))
  edge.append((i + 1, i + 2, (1 << i)))

for i in range(N - 1, 0, -1):
  if L - (1 << (i - 1)) >= 2 ** (N - 1):
    edge.append((i, N, L - (1 << (i - 1))))
    L -= (1 << (i - 1))

print(N, len(edge))
for e in edge:
  print(str(e).lstrip('(').rstrip(')').replace(',', ''))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

int main()
{
    int h,w;
    cin>>h>>w;
    char x;
    vector<vector<int > > grid(h,vector<int> (w,0));
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
        {
            cin>>x;
            if(x=='#')
                grid[i][j]=-1;
        }
    for(int i=0;i<h;i++){
        if(grid[i][0]!=-1)
            grid[i][0]=1;
        else
            break;
    }
    for(int j=0;j<w;j++)
    {
        if(grid[0][j]!=-1)
            grid[0][j]=1;
        else
            break;
    }
    grid[0][0]=1;
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(grid[i][j]!=-1)
            {
                if(grid[i-1][j]!=-1 and grid[i][j-1]!=-1){
                    grid[i][j]=(grid[i-1][j]%mod + grid[i][j-1]%mod)%mod;
                }
                else if(grid[i-1][j]!=-1 and grid[i][j-1]==-1)
                    grid[i][j]=grid[i-1][j];
                else   
                    grid[i][j]=grid[i][j-1];
            }
        }
    }
    if(grid[h-1][w-1]!=-1)

    cout<<grid[h-1][w-1]<<endl;
    else
    cout<<0<<endl;
            

}

Measured memory_bytes: 7512
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n,d=MI()
	X=[LI() for _ in range(n)]
	#print(X)
	ans=0

	for i in range(n-1):
		for j in range(i+1,n):
			k=0
			for x,y in zip(X[i],X[j]):
				k+=(x-y)**2
			#print(k)
			if k**0.5==int(k**0.5):
				ans+=1

	print(ans)








if __name__ == "__main__":
	main()


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

int main()
{
    int n;
    long long c=0;
    cin>>n;
    vector<int> v(n);
    
    for(int i=0;i<n-1;i++)
        cin>>v[i];
    c+=v[0];
    for(int i=0;i<n-2;i++)
    {
        if(v[i]>=v[i+1])
            c+=v[i+1];
        else
            c+=v[i];

    }
    cout<<c+v[n-2]<<endl;

}

Measured memory_bytes: 256
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)
a = (A ^ K).sum()

bit_cnt = [((A >> i) & 1).sum() for i in range(40)]
bit_cnt = [0 if i > N - i else 1 for i in bit_cnt]

K = format(K, 'b')
k = len(K)
X = []
if sum([2 ** i for i in range(k) if bit_cnt[i] == 1]) > int(K, 2):
    for i in range(k - 1, -1, -1):
        if int(K[-i - 1]) < bit_cnt[i]:
            bit_cnt[i] = 0
            X.append(sum([2 ** i for i in range(k) if bit_cnt[i] == 1]))
    X = [i for i in X if i <= int(K, 2)]
else:
    X.append(sum([2 ** i for i in range(k) if bit_cnt[i] == 1]))

answer = 0
for i in X:
    answer = max(answer, (i ^ A).sum())
print(answer)

Measured memory_bytes: 28176
//#include <climits>
#include <vector>
#include <iostream>
//#include <sstream>
// #include <string>
using namespace std;


bool binarySearch(vector<int> &S, int target) {

    int left  = 0;
    int right = (int)S.size();

    while(left < right) {
        int mid = (left + right) / 2;

        if(target == S[mid]) {
            return true;
        }

        if(target < S[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }

    return false;
}


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

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

    int q;
    cin >> q;

    vector<int> T(q);
    for (int i = 0; i < q; ++i)
    {
        cin >> T[i];
    }



    int ans = 0;
    for (int i = 0; i < q; ++i)
    {
        int target = T[i];
        if(binarySearch(S, target)) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3288
N,K=map(int,input().split())
if K==1 :
    print(N**3)
elif K==2:
    print(int(N/2)**3+int(N/2+0.5)**3)
elif K%2==1:
    a=int(N/K)
    print(a**3)
else:
    a=int(N/(K/2))
    print(int(a/2)**3+int(a/2+0.5)**3)

Measured memory_bytes: 3060
#include<cstdio>

int n,q;
int par[10000];
int rank[10000];

void init(){
  for(int i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x]==x) return x;
  else return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x==y) return;
  if(rank[x]<rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x]==rank[y]) rank[x]++;
  }
}

void same(int x,int y){
  if(find(x)==find(y)) printf("1\n");
  else printf("0\n");
}

int main(){
  scanf("%d %d",&n,&q);
  init();
  for(int i=0;i<q;i++){
    int cmd,x,y;
    scanf("%d %d %d",&cmd,&x,&y);
    if(cmd==0) unite(x,y);
    if(cmd==1) same(x,y);
  }
  return 0;
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int N,A,B,C;
    int ans=0;
    cin>>N;
    int S[N],D[N];
    vector <double> V(N); 
    rep(i,N){
        cin>>V[i];
    }
    sort(ALL(V));
    rep1(i,N-1){
        V[0]=(V[0]+V[i])/2.0;
    }

    Out(V[0]);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int G[101][101],n,m=1,stump[101][2];
int DFS(int);
int main(void)
{
    int k,v,u,i,j;
    scanf("%d", &n);
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++) G[i][j]=0;
        stump[i][0]=0;
        stump[i][1]=0;
    }
    for(i=0;i<n;i++){
        scanf("%d", &u);
        scanf("%d", &k);
        for(j=0;j<k;j++){
            scanf("%d", &v);
            G[u][v] = 1;
        }
    }
    DFS(1);
    for(i=1;i<=n;i++){
        if(stump[i][0]==0) DFS(i);
    }
    for(i=1;i<=n;i++) printf("%d %d %d\n", i, stump[i][0], stump[i][1]);
    return 0;
}
int DFS(int num)
{
    int l;
    if(stump[num][0]==0){
        stump[num][0]=m;
        m++;
    }
    for(l=0;l<=n;l++){
        if(G[num][l]==1&&stump[l][0]==0) DFS(l);
    }
    if(stump[num][1]==0){
        stump[num][1]=m;
        m++;
    }
    return 0;
}


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

int main(void){
	char str[1200];
	int len, i;
	
	gets(str);
	
	len = strlen(str);
	
	for(i=0; i<len; i++){
		if(0x41 <= str[i] && str[i] <= 0x5a){
			str[i] += 0x20;
		}else if(0x61 <= str[i] && str[i] <= 0x7a){
			str[i] -= 0x20;
		}
		printf("%c", str[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 524
#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

typedef long long int lli;

typedef pair<lli, lli> pii;
typedef vector<lli> vi;
typedef set<lli> si;
typedef unordered_map<lli, lli> umii;
typedef unordered_set<lli> usi;

lli mod = 1000000007;

void dispvec(si arr)
{
    si::iterator itr = arr.begin();
    while (itr != arr.end())
    {
        cout << *itr << " ";
        itr++;
    }
    cout << endl;
}

struct CustomCompare
{
    //stable sort by first then second both in increasing
    bool operator()(const pii &i, const pii &j)
    {
        if (i.first == j.first)
            return i.first < j.first;
        return i.second < j.second;
    }
};

lli max(lli a, lli b)
{
    return a > b ? a : b;
}

void solve()
{
    int n;
    cin >> n;
    vi ans(3, 0);
    for (int p = 0; p < n; p++)
    {
        vi dp(3, 0);
        vi c(3, 0);
        for (int i = 0; i < 3; i++)
            cin >> c[i];
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (i != j)
                {
                    dp[i] = max(dp[i], ans[j] + c[i]);
                }
            }
        }
        ans = dp;
    }
    cout << max(ans[0], max(ans[1], ans[2])) << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("/home/mufaddal/Mufaddal/Programs/Competitive/input", "r", stdin);
    freopen("/home/mufaddal/Mufaddal/Programs/Competitive/output", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    int i = 1;
    while (i <= t)
    {
        solve();
        i++;
    }

    return 0;
}

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

using namespace std;

struct triple
{
	int a, b, c;
};

int main()
{
	ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
  
	int n; cin >> n;
	vector<triple> h(n), dp(n);
	for (int i = 0; i < n; ++i) {
		cin >> h[i].a >> h[i].b >> h[i].c;
	}
	dp[0] = h[0];
	for (int i = 1; i < n; ++i) {
		dp[i].a = h[i].a + max(dp[i - 1].b, dp[i - 1].c);
		dp[i].b = h[i].b + max(dp[i - 1].a, dp[i - 1].c);
		dp[i].c = h[i].c + max(dp[i - 1].a, dp[i - 1].b);
	}
	cout << max({dp[n - 1].a, dp[n - 1].b, dp[n - 1].c}) << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
using namespace std;
typedef long long ll;

int gcd(int a, int b){
	while(b){
		int c=a%b;
		a=b;b=c;
	}
	return a;
}

int main(){
	int n,k;
	int mx=-1,g=0;
	scanf("%d%d",&n,&k);
	fore(i,0,n){
		int x;
		scanf("%d",&x);
		mx=max(mx,x);
		g=gcd(g,x);
	}
	puts(k%g==0&&k<=mx?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long long unsigned llu;
typedef pair<ll, ll> P;//change when necessary
typedef long double ld;
#define mp make_pair
#define N ll(1e5 + 5)//change it
#define M ll(0)
const ll OO = 1e18;
const ll md = 1e9 + 7;
ll X[] = { 0,0,1,-1 }, Y[] = { 1,-1,0,0 };
void fast()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
ll dp[N][2], kb[N][2], n, c, res, f[N][2];
P p[N];
int main()
{
	scanf("%lld%lld", &n, &c);
	for (int i = 0; i < n; i++)
		scanf("%lld%lld", &p[i].first, &p[i].second);// x, v
	for (int i = 0; i < n; i++)
	{
		if (i > 0)
			dp[i][0] += dp[i - 1][0];
		dp[i][0] += p[i].second;
		kb[i][0] = p[i].first;
	}
	for (int i = n - 1; i >= 0; i--)
	{
		dp[i][1] += dp[i + 1][1];
		dp[i][1] += p[i].second;
		kb[i][1] = c - p[i].first;
	}
	for (int j = 0; j < 2; j++)
		for (int i = 0; i < n; i++)
			f[i][j] = dp[i][j] - kb[i][j]*2;

	for (int i = 0; i < n; i++)
		if (i > 0)
			f[i][0] = max(f[i][0], f[i - 1][0]);

	for (int i = n - 1; i >= 0; i--)
		f[i][1] = max(f[i + 1][1], f[i][1]);

	for (int i = 0; i < n; i++)
	{
		dp[i][0] = max(dp[i][0], dp[i][0] + f[i + 1][1]);
		res = max(res, dp[i][0] - kb[i][0]);
	}
	for (int i = 0; i < n; i++)
	{
		if(i > 0)
			dp[i][1] = max(dp[i][1], dp[i][1] + f[i - 1][0]);
		res = max(res, dp[i][1] - kb[i][1]);
	}
	printf("%lld\n", res);
	return 0;
}

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

int64_t count(int64_t A, int64_t B, int64_t div) {
	return B / div - (A - 1) / div;
}

int gcd(int C, int D) {
	if (C > D) {
		return gcd(D, C);
	}
	else if (D % C == 0) {
		return C;
	}
	else {
		return gcd(D % C, C);
	}
}

int main() {
	int64_t A, B;
	int C, D;
	cin >> A >> B >> C >> D;
	cout << B - A + 1 - count(A, B, C) - count(A, B, D) + count(A, B, (int64_t)C / gcd(C, D) * D) << endl;
	return 0;
}

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

using namespace std;

int main() {
  int N, T, A;
  cin >> N >> T >> A;

  int answer = 1;
  int diff = 1 << 30;
  for (int i = 1; i <= N; i++) {
    int H;
    cin >> H;

    int diffH = abs(A * 1000 - (T * 1000 - H * 6));

    if (diffH < diff) {
      answer = i;
      diff = diffH;
    }
  }

  cout << answer << endl;
}


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

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] subordinate = new int[N];
        Arrays.fill(subordinate,0);
        for(int i = 1; i < N; i++){
            subordinate[in.nextInt()-1] += 1;
        }
        for(int i = 0; i < N; i++){
            System.out.println(subordinate[i]);
        }
    }

}


Measured memory_bytes: 69756
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x;std::cin >> x;
  ll y = (x/500)*1000;
  x %= 500;
  ll z = (x/5)*5;
  std::cout << y + z << '\n';
  return 0;
}


Measured memory_bytes: 888
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int MAXN=110;
char a[MAXN][MAXN];
bool b[MAXN],c[MAXN];
int m,n,l,p,k,ans,tot;
bool flg;
int inline read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
	n=read();
	m=read();
	for (int i=1;i<=n;i++)
	{
		scanf("%s",a[i]+1);
	}
	
	if (n==1)
	{
		bool flg=true;
		if (a[1][1]!='.') 
		{
			for (int i=2;i<=m;i++)
			{
				if (a[1][i]!=a[1][1])
				{
					flg=false;
					continue;	
				}	
			}	
			if (flg) 
			{
				printf("%s",a[1]+1);
				return 0;
			}
		}
	} 
	
	
	
	if (m==1)
	{
		bool flg=true;
		if (a[1][1]!='.')
		{
			for (int i=2;i<=n;i++)
			{
				if (a[i][1]!=a[1][1])
				{
					flg=false;
					continue;	
				}	
			}	
			if (flg) 
			{
				for (int i=1;i<=n;i++) printf("%c\n",a[i][1]);
				return 0;
			}
		}
	} 
	
	for (int i=1;i<=n;i++)
	{
		b[i]=1;
		if (a[i][1]!='.')
		{
			b[i]=0;
			continue;
		}
		for (int j=2;j<=m;j++)
		{
			if (a[i][j]!=a[i][1])
			{
				b[i]=0;
				break;
			}
		}
	}
	
	for (int i=1;i<=m;i++)
	{
		c[i]=1;
		
		if (a[1][i]!='.')
		{
			c[i]=0;
			continue;
		}
		
		for (int j=2;j<=n;j++)
		{
			if (a[j][i]!=a[1][i])
			{
				c[i]=0;
				break;
			}
		}
	}
	/*
	flg=true;
	for (int i=1;i<=n;i++)
	{
		if (!b[i])
		{
			flg=false;
			break;
		}
	}
	if (flg)
	{
		printf("%s",a[1]+1);
		return 0;
	}
	
	
	flg=true;
	for (int i=1;i<=m;i++)
	{
		if (!c[i])
		{
			flg=false;
			break;
		}
	}
	if (flg)
	{
		for (int i=1;i<=n;i++) printf("%c\n",a[i][1]);
			return 0;
	}
	*/
	
	for (int i=1;i<=n;i++)
	{
		if (b[i]) continue;
		for (int j=1;j<=m;j++)
		{
			if (c[j])
			{
				continue;
			}
			printf("%c",a[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}



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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string a,b,c;cin>>a>>b>>c;
    if (a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
        cout<<"YES"<<endl;
    }else cout<<"NO"<<endl;
    return 0;
}

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

int main() {
  int n;
  int total = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    total += b.at(a.at(i) - 1);
    if (a.at(i) + 1 == a.at(i + 1)) {
      total += c.at(a.at(i) - 1);
    }
  }
  total += b.at(a.at(n - 1) - 1);
  cout << total << endl;
}

Measured memory_bytes: 256
N = int(input())
C = [[0 for i in range(10)] for i in range(10)]

for i in range(N):
    si = str(i+1)
    f,l = int(si[0]),int(si[len(si)-1])
    C[f][l] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += C[i][j] * C[j][i]
    
print(ans)




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


const int MAXN = 100005;
int a[MAXN];
int r[MAXN];

int main()
{
    //freopen("input.txt", "r", stdin);
    int w, h, n;
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int l = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            int k = (i % 2) ? j : (w - j - 1);
            while (a[l] == 0) l++;
            r[k] = l + 1;
            a[l]--;
        }
        for (int j = 0; j < w; j++)
            cout << r[j] << " ";
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,x,sum,ten[13],sum1,pen[13],ans,fi,en,p;
int main()
{
	scanf("%d",&n);
	x=n,sum1=0;
	while(x!=0)
		x/=10,sum1++;	
	ten[0]=1;
	for(int i=1;i<=8;i++)
		ten[i]=ten[i-1]*10;
	for(int i=3;i<=8;i++)
		pen[i]=pen[i-1]+9*ten[i-2];
	for(int i=1;i<=n;i++)
		if(i%10!=0)
		{
			x=i,sum=0;
			while(x!=0)
				x/=10,sum++;
			for(int j=1;j<=sum1;j++)
			{
				if(j==1)
				{
					if(i/ten[sum-1]==i%10)
						ans++;				
				}
				else
				{
					fi=i/ten[sum-1],en=i%10,p=en*ten[j-1]+fi;
					if(p+pen[j]>n)
					{
						if(p<=n)
						{
							ans+=n%ten[sum1-1]/10;
							if(n%10>=fi)
								ans++;
						}
					}
					else if(p<=n)
						ans+=ten[j-2];
				}
			}
		}
	cout<<ans;
	return 0;  
}


Measured memory_bytes: 256
H, W = map(int, input().split())
maze = [input() for i in range(H)]

direction = [
    (0, 1),
    (1, 0),
    (-1, 0),
    (0, -1)
]


def bfs(sy, sx):
    reached = [[-1] * W for _ in range(H)]
    reached[sy][sx] = 0
    from collections import deque
    que = deque([[sy, sx]])
    #d_max = 0
    while que:
        iy, ix = que.popleft()
        for d in direction:
            tx, ty = ix + d[0], iy + d[1]
            if tx >= W or ty >= H or tx < 0 or ty < 0:
                continue
            if reached[ty][tx] != -1 or maze[ty][tx] == '#':
                continue
            reached[ty][tx] = reached[iy][ix] + 1
            #d_max = max(reached[ty][tx], d_max)
            que.append([ty, tx])
    d_max = 0
    for i in range(H):
        for j in range(W):
            d_max = max(d_max,reached[i][j])

    return d_max


ans = 0

for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            ans = max(ans, bfs(i, j))

# for i in range(H):
#     for j in range(i, W):
#         for k in range(H):
#             for l in range(k, W):
#                 if maze[i][j] == '#' or maze[k][l] == '#':
#                     continue
#                 else:
#                     ans = max(ans, bfs(i, j, k, l))
print(ans)


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

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n,a,b;
    string s;
    cin>>n>>a>>b>>s;
    int qualCount = 0, overCount = b;
    for(char c:s) {
    	switch(c) {
    		case 'c': {
    			cout<<"No"<<endl;
    			break;
    		}
    		case 'a': {
    			if(qualCount < (a+b)) {
    				cout<<"Yes"<<endl;
    				qualCount++;
    			}
    			else {
    				cout<<"No"<<endl;
    			}
    			break;
    		}
    		case 'b': {
    			if(qualCount < (a+b) && overCount > 0) {
    				cout<<"Yes"<<endl;
    				qualCount++;
    				overCount--;
    			}
    			else {
    				cout<<"No"<<endl;
    			}
    			break;
    		}
    	}
    }

	return 0;		
}


Measured memory_bytes: 848
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
A.append(1)
count = 0
Tmax = 1
Amax = 1
T2 = [0] * N
A2 = [0] * N
ans = 1

for i in range(N):
    if T[i] > Tmax:
        Tmax = T[i]
        if A[i] > A[i+1]:
            Amax = A[i+1]
            if T[i] == A[i]:
                count = 1
            else:
                ans = 0
                break
        else:
            if T[i] > A[i]:
                ans = 0
                break
            else:
                count = 1
    else:
        if A[i] > A[i+1]:
            Amax = A[i+1]
            if A[i] > T[i]:
                ans = 0
                break
            else:
                count = 1
        else:
            count = min(A[i],T[i])
    ans *= count
    ans = ans % (10**9+7)
print(ans)

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

namespace ABC142D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] AB = Console.ReadLine().Split(' ');
            long A = long.Parse(AB[0]);
            long B = long.Parse(AB[1]);
            long[] Ayaku = new long[1000001];
            long[] Byaku = new long[1000001];
            Ayaku[1] += 1;
            Byaku[1] += 1;
            long a = 2;
            long Atemp = A;
            while (a * a <= A)
            {
                while (Atemp % a == 0)
                {
                    Ayaku[a] += 1;
                    Atemp /= a;
                    //Console.WriteLine(a);
                }
                a += 1;
            }
            long b = 2;
            long Btemp = B;
            while (b * b <= B)
            {
                while (Btemp % b == 0)
                {
                    Byaku[b] += 1;
                    Btemp /= b;
                    //Console.WriteLine(b);
                }
                b += 1;
            }
            long count = 0;
            if (Atemp >= 1000001)
            {
                if (Atemp == Btemp)
                {
                    count += 1;
                }
            }
            if(Atemp < 1000001)
            {
                Ayaku[Atemp] += 1;
            }
            if (Btemp < 1000001)
            {
                Byaku[Btemp] += 1;
            }
            for (int i = 0; i < 1000001; i++)
            {
                if (Ayaku[i] > 0 && Byaku[i] > 0)
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27924
n,m =  map(int,input().split())

a = [0]*m
b = [0]*m
checks = [0]*n
checkg = [0]*n
for i in range(m):
    a[i],b[i] = map(int,input().split())
    if a[i]== 1:
        checks[b[i]]=1
    if b[i]== n:
        checkg[a[i]]=1
ans = 0
for i in range(n):
    if checks[i] == checkg[i] == 1:
        ans = 1
if ans :
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 21876
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  int N;
  cin >> N;
  ll dp[N][4][4][4];//dp[i][j][k]==>i:length-1 j,k:character(0==>a,1==>g,2==>c,3==>t)
  rep(i,N){
    rep(j,4){
      rep(k,4){
        rep(m,4){
          dp[i][j][k][m]=0;
        }
      }
    }
  }
  rep(i,3){
    rep(j,4){
      rep(k,4){
        rep(l,4){
          if(i<=1||(j==0&&k==1&&l==2)||(j==0&&k==2&&l==1)||(j==1&&k==0&&l==2))
            dp[i][j][k][l]=0;
          else
            dp[i][j][k][l]=1;
        }
      }
    }
  }
  FOR(i,3,N){
    rep(j,4){
      rep(k,4){
        rep(l,4){
          rep(m,4){
            if(!((j==0&&l==1&&m==2)||(j==0&&k==1&&m==2)||(k==0&&l==2&&m==1)||(k==1&&l==0&&m==2)||(k==0&&l==1&&m==2))){
              dp[i][k][l][m]+=dp[i-1][j][k][l];
              dp[i][k][l][m]%=MOD;
            }
          }
        }
      }
    }
  }
  ll ans=0;
  rep(i,4){
    rep(j,4){
      rep(k,4){
        ans+=dp[N-1][i][j][k];
        ans%=MOD;
      }
    }
  }
  cout << ans << endl;
}

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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};

const int MOD = 1e9+7;
map<int,int> M;
vector<int> A;
int n,m;
int pd[100002];
int dp(int id){
	if(id==n) return 1;
	if(id>n) return 0;
	if(pd[id]!=-1) return pd[id];
	int ans=0;
	if(!M.count(id+1))
		ans= (ans+dp(id+1))%MOD;
	if(!M.count(id+2))
		ans = (ans+dp(id+2))%MOD;
	return pd[id] = ans;
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(pd,-1,sizeof pd);
	cin >> n >> m;
	A = vector<int>(m);
	for(auto &a:A)
		cin >> a,M[a]=1;
	cout << dp(0) << '\n';
	
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




















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

int main() {
  int n;
  string s;
  cin >> n >> s;
  string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (int i = 0; i < s.size(); i++) {
    for (int j=0; j<26; j++) {
      if (s.at(i)==alp.at(j)) {
        j += n;
        if (j >= 26) {
          j -= 26;
        }
        s.at(i) = alp.at(j);
      } 
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
// Aizu 2330: Earth Invasion Diary of Miyabi-sensei
// 2017.9.27 bal4u@uu

#include <stdio.h>

int main()
{
	long long n, k;
	int ans;

	scanf("%lld", &n);
	for (ans = 0, k = 1; k < n; k *= 3, ans++);
	printf("%d\n", ans);
	return 0;
}

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

int main()
{
    long long n,k,sum=0;
    cin >> n >> k;
    long long h[n];
    for(int i=0;i<n;i++) {
        cin >> h[i];
    }
    sort(h,h+n);
    for(int i=1;i<=k;i++) {
        h[n-i] = 0;
    }
    for(int i=0;i<n;i++) {
        sum += h[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
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")
    };
}


fn main() {
    input! {
        a: i32,
        s: chars,
    }
    let ss: String = s.into_iter().collect();
    if a >= 3200{
        println!("{}", ss);
    }else{
        println!("{}", "red");
    }
}


Measured memory_bytes: 4352