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

int a[101][101];
int main() {
	int r, c; cin >> r >> c;
	rep(i, r)rep(j, c)cin >> a[i][j];
	rep(i, r) {
		rep(j, c)a[i][c] += a[i][j];
	}
	rep(i, c+1) {
		rep(j, r)a[r][i] += a[j][i];
	}
	rep(i, r + 1) {
		rep(j, c + 1) {
			if (j)cout << ' ';
			cout << a[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 3096
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int c,int d){
    return d ? gcd(d, c % d) : c;
}



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

    set<string> st;
    int n; cin >> n;
    string s;
    for(int i = 0;i < n;i ++){
        cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;

}



Measured memory_bytes: 19252
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string s;
    cin >> s;
    s.at(3) = '8';
    cout << s << endl;
} 

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#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>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#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>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;


int main(){
  int N;
  cin >> N;
  vector<int> a(N+1);
  srep(i,1,N+1){
    cin >> a[i];
  }

  vector<int> ans(N+1);
  for(int i=N; i>0; i--){
    int sum=0;
    srep(j,2,N/i+1){
      sum+=ans[i*j];
    }
    if(sum%2==a[i]){
      ans[i]=0;
    }
    else{
      ans[i]=1;
    }
  }

  int M=0;
  srep(i,1,N+1){
    if(ans[i]==1){
      M++;
    }
  }
  printf("%d\n", M);
  if(M!=0){
    srep(i,1,N+1){
      if(ans[i]==1){
        printf("%d ", i);
      }
    }
    printf("\n");
  }
}


Measured memory_bytes: 2432
import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,K = map(int,input().split())
    a = np.array(list(map(int,input().split())))
    a.sort()
    posi,zero,nega = a[a>0],a[a==0],a[a<0]
    lz = len(zero)
    
    def ch(x):
        count = 0
        if x >= 0:
            count += lz*N
        count += np.searchsorted(a,x//posi,side="right").sum()
        count += (N-np.searchsorted(a,-(-x//nega))).sum()
        count -= np.count_nonzero(a**2<=x)
        return count//2

    l,r = -10**18-1,10**18
    while r-l > 1:
        mid = (r+l)//2
        if ch(mid) >= K:
            r = mid
        else:
            l = mid

    print(r)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 29380
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int w=3e5+5;
const ll mod=1e9+7;
vector<string> ve;
map<string,int> ma;
char b[w];
int main()
{
    int i,j;
    int n;
    scanf("%d",&n);
    int max1=0;
    for(i=1;i<=n;i++)
    {
        scanf("%s",b);
        string a(b);
        ma[a]++;
        if(ma[a]>max1)
        {
            max1=ma[a];
            ve.clear();
            ve.push_back(a);
        }
        else if(ma[a]==max1)
            ve.push_back(a);
    }
    sort(ve.begin(),ve.end());
    for(i=0;i<ve.size();i++)
        cout<<ve[i]<<endl;
    return 0;
}


Measured memory_bytes: 25456
(n,m) = map(int, input().split())
pys = []
for i in range(m):
    (a,b) = map(int, input().split())
    pys.append((a,b,i))

pys.sort()
ans = []
cur = -1
j = 0
for (p,y,i) in pys:
    if cur != p:
        j = 1
        cur = p
    #print(p,y,i,j)
    ans.append((i,"{:0=6}".format(p) + "{:0=6}".format(j)))
    j = j + 1

ans.sort()
for (i, a) in ans:
    print(a)


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

using namespace std;

double value[45];
int size[45];

double get_value(string &pile){
    bool b_can_move = 0, w_can_move = 0;
    double b_max, w_min;
    double last_value = 0;
    for(int i=0;i<pile.length();i++){
        double value;
        if(pile[i]=='B'){
            if(b_can_move){
                b_max = max(b_max,last_value);
            }
            else{
                b_max = last_value;
            }
            b_can_move = 1;
            if(w_can_move){
                value = (b_max + w_min) / 2;
            }
            else{
                value = b_max + 1;
            }
        }
        if(pile[i]=='W'){
            if(w_can_move){
                w_min = min(w_min,last_value);
            }
            else{
                w_min = last_value;
            }
            w_can_move = 1;
            if(b_can_move){
                value = (b_max + w_min) / 2;
            }
            else{
                value = w_min - 1;
            }
        }
        last_value = value;
    }
    return last_value;
}

//#define map unordered_map //not neccessary

void enumerate(int st, int ed,map<double,int> &table ,double value_sum = 0, int size_sum = 0){
    if(st==ed){
        if(table.count(value_sum)){
            table[value_sum] = max(table[value_sum], size_sum);
        }
        else{
            table[value_sum] = size_sum;
        }
    }
    else{
        enumerate(st+1, ed, table, value_sum, size_sum);
        enumerate(st+1, ed, table, value_sum + value[st], size_sum + size[st]);
    }
}

int find_zero_game(int st,int ed,map<double,int> &table ,double value_sum = 0, int size_sum = 0){
    if(st==ed){
        if(table.count(-value_sum)){
            return table[-value_sum] + size_sum;
        }
        else return 0;//don't use any box;
    }
    else{
        int get1 = find_zero_game(st+1, ed, table, value_sum, size_sum);
        int get2 = find_zero_game(st+1, ed, table, value_sum + value[st], size_sum + size[st]);
        return max(get1, get2);
    }
}

map<double,int> size_table;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        string pile;
        cin>>pile;
        size[i] = pile.length();
        value[i] = get_value(pile);
    }
    if(n<=20){
        enumerate(0,n,size_table);
        printf("%d\n",size_table[0]);
    }
    else{
        enumerate(0,20,size_table);
        printf("%d\n",find_zero_game(20,n,size_table));
    }

    return 0;
}

Measured memory_bytes: 68784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int l, r, B;
    cin >> l >> r;
    
    B = r - l + 1;
    A = A + B;
  }
  cout << A << endl;
}

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

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = 1000 + 10;

int a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){

	fastio();
	//inputread();
	int n; cin>>n;
	vector<int> a(n+1);
	map<int, int> o, e;
	for (int i=1; i<=n; ++i){
		 cin>>a[i];
		 if (i%2) o[a[i]]++;
		 else e[a[i]]++;
	 }
	int x, y, u, v, m = 0;
	for (auto i: o){
		if (i.second > m){
			x = i.first;
			m = i.second;
		}
	}
	o.erase(x);
	m = 0;
	for (auto i: o){
		if (i.second > m){
			y = i.first;
			m = i.second;
		}
	}
	m = 0;
	for (auto i: e){
		if (i.second > m){
			u = i.first;
			m = i.second;
		}
	}
	e.erase(u);
	m = 0;
	for (auto i: e){
		if (i.second > m){
			v = i.first;
			m = i.second;
		}
	}
	int p = 0, q = 0;
	if (x != u){
		for (int i=1; i<=n; ++i){
			if (i%2 != 0 && a[i] != x) p++;
			if (i%2 == 0 && a[i] != u) p++;
		}
		cout<<p;
	}else{
		p = 0;
		for (int i=1; i<=n; ++i){
			if (i%2 != 0 && a[i] != x) p++;
			if (i%2 != 0 && a[i] != y) q++;
			if (i%2 == 0 && a[i] != v) p++;
			if (i%2 == 0 && a[i] != u) q++;
		}
		cout<<min(p, q);
	}
	return 0;
}


Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {
	private static class UnionFind {
		int n;
		int[] p;
		int size;

		UnionFind(int n) {
			this.n = n;
			this.size = n;
			p = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
		}

		public void connect(int v, int u) {
			int rv = root(v);
			int ru = root(u);
			if (rv != ru) size--;
			p[rv] = p[ru];
		}

		public int size() {
			return size;
		}

		private int root(int v) {
			while (v != p[v]) {
				p[v] = p[p[v]];
				v = p[v];
			}
			return p[v];
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		UnionFind uf = new UnionFind(n);
		for (int i = 0; i < m; i++) {
			uf.connect(sc.nextInt() - 1, sc.nextInt() - 1);
			sc.nextInt();
		}

		System.out.println(uf.size());
	}
}


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


int main()
{
  int N;	cin >> N;
  int x[N], y[N], h[N];
  
  rep (i, N) {
    cin >> x[i] >> y[i] >> h[i];
  }
  int si = -1;
  rep(i, N) {
    if (h[i] > 0) si = i;
  }
  
  int Cx, Cy, Ch;
  rep(X,101) {
    rep(Y, 101) {
      bool ok = true;
      ll H = h[si] + abs(x[si] - X) + abs(y[si] - Y);
      rep(i, N) {
        if (h[i] > 0 && H - abs(x[i] - X) - abs(y[i] -Y) != h[i]) {
          ok = false;
        }
        if (h[i] == 0 && H > abs(x[i] - X) + abs(y[i] -Y)) {
          ok = false;
        }
      }
      if(ok) {
        Cx = X; Cy = Y; Ch = H;
        break;
      }
    }
  }
  cout << Cx << " " << Cy << " " << Ch << endl;
  return 0;
}

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


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout << "OK" <<endl;
      return 0;
    }
  }
  cout << "NG" <<endl;
  return 0;
}


