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

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll i,j,k,l,n,v;
    cin>>n>>v;
    ll ar[n+1];
    for(i=1;i<=n;i++){
        cin>>ar[i];
    }
        
    vector<ll> vc;
    i=1;  ll fl[n+1]={0};
    while(fl[i]==0){
        fl[i]=1;
        vc.ps(i);
        i=ar[i];
    }
    k=vc.size();
    vector<ll> an;
    for(j=k-1;j>=0;j--){
        if(vc[j]==i){
            an.ps(vc[j]);
            break;
        }
        an.ps(vc[j]);
    }
    reverse(all(an));

    if(v<vc.size()-an.size()){
        cout<<vc[v]<<endl;
        return 0;
    }
    if(v==vc.size()-an.size()){
        cout<<an[0]<<endl;
        return 0;
    }
    v-=(vc.size()-an.size());
    k=an.size();
    // cout<<k<<endl;
    l=(v%k);
    // for(auto it:an){
    //     cout<<it<<" ";
    // }cout<<endl;
    cout<<an[l]<<endl;
    return 0;   
}

Measured memory_bytes: 10760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, q, h, s, d, n);
    int p1 = min({4*q, 2*h, s});
    int p2 = min(2*p1, d);
    ll ans = n/2 * (ll)p2;
    if(n % 2) ans += p1;
    Cout(ans);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        while(true) {
            int n = scn.nextInt();
            int x = scn.nextInt();
            if(n == 0 && x == 0) {
                break;
            }
            int c = 0;
            for(int i = n; i > 2; i--) {
                for(int j = ~-i; j > 1; j--) {
                    for(int k = ~-j; k > 0; k--) {
                        if(i + j + k == x) {
                            c++;
                        }
                    }
                }
            }
            System.out.println(c);
        }
    }
}

Measured memory_bytes: 19624
#include <iostream>
#include <vector>
 
const int64_t MOD = 1000 * 1000 * 1000 + 7;
 
int main() {
  int64_t n, k;
  std::cin >> n >> k;
 
  std::vector<int64_t> cand;
  std::vector<int64_t> num;
  cand.push_back(0);
  num.push_back(0);
 
  for (int64_t i = 1;;) {
    auto div = n / i;
    cand.push_back(div);
    auto next = n / div + 1;
    num.push_back(next - i);
    i = next;
    if (div == 1) {
      break;
    }
  }
 
  --k;
  auto size = cand.size();
  std::vector<int64_t> dp(size * k);
 
  dp[0] = 0;
  for (int64_t j = 1; j < size; ++j) {
    int64_t &now = dp[j];
    const int64_t &left = dp[j - 1];
    now = ((cand[j] * num[j]) % MOD + left) % MOD;
  }
 
  for (int64_t i = 1; i < k; ++i) {
    dp[i * size + 0] = 0;
    for (int64_t j = 1; j < size; ++j) {
      int64_t &now = dp[i * size + j];
      const int64_t &val = dp[i * size - j];
      const int64_t &left = dp[i * size + j - 1];
 
      now = ((val * num[j]) % MOD + left) % MOD;
    }
  }
 
  std::cout << *(dp.end() - 1) << std::endl;
 
 
  return 0;
}

Measured memory_bytes: 50420
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=510000;
const int mod=1e9+7;
const ll oo=1e18+5;



