akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
#define TRUE 1

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }

  z->parent = y;
  if(y==NIL) root  = z;
  else if(y->key > z->key) y->left=z;
  else y->right = z;

}

void inorder(Node u){
  if(u!=NIL){
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

Node find(int k,Node u){
  if(u==NIL || u->key==k) return u;
  if(k > u->key) find(k,u->right);
  else find(k,u->left);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if(com[0]=='f'){
      scanf("%d", &x);
      Node t = find(x,root);
      if ( t != NIL ) printf("yes");
      else printf("no");
      printf("\n");
    }

    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    
  }
  return 0;
}

Measured memory_bytes: 19352
#include <bits/stdc++.h>
using namespace std;
#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++)
 
int main() {
    int n;
    cin>>n;
    string s;
    int ac=0,wa=0,tle=0,re=0;
    rep(i,n){
        cin>>s;
        if (s=="AC"){
            ac++;
        }
        else if (s=="WA"){
            wa++;
        }
        else if (s=="TLE"){
            tle++;
        }
        else{
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
def func(S):
	l = []
	# マスクパターン数(0～桁数-1(4桁なら111=7))分、周回する
	for mask in range(2 ** (len(S) - 1)):
		# マスクパターンが0になるまで周回する
		end = len(S)
		begin = end - 1
		mask_t = mask
		while(0 < mask_t):
			# マスクが0でないなら、1にヒットするまで下の桁から数える
			while(0 == mask_t & 0x01):
				mask_t >>= 1
				begin -= 1
			# 下の桁から数えて、前回～今回の桁分、加算する数のリストに加える
			l.append(int(S[begin:end]))
			# マスクを1ビット右シフトする、カウンタを保持する
			mask_t >>= 1
			end = begin
			begin = end - 1
		# 残った数を、加算する数のリストに加える
		l.append(int(S[:end]))
	return str(sum(l))

def main():
	print(func(input()))
	#print("OK" if (func("125") == "176") else "NG")
	#print("OK" if (func("9999999999") == "12656242944") else "NG")
	return

if __name__ == '__main__':
	main()


Measured memory_bytes: 3064
def BC133_E():
    n, k = map(int, input().split())
    d = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(int, input().split())
        d[a - 1].append(b - 1)
        d[b - 1].append(a - 1)
    stack = [(0, 0)]
    visited = set()
    res = []
    while stack:
        i, l = stack.pop(0)
        visited.add(i)
        c = len(set(d[i]) - visited)
        if c != 0:
            if l == len(res):
                res.append([c])
            else:
                res[l].append(c)
        for j in d[i]:
            if j not in visited: stack.append((j, l + 1))
    ans = k
    MOD = 10**9 + 7
    for i in range(len(res)):
        if i == 0:
            c = k - 1
            for m in range(res[0][0] - 1):
                c = ((k - m - 2) * c) % MOD
            ans = (ans * c) % MOD
        else:
            for j in res[i]:
                c = k - 2
                for m in range(j - 1):
                    c = ((k - m - 3) * c) % MOD
                ans = (ans * c) % MOD
    print(ans)


BC133_E()

Measured memory_bytes: 34344
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= int(m); -- (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }

constexpr int inf = 1e9 + 7;
constexpr int max_a = 50;
ll solve(int n, vector<int> const & a, vector<int> const & b) {
    // compute the costs
    array<array<int, max_a + 1>, max_a + 1> max_k = {};
    REP (i, max_a + 1) {
        REP (j, max_a + 1) {
            max_k[i][j] = inf;
        }
        max_k[i][i] = 0;
    }
    REP3R (kk, 1, max_a + 1) {
        REP (i, max_a + 1) {
            int j = i % kk;
            chmin(max_k[i][j], kk);
        }
        REP (k, max_a + 1) {
            REP (i, max_a + 1) if (max_k[i][k] != inf) {
                REP (j, max_a + 1) if (max_k[k][j] != inf) {
                    chmin(max_k[i][j], max(max_k[i][k], max_k[k][j]));
                }
            }
        }
    }
    // check trivial cases
    if (a == b) {
        return 0;
    }
    REP (i, n) {
        if (max_k[a[i]][b[i]] == inf) {
            return -1;
        }
    }
    // reconstruct
    ll answer = 0;
    vector<vector<int> > aa(n);
    REP (i, n) aa[i].push_back(a[i]);
    while (true) {
        vector<int> min_k(n, inf);
        REP (i, n) {
            REP (j, aa[i].size()) {
                chmin(min_k[i], max_k[aa[i][j]][b[i]]);
            }
        }
        int k = *max_element(ALL(min_k));
        assert (k != inf);
        if (k == 0) break;
        answer |= 1ll << k;
        REP (i, n) {
            vector<int> next_aa_i;
            REP (j, aa[i].size()) {
                for (int na : { aa[i][j], aa[i][j] % k }) {
                    if (max_k[na][b[i]] < k) {
                        next_aa_i.push_back(na);
                    }
                }
            }
            aa[i] = next_aa_i;
            sort(ALL(aa[i]));
            aa[i].erase(unique(ALL(aa[i])), aa[i].end());
        }
    }
    return answer;
}

int main() {
    int n; cin >> n;
    vector<int> a(n); REP (i, n) cin >> a[i];
    vector<int> b(n); REP (i, n) cin >> b[i];
    ll answer = solve(n, a, b);
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#import math
#import numpy as np
#import torch
#import torch.nn as nn
#import matplotlib.pyplot as plt
#from decimal import Decimal

#N=int(input())
N,K = map(int,input().split())
#B,W = map(int,input().split())
#T=int(input())
#A = list(map(int,input().split()))
#S=str(input())


for k in range(N+1):
    x=k*2 + (N-k)*4
    if x==K:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    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;
int64 a[MAXN],x,ans;
void Solve() {
    read(N);read(x);
    for(int i = 1 ; i <= N ; ++i) {
	read(a[i]);
	if(a[i] > x) {
	    ans += a[i] - x;
	    a[i] = x;
	}
    }
    int64 t = 0;
    for(int i = 2 ; i <= N ; ++i) {
	int64 m = x - a[i - 1];
	if(a[i] > m) {t += a[i] - m;a[i] = m;}
    }
    out(ans + t);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int max= 0;
		int sum = 0;
		for (int i = 0; i < 3; i++) {
			int a  = sc.nextInt();
			sum += a;
			if (max < a) {
				max = a;
			}
		}
		System.out.println(sum + 9 * max);
	}
	
	
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[5],k;
    int idx=-1;
    int b=INT_MAX;
    for(int i=0;i<5;i++){
        cin>>a[i];
        if(a[i]%10!=0){
            int x=a[i]%10;
            if(x<b){
                b=x;
                idx=i;
            }
        }
    }
    int c=0;
    for(int i=0;i<5;i++){
        if(a[i]%10==0){
            c+=a[i];
            a[i]=-1;
        }
    }
    for(int i=0;i<5;i++){
        if(a[i]!=-1&&i!=idx){
            c=c+a[i]+10-(a[i]%10);
        }
    }
    if(idx==-1){
        cout<<c<<endl;
        return 0;
    }
    cout<<c+a[idx]<<endl;
    
    return 0;
    
}



Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10000)


dx = [0, 1, 0, -1, 1, 1, -1, -1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]


def dfs(field, w, h, height, width):
    field[height][width] = 0

    for i in range(8):
        nw = width + dx[i]
        nh = height + dy[i]

        if nw < 0 or nw >= w or nh < 0 or nh >= h:
            continue
        if field[nh][nw] == 0:
            continue

        dfs(field, w, h, nh, nw)
    return


def solve():
    ans = []
    while True:
        w, h = map(int, input().split())
        if w == h == 0:
            break

        field = [list(map(int, input().split())) for _ in range(h)]
        count = 0
        for c in range(h):
            for r in range(w):
                if field[c][r] == 1:
                    count += 1
                    dfs(field, w, h, c, r)

        ans.append(count)
    print(*ans, sep="\n")


if __name__ == "__main__":
    solve()


Measured memory_bytes: 7932
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    string s;
    cin >>s;

    rep(i,s.size()){
        if(i%2==0){
            cout << s[i];
        }
    }
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int x; cin>>x;
  for(int i=-2000;i<2000;i++){
    for(int j=-2000;j<2000;j++){
      if(pow(i,5)-pow(j,5)==x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 4148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {
    static int[] set;

    static void union(int v, int u) {
        int vGroup = getGroup(v);
        int uGroup = getGroup(u);
        if(vGroup != uGroup) {
            set[vGroup] = uGroup;// i think its ok, but its better to double check, what if smth goes wrong
        }
    }

    static int getGroup(int v) {
        if(set[v] == v) {
            return v;
        }
        set[v] = getGroup(set[v]);
        return set[v];
    }

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();
        int N = fastReader.nextInt();
        int M = fastReader.nextInt();
        set = new int[N];
        for(int i = 1; i < N; i++) set[i] = i;
        for(int i = 0; i < M; i++) {
            int v1 = fastReader.nextInt() - 1;
            int v2 = fastReader.nextInt() - 1;
            union(v1, v2);
        }
        int[] sizes = new int[N];
        for(int i = 0 ; i < N; i++) {
            sizes[getGroup(i)]++;
        }

        int max = 0;
        for(int i = 0; i < sizes.length; i++) {
            if(sizes[i] > max) {
                max = sizes[i];
            }
        }

        System.out.println(max);
        //what should you do next?
        //calc number of independent groups
    }
    static final Random random=new Random();

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

vector<int> adj[234567];
vector<int> elements;
vector<int> visited;

int dfs(int src) {
	visited[src] = true;
	int cnt = 1;
	for (int node: adj[src]) {
		if (!visited[node]) {
			cnt += dfs(node);
		}
	}
	return cnt;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0, x, y; i < m; ++i) {
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	visited.resize(n+1);
	for (int i = 1; i <= n; ++i) {
		if (!visited[i]) {
			elements.push_back(dfs(i));
		}
	}
	cout << *max_element(elements.begin(), elements.end()) << endl;
	return 0;
}

Measured memory_bytes: 21860
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main(void) {
    int x;
    cin >> x;

    long i;
    for(i = 1; i * (i + 1) / 2 < x; i++);
    cout << i << endl;

    return 0;
}


Measured memory_bytes: 256
local n, m, p = io.read("*n", "*n", "*n")
local edge = {}
local len = {}
for i = 1, n do
  len[i] = {}
  edge[i] = {}
end
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  edge[i] = {a, b, c - p}
end
local len = {}
local inf = 10000000000
for i = 1, n do len[i] = -inf end
len[1] = 0
local lim = n + 4
for i = 1, lim do
  for j = 1, m do
    local src, dst, c = edge[j][1], edge[j][2], edge[j][3]
    if len[src] ~= -inf and len[dst] < len[src] + c then
      len[dst] = len[src] + c
      if i == lim then
        len[dst] = inf
      end
    end
  end
end
for i = 1, lim do
  for j = 1, m do
    local src, dst, c = edge[j][1], edge[j][2], edge[j][3]
    if len[src] == inf then
      len[dst] = inf
    end
  end
end
print(inf <= len[n] and -1 or math.max(0, len[n]))


Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int n,p=0,i;
    char s[10000];
    scanf("%d",&n);
    scanf("%s",s);
    if(n%2==0)
    {
        for(i=0;i<n/2;i++)
        {
            if(s[i]!=s[i+(n/2)])
            {
               p=1;
            }
        }
        if(p==0)
            printf("Yes");
        else
            printf("No");
    }
    else
        printf("No");
 
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Integer[] array = new Integer[m];
		int n = sc.nextInt();
		if(n%2==0) {
		System.out.println(n/2-1);
		}
		else {
			System.out.println(n/2);
		}
	}
}

Measured memory_bytes: 23764
A=[(j,i)for i in range(150)for j in range(1,i)]
A.sort(key=lambda(j,i):(i**2+j**2,j,i))
while 1:
 h,w=map(int,raw_input().split())
 if h<1:break
 h,w=A[A.index((h,w))+1];print h,w

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

int main() {
	vector<vector<char>>c(3, vector<char>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++)cin >> c.at(i).at(j);
	}
	cout << c.at(0).at(0) << c.at(1).at(1) << c.at(2).at(2) << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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 all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int a,sum = 0;
	rep(i,3){
		cin >> a;
		sum += a;
	}
	cout << (sum >= 22 ? "bust" : "win") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

template<class T>
struct CumulativeSum2D{
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}

    void add(int x, int y, T z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }

    void build(){
        for(int i = 1; i < data.size(); ++i){
            for(int j = 1; j < data[i].size(); ++j){
                data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

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

    int n, k;
    cin >> n >> k;
    CumulativeSum2D<int> S(k * 2, k * 2);
    for(int i = 0; i < n; ++i){
        int x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'B')    x += k;
        x %= k * 2, y %= k * 2;
        S.add(x, y, 1);
    }
    S.build();
    int ans = 0;
    for(int i = 0; i <= k; ++i){
        for(int j = 0; j <= k; ++j){
            int X = S.query(i, j, i + k, j + k);
            X += S.query(0, 0, i, j);
            X += S.query(i + k, 0, k * 2, j);
            X += S.query(0, j + k, i, k * 2);
            X += S.query(i + k, j + k, k * 2, k * 2);
            chmax(ans, X);
        }
    }
    for(int i = k; i <= k * 2; ++i){
        for(int j = 0; j <= k; ++j){
            int X = S.query(i, j, k * 2, j + k);
            X += S.query(i - k, 0, i, j);
            X += S.query(i - k, j + k, i, k * 2);
            X += S.query(0, j, i - k, j + k);
            chmax(ans, X);
        }
    }
    for(int i = 0; i <= k; ++i){
        for(int j = k; j <= k * 2; ++j){
            int X = S.query(i, j, i + k, k * 2);
            X += S.query(0, j - k, i, j);
            X += S.query(i + k, j - k, k * 2, j);
            X += S.query(i, 0, i + k, j - k);
            chmax(ans, X);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19004
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

int mygcd(int a, int b){
	if(b == 0) return a;
	return mygcd(b, a % b);
}

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

	int n;
	cin >> n;

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	ll g = a[0];
	rep(i, n - 1) g = mygcd(g, a[i+1]);

	if(g > 1){
		cout << "not coprime" << endl;
		exit(0);
	}

	int max_n = 5050;
	vector<bool> isprime(max_n, true);
	isprime[0] = isprime[1] = false;
	for(int i = 2; i < max_n; i++){
		if(isprime[i]){
			for(int j = 2 * i; j < max_n; j += i) isprime[j] = false;
		}
	}

	vector<int> primes;
	rep(i, max_n) if(isprime[i]) primes.push_back(i);

	set<int> stall;
	rep(i, n){
		int t = a[i];
		set<int> st;
		for(int p : primes){
			if(t % p == 0) st.insert(p);
			while(t % p == 0) t /= p;
		}

		if(t > 1) st.insert(t);

		for(int x : st){
			if(stall.count(x) == 1){
				cout << "setwise coprime" << endl;
				exit(0);
			}

			stall.insert(x);
		}
	}

	cout << "pairwise coprime" << endl;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> A;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        A.push_back(a);
    }
    vector<int> B;
    for(int i = 0; i < k; i++){
        B.assign(n+1, 0);
        for(int j = 0; j < n; j++){
            int d = A[j];
            B[max(0, j-d)]++;
            B[min(n, d+j+1)]--;
        }
        for(int j = 1; j < n; j++)B[j] += B[j-1];
        B.pop_back();
        if (A == B) break;
        swap(A, B);
    }

    for(auto a : A)cout << a << " ";
    cout << endl;
    return 0;
}

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

int main() {
  int n, k, i, max_a, count = 0, ans = 0;
  cin >> n >> k;
  vector<int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  max_a = a[n - 1];
  vector<int> c(max_a + 1, 0);
  for (i = 0; i < n; i++) {
    c[a[i]]++;
  }
  for (i = 1; i <= max_a; i++) {
    if (c[i] != 0) {
      count++;
    }
  }
  sort(c.begin(), c.end());
  i = 0;
  while (count > k) {
    if (c[i] != 0) {
      ans += c[i];
      count--;
    }
    i++;
  }
  cout << ans << "\n";
  return 0;
}

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

int main() {
  int n; cin >>n;
  int x = 0;
  for (int i=0; i<n; i++){
    int y = (i+1)*1.08/1;
    if (y==n) x = i+1;
  }
  if (x == 0) cout <<":(" <<endl;
  else cout <<x <<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        int a[100000];
        int i;
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a,a+n);
        int Min=a[0],Max=a[n-1];
        for(i=1; i<n-1; i++)
        {
            if(a[i]>=0)
                Min-=a[i];
            else
                Max-=a[i];
        }
        cout<<Max-Min<<endl;
        Max=a[n-1];
        Min=a[0];
        for(i=1; i<n-1; i++)
        {
            if(a[i]>=0)
            {
                cout<<Min<<' '<<a[i]<<endl;
                Min-=a[i];
            }
            else
            {
                cout<<Max<<' '<<a[i]<<endl;
                Max-=a[i];
            }
        }
        cout<<Max<<' '<<Min<<endl;
    }
    return 0;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

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

   vector<int> d(n);
   for(int i=0;i<n;i++){
       int x;
       cin>>x;
       d[i] = x;
   }

   int sum = 0;

   for(int i=0;i<n-1;i++){
       for(int j=i+1;j<n;j++){
           sum += d[i] * d[j];
           //cout<<sum<<" ";
       }
   }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int x[2], y[2];
   for(int i=0; i<2; ++i)
      std::cin >> x[i] >> y[i];

   int dx = x[1]-x[0];
   int dy = y[1]-y[0];
   std::cout << x[1]-dy << ' ' << y[1]+dx << ' ';
   std::cout << x[0]-dy << ' ' << y[0]+dx << std::endl;
}


Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func Min(x, y int) int {
  if x < y { return x }
  return y
}

func Pre(A *[]int, s int) int {
  N := len((*A))
  if N < 1 || s <= (*A)[0] { return -1 }
  if (*A)[N - 1] < s { return (*A)[N - 1] }
  ges, lts := N - 1, 0
  for 1 < ges - lts {
    med := (ges + lts) / 2
    if (*A)[med] < s {
      lts = med
    } else {
      ges = med
    }
  }
  return (*A)[lts]
}
func Post(A *[]int, s int) int {
  N := len((*A))
  if N < 1 || (*A)[N - 1] <= s { return -1 }
  if s < (*A)[0] { return (*A)[0] }
  gts, les := N - 1, 0
  for 1 < gts - les {
    med := (gts + les) / 2
    if s < (*A)[med] {
      gts = med
    } else {
      les = med
    }
  }
  return (*A)[gts]
}

func main() {
  A := NextLine()
  N := len(A)
  S := make([][]int, 26)
  for s := range S {
    S[s] = make([]int, 0)
  }
  for i, a := range A {
    s := int(a) - int('a')
    S[s] = append(S[s], i + 1)
  }
  Z := make([]int, N + 1)
  pos := N + 1
  for 0 < pos {
    _p := pos
    for _, s := range S {
      _p = Min(Pre(&s, pos), _p)
    }
    if _p < 0 { break }
    pos = _p
    Z[pos]++
  }
  for i := range Z[1:] {
    Z[i + 1] += Z[i]
  }
  ans := make([]rune, Z[N] + 1)
  pos = 0
  for i := range ans {
    for j, s := range S {
      z := Post(&s, pos)
      if z < 0 || Z[pos] < Z[z] {
        ans[i] = rune(j + 97)
        pos = z
        break
      }
    }
  }
  Write(string(ans))
  Output()
}

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

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<pair<int, int>> x(N);
    for(int i = 0; i < N; i++){
        int xx, yy;
        cin >> xx >> yy;
        x[i] = make_pair(xx, yy);
    }
    sort(x.begin(), x.end());
    int ans = N;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            int p = x[j].first - x[i].first;
            int q = x[j].second - x[i].second;
            vector<bool> free(N, false);
            for(int k = 0; k < N; k++){
                for(int l = k + 1; l < N; l++){
                    if(x[l].first == x[k].first + p && x[l].second == x[k].second + q) free[l] = true;
                }
            }
            int sub = N;
            for(int k = 0; k < N; k++){
                if(free[k]) sub--;
            }
            ans = min(ans, sub);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ls  (n<<1)
#define rs  (ls|1)
using namespace std;

typedef long long  LL;
int n,m,a[5010],b[5010][205],S[205][5010],T[205];
LL t[20010],tag[20010],ans;

void modify(int n,int l,int r,int L,int R,int k)
{
	if ((L<=l)&&(r<=R))  t[n]+=k,tag[n]+=k;
	else
		{
			int mid=(l+r)>>1;
			if (L<=mid)  modify(ls,l,mid,L,R,k);
			if (mid<R)  modify(rs,mid+1,r,L,R,k);
			t[n]=max(t[ls],t[rs])+tag[n];
		}
}

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=2; i<=n; i++)	 scanf("%d",&a[i]);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			scanf("%d",&b[i][j]);
	for (int i=1; i<=n; i++)
		{
			if (i>1)  modify(1,1,n,1,i-1,-a[i]);
			for (int j=1; j<=m; j++)
				{
					while ((T[j])&&(b[S[j][T[j]]][j]<b[i][j]))
						modify(1,1,n,S[j][T[j]-1]+1,S[j][T[j]],-b[S[j][T[j]]][j]),T[j]--;
					modify(1,1,n,S[j][T[j]]+1,i,b[i][j]),S[j][++T[j]]=i;
				}
			ans=max(ans,t[1]);
		}
	printf("%lld",ans);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 1000100
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}

string s;
int k;
vector<int>v;

void conv()
{
    for(int i=0;i<s.size();i++)
        v.push_back(s[i]-'0');
}
int DP[110][110][4];
int solve(int idx,int digits,bool Less)
{
    if(digits>k)
        return 0;
    if(idx==v.size())
    {
        if(digits==k)
            return 1;
        return 0;
    }
    int &ret=DP[idx][digits][Less];
    if(ret!=-1)
        return ret;
    int limit;
    if(!Less)
        limit=v[idx];
    else
        limit=9;
    int cnt=0;
    for(int i=0;i<=limit;i++)
    {
        int dig=digits;
        int LESS=Less;
        if(i!=0)
            dig++;
        if(i<limit)
            LESS=1;
        cnt+=solve(idx+1,dig,LESS);
    }
    return ret=cnt;
}


int32_t main()
{
    //freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/input/input11.txt", "r", stdin);
    //freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/output/output11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    memset(DP,-1,sizeof(DP));
    cin >> s >> k;
    conv();
    cout << solve(0,0,0);

    return 0;
}


Measured memory_bytes: 640
n = int(input())
point_t = []
f = []
ans = 0
index_0 = 0
cnt = 0
sum_of_0 = 0

for _ in range(n):
    point_t.append(int(input()))

point = sorted(point_t)

for i in range(n):
    if point[i]%10 != 0:
        if cnt == 0:
            index_0 = i
            cnt += 1
        f.append(int(point[i]%10))
if sum(f) == 0:
    print(0)
elif sum(f)%10 != 0:
    for i in range(n):
        ans += int(point[i])
    print(ans)
else:
    print(sum(point) - point[index_0])

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    int n;
    cin >> n;
    vector<pair<int,int>> v(n);
    for (auto &it: v) {
        cin >> it.first >> it.second;
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int ans = 0;
    map<int,int> diff, add;
    for (auto [x, y]: v) {
        diff[x - y]++;
        add[x + y]++;
    }
    auto rem = [&] (int v, map<int,int> &mp) {
        int t = --mp[v];
        if (!t) mp.erase(v);
    };
    auto readd = [&] (int v, map<int,int> &mp) {
        mp[v]++;
    };
    for (auto [x, y]: v) {
        rem(x - y, diff);
        rem(x + y, add);

        if (!add.empty()) {
            int now = x + y;
            auto it = add.begin();
            ans = max(ans, now - it->first);
        }
        if (!diff.empty()) {
            int now = -x + y;
            auto it = prev(diff.end());
            ans = max(ans, now + it->first);
        }
        readd(x - y, diff);
        readd(x + y, add);
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 31420
#include <bits/stdc++.h>
using namespace std;
string board[50];
const int dx[] = {1,1,0,-1,-1,-1,0,1};
const int dy[] = {0,1,1,1,0,-1,-1,-1};
int main(){
    int h,w; cin >> h >> w;
    for(int i=0; i < h; ++i) cin >> board[i];
    for(int i=0; i < h; ++i){
        for(int j=0; j < w; ++j){
            if(board[i][j] == '#') continue;
            int num=0;
            for(int k=0; k < 8; ++k){
                const int x = i + dx[k];
                const int y = j + dy[k];

                if(x < 0 || h <= x) continue;
                if(y < 0 || w <= y) continue;
                if(board[x][y] == '#') num++;
            }
            board[i][j] = char(num + '0');
        }
    }
    for(int i=0; i < h; i++) cout << board[i] << endl;
}

Measured memory_bytes: 256
if __name__=='__main__':
    n,k = map(int,input().split())
    have_okasi = [False for i in range(n)]
    for i in range(k):
        d = int(input())
        a = [int(x) for x in input().split()]
        for j in range(d):
            have_okasi[a[j]-1] = True
    print(have_okasi.count(False))

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

int color[9] = {0};

int main() {
    int N, a;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> a;
        if(a < 3200) ++color[a / 400];
        else ++color[8];
    }
    int ans = 0;
    for (int i = 0; i < 8; ++i) {
        ans += (color[i] > 0);
    }
    cout << ans + (ans == 0) << " " << ans + color[8] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, k, m;
  cin >> n >> m >> k;

  rep(i, 0, n+1){
    rep(j, 0, m+1){
      ll sum = i*m + j*n - (i*j + j*i);
      if(sum == k){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

using namespace std;

typedef vector<string> vs;
int main() {
  int n, l;
  cin >> n >> l;
  vs v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) cout << v[i];
  cout << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

d = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(d)]
T = [int(input()) for i in range(d)]
c = 26

ans = 0
L = [-1] * c

for i in range(d):
    T[i] -= 1

for i in range(d):
    ans += S[i][T[i]]
    L[T[i]] = i
    for j in range(c):
        ans -= C[j] * (i - L[j])
    print(ans)

Measured memory_bytes: 68664
if __name__=="__main__":
    n = input()
    s = list(n)
    a = int(s[0])
    b = int(s[1])
    c = int(s[2])
    d = int(s[3])

    if a+b+c+d==7:
        print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
    elif a-b-c-d==7:
        print(s[0] + "-" + s[1] + "-" + s[2] + "-" + s[3] + "=7")
    elif a-b+c+d==7:
        print(s[0] + "-" + s[1] + "+" + s[2] + "+" + s[3] + "=7")
    elif a-b-c+d==7:
        print(s[0] + "-" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
    elif a+b-c-d==7:
        print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
    elif a+b+c-d==7:
        print(s[0] + "+" + s[1] + "+" + s[2] + "-" + s[3] + "=7")
    elif a+b-c+d==7:
        print(s[0] + "+" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
    elif a-b+c-d==7:
        print(s[0] + "-" + s[1] + "+" + s[2] + "-" + s[3] + "=7")



Measured memory_bytes: 3064
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define read(a) scanf("%d", &a)
#define readf(a) scanf("%lf", &a)
#define pb push_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7;
const int N = 3e5 + 7;
const int M = 1e6 + 7;

#define lson rt << 1
#define rson rt << 1 | 1
template<class T>
class SegTree
{
public:
    T maxv[N << 2];
    void init()
    {
        mem(maxv);
    }
    inline void pushup(int rt)
    {
        maxv[rt] = max(maxv[lson], maxv[rson]);
    }
    void update(int rt, int l, int r,int pos, T val)
    {
        if(l == r)
        {
            maxv[rt] = max(maxv[rt], val);
            return;
        }
        int mid = (l + r) >> 1;
        if(pos <= mid) update(lson, l, mid, pos, val);
        else          update(rson, mid + 1, r, pos, val);
        pushup(rt);
    }

    T query(int rt, int l, int r, int L, int R)
    {
        if(L <= l && r <= R) return maxv[rt];
        int mid = (l + r) >> 1;
        T ans = 0;
        if(L <= mid) ans = max(ans, query(lson, l, mid, L, R));
        if(R > mid)  ans = max(ans, query(rson, mid + 1, r, L, R));
        return ans;
    }
};
SegTree<int> tree;

int a[N];
signed main()
{
    tree.init();
    int n, k;
    read(n); read(k);

    int ans = 0, maxx = 0;
    for(int i = 1; i <= n; i++)
    {
        read(a[i]);
        maxx = max(maxx, a[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        int l = max(0, a[i] - k);
        int r = min(maxx, a[i] + k);
        int tmp = tree.query(1, 1, maxx, l, r);
//        cout << "tmp = " << tmp << "\n";
        ans = max(ans, tmp + 1);
        tree.update(1, 1, maxx, a[i], tmp + 1);
    }
    printf("%d\n", ans);
    return 0;
}
/**
**/



Measured memory_bytes: 9668
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace ITP1_6C
{
    class Program
    {
        static void Main(string[] args)
        {
            //n????????????
            //b?£?f??????r???????????¨?±????v???

            //????????????????????????building[4][3][10]?????????
            int[,,] building = new int[4, 3, 10];
            int b, f, r, v;
            //?????????0??§?????????
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        building[i, j, k] = 0;
                    }
                }
            }
            //???????????°?????\??? n ?????£??\
            int n = int.Parse(Console.ReadLine());
            //n?????°?????????
            for (int i = 0; i < n; i++)
            {
                string[] indata = Console.ReadLine().Split(' ');
                b = int.Parse(indata[0]) - 1;
                f = int.Parse(indata[1]) - 1;
                r = int.Parse(indata[2]) - 1;
                v = int.Parse(indata[3]);
                building[b, f, r] += v;
            }
            //??????
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        Console.Write(" " + building[i, j, k]);
                        //if (k < 9) Console.Write(" ");
                    }
                    Console.Write("\n");
                }
                if (i < 3)
                    Console.WriteLine("####################");
            }
        }
    }
}

Measured memory_bytes: 9208
#active infants

n=int(input())
lists=list(map(int,input().split()))
data=[]
for i in range(n):
    data.append((lists[i],i+1))
data=sorted(data,key=lambda x:-x[0])


#dp[K][i]=始めのKつまで考えてそのうちプラスの個数がiこの方法で最大のあたい(0<=i<=K)
#求める値はmax(dp[N][i]　for i in range(N+1))で与えられる
#dp[N][N]まで考えればいい

#計算量0(N**2)
dp=[[0 for i in range(n+1)] for j in range(n+1)]

dp[1][1]=n*(data[0][0])-data[0][0]*data[0][1]
dp[1][0]=data[0][0]*data[0][1]-data[0][0]

for i in range(2,n+1):
    #dp[i]について考える
    for j in range(i+1):
        x=data[i-1][0]
        y=data[i-1][1]
        #j=0,1,,,,,iまで
        #dp[i][j]-> 直前は i-1,j-1, or i-1 j のどちらか
        if i>j>=1:
            dp[i][j]=max(dp[i-1][j-1]+x*(n+1-j)-x*y,dp[i-1][j]-(i-j)*x+x*y)
        elif j==0:
            dp[i][j]=dp[i-1][0]-i*x+x*y
        elif j==i:
            dp[i][j]=dp[i-1][i-1]+x*(n+1-j)-x*y        
K=0
for i in range(n+1):
    K=max(K,dp[n][i])
print(K)





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

#define int long long

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

	int arr[n];
	int res[n];

	for(int i = 0; i < n; i++)
		cin >> arr[i];

	res[0] = 0;
	res[1] = abs(arr[0] - arr[1]);
	for(int i = 2; i < n; i++)
		res[i] = min(res[i-1] + abs(arr[i]-arr[i-1]),
				res[i-2] + abs(arr[i]-arr[i-2]));

	cout << res[n-1] << endl;

	return 0;
}


Measured memory_bytes: 1792
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	private Integer[][] graph;
	private boolean[][] g;
	private int[] d,f;
	private int time = 0;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		g = new boolean[totalVertex][totalVertex];
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
				g[idx1][idx2] = true;
			}	
			adjList.add(tmp);
		}
		in.close();
		
		d = new int[totalVertex];
		f = new int[totalVertex];
		
		graph = new Integer[totalVertex][totalVertex];
		for(int i = 0; i < totalVertex; i++) {
			for(int x = 0; x < totalVertex; x++) {
				graph[i][x] = 0;
			}
		}
		for(int i = 0; i < adjList.size(); i++) {
			LinkedList<Integer> curr = adjList.get(i);
			for(int x = 0; x < curr.size(); x++) {
				graph[i][curr.get(x)] = 1;
			}
		}
		
		dfs(0);
		for (int i = 0; i < totalVertex; i++)
			if (d[i] == 0)
				dfs(i);
//		for(int i = 0;i < totalVertex;i++){
//            System.out.println((i + 1) + " " + d[i] + " " + f[i]);
//        }
	}
	public void printAdjMatrix() {
		for(int i = 0; i < totalVertex; i++) {
			for(int x = 0; x < totalVertex; x++) {
				if(x != totalVertex - 1) System.out.print(graph[i][x] + " ");
					else System.out.print(graph[i][x]);
			}
			System.out.println();
		}
	}
	public void dfs(int u) {
		if (d[u] > 0 || f[u] > 0)
			return;

		d[u] = ++time;
		for (int i = 0; i < totalVertex; i++)
			if (g[u][i])
				dfs(i);
		f[u] = ++time;
	}
}
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


Measured memory_bytes: 33716
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, before = 0, ans = 0, H;
    cin >> N;
    REP(i, N) {
        cin >> H;
        if (H >= before) ans++;
        before = max(before, H);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256