akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
using mint = modint998244353;
using pr = pair<mint, int>;

mint ten[N], elev[N];

pr op(pr a, pr b){
	return MP(a.first * ten[b.second] + b.first, a.second + b.second);
}
pr e() {
	return MP(0, 0);
}
pr mapping(int a, pr b){
	if(a == 0) return b;
	else return MP(elev[b.second] * a, b.second);
}
int composition(int a, int b){
	if(a == 0) return b;
	else return a;
}
int id() {
	return 0;
}

lazy_segtree<pr, op, e, int, mapping, composition, id> seg(N);

int main(){
	ten[0] = 1;
	FOR(i, 1, N) ten[i] = ten[i-1] * 10;
	elev[0] = 0;
	FOR(i, 1, N) elev[i] = elev[i-1] * 10 + 1;

	int n, q; scanf("%d%d", &n, &q);
	REP(i, n) seg.set(i, MP(1, 1));
	REP(iq, q){
		int l, r, d; scanf("%d%d%d", &l, &r, &d);
		seg.apply(l-1, r, d);
		printf("%d\n", seg.prod(0, n).first.val());
	}
}


Measured memory_bytes: 11548
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<int,int> pii;
map<string,int>M;
vector<int> V[MAX];
string S[MAX];
int checkbit(int n,int bit){ /// bit 0 index
    return (n>>bit)&1;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h,w,k,ans=0;
    cin>>h>>w>>k;
    for(int i=0;i<h;i++) cin>>S[i];
    for(int i=0;i<(1<<h);i++){
        for(int j=0;j<(1<<w);j++){
            int sum=0;
            for(int x=0;x<h;x++){
                for(int y=0;y<w;y++){
                    if(!checkbit(i,x) && !checkbit(j,y) && S[x][y]=='#')
                        sum++;
                }
            }
            if(sum==k) ans++;
        }
    }
    cout<<ans;
    return 0;
}


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

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  cout << 800 * n - 200 * (n / 15) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   vector<int> p(n);
   for(int i = 0;i<n;i++){
       cin >> p.at(i);
   }

   for(int j = 0; j < n - 1; j++){
            cout << p.at(j) << " ";
        }

        cout << p.at(n-1) << endl;
   int v = 0;
   int j = 0;
   for(int i = 1; i < n; i++){
        v = p.at(i);
        j = i - 1;
        while(j >= 0 && p.at(j) > v){
            p.at(j+1) = p.at(j);
            j--;
        }
        p.at(j+1) = v;
        for(int j = 0; j < n - 1; j++){
            cout << p.at(j) << " ";
        }

        cout << p.at(n-1) << endl;
   }
}