int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n;
	cin>>n;
	if(n<3) return cout<<-1,0;
	if(n==3){
		cout<<"aa.\n..a\n..a"<<endl;
		return 0;
	}
	vector<string> matrixx[8];
	// 4
	matrixx[4].push_back("aabc");
	matrixx[4].push_back("ddbc");
	matrixx[4].push_back("bcaa");
	matrixx[4].push_back("bcdd");
	// 5
	matrixx[5].push_back("aabba");
	matrixx[5].push_back("bcc.a");
	matrixx[5].push_back("b..cb ");
	matrixx[5].push_back("a..cb");
	matrixx[5].push_back("abbaa");
	// 6
	matrixx[6].push_back("aabc..");
	matrixx[6].push_back("ddbc..");
	matrixx[6].push_back("..aabc");
	matrixx[6].push_back("..ddbc");
	matrixx[6].push_back("bc..aa");
	matrixx[6].push_back("bc..dd");
	//7
	matrixx[7].push_back("aabbcc.");
	matrixx[7].push_back("dd.dd.a");
	matrixx[7].push_back("..d..da");
	matrixx[7].push_back("..d..db");
	matrixx[7].push_back("dd.dd.b");
	matrixx[7].push_back("..d..dc");
	matrixx[7].push_back("..d..dc");
	
	int rem=n%4;
	int k=n/4;
	if(rem) --k;
	int times=-1;
	//~ int loopp=0;
	for(int i=0;i<k*4;++i)
	{
		if(i%4==0) ++times;
		for(int j=0;j<times*4;++j) cout<<".";
		cout<<matrixx[4][i%4];
		for(int j=times*4+4;j<n;++j) cout<<".";
		cout<<endl;
	}
	++times;
	if(rem){
		for(int i=0;i<4+rem;++i){
			for(int j=0;j<times*4;++j) cout<<".";
			cout<<matrixx[rem+4][i%(rem+4)];
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int r = in.nextInt();
		int c = in.nextInt();
		int[][] ary = new int[r+1][c+1];
		
		//Insert the given values
		for(int i=0; i<r; i++){
			for(int j=0; j<c; j++){
				ary[i][j] = in.nextInt();
			}
		}
		//Calculate the total values
		for(int i=0; i<r; i++){
			for(int j=0; j<c; j++){
				ary[i][c] += ary[i][j];
				ary[r][j] += ary[i][j];
				ary[r][c] += ary[i][j];
			}
		}
		//Display the matrix
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c+1; j++){
				System.out.print(ary[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		in.close();
	}
}

Measured memory_bytes: 39344
#include<stdio.h>

int main() { 
  long long  n, m, ans = 1;
  scanf("%Ld %Ld", &n, &m);
  if( n-m > 1 || m-n > 1){
    printf("%d\n", 0);
    return 0;
  }
  int i;
  for(i = 0; i < n; i++){
    ans *= (i + 1);
    ans %= 1000000007;
  }
  for(i = 0; i < m; i++){
    ans *= (i + 1);
    ans %= 1000000007;
  }
  if(n == m){
    ans *= 2;
  }
  ans %= 1000000007;
  printf("%Ld\n", ans);
  return 0;
}

Measured memory_bytes: 128
use utf8;
use strict;
use warnings;

chomp(my ($s, $t) = split(/ /, <>));
chomp(my ($a, $b) = split(/ /, <>));
chomp(my $u = <>);
my $h = +{$s => $a, $t => $b};
$h->{$u}--;
print $h->{$s}." ".$h->{$t}." \n ";

Measured memory_bytes: 768
# https://atcoder.jp/contests/abc125/tasks/abc125_c

import itertools
from collections import Counter
from collections import defaultdict
import bisect

memo = {}


def gcd(a, b):
    if a in memo:
        if b in memo[a]:
            return memo[a][b]
    ans = gcd_core(a, b)
    if a in memo:
        memo[a][b] = ans
    else:
        memo[a] = {}
        memo[a][b] = ans
    return ans


def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ming = 0

    cand = []

    for i in range(N):
        temp = gcd(A[i], ming)
        # print(temp)
        if temp != ming:
            cand.append(i)
        ming = temp

    # print(index)

    answers = []
    for c in cand:
        ans1 = 0
        for i in range(N):
            if i != c:
                ans1 = gcd(A[i], ans1)
        answers.append(ans1)

    print(max(answers))


if __name__ == '__main__':
    main()


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

int main()
{
    int p, q, r;
    cin >> p >> q >> r;

    int mx = p;
    if (mx < q)
    {
        mx = q;
    }
    if (mx < r)
    {
        mx = r;
    }

    int ans = p + q + r - mx;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
typedef long long ll;

using namespace std;
int main(){
    int a,b;
    cin >> a>>b;
    if((b-1)%(a-1)==0){
        cout<<(b-1)/(a-1)<<endl;
    }else{
        cout<<(b-1)/(a-1)+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int i, u, v, cnt[5];
vector <int> G[5];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for (i = 0; i < 3; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (i = 1; i <= 4; i++){
		cnt[G[i].size()] += 1;
	}
	cout << (cnt[1] == 2 && cnt[2] == 2 ? "YES" : "NO") << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;



int main(){
	int n;
	string f="Three";
	cin>>n;
	vector<char>c(10000000);
	for(int i=0;i<n;i++){
		cin>>c[i];
		if(c[i]=='Y'){
			f="Four";
		}
	}
	cout<<f<<endl;
    return 0;
}

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

using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> v(N);
  vector<int> w(N);
  for (int i = 0; i < N; ++i) {
    cin >> v[i] >> w[i];
  }

  // answer: dp[N][W] largest value with 0 .. N-1 elements that have not over total weight <= W 
  // dp[n+1][w] = max(dp[n][w - w[n]] + v[n], dp[n][w]) if w[n] <= w else dp[n][w]
  // dp[0][w] = 0;
  vector<vector<int>> dp(N + 1, vector<int>(W + 1));
  for (int n = 0; n < N; ++n) {
    for (int wm = 0; wm <= W; ++wm) {
      dp[n + 1][wm] = w[n] <= wm ? max(dp[n][wm - w[n]] + v[n], dp[n][wm]) : dp[n][wm];
    }
  }
  cout << dp[N][W] << endl;
}


Measured memory_bytes: 6740
#include <stdio.h>

int main() {
    int n, i;
    scanf("%d", &n);
    if(n%2 == 0) {
        i=n/2;
        printf("%d\n", i);
    }
    if(n%2 == 1) printf("%d\n", n/2 +1);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	rep(i, n - 1) if(a[i] == a[i + 1]){
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define N 55
int X[N],Y[N],n,ret;
map<pair<int ,int > , int >mp;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&X[i],&Y[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)if(i!=j)
			mp[make_pair(X[i]-X[j],Y[i]-Y[j])]++,ret=max(ret,mp[make_pair(X[i]-X[j],Y[i]-Y[j])]);
	printf("%d\n",n-ret);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

 typedef struct{
    char c;
    int value;
  }Card;

void BubbleSort(Card *,int);
void SelectionSort(Card *,int);
void swap(int *,int *);
void swapc(char *,char *);
int isStable(Card[], Card[],int);

int main(){

  int i,j,n,flag=1;
  
scanf("%d",&n);

 Card *card,*card2,*card3;
 
 card = malloc(sizeof(Card)*n);
 card2 = malloc(sizeof(Card)*n);
 card3 = malloc(sizeof(Card)*n);
 
 for(i=0;i<n;i++){

   scanf(" %c",&card[i].c);
   scanf("%d",&card[i].value);
   card2[i].value=card[i].value;
   card2[i].c=card[i].c;
   card3[i].value=card[i].value;
   card3[i].c=card[i].c;

   //printf("%c%d\n",card[i].c,card[i].value);
 }

 
 
 BubbleSort(card,n);
  
 // for(i=0;i<n-1;i++)printf("%c%d ",card2[i].c,card2[i].value);
 // printf("%c%d\n",card2[i].c,card2[i].value);

 if(isStable(card3,card,n)==1)printf("Stable\n");
 else printf("Not stable\n");
 
 SelectionSort(card2,n);
 
 // for(i=0;i<n-1;i++)printf("%c%d ",card[i].c,card[i].value);
 //printf("%c%d\n",card[i].c,card[i].value);
if(isStable(card3,card2,n)==1)printf("Stable\n");
 else printf("Not stable\n");
 
 free(card);
 free(card2);
 free(card3);
 return 0;
}

void swap(int *a,int *b){

  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;

}


void BubbleSort(Card c[],int n){

  int i,k,flag=1;
  
while(flag==1){
    flag=0;

    for(i=n-1;i>0;i--){

      if(c[i].value < c[i-1].value){
	swap(&c[i].value,&c[i-1].value);
	swapc(&c[i].c,&c[i-1].c);
	flag = 1;
      }
      
     
    }

 }
   for(k=0;k<n-1;k++)printf("%c%d ",c[k].c,c[k].value);
      printf("%c%d\n",c[k].c,c[k].value);

      
}


void SelectionSort(Card c[],int n){

  int i,j,k,min;
  
for(i=0;i<n;i++){
    min = i;
    for(j=i;j<n;j++)if(c[j].value < c[min].value)min = j;

    if(c[i].value!=c[min].value){
      swap(&c[i].value,&c[min].value);
      swapc(&c[i].c,&c[min].c);
    }
    
  }
for(k=0;k<n-1;k++)printf("%c%d ",c[k].c,c[k].value);
    printf("%c%d\n",c[k].c,c[k].value);
      
}

void swapc(char *a,char *b){

  char tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;

}

int isStable(Card in[], Card out[],int n){

  int i,j,a,b;

  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(a=0;a<n;a++){
	for(b=a+1;b<n;b++){
	  if(in[i].value==in[j].value && in[i].c==out[b].c && in[i].value==out[b].value && in[j].value==out[a].value && in[j].c==out[a].c)return -1;
	}

      }

    }

  }
  return 1;
}



Measured memory_bytes: 2096
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

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

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

	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

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

    vector<int> a(n);

    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=n-1;i>=0;i--) {
        if(i == 0) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
}


Measured memory_bytes: 3084
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            foreach (var n in Enumerable.Range(0, 11))
            {
                if (N <= n * 1000)
                {
                    Console.WriteLine(n * 1000 - N);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 28304
#include<bits/stdc++.h>
#define int long long

using namespace std;

bool gr[2000][2000] = {};
int dp[2001][2001][2] = {};

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

    char c;
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> c, gr[i][j] = (c == '.');

    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
        {
            if (j == 0)
                dp[i][j][0] = gr[i][j];
            else
                if (gr[i][j])
                    dp[i][j][0] = dp[i][j - 1][0] + 1;
                else
                    dp[i][j][0] = 0;
        }
    for (int i = 0; i < h; i++)
        for (int j = w - 2; j >= 0; j--)
        {
            if (gr[i][j])
                dp[i][j][0] = max(dp[i][j][0], dp[i][j + 1][0]);
            else
                dp[i][j][0] = 0;
        }

    for (int i = 0; i < w; i++)
        for (int j = 0; j < h; j++)
        {
            if (j == 0)
                dp[j][i][1] = gr[j][i];
            else
                if (gr[j][i])
                    dp[j][i][1] = dp[j - 1][i][1] + 1;
                else
                    dp[j][i][1] = 0;
        }
    for (int i = 0; i < w; i++)
        for (int j = h - 2; j >= 0; j--)
        {
            if (gr[j][i])
                dp[j][i][1] = max(dp[j][i][1], dp[j + 1][i][1]);
            else
                dp[j][i][1] = 0;
        }

    int ans = 0;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            ans = max(ans, dp[i][j][0] + dp[i][j][1]);
    cout << max(ans - 1, 0ll) << '\n';

    return 0;
}


Measured memory_bytes: 66688
#include <iostream>

int main()
{
    int n;
    while(1){
        std::cin >> n;
        if(n == 0){
            break;
        }
        int score[n];
        int sum = 0;
        int max = 0;
        int min = 1000;
        for(int i = 0; i < n; i++){
            std::cin >> score[i];
            if(max < score[i]){
                max = score[i];
            }
            if(min > score[i]){
                min = score[i];
            }
            sum += score[i];
        }
        int average;
        average = (sum - max - min) / (n - 2);
        std::cout << average << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vl s(n+1),t(m+1);
	rep(i,n)cin>>s[i];
	rep(i,m)cin>>t[i];
	vvl dp(n+1,vl(m+1));
	rep(i,n+1)rep(j,m+1)if(i==0||j==0)dp[i][j]=1;
	rep(i,n)rep(j,m){
		dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j];
		if(s[i]!=t[j])dp[i+1][j+1]+=MOD-dp[i][j];
		dp[i+1][j+1]%=MOD;
	}
	cout<<dp[n][m]<<endl;
}


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

int main() {
    long long N;
    cin >> N;
    string res = "";
    while (N) {
        --N;
        res += (char)('a' + (N % 26));
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d,e=0;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    while(1){
        c-=b;
        if(c<=0){
            e=0;
            break;
        }
        a-=d;
        if(a<=0){
            e=1;
            break;
        }
    }
    if(e==0)printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 3824
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a, b, c, d, e;
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			d = sc.nextInt();
			e = sc.nextInt();
			if(a+b+c+d+e==0)
				break;
			int na, nb, nc;
			na = sc.nextInt();
			nb = sc.nextInt();
			nc = sc.nextInt();

			int res;
			res = 1000000100;
			for(int i = 0; i <= na + nb + nc; i++) {
				if(i < nc) {
					if(i < d)
						res = Math.min(res, Math.min(i * c, d * e) + c * (nc-i) + b * nb + a * na);
					else
						res = Math.min(res, Math.min(i * c, i * e) + c * (nc-i) + b * nb + a * na);
				}
				else if(i < nc + nb) {
					if(i < d)
						res = Math.min(res, Math.min(nc * c + (i-nc) * b, d * e) + b * (nb -i+nc) + a * na);
					else
						res = Math.min(res, Math.min(nc * c + (i-nc) * b, i * e) + b * (nb -i+nc) + a * na);
				}
				else {
					if(i < d)
						res = Math.min(res, Math.min(nc * c + nb * b + (i-nc-nb) * a, d * e) + a * (na-i+nb+nc));
					else
						res = Math.min(res, Math.min(nc * c + nb * b + (i-nc-nb) * a, i * e) + a * (na-i+nb+nc));
				}
			}
			System.out.println(res);
		}
	}
}

Measured memory_bytes: 29720
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int N, ptr, res;
  cin >> N;
  vector<int> paper(N,0);
  for(int i = 0; i < N; ++i){ cin >> paper[i];}
  sort(paper.begin(), paper.end());
  while(ptr < N){
    int cc = paper[ptr], f = 0;
    while(ptr < N && paper[ptr] == cc) f++, ptr++;
    res += f % 2;
  }
  cout << res << endl;
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#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())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(string S){
	if (SZ(S) == 2) {
		cout << S << endl;
	} else {
		REP(i, SZ(S)) {
			cout << S[SZ(S) - i - 1];
		}
		cout << endl;
	}
}


int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k, --k;
  string s; cin >> s;
  s[k] += 32;
  cout << s << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        boolean result = true;
        for (int i = 0; i < 3; i++) {
            if (S.substring(i,i+1).equals(S.substring(i+1,i+2))) {
                result = false;
                break;
            }
        }
        if (result) {
            System.out.println("Good");
        } else {
            System.out.println("Bad");
        }

    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))  // xが範囲内か
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()  // 配列のサイズ
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;  // 確認したいとき
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))  // 切り上げたいとき
#define newline puts("")
#define v(T) vector<T>  // Tはどんな型でもいい
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;  // ******
typedef vector<vi> vvi;
typedef vector<ll> vl;  // ******
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}  // vi a(n); cin>>a;
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}  // 
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}  // cout<<a;  aの中身全部出す
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame1 { puts("-1"); return 0;}
#define dame0 { puts("0"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define out cout << ans << endl;
//mins(ans,now);  ansに最小値が入る
//if(max(ans,now)) ansが小さければ更新して実行。cnt++とか。
//ll sum = suma(a);  aの累積和
//int vec[3][4];

