akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

vector<ll> divisor (ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) res.push_back(n / i);
        }
    }
    return res;
}

ll GetDigit(ll num)
{
    return std::to_string(num).length();
}

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

    vector<ll> v = divisor(n);

    ll _min = 100000;
    for (auto e : v)
    {
        ll temp = max(GetDigit(e), GetDigit(n / e));

        if (temp < _min)
        {
            _min = temp;
        }
    }

    cout << _min << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int i=0;
		for(;i<n;i++) a[i]=scan.nextInt();
		for(i--;0<i;i--){
			System.out.print(a[i]+" ");
		}
		System.out.println(a[0]);
		scan.close();
	}
}

Measured memory_bytes: 18984
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A; cin >> A;
  if (A<1200){ cout << "ABC" << endl;}
  if (A>1199 && A<2800) { cout << "ARC" << endl;}
  if (A>2799){ cout << "AGC" << endl;}
}




Measured memory_bytes: 256
counts = {chr(code): 0 for code in range(ord('a'), ord('z') + 1)}

words = []

while True:
     try:
         wordr = input()
     except EOFError:
         break
     word = wordr.lower()
     words.append(word)

for word in words:
    for letter in word:
        if letter in counts.keys():
            counts[letter] += 1

for letter, count in counts.items():
    print(letter,':', count)



