akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  vector<int> A;
  vector<ll> B;

  rep(i, n) {
    int a;
    cin >> a;

    A.push_back(a);
  }

  ll b_total = 0;

  rep(i, m) {
    int b;
    cin >> b;

    b_total += b;
    B.push_back(b_total);
  }

  ll total_a = 0;
  int max_books = 0;
  int bi = B.size() - 1;

  while (bi >= 0 && B[bi] > k - total_a) {
    bi--;
  }
  max_books = max(max_books, bi + 1);

  rep(ai, n) {
    total_a += A[ai];
    if (total_a > k) break;

    while (bi >= 0 && B[bi] > k - total_a) {
      bi--;
    }

    max_books = max(max_books, ai + 1 + bi + 1);
  }

  cout << max_books << endl;

  return 0;
}


Measured memory_bytes: 6048
N = int(input())
A = [[x-1 for x in list(map(int, input().split()))[::-1]] for _ in range(N)]

def can_match(i, A, next_set):
  if not A[i]:
    return
  j = A[i][-1]
  if A[j][-1] == i:
    if i < j:
      next_set.add((i,j))
    else:
      next_set.add((j,i))
      
next_set = set()
for i in range(N):
  can_match(i, A, next_set)
  
day = 0
battle = 0
while next_set:
  day += 1
  current_set, next_set = next_set.copy(), set()
  for match in current_set:
    battle += 1
    del A[match[0]][-1]
    can_match(match[0], A, next_set)
    del A[match[1]][-1]
    can_match(match[1], A, next_set)
    
if battle == N*(N-1)//2:
  print(day)
else:
  print(-1)

Measured memory_bytes: 35612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l,i;
    cin>>n>>l;
    vector<string> str(n);
    for(i=0;i<n;i++)
    {
        cin>>str[i];
    }

    sort(str.begin(),str.end());
    for(i=0;i<n;i++)
        cout<<str[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	int n, a;
	cin >> n;
	// 全て-100にした時のコスト、…、100の時のコストを格納
	vector<int> cost(201, 0);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		for (int j = 0; j <= 200; j++) {
			// 置き換えたい整数y
			int y = j - 100;
			cost[j] += (a - y) * (a - y);
		}
	}
	int ans = *min_element(cost.begin(), cost.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int op, duit=1000;
    int flag = 0;
    int c;
    scanf("%d", &op);

    if (op <= 1000){
        printf("%d",1000 - op);
    }
    else{
        while (flag == 0){
                duit+=1000;
                if (duit >= op){
                    c = duit - op;
                    printf("%d", c);
                    break;
                }
        }
    return 0;
    }



    return 0;
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

const ll maxk=20000;
bool dp[100][100][maxk+1];
ll h,w;
ll a[100][100];
ll b[100][100];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>h>>w;
  rep(i,h) rep(j,w) cin>>a[i][j];
  rep(i,h) rep(j,w) cin>>b[i][j];
  
  dp[0][0][0]=true;
  
  rep(i,h) rep(j,w){
    ll d=abs(a[i][j]-b[i][j]);
    ireps(ki,0,maxk){
      if(dp[i][j][ki]){
        dp[i+1][j][ki+d]=true;
        dp[i][j+1][ki+d]=true;
        dp[i+1][j][abs(ki-d)]=true;
        dp[i][j+1][abs(ki-d)]=true;
      }
    }
  }
  
  ireps(i,0,maxk){
    if(dp[h][w-1][i]!=0 || dp[h-1][w][i]!=0) {
      cout<<i<<endl;
      return 0;
    }
  }
  
}

Measured memory_bytes: 158720
from itertools import combinations, product
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

amount = 0
for a in range(1, K+1):
    for b in range(a, K+1):
        for c in range(b, K+1):
            count = gcd(a, b, c)
            if a == b and b == c:
                amount += count
            elif a == b or b == c:
                amount += count * 3
            else:
                amount += count * 6
print(amount)