int main() {
    int a,b,c,x,y; cin>>a>>b>>c>>x>>y;
    ll ans = LINF;
    int z = 2*max(x,y);
    for(int i=0; i<=z; i=i+2){
        int x1 = x-i/2; int y1 = y-i/2;
        if(x1 < 0) x1 = 0;
        if(y1 < 0) y1 = 0;
        ll sum = x1*a + y1*b + i*c;
        mins(ans,sum);
    }
    out;
}

/*
g++ a.cpp
./a.out

oj d
oj t

debug:ctrl+shift+B+./problem.exe
problem.in+f5

*/


Measured memory_bytes: 3612
fun main(args:Array<String>) {
    val (r, c) = readLine()!!.split(" ").map { it.toInt() }
    var map = (1..r).map { readLine()!! }.filter { a-> !a.all { it == '.' } }
    map = (0 until c).map {idx-> map.map { it[idx] }.joinToString("") }.filter { a -> !a.all { it == '.' } }
    map = (0 until map[0].length).map { idx -> map.map { it[idx] }.joinToString("") }
    map.forEach{ println(it)}
}

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

int main() {
	string str;
	cin >> str;
	for(int i=0; i<3; i++){
		if(str.at(i) == '1'){
			cout << 9;
		}else if(str.at(i) == '9'){
			cout << 1;
		}else{
			cout << str.at(i);
		}
	}
	cout << endl;
}