Measured memory_bytes: 5576
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,C,K,T[MAX],ans,s,t;
int main()
{
	n=read();C=read();K=read();
	for(int i=1;i<=n;++i)T[i]=read();
	sort(&T[1],&T[n+1]);
	for(int i=1;i<=n;++i)
		if(!s)++ans,s=1,t=T[i];
		else
		{
			if(s==C)++ans,s=1,t=T[i];
			else
			{
				if(T[i]-t>K)++ans,s=1,t=T[i];
				else ++s;
			}
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,m):
        e = collections.defaultdict(list)
        for _ in range(m):
            u,v,d,c = LI()
            e[u].append((v,d,c))
            e[v].append((u,d,c))

        def search(s):
            d = collections.defaultdict(lambda: inf)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True

                for uv, ud, _ in e[u]:
                    if v[uv]:
                        continue
                    vd = k + ud
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            return d

        d = search(1)
        r = 0
        for i in range(2,n+1):
            t = inf
            for j,dd,c in e[i]:
                if d[i] - dd == d[j] and t > c:
                    t = c
            r += t
        return r

    while 1:
        n,m = LI()
        if n == 0 and m == 0:
            break
        rr.append(f(n,m))
        # print('rr', rr[-1])

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 16836
w=int(input())
n=int(input())

lis=[i+1 for i in range(w)]

for _ in range(n):
    a,b=map(int,input().split(","))
    a-=1
    b-=1
    x=lis[a]
    lis[a]=lis[b]
    lis[b]=x

for i in range(w):
    print(lis[i])
    

Measured memory_bytes: 6720
#include <stdio.h>

int main()
{
	int D, N, A, B;

	scanf("%d", &N);
	scanf("%d", &A);
	scanf("%d", &B);

	D = N * A;

	if (D < B) {
		printf("%d\n", D);
	}
	else {
		printf("%d\n", B);
	}

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}


Measured memory_bytes: 2048
S = input()
count = 0
l = [0] * 2019 #mod2019 は0~2018まで
l[0] = 1
mod = 2019
tmp = 0

for i in range(1, len(S) + 1):
    tmp = (tmp + int(S[len(S) - i]) * pow(10, i - 1, mod)) % mod
    #print(tmp)
    l[tmp] += 1

#print(l)
for j in range(2019):
    if l[j] >= 2:
        count += l[j] * (l[j] - 1) // 2

print(count)

Measured memory_bytes: 9216
n = int(input())
a = list(map(int, input().split()))
mod = [0]*n
check = 0
    
for ii in range(1000):
    for i in range(n):
        mod[i] = a[i] % 2
        check = check + mod[i]
        a[i] = a[i]/2
    if (check>=1):
        print(ii)
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;

  // NlogN + N 798 ms
  // vector<int> F(N + 1, 0);
  // for (ll i = 1; i <= N; i++) {
  //   ll j = 1;
  //   while (i * j <= N) {
  //     F.at(i * j)++;
  //     j++;
  //   }
  // }
  // for (ll i = 1; i <= N; i++) {
  //   ans += i * F.at(i);
  // }

  // NlogN 69 ms
  // for (ll i = 1; i <= N; i++) {
  //   ll j = 1;
  //   while (i * j <= N) {
  //     ans += i * j;
  //     j++;
  //   }
  // }

  // N
  for (ll i = 1; i <= N; i++) {
    ll n = (N / i);
    ans += i * n * (n + 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI=3.14159265358979323846;
ll gcd(ll x,ll y) {
    if(x%y==0) return y;
    else {
        return gcd(y,x%y);
    }
    
}

vector<pair<ll,ll>> prime_factorize(ll n) {
    vector <pair<ll, ll>> res;
    for(ll i=2;i*i<=n;++i) {
        if(n%i!=0) continue;
        ll num=0;
        while(n%i==0) {
            num+=1;
            n/=i;
        }
        res.push_back(make_pair(i,num));
    }
    if(n!=1) res.push_back(make_pair(n,1));
    return res;
}

int main() {
    ll a,b;
    cin >> a >> b;
    ll x=gcd(a,b);
    auto pf=prime_factorize(x);
    cout << pf.size()+1 << endl;
}
    


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

print(*a)
for i in range(1, n):
    v = a[i]
    while i-1 >= 0 and a[i-1]>v:
        a[i]=a[i-1]
        i -= 1
    a[i] = v
    print (*a)



Measured memory_bytes: 5984
N = int(input())
alp = lambda c: chr(c+96)
def num(L,key):
    if len(L) == N:
        ans = [alp(a) for a in L]
        print(''.join(ans))
    else:
        for k in range(1,key+1):
            l = L + [k]
            num(l,key)
        l = L + [key+1]
        num(l, key+1)

init =[1]
num(init,1)

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N ;
    vector<int> vec(N);

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

    int a = 1, count = 0;
    for (int i = 0; i < N; i++){
        a = vec.at(a-1);
        count++;
        if (a == 2){
            cout << count << endl;
            break;
        }
    }

    if (count == N)cout << -1 << endl;

}

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

using namespace std;

typedef long long ll;
const int N=1e5+10;
ll a[N];

int main()
{
    int n,q;

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

    while(cin>>n>>q)
    {
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }


        while(q--)
        {
            ll x;
            cin>>x;
            ll ans=0;
            ll sum=0;

            for(int l=0,r=0;l<n;l++)
            {
                while(r<n&&sum+a[r]<=x)
                {
                    sum+=a[r++];
                }
                if(sum<=x)
                {
                    ans+=r-l;
                }
                sum-=a[l];
            }
            cout<<ans<<endl;
        }
    }

    return 0;
}



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

#define int long long
#define double long double
#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 uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int M, K;
signed main() {
    cin >> M >> K;
    if (M == 1) {
        if (K == 0) { fin("0 0 1 1"); }
        else { fin(-1); }
    }
    if (bit(M) - 1 < K) { fin(-1); }
    cout << K << " ";
    rep(i, bit(M)) { if (i != K) { cout << i << " "; }}
    cout << K << " ";
    for (int i = bit(M) - 1; i >= 0; i--) { if (i != K) { cout << i << " "; }}
}

Measured memory_bytes: 1792
let bfs vs n =
  let d = Array.make n (-1) in
  let q = Queue.create () in
  d.(0) <- 0;
  Queue.add 0 q;
  while not (Queue.is_empty q) do
    let i = Queue.take q in
    let x = d.(i) + 1 in
    List.iter (fun v ->
      if d.(v-1) = (-1) then begin
        d.(v-1) <- x;
        Queue.add (v-1) q;
      end)
      vs.(i);
  done;
  d

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let vs = Array.make n [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> vs.(u-1) <- l
    | _ -> assert false
  done;
  bfs vs n |> Array.iteri (fun i e -> Printf.printf "%d %d\n" (i + 1) e)

Measured memory_bytes: 2324
<?php
$input = trim(fgets(STDIN));
list($x1, $y1, $x2, $y2) = explode(' ', $input);

$dx = $x2 - $x1;
$dy = $y2 - $y1;

$x3 = $x2 - $dy;
$y3 = $y2 + $dx;
$x4 = $x1 - $dy;
$y4 = $y1 + $dx;

echo "$x3 $y3 $x4 $y4";

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

int main(){
  double W,H;
  cin >> W >> H;
  
  int x,y;
  cin >> x >>y;
  
  cout << (W*H)/2 << endl;
  
  if(x==W/2 && y==H/2){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int P[20];
int main(){
  int i, res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(P[Lj4PdHRW]);
    }
  }
  for(i=1;i<N-1;i++){
    if(P[i-1] < P[i]  &&  P[i] < P[i+1]){
      res++;
    }
    if(P[i-1] > P[i]  &&  P[i] > P[i+1]){
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190630-1

// --- original code ---
// int N, P[20];
// {
//   int i, res = 0;
//   rd(N,P(N));
//   rep(i,1,N-1){
//     if(P[i-1] < P[i] < P[i+1]) res++;
//     if(P[i-1] > P[i] > P[i+1]) res++;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
      	int factorAmount = scanner.nextInt();
      	long[] factors = new long[factorAmount];
      	for(int i = 0; i < factorAmount; i++) {
      		factors[i] = scanner.nextLong(); 
      	}
      	
      		System.out.print(Calculate(factors));
	}
	
	private static BigInteger Calculate(long[] numbers) {
		for(int i = 0; i < numbers.length; i++) 
      		if(numbers[i] == 0l)
      			return  BigInteger.ZERO;
      	
      	BigInteger result = BigInteger.ONE;
      	BigInteger limit = BigInteger.valueOf((long)Math.pow(10, 18));
      	for(int i = 0; i < numbers.length; i++) {
      		result = result.multiply(BigInteger.valueOf(numbers[i]));
     		if (result.min(limit) == limit && !result.equals(limit))
      		    return BigInteger.valueOf(-1); 
     		
      	}
      	
		return result;
	}
}


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

typedef long long ll;
typedef vector<int> vi;

#define PB push_back
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    optimize();
    string s;
    cin>>s;
    if(s[s.size()-1]=='s')
        s+="es";
    else
        s+="s";
    cout<<s<<endl;
    return 0;
}


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

#define fastio {\
    ios::sync_with_stdio(0);\
    cin.tie(0);\
}

#define file {\
    freopen("io\\in.txt", "r", stdin);\
    freopen("io\\out.txt", "w", stdout);\
    freopen("io\\err.txt", "w", stderr);\
}