Measured memory_bytes: 3600
N, M = list(map(int, input().split()))

a = []
c = []
for i in range(0, N + M):
    s = list(map(int, input().split()))
    if  i < N:
        a.append(s)
    else:
        c.append(s)

for i in range(0, N):
    min_idx = 0
    min_dis = 999999999999
    for j in range(0, M):
        dis = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if min_dis > dis:
            min_dis = dis
            min_idx = j + 1
    print(str(min_idx))

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip> 



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

using namespace std;
int a,b;

int main(){
  cin >> a >> b;
  cout << fixed << setprecision(10) << (double)a / b << endl;
  return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, r; cin >> n >> r;
    if(n>=10) cout << r << endl;
    else{
        cout << r + 100*(10-n) << endl;
    }
}

Measured memory_bytes: 3600
s = input()

S = []
for i in range(len(s)):
    S.append(s[i])

B = list(set(S))

cnt1 = 0
cnt2 = 0

if len(B) != 2:
    print('No')
else:
    for i in range(len(s)):
        if B[0] == s[i]:
            cnt1 += 1
        elif B[1] == s[i]:
            cnt2 += 1
    if cnt1 == 2 and cnt2 == 2:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 9124
# coding: utf-8
# Your code here!

while True:
   n, x = map(int, input().split())
   if n + x == 0:
      break
   
   c = 0
   li = []
   for i in range(1, n + 1):
      for j in range(i + 1, n + 1):
         for k in range(j + 1, n + 1):
            if i + j + k == x:
                  c += 1
   print(c)



