akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n-1);
    REP(i,n-1) cin >> b[i];
    REP(i,n) {
        if (i == 0) {
            a[i] = b[i];
        } else if (i == n-1) {
            a[i] = max(b[i-1],a[i-1]);
        } else {
            a[i] = min(b[i-1],b[i]);
        }
    }

    ll ans = accumulate(ALL(a),0LL);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    
	  Scanner sc = new Scanner(System.in);
	  
	  while(true){
	  
		  int a = sc.nextInt();
		  String op = sc.next();
		  int b = sc.nextInt();
		 
		  if ( op.equals("+")){
			 System.out.println(a + b);
			 } else if ( op.equals("-")){
			 System.out.println(a - b);
			 } else if ( op.equals("*") ){
			 System.out.println(a * b);
			 } else if ( op.equals("/") ){
			 System.out.println(a / b);
			 } else {
			 break;
			 }
	  }
  }
}

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int dp[101][100001];
int32_t main() {
    nitin;
    int n,k;
    cin>>n>>k;
    vector<int>v(n+1,0);
    for(int i=1;i<=n;i++)
        cin>>v[i];
    for(int i=n;i>=1;i--)
    {
        dp[i][0]=1;
        for(int j=1;j<=k;j++)
        {
            if(i!=n)
            {
                if(j>=v[i]+1)
                dp[i][j]=((dp[i][j]+dp[i][j-1])%mod+(dp[i+1][j]-dp[i+1][j-v[i]-1]+mod)%mod)%mod;
                else
                    dp[i][j]=((dp[i][j]+dp[i][j-1])%mod+dp[i+1][j])%mod;
            } else
            {
                if(j<=v[n])
                    dp[n][j]=1;
            }
        }
    }
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=k;j++)
//            cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }
    cout<<dp[1][k]<<endl;
    return 0;
}

Measured memory_bytes: 81632
while True:
  n, x = list(map(int, input().split()))    
  if n == 0 and x == 0:
    break
  ans = 0
  for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
      rem = x - i - j
      if j < rem <= n:
        ans += 1
  print(ans)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  long k;
  cin >> n >> k;

  vector<pair<int,int>> ab(n);
  for (int i=0;i<n;i++){
    cin >> ab[i].first >> ab[i].second;
  }
  
  sort(ab.begin(),ab.end(),[](pair<int,int> ab1, pair<int,int> ab2){
    return ab1.first < ab2.first;
  });

  for (int i=0;i<n;i++){
    k-=ab[i].second;
    if (k<=0){
      cout << ab[i].first << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, d;
  cin >> h >> w >> d;
  vector<VI> a(h, VI(w));
  vector<PI> t(h * w);
  REP(i, 0, h) {
    REP(j, 0, w) {
      cin >> a[i][j];
      a[i][j]--;
      t[a[i][j]] = PI(i, j);
    }
  }
  vector<ll> acc(h * w + 1);
  REP(i, d, h * w) {
    acc[i] = acc[i - d] + abs(t[i].first - t[i - d].first)
      + abs(t[i].second - t[i - d].second);
  }
  int q;
  cin >> q;
  REP(i, 0, q) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    cout << acc[r] - acc[l] << endl;
  }
}


Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int v, e, r, inf = 1000000000;
    scanf("%d %d %d", &v, &e, &r);
    vector<vector<pair<int, int>>> a(v, vector<pair<int, int>>(0));
    for (int i = 0, s, t, d; i < e; i++)
    {
        scanf("%d %d %d", &s, &t, &d);
        a[s].push_back(make_pair(d, t));
    }
    vector<int> cost(v, inf), vis(v, false);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    cost[r] = 0;
    q.push(make_pair(0, r));
    for (pair<int, int> t; !q.empty(); )
    {
        t = q.top();
        q.pop();
        vis[t.second] = true;
        if (cost[t.second] < t.first)
        {
            continue;
        }
        for (int i = 0; i < a[t.second].size(); i++)
        {
            if (!vis[a[t.second][i].second] && cost[a[t.second][i].second] > cost[t.second] + a[t.second][i].first)
            {
                cost[a[t.second][i].second] = cost[t.second] + a[t.second][i].first;
                q.push(make_pair(cost[a[t.second][i].second], a[t.second][i].second));
            }
        }
    }
    for (int i = 0; i < v; i++)
    {
        printf(cost[i] >= inf ? "INF\n" : "%d\n", cost[i]);
    }
}