Measured memory_bytes: 69656
package main

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

//const MaxBuf = 200100

var sc = bufio.NewScanner(os.Stdin)

//var buf []byte = make([]byte, MaxBuf)

func init() {
	sc.Split(bufio.ScanWords)
	//sc.Buffer(buf, MaxBuf)
}

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

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	var h int
	h, _ = readInt(), readInt()
	s := make([]string, h)
	for i := 0; i < h; i++ {
		s[i] = readString()
		fmt.Println(s[i])
		fmt.Println(s[i])
	}
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    int[] a = Stream.of(sc.nextLine().split("\\s")).mapToInt(Integer::parseInt).toArray();
    sc.close();
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        sum += a[i] * a[j];
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 26964
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[200020];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),cnt=0;
	long long ans=0;
	for(int i=1;i<n;++i)
	{
		if(s[i]=='B'&&s[i+1]=='C')ans+=cnt,++i;
		else if(s[i]=='A')++cnt;
		else cnt=0;
	}
	printf("%lld",ans);
	return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

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

#define MAXN 20000

ll dp[MAXN+10][256+10];

int add(int y,int diff){
    int ny = y+diff;
    if(ny<0) ny=0;
    if(ny>255) ny=255;
    return ny;
}

void solve(int N,int M){
    vector<int> c(M),x(N);
    rep(i,M) cin>>c[i];
    rep(i,N) cin>>x[i];

    rep(i,MAXN+10) rep(j,256) dp[i][j]=LINF;

    dp[0][128]=0;

    for(int i=0;i<N;i++){
        for(int j=0;j<256;j++){
            for(int k=0;k<M;k++){       // c[k]????????¨
                ll nx = add(j,c[k]);
                ll dif = x[i] - nx;
                dp[i+1][add(j,c[k])] = min(dp[i+1][add(j,c[k])],dp[i][j]+dif*dif);
            }
        }
    }

    ll ans = LINF;
    for(int i=0;i<256;i++){
        ans = min(ans,dp[N][i]);
    }



//    for(int i=0;i<256;i++){
//        cout << dp[N][i] << endl;
//    }

    cout << ans << endl;
}

int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0 and m==0) break;
        solve(n,m);
    }
}

Measured memory_bytes: 44736
'use strict'
function GCM(p,q){
  if(p===0||q===0)return Math.max(p,q);
  if(p===q)return p;
  else return GCM(p%q,q%p);
}

function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var N=input.shift();
  var candidates=[0];
  var values=[];
  var a=0;
  for(let i=0;i<N;i++){
    let b=GCM(a,input[i]);
    if(a>b)candidates.push(i);
    a=b;
  }
  for(let j=0;j<candidates.length;j++){
    let v=0;
    v=input.reduce(function(acum,cur,index){
      if(index===candidates[j])
        return acum;
      else
        return GCM(acum,cur);
    },0);
    values.push(v);
  }
  var ans=Math.max.apply(null,values);
  console.log(ans);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 26920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
ll A[N],dp[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>A[i];
    dp[1]=0,dp[2]=abs(A[2]-A[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(A[i]-A[i-1]),dp[i-2]+abs(A[i]-A[i-2]));
    }
    cout<<dp[n];


}


Measured memory_bytes: 5136
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

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