#ifdef LOCAL
#define debug(args...) {\
    string _s(#args);\
    replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s);\
    istream_iterator<string> _it(_ss);\
    debug1(_it, args);\
}

#pragma GCC diagnostic ignored "-Wunused-parameter"
void debug1(istream_iterator<string> it) {
    cerr << endl;
}
#pragma GCC diagnostic pop

template<class T, class... Args>
void debug1(istream_iterator<string> it, T a, Args... args) {
    cerr << '>' << *it << " = " << a << "; ";
    debug1(++it, args...);
}
#else
#define debug(args...)
#define cerr if (false) cerr
#endif

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < n; i++)
#define dotc()      int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));

signed main() {
    fastio;
#ifdef LOCAL
    file;
#endif

    int n, m;
    cin >> n >> m;
    vi a(n);
    while (m--) {
        int s, c;
        cin >> s >> c;
        s--;
        if (s == 0 && c == 0 && n != 1 || a[s] && a[s] != c) {
            a.resize(1);
            a[0] = -1;
            break;
        }

        a[s] = c;
    }

    if (n != 1 && a[0] == 0) a[0] = 1;
    rep(i, sz(a)) cout << a[i];

    return 0;
}


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


/********************************************************************/
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)











map<long long, long long> factorize(long long n) {
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


/********************************************************************/
int main() {
	FAST();
	ll n;
	cin >> n;
	auto t = factorize(n);
	vi pps;
	ll ans = 0;
	for (auto it : t) {
		// cout << it.first << ' ' << it.second << endl;
		pps.pb(it.second);
	}
	for (auto pp : pps) {
		// cout << pp << ' ';
		ll ind = 1;
		while (ind * (ind + 1) / 2 < pp)
			ind++;
		if (ind * (ind + 1 ) / 2 > pp)
			ind--;
		// cout << ind << endl;
		ans += ind;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 3656
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    long long N, M;
    cin >> N >> M;

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

    vector<long long> B(N + 1, 0);
    for (int i = 0; i < N; i++) B[i + 1] = B[i] + A[i];
    for (int i = 0; i < N + 1; i++) B[i] %= M;

    long long ans = 0;
    map<long long, long long> MM;
    for (int i = 0; i < N + 1; i++) {
        ans += MM[B[i]];
        MM[B[i]]++;
    }

    cout << ans << endl;

    return 0;
}




















































































Measured memory_bytes: 5760
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n, wt; readV(n, wt);
  int[] w, v; readC(n, w, v);

  auto u = w.dup; u[] -= w[0];

  auto dp = new int[][][](n+1, n+1, n*3+1);
  foreach (i; 0..n)
    foreach (j; 0..n+1)
      dp[i][j][] = -1;
  dp[0][0][0] = 0;

  foreach (i; 0..n)
    foreach (j; 0..n+1)
      foreach (k; 0..n*3+1) {
        dp[i+1][j][k] = dp[i][j][k];
        if (j >= 1 && k >= u[i] && dp[i][j-1][k-u[i]] >= 0)
          dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j-1][k-u[i]]+v[i]);
      }

  auto ans = 0;
  foreach (j; 0..n+1)
    foreach (k; 0..n*3+1)
      if (j.to!long*w[0]+k <= wt)
        ans = max(ans, dp[n][j][k]);

  writeln(ans);
}