Measured memory_bytes: 13364
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> shops;
    map<string, vector<pair<int, int>>> shop_rank;
    string city;
    int point;
    for (int i = 0; i < N; i++) {
        cin >> city >> point;
        shop_rank[city].push_back({point, i + 1});
    }

    for (auto c : shop_rank) {
        shops.push_back(c.first);
        sort(shop_rank[c.first].begin(), shop_rank[c.first].end());
    }
    sort(shops.begin(), shops.end());

    for (auto c : shops) {
        for (int i = shop_rank[c].size() - 1; i >= 0; i--) {
            cout << shop_rank[c][i].second << endl;
        }
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  for(ll i = k; i <= n + 1; i++) {
    ll min = (i * (i - 1)) / 2;
    ll max = (i * (2 * n - i + 1)) / 2;
    ans = (ans + max - min + 1) % MOD;
  }
  cout << ans;
}


Measured memory_bytes: 3584
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n, m = LI()
G = [[] for _ in range(n)]
for _ in range(m):
    a, b = LI()
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

ans = [0] * n
q = I()
Q = LIR(q)
dq = deque()
depth = [-1] * n
for v, d, c in Q[::-1]:
    if depth[v - 1] >= d:
        continue
    if ans[v - 1] == 0:
        ans[v - 1] = c
    depth[v - 1] = d
    dq += [v - 1]
    while dq:
        u = dq.popleft()
        for x in G[u]:
            if depth[x] >= depth[u] - 1:
                continue
            depth[x] = depth[u] - 1
            if ans[x] == 0:
                ans[x] = c
            if depth[x]:
                dq += [x]

print(*ans, sep="\n")

Measured memory_bytes: 90016
n = int(input())
hirabun = input()
A = list(range(65,91))


def enc(m):
    hira   = list(m.encode("ascii"))
    ango   = hira.copy()
    for i, code in enumerate(hira):
        if 65 <= code <= 91:
            ango[i] = A[ (A.index(code) + n) % 26]
    c = bytes(ango).decode("ascii") 
    return c

angobun = enc(hirabun)
print(angobun)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+7,M=1e9;
 
#define C getchar()-48
int read()
{
  int s=0,t=1,k=C;
  for (;k<0||9<k;k=C) if (k==-3) t=-1;
  for (;0<=k&&k<=9;k=C) s=(s<<1)+(s<<3)+k;
  return s*t;
}
 
  int n,k;
  int a[N];
void in()
{
  cin>>n>>k;
  for (int i=0;++i<=n;)
    a[read()]=i;
}
 
  struct tr
    {
      int l,r,m;
    }tr[N+N];
#define ls(k) k*2
#define rs(k) k*2+1
void bui(int k,int l,int r)
{
  tr[k].l=l;tr[k].r=r;
  tr[k].m=M;
  if (l==r) return;
  int m=l+r>>1;
  bui(ls(k),l,m);
	bui(rs(k),m+1,r);
}
 
void add(int k,int p,int v)
{
  tr[k].m=v;
  if (tr[k].l==tr[k].r)
    return;
  if (tr[ls(k)].r<p)
    add(rs(k),p,v);
  else
    add(ls(k),p,v);
}
 
int que(int k,int l,int r)
{
  if (tr[k].r<l||r<tr[k].l)
    return M;
  if (l<=tr[k].l&&tr[k].r<=r)
    return tr[k].m;
  int x=que(ls(k),l,r),
      y=que(rs(k),l,r);
  return min(x,y);
}
 
  int t;
  int h[N],d[N];
  struct hh
    {
      int n,r;
    }e[N];
void ins(int x,int y)
{
  e[++t]=(hh){h[x],y};
	h[x]=t;++d[y];
}
 
  set<int> S;
  int A[N];
#define P(i) e[i].r
void top()
{
  for (int i=0;++i<=n;)    
    if (!d[i]) S.insert(i);
  for (int j=0;++j<=n;)
    {
      int x=*S.begin();
      A[x]=j;
      S.erase(x);
      for (int i=h[x];i;i=e[i].n)
        if (--d[P(i)]==0)
          S.insert(P(i));
    }
}
 
void wor()
{
  bui(1,1,n);
  for (int i=n,x;i;--i)
    {
      x=que(1,a[i]-k+1,a[i]);
      if (x<=n) ins(a[i],a[x]);
      x=que(1,a[i],a[i]+k-1);
      if (x<=n) ins(a[i],a[x]);
      add(1,a[i],i);
    }  
  top();
}
 
void out()
{
  for (int i=0;++i<=n;)
    printf("%d\n",A[i]);
}
 