signed main(){

	int N, M;
	cin >> N >> M;
	int cnt[123456] = { 0 };

	rep(i, M){
		int a, b;
		cin >> a >> b;
		a--; b--;
		cnt[a]++; cnt[b]++;
	}
	rep(i, N){
		if (cnt[i] % 2 != 0){
			NO;
			return 0;
		}
	}
	YES;

	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll x = b - (b/c + b/d)+b/lcm(c,d);
    ll y = (a-1) - ((a-1)/c + (a-1)/d)+(a-1)/lcm(c,d);
    ll ans = x-y;
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
			v = v % int(math.Pow10(9)+7)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func main() {
	// Code for C - Reconciled?
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	var count int
	var flag int = 0
	if N == M {
		count = count + 2
	} else if int(math.Abs(float64(N-M))) == 1 {
		count++
	} else {
		flag = 1
	}

	if flag == 0 {
		count *= factorial(N) % int(math.Pow10(9)+7)
		count *= factorial(M) % int(math.Pow10(9)+7)
		count = count % int(math.Pow10(9)+7)
		fmt.Println(count)
	} else {
		fmt.Println("0")
	}
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    string S;
    cin >> N >> K >> S;
    vector<ll> ruiseki{0};
    S.push_back(S.back() == '0' ? '1' : '0');
    ll count = 0;
    rep(i, N) {
        count++;
        if(S[i] != S[i + 1]) {
            ruiseki.push_back(ruiseki.back() + count);
            count = 0;
        }
    }
    ll ans = 0;
    rep(i, ruiseki.size()) {
        ll temp = ruiseki[min(2 * K + i + (S.front() == '0' ? (i % 2 == 0 ? 0 : 1) : (i % 2 != 0 ? 0 : 1)), (ll)ruiseki.size() - 1)] - ruiseki[max(0LL, i + (S.front() == '0' ? (i % 2 == 0 ? -1 : 0) : (i % 2 != 0 ? -1 : 0)))];
        ans = max(ans, temp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4472
N=int(input())
A=list(map(int, input().split()))
tmpmax=A[0]
ikeru=True
ok=True
for i in range(1,N):
  if tmpmax>A[i]:
    if tmpmax-1==A[i] and ok:
      tmpmax-=1
      ok=False
    else:
      ikeru=False
      break
  elif tmpmax<A[i]:
    ok=True
    tmpmax=A[i]

if ikeru:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 14396
h,w = input().split()
h = int(h)
w = int(w)
inp = []
count = 0
for i in range(h):
    tmp_input = list(input())
    if '#' in tmp_input:
        inp.append(tmp_input)
    else:
        count += 1
inp2 = list(map(list,zip(*inp)))
youso = []
for i in range(w):
    if "#" in inp2[i]:
        pass
    else:
        youso.append(i)
youso.reverse()
if len(youso) != 0:
    for i in range(len(youso)):
        for j in range(h-count):
            del inp[j][youso[i]]
else:
    pass
for i in range(len(inp)):
    mojiretu = ''.join(inp[i])
    print(mojiretu)


Measured memory_bytes: 3188
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var dishes = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).OrderByDescending(x => x.Sum()).ToArray();
        Console.WriteLine(dishes.Where((_, ind) => ind % 2 == 0).Sum(x => x[0]) - dishes.Where((_, ind) => ind % 2 == 1).Sum(x => x[1]));
    }
}


Measured memory_bytes: 28084
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long int ll;
using namespace std;

ll S(ll n){
	ll cnt=0;
	while(n>0){
		cnt+=n%10;
		n/=10;
	}
	return cnt;
}
int main(){
	ll k; cin >>k;
	ll cnt=0;
	ll digit=1;
	for(ll i=0;i<k;i++){
		cnt+=digit;
		cout << cnt << endl;
		if((double)cnt/S(cnt)<(double)(cnt+digit)/S(cnt+digit)&&(double)(cnt+digit)/S(cnt+digit)>(double)(cnt+digit*2)/S(cnt+digit*2)){
			digit*=10;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    vector<pair<string,int>> v(n);
    REP(i,n){
        cin>>v[i].first>>v[i].second;
    }
    string sleep_str;
    cin >> sleep_str;
    long long int result = 0;
    bool flag = false;
    REP(i,n){
        if(flag){
            result += v[i].second;
        } 
        if(v[i].first==sleep_str){
            flag = true;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    string o = "";
    string e = "esare";
    string e1 = "resare";
    string d1 = "remaerd";
    string d = "maerd";
    for(int i = 0; i < s.size(); i++){
        o += s[s.size() - i - 1];
        if(!d.find(o) && !d1.find(o) && !e1.find(o) && !e.find(o)){
            cout << "NO";
            return 0;
        }
        if(o == e || o == e1 || o == d || o == d1){
            o = "";
        }
    }
    if(o != ""){
        cout << "NO";
        return 0;
    }
    cout << "YES";
}


Measured memory_bytes: 576
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
E = defaultdict(list)
for i in range(M):
	u, v = rl()
	E[u-1].append(v-1)
S, T = rl()
S -= 1
T -= 1

dp = [[float('inf')]*3 for i in range(N)]

heap = []
heappush(heap, (0, S, 0))
while heap:
	d, n, r = heappop(heap)
	if n == T and r == 0:
		continue
	#if dp[n][r] != d:
	#	continue
	nr = (d+1)%3
	for m in E[n]:
		if dp[m][nr] > d+1:
			dp[m][nr] = d+1
			heappush(heap, (d+1, m, nr))

if dp[T][0] != float('inf'):
	print(dp[T][0]//3)
else:
	print(-1)


Measured memory_bytes: 116068
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

#define TST 0
int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    long n;
    cin >> n;
    vvl abc(n);
    F(i, 0, n){
        abc[i].resize(3);
        F(j, 0, 3){
        cin >> abc[i][j];
    }}
    // dp table has maximum happiness of i-1 th day
    // for convenience, allocate more memory than actually is
    vvl dp(n+2);
    F(i, 0, n+2){
        dp[i].resize(3);
        F(j, 0, 3) dp[i][j] = 0;
    }
    dp[0][0] = abc[0][0];
    dp[0][1] = abc[0][1];
    dp[0][2] = abc[0][2];
    F(i, 0, n-1){
        F(j, 0, 3){
            dp[i+1][j] = max(dp[i+1][j], dp[i][(j+1)%3] + abc[i+1][j]);
            dp[i+1][j] = max(dp[i+1][j], dp[i][(j+2)%3] + abc[i+1][j]);
        }
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;;

#if TST==1

#endif
}


Measured memory_bytes: 11136
import sys
input = sys.stdin.readline
from collections import defaultdict

S = input()[:-1]
cnt = defaultdict(int)
cnt[0] = 1
ans = 0
now = 0

for i in range(len(S)-1, -1, -1):
    now = (now+int(S[i])*pow(10, len(S)-1-i, 2019))%2019
    ans += cnt[now]
    cnt[now] += 1

print(ans)

Measured memory_bytes: 68972
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 int N;
 cin >> N;
 vector<int> A(N);
 int sum = 0;
 for(int i = 0; i < N; i++){
 cin >> A.at(i);
 sum += A.at(i);
 }
 sort(A.begin(),A.end());
 cout << sum - A.at(N-1) / 2;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[3];
        long ff = sc.nextLong();
        if(ff != 0){
            System.out.println(0);
            return;
        }
        long ans = 1;
        arr[0] = 1;
        for(int i = 0; i < n-1; i++){
            int fi = -1;
            long cnt = 0;
            long a = sc.nextLong();
            for(int j = 0; j < 3; j++){
                if(arr[j] == a){
                    cnt++;
                    if(fi == -1){
                        arr[j]++;
                        fi = j;
                    }
                }
            }
            //System.out.println(cnt);
            ans *= cnt;
            ans %= mod;
        }
        System.out.println((ans*3)%mod);
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 33888
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	vl v(n);
	REP(i, n)cin >> v[i];
	vl e(n + 1, 0), o(n + 1, 0);
	REP(i, n) {
		e[i + 1] += e[i];
		o[i + 1] += o[i];
		if (i & 1)o[i + 1] += v[i];
		else e[i + 1] += v[i];
	}
	vl p(n + 1, 0);
	RREP(i, n)p[i] = p[i + 1] + v[i];
	REP(aa, q) {
		int x;
		cin >> x;
		if (x >= v.back()) {
			if (n & 1)cout << e[n] << endl;
			else cout << o[n] << endl;
			continue;
		}
		if (x <= v.front()) {
			cout << p[n / 2] << endl;
			continue;
		}
		int l = -1, r = INF;
		while (r - l > 1) {
			int mid = (r + l) / 2;

			int a = lower_bound(ALL(v), x - mid) - v.begin();
			int b1 = lower_bound(ALL(v), x + mid) - v.begin();
			int b2 = upper_bound(ALL(v), x + mid) - v.begin();

			if (n - b1 - (b1 - a) > 1) {
				if (n - b2 - (b2 - a) > 1) {
					l = mid;
				}
				else r = mid;
			}
			else {
				
					r = mid;
				
			}
		}
		int a = lower_bound(ALL(v), x - r) - v.begin();
		int b1 = lower_bound(ALL(v), x + r) - v.begin();
		int b2 = upper_bound(ALL(v), x + r) - v.begin();
		if (n - b1 - (b1 - a) > 1) {
			if (n - b2 - (b2 - a) == 1) {


				ll ans = p[b2];
				if (a == 0) {
					cout << ans << endl;
				}
				else {
					a--;
					if (a & 1)ans += e[a];
					else ans += o[a];
					cout << ans << endl;
				}
			}
			else {
				//assert(n - b2 - (b2 - a) == 0);
				ll ans = p[b2];
				if (a & 1)ans += e[a];
				else ans += o[a];
				cout << ans << endl;
			}
		}
		else {
			if (n - b1 - (b1 - a) == 1) {
				ll ans = p[b1];
				if (a == 0) {
					cout << ans << endl;
				}
				else {
					a--;
					if (a & 1)ans += e[a];
					else ans += o[a];
					cout << ans << endl;
				}

			}
			else {
				assert(n - b1 - (b1 - a) == 0);
				ll ans = p[b1];
				if (a & 1)ans += e[a];
				else ans += o[a];
				cout << ans << endl;
			}
		}
	}
}

Measured memory_bytes: 4864
#include <iostream>
#include <sstream>
using namespace std;
main(){
	int a,r,x;
	string s;
	for(;getline(cin,s);cout<<(r>21?0:a&&r<12?r+10:r)<<endl){
		istringstream is(s);
		for(a=r=0;is>>x;r+=x>9?10:x)if(x==1)a=1;else if(!x)return 0;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <double, double>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << 0; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n;
    cout << (n + 1 >> 1);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n,k;cin>>n>>k;
	string s;cin>>s;

	if(n==1){
		cout<<0<<endl;
		return 0;
	}else if(n==2){
		cout<<1<<endl;
		return 0;
	}

	ll ans = 0;
	For(i,1,n) if(s[i]==s[i-1]) ans++;

	ll i = 1;
	while(i<n && k>0){
		while(i<n && s[i-1]==s[i]) i++;
		if(i>=n) break;

		ll j = i+1;
		while(j<n && s[j-1]==s[j]) j++;
		if(j>=n){
			ans++;
			k--;
			break;
		}else{
			ans+=2;
			k--;
			i = j+1;
		}

	}

	cout<<ans<<endl;





























	
}

Measured memory_bytes: 512
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

vector<set<ll>> S(20);
int lunlun(int n){
    if(n == 1){
        for(ll i = 1; i <= 9; i++) S[n].insert(i);
    }
    for(ll i : S[n-1]){

    }
    return S[n].size();
}

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

    queue<ll> que;
    for(int i = 1; i<= 9; i++){
        que.push(i);
    }

    while(1){
        ll i = que.front();
        que.pop();
        K--;
        if(K == 0){
            cout << i << endl;
            return 0;
        }

        ll last = i % 10;
        if(last != 0) que.push(i * 10 + last - 1);
        que.push(i * 10 + last);
        if(last != 9) que.push(i * 10 + last + 1);
    }
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()

int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	ll taka = max(a - k, (ll)0);
	k -= (a - taka);
	ll ao = max(b - k, (ll)0);
	cout << taka << " " << ao << endl;
	return(0);
}

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

int main()
{
	int n, x;
	cin >> n >> x;
	int min = 1000000;
	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		if (c < min)
			min = c;
		x -= c;
	}
	cout << n + x / min << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;

int main(){
    int K; cin >> K;
    ll ans = 0;
    for(int i=1; i<=K; ++i){
        for(int j=1; j<=K; ++j){
            for(int k=1; k<=K; ++k){
                ans += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
s=list()
t=list()
v=list()
last=[0]*26
D=int(input())
c=list(map(int,input().split()))
for i in range(D):
    s.append(list(map(int,input().split())))
for i in range(D):
    t.append(int(input()))
legacy=0
for i in range(D):
    minus=0
    v.append(legacy)
    v[i]+=s[i][t[i]-1]
    last[t[i]-1]=i+1
    for j in range(26):
        minus+=c[j]*(i+1-last[j])
    v[i]-=minus
    legacy=v[i]
for i in range(D):
    print(v[i])

Measured memory_bytes: 9524
n=int(input())
l=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=0
  for j in range(i,n-1):
    c,s,f=l[j]
    if ans<s:
      ans+=s-ans
    else:
      if ans%s!=0:
        if (ans%s)%f!=0:
          ans+=f-(ans%s)%f
    ans+=c
  print(ans)
print(0)

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  string s;
  cin >> s;

  if(s == "keyence") return cout << "YES\n", 0;

  rep(i, 0, s.size()) {
    rep(j, i + 1, s.size()) {
      string t = s.substr(0, i) + s.substr(j);
      if(t == "keyence") return cout << "YES\n", 0;
    }
  }
  cout << "NO\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char s[] = sc.next().toCharArray();
        char t[] = sc.next().toCharArray();
        int count = 0;
        for (int i = 0; i < 3; i++) {
            if (s[i] == t[i]) {
                count++;
            }
        }
        System.out.println(count);
        sc.close();
    }
}


Measured memory_bytes: 35548
#include <bits/stdc++.h>
using namespace std;
typedef                 long long ll;
typedef                 unsigned long long ull;
#define mkp             make_pair
#define pii             pair<int,int>
#define piii            pair<pii,int>
#define vi              vector<int>
#define PI              acos(-1)
#define all(v)          v.begin(),v.end()
#define mmset(a,val)    memset(a,val,sizeof(a))
#define sc(a)           scanf("%d",&a)
#define sc2(a,b)        scanf("%d%d",&a,&b)
#define sc3(a,b,c)      scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)    scanf("%d%d%d%d",&a,&b,&c,&d)
#define sc5(a,b,c,d,e)  scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define scll(a)         scanf("%I64d",&a)
#define scll2(a,b)      scanf("%lld%lld",&a,&b)
#define scll3(a,b,c)    scanf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)  scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define Pr(a)           printf("%d\n",a)
#define Prll(a)         printf("%lld\n",a)
#define pb(a)           push_back(a)
#define SZ              size()
#define tcs(t)          for(int tc=1;tc<=t;tc++)
#define INF             0x3f3f3f3f
#define hash_val        347
#define popcount        __builtin_popcount
#define MOD             1000000007
#define MX              105
int fx[]={-1,-1,0,1,1,1,0,-1};
int fy[]={0,1,1, 1,0,-1,-1,-1};
int Set(int n,int pos){return n=n|(1<<pos);}
int reset(int n,int pos){return n=n& ~ (1<<pos);}
bool check(int n,int pos){return (bool) (n& (1<<pos));}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);};
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);};
int dp[5][MX][10009],n;
int d[5][MX];
int calc(int x,int y,int amount)
{
    if(y==n&& x==2)
    {
        return  amount;
    }
    if(dp[x][y][amount]!=-1)return dp[x][y][amount];
    int f1=-1;
    if(y <n){
        f1=max(f1,calc(x,y+1,amount+d[x][y+1]));
    }
    if(x==1)
    f1=max(f1,calc(x+1,y,amount+d[x+1][y]));
    dp[x][y][amount]=f1;
    return dp[x][y][amount];
}
int main()
{
            #ifdef AINAN
                       freopen("input.txt","r",stdin);
             //    freopen("output.txt","w",stdout);
              #endif

                sc(n);
                for(int i=1;i<=2;i++)
                {
                    for(int j=1;j<=n;j++)
                        sc(d[i][j]);
                }
                mmset(dp,-1);
               Pr(calc(1,1,d[1][1]));

}


Measured memory_bytes: 20736
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, k;
    cin>>n>>k;
    vector<ll> a(n);
    ll m = 0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        m = max(m, a[i]);
    }

    ll g = a[0];
    for(ll i=1;i<n;++i){
        g = gcd(g, a[i]);
    }

    string ans = "IMPOSSIBLE";
    if(m < k){
        ans = "IMPOSSIBLE";
    }else if((k - m) % g == 0){
        ans = "POSSIBLE";
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)clim
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for(int i = (int)(n) - 1 - (int)(x); i >= 0; i--)

vector<int> A(10e6+1);

int main(void){
    // Your code here!
    int N;
    cin >> N;
    REP(i,1,N+1) {
        int h;
        cin >> h;
        A[i] = h;
    }
    ll count = 0;
    map<int,int> mp;
    REP(i,1,N+1){
        // こうすることでi==jのときを弾ける
        count += mp[i-A[i]];
        mp[i+A[i]]++;
    }
    // REP(i,1,N+1){
    //     int r = i-A[i];
    //     count += mp[r];
    // }

    // REP(i,1,N+1){
    //     if (i+A[i] > N) continue;
    //     REP(j,i+A[i],N+1){
    //         if(j-i == A[i]+A[j]) count++;
    //     }
    // }
    cout << count;
}


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

using ll = long long;

ll A, B;
void solve(){
    ll gcd = __gcd(A, B);
    bool prime = true;
    ll ans = 1;
    for(ll i = 2; i * i <= gcd; ++i){
        if(gcd % i != 0) continue;
        ans++;
        while(gcd % i == 0) gcd /= i;
    }
    if(gcd != 1) ans++;
    cout << ans;
}

int main(){
    cin >> A >> B;
    solve();
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
using namespace std;
//#define int long long
int cnt[300000];
vector <int> est[26];
signed main() {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		est[s[i] - 'a'].push_back(i);
	}
	int cntt = 0;
	set <char> sss;
	for (int i = s.size() - 1; i >= 0; --i) {
		char it = s[i];
		sss.insert(it);
		if (sss.size() == 26) {
			++cntt;
			sss.clear();
		}
		cnt[i] = cntt;
	}
	int len = cntt + 1;
	string ans = "";
	int cur = -1;
	for (int i = 0; i < len; ++i) {
		for (char c = 'a'; c <= 'z'; ++c) {
			int go = c - 'a';
			auto it = upper_bound(est[go].begin(), est[go].end(), cur);
			if (it == est[go].end()) {
				ans.push_back(c);
				break;
			}
			int new_cur = *it;
			int curr = cnt[new_cur + 1];
			if (curr < len - ans.size() - 1) {
				ans.push_back(c);
				cur = new_cur;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> a(n,vector<int>(m));
  vector<int> b(m);
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
      cin >> a.at(i).at(j);
    }
  }
  for(int i=0;i<m;++i){
    cin >> b.at(i);
  }
  vector<int> c(n,0);
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
      c.at(i) += a.at(i).at(j)*b.at(j);
    }
    cout << c.at(i) << endl;
  }
}




Measured memory_bytes: 3168
n,t = map(int,input().split())
time = [0 for i in range(3000)]
now = 0
ans = 0
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort(key=lambda x:x[1],reverse=True)
lis.sort(key=lambda x:x[0])
for i in range(n):
    for j in range(t-1,-1,-1):
        if lis[i][0] + j >= t:
            ans = max(ans,time[j]+lis[i][1])
        else:
            time[j+lis[i][0]] = max(time[j+lis[i][0]],time[j]+lis[i][1])
print(max(ans,max(time)))

Measured memory_bytes: 46568
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2

output:
3
"""

import sys
from collections import deque


def graph_bfs(source, target, parent):
    visited = [False] * vertices
    queue = deque()
    queue.append(source)
    visited[source] = True

    while queue:
        current = queue.popleft()
        for adj, cp in adj_table[current].items():
            if cp and not visited[adj]:
                queue.append(adj)
                visited[adj] = True
                parent[adj] = current

    return True if visited[target] else False


def graphFordFulkerson(source, sink):
    parent = [-1] * vertices
    max_flow = 0

    while graph_bfs(source, sink, parent):
        path_flow = float('inf')

        bk_1 = sink
        while bk_1 is not source:
            path_flow = min(path_flow, adj_table[parent[bk_1]][bk_1])
            bk_1 = parent[bk_1]

        max_flow += path_flow

        bk_2 = sink
        while bk_2 is not source:
            parent_bk_2 = parent[bk_2]
            assert parent_bk_2 != -1
            adj_table[parent_bk_2].setdefault(bk_2, 0)
            adj_table[bk_2].setdefault(parent_bk_2, 0)

            # print(bk_2, parent_bk_2, path_flow, bk_1, parent[bk_1], parent, adj_table)
            adj_table[parent_bk_2][bk_2] -= path_flow
            adj_table[bk_2][parent_bk_2] += path_flow
            bk_2 = parent[bk_2]

    return max_flow


def generate_adj_table(v_table):
    for each in v_table:
        source, target, cp = map(int, each)
        init_adj_table[source][target] = cp

    return init_adj_table


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    init_adj_table = [dict() for _ in range(vertices)]
    adj_table = generate_adj_table(v_info)
    ans = graphFordFulkerson(source=0, sink=vertices - 1)
    print(ans)

Measured memory_bytes: 8204
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    SORTR(a);
    int alice = 0;
    int bob   = 0;
    FOR(i, 0, N) {
        if (i % 2 == 0) {
            alice += a.at(i);
        } else {
            bob += a.at(i);
        }
    }
    cout << alice - bob << endl;
}


Measured memory_bytes: 3620
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math,sys
P = 1000000007
# def modpow(a,n,mod):
#     res = 1
#     while n > 0:
#         if n & 1:
#             res = res * a % mod
#         a = a * a % mod
#         n >>= 1
#     return res

N = int(sys.stdin.readline())
print((pow(10,N,P)-pow(9,N,P)-pow(9,N,P)+pow(8,N,P))%P)


Measured memory_bytes: 9076
# -*- coding: utf-8 -*-
    
################ DANGER ################
test = ""
#test = \
"""
3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0
ans 0
"""

"""
3
1
2 1
1
1 1
1
2 0
ans 2
"""

"""
2
1
2 0
1
1 0
ans 1
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################

n = int(input2())
a = [None] * (n+1)
for i in range(1, n+1):
    ai = int(input2())
    a[i] = [tuple(map(int, input2().split())) for i in range(ai)]
    

def bitsearch(bit, *, start=0):
    end = 2 ** bit
    len0 = len(format(end, "b"))
    return [format(i, "b").zfill(len0) for i in range(start, end)] 


cand = [0]
for b in bitsearch(n):
    lie, i = 0, 1
    while (not lie) and i < n+1:
        for c in a[i]:
            if int(b[i]) and c[1] ^ int(b[c[0]]):
                lie += 1            
        i += 1
        
    if not lie:
        cand.append(b.count("1"))
        
print(max(cand))
        

Measured memory_bytes: 5912