Measured memory_bytes: 5604
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    string a;
    cin >> a;
    int ans = 0;
    if (a[0] == '+') {
        ans++;
    }
    else {
        ans--;
    }
    if (a[1] == '+') {
        ans++;
    }
    else {
        ans--;
    }
    if (a[2] == '+') {
        ans++;
    }
    else {
        ans--;
    }
    if (a[3] == '+') {
        ans++;
    }
    else {
        ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Identically Colored Panels Connection
 */
public class Main {

	enum COLOR {
		NONE, YELLOW, PINK, RED, PURPLE, GREEN, BLUE,
	}

	static int[][] DIR = {
			{1, 0},
			{0, 1},
			{-1, 0},
			{0, -1},
	};

	static COLOR tc;
	static int max = 0;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringTokenizer st;

			st = new StringTokenizer(line);

			int h, w;
			h = parseInt(st.nextToken());
			w = parseInt(st.nextToken());
			tc = COLOR.values()[parseInt(st.nextToken())];
			if ((h | w) == 0) break;

			COLOR[][] pane = new COLOR[h + 2][w + 2];

			for (COLOR[] pp : pane) {
				Arrays.fill(pp, COLOR.NONE);
			}

			for (int i = 0; i < h; i++) {
				st = new StringTokenizer(br.readLine());
				for (int j = 0; j < w; j++) {
					pane[i + 1][j + 1] = COLOR.values()[st.nextToken().charAt(0) - '0'];
				}
			}

			//
			max = 0;

			solve(pane, 5);

			System.out.println(max);
		}
	}

	static void solve(COLOR[][] pane, int r) {

		if (r == 0) {
			if (pane[1][1] == tc) {
				int count = 0;
				Deque<int[]> queue = new ArrayDeque<>();
				queue.offer(new int[]{1, 1});
				while (!queue.isEmpty()) {
					int[] q = queue.poll();
					for (int[] dir : DIR) {
						int ny, nx;
						ny = q[0] + dir[0];
						nx = q[1] + dir[1];
						if (pane[ny][nx] == tc) {
							pane[ny][nx] = COLOR.NONE;
							queue.offer(new int[]{ny, nx});
							count++;
						}
					}
				}
				if (count == 0) count = 1;
				max = Math.max(max, count);
			}
			return;
		}

		COLOR pc = pane[1][1];

		for (COLOR nc : COLOR.values()) {
			if (nc != COLOR.NONE && nc != pc) {
				COLOR[][] _pane = copy(pane);
				_pane[1][1] = nc;
				//
				Deque<int[]> queue = new ArrayDeque<>();
				queue.offer(new int[]{1, 1});
				while (!queue.isEmpty()) {
					int[] q = queue.poll();
					for (int[] dir : DIR) {
						int ny, nx;
						ny = q[0] + dir[0];
						nx = q[1] + dir[1];
						if (_pane[ny][nx] == pc) {
							_pane[ny][nx] = nc;
							queue.offer(new int[]{ny, nx});
						}
					}
				}
				solve(_pane, r - 1);
			}
		}
	}

	static COLOR[][] copy(COLOR[][] pane) {
		COLOR[][] _pane = new COLOR[pane.length][];
		for (int i = 0; i < pane.length; i++) {
			_pane[i] = pane[i].clone();
		}
		return _pane;
	}
}