Measured memory_bytes: 256
pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let n: usize = rd.get();
    let xy: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let x: i64 = rd.get();
            let y: i64 = rd.get();
            (x, y)
        })
        .collect();
    let pts = vec![
        xy.iter()
            .max_by(|(x1, y1), (x2, y2)| (-x1 - y1).cmp(&(-x2 - y2)))
            .unwrap(),
        xy.iter()
            .max_by(|(x1, y1), (x2, y2)| (x1 + y1).cmp(&(x2 + y2)))
            .unwrap(),
        xy.iter()
            .max_by(|(x1, y1), (x2, y2)| (x1 - y1).cmp(&(x2 - y2)))
            .unwrap(),
        xy.iter()
            .max_by(|(x1, y1), (x2, y2)| (-x1 + y1).cmp(&(-x2 + y2)))
            .unwrap(),
    ];
    let mut ans = 0;
    for (x, y) in &xy {
        for (xx, yy) in &pts {
            ans = std::cmp::max(ans, (x - xx).abs() + (y - yy).abs());
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 5172
#!python3

from time import perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(26)]
    S = [[next(it) for i in range(26)] for i in range(D)]
    L = [[-1]] * 26
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    score = 0
    for i in range(D):
        score += S[i][0]
    L[0] = [i for i in range(-1, D)]

    x = (1+D)*D//2
    for i in range(1, 26):
        score -= C[i] * x

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, 26)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int k;
    cin>>k;
    string s,t;
    cin>>s;
    if(s.size()<=k)cout<<s<<endl;
    else{
        rep(i,0,k){
            t.push_back(s.at(i));
        }
        t+="...";
        cout<<t<<endl;
    }
    