Measured memory_bytes: 3096
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,M = IL()
if 2*N >= M:
  PE(M//2)
R = M-2*N
P(N+(R//4))

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


#define int long long
#define ll long long
#define pb push_back

#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, a, b) for(int i = (a); i > (b); --i)

typedef pair <int,int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <ll> vl;

const int mod = 1e9+7;
const ll inf = 2e18+5;

void solve(){
    int n,k;
    cin>>n;
    int m=n%1000;
    m=1000-m;
    if(m==1000) cout<<0<<endl;
    else cout<<m<<endl;
}















signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
            freopen("fin.txt", "r", stdin);
            freopen("fout.txt", "w", stdout);
    #endif   
    int cases=1;
    //cin>>cases;
    
    
    for(int iter=0; iter<cases; iter++){      
        solve();
    }
    return 0;
}

Measured memory_bytes: 3696
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  pair<ll, ll> p[N];
  for(int i = 0; i < N; i++){
    cin >> p[i].second >> p[i].first;
  }

  sort(p, p + N);

  ll time = 0;
  for(int i = 0; i < N; i++){
    if(time + p[i].second > p[i].first){
      cout << "No" << endl;
      return 0;
    }
    else{
      time += p[i].second;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>

using namespace std;

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

ll dosuffix(const string &S, ll i)
{
  int j=i;
  while(S[j]=='A' || S[j]=='T' || S[j]=='G' || S[j]=='C'){
    j++;
  }
  return j;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin

  string S;
  cin >> S;

  int n=S.length();

  ll maxlen=0;
  rep(i,n){
    ll j = dosuffix(S, i);
    if(j-i>maxlen){
      maxlen=j-i;
      i=j;
    }
  }

  cout << maxlen << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  set<string> s;
  REP(i,n) {
    string a;
    cin >> a;
    s.insert(a);
  }
  cout << s.size() << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 15652
#include<bits/stdc++.h>
    using namespace std;
    #define PAIN___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < int , int >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 1000005

    int main()
    {
        PAIN___;
        ll t;
        t=1;
        while(t--)
        {
            string s;
            cin>>s;
            sort(s.begin(),s.end());
            map<char,int>m;
            forl(i,0,n,s.size())
            {
                m[s[i]]++;
            }
            if(m[s[0]]==2&&m[s[s.size()-1]]==2)cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;


    }
    }



Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define nax (int)1e5+2
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n" 
#define INF (int)1e9
#define eps (long double)1e-9
using namespace std;



int main(){
	fast;
	ll x;
	cin >> x;
	set<ll> s;
	s.insert(1);
	map<ll,ll> m;
	m[1] = 1;
	m[0] = 0;
	for(ll i = 2 ;i <= 3500;i++ ){
		ll val = i*i*i*i*i;
		if(val >= (ll)1e18){
			deb(i);
			break;
		}
		m[val] = i;
		s.insert(val);
	}
	ll a, b;
	set<ll> val;
	for(auto it : s){
		ll k = it - 2*(it);
		m[k] = m[it] - 2*m[it];
		//deb(m[k]);	
		val.insert(k);
		val.insert(it);
	}
	val.insert(0);
	for(auto it : val){	
		//deb(it);
		auto ip = val.find(it-x);
		if(ip != val.end()){
			//debi;
			//deb(it);
			//deb(it-x);
			b = m[-it];
			a = m[x -it];
			break;
		}
	}
	cout<<a << " "<<b;
	
	return 0;
}
	


Measured memory_bytes: 4568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int n;
	cin >> n;
	set<int> s;
	for(int i = 0; i < n; i++){
		int d;
		cin >> d;
		s.insert(d);
	}
	cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    string s;
    cin >> s;
    int n = (int)s.length();
    string t;
    rep(i,n){
        t+=s[n-i-1];
    }
    int now = 0;
    while(now<n){
        if(t[now]=='r'){
            if(t.substr(now,6)=="resare"){
                now+=6;
            }
            else if(t.substr(now,7)=="remaerd"){
                now+=7;
            }
            else{
                puts("NO");
                return 0;
            }
        }
        else if(t[now]=='m'){
            if(t.substr(now,5)=="maerd"){
                now+=5;
            }
            else{
                puts("NO");
                return 0;
            }

        }
        else if(t[now]=='e'){
            if(t.substr(now,5)=="esare"){
                now+=5;
            }
            else{
                puts("NO");
                return 0;
            }
        }
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define id first
#define lf second.first
#define rg second.second


void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<E> v;
int n,t[555];

void update(int p, int x = 1){
	while(p<=n){
		t[p] += x;
		p += (p&(-p));
	}
}

int query(int p){
	int x = 0;
	while(p){
		x += t[p];
		p -= (p&(-p));
	}
	return x;
}

bool comp(E a, E b){
	return ((a.rg == b.rg)?(a.id < b.id):(a.rg < b.rg));
}

int main(void){
	int m,q,i,l,r,ans[111111];
	E tmp;
	fill(t,t+555,0);
	cin >> n >> m >> q;
	for(i=0; i<(m+q); ++i){
		cin >> l >> r;
		v.push_back(E(i,P(l,r)));
	}
	sort(v.begin(),v.end(),comp);
	for(i=0; i<(m+q); ++i){
		if(v[i].id < m){
			update(v[i].lf);
		}else{
			ans[v[i].id-m] = query(v[i].rg)-query(v[i].lf-1);
		}
	}
	for(i=0; i<q; ++i){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 8432
-- 答え参照
local function xyz(x, y, z)
	return x*x + y*y + z*z + x*y + y*z + z*x
end

local N = io.read("*n")

local loop_num = math.ceil(math.sqrt(N))

local out_s = {}
for i = 1, N do
	out_s[i] = 0
end

for x = 1, loop_num do
	for y = 1, loop_num do
		for z = 1, loop_num do
			local result = xyz(x, y, z)
			if result <= N then
				out_s[result] = out_s[result] + 1
			end
		end
	end
end

print(table.concat(out_s, "\n"))

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N, K; cin >> N >> K;
    if (K > (N-1)*(N-2)/2) {
        cout << -1 << endl;
        return 0;
    } else {
        printf("%d\n", N-1+(N-1)*(N-2)/2 - K);
        for (int i = 2; i <= N; i++) {
            printf("%d %d\n", 1, i);
        }
        int s = 2;
        int t = s + 1;

        for (int i = 0; i < (N-1)*(N-2)/2 - K; i++) {
            if (t > N) {
                s++;
                t = s + 1;
            }
            printf("%d %d\n", s, t);
            t++;
        }
    }
}


Measured memory_bytes: 256
use std::io::Read;

fn main(){
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  let N : i64 = buf.trim().parse().unwrap();
  for a in 1 .. 3500 {
    for b in a .. 3500 {
      let div = 4 * a * b - N * b  - N  * a;
      if div <= 0 {
        continue;
      }

      let m = (N * a * b) % (4 * a * b  - N * b  - N * a);
      let c = (N * a * b) / (4 * a * b  - N * b  - N * a);
      if m > 0 || c <= 0 {
        continue;
      }
      
      println!("{} {} {}", a,b,c);
      return;
      
    }
  }
}

Measured memory_bytes: 2172
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = (int)1e6 + 1;
	
	void doIt() {
		int[] A = new int[9];
		for(int i = 0; i < 9; i++) {
			A[i] = sc.nextInt();
		}
		int N = sc.nextInt();
		int b[] = new int[N];
		for(int i = 0; i < N; i++) {
			b[i] = sc.nextInt();
		}
		boolean[] opened = new boolean[9];
		Arrays.fill(opened, false);
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < 9; j++) {
				if(b[i] == A[j]) opened[j] = true;
			}
		}
		
		for(int i = 0; i < 3; i++) {
			if(opened[i] && opened[i + 3] && opened[i + 6]) {
				System.out.println("Yes");
				return;
			}
		}
		for(int i = 0; i < 9; i += 3) {
			if(opened[i] && opened[i + 1] && opened[i + 2]) {
				System.out.println("Yes");
				return;
			}
		}
		if(opened[0] && opened[4] && opened[8]) {
			System.out.println("Yes");
		}
		else if(opened[2] && opened[4] && opened[6]) {
			System.out.println("Yes");
		}
		else System.out.println("No");
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K; cin >> N >> K;
    vector<int> A(N); cin >> A;
    vector<int> ans(N),imos(N);
    for (int i=0;i<N;++i) ans[i]=A[i];
    for (int i=0;i<K;++i){
        for (int j=0;j<N;++j) imos[j]=0;
        for (int j=0;j<N;++j){
            ++imos[max(0,j-ans[j])];
            if (j+ans[j]+1<N) --imos[j+ans[j]+1];
        }
        for (int j=0;j<N-1;++j) imos[j+1]+=imos[j];
        int check=1;
        for (int j=0;j<N;++j){
            ans[j]=imos[j];
            if (ans[j]!=N) check=0;
        }
        if (check) break;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5576
#include<bits/stdc++.h>
#define pb push_back 
 #define fo(i,n) for(int i=0;i<n;i++)
#define ll long long
#define Mod 1000000009 
#define MAX 4294967296  // 2^32

using namespace std;



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


     int k;
     cin>>k;
     ll a[k];
     for(int i=0;i<k;i++)cin>>a[i];
sort(a,a+k);
set<pair<int,pair<int,int>>>st;
int count=0;
        for(int i=0;i<k;i++){ 
            for(int j=i+1;j<k;j++){
if(a[i]==a[j])continue;
               for(int l=j+1;l<k;l++){
                if(a[j]==a[l])continue;
                if(a[i]+a[j]>a[l]){
                    
              count++;



                }
               }
            }
        }

cout<<count;




}



Measured memory_bytes: 3660
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
ll INF = 10000000000 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vll &a){sort(a.begin(),a.end()) ;}
//void myrev(vll &a){reverse(a.begin(),a.end()) ;}

void BFS(vvll &g,vll &cnt,ll n,queue<ll> &q){
	ll d = cnt.at(n) ;
	for(int i=0;i<g.at(n).size();i++){
		if(cnt.at(i)>d+g.at(n).at(i)){
			cnt.at(i) = d+g.at(n).at(i) ;
			q.push(i) ;
		}
	}
	if(q.empty()) return ;
	ll next = q.front() ; q.pop() ;
	BFS(g,cnt,next,q) ;
}

int main(){
	ll h,w ;
	cin >> h >> w ;
	vvll g(10,vll(10)) ;
	for(int i=0;i<10;i++) for(int j=0;j<10;j++) cin >> g.at(i).at(j) ;
	vll cost(10,INF) ;
	cost.at(1) = 0 ;
	queue<ll> q ;
	for(int i=0;i<10;i++){
		vll cnt(10,INF) ;
		cnt.at(i) = 0 ;
		BFS(g,cnt,i,q) ;
		cost.at(i) = cnt.at(1) ;
	}
	ll ans = 0 ;
	for(int i=0;i<h*w;i++){
		ll a ; cin >> a ;
		if(a==-1) continue ;
		ans += cost.at(a) ;
	}
	cout << ans << endl ;
}


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


int main() {
  ll n,a,b; cin >> n >> a >> b;
  if(n%(a+b) <= a) cout << (n/(a+b))*a+ n%(a+b) << endl;
  else cout << (n/(a+b))*a + a << endl;
}

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

int main() {
    for(int N; cin >> N, N; ) {
        vector<int> v(N);
        for(int i = 0; i < N; i++) {
            cin >> v[i];
        }
        bool na = true;
        for(int i = 0; i < N; i++) {
            int item = v[i];
            if(item >= 2) na = false;
        }
        if(na) {
            cout << "NA" << endl;
            continue;
        }
        int ans = 0;
        for(int i = 0; i < N; i++) {
            int item = v[i];
            if(item > 0) ans++;
        }
        cout << ans + 1 << endl;
    }
}

Measured memory_bytes: 1232
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
using namespace std;
string s, t;
ll dp[3005][3005];
ll solve(ll i, ll j)
{
    if(i == s.size() || j == t.size())  return 0;
    if(~dp[i][j])                       return dp[i][j];
    return dp[i][j] = (s[i] == t[j] ? solve(i + 1, j + 1) + 1 : max(solve(i + 1, j), solve(i, j + 1)));
}
void print(ll i, ll j)
{
    if(i == s.size() || j == t.size())  return;
    if(s[i] == t[j])                    cout << s[i], print(i + 1, j + 1);
    else                                solve(i + 1, j) > solve(i, j + 1) ? print(i + 1, j) : print(i, j + 1);
}
int main()
{
    IO
    cin >> s >> t;
    memset(dp, -1, sizeof dp);
    solve(0, 0);
    print(0, 0);
    return 0;
}


Measured memory_bytes: 71168
#include<iostream>
#include<string.h>
#include<map>
using namespace std;
const int maxn=110;
map<int ,int>m;
int a,n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		m[a]=i;
	}
	for(int i=1;i<=n;i++){
		cout<<m[i]<<' ';
	}
	return 0;
}



Measured memory_bytes: 5504
#include <stdio.h>
#include <limits.h>
int main()
{
	long long k;
	int i;
	char s[100],tmp;
	scanf("%s%lld",&s,&k);
	for(i=0;i<sizeof(s);i++){
		if(s[i]!='1'){
			tmp=s[i];
			break;
			}
		}
	if(k>=i+1){
		printf("%c",tmp);
		}
	else if(k<i+1){
		printf("1");
		}
	return 0;
}


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

int main() {
  set<char> s;
  rep(i,3){
    char a; cin >> a;
    s.insert(a);
  }
  if(s.size() == 3){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	long long int n, a, b;
	cin >> n >> a >> b;
	vector<long long int> x(n);
	for (long long int i = 0; i < n; i++) {
		cin >> x[i];
	}
	long long int c = 0;
	for (long long int i = 0; i < n-1; i++) {
		c += min((x[i+1]-x[i])*a, b);
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1152
process.stdin.resume();
process.stdin.setEncoding('utf8');

var input = '';
process.stdin.on('data', (chunk) => {
  input += chunk;
});
process.stdin.on('end', () => {
  main(input.split(/\r?\n/));
});

var main = (lines) => {
  var N = lines[0];
  var A = lines[1].split(/ /);
  var flag = false;
  A.forEach((e) => {
    if(e%2 === 0 && e%3 !== 0 && e%5 !==0) {
      flag = true;
    }
  });
  if(flag) {
    console.log('DENIED');
  }
  else {
    console.log('APPROVED');
  }
}

Measured memory_bytes: 9548
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    int num[4], per2[4], i, ans=0;

    for(i=1; i<=3; i++){
        cin >> num[i];
    }

    sort(num+1, num+4);
    
    for(i=1; i<=3; i++){
        per2[i] = num[i] % 2;
    }

    if(per2[1]!=per2[2] && per2[2]!=per2[3]){
        num[1]++;
        num[3]++;

        ans++;
    }

    else if(per2[1]!=per2[3] && per2[2]!=per2[3]){
        num[1]++;
        num[2]++;

        ans++;
    }

    else if(per2[1]!=per2[2] && per2[1]!=per2[3]){
        num[2]++;
        num[3]++;

        ans++;
    }

    sort(num+1, num+4);

    while(num[1] != num[3]){
        num[1] += 2;

        ans++;
    }

    while(num[2] != num[3]){
        num[2] += 2;

        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str


def bfs(N, edges):
    from collections import deque
    par = [None] * (N + 1)
    que = deque([(1, 1)])
    while que:
        p, n = que.popleft()
        if par[n] is not None:
            continue
        par[n] = p
        for nn in edges[n]:
            if par[nn] is not None:
                continue
            que.append((n, nn))
    return par

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    edges = [[] for _ in range(N+1)]
    for a, b in zip(A, B):
        edges[a].append(b)
        edges[b].append(a)
    par= bfs(N, edges)
    return par[2:]


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    print('Yes')
    print(*solve(N, M, A, B), sep='\n')

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 43108
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	if (s[0]==s[s.size()-1]&&s.size()%2==1||s[0]!=s[s.size()-1]&&s.size()%2==0){
		printf("Second\n");
	}else{
		printf("First\n");
	}
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    int c = Integer.parseInt(a);
    int d = Integer.parseInt(b);
    String x = "";
    if(c >= d){
      for(int i = 0; i < c; i++){
        x += b;
      }
      System.out.println(x);
    }else{
        for(int i = 0; i<d; i++){
          x += a;
        }
      System.out.println(x);
      }
      
    }
  }


Measured memory_bytes: 23764
def solve(N,S):
	num_b = 0
	counter=["0"]*N
	pointer = []
	flag = 0;
	for i in range(N):
		if(S[i]=='#'):
			if(flag==0):
				counter[i]=num_b
				flag=1
				pointer.append(i)
			num_b+=1
		elif(S[i]=='.'):
			flag=0
	if(pointer==[]):return 0
	min_change=N+1
	for i in pointer:
		#all_white
		a = counter[i] + (num_b - counter[i])
		if(min_change>a):min_change=a
		#all_black
		a = (i - counter[i]) + (N - i - (num_b - counter[i]))
		if(min_change>a):min_change=a
		#L_white R_black
		a = counter[i] + (N - i - (num_b - counter[i]))
		if(min_change>a):min_change=a

	return min_change



if __name__ == '__main__':
	N = int(input())
	S = input()
	print(solve(N,S))


Measured memory_bytes: 12260
#include<bits/stdc++.h>
#define  ll long long int
#include<algorithm>
using namespace std;
int gcd(int x,int y,int z)
{
    int d=1;
    int i=1;
    while(i<=x&&i<=y&&i<=z)
        {
          if(x%i==0&&y%i==0&&z%i==0)
            {
              d=i;
             }
              i++;
        }
        return d;
}
int main()
{
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

int a,b,c,p=0,i,j,k;
cin>>a;
for(i=1;i<=a;i++)
{
    for(j=1;j<=a;j++)
    {
        for(k=1;k<=a;k++)
        {
            b=gcd(i,j,k);
            p+=b;
        }
    }
}

cout<<p<<endl;


}







Measured memory_bytes: 3652
# seishin.py
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    MOD = 10**9 + 7
    N = int(readline())
    M = 20
    L = 26
    ca = ord('a')
    cq = ord('?')
    S = [[ca-1]*M for i in range(N)]
    for i in range(N):
        s = readline().strip()
        S[i][:len(s)] = map(ord, s)

    memo = [[[[-1]*(L+2) for i in range(M+1)] for j in range(N+1)] for k in range(N+1)]
    for i in range(N+1):
        for p in range(M+1):
            for c in range(L+2):
                memo[i][i][p][c] = 1
    for i in range(N+1):
        for j in range(i+1, N+1):
            for p in range(M+1):
                memo[i][j][p][L+1] = 0
            for c in range(L+2):
                memo[i][j][M][c] = (i+1 == j)

    def dfs(l, r, p, c):
        if memo[l][r][p][c] != -1:
            return memo[l][r][p][c]
        res = dfs(l, r, p, c+1)
        for i in range(l+1, r+1):
            if (S[i-1][p] != ca + c - 1) if S[i-1][p] != cq else (c == 0):
                break
            res += dfs(l, i, p+1, 0) * dfs(i, r, p, c+1) % MOD
        memo[l][r][p][c] = res = res % MOD
        return res
    write("%d\n" % dfs(0, N, 0, 0))
solve()


Measured memory_bytes: 42344
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let n=tn(),m=tn(),sr=tss(n)
  for(let k=0;k<n;k++){
    for(let i=n-1;i>=1;i--){
      if(sr[i-1]>sr[i])[sr[i-1],sr[i]]=[sr[i],sr[i-1]]
    }
  }
  to(sr.join(''))
}
main()

Measured memory_bytes: 7500
# ABC137C_GreenBin.py
# ちなみに D は DP, E は ヘルマンフォード法 の良問。

import collections

"""
英子文字 26 個を素数で置き換えて掛け合わせると、アナグラムの組は同じ値となる。
1 <= i < j <= n であって、 si が sj のアナグラムであるようなものの個数を求める。
"""


def eratosthenes_sieve(n):
    primes = [2]
    for odd in range(3, n + 1, 2):
        for p in primes:
            if odd % p == 0:
                break
            if p ** 2 > odd:
                primes.append(odd)
                break
    return primes


# 入力と同時にアナグラムを素数の積に変換
Era = eratosthenes_sieve(150)  # 小さいほうから素数 26 個あまり用意する
chars = "abcdefghijklmnopqrstuvwxyz"  # Python では文字列もイテラブル
N = int(input())
array = [0] * N
for i in range(N):
    new = input()
    var = 1
    for j in range(10):
        h = chars.index(new[j])
        var *= Era[h]
    array[i] = var

# 加工と出力
kinds = collections.Counter(array)
kind = list(kinds.values())
print(sum(kind[i] * (kind[i] - 1) // 2 for i in range(len(kinds))))

"""
# collection モジュールのまとめ
Counter は辞書型 dict のサブクラスで、キーに要素、値に出現回数という形のデータを持つ。
キーのリスト（keys()メソッド）、値のリスト（values()）、
キーと値のペアのタプルのリスト（items()メソッド）を取得したりできる。
リストに変換したい場合はlist()を使えばよい。
"""


Measured memory_bytes: 17332
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define INF 1LL << 60
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;

int main(){
	fast_io();
	int n,k;
	cin >> n >> k;
	cout << (n-k + k - 1 - 1)/(k-1) + 1 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int n, k; cin >> n>> k;
        vector<int> v(n);
        lp(i, n) {
                cin >> v[i];
        }
        sort(all(v));
        int an= 0;
        lp(i, k) an += v[i];
        cout << an;
return 0;
}


Measured memory_bytes: 3664
## [標準入力を受け取る] ##
line = input()  # 標準入力を文字列として受け取ります
# print(line)  # for debugging
arrayed_line = line.split(" ")  # スペース区切りで与えられたものをスペースで分割して配列に格納します
# print(arrayed_line)  # for debugging
a = int(arrayed_line[0])  # 文字列を数字に変換します
b = int(arrayed_line[1])  # 文字列を数字に変換します

## [計算する] ##
ans = 0  # 答えは恐らく数字なので、まず0とします

plus = a+b  # 足し算
minus = a-b # 引き算
multiply = a*b # 掛け算

ans = plus  # 答えをとりあえず足し算の結果とする

if minus > ans:  # 引き算のほうが答え(予定)より大きければ
    ans = minus  # 答えを引き算にする

if multiply > ans:  # 掛け算のほうが答え(予定)より大きければ
    ans = multiply  # 答えを掛け算にする

## [答えを出力する] ##
print(ans)  # 答え(ans)を出力します

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    while(sc.hasNext()){
      char[] s1 = sc.next().toCharArray();
      char[] s2 = sc.next().toCharArray();
      int len1 = s1.length;
      int len2 = s2.length;

      //intテ・ツ楪凝」ツ?ァ, 4000*4000テ」ツつ津ァツ「ツコテ、ツソツ敕」ツ?凖」ツつ?-> MLE
      //shortテ・ツ楪凝」ツ?繰avaテ」ツ?ァテ、ツスツ陛」ツδ静」ツつ、テ」ツδ暗」ツ?凝、ツクツ催ヲツ伉偲」ツ??」ツ?古ィツゥツヲテ」ツ??-> MLE
      //テ、ツサツ陛ヲツ鳴ケテ」ツ?古」ツ?ェテ」ツ??」ツ?ョテ」ツ?ァテ」ツ??ゥツ?催・ツ按療ッツシツ妥ィツ。ツ古」ツつ津、ツスツソテ」ツ??・ツ崢榲」ツ?凖・ツスツ「テ」ツ?ォ
      short[][] dp = new short[2][len2 + 1];
      short maxLen = 0;

      for(int idx1 = 0; idx1 < len1; idx1++){
        int i = idx1 % 2;
        int ni = (i + 1) % 2;

        Arrays.fill(dp[ni], (short)0);

        for(int idx2 = 0; idx2 < len2; idx2++){
          if(s1[idx1] == s2[idx2]){
            dp[ni][idx2 + 1] = (short)(dp[i][idx2] + 1);
            maxLen = (short)Math.max(maxLen, dp[ni][idx2 + 1]);
          }
        }
      }

      System.out.println(maxLen);
    }
  }
}

Measured memory_bytes: 22448
/**
*    created: 27.06.2020 21:00:09
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}

signed main() {

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

    int a;
    cin >> a;
    cout << a * a * a + a * a + a << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repr(i, n) for(int i = n; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 100100100
typedef long long ll;
typedef pair<int, int> p;

int h, w, c[10][10], d[10][10], a[202][202];
long long ans = 0;

int calc(void) {
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main(void) {
	scanf("%d%d", &h, &w);
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			scanf("%d", &c[i][j]);
			d[i][j] = c[i][j];
		}
	}
	calc();
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			scanf("%d", &a[i][j]);
			if (a[i][j] == -1) continue;
			else {
				ans += d[a[i][j]][1];
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      ans += b[0];
    else if (i == n - 1)
      ans += b[n - 2];
    else
      ans += min(b[i - 1], b[i]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
#define BUF (1000)

int H,W;
char s[52][52];

typedef struct{
	int row;
	int col;
} P;

vector<P> p;

int main(void){
	cin >> H >> W;
	for(int i=0;i<H;i++){
		 cin >> s[i];
		// cout << s[i];
		 for(int j=0;j<W;j++){
			 if('#'==s[i][j]){
				P temp;
				temp.row = i;
				temp.col = j;
				p.push_back(temp);
			}else{
				s[i][j]='0';
			}
		}
	}
	while(!p.empty()){
		for(int i=max(0,p.back().row-1);i<=min(H-1,p.back().row+1);i++){
			for(int j=max(0,p.back().col-1);j<=min(W-1,p.back().col+1);j++){
				if(s[i][j]!='#') s[i][j]++;
			}	
		}
		p.pop_back();
	}
	for(int i=0;i<H;i++){
		cout << s[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int l, r;
    cin >> l >> r;
    int minimum = 2019;
    if(r - l >= 2019)
    {
        l = l % 2019;
        r = r % 2019;
        r += 2019;
    }else{
        l = l % 2019;
        r = r % 2019;
    }
    for(int i = l; i < r; i++)
    {
        for(int j = i + 1; j <= r; j++)
        {
            int temp = (i * j) % 2019;
            minimum = min(minimum, temp);
        }
    }
    cout << minimum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <map>

#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 ll;

const int N=100100;
int n;
ll m,a[N],c[N];

int main(void){
  scanf("%d%lld",&n,&m);
  REP(i,0,n){
    scanf("%lld",a+i);
    c[i+1]=c[i]+a[i];
  }
  map<ll,ll> cnt;
  REP(i,0,n+1){
    cnt[c[i]%m]++;
  }
  ll ans=0;
  for(auto e:cnt){
    ll x=e.second;
    ans+=x*(x-1)/2;
  }
  printf("%lld\n",ans);
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;

const int SIZE = 500;

int main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;

	vector<vector<int>> cost(SIZE, vector<int>(SIZE,BIG_INT));

	cost[0][0] = 0;
	for (int i = 0;i < n;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int j = SIZE - 1; j >= a;j--) {
			for (int k = SIZE - 1;k >= b; k--) {
				
				cost[j][k] = min(cost[j][k], cost[j - a][k - b] + c);
				
			}
		}

	}

	
	int ans = BIG_INT;
	int sum_a = ma;
	int sum_b = mb;
	while (sum_a < SIZE && sum_b < SIZE) {
		ans = min(ans, cost[sum_a][sum_b]);
		
		sum_a += ma;
		sum_b += mb;
	}
	if (ans == BIG_INT) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
vector<int>Z_Algorithm(const string&s) {
    int n=s.size();
    vector<int>z(n);
    int l = 0, r = 0;
    for (int i=1; i<n; i++) {
	if (i > r) {
	    l = r = i;
	    while (r<n && s[r-l] == s[r]) r++;
	    z[i] = r-l; r--;
	} else {
	    int k = i-l;
	    if (z[k] < r-i+1) z[i] = z[k];
	    else {
		l = i;
		while (r<n && s[r-l] == s[r]) r++;
		z[i] = r-l; r--;
	    }
	}
    }
    return z;
}

int N;
int A[200011];
int B[200011];
    
int X[200011][30];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);
    REP (i, N) scanf("%d", B+i);

    memset(X, -1, sizeof X);

    string s;
    REP (t, 30) {
	REP (k, 2) {
	    s.clear();
	    REP (i, N) s.push_back(((B[i]>>t&1)^k) + '0');
	    REP (i, N) s.push_back((A[i]>>t&1) + '0');
	    REP (i, N) s.push_back((A[i]>>t&1) + '0');

	    VI Z = Z_Algorithm(s);
	    for (int i=N; i<N+N; i++) {
		if (Z[i] >= N) {
		    X[i-N][t] = k;
		}
	    }
	}
    }

    REP (i, N) {
	bool yes = true;
	int ans = 0;
	REP (t, 30) {
	    if (X[i][t] == -1) {
		yes = false;
	    } else if (X[i][t] == 1) {
		ans |= 1<<t;
	    }
	}
	if (yes) {
	    printf("%d %d\n", i, ans);
	}
    }

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 31324
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N, K] = input[0].map(Number);

  const sunukes: boolean[] = [];
  let answer = N;

  for (let i = 1; i <= K * 2; i += 2) {
    const A = input[i + 1].map(Number);

    A.forEach((a) => {
      if (!sunukes[a]) {
        sunukes[a] = true;
        answer -= 1;
      }
    });
  }

  return answer;
};

console.log(main(read()));


Measured memory_bytes: 29732