Measured memory_bytes: 282096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
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;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

ll dp[1001][1001];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ll,N);
  AIN(ll,A,N);
  ll count = 1;
  REP(i,N){
    if(A.at(i) == count)
      count++;
  }
  if(count == 1){
    OUT(-1);
  }else{
    OUT(N - count + 1);
  }
  
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N;
  cin >> N;


  vector<vector<int>> vec(10, vector<int>(10, 0));
  FOR(i, 1, N+1){
    int M = to_string(i).size();
    int t = i/(pow(10, M-1));
    int b = i%10;
    vec[b][t]++;
  }

  int ans = 0;
  FOR(i, 1, N+1){
    int M = to_string(i).size();
    int t = i/(pow(10, M-1));
    int b = i%10;

    ans += vec[t][b];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
N,K=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i)
dp=Array.new(K+1,false)

a[0].upto(K) do |i|
  a.each do |v|
    break if i - v < 0
    if dp[i - v] == false
      dp[i] = true
      break
    end
  end
end

puts dp[K] ? "First" : "Second"

Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,x,y,s,t;
char str[8005];
vector<int> dir[2];
bitset<16005> f[2];
bool cmp(int a,int b) {
    return a > b;
}
void Solve() {
    scanf("%s",str + 1);read(x);read(y);
    N = strlen(str + 1);
    int d = 0;
    s = 0,t = 0;
    int p = 1;
    while(p <= N && str[p] == 'F') {++s;++p;}
    int cnt = 0;
    for(int i = p ; i <= N ; ++i) {
	if(str[i] == 'T') {
	    if(cnt) dir[d].pb(cnt);
	    d ^= 1;cnt = 0;
	}
	else {++cnt;}
    }
    if(cnt) dir[d].pb(cnt);
    if(abs(s - x) > N) {puts("No");return;}
    int cur = 0;
    f[cur].reset();
    f[cur][8000] = 1;
    for(auto k : dir[0]) {
	f[cur ^ 1].reset();
	f[cur ^ 1] = (f[cur] << k) | (f[cur] >> k);
	cur ^= 1;
    }
    if(!f[cur][8000 + abs(s - x)]) {puts("No");return;}
    cur = 0;
    f[cur].reset();
    f[cur][8000] = 1;
    for(auto k : dir[1]) {
	f[cur ^ 1].reset();
	f[cur ^ 1] = (f[cur] << k) | (f[cur] >> k);
	cur ^= 1;
    }
    if(!f[cur][8000 + abs(t - y)]) {puts("No");return;}
    puts("Yes");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

using namespace std;

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

#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sc(t) scanf("%d",&t)
#define sc3(t,u,v) scanf("%d %d %d",&t,&u,&v)
#define sc2(t,u) scanf("%d %d",&t,&u)
#define scL(t) scanf("%lld",&t)
#define scL3(t,u,v) scanf("%lld %lld %lld",&t,&u,&v)
#define scL2(t,u) scanf("%lld %lld",&t,&u)
#define mem(a,i) memset(a,i,sizeof a)
#define fr(i,n) for(int i=0;i<n;i++)
#define fr1(i,n) for(int i=1;i<=n;i++)
#define itr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define inf 10000007
#define endd printf("\n")
#define MAXX 100007
///unsigned int isprime[(MAXX>>6)+2];
///freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);
#define check(i) (isprime[i>>6] & (1<<((i>>1)&31)))
#define sett(i) (isprime[i>>6] |= (1<<((i>>1)&31)))
#define eps 1e-6

int h[MAXX],dp[MAXX];

int main()
{
    int n;
    sc(n);
    for(int i=0;i<n;i++) sc(h[i]);
    dp[0] = 0,dp[1] = abs(h[1] - h[0]);
    for(int i=2;i<n;i++) dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]) , dp[i-2] + abs(h[i] - h[i-2]));
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t;
	t=1;
	while(t--)
    {
        ll n;
        cin>>n;
        ll arr[n+1];
        for(int i=1;i<=n;i++)cin>>arr[i];
        ll sh=0;ll ans=0;
        for(int i=1;i<=n;i++)
        {
            if((i-sh)!=arr[i])
            {
                ans++;
                sh++;
            }
        }
        if(ans==n)
            ans=-1;
        cout<<ans;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int n;
  cin>>n;
  vector<pair<int, int>> xy[n];
  REP(i,n){
    int a;
    cin>>a;
    int x,y;
    REP(j,a){
      cin>>x>>y;
      x--;
      xy[i].push_back(make_pair(x,y));
    }
  }
  int ans = 0;
  for(int i = 0; i < (1<<n); i++){
    bool flag = true;
    REP(j,n){
      if(i & (1<<j)){//j番の人が正直者な時
        for(auto p:xy[j]){
          int x = p.first;
          int y = p.second;
          if(y == 1){
            if(i & (1<<x)){
              continue;
            }else{
              flag = false;
              break;
            }
          }else{
            if(i & (1<<x)){
              flag = false;
              break;
            }else{
              continue;
            }
          }
        }
      }
    }
    if(!flag){
      continue;
    }
    int temp = 0;
    REP(j,n){
      if(i & (1<<j)){
        temp++;
      }
    }
    ans = max(ans, temp);
  }
  
  cout<<ans<<endl;
          
  return 0; 
}


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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  --a;
  --b;
  --c;
  --d;
  auto check = [&](int a, int b) {
    for (int i = a; i < b; ++i) {
      if (s[i] == '#' && s[i + 1] == '#') {
        return false;
      }
    }
    return true;
  };
  if (!check(a, c) || !check(b, d)) {
    cout << "No" << "\n";
  } else if (c <= d) {
    cout << "Yes" << "\n";
  } else {
    for (int i = b; i <= d; ++i) {
      if (i - 1 >= 0 && i + 1 < n && s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') {
        cout << "Yes" << "\n";
        return 0;
      }
    }
    cout << "No" << "\n";
  }
  return 0;
}