int main()
{
  in();
  wor();
  out();
  exit(0);
}

Measured memory_bytes: 49408
;;;; union find tree
(defun make-uft (n)
  (let ((parent (make-array (list (1+ n))))
        (rank (make-array (list (1+ n)))))
    (loop :for i :from 0 :to n
          :do (setf (aref parent i) i))
    (cons parent rank)))

(defun find-root (uft x)
  (let ((p nil)
        (stack nil))
    (loop :with stack := nil
          :while (/= (aref (car uft) x) x)
          :do (push x stack)
          :do (setf x (aref (car uft) x))
          :finally (setf p x))
    (loop :for y :in stack
          :do (setf (aref (car uft) y) p))
    p))

(defun union-nodes (uft x y)
  (let ((x-root (find-root uft x))
        (y-root (find-root uft y)))
    (cond ((> (aref (cdr uft) x-root) (aref (cdr uft) y-root))
           (setf (aref (car uft) y-root) x-root))
          ((< (aref (cdr uft) x-root) (aref (cdr uft) y-root))
           (setf (aref (car uft) x-root) y-root))
          ((/= x-root y-root)
           (setf (aref (car uft) y-root) x-root)
           (incf (aref (cdr uft) x-root))))))

(defun same-root (uft x y)
  (= (find-root uft x) (find-root uft y)))

;;;; main
(let* ((n (read))
       (m (read))
       (uft (make-uft n)))
  (loop :for _ :from 1 :to m
        :for a := (read)
        :for b := (read)
        :do (union-nodes uft a b))
  (loop :with cnt := 0
        :for i :from 2 :to n
        :do (unless (same-root uft 1 i)
              (union-nodes uft 1 i)
              (incf cnt))
        :finally (format t "~A~%" cnt)))


Measured memory_bytes: 78712
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

import numpy as np

import math

import collections
import itertools


def createmaiz(listh,listw,list):
    for i in range(h):
        if listh[i] == "1":
            for j in range(w):
                list[i][j] ="."
    for i in range(w):
        if listw[i] == "1":
            for j in range(h):
                list[j][i] ="."
    return  list


def calc(maiz):
    count = 0
    for i in maiz:
        for j in i:
            if j =="#":
                count +=1
    return count


if __name__ == '__main__':
    h,w,k = map(int, input().split())
    maiz = []
    for i in range(h):
        s = input()
        maiz.append(list(s))

    listh=[]
    for i  in itertools.product('01', repeat=h):
        listh.append(list(i))
    listw=[]
    for i in itertools.product('01', repeat=w):
        listw.append(list(i))
    ans = 0

    for i in listh:
        for j in listw:
            temp = copy.deepcopy(maiz)
            temp =createmaiz(i,j,temp)
            black = calc(temp)
            if black ==k:
                ans+=1
    print(ans)



