akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	vl v(3);
	set<vl> st;
	rep(i, 3) cin >> v[i];
	sort(all(v));
	st.insert(v);
	for(int i = 0; ; i++) {
		if(v[0] % 2 == 1 || v[1] %2 == 1 || v[2] % 2 == 1) {
			cout << i << endl;
			return 0;
		}
		vl u(3);
		u[0] = v[1] / 2 + v[2] / 2;
		u[1] = v[0] / 2 + v[2] / 2;
		u[2] = v[1] / 2 + v[0] / 2;
		sort(all(u));
		if(st.count(u)) {
			cout << "-1" << endl;
			return 0;
		}else st.insert(u);
		v = u;
	}
}


Measured memory_bytes: 256
/**
 * CODE
 * BY
 * VIKAS VERMA
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n; i++)

#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef long long ll;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6 + 13;
//=======================
vi g[N];
int a[N];
//=======================

void solve()
{
  string s;
  cin >> s;
  int len = s.length();
  int count = 0;
  if (s[0] == 'R')
    count++;
  int _max = 0;
  for (int i = 1; i < len; i++)
  {
    if (s[i] == 'R')
      count++;
    else
    {
      _max = max(_max, count);
      count = 0;
    }
  }
  _max = max(_max, count);
  cout << _max << endl;
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  int t = 1;

  // cin >> t;

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

  return 0;
}

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

int main() {
  char c;
  map<char, int> m;
  for (int i=0; i<4; i++) {
    cin >> c;
    m[c]++;
  }
  int ans=0;
  for (auto x: m) {
    ans += (x.second == 2);
  }
  if (ans == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  string s[100];
  cin>>n>>l;
  for(int i=0;i<n;i++)cin>>s[i];
  sort(s,s+n);
  for(int i=0;i<n;i++)cout<<s[i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
int partition(int,int);

int A[N];
int main()
{
  int i,n,q;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  q=partition(0,n-1);
  
  for(i=0;i<n;i++)
    {
      if(i!=0) printf(" ");
      if(i==q) printf("[");
      printf("%d",A[i]);
      if(i==q) printf("]");
    }
  printf("\n");
  
  return 0;
}

int partition(int x,int y)
{
  int i,j,n,m;
  n=A[y];
  j=x-1;
  for(i=0;i<y;i++)
    {
      if(A[i]<=n)
	{
	  j++;
	  m=A[j];
	  A[j]=A[i];
	  A[i]=m;  
	}
    }
      m=A[j+1];
      A[j+1]=A[y];
      A[y]=m;
      return j+1;
}

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

int main() {
  string s;
  cin >> s;
  int min_diff=1000;
  for(int i=0;i<s.size()-2;i++){
    string num_s;
    num_s += s.at(i);
    num_s += s.at(i+1);
    num_s += s.at(i+2);
    int num = stoi(num_s);
    //cout << num << endl;
    if( min_diff > abs(num-753) ){
      min_diff = abs(num-753);
    }
  }
  cout << min_diff << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

bool kaibun(string s){
  if(s.size()==2){
    if(s.at(0)==s.at(1)){
      return true;
    }else{
      return false;
    }
  }
  rep(i,(s.size()-1)/2){
    if(s.at(i)!=s.at(s.size()-i-1)){
      return false;
    }
  }return true;
}

int main(){
  string s;
  cin>>s;
  string ss;
  rep(i,(s.size()-1)/2){
    ss.push_back(s.at(i));
  }
  if(kaibun(s)&&kaibun(ss)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,l[100];
  int r=0;
  int s=0;
  scanf("%d",&n);
  for(int t=0;t<n;t++){
    scanf("%d",&l[t]);
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if((l[i]<(l[j]+l[k]))&&(l[j]<(l[k]+l[i]))&&(l[k]<(l[i]+l[j]))){
        //  printf("i:%d j:%d k:%d l[i]:%d l[j]:%d l[k]:%d\n",i+1,j+1,k+1,l[i],l[j],l[k]);
          r++;
          if((l[i]==l[j])||(l[j]==l[k])||(l[i]==l[k])){
            s++;
        //    printf("same!\n");
          }
        }
      }
    }
  }

  r-=s;
  printf("%d",r);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int32_t main() 
{ 
    fastio
    char a;
    cin>>a;
    if(a>='A' && a<='Z') {
        cout<<'A'<<endl;
    }
    else {
        cout<<"a"<<endl;
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>

int main() {
  int n;
  while (std::cin >> n) {
    std::cout<< "3C" << std::setfill('0') << std::right << std::setw(2) << (n - 1) % 39 + 1 << std::endl;
  }
  return 0;
}



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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(m),b(m);
  for(int i=0;i<m;i++){
    cin >> a.at(i) >> b.at(i);
  }

  vector<int> r(n,0);
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(a.at(i) == j+1 || b.at(i) == j+1) ++r.at(j);
    }
  }

  for(int j=0;j<n;j++){
    cout << r.at(j) << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();

		int B = sc.nextInt();

		if(A%2 == 0 || B%2 ==0) {

			System.out.println("No");

		}else {

			System.out.println("Yes");
		}

	}

}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
int n;
int an[100010];

int main()
{
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		cin >> an[i];
	}
	long long  res = 1;
	ll ans = 0;

	for(int i = 0;i < n;i++){
		res *= an[i];
		ans += (res - 1)%an[i];
		res = ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
  
int main(){
  int N,M;
  cin >> N >> M;
  if(N>=M){
    cout << "0\n";
    return 0;
  }
  if(M==1){
    cout << "0\n";
    return 0;
  }
  vector<int> L(M);
  for(int i=0;i<M;i++){
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  vector<int> Width(M-1);
  for(int i=0;i<M-1;i++){
    Width[i] = L[i+1] - L[i];
  }
  sort(Width.begin(), Width.end());
  for(int i=0;i<N-1;i++){
    Width.pop_back();
  }
  cout << accumulate(Width.begin(), Width.end(), 0) << "\n";
}


Measured memory_bytes: 1024
import java.lang.Math

fun main(args: Array<String>)
{
    val (n) = readInts()
    val a = readIntArr()
    val b = readIntArr()
    val c = readIntArr()

    var conf = 0
    for (bi in b) conf += bi

    for (i in 0..n-2) {
        if (a[i+1] - a[i] == 1) conf += c[a[i]-1]
    }

    println(conf)
}

fun readInts(): List<Int> = readLine()!!.split(" ").map(String::toInt)
fun readLongs(): List<Long> = readLine()!!.split(" ").map(String::toLong)

fun readIntArr(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray()
fun readLongArr(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray()

fun readIntArrS(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray().sortedArray()
fun readLongArrS(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray().sortedArray()

fun readIntArrSD(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray().sortedArrayDescending()
fun readLongArrSD(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray().sortedArrayDescending()

fun readString() = readLine()!!


Measured memory_bytes: 38072
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll a[200000];
ll b[200000];

int main() {
  ll n;
  cin >> n;
  rep(i, n){
    cin >> a[i];
  }
  rep(i, n){
   if(i) b[i] += b[i-1];
   b[i] += a[i];
  }
  map<ll,ll> mp;
  rep(i, n){
    mp[b[i]]++;
  }
  ll sum = 0;
  for(auto at: mp){
    ll tm = at.first == 0 ? at.second : at.second - 1;
    reps(i, tm){
      sum += i;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 15872
n = int(input())
s = input()
s = list(s)
a = ''
for i in range(len(s)):
    if 'A' <= chr(ord(s[i]) + n) and chr(ord(s[i]) + n) <= 'Z':
        s[i] = chr(ord(s[i]) + n)
    else:
        s[i] = chr(ord('A') + (ord(s[i]) + n) % (ord('Z') + 1))
    a += s[i]
print(a)

Measured memory_bytes: 3060
use proconio::{fastout, input};
use itertools::Itertools;

#[fastout]
fn main() {
    input! {
        n: usize,
        d: [usize; n]
    }
    println!("{}",
        d.iter().combinations(2)
            .fold(0, |acc : usize, c| acc + c[0] * c[1])
    );
}


Measured memory_bytes: 2184
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int a[maxn],n,b[maxn],K,t;
int ans[maxn],tmp[maxn];
int c[maxn][30],d[maxn][30];
int A[maxn],B[maxn];

int main(){
    cin >> n >> K;
    for (int i=1;i<=n;i++) cin >> a[i];
    for (int i=1;i<=n;i++) A[a[i]]=i;
    for (int i=1;i<=n;i++) cin >> b[i];
    for (int i=1;i<=n;i++) B[b[i]]=i;
    if (K==1){
        for (int i=1;i<=n;i++) printf("%d ",a[i]);puts("");
        return 0;
    }

    K-=2; t=K/6;
    for (int i=1;i<=n;i++) ans[i]=i;
    for (int i=1;i<=n;i++) c[i][0]=A[b[a[B[i]]]];
    for (int i=1;i<=n;i++) d[i][0]=b[A[B[a[i]]]];
    for (int i=1;i<30;i++)
        for (int j=1;j<=n;j++)
            c[j][i]=c[c[j][i-1]][i-1],
            d[j][i]=d[d[j][i-1]][i-1];
    for (int i=0;i<30;i++) if (t&(1<<i)) {
        for (int j=1;j<=n;j++) tmp[j]=ans[j];
        for (int j=1;j<=n;j++) ans[j]=c[tmp[j]][i];
    }
    for (int i=1;i<=n;i++) tmp[i]=ans[i];
    for (int i=1;i<=n;i++){
        if (K%6==0) ans[i]=b[tmp[i]];
        if (K%6==1) ans[i]=b[A[tmp[i]]];
        if (K%6==2) ans[i]=b[A[B[tmp[i]]]];
        if (K%6==3) ans[i]=b[A[B[a[B[tmp[i]]]]]];
        if (K%6==4) ans[i]=b[A[B[a[a[B[tmp[i]]]]]]];
        if (K%6==5) ans[i]=b[A[B[a[b[a[B[tmp[i]]]]]]]];
    }
    for (int i=0;i<30;i++) if (t&(1<<i)) {
        for (int j=1;j<=n;j++) tmp[j]=ans[j];
        for (int j=1;j<=n;j++) ans[j]=d[tmp[j]][i];
    }
    for (int i=1;i<=n;i++) cout << ans[i] << ' '; cout << endl;
    return 0;
}


Measured memory_bytes: 26624
H, W = list(map(int, input().split()))
res = min(H,W)
hr,vr = H%3*W,W%3*H
def min_s_diff(x, y):
    if x % 3 == 0:
        return 0
    if x % 3 == 1:
        a = x // 3
        b = y // 2
        s1 = a * y
        s2 = (x - a) * b
        s3 = x * y - s1 - s2
        return max(s1, s2, s3) - min(s1, s2, s3)
    if x % 3 == 2:
        a = x // 3 + 1
        b = y // 2
        s1 = a * y
        s2 = (x - a) * b
        s3 = x * y - s1 -s2
        return max(s1, s2, s3) - min(s1, s2, s3)

print(min(min_s_diff(H, W), min_s_diff(W, H), res, hr, vr))
        


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

using namespace std;

int N;
void solve();

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

void solve() {
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    string s = to_string(i);
    if (s.size() % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>
#include <cmath>

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

const int MAXN = 1e5 + 20;

ll mod = 1e9 + 7;


struct pt {
    ld x, y;

    pt operator-(pt & other){
        return pt{x - other.x, y - other.y};
    }

    pt operator+(pt & other){
        return pt{x + other.x, y + other.y};
    }


    ld len(){
        return sqrt(x * x + y * y);
    }
};

int n;
bool no_c = false;

pt get_c(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3) {

    ld A = x2 - x1;
    ld B = y2 - y1;
    ld C = x3 - x1;
    ld D = y3 - y1;
    ld E = A * (x1 + x2) + B * (y1 + y2);
    ld F = C * (x1 + x3) + D * (y1 + y3);
    ld G = 2 * (A * (y3 - y2) - B * (x3 - x2));
    if (G == 0) {
        no_c = true;
    }
    no_c = false;
    ld Cx = (D * E - B * F) / G;
    ld Cy = (A * F - C * E) / G;

    return pt{Cx, Cy};
}

vector<pt> pts;
ld calc_over(int i, int j, int k){
    ld ret = 1e18;

    pt centr = get_c(pts[i].x, pts[i].y, pts[j].x, pts[j].y, pts[k].x, pts[k].y);

    if (no_c)
        return ret;


    ret = (pts[i] - centr).len();
    for (int ii = 0; ii < n; ++ii){
        if (ii == i || ii == j || ii == k)
            continue;
        if ((pts[ii] - centr).len() > ret)
            return 1e18;
    }

    return ret;
}

ld calc_over(int i, int j){
    ld ret = 1e18;

    pt centr = pts[i] + pts[j];

    centr.x /= 2;
    centr.y /= 2;


    ret = (pts[i] - centr).len();
    for (int ii = 0; ii < n; ++ii){
        if (ii == i || ii == j)
            continue;
        if ((pts[ii] - centr).len() > ret)
            return 1e18;
    }

    return ret;
}


void solve() {


    cin >> n;

    for (int i = 0; i < n; ++i) {
        pt p;
        cin >> p.x >> p.y;
        pts.push_back(p);
    }

    if (n == 2) {
        ld answr = (pts[0] - pts[1]).len() / 2;

        cout << answr << "\n";
        return;
    }

    ld answr = 1e18;

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {

            answr = min(answr, calc_over(i, j));
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                answr = min(answr, calc_over(i, j, k));
            }
        }
    }
    cout << answr << "\n";
}


int main() {
    ios_base::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(20);
    solve();
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

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

    rep(i,h){
        rep(j,w){
            string s;
            cin>>s;
            if(s=="snuke"){
                cout<<char ('A'+j)<<i+1<<endl;
                return 0;
            }
        }
    }
    return 0;
}



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

#define dbg(help) cerr << #help << " = " << (help) << endl;
#define int  long long
#define endl "\n"

using namespace std;

void boot_up() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif
    cout.setf(ios::fixed); cout.precision(4);
}

const int INF = 1e18, maxn = 3e5 + 1;

signed main() {
    boot_up();

    int a, b, c, d, cnt1 = 0, cnt2 = 0, cnt3 = 0;
    cin >> a >> b >> c >> d;
    int k;
    if (a % c == 0) {
        k = a;
    }
    else {
        k = (a / c + 1) * c;
    }
    if (k <= b) {
        cnt1 = ((b - k + 1) - 1) / c + 1;
    }

    if (a % d == 0) {
        k = a;
    }
    else {
        k = (a / d + 1) * d;
    }
    if (k <= b) {
        cnt2 = ((b - k + 1) - 1) / d + 1;
    }

    int e = c * d / __gcd(c, d);

    if (a % e == 0) {
        k = a;
    }
    else {
        k = (a / e + 1) * e;
    }
    if (k <= b) {
        cnt3 = ((b - k + 1) - 1) / e + 1;
    }

    cout << b - a + 1 - (cnt1 + cnt2 - cnt3) << endl;
    
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pi>;
const int maxn = 2020, mod = 998244353;
int n;
int dp[maxn][maxn], countw[maxn][2*maxn], countb[maxn][2*maxn], wpos[maxn], bpos[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	char c;
	for(int t, i = 1; i <= 2*n; i++) {
		cin >> c >> t;
		if(c == 'B') bpos[t] = i;
		else wpos[t] = i;
	}
	memset(countw, 0, sizeof countw);
	memset(countb, 0, sizeof countb);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= 2*n; j++) {
			countw[i][j] = countw[i-1][j] + (wpos[i]<j);
			countb[i][j] = countb[i-1][j] + (bpos[i]<j);
		}
	}
	memset(dp, 0x3f, sizeof dp);
	dp[0][0] = 0;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j + i < 2*n && j<=n; j++) {
			if(j!=n)dp[i][j+1] = min(dp[i][j+1], dp[i][j] + bpos[j+1] - 1 - countw[i][bpos[j+1]] - countb[j][bpos[j+1]]);
			if(i!=n)dp[i+1][j] = min(dp[i+1][j], dp[i][j] + wpos[i+1] - 1 - countw[i][wpos[i+1]] - countb[j][wpos[i+1]]);
		}
	cout << dp[n][n];
}

Measured memory_bytes: 80000
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
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 (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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

    vector<int> C(N);
    vector<int> D(N);
    for (int i = 0; i < N; i++) {
        C[i] = A[i] + i;
        D[i] = -A[i] + i;
    }

    map<int, int> m;
    for (int d : D) m[d]++;

    int ret = 0;
    for (int i = 0; i < N; i++) {
        m[D[i]]--;
        ret += m[C[i]];
    }

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

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

using namespace std;

const int mod = 1e9 + 7;

int n, k;
vector<int> arr;
vector<vector<int>> dp;


int main(){
    cin>>n>>k;
    arr.resize(n);
    dp.resize(n+1, vector<int>(k+1, 0));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++) cin>>arr[i];
    for(int i = 1; i <= n; i++){
        vector<int> ps(k+1, 0);
        int cur = 0;
        for(int u = 0; u <= k; u++){
            cur = (cur%mod + dp[i-1][u]%mod);
            ps[u] = cur % mod;
        }
        for(int j = 0; j <= k; j++){
            int idx = j - arr[i-1] - 1;
            if(idx < 0){
                dp[i][j] = ps[j] % mod;
            }else{
                dp[i][j] = (ps[j] - ps[idx] + mod)%mod;
            }
        }
    }
    int res = dp[n][k];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 40192
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func count(sw int, s []int) int {
	cnt := 0
	for i := range s {
		if (sw>>uint(s[i]-1))&1 == 1 {
			cnt++
		}
	}
	return cnt
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	k, s := make([]int, m), make([][]int, m)
	for i := 0; i < m; i++ {
		k[i] = nextInt()
		s[i] = nextInts(k[i])
	}
	p := nextInts(m)

	ans := 0
	for sw := 0; sw < (1 << uint(n)); sw++ {
		allon := true
		for i := 0; i < m && allon; i++ {
			allon = count(sw, s[i])%2 == p[i]
		}
		if allon {
			ans++
		}
	}

	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define foro(i, n) for(i=0; i<n; i++)
#define forl(i, n) for(i=1; i<=n; i++)
#define x first
#define y second
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;

int main()
{
	int i, j, l, tmp;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll n, k;
	cin >> n >> k;
	n = (n%k);
	while(n > abs(n-k)){
		n = abs(n-k);
	}
	cout << n << endl;
}


Measured memory_bytes: 256
#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(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  vi h(n);
  REP(i,n)cin >> h[i];

  vi dp(n+1, INF);
  dp[0]=0;
  REP(i,n){
    if(i+1<n)chmin(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
    if(i+2<n)chmin(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
  }
  cout << dp[n-1] << endl;
}



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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i){
	if ((i * 108) / 100  == n){
		cout << i << "\n";
		return 0;
	}	
  }
  cout << ":(\n";
return 0;
}


Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 600010;
const int MAXK = 110;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    string s;
    int n;
    cin >> n;
    cin >> s;
    if (n % 2) cout << "No";
    else if (s.substr(0, n/2) + s.substr(0, n/2) == s) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1e+7
#define int long long
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int l[100000];
signed main() {
	garou;
	int n,m;
	cin>>n>>m;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
		l[i]=1;
	}
	int a[m][2];
	for(int i=0;i<m;i++){
    cin>>a[i][0]>>a[i][1];
	a[i][0]--;
	a[i][1]--;
	} 
	for(int i=0;i<m;i++){
		if(h[a[i][0]]>=h[a[i][1]]){
		l[a[i][1]]=0;
	}    
   if(h[a[i][0]]<=h[a[i][1]]){
		l[a[i][0]]=0;
	}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=l[i];
	}
	cout<<ans;
}

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

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
    // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll x,y;
    cin >> x >> y;
    ll a = (2*x-y)/3;
    ll b = (2*y-x)/3;
    if(a<0 || b<0){
        cout << 0;
        return 0;
    }
    if(2*a+b==x && a+2*b==y){
        ll fac[1000005];
        fac[0] = 1;
        for (ll i=1 ; i<1000005; i++)
            fac[i] = (fac[i-1]*i)%mod;
        cout << ((fac[a+b]* modInverse(fac[a], mod) % mod * modInverse(fac[b], mod) % mod) % mod);

        return 0;
    }
    cout << 0;
}

Measured memory_bytes: 8064
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}


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

	int ans = n - a;
	if (ans > 0) {
		cout << ans << endl;
	}
	else {
		cout << '0' << endl;
	}

}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
ans = 1
 
for n in range(N):
 ans = L[n]*ans
 if ans >= 1000000000000000001: ans = -1
 if ans == -1: break
 
for n in range(N):
 if L[n] == 0: ans = 0
print(ans)

Measured memory_bytes: 21584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		for (int i = 0; i < input.length; i++) {
			input[i] = sc.nextInt();
		}
		int[] ans = new int[N];

		for (int i = 0; i < input.length; i++) {
			ans[input[i] - 1] = i + 1;
		}
		for (int i = 0; i < ans.length; i++) {
			if (i == ans.length - 1)
				System.out.print(ans[i]);
			else
				System.out.print(ans[i] + " ");
		}
		sc.close();
	}
}

Measured memory_bytes: 60260
turnNum = gets.to_i
cardNums = gets.chomp.split(" ").map(&:to_i).sort.reverse
cardNums.sort.reverse
result =0
for i in 0...turnNum do
  if i % 2 == 0 then
    result = result+cardNums[i]
  else
    result = result-cardNums[i]
  end
end
puts "#{result}"

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define deb(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
using namespace std;
int main()
{
    int n;
    cin>>n;
    int pts[n][3];

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

    int dp[n][3];
    dp[0][0]=pts[0][0];
    dp[0][1]=pts[0][1];
    dp[0][2]=pts[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=pts[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=pts[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=pts[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 5908
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder//ditmeatcoder//ditmeatcoder//ditmeatcoder//ditmeatcoder//ditmeatcoder
//ditmeatcoder//ditmeatcoder
//ditmeatcoder
//ditmeatcoder//ditmeatcoder//ditmeatcoder//ditmeatcoder//ditmeatcoder

//ditmeatcoder
//ditmeatcoder//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
//ditmeatcoder
#include<bits/stdc++.h>
using namespace std;
int dx[9]={-1,-1,-1,0,0,0,1,1,1};
int dy[9]={-1,0,1,-1,0,1,-1,0,1};
	map<pair<int,int>,int> cnt;
	long long H,W,N,a,b,p,q;
	long long ditmedevc[11];
int main (){

	cin>>H>>W>>N;
	ditmedevc[0]=(H-2)*(W-2);
  while(N--){
  	cin>>a>>b;
      for(int i=0;i<9;i++){
      	p=a+dx[i];
      	q=b+dy[i];
      	if(p>1&&p<=H-1&&q>1&&q<=W-1){
      		cnt[{p,q}]++;
      		ditmedevc[cnt[{p,q}]-1]--;
      		ditmedevc[cnt[{p,q}]]++;
		  }
	  } 
  }
   for(int i=0;i<10;i++){
	  	cout<<ditmedevc[i]<<endl;
	  }
}

Measured memory_bytes: 56448
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    string s;
    cin>>s;
    bool ok=true;
    for(int i=0;i<s.length();i+=2){
        if(s.substr(i,2)=="hi") continue;
        else ok=false;
    }

    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int dp[1000010][2];

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

    string N;
    cin >> N;
    int n = N.size();
    reverse(N.begin(), N.end());
    fill((int*)dp, (int*)dp + sizeof(dp) / sizeof(dp[0][0]), (1 << 30));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) {
        char Ni;
        if (i < n)
            Ni = N[i];
        else
            Ni = '0';
        dp[i + 1][0] = min(dp[i][0] + (Ni - '0'), dp[i][1] + (Ni - '0' + 1));
        dp[i + 1][1] = min(dp[i][0] + 10 - (Ni - '0'), dp[i][1] + 10 - (Ni - '0' + 1));
    }

    cout << dp[n + 1][0] << endl;

    return 0;
}

Measured memory_bytes: 9116
#include<iostream>
#include<cmath>
#include <iomanip>

using namespace std;

int main(){
  double x1,y1,x2,y2;

  long double ans;

  cin >> x1 >> y1 >> x2 >> y2;
  
  ans = sqrt(pow(x2-x1,2)+pow(y2-y1,2));

  cout << fixed << setprecision(5) << ans << endl;
}
  

Measured memory_bytes: 3244
fun main(argas: Array<String>) {
    val n = readLine()!!.toInt()
    val values = readLine()!!.split(" ").map(String::toInt)

    val sortedValues = values.sorted()
    var count = 0;

    for (i in 0 until values.size) {
        if (values[i] != sortedValues[i]) count++
    }

    if (count == 2 || count == 0) {
        println("YES")
    } else {
        println("NO")
    }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code
template<typename T> struct comb {
	T n,k;
	LL numerator = 1;   //分子
	LL denominator = 1; //分母
	LL ans = 1;
	comb(T a, T b) : n(a), k(b) {set_nd();}

	// function
	/// 分子分母の設定
	void set_nd() {
		for (T i = 0, j = n; i < k; i++,j--) {
			numerator *= j;
			numerator %= MOD;
		}
		for (T i = 1; i < k + 1; i++) {
			denominator *= i;
			denominator %= MOD;
		}
	}
	/// a^b%pの計算
	LL calcInv(LL a,LL b,LL p) {
		if (b == 0) {
			return 1;
		}
		if (b % 2 == 0) {
			LL d = calcInv(a,b/2,p);
			return (d*d)%p;
		}
		return (a * calcInv(a,b-1,p)) % p;
	}

	LL getans() {
		denominator = calcInv(denominator,MOD-2,MOD);
		return (numerator * denominator) % MOD;
	}

};

int main(int argc, char const* argv[])
{
	int n,k;
	cin >> n >> k;

	for (int i = 1; i <= k; i++) {
		comb<LL> bs(k-1,i-1);
		comb<LL> bi(n-k+1,i);
		LL ans = bs.getans() * bi.getans();
		ans %= MOD;
		cout << ans << endl;

	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N; cin >> N;
    map<long long, long long> map;
    for (long long i = 0; i < N; i++) {
        long long in; cin >> in;
        ++map[in];
    }

    for (auto mp : map) {
        if (mp.second != 1) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 12800
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

N = int(input())
S = list(str(input()))

if N % 2 == 1:
    print("No")
    sys.exit()

m = int(N / 2)
for i in range(m):
    if S[i] != S[m + i]:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> p(n);
    REP(i, n) {
        cin >> a[i];
        p[a[i] - 1] = i;
    }

    set<ll> s{-1, n};
    ll ans = 0;
    REP(i, n) {
        s.insert(p[i]);
        auto itr = s.find(p[i]);
        ans += (*next(itr) - *itr) * (*itr - *prev(itr)) * (i + 1);
    }
    cout << ans << endl;
        
}



Measured memory_bytes: 12800
#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

void solve() {
    ll a, b, c, d, e, f, g;
    sc(a, b, c, d, e, f, g);
    ll ans = 2 * b + 4 * ((a / 2) + (d / 2) + (e / 2));
    if(min({a, d, e}) >= 1) {
        a--, d--, e--;
        ans = max(ans, 2 * b + 6 + 4 * (a / 2 + d / 2 + e / 2));
    }
    cout << ans / 2;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  int n; cin >> n;
  if(n < 1000) cout << "ABC";
  else cout << "ABD";
  cout << endl;
}

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

int main()
{
    long long int n,m,i,j,k=0;
    cin>>n>>m;
    int a[m+10];
    for(i=1;i<=m;i++)
    {
        cin>>a[i];
        k+=a[i];
    }
    if(k>n)cout<<-1<<endl;
    else cout<<n-k<<endl;
    return 0;
}


Measured memory_bytes: 3636
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, A, B, C, D = map(int, input().split())

    A, B = min(A, B), max(A, B)
    diff = B - A

    for plus in range(N):
        if C * (N - 1 - plus) - D * plus <= diff<= -C * plus + D * (N - 1 - plus):
            print('YES')
            return

    print('NO')

sol()

Measured memory_bytes: 3380
#include<cstdio>

using namespace std;
typedef long long ll;

int gcd(int a,int b){
    if(b==1||a==1)return 1;
    while(b>0){
        int temp = a;
        a = b;
        b = temp%b;
    }
    return a;
}

int main(){
    int k = 0;
    ll ans = 0;
    scanf("%d",&k);
    for(int i = 1;i<=k;i++){
        for(int j = 1;j<=k;j++){
            for(int ii = 1;ii<=k;ii++){
                ans+=gcd(i,gcd(ii,j));
            }
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std; 
typedef long long lli;
#define mod 1000000007
const int INF = 1e6;
const int MAX = 1e5+10;
#define fori(n) for(int i=0;i<n;i++)
#define forj(n) for(int j=0;j<n;j++)
#define forli(n) for(lli i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define print(a) cout<<a<<endl
#define print2(a,b) cout<<a<<" "<<b<<endl
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define sortvec(a) sort(a.begin(),a.end())
 
//FUNCTONS
lli llipower(lli x, lli y){lli res = 1;x = x % mod; while (y > 0){if (y & 1) res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
lli llipowerp(lli x, lli y,lli p){lli res = 1;x = x % p; while (y > 0){if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}
lli gcd(lli a, lli b){ if (!a) return b; return gcd(b%a,a);}
lli binarySearch(vector<int> arr, int l, int r, int x){ 
	if (r >= l) { 
		lli mid = l + (r - l) / 2; 
		if (arr[mid] == x) return mid; 
		if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); 
		return binarySearch(arr, mid + 1, r, x); 
	} 
	return -1;
}

template <typename T>
void printvec(vector<T> inp){
	for(int i=0;i<inp.size();i++){
		cout<<inp[i]<<" ";
	}
	cout<<endl;
}
template <typename T>
T ceildiv(T x, T y){
	return 1 + ((x - 1) / y);
}
lli modInverse(lli a, lli m){//m is PRIME 
    lli g = gcd(a, m); 
    if (g != 1) return -1;
    else return llipowerp(a, m-2, m);
} 
int main(){

	vector<vector<int>> grid(3,vector<int> (3,0));
	fori(3){
		forj(3){
			cin>>grid[i][j];
		}
	}
	vector<vector<int>> check(3,vector<int> (3,0));
	int n;
	cin>>n;
	int temp;
	for(int k=0;k<n;k++){
		cin>>temp;
		fori(3){
			forj(3){
				if(temp==grid[i][j]){
					check[i][j]=1;
				}
			}
		}
	}
	if(check[0][0]+check[0][1]+check[0][2]==3 || check[1][0]+check[1][1]+check[1][2]==3 || check[2][0]+check[2][1]+check[2][2]==3 || check[0][0]+check[1][0]+check[2][0]==3 || check[0][1]+check[1][1]+check[2][1]==3 || check[0][2]+check[1][2]+check[2][2]==3 || check[0][0]+check[1][1]+check[2][2]==3 || check[0][2]+check[1][1]+check[0][2]==3) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
 
 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

double cross_product (xy_t a, xy_t b) {
    return (conj(a) * b).imag();
}

xy_t P[110];

int main() {
    int n;
    cin >> n;
    double x[4], y[4];
    for (int i = 0; i < n; i++) {
        for (int i = 0; i < 4; i++) {
            cin >> x[i] >> y[i];
        }
        xy_t a[2] = {
            xy_t (x[0], y[0]) - xy_t (x[1], y[1]),
            xy_t (x[2], y[2]) - xy_t (x[3], y[3])
        };
        bool ok = abs(cross_product(a[0], a[1])) < eps;
        cout << (ok ? "YES" : "NO") << endl;
    }
}



Measured memory_bytes: 3148