Measured memory_bytes: 592
#include <stdio.h>

int di[100000];
int hi[100000];

#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(){
  int n, h; scanf("%d%d", &n, &h);
  int i;
  int pos = 0;
  int hp  = h;
  int cnt = 0;

  for(i = 0; i < n - 1; i++)
    scanf("%d%d", di+i, hi+i);

  while(1){
    int mxv = -1;
    int memohp  = 0;
    int memopos = 0;

    // printf("pos: %d, hp: %d\n", pos, hp);

    while(1){
      if(mxv <= MIN(h - hp, hi[pos])){
        mxv     = MIN(h - hp, hi[pos]);
        memohp  = hp;
        memopos = pos;
      }

      if((hp -= di[pos]) > 0){
        ++pos;
      }else{
        break;
      }

      if(pos == n - 1){
        printf("%d\n", cnt);
        return 0;
      }
    }

    pos = memopos;
    hp  = MIN(memohp + hi[pos], h);
    cnt++;
  }
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
const ll MOD =1e9 + 7;


class Combination
{
    vector<long long> fact;
    vector<long long> factinv;
    long long MOD = 1e9 + 7;
    long long modpow(long long a, long long n)
    {
        if (n == 0)
            return 1;
        if (n % 2 == 0)
        {
            long long t = modpow(a, n / 2);
            return t * t % MOD;
        }
        return a * modpow(a, n - 1) % MOD;
    }

    long long modinv(long long a)
    {
        // mod is prime
        return modpow(a, MOD - 2);
    }

public:
    Combination(int n) : fact(n), factinv(n)
    {
        fact[0] = 1;
        for (int i = 1; i < n; i++)
        {
            fact[i] = fact[i - 1] * i % MOD;
        }
        factinv[n - 1] = modinv(fact[n - 1]);
        for (int i = n - 2; i >= 0; i--)
        {
            factinv[i] = factinv[i + 1] * (i + 1) % MOD;
        }
    }

    long long ncr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }

    long long npr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[n - r] % MOD;
    }

    long long nhr(long long n, long long r)
    {
        if (n == 0 && r == 0)
            return 1;
        return ncr(n + r - 1, r);
    }
};



int main(){
	int x,y;
	int c=0;
	cin>>x>>y;
	int x1=-1,x2=-1;
	Combination comb(1010101);
	rep(i,x){
		int j=x-(i*2);
		if((2*j)+i==y){
			x1=j;
			x2=i;
			break;
		}
	}
	if(x1==-1){
		cout<<0<<endl;
		return 0;
	}else if(x1==0||x2==0){
		cout<<1<<endl;
		return 0;
	}else{
		cout<<(comb.ncr(x1+x2,x2))%MOD<<endl;
	}
	
}