Measured memory_bytes: 27152
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,k;
  cin >> n >> k;
  
  if(k==0) {cout<<n*n<<endl;return 0;}
  
  int ans = 0;
  repeq(i,k+1,n){
    ans += (n/i)*(i-k);
    ans += max(0LL,(n%i)-k+1);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

    int ans = 0;
    while(true){
        if (*max_element(h.begin(), h.end()) == 0) break;

        int i = 0;
        while(i < n){
            if(h[i] > 0){
                ++ans;
                while(i < n && h[i] > 0){
                    --h[i];
                    ++i;
                }
            }
            ++i;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

ll GCD(ll x, ll y) {
	return x ? GCD(y % x, x) : y;
}

int main()
{
	ll A, B;
	cin >> A >> B;
	ll G = GCD(A, B);
	cout << A / G * B << endl;;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
    int k;
    char s[110];
    scanf("%d",&k);
    scanf("%s",s);
    if(strlen(s)<=k){
        printf("%s\n",s);
    }else{
        for(int i=0;i<k;i++){
            printf("%c",s[i]);
        }
        printf("...\n");
    }
    return 0;

}

Measured memory_bytes: 1660
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    private static class Node {
        int u;
        int v;
        long w;

        public Node(int u, int v, long w) {
            this.u = u;
            this.v = v;
            this.w = w;
        }
    }

    private static int inverse(int n) {
        if (n % 2 == 0) {
            return 1;
        }
        return 0;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, List<Node>> uvw = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            uvw.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = sc.nextInt();
            int v = sc.nextInt();
            long w = sc.nextLong();
            List<Node> nodeu = uvw.get(u);
            nodeu.add(new Node(u, v, w));
            uvw.put(u, nodeu);
            List<Node> nodev = uvw.get(v);
            nodev.add(new Node(v, u, w));
            uvw.put(v, nodev);
        }
        int[] color = new int[n + 1];
        Arrays.fill(color, -1);
        for (int i = 1; i <= n; i++) {
            Deque<Node> queue = new ArrayDeque<>();
            if (color[i] == -1) {
                color[i] = 0;
                for (Node node : uvw.get(i)) {
                    queue.add(node);
                }
            }
            while (!queue.isEmpty()) {
                int size = queue.size();
                for (int j = 0; j < size; j++) {
                    Node node = queue.poll();
                    if (node.w % 2 == 0) {
                        color[node.v] = color[node.u];
                    } else {
                        color[node.v] = inverse(color[node.u]);
                    }
                    for (Node next : uvw.get(node.v)) {
                        if (color[next.v] == -1) {
                            queue.add(next);
                        }
                    }
                }
            }
        }

        for (int i = 1; i <= n; i++) {
            System.out.println(color[i]);
        }
    }

}


Measured memory_bytes: 86136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

int main() {

    double w,h,x,y; cin >> w >> h >> x >> y;

    double ans1 = w*h / 2.0;
    int ans2 = 0;
    if (x == w/2.0 && y == h/2.0) {
        ans2 = 1;
    }

    cout << setprecision(15) << ans1 << " " << ans2 << endl;


}


Measured memory_bytes: 256
#include <stdio.h>

int card[4][13];
char moji[]={'S','H','C','D'};

int main()
{
    int i,j,n;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        char a;
        int x;
        scanf(" %c %d",&a,&x);
        if(a=='S') card[0][x-1]=1;
        else if(a=='H') card[1][x-1]=1;
        else if(a=='C') card[2][x-1]=1;
        else if(a=='D') card[3][x-1]=1;
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(card[i][j]==0){
                printf("%c %d\n",moji[i],j+1);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 596
// C - Vacation

#include <bits/stdc++.h>             // basically in this 2d DP we are actually maintaining 3 1-d dps if you visualise . one dp[i][1] which indicates
using namespace std;                 // the max happiness if ith day ends with taro doing 1st task on the ith day. similiarly for dp[i][2] and dp[i][3] 
#define ll long long                 // finally for the nth day we find max of these 3. So basically we are not finding aunique path , rather taking
int main() {                         // max of the best possible paths.
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n+1][4];
    for(int i=1;i<n+1;i++)
     for(int j=1;j<4;j++)
      cin>>a[i][j];
    int dp[n+1][4];
    dp[0][1]=0;
    dp[0][2]=0;
    dp[0][3]=0;
    for(int i=1;i<n+1;i++)
    {
    	dp[i][1]=max(dp[i-1][2]+a[i][1],dp[i-1][3]+a[i][1]);
    	dp[i][2]=max(dp[i-1][1]+a[i][2],dp[i-1][3]+a[i][2]);
        dp[i][3]=max(dp[i-1][1]+a[i][3],dp[i-1][2]+a[i][3]);
    }
    cout<<max(max(dp[n][1],dp[n][2]),dp[n][3]);
	return 0;
}


Measured memory_bytes: 3328
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))


INF = 2147483647


import sys
stdin = sys.stdin

T =   stdin.readline().strip() 

N = len(T)
ts = ['' for _ in range(2*N)]
for i in range(N):
    ts[2*i] = T[i]

rr = 0
for i in range(1 << (N-1)):
    here = ts[:]
    for k in range(N):
        if i & (1 << k):
            here[2*k+1] = '+'

    rr += eval(''.join(here))

print rr




Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    int dp[100010] = {};
    rep(i, 1, n + 1) {
        dp[i] = INF;
        for (int j = 1; j <= i; j *= 6) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
        for (int j = 1; j <= i; j *= 9) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
    }

    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
string s[105],t[105];