Measured memory_bytes: 23420
import static java.util.stream.IntStream.range;
import java.util.*;

public class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		String t=s.next();
		System.out.println(t.length()%2==0&&range(0,t.length()).allMatch(i->t.charAt(i)==(i%2==0?'h':'i'))
				?"Yes":"No");
	}
}


Measured memory_bytes: 27092
#include<stdio.h>

int main(void){
  int a[5];
  int k;
  int m;


  for(m = 0; m <= 4; m++){

    scanf("%d",&a[m]);

  }

  scanf("%d",&k);

  int i;
  int hantei = 0;
  for(i = 0; i < 4; i++){

    if( (a[4]-a[i]) > k ){
      hantei ++;
    }

  }


  for(i = 0; i < 3; i++){

    if( (a[3]-a[i]) > k ){
        hantei ++;
      }

    }

  for(i = 0; i < 2; i++){

      if( (a[2]-a[i]) > k ){
          hantei ++;
        }

      }

    if( (a[1]-a[0]) > k ){
        hantei ++;
          }


  if(hantei == 0){
    printf("Yay!");
  }else{
    printf(":(");
  }


  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      string s;
      string t;
      cin >> s;
      cin >> t;
      lld a, b;
      cin >> a;
      cin >> b;
      string u;
      cin >> u;
      if (u == s)
      	a-=1;
      else
      	b-=1;
      cout << a << " " << b << "\n";
      return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  string A, B;
  cin >> A >> B;

  if (A.size() > B.size()) cout << "GREATER" << endl;
  else if(A.size() < B.size()) cout << "LESS" << endl;
  else {
    rep(i, A.size()) {
      if (A[i] > B[i]) {
        cout << "GREATER" << endl;
        return 0;
      } else if (A[i] < B[i]) {
        cout << "LESS" << endl;
        return 0;
      }
    }

    cout << "EQUAL" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
in_list = input().split(' ')
N = int(in_list[0])
A = int(in_list[1])
B = int(in_list[2])

count = 0
for i in range(N+1):
    if i == 10000:
        i_4 = 1
        res_i = 0
    else:
        i_4 = 0
        res_i = i

    i_3 = int(res_i/1000)
    if i_3 != 0:
        res_i = res_i - i_3*1000
    
    i_2 = int(res_i/100)
    if i_2 != 0:
        res_i = res_i - i_2*100
    
    i_1 = int(res_i/10)
    if i_1 != 0:
        res_i = res_i - i_1*10
    
    i_0 = res_i
    i_sum = i_4 + i_3 + i_2 + i_1 + i_0
    # print('i_sum：', i_sum)
    # print(i_4, i_3, i_2, i_1, i_0)

    if i_sum >= A and i_sum <= B:
        count += i
        # print('clear i_sum：', i_sum)
        # print('clear', i_4, i_3, i_2, i_1, i_0)

print(count)

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

using namespace std;

typedef long long ll;

#define MAX (ll)1e6+1    //nCrのnの最大値+1

ll fac[MAX], inv[MAX], finv[MAX];

void COMinit(ll mod) {
    fac[0] = 1, finv[0] = 1;
    fac[1] = 1, inv[1] = 1, finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - (inv[mod % i] * (mod/i) % mod) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(ll n, ll k, ll mod) {
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * finv[k] % mod * finv[n-k] % mod;
}

ll dfs(int k, vector<vector<int> > &G, int s, int p, ll mod) {
    ll ans = 1, cnt = 0;
    for (auto u: G[s]) {
        if (u == p)
            continue;
        cnt++;
    }
    ll l = k-1-((p >= 0) ? 1 : 0);
    if (l < cnt)
        return 0;
        
    ans *= fac[l] * finv[l-cnt] % mod;
    ans %= mod;
    for (auto u: G[s]) {
        if (u == p)
            continue;
        ans = ans * dfs(k, G, u, s, mod) % mod;
    }
    return ans;
}

int main() {
    ll n, k, mod = 1e9+7;    cin >> n >> k;

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

    vector<vector<int> > G(n);
    for (int i = 0; i < n-1; i++) {
        int a, b;   cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    COMinit(mod);

    cout << k * dfs(k, G, 0, -1, mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 38004
N=int(input())
A=list(map(int,input().split()))
dp=[[0]*2 for _ in range(N+1)]
dp[0][1]=-float("inf")
for i in range(N):
  dp[i+1][0]=max(dp[i][0]+A[i],dp[i][1]-A[i]) 
  dp[i+1][1]=max(dp[i][0]-A[i],dp[i][1]+A[i])
print(dp[-1][0])

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

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
const ll mod = 1000000007;

int main() {
  ll N;
  cin >> N;
  vi A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  vi cnt(60);
  for (auto i : A) {
    for (ll j = 0; j < 60; j++) {
      if ((i >> j) % 2) cnt[j]++;
    }
  }
  ll ans = 0;
  for (ll i = 0; i < 60; i++) {
    ll x = cnt[i];
    x = cnt[i] * (N - cnt[i]) % mod;
    for (ll j = 0; j < i; j++) {
      x = x * 2 % mod;
    }
    ans = (ans + x) % mod;
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 100001
#define int ll
int N;
int A[maxn],B[maxn];
unordered_map <int,int> p;

int num;
int fl(int x){
	if (p[x] == x) return x;
	return p[x] = fl(p[x]);
}

void join(int a,int b){
	if (fl(a) != fl(b)) num--;
	p[fl(a)] = fl(b);
}

int32_t main(){
	fast;
	
	cin>>N;
	
	int x = 0;
	
	multiset <int> st;
	unordered_set <int> st2;
	
	FOR(i,0,N-1){
		cin>>A[i];
		st.insert(A[i]);
		x ^= A[i];
	}
	
	
	
	st.insert(x);
	st2.insert(x);
	
	
	FOR(i,0,N-1){
		cin>>B[i];
		if (A[i] != B[i]) st2.insert(B[i]), st2.insert(A[i]);
		if (st.find(B[i]) == st.end()){
			cout<<"-1";
			return 0;
		}else{
			st.erase(st.find(B[i]));
		}
	}
	
	num = st2.size();
	
	
	aFOR(i,st2) p[i] = i;
	
	int ans = 0;
	FOR(i,0,N-1){
		if (A[i] != B[i]){
			join(A[i],B[i]);
			ans++;
		}
	}
	
	cout<<ans + num - 1;


	
}



Measured memory_bytes: 13220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    int M=max({A,B,C});
    int X=3*M-A-B-C;
    if(X%2==0) cout<<X/2<<endl;
    else cout<<(X+3)/2<<endl;
}

Measured memory_bytes: 256
n = int(input())
l = [int(x) for x in input().split()]
m = sum(l) / n
s = 0
sp = 0

if sum(l) % n == 0:
    now = sum(l) // n

    for x in l:
        s += (now - x) * (now - x)

    print(s)
    
else:
    now = sum(l) // n

    for x in l:
        s += (now - x) * (now - x)
        sp += (now - x + 1) * (now - x + 1)

    print(s if (s < sp) else sp)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		char head = str.charAt(0);
		int body = str.length() - 2;
		char leg = str.charAt(body+1);
		System.out.print(head);
		System.out.print(body);
		System.out.println(leg);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>

int main(void){
    int A, B, ans=0;
    std::cin >> A >> B;

    for (int i=A; i<=B; ++i){
        std::string S = std::to_string(i);
        if (S.at(0) == S.at(4) && S.at(1) == S.at(3)) ++ans;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
 
int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
 
  if ((x >= r) && ( x <= W-r) && (y >= r) && (y <= H-r))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
int cnt,mo,n,m,dp[4011][4011],x[200001],y[200001],xi[501],yi[501],a,b,tot,ans,jie[20001],ni[20001];
int mi(int aa,int bb)
{
	int s=1;
	while(bb!=0)
	{
		if((bb%2)==1)s=(1ll*s*aa)%mo;
		aa=(1ll*aa*aa)%mo;
		bb=bb/2;
	}
	return(s);
}
int main()
{
	scanf("%d",&n);
	tot=0;
	mo=1000000007;
	jie[0]=1;
	for(int i=1;i<=20000;i++)jie[i]=(1ll*jie[i-1]*i)%mo;
	ni[20000]=mi(jie[20000],mo-2);
	for(int i=20000;i>=1;i--) ni[i-1]=(1ll*ni[i]*i)%mo;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		if((a<=4000)&&(b<=4000))
		{
			tot++;
			x[tot]=a;
			y[tot]=b;
			ans=(ans-1ll*((1ll*jie[a+b+a+b]*ni[2*a])%mo)*ni[2*b])%mo;
			dp[a+2001][b+2001]++;
		}
		else
		{
			cnt++;
			xi[cnt]=a;
			yi[cnt]=b;
		}
	}
	for(int i=4001;i>=1;i--)
	for(int j=4001;j>=1;j--)
	{
		dp[i][j-1]=(dp[i][j-1]+dp[i][j])%mo;
		dp[i-1][j]=(dp[i-1][j]+dp[i][j])%mo;
	}
	for(int i=1;i<=tot;i++)ans=(ans+dp[2001-x[i]][2001-y[i]])%mo;
	ans=(1ll*ans*mi(2,mo-2))%mo;
	for(int i=1;i<=cnt;i++)
	for(int j=i+1;j<=cnt;j++)ans=(ans+1ll*((1ll*jie[xi[i]+yi[i]+xi[j]+yi[j]]*ni[xi[i]+xi[j]])%mo)*ni[yi[i]+yi[j]])%mo;
	for(int i=1;i<=cnt;i++)
	for(int j=1;j<=tot;j++)ans=(ans+1ll*((1ll*jie[xi[i]+yi[i]+x[j]+y[j]]*ni[xi[i]+x[j]])%mo)*ni[yi[i]+y[j]])%mo;
	ans=(ans+mo)%mo;
	printf("%d\n",ans);
} 

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

vector<vector<int>> g;
vector<ll> ans;

void dfs(int par, int crt)
{
  ans[crt] += ans[par];
  for (auto& nxt : g[crt])
    if (nxt != par)
      dfs(crt, nxt);
}

int main()
{
  int n, q;
  cin >> n >> q;
  g.resize(n);
  rep(i, n - 1)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans.resize(n);
  rep(i, q)
  {
    int p, x;
    cin >> p >> x;
    ans[p-1] += x;
  }
  for (auto& nxt : g[0])
    dfs(0, nxt);
  rep(i, n)
    cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 24320
lst=list(input())
unique=list(set(lst))
dct={}
is_yes=None
if len(unique)==2:
    len0=len([i for i, c in enumerate(lst) if c == unique[0]])
    len1=len([i for i, c in enumerate(lst) if c == unique[1]])
    if len0==2 & len1==2:
        is_yes=True
    else:
        is_yes=False
else:
    is_yes=False
if is_yes:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s = "", t;
    rep(i, 0, 4){
        cin >> t;
        s += t;
    }
    sort(s.begin(), s.end());
    if(s == "1479") cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC\n";
  } else if (r < 2800) {
    cout << "ARC\n";
  } else {
    cout << "AGC\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a = n % 1000;
    int b = (n - n%10) / 10;

    if(a%111 == 0 || b%111 == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n,a,b, = gets.chomp.split(" ").map(&:to_i)
ans = 0
1.upto(n) do |i|
    sum = 0
    array = i.to_s.split("").map(&:to_i)
    array.each do |num|
      sum += num
    end
    if (sum >= a)&&(sum <= b)
      ans += i
    end
end
puts ans


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


int main() {
  int n; cin >> n;
  long long a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a,a+n);
  for(int i = 0; i < n-1; i++){
    if(a[i] == a[i+1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


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

using namespace std;
#define int long long

signed main(){
    int S;
    cin >> S;
    
    int wa1 = 0;
    int wa2 = 0;
    for(int i=0;i<6;i++){
        wa1= S / pow(10,i);
        wa2 =wa2 + (wa1 % 10);
    }
    
    cout << wa2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int A, B, C; std::cin >> A >> B >> C;
  if (A == B && B != C) std::cout << "Yes" << std::endl;
  else if (B == C && C != A) std::cout << "Yes" << std::endl;
  else if (C == A && A != B) std::cout << "Yes" << std::endl;
  else                  std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void solve();
int main(void) {
  std::cout << std::fixed << std::setprecision(15);
  solve();
	return 0;
}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = (1<<30)-10;
const long long LINF=1LL<<59;

void solve(){
  int N; cin >> N ;
  cout << N*N*N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

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

int ctoi(char c){
  return c - '0';
}

int main(){
  I n;
  cin >> n;
  V a(n),b(n),c(n-1);
  VIN(a);
  VIN(b);
  VIN(c);
  I t=0;
  REP(i,n){
    t += b.at(a.at(i)-1);
    if (i > 0 && a.at(i) - a.at(i-1) == 1){
      t += c.at(a.at(i-1)-1);
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
//Score	663
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
int n, m, p, MOD;
lint pow2[2505], ans;
inline int ask(int x1, int y1, int x2, int y2) {
	cout << "? " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
	int ret = 0; cin >> ret; return ret;
}
inline int siz(int x1, int y1, int x2, int y2) {
	return (x2 - x1 + 1) * (y2 - y1 + 1);
}
inline void search(int x1, int y1, int x2, int y2, int las) {
	if (x1 == x2 && y1 == y2) {
		ans = (ans + pow2[x1 * m + y1]) % MOD;
	} else if (x2 - x1 < y2 - y1) {
		int mid = (y1 + y2) >> 1;
		int a1 = ask(x1, y1, x2, mid);
		int a2 = las - a1;
		if (a1) {
			if (a1 == siz(x1, y1, x2, mid)) {
				rep (i, x1, x2) {
					rep (j, y1, mid) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, y1, x2, mid, a1);
			}
		}
		if (a2) {
			if (a2 == siz(x1, mid + 1, x2, y2)) {
				rep (i, x1, x2) {
					rep (j, mid + 1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, mid + 1, x2, y2, a2);
			}
		}
	} else {
		int mid = (x1 + x2) >> 1;
		int a1 = ask(x1, y1, mid, y2);
		int a2 = las - a1;
		if (a1) {
			if (a1 == siz(x1, y1, mid, y2)) {
				rep (i, x1, mid) {
					rep (j, y1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, y1, mid, y2, a1);
			}
		}
		if (a2) {
			if (a2 == siz(mid + 1, y1, x2, y2)) {
				rep (i, mid + 1, x2) {
					rep (j, y1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(mid + 1, y1, x2, y2, a2);
			}
		}
	}
}
int main() {
	cin >> n >> m >> p >> MOD;
	pow2[0] = 1;
	rep (i, 1, 2500) {
		pow2[i] = pow2[i - 1] * 2 % MOD;
	}
	//search(0, 0, n - 1, m - 1, p);
	for (int i = 0; i < 50; i += 10) {
		for (int j = 0; j < 50; j += 10) {
			search(i, j, i + 9, j + 9, ask(i, j, i + 9, j + 9));
		}
	}
	cout << "! " <<  ans << endl;
	return 0;
}

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

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               int n;
               cin>>n;
               int a[n];
               vector<int> v(n);
               for(int i=0;i<n;++i)
               {
                    cin>>a[i];
                    v[a[i]-1] = i+1;
               }
               for(auto i : v)
                    cout<<i<<" ";
       }
}


Measured memory_bytes: 3996
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	Int x, y, z, k;
	cin >> x >> y >> z >> k;

	vector<Int> a(x);
	vector<Int> b(y);
	vector<Int> c(z);

	for (Int i = 0; i < x; i++) {
		cin >> a[i];
	}
	for (Int i = 0; i < y; i++) {
		cin >> b[i];
	}
	for (Int i = 0; i < z; i++) {
		cin >> c[i];
	}

	vector<Int> ab(x * y);
	Int temp = 0;
	for (Int i = 0; i < x; i++) {
		for (Int j = 0; j < y; j++) {
			ab[temp] = a[i] + b[j];
			temp++;
		}
	}

	sort(ab.begin(), ab.end(),greater<Int>());

	vector<Int> abc(k * z);
	temp = 0;
	for (Int i = 0; i < min(k,x*y); i++) {
		for (Int j = 0; j < z; j++) {
			abc[temp] = ab[i] + c[j];
			temp++;
		}
	}

	sort(abc.begin(), abc.end(),greater<Int>());

	for (Int i = 0; i <k ; i++) {
		cout << abc[i] << "\n";
	}

}

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

int main()
{
    int n, T;
    cin >> n >> T;
    int c[n], t[n];
    vector <pair<int, int> > pairs(n);
    for(int i=0;i<n;i++){
        cin >> c[i] >> t[i];
        pairs[i] = make_pair(c[i], t[i]);
    }
    sort(pairs.begin(), pairs.end());
    for(int j=0;j<n;j++){
        if(pairs[j].second <= T){
            cout << pairs[j].first << endl;
            break;
        }
        if(j==n-1){
            cout << "TLE" << endl;
        }
    }
    return 0;
}

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

int a,b=0,temp;
int maxi=0;
int mini=100000;
long sum=0;
int result[1000];

int main(){

  while(cin >> a && a!=0){
    for(int i=0;i<a;i++){
      cin >> temp;
      sum+=temp;
      if(temp>maxi)maxi=temp;
      if(temp<mini)mini=temp;
      //cout <<maxi<<mini<<sum<< endl;
    }
    result[b]=(sum-maxi-mini)/(a-2);
    b++;
    //cout << (sum-maxi-mini)/(a-2) << endl;
    maxi=0;
    mini=100000;
    sum=0;
    //temp=0;
  }

  for(int i=0;i<b;i++){
    cout << result[i] << endl;
  }
}



Measured memory_bytes: 2976
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  vector<int> vc(n);
  for(int i = 0 ; i < n ; i++ ) scanf("%d",&vc[i]);
  int ans = 0,q,a;
  scanf("%d",&q);
  sort(vc.begin(),vc.end());
  while(q--){
    cin >> a;
    if(binary_search(vc.begin(),vc.end(),a)) ans++;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 1532
import copy
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
B = copy.deepcopy(A)
sum1 = 0
sum2 = 0
center = -(-N // 2) - 1
if N%2 == 1:
    for i in range(N):
        if i == 0:
            beforeNum = A.pop(center)
        else:
            if i%2 == 1:
                num = A.pop(-1)
            else:
                num = A.pop(0)
            sum1 += abs(beforeNum - num)
            beforeNum = num
    for i in range(N):
        if i == 0:
            beforeNum = B.pop(center)
        else:
            if i%2 == 1:
                num = B.pop(0)
            else:
                num = B.pop(-1)
            sum2 += abs(beforeNum - num)
            beforeNum = num
else:
    for i in range(N):
        if i == 0:
            beforeNum = A.pop(center)
        else:
            if i%2 == 1:
                num = A.pop(-1)
            else:
                num = A.pop(0)
            sum1 += abs(beforeNum - num)
            beforeNum = num
    center = center + 1
    for i in range(N):
        if i == 0:
            beforeNum = B.pop(center)
        else:
            if i%2 == 1:
                num = B.pop(0)
            else:
                num = B.pop(-1)
            sum2 += abs(beforeNum - num)
            beforeNum = num
print(max(sum1,sum2))


Measured memory_bytes: 8648