return 0;
}

Measured memory_bytes: 3640
def pre_combi1(n, p):
    fact = [1]*(n+1)  # fact[n] = (n! mod p)
    factinv = [1]*(n+1)  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0]*(n+1)  # factinv 計算用
    inv[1] = 1
    # 前処理
    for i in range(2, n + 1):
        fact[i]= fact[i-1] * i % p
        inv[i]= -inv[p % i] * (p // i) % p
        factinv[i]= factinv[i-1] * inv[i] % p
    return fact, factinv

def combi1(n, r, p, fact, factinv):
    if r < 0 or n < r:
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p

import sys
x,y=map(int,input().split())
if (x+y)%3 > 0:
  print(0)
  sys.exit()
n=(x+y)//3
r=x-n
f,inv=pre_combi1(n,1000000007)
print(combi1(n,r,1000000007,f,inv))

Measured memory_bytes: 82036
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  import scala.io.StdIn._


  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val direction = readLine.trim.map(_ == 'R').toArray
  val costs = readLine.trim.split(' ').map(_.toInt)
  val relation = Array.tabulate(m){_ ⇒
    val Array(s, t, b) = readLine.trim.split(' ').map(_.toInt)
    if (s < t) (s, t, b) else (t, s, b)
  }
  println(
    calMinCut(direction, costs, relation)
  )

  def calMinCut(direction: Array[Boolean], costs: Array[Int], relations: Array[(Int, Int, Int)]): Long = {
    val source = 0
    val drain = direction.length + 1
    val nodes = Array.tabulate(direction.length + 2){_ ⇒ ArrayBuffer[Edge]()}
    for (i ← direction.indices){
      if (direction(i)){
        nodes(i + 1).append(Edge(drain, nodes(drain).length, costs(i)))
        nodes(drain).append(Edge(i + 1, 0, 0))
      }else {
        nodes(i + 1).append(Edge(source, nodes(source).length, 0))
        nodes(source).append(Edge(i + 1, 0, costs(i)))
      }
    }
    for ((s, t, b) ← relations){
      nodes(t).append(Edge(s, nodes(s).length, b))
      nodes(s).append(Edge(t, nodes(t).length - 1, 0))
    }
    calMinCut(nodes, source, drain)
  }
  def calMinCut(nodes: Array[ArrayBuffer[Edge]], source: Int, drain: Int): Long = {
    val depth = Array.tabulate(nodes.length){_ ⇒ 0}
    val searching = Array.tabulate(nodes.length){_ ⇒ 0}
    val queue = mutable.Queue[Int]()
    def bfs(): Unit ={
      queue.clear()
      queue.enqueue(source)
      depth.indices.foreach(i ⇒ depth(i) = -1)
      depth(source) = 0
      while (queue.nonEmpty && queue.head != drain){
        val current = queue.dequeue()
        for (next ← nodes(current) if next.flow > 0 && depth(next.to) == -1){
          depth(next.to) = depth(current) + 1
          queue.enqueue(next.to)
        }
      }
    }
    def dfs(current: Int, minFlow: Long = Long.MaxValue): Long = {
      if (current == drain) minFlow
      else {
        var flow = 0L
        while(searching(current) < nodes(current).length && flow == 0) {
          val next = nodes(current)(searching(current))
          if (next.flow > 0 && depth(current) < depth(next.to)) {
            flow = dfs(next.to, math.min(minFlow, next.flow))
            if (flow != 0) {
              next.flow -= flow
              nodes(next.to)(next.pair).flow += flow
              searching(current) -= 1
            }
          }
          searching(current) += 1
        }
        flow
      }
    }
    var result = 0L
    var canFlow = true
    while(canFlow){
      bfs()
      searching.indices.foreach(i ⇒ searching(i) = 0)
      canFlow = false
      var r = dfs(source)
      while(r != 0){
        canFlow = true
        result += r
        r = dfs(source)
      }
    }
    result
  }
  case class Edge(to: Int, pair: Int, var flow: Long)

  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}