int main()
{
	int N,M;
	cin >> N;
	rep(i,N)
	{
		cin >> s[i];
	}
	cin >> M;
	rep(i,M)
	{
		cin >> t[i];
	}
	int ans = 0;
	rep(i,N)
	{
		int res = 0;
		string temp = s[i];
		//cout << temp << endl;
		rep(j,N)
		{
			if (s[j] == temp) res++;
		}
		rep(j,M)
		{
			if (t[j] == temp) res--;
		}
		//cout << res << endl;
		ans = max(ans,res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3552
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

inline int read(){
    register int x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
	return x * flag;
}

template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 

int A, B, C;
int k;
int ans = 0;
int main() {
	cin >> A >> B >> C;
	cin >> k;
	while (A >= B) {
		B *= 2; ans++;
	}
	while (B >= C) {
		C *= 2; ans++;
	}
	if (ans <= k) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 3632
def func(S,T):
  tlen = len(T)
  min = 1000
  for x in range(0,len(S)-tlen+1,1):
    tmp = S[x:x+tlen]
    tmpNum = 0
    for i in range(0,len(tmp),1):
      if tmp[i] != T[i]:
        tmpNum += 1
    if min > tmpNum:
      min = tmpNum
  return min

if __name__ == "__main__":
    S = input()
    T = input()
    print(func(S,T))

Measured memory_bytes: 8932
#include<stdio.h>
int main(void){
	int i,n,x;
	scanf("%d",&n);
	for(i = 3;i <= n;i++){
		if((i % 3) == 0){
			printf(" %d",i);
			continue;
		}
		else if((i % 10) == 3){
			printf(" %d",i);
			continue;
		}
		else{
			x = i;
			while(x > 0){
				if(((x /= 10) % 10) == 3){
					printf(" %d",i);
					break;
				}
			}
		}
	}
	puts("");
	return 0;
}

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

int main(){
  int N;  cin >> N;
  vector<long long int> A;
  long long int k;
  for(int i = 0;i < N;i++){
    cin >> k;
    A.push_back(k);
  }

  long long int mx = *max_element(A.begin(),A.end());
  long long int mn = *min_element(A.begin(),A.end());
  cout << mx-mn << endl;
}

Measured memory_bytes: 256
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()

ans = []

for i in range(n):
    for j in range(len(b))[::-1]:
        if b[j] == j + 1:
            ans.append(b[j])
            del b[j]
            break
        if j == 0:
            print(-1)
            exit()

print(' '.join([str(_) for _ in reversed(ans)]))


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int r, g;
    cin >> r >> g;

    if(r-g < 0) cout << g+abs(r-g) << endl;
    else cout << g-abs(r-g) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cctype>
#include <algorithm>
#include <set>
#include <cmath>
#include <cassert>
#include <array>
using namespace std;

#define dump(a) //(cerr << #a << " = " << (a) << endl)

inline int match(const string &a, const string &b) {
  const int n = a.size();
  int res = 0;
  for(int i = 0; i < n; ++i) {
	if(a[i] == b[i]) ++res;
  }
  return res;
}

inline int count_blow(const string &a, const string &b) {
  int res = 0;
  for(int c = '0'; c <= '9'; ++c) {
	res += min(count(a.begin(), a.end(), c), count(b.begin(), b.end(), c));
  }
  return res - match(a, b);
}

inline string to_leading_zero_string(int x, int n) {
  char buf[256];
  sprintf(buf, "%0*d", n, x);
  return string(buf);
}

bool valid(const string &s) {
  for(char c = '0'; c <= '9'; ++c) {
	if(count(s.begin(), s.end(), c) > 1) return false;
  }
  return true;
}

vector<string> solve(const vector<string> &number, const vector<int> &hit, const vector<int> & blow) {
  const int n = number.size();
  const int l = number[0].size();
  const int half = l / 2;

  const int first_size = half;
  const int second_size = l - half;

  const int max_first = pow(10, first_size);
  const int max_second = pow(10, second_size);

  map<vector<int>, vector<string>> candidates;

  for(int x = 0; x < max_first; ++x) {
	const string str = to_leading_zero_string(x, first_size);
	if(!valid(str)) continue;

	vector<int> key(n);

	for(int i = 0; i < n; ++i) {
	  const string first = number[i].substr(0, half);
	  const int rest_hit = hit[i] - match(str, first);
	  if(rest_hit < 0) goto first_ng;
	  key[i] = rest_hit;
	}

	candidates[key].emplace_back(str);

  first_ng:;
  }

  vector<string> res;
  for(int x = 0; x < max_second; ++x) {
	const string str = to_leading_zero_string(x, second_size);
	if(!valid(str)) continue;
	vector<int> key(n);

	for(int i = 0; i < n; ++i) {
	  const string second = number[i].substr(half);
	  key[i] = match(str, second);
	  if(key[i] > hit[i]) goto second_ng;
	}

	if(str == "281") dump(str);
	if(str == "281") for(auto &e : key) dump(e);
	if(!candidates.count(key)) goto second_ng;
	for(const auto &e : candidates.at(key)) {
	  string s = e + str;
	  if(!valid(s)) continue;

	  bool ok = true;

	  if(s == "637281") dump(s);

	  for(int i = 0; i < n; ++i) {
		if(s == "637281") dump(count_blow(s, number[i]));
		if(count_blow(s, number[i]) != blow[i]) {
		  ok = false;
		  break;
		}
	  }

	  if(ok) res.emplace_back(s);
	}

  second_ng:;
  }

  return res;
}

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

  for(int l, h; cin >> l >> h && l;) {
	vector<string> number(h);
	vector<int> hit(h), blow(h);

	for(int i = 0; i < h; ++i) {
	  cin >> number[i] >> hit[i] >> blow[i];
	}

	const auto answers = solve(number, hit, blow);
	dump(answers.size());
	cout << (answers.size() == 1 ? answers.front() : "NO") << endl;
  }

  return 0;
}

Measured memory_bytes: 3108
#include<stdio.h>
int main(){
int h,w,i,p;
	while(1){
		scanf("%d %d",&h,&w);
		if((h*w)==0){break;}
		for(i=0;i<h;i++){
			for(p=0;p<w;p++){
				if(i%2==p%2){
					printf("#");
				}else{
					printf(".");
				}
			}
		printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}
use std::iter::Iterator;
fn main() {
    let _n = get!(usize);
    let (s,t) = get!(String,String);

    for (i,j) in s.chars().enumerate() {
        print!("{}",j);
        print!("{}",t.chars().nth(i as usize).unwrap());
    }
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    abc082c()
}

fun abc082c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val answer = aList.groupBy { it }
        .map { if (it.value.size >= it.key) it.value.size - it.key else it.value.size.toLong() }.sum()

    println(answer)
}


Measured memory_bytes: 59880
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // ????????????????????¨??????????????????????????????????????????
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    long long a[100000];
    long long b[100000];
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        b[i]=a[i];
    }
    for(int i=0; i<n-1; i++)
    {
        for(int j=0; j<n-i-1; j++)
        {
            if(b[j]>b[j+1])
            {
                int temp=b[j];
                b[j]=b[j+1];
                b[j+1]=temp;
            }
        }
    }
    int temp=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            temp++;
        }
    }
    if(temp<=2)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }


    return 0;
}