Measured memory_bytes: 16000
N = int(input())
A = list(map(int,input().split()))

even_list = [i for i in A if i % 2 == 0 ]
ans = 0
for j in even_list:
    if j % 3 == 0 or j % 5 == 0:
        continue
    else:
        ans += 1
if ans == 0:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n;
	cin >> n;
	if(n%2==0) cout << n/2 << endl;
	else cout << n/2 + 1 << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9+7;

int main()
{   
    fastio
    int k;
    cin>>k;
    map<int, int>m;
    int rem = 7%k, freq = 1;  
    while(true)
    {
        if(rem==0)
        {
            cout<<freq<<endl;
            break;
        }
        if(m.find(rem)!=m.end())
        {
            cout<<-1<<endl;
            break;
        }
        m[rem]=1;
        freq++;
        rem = (10*rem + 7)%k;
    }    
}

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

using namespace std;

int a[200001];
typedef long long ll;

int main() {
	ll n, k = 0, l = 1;
	ll s = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	ll c = a[0];
	while (l < n) {
		if ((c + a[l]) == (c ^ a[l])) {
			c += a[l];
			l++;
		} else {
			s += l - k;
			c -= a[k];
			k++;
		}
	}
	ll z = l - k;
	s += z * (z + 1) / 2;
	cout << s << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

struct Edge {
  int to;
  ll cost;
};
using Graph = vector<vector<Edge>>;

vector<bool> can_reach(const Graph& G, int start) {
  ll n = G.size();
  vector<bool> ans(n);
  queue<int> que;

  que.push(start);
  ans[start] = true;

  while (!que.empty()) {
    int index = que.front();
    que.pop();
    for (const auto& it : G[index]) {
      if (ans[it.to] == false) {
        que.push(it.to);
        ans[it.to] = true;
      }
    }
  }

  return ans;
}

// Bellman Ford
// G: グラフ
// rev: 逆辺のグラフ(負の閉路検出用)
// start: 始点
// goal: 終点
// 戻り値: goalに行くまでの最小コスト。負の閉路が存在する場合は-INFとなる。
ll bellman_ford(const Graph& G, const Graph& rev, const int start, const int goal) {
  const int n = G.size();

  // 始点からそこまで行くのにかかるのコスト
  vector<ll> cost(n, INF);
  vector<ll> cost_middle;
  cost[start] = 0;

  // 閉路がなければn回のループで良いが、閉路検出用にn+1回回す
  for (int i = 0; i < n + 1; i++) {
    // すべての辺を走査
    for (int from = 0; from < n; from++) {
      if (cost[from] == INF) {
        continue;
      }
      for (auto e : G[from]) {
        // 更新
        if (cost[e.to] > cost[from] + e.cost) {
          cost[e.to] = cost[from] + e.cost;
        }
      }
    }

    // 閉路検出用
    if (i == n - 1) {
      cost_middle = cost;
    }
  }

  // 始点から到達できるか
  auto can_reach_from_start = can_reach(G, start);
  // 終点へ到達できるか
  auto can_reach_from_goal = can_reach(rev, goal);

  for (int i = 0; i < n; i++) {
    if (can_reach_from_start[i] && can_reach_from_goal[i]) {
      // 始点から終点へ移動できる経路上のノードの内、値が更新されるものが存在したら負のループが存在する。
      if (cost_middle[i] != cost[i]) {
        return -INF;
      }
    }
  }

  return cost[goal];
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m, p;
  cin >> n >> m >> p;

  Graph G(n + 1), rev(n + 1);

  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    G[a].push_back((Edge){b, -c + p});
    rev[b].push_back((Edge){a, -c + p});
  }

  ll ans = bellman_ford(G, rev, 1, n);
  ans *= -1;
  chmax(ans, 0ll);
  if (ans == INF) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
int main(){
    int N,M;
    cin >> N >> M;
    vector<int> wa(N,0);
    vector<bool> res(N,false);
    for(int i=0;i<M;i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s=="AC"){
            res[p]=true;
        }else if(!res[p]){
            wa[p]++;
        }
    }
    
    int sum_ac=0;
    int sum_wa=0;
    for(int i=0;i<N;i++){
        if(res[i]){
            sum_ac++;
            sum_wa+=wa[i];
        }
        
    }

    cout << sum_ac << " " << sum_wa << endl;


}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin>>S;
  string a="Yes";
  for(int i=0;i<S.size();i+=2) {
    if(S.at(i)=='L') {
      a="No";
      break;
    }
  }
  for(int i=1;i<S.size();i+=2) {
    if(S.at(i)=='R') {
      a="No";
      break;
    }
  }
  cout<<a<<endl;
  return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a, b;
    cin >> a >> b;
    if( a < 6 ) cout << 0 << endl;
    else if( a >= 13 ) cout << b << endl;
    else cout << b / 2 << endl;

    return 0;
}