Measured memory_bytes: 46696
// https://atcoder.jp/contests/abc102/tasks/arc100_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, sum = 0;
    cin >> n;
    vector<int> v;

    for (int i = 0; i < n; i++) {
        cin >> m;
        v.push_back(m - i - 1);
    }
    sort(ALL(v));

    int mid = v[n / 2];
    for (int i = 0; i < n; i++) {
        sum += abs(v[i] - mid);
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    for (auto& V : graph) {
        sort(V.begin(), V.end());
    }

    long long res = 0;

    for (int i = 0; i < n; ++i) {
        auto& V = graph[i];
        auto it = lower_bound(V.begin(), V.end(), i);
        int p = it - V.begin();
        int pre = -1;
        for (int j = 0; j < p; ++j) {
            res += (V[j] - pre) * 1LL * (p - j) * 1LL * (n - i);
            // cout << i << " " << V[j] << " " << (p - j) << " " << V[j] - pre <<  endl;
            pre = V[j];
        }
    }

    long long total = 0;
    for (int i = 1; i <= n; ++i) {
        total += (n + 1 - i) * 1LL * i;
    }

    // cout << total << " " << n << " " << res << endl;
    res = total - res;

    cout << res << '\n';


    return 0;
}

Measured memory_bytes: 15028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n,q;
string s;
char t[220000],d[220000];
int check(int c){
    rep(i,q){
        if(t[i]==s[c]){
            if(d[i]=='L')c--;
            else c++;
        }
        if(c<0)return 1;
        if(c>=n)return 2;
    }
    return 0;
}
int main(){
    cin>>n>>q;
    cin>>s;
    rep(i,q)cin>>t[i]>>d[i];
    int l=-1,r=n;
    while(r-l>1){
        int c=(l+r)/2;
        if(check(c)==1)l=c;
        else r=c;
    }
    int l2=-1,r2=n;
    while(r2-l2>1){
        int c=(l2+r2)/2;
        if(check(c)==2)r2=c;
        else l2=c;
    }
    int ans=n-(l+1)-(n-r2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
const ll inf = 1e9;

int main(){
  ll N , K; cin >> N >> K;
  vector<ll> a(N); rep(i,N) cin >> a[i];
  vector<ll> s(N); vector<ll> t(N);
  rep(loop , K){
    if(a[0] == N and a[N - 1] == N) break;
    // update s and t
    rep(i,N){
      s[i] = max( (ll)0 , i - a[i]);
      t[i] = min(N , i + a[i] + 1);
    }
    SORT(s); SORT(t);
    ll cnt = 0;
    // update a
    rep(i,N){
      cnt += POSU(s, i) - POSL(s , i);
      cnt -= POSU(t, i) - POSL(t , i);
      a[i] = cnt;
    }
  }
  rep(i,N) cout << a[i] << " ";
  cout << endl;
}


Measured memory_bytes: 8016
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int a,b;
    cin >> a >> b;
    if(max(a,b) >= 0 && min(a,b) <= 0) cout << "Zero\n";
    else if(a > 0 && b > 0) cout << "Positive\n";
    else if(a == b) cout << "Positive\n";
    else if(abs(a - b) % 2 == 0) cout << "Negative\n";
    else cout << "Positive\n";
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
hand = []
for _ in range(m):
    b, c = map(int, input().split())
    hand.append((b, c))
hand.sort(key=lambda x: x[1], reverse=True)

i = 0
lena = len(a)
flag = False
for h in hand:
    for j in range(h[0]):
        if i >= lena:
            flag = True
            break
        if a[i] >= h[1]:
            flag = True
            break
        else:
            a[i] = h[1]
            i += 1
    if flag:
        break

print(sum(a))


Measured memory_bytes: 22440
#include<stdio.h>
#include<string.h>
int main(){
    int len;
    char str1[100000];
    char str2[26]={"abcdefghijklmnopqrstuvwxyz"};
    scanf("%s",str1);
    len=strlen(str1);
    for(int i=0;i<len;i++){
        for(int j=0;j<26;j++){
            if(str1[i]==str2[j]){
                str2[j]='0';
            }
        }
    }
    for(int k=0;k<26;k++){
        if(str2[k]!='0'){
            printf("%c",str2[k]);
            break;
        }else if(k==25){
            printf("None");
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll mod = 1000000007;
map<pair<ll,ll>,ll>dp;
ll cal(ll x,ll y){
    if(x < 0 or y < 0)return 0;
    if(dp[{x,y}]){
        return dp[{x,y}];
    }
    ll res = cal(x/2,y/2);
    if(x>=1 and y>=1)res+=cal((x-1)/2,(y-1)/2);
    if(x>=2)res+= cal((x-2)/2,y/2);
    return dp[{x,y}] = res%mod;
}
int main(){
    ll n;
    cin >> n;
    dp[{0,0}] = 1;
    cout << cal(n,n) << endl;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const hw1 = input.split('\n')[0].split(' ');
const hw2 = input.split('\n')[1].split(' ');

const h1 = hw1[0];
const w1 = hw1[1];
const h2 = hw2[0];
const w2 = hw2[1];

console.log(h1*w1 - (w1*h2 + h1*w2 - h2*w2));

Measured memory_bytes: 7500
import sys

input = sys.stdin.readline

def main():
    ans = 'No'
    A, B = map(int, input().split())
    S = input()
    if S[A] == '-' and list(S).count('-') == 1:
        ans = 'Yes'
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    
}
return 0;
}

Measured memory_bytes: 256