Measured memory_bytes: 256
#include       <set>
#include       <map>
#include     <queue>
#include     <cmath>
#include    <cstdio>
#include    <cctype>
#include    <vector>
#include   <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int maxn = 5e6+5;

ll fast_pow(ll a,ll b,ll mod){
    ll ans = 1;
    while(b){
        if(b&1)
            ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}
int S[105][105];
int SG(int x,int y){
    if(x>y)swap(x,y);
    if(S[x][y]!=-1)return S[x][y];

    for(int i=2;i<=x;i+=2){
        if(SG(x-i,y+i/2)==0)
            return S[x][y] = 1;
    }
    for(int i=2;i<=y;i+=2){
        if(SG(x+i/2,y-i)==0)
            return S[x][y] = 1;
    }
    return S[x][y] = 0;
}
int main(){
    /*
    memset(S,-1,sizeof(S));
    S[0][0] = S[0][1] = S[1][0] = S[1][1] = 0;
    for(int i=1;i<=60;i++)
    for(int j=1;j<=60;j++)
        SG(i,j);
    for(int j=0;j<=15;j++){
        for(int i=0;i<=j;i++)
            printf("SG[%d][%d]=%d ",i,j,S[i][j]);
        puts("");
    }
    */
    ll x, y;
    scanf("%lld%lld",&x,&y);
    ll t = x-y;
    if(t<0)t=-t;
    printf("%s\n",(t<=1?"Brown":"Alice"));
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    cin >> n;

    int s = 0;
    int tmp = n;
    while(tmp != 0){
        s += tmp % 10;
        tmp /= 10;
    }
    if(n%s == 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int w,int q){
    if(max(w,q)%min(w,q)==0)return min(w,q);
    return gcd(min(w,q),max(w,q)%min(w,q));
}
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long l,m,n,k,j,g;
  l=(a-1)/c,m=b/c,n=(a-1)/d,k=b/d,j=(a-1)/(c*d/gcd(c,d)),g=b/(c*d/gcd(c,d));
  cout<<b-a+1-(m-l+k-n+j-g)<<endl;
}

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

int main() {
  long long int h;
  cin >> h;
  long long int total = 0;
  long long int ind = 0;
  while(h != 0) {
    total += (long long int)pow(2, ind);
    ind++;
    h /= 2; 
  }

  cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
#define f(i,l,r) for(ll i=l;i<=r;i++)
using namespace std;
int main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   ll conchonay;
   cin >> conchonay;
   ll a[1005] = {0};
   f(i,1,1004) a[i] = pow(i,5);
   bool ditmemay = false;
   f(i,0,1004){
      if(a[i] == conchonay){
          cout << i << " 0";
          return 0;
      }
      else{
         f(j,1,1004) if(a[i] - a[j] == conchonay){
             cout << i << " " << j;
            ditmemay  = true;
            return 0;
         }
         if(ditmemay == false) f(j,1,1004) if(a[i] + a[j] == conchonay){
             cout << i << " " << -j;
             return 0;
         }
      }
   }
   return 0;
}


Measured memory_bytes: 4100
#include <stdio.h>
int main(void){
  int i, max = 0, count = 0;
  char S[3];
  for(i=0; i<3; i++){
    scanf("%c",&S[i]);
    if(S[i] == 'R'){
      count++;
    }
    else if(S[i] == 'S' && max < count){
      max = count;
      count = 0;
    }
    if(i == 2 && max < count){
      max = count;
    }
  }
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 1664
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

class SplitStream {
	typedef basic_ostream<char, char_traits<char> > BaseOst;
	std::ostream& ost_m;
	bool line_is_empty_m;
public:
	SplitStream(std::ostream& ost);
	template <typename T>
	SplitStream& operator<<(T right);
	SplitStream& operator<<(BaseOst& (*right)(BaseOst&));
};
SplitStream::SplitStream(std::ostream& ost) : ost_m(ost), line_is_empty_m(true) {}
template <typename T>
SplitStream& SplitStream::operator<<(T right) {
	if (!line_is_empty_m) ost_m << ' ';
	line_is_empty_m = false;
	ost_m << right;
	return *this;
}
/* std::endl のみ */
SplitStream& SplitStream::operator<<(BaseOst& (*right)(BaseOst&)) {
	ost_m << '\n';
	ost_m.flush();
	line_is_empty_m = true;
	return *this;
}
SplitStream Scout(cout);

template <typename T, int Begin, int End>
class OffsetArray {
	T arr_m[End - Begin];
public:
	OffsetArray();

	T& operator[](int index);
	T operator[](int index) const;
};
template<typename T, int Begin, int End>
OffsetArray<T, Begin, End>::OffsetArray() : arr_m() {}
template<typename T, int Begin, int End>
T& OffsetArray<T, Begin, End>::operator[](int index) {
	return arr_m[index - Begin];
}
template<typename T, int Begin, int End>
T OffsetArray<T, Begin, End>::operator[](int index) const {
	return arr_m[index - Begin];
}

string s;

int main() {
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = 0;
    if(10*a + b + c > ans) ans = 10*a + b + c;
    if(a + 10*b + c > ans) ans = a + 10*b + c;
    if(a + b + 10*c > ans) ans = a + b + 10*c;
    cout << ans;
    return 0;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010, M = 10;

int n, m;
int a[N];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
	sort(a, a + n);
	
	LL res = 0;
	for (int i = 0; i < n - m; i ++ ) res += a[i];
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1024
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5
1 1 2 1 2
'''

def solve(l):
	n = len(l)
	d = dict(Counter(l))
	ans = []
	tot = 0
	for i in d:
		j = d[i]
		tot += j*(j-1)//2
	for i in range(n):
		curr = d[l[i]]
		temp = tot - curr + 1
		ans.append(temp)
	return ans


N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
for i in ans:
	print(i)


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

int main()
{
	int64_t n, m;
	cin >> n >> m;
	vector<int64_t> as(n);
	for (auto &a : as)
	{
		cin >> a;
	}
	vector<int64_t> dp(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		dp[i + 1] = dp[i] + as[i];
	}
	for (auto &i : dp)
	{
		i %= m;
	}
	map<int64_t, int64_t> puni, muni;
	for (auto &i : dp)
	{
		puni[i]++;
	}
	int64_t ans = 0;
	for (auto &i : dp)
	{
		muni[i]++;
		ans += puni[i] - muni[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9728
#include <iostream>

using namespace std;

int adja[101][101];
int stamp1[101], stamp2[101];
int n, cur = 1;

void dfs(int u) {
    stamp1[u] = cur++;
    for (int i = 1; i <= n; ++i) {
        if (adja[u][i] && stamp1[i] == 0)
            dfs(i);
    }
    stamp2[u] = cur++;
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            adja[u][v] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (stamp1[i] == 0)
            dfs(i);
        cout << i << " " << stamp1[i] << " " << stamp2[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include<string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    char s[15];
    char a[15];
	scanf("%s",s+1);
	scanf("%s",a+1);
	bool st=0;
	int len=strlen(s+1);

	for(int i=1;i<=len;i++)
	{
		if(s[i]!=a[i]) st=1;
	}
	if(st==0) cout<<"Yes";
    else cout<<"No";
	 
 

}

Measured memory_bytes: 3612
N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]
Q = int(input())

class WarshallFloyd:
    def __init__(self,n):
        self.n = n
        self.inf = 100000000000000
        self.d = [[self.inf for _ in range(n)] for _ in range(n)]
        for i in range(self.n):
            self.d[i][i] = 0
    def register(self,v1,v2,l,multiple=True):
        self.d[v1][v2] = l
        if multiple:
            self.d[v2][v1] = l
    
    def solve(self):
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    self.d[j][k] = min(self.d[j][k],self.d[j][i]+self.d[i][k])
        return self.d

W = WarshallFloyd(N)
for a,b,c in ABC:
    W.register(a-1,b-1,c)
D = W.solve()

WL = WarshallFloyd(N)
for i in range(N):
    for j in range(N):
        if D[i][j] <= L and i != j:
            WL.register(i,j,1)
DL = WL.solve()
ST = [list(map(int,input().split())) for _ in range(Q)]
for i in range(Q):
    s,t = ST[i]
    transition = DL[s-1][t-1]
    if transition == 100000000000000:
        print(-1)
    else:
        print(transition-1)

Measured memory_bytes: 81240
#include<cstdio>
#include<vector>
#include<queue>


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;


struct q_t
{
	int v, d, c;
};


struct n_t
{
	int d, c;
	vi e;
};


struct pqm_t
{
	int v, d, c;
	bool operator<(const pqm_t&rhs) const
	{
		return d>rhs.d;
	}
};

class pq_t
{
	priority_queue<pqm_t> q;
public:
	void push(int v, int d, int c)
	{
		q.push((pqm_t){v, d, c});
	}
	int pop(int&v, int&d, int&c)
	{
		if(q.empty()) return 0;
		v=q.top().v;
		d=q.top().d;
		c=q.top().c;
		q.pop();
		return 1;
	}
};


void max_u(int&m, int v)
{
	if(m<v) m=v;
}


void paint(vector<n_t>& x, int v, int d, int c)
{
	pq_t pq;

	pq.push(v, d, c);
	while(pq.pop(v, d, c))
	{
		max_u(x[v].c, c);
		if(d<=x[v].d) continue;
		max_u(x[v].d, d);
		for(auto e:x[v].e)
		{
			pq.push(e, d-1, c);
		}
	}
}


void solve(vector<n_t>& x, vector<q_t>& q)
{
	for(int c=q.size()-1;c>=0;c--)
	{
		paint(x, q[c].v, q[c].d, c+1);
	}
}


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vector<n_t> x(n);

		for(int i=0;i<m;i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			a--;
			b--;
			x[a].e.push_back(b);
			x[b].e.push_back(a);
		}

		int qn;
		scanf("%d", &qn);
		vector<q_t> q(qn);
		for(int i=0;i<qn;i++)
		{
			scanf("%d%d%d", &q[i].v, &q[i].d, &q[i].c);
			q[i].v--;
		}
		solve(x, q);

		for(int i=0;i<n;i++)
		{
			if(x[i].c==0)
			{
				printf("0\n");
				continue;
			}
			printf("%d\n", q[x[i].c-1].c);
		}
	}

	return 0;
}


Measured memory_bytes: 10820
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		
		String s = sc.nextLine();
		int[] i = ArrconvAtoi(s);
			
		System.out.println(i[0] / i[1] + i[0] % i[1]);

	}
	
    private static int[] ArrconvAtoi(String s) {
        String[] strs = s.split(" ");
        int[] ints = new int[strs.length];
        int i = 0;
 
        for (String st : strs) {
            ints[i] = Integer.parseInt(st);
            i++;
        }
 
        return ints;
    }
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    string s;
    cin>>s;

    int cnta = 0, cntb = 0;
    for( char c : s )
    {
        cnta += ( c == 'A' );
        cntb += ( c == 'B' );
    }

    if( cnta > 0 && cntb > 0 )
        cout<<"Yes";
    else
        cout<<"No";

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 256