Measured memory_bytes: 256
N,K=map(int,input().split())
l=[0]*3*N
for i in range(3*N):
    z=(i//(2*N))*(3*((i%2)*(N//2-(i%N)//2-1)+(1-i%2)*(-(i%N)//2-N%2)))
    #print(i+K,z)
#    print(i+K,(i//N+3*(i%N)+(i//N)*3*((N+1)//2)))
    l[(i//N+3*(i%N)+(i//N)*3*((N+1)//2)+z)%(3*N)] = i+K
s=("{} "*3+"\n")*N
print(-1 if 2*K-1>N else s.format(*l))
#print(%(*l))

Measured memory_bytes: 90820
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;
int num[maxn];
int prime[maxn];
int vis[maxn];
int Prime(int n) {
        int cnt = 0;
        memset(vis, 0, sizeof(vis));
        for (int i = 2; i < n; i ++) {
                if (!vis[i]) prime[cnt++] = i;
                for (int j = 0; j < cnt && i * prime[j] < n; j ++) {
                        vis[i * prime[j]] = 1;
                        if (i % prime[j] == 0) break;
                }
        }
        return cnt;
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    int cnt=Prime(2000000);
    for(int i=0;i<cnt;i++){
    	while(n%prime[i]==0){
    		n/=prime[i];
    		num[prime[i]]++;
		}
	}
	ll ans=0;
	if(n!=1)
	ans=1;
	for(int i=0;i<cnt;i++){
		int j=1;
		while(j*(j+1)/2<=num[prime[i]]){
			j++;
		}
		j--;
		ans+=j;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 15964
def main():
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]
    ans = [[0] * W for _ in range(H)]
    cur = 0
    for i in range(H):
        if "#" not in S[i]:
            continue
        cur += 1
        first = S[i].index("#")
        for j in range(W):
            if S[i][j] == "#" and j != first:
                cur += 1
            ans[i][j] = cur
    for i in range(1, H):
        if ans[i][0] == 0:
            ans[i] = ans[i-1]
    for i in range(H-2, -1, -1):
        if ans[i][0] == 0:
            ans[i] = ans[i+1]
    for i in range(H):
        print(*ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 46172
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a[10][10],c1,c2,ans,c;

void dfs(){
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      int fl=1;
      if(~a[i][j]&&!(i==n-2&&j==n-1))continue;
      if(~a[i][j])fl=0;
      r(o,2){
        if(o&&!fl)break;
        int f=0;
        if(fl)a[i][j]=o;
        if(fl)a[j][i]=o^1;
        r(k,i+1){
          c1=c2=0;
          if(k==i&&j!=n-1)continue;
          r(l,n)if(k!=l){
            if(a[k][l])c1++;
            else c2++;
          }
          if(c1!=c2)f++;
        }
        if(f)continue;
        if(i==n-2&&j==n-1)ans++;
        else dfs();
      }
      if(fl)a[i][j]=-1;
      return;
    }
  }
}

int main(){
  while(cin>>n,n){
    ans=0;
    cin>>m;
    memset(a,-1,sizeof(a));
    r(i,m){
      int x,y;
      cin>>x>>y;
      x--;y--;
      a[x][y]=1;
      a[y][x]=0;
    }
    dfs();
    cout<<ans<<endl;
  }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/05  Problem: ABC 095 C / Link: http://abc095.contest.atcoder.jp/tasks/abc095_c  ----- */


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


	LL ans = LINF;
	LL A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
	auto f = [&](LL xy) {
		LL cost = 0;
		cost += xy * C;
		X -= xy / 2;
		Y -= xy / 2;
		if (X > 0)cost += X * A;
		if (Y > 0)cost += Y * B;
		X += xy / 2;
		Y += xy / 2;
		return cost;
	};
	FOR(xy, 0, 2 * (X + Y) + 1) {
		if (xy & 1)continue;
		ans = min(ans, f(xy));
	}


	cout << (ans) << "\n";

	return 0;
}


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

int main() {
    ll x,n;
    std::cin >> x>>n;
    map<ll,bool> used;
    for (int i = 0; i < n; i++) {
        int p;
        std::cin >> p;
        used[p] = true;
    }
    
    ll mini;
    ll minv=200;
    
    for (int i = -5; i <=  200; i++) {
        if(minv>abs(x-i)&&!used[i]){
            minv = abs(x-i);
            mini = i;
        }
    }
    std::cout << mini << std::endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b;cin>>a>>b;
  if(a<=b){
    P(a);
  }else{
    P(a-1);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int main() {
  string S;
  cin >> S;
  int N, n, w, s, e;
  N=S.size();
  n=0;
  w=0;
  s=0;
  e=0;
  for (int i=0; i<N; i++) {
    if (S[i]=='N') {
      n=n+1;
    }
    else {
      if (S[i]=='W') {
        w=w+1;
      }
      else {
        if (S[i]=='S') {
          s=s+1;
        }
        else {
          e=e+1;
        }
      }
    }
  }
  if (n==0 && s==0) {
    if (w!=0 && e!=0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    if (n==0||s==0) {
      cout << "No" << endl;
    }
    else {
      if (w==0 && e==0) {
        cout << "Yes" << endl;
      }
      else {
        if (w==0||e==0) {
          cout << "No" << endl;
        }
        else {
          cout << "Yes" << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	int i;
	for(i=0;i<n;i++)
		cin>>arr[i];
	int dp[n]={0};
    dp[0]=arr[0];
    dp[1]=abs(arr[1]-arr[0]);
    dp[2]=min(abs(arr[0]-arr[2]),abs(arr[2]-arr[1])+dp[1]);
    for(i=3;i<n;i++)
    	dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 4332
import java.util.*;
public class Main {

		static void solve() {
			Scanner sc = new Scanner(System.in);
			int a =sc.nextInt();
			int b =sc.nextInt();
			int res = (b-a)*(b-a+1)/2;
			System.out.println(res -b);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

}

Measured memory_bytes: 21460
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll MOD = 1e9 + 7;

// ll C[2005][2005];
// ll dp[100005][13];

// d: 現在のケタ数
// val: 現在の値
// all: ここに格納していく (参照型にしておく)
void rec(ll d, ll val, vector<ll> &all) {
    all.push_back(val);

    if(d == 10) return;

    for(int j=-1; j<= 1; j++){
        int add = val % 10 + j;
        if(add >=0 && add <= 9) rec(d+1, val*10+add, all);
    }

}

int main(){
    ll ans=0;
    ll N,K;
    cin >> K;
    vector<ll> all;    
    for(int v=1; v<10; v++) rec(1,v,all);

    sort(all.begin(), all.end());

    cout << all[K-1] << endl;
}

Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Security.Cryptography;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Split(' ');
            int N = int.Parse(S[0]);
            int M = int.Parse(S[1]);

            string[] H = Console.ReadLine().Split(' ');

            Dictionary<int, Tower> dict = new Dictionary<int, Tower>();

            for (int i = 1; i < N+1; i++)
            {
                dict.Add(i, new Tower { Hight = int.Parse(H[i-1])} );
            }

            for (int i = 0; i < M; i++)
            {
                string[] pair = Console.ReadLine().Split(' ');
                int A = int.Parse(pair[0]);
                int B = int.Parse(pair[1]);
                dict[A].nodeDest.Add(B);
                dict[B].nodeDest.Add(A);
            }

            int cnt = 0;
            for (int i = 1; i < N+1; i++)
            {
                if (!dict.ContainsKey(i)) continue;

                if (dict[i].nodeDest.Count == 0)
                {
                    cnt++;
                    continue;
                }

                int nowHight = dict[i].Hight;
                bool flag = true;
                foreach (int dest in dict[i].nodeDest)
                {
                    if (dict.ContainsKey(dest))
                    {
                        if (dict[dest].Hight >= nowHight)
                        {
                            flag = false;
                            break;
                        }
                    }
                }
                if(flag) cnt++;

                //dict.Remove(i);
            }

            Console.WriteLine(cnt);

        }

        class Tower
        {
            public int Hight = 0;
            public List<int> nodeDest = new List<int>();
        }
    }
}


Measured memory_bytes: 59188
N, K = map(int, input().split())
H = list(map(int, input().split()))
C = [0]*N
for i in range(1, N):
  j = max(0, i-K)
  C[i] = min([c + abs(H[i]-h) for c, h in zip(C[j:i], H[j:i])])
print(C[N-1])

Measured memory_bytes: 13980
n, k = map(int, input().split())
d = [1] * n
for _ in range(k):
    int(input())
    for x in list(map(int, input().split())):
        d[x - 1] = 0
ans = 0
for i in range(n):
    if d[i]:
        ans += 1
print(ans)


Measured memory_bytes: 67556