akhauriyash/Code-Regression huggingface dataset:
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

int n, X, Y, w[N], c[N], fac[N], inv[N], pnt, ted;
vi COL[N], pre[N];
vector<int> G[N << 3], No;
int PRE[N];

map<int, int> cnt;

int POW(int x, int t){
	int res = 1;
	while (t){
		if (t & 1) res = res * x % MOD;
		t >>= 1;
		x = x * x % MOD;
	}
	return res;
}

int nCr(int x, int y){
	if (x < 0 || y < 0 || y > x) return 0;
	int res = fac[x];
	res *= inv[y];
	res %= MOD;
	res *= inv[x - y];
	res %= MOD;
	return res;
}

bool cmp(int x, int y){
	return w[x] < w[y];
}

int mark[N], ans;

void DFS(int v){
	mark[v] = 1;
	ted ++;
	cnt[c[v]]++;
	for (auto u:G[v]){
		if (!mark[u]) DFS(u);
	}
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> X >> Y;
	fac[0] = 1;
	inv[0] = 1;
	pnt = n + 1;
	for (int i = 1; i < N; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = POW(fac[i], MOD - 2);
	}
	for (int i = 1; i <= n; i++){
		cin >> c[i] >> w[i];
		COL[c[i]].pb(i);
	}
	for (int i = 1; i <= n; i++){
		sort(all(COL[i]), cmp);
		for (auto u:COL[i]){
			if (w[u] + w[COL[i][0]] <= X){ 
				//cout << "YES " << COL[i][0] << ' ' << u << '\n';
				G[u].pb(COL[i][0]);
				G[COL[i][0]].pb(u);
			}
		}
	}
	vector<int> node;
	for (int i = 1; i <= n; i++){
		if (COL[i].size()){
			node.pb(COL[i][0]);
		}
	}
	node.pb(0);
	node.pb(0);
	w[0] = 1000000010;
	node.pb(0);
	node.pb(0);
	sort(all(node), cmp);
	//cout << node[0] << ' ' << node[1] << '\n';
	for (int i = 1; i <= n; i++){
		if (c[i] == c[node[0]]){
			if (w[i] + w[node[1]] <= Y) G[i].pb(node[1]), G[node[1]].pb(i);
		}else{
			if (w[i] + w[node[0]] <= Y) G[i].pb(node[0]), G[node[0]].pb(i);
		}
	}
	ans = 1;
//	for (int i = 1; i <= n; i++){
//		cout << i << ": ";
//		for (auto u:G[i]) cout << u << ' ';
//		cout << '\n';
//	}
	for (int i = 1; i <= n; i++){
		if (!mark[i]){
			cnt.clear();
			ted = 0;
			DFS(i);
	
			int res = fac[ted];
			for (auto u:cnt){
				res *= inv[u.S];
				res %= MOD;
			}
			ans = ans * res % MOD;
		}
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 78704
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    ll s; cin>>s;
    cout<<0<<" "<<0<<" ";
    if(s<=(ll)(1e9)){
        cout<<s<<" "<<0<<" "<<0<<" "<<1<<endl;
        return 0;
    }
    ll x1=0, x2=(ll)(1e9)+1;
    while(x2-x1>1){
        ll x=(x1+x2)/2;
        if(x*x>=s) x2=x;
        else x1=x;
    }
    ll x=x2;
    if(x*(x-1)>=s){
        cout<<x<<" "<<1<<" "<<x*(x-1)-s<<" "<<x-1<<endl;
    }else{
        cout<<x<<" "<<1<<" "<<x*x-s<<" "<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n;cin>>n;

    ll sum=0;
    rep(i,100000){
        sum+=i;
        if(sum>=n){
            repe(j,1,i){
                if(j==sum-n)continue;
                cout<<j<<endl;
            }
            return;
        }
    }
    
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll x, y; cin >> x >> y;

    ll ans = LINF;
    if (x <= y) ans = min(ans, y - x);
    if (-x <= y) ans = min(ans, y + x + 1);
    if (x <= -y) ans = min(ans, -y - x + 1);
    if (-x <= -y) ans = min(ans, -y + x + 2);

    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
    int A,B;
    cin >> A >> B;
    int ans = 0;
    for(int i = 0;i<2;i++){
        if(A>=B){
            ans = ans + A;
            A--;
        }
        else{
            ans = ans + B;
            B--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string s = in<string>();
    cout << s[0] << s.size()-2 <<s[s.size()-1]<< "\n";
}

Measured memory_bytes: 256
# include "stdio.h"
int main(){
    int a,b,k;
    scanf("%d %d %d",&a,&b,&k);
  
  for(int i=0;i<k/2;i++){
    if(a%2)   {a--;
               b=b+a/2;
           a=a/2;
              }
    else { b+=a/2;
           a/=2;
         }
    if(b%2)  { b--;
              a+=b/2;
           b/=2;
             }
    else { a+=b/2;
           b/=2;
         }
  }
  if(k%2){
    if(a%2)   {a--;
               b+=a/2;
           a/=2;
              }
    else { b+=a/2;
           a/=2;
         }
  }
  printf("%d %d",a,b);
  return 0;
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_cols<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn exec() -> bool {
    let a1_col = read_cols::<i32>();
    let a2_col = read_cols::<i32>();
    let a3_col = read_cols::<i32>();

    let mut diff21_iter = a1_col.iter().zip(a2_col).map(|(a1, a2)| a1 - a2);

    let diff21 = diff21_iter.next().unwrap();
    if !diff21_iter.all(|d| d == diff21) {
        return false;
    }

    let mut diff31_iter = a1_col.iter().zip(a3_col).map(|(a1, a3)| a1 - a3);
    let diff31 = diff31_iter.next().unwrap();
    if !diff31_iter.all(|d| d == diff31) {
        return false;
    }

    return true;
}

fn main() {
    if exec() {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  int i, n, k;
  cin>>n>>k;
  vector<int>v(n);
  for(i=0; i<n; i++)cin>>v[i];
  sort(v.begin(), v.end());
  int sum=0;
  for(i=0; i<k; i++)sum+=v[i];
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	string S;

	cin >> S;
	int N=S.size();
	string str[2]={"",""};
	for(int i=0;i<N;i++)
	{
		if(i%2==0)
		{
			str[0]=str[0]+"0";
			str[1]=str[1]+"1";
		}
		else
		{
			str[0]=str[0]+"1";
			str[1]=str[1]+"0";
		}
	}



	int ans[2]={};
	for(int i=0;i<N;i++)
	{
		if(S[i]==str[0][i])ans[0]++;
		if(S[i]==str[1][i])ans[1]++;
	}

	ans[0]=N-ans[0];
	ans[1]=N-ans[1];

	cout << min(ans[0],ans[1]) << endl;

	return 0;
}



Measured memory_bytes: 872
char s[3333],t[3333];p[3333][3333];i,j,l;A(a){i--*l--?(a=s[i])-t[l]?A(p[i+1][l+1]-p[i][l+1]?i++:l++):putchar(a,A()):0;}main(){gets(s);for(l=strlen(gets(t));j<l?:(j=0,++i<strlen(s));j++)p[i+1][j+1]=s[i]-t[j]?fmax(p[i+1][j],p[i][j+1]):p[i][j]+1;A();}

Measured memory_bytes: 41216
#include <iostream>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	long long N, K;
	cin >> N >> K;
	priority_queue<long long,vector <long long>,greater<long long>> p;
	int tmp;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		p.push(tmp);
	}
	long long sum = 0;
	for (int j = 0; j < (N - K); j++) {
		sum +=  p.top() ;
		p.pop();
	}
	cout << sum;
		//system("pause");
}

Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    for(int i = 0;i < n;i++){
        cin >> x[i] >> y[i];
    }
    
    int ans = n;
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(i == j) continue;
            int dx = x[j]-x[i];
            int dy = y[j]-y[i];
            
            int tmp = 0;
            for(int k = 0;k < n;k++){
                for(int l = 0;l < n;l++){
                    if(k == l) continue;
                    if(dx == x[l]-x[k] && dy == y[l]-y[k]) tmp++;
                }
            }
            ans = min(ans,n-tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int n,a[3][120];
    cin>>n;
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    int ans=0,sum=0,sum2=0;
    for(int i=0;i<n;i++){
        sum+=a[0][i];
        for(int j=i;j<n;j++){
            sum2+=a[1][j];
        }
        if(sum+sum2>ans)ans=sum+sum2;
        sum2=0;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[temp.length];
		for(int i = 0; i < 3; i++) {
			list[i] = Integer.parseInt(temp[i]);
			if(list[0] > list[i]) {
				int te = list[0];
				list[0] = list[i];
				list[i] = te;
			}
		}

		int ans = 0;
		if(list[2] > list[1]) {
			ans = (list[1] - list[0]) + (list[2] - list[1]);
		}else {
			ans = (list[2] - list[0]) + (list[1] - list[2]);
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

type node struct {
	ID     int
	Height int
	Neigh  []*node
}

func dfs(nodes []*node, index int, visited map[*node]bool) int {
	if visited[nodes[index]] {
		return 0
	}

	nd := nodes[index]
	visited[nd] = true
	heighest := true
	ans := 0
	for _, ng := range nd.Neigh {
		if ng.Height >= nd.Height {
			heighest = false
			ans += dfs(nodes, ng.ID, visited)
			break
		}
	}
	if heighest {
		return ans + 1
	}
	return ans
}

func main() {
	n, m := nextInt(), nextInt()
	nodes := make([]*node, n)
	for i := 0; i < n; i++ {
		nodes[i] = &node{i, nextInt(), nil}
	}

	for i := 0; i < m; i++ {
		a, b := nextInt()-1, nextInt()-1
		nodes[a].Neigh = append(nodes[a].Neigh, nodes[b])
		nodes[b].Neigh = append(nodes[b].Neigh, nodes[a])
	}

	visited := make(map[*node]bool)
	ans := 0
	for i := 0; i < n; i++ {
		ans += dfs(nodes, i, visited)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 17300
N = int(input())
num = input().split()
num = list(map(int, num))

count = 0
abnum = []

for i in num:
    abnum.append(abs(i))
abnum.sort()

for i in num:
    if i < 0:
        count += 1

if count % 2 == 0:
    ans = sum(abnum)
else:
    ans = sum(abnum)-abnum[0]*2

print(ans)

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

int main() {
    int a,b;
    cin >> a >>b;
    int sum,diff,pro;
    sum = a +b;
    diff = a - b;
    pro = a*b;
    if(sum >= pro && sum>=diff){
        cout << sum << endl;
    }
    else if(pro>=diff){
        cout << pro << endl;
    }
    else {
        cout << diff << endl;
    }
}

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

int main() {
    int m, h;
    string deck;
    while(true) {
        cin >> deck >> m;
        if(deck == "-") break;
        for(int i = 0; i < m; ++i) {
            cin >> h;
            deck = deck.substr(h, deck.size()-h) + deck.substr(0, h);
        }
        cout << deck << endl;
    }
    return 0;
}


Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}
class point{
	static int d;
	static{
		d = Main.d;
	}
	int[] x;
	point(int... x){
		this.x = x;
	}
	boolean checkGD(point p){
		double dist = 0;
		for(int i = 0; i < d; i++){
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		}
		dist = Math.sqrt(dist);
		int idist = (int)dist;
		return (int)(dist * dist * dist * dist) == idist * idist * idist * idist;
//		return dist == dist % 1;
	}
}


Measured memory_bytes: 21972
import java.util.*;

public class Main {


    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> pos = new ArrayList<>();
        List<Integer> neg = new ArrayList<>();
        List<Integer> all = new ArrayList<>();
        int zn = 0;
        for(int i=0; i<n; i++) {
            int num = sc.nextInt();
            if(num == 0) {
                zn++;
                all.add(0);
            } else if(num > 0) {
                pos.add(num);
                all.add(num);
            } else {
                neg.add(-num);
                all.add(-num);
            }
        }
        int pn = pos.size();
        int nn = neg.size();
        Collections.sort(pos, Comparator.reverseOrder());
        Collections.sort(neg, Comparator.reverseOrder());
        Collections.sort(all);
        long[] pa = new long[pn];
        long[] na = new long[nn];

        for(int i=0; i<pn; i++) {
            pa[i] = pos.get(i);
        }
        for(int i=0; i<nn; i++) {
            na[i] = neg.get(i);
        }

        if(pn + nn < k) {
            System.out.println(0);
            return;
        }

        if( k % 2 == 0 ) {
            int a = Math.min(pn - pn%2, k);
            int b = k - a;
            if(b > nn) {
                System.out.println(min(all, k));
                return;
            }
            int ma = a;
            int mb = b;
            while(true) {
                if(a >= 2 && b+2<=nn && pa[a-1]*pa[a-2] < na[b]*na[b+1]) {
                    a-=2;
                    b+=2;
                    ma = a;
                    mb = b;
                } else {
                    break;
                }
            }
            System.out.println(calc(pa, na, ma, mb));
        } else {
            int a = pn;
            if(pn %2 == 0) {
                a--;
            }
            a = Math.min(a, k);
            int b = k-a;
            if(a < 0 || b > nn) {
                System.out.println(min(all, k));
                return;
            }
            int ma = a;
            int mb = b;
            while(true) {
                if(a >= 2 && b+2<=nn && pa[a-1]*pa[a-2] < na[b]*na[b+1]) {
                    a-=2;
                    b+=2;
                    ma = a;
                    mb = b;
                } else {
                    break;
                }
            }
            System.out.println(calc(pa, na, ma, mb));

        }


    }
    static long mod = 1000000007;
    static long min(List<Integer> list, int k) {
        long res = 1;
        for(int i=0; i<k; i++) {
            res *= list.get(i);
            res %= mod;
        }
        if(res > 0) {
            res = (mod - res) % mod;
        }

        return res;

    }
    static long calc(long[] pa, long[] na, int a, int b) {
        long res = 1;
        for(int i=0; i<a; i++) {
            res *= pa[i];
            res %= mod;
        }
        for(int i=0; i<b; i++) {
            res *= na[i];
            res %= mod;
        }
        return res;
    }


}

Measured memory_bytes: 71540
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut result = vec![vec![0; w]; h];
    let mut square = vec![];
    for _ in 0..h {
        let str: String = read();
        let row = str.chars().collect::<Vec<char>>();
        square.push(row);
    }
    for i in 0..h {
        let mut counter = 0;
        let mut start = None;
        for j in 0..w {
            if square[i][j] == '#' {
                if start.is_some() {
                    for s in start.unwrap()..j {
                        result[i][s] += counter;
                    }
                }
                start = None;
                counter = 0;
            } else if j == (w - 1) {
                counter += 1;
                if start.is_none() {
                    start = Some(j);
                }
                for s in start.unwrap()..j + 1 {
                    result[i][s] += counter;
                }
                start = None;
                counter = 0;
            } else {
                counter += 1;
                if start.is_none() {
                    start = Some(j);
                }
            }
        }
    }
    for j in 0..w {
        let mut counter = 0;
        let mut start = None;
        for i in 0..h {
            if square[i][j] == '#' {
                if start.is_some() {
                    for s in start.unwrap()..i {
                        result[s][j] += counter;
                    }
                }
                start = None;
                counter = 0;
            } else if i == (h - 1) {
                counter += 1;
                if start.is_none() {
                    start = Some(i);
                }
                for s in start.unwrap()..i + 1 {
                    result[s][j] += counter;
                }
                start = None;
                counter = 0;
            } else {
                counter += 1;
                if start.is_none() {
                    start = Some(i);
                }
            }
        }
    }
    let mut max = 0;
    for row in result {
        for cell in row {
            max = std::cmp::max(max, cell);
        }
    }
    println!("{}", max - 1);
}


Measured memory_bytes: 37116
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

long long tmp[50][50];
long long ans[50][50];
long long tmp_square[50][50];
long long a[50][50];

int M = 1000000007;

void mat_copy(long long s[50][50], long long t[50][50], int N){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            t[i][j] = s[i][j];
        }
    }
}

void mat_square(long long s[50][50], long long t[50][50], int N){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            t[i][j] = 0;
            for(int k = 0; k < N; k++){
                t[i][j] = (t[i][j] + (s[i][k] * s[k][j]) % M) % M;
            }
        }
    }

}

void mat_mult(long long s1[50][50], long long s2[50][50], long long t[50][50], int N){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            t[i][j] = 0;
            for(int k = 0; k < N; k++){
                t[i][j] = (t[i][j] + (s1[i][k] * s2[k][j]) % M) % M;
            }
        }
    }
}

/*
void print_matrix(long long m[50][50], int N){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cout << tmp_square[i][j] << " ";
        }
        cout << endl;
    }
}
*/

int main(){
    int N;
    long long K;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> a[i][j];
        }
    }

    //set ans as unit matrix
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j){
                ans[i][j] = 1;
            }else{
                ans[i][j] = 0;
            }
        }
    }
    mat_copy(a, tmp_square, N);
    long long n = K;
    while(n > 0){
        if((n & 1) == 1){
            mat_mult(ans, tmp_square, tmp, N);
            mat_copy(tmp, ans, N);
        }
        mat_square(tmp_square, tmp, N);
        mat_copy(tmp, tmp_square, N);
        n = n >> 1;
        
        //print_matrix(tmp_square, N);
        //print_matrix(ans)
        //cout << endl;

    }
    
    long long path_num = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            path_num = (path_num + ans[i][j]) % M;
        } 
    }
    
    //print_matrix(tmp_square, N);
    cout << path_num << endl;

    return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

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

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



set<ll> factor(ll N){
    ll max_a = (ll) sqrt(N);
    set<ll> factor_st;
    rep(i,max_a){
        if(N%(i+1)==0){
            factor_st.insert(i+1);
            factor_st.insert(N/(i+1));
        }
    }
    return factor_st;
}


int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N;
	cin>>N;
    ll ans=0;

    ans += factor(N-1).size()-1;
    set<ll> st;
    st = factor(N);

    for(auto v: st){
        if(v == 1) continue;
        ll n = N;
        while(n%v==0){
            n/=v;
        }
        if(n%v==1){
            ++ans;
        }
    }

    cout<<ans<<"\n";

    
	
	return 0;
}

Measured memory_bytes: 512
//Author: Rahul Purohit

#include<bits/stdc++.h>
#define vi vector<int>
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define ll  long long int
#define pi pair<ll,ll>
#define f first
#define mp make_pair
#define mod 1000000007
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
int gcd(int a, int b)
{
	if(b==0)
		return a;
	else
		return (b,a%b);
}
/*ll isp[N]={1};
void sieve(int n)
{
	isp[0]=isp[1]=0;
	for(int i=2;i<=n;i++)
	{
		if(isp[i]==1)
		{
			for(int j=i*i;j<=n;j+=i)
			{
				isp[j]==0;
			}
		}
	}
}*/
ll pow(int x,int  y,int m)
{
	ll ans=1;
	while(y!=0)
	{
		if(y%2==1)
		{
			ans=(ans*x)%m;
		}
		x=(x*x)%m;
		y/=2;
	}
	return ans;
}
template <class x>
void swap(x &a,x &b)
{
	x tp;
	tp=a;
	a=b;
	b=tp;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll r,x,d;
    cin>>r>>d>>x;
    for(auto i=0;i<10;++i)
    {
        x=r*x-d;
        cout<<x<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <pair <int, int>> vii;

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    int n;
    string s;
    cin >> n >> s;
    if (sz(s) % 2 == 1) {
        cout << "No";
        return 0;
    }
    for (int i = 0, j = sz(s) / 2; j < sz(s); ++i, ++j) {
        if (s[i] != s[j]) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const ll INF = 1e9+10;

template< typename Monoid >
struct SegmentTree{
  using F = function< Monoid(Monoid, Monoid) >;
  
  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  //SegmentTree(n,f,M1):サイズnの初期化，fは2つの苦汗の要素をマージする二項演算，M1はモノイドの単位元
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
    sz = 1;
    while(sz < n) sz<<=1;
    seg.assign(2*sz,M1);
  }

  //set(k,x):k番目の要素にxを代入
  void set(int k, const Monoid &x){
    seg[k+sz] = x;

  }
  
  //build():segTreeの構築
  void build(){
    for(int k = sz-1; k>0; --k){
      seg[k] = f(seg[2*k+0], seg[2*k+1]);
    }
  }

  //update(k,x):k番目の要素をxに変更
  void update(int k, const Monoid &x){
    k += sz;
    seg[k] = x;
    while(k>>=1) seg[k] = f(seg[2*k+0],seg[2*k+1]);
  }

  //区間[a,b)のMonoidを計算
  Monoid query(int a, int b){
    Monoid L = M1, R = M1;
    for(a += sz, b+=sz; a < b; a>>=1, b>>=1){
      if(a&1) L = f(L,seg[a++]);
      if(b&1) R = f(seg[--b],R);
    }
    return f(L,R);
  }

  //operator[k]:k番目の要素を返す
  Monoid operator[](const int &k) const{
    return seg[k+sz];
  }

};

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<PLL> v(N);
  ll ans = 0;
  rep(i,N){
    cin >> v[i].first >> v[i].second;
    ++v[i].second;
    ans = max(ans,v[i].second-v[i].first);
    v[i].second = -v[i].second;
  }
  sort(all(v));
  rep(i,N) v[i].second = -v[i].second;
  SegmentTree< PLL > rangeseg(N, [](PLL a, PLL b){
      return PLL(max(a.first,b.first),min(a.second,b.second)); }, PLL(1,INF));

  rep(i,N) rangeseg.set(i, v[i]);
  rangeseg.build();
  PLL p,q;
  p = rangeseg.query(0,N);
  ans += max(0ll,p.second-p.first);
  repp(i,1,N){
    p = rangeseg.query(0,i);
    q = rangeseg.query(i,N);
    ans = max(ans, max(0ll,p.second - p.first) + max(0ll,q.second - q.first));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5888
a, b, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ans = float('inf')
for _ in range(M):
    x, y, c = [int(i) for i in input().split()]
    ans = min(ans, A[x-1] + B[y-1] - c)
ans = min(ans, min(A)+min(B))
print(ans)


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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def solve(N: int, A: "List[int]"):
    A.sort()
    ret = A[0]
    for i in range(1, N):
        if A[i] % ret > 0:
            ret = gcd(ret, A[i])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15588
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define N 1000005
typedef long long int ll;
//const int mx=1e5+7;
//int n,m;
//vector<int> a(mx),b(mx);
// vector<int> g[mx];
// int deg[mx];
//vector<int> adj[mx];
//vector<int> ans;
//---dfs--
// bool visited[mx];
// vector<ll> val(mx,0);

// void dfs(int s,int e,int c1,int c2){
// 	if(a[s]^c1!=b[s]) {ans.push_back(s), c1^=1;}
// 	for(auto u:adj[s]){
// 		if(u!=e){
// 			dfs(u,s,c2,c1);
// 		}
// 	}
// }
//---dfs---

//---primes---
// const int N = 1e7 + 10;

// bool prime[N];
 
// int spf[N];
 
// void calc(){
// 	for(int i = 2; i<1e4; i++){
// 		if(prime[i])
// 			continue;
// 		spf[i] = i;
// 		for(int j = i * i; j < N; j += i){
// 			prime[j] = 1;
// 			spf[j] = i;
// 		}
// 	}
// 	for(int i = 2; i < N; i++)
// 		if(!spf[i])
// 			spf[i] = i;
// }

// vector<pair<int,int>> getp(int x){
// 	int curr=x;
// 	vector<pair<int,int>> ans;
// 	while(curr>1){
// 		int a=spf[curr];
// 		int count=0;
// 		while(curr%a==0){ curr/=a; count++;}
// 		ans.push_back(make_pair(a,count));
// 	}
// 	return ans;
// }

// bool ispr(int n) {
// 	if(n==1) return false;
//     for (int i=2;i*i<=n;++i){
//         if(n%i==0){
//             return false;
//         }
//     }
//     return true;
// }
//---primes---

//---segment_tree---
// int upd(int t,int val,int l,int r,int y, int z){
// 	if(y<l||y>r) return tr[val];
// 	if(l==r) return tr[val]=z;
// 	int s=(l+r)/2;
// 	upd(t^1,2*val+1,l,s,y,z);
// 	upd(t^1,2*val+2,s+1,r,y,z);
// 	if(t) tr[val]=tr[2*val+1]|tr[2*val+2];
// 	else tr[val]=tr[2*val+1]^tr[2*val+2];
// 	return tr[val];
// }
//int query(){}
//---segment_tree---

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int cnt=0;
		for(int i=0;i<n;i++){
			if(s[i]=='W') cnt++;
		}
		int ans=0;
		if(cnt>0){
			for(int i=0;i<n-cnt;i++){
				if(s[i]=='W') ans++;
			}
		}
		cout<<ans<<"\n";
 	}
}

Measured memory_bytes: 3708
#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<iostream>
#include<algorithm>//next_permutation

using namespace std;
int main() {
	vector<vector<int>> data(3, vector<int>(3));
	bool F = false;
	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < 3;j++) {
			cin >> data.at(i).at(j);
		}
	}
	int N;
	cin >> N;
	vector<int>kotae(N);
	for (int i = 0;i < N;i++) {
		cin >> kotae.at(i);
	}
	for (int k = 0;k < N;k++) {
		for (int i= 0;i < 3;i++) {
			for (int j = 0;j < 3;j++) {
				if (kotae.at(k) == data.at(i).at(j)) {
					data.at(i).at(j) = 0;
				}
			}
		}
	}
	for (int i = 0;i < 3;i++) {
		if (data.at(0).at(i) == 0 && data.at(1).at(i) == 0 && data.at(2).at(i) == 0) {
			F = true;
		}
	}
	for (int i = 0;i < 3;i++) {
		if (data.at(i).at(0) == 0 && data.at(i).at(1) == 0 && data.at(i).at(2) == 0) {
			F = true;
		}
	}
	if (data.at(0).at(0) == 0 && data.at(1).at(1) == 0 && data.at(2).at(2) == 0) {
		F = true;
	}
	if (data.at(2).at(0) == 0 && data.at(1).at(1) == 0 && data.at(0).at(2) == 0) {
		F = true;
	}
	if (F) {
		cout << "Yes";
	}
	else { 
		cout << "No"; 
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  
  map<int, int> cnt;
  cnt[0] = 1;
  ll ans = 0;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += vec[i];
    ans += cnt[sum % m];
    cnt[sum % m]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def paintable(H, W, S, i, j):
    return (i - 1 >= 0 and S[i - 1][j] == '#') or (i + 1 <= H - 1 and S[i + 1][j] == '#') or (
        j - 1 >= 0 and S[i][j - 1] == '#') or (j + 1 <= W - 1 and S[i][j + 1] == '#')


def main():
    H, W = read_h()
    S = read_v(H, typ=str)

    for i, row in enumerate(S):
        for j, c in enumerate(row):
            if c == '.':
                continue

            if not paintable(H, W, S, i, j):
                print('No')
                return

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

#define swap(a, b) do {a ^= b; b ^= a; a ^= b;} while(0)

int main()
{
        int N;
        int v[3];
        scanf("%d ", &N);
        while (N--) {
                scanf("%d %d %d ", v, v+1, v+2);
                if (v[0] > v[1])
                        swap(v[0], v[1]);
                if (v[1] > v[2])
                        swap(v[1], v[2]);
                if (v[0]*v[0] + v[1]*v[1] == v[2]*v[2])
                        printf("YES\n");
                else
                        printf("NO\n");
        }
        return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>

#define _USE_MATH_DEFINES
#include <math.h>


#include <vector>
#include <list>

#include <set>
#include <map>

#include <unordered_map>

#include <queue>
#include <stack>

#include <string>

#include <vector>

#define sqr(x) (x) * (x)

#include <algorithm>
#include <functional>

#include <bitset>

#include <functional>

#include <chrono>

typedef unsigned int u32;
typedef int i32;

typedef unsigned long long int u64;
typedef long long int i64;

typedef uint16_t u16;
typedef int16_t i16;

typedef uint8_t u8;
typedef int8_t i8;


using namespace std;
using namespace std::chrono;

struct less_key
{
    bool operator() (pair<i64, i64> p1, pair<i64, i64> p2)
    {
        return p1.first > p2.first || (p1.first == p2.first && p1.second < p2.second);
    }
};

struct pair_hash {
public:
    std::size_t operator()(const std::pair<u64, u64> &x) const
    {
        return std::hash<u64>()(x.first) ^ std::hash<u64>()(x.second);
    }
};
#include <random>

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 200005;

i64 N, Q;

i64 S[MAXN];
i64 T[MAXN];
i64 X[MAXN];
pair<i64, i64> D[MAXN];
i64 R[MAXN];

struct C {
    i64 S;
    i64 T;
    i64 X;
};

C c[MAXN];

struct less_c {
    bool operator() (const C& c1, const C& c2) const {
        return c1.X < c2.X || (c1.X == c2.X && c1.S < c2.S);
    }
};

map<i64, i64> E;

void add(pair<i64, i64> w) {
    auto sit = E.upper_bound(w.first);
    if (sit != E.begin()) {
        --sit;
    }

    i64 xs = w.first;

    if (sit != E.end()) {
        if (sit->first <= w.first && w.first <= sit->second) {
            xs = sit->first;
        }
    }


    auto eit = E.lower_bound(w.second);
}

set<pair<i64, i64>> W;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> N >> Q;

    for (i64 i = 0; i < N; i++) {
        cin >> S[i] >> T[i] >> X[i];
        C& t = c[i];
        t.S = S[i];
        t.T = T[i];
        t.X = X[i];

    }

    sort(c, c + N, less_c());

    for (i64 i = 0; i < Q; i++) {
        i64 t;
        cin >> t;
        D[i] = {t, i};
        W.insert({ t, i });
    }

    for (i64 i = 0; i < Q; i++) {
        R[i] = -1;
    }

    sort(D, D + Q);

    for (i64 i = 0; i < N; i++) {
        auto sit = W.lower_bound({ c[i].S - c[i].X, -1});
        auto eit = W.upper_bound({ c[i].T - c[i].X, -1 });

        if (sit == W.end()) {
            continue;
        }

        i64 x = -1;
        if (eit != W.end()) {
            x = eit->first;
        }

        auto it = sit;
        while (it != W.end() && (x == -1 || it->first < x)) {
            R[it->second] = c[i].X;
            W.erase(it++);
        }
    }

    for (i64 i = 0; i < Q; i++) {
        cout << R[i] << endl;
    }

    return 0;
}

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

const long MOD=998244353;
const long INF=100000000000000000;
int main(){
    long N;
    cin>>N;
    vector<long> A(N);
    for(int i=0;i<N;i++) cin>>A.at(i);
    
    long odd=0,even=0,eeven=0;
    for(int i=0;i<N;i++){
        if(A.at(i)%2!=0) odd++;
        else if(A.at(i)%4!=0) even++;
        else eeven++;
    }
    
    if(eeven>=odd || (eeven+1==odd && even==0)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

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

        long n = scanner.nextLong();
        int NUM = 26;
        int BASE = 96;

        StringBuilder builder = new StringBuilder();
        while (n > NUM) {
            int val = (int) (n % NUM);
            long tmp = n / NUM;
            if (val == 0) {
                val = NUM;
                tmp -= 1;
            }
            builder.append((char) (BASE + val));
            n = tmp;
        }
        builder.append((char) (BASE + n));
        System.out.println(builder.reverse().toString());

    }
}

Measured memory_bytes: 35812
#include <bits/stdc++.h>
using namespace std;
const long long lim=(10e8)+7;
int main(){
	//freopen ("t.txt","r",stdin);
	int h,w;
	cin>>h>>w;

	vector<vector<long long>> arr(h+1,vector<long long >(w+1,0));
	vector<string> st(h);
	for(int i=0;i<h;i++){
		cin>>st[i];
		
	}
	//cout<<lim<<"   ";
	for(int i=h-1;i>=0;i--){
		for(int j=w-1;j>=0;j--){
			if(i==h-1 && j==w-1){
				arr[i][j]=1;
				continue;
			}
				
			if(st[i][j]=='.')
			arr[i][j]=(arr[i+1][j]+arr[i][j+1])%(lim);

		}
	}
	// for(int i=0;i<=h;i++){
	// 	for(int j=0;j<=w;j++){
	// 		cout<<arr[i][j];
	// 	}
	// }
	cout<<arr[0][0];
	
return 0;
}


Measured memory_bytes: 9216
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    int a;
    bool flag = true;
    cin >> n;
    REP(i,n){
        cin >> a;
        if(a%2==0){
            if(!(a%3==0 || a%5==0)){
                flag = false;
            }
        }
    }
    if(flag)cout << "APPROVED" <<endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
package main

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

var in = newIo(bufio.NewScanner(os.Stdin))

func main() {
	in.setSplit(bufio.ScanLines)
	var n = in.nextInt()
	var v = strings.Split(in.next(), " ")
	print(solve(n, v))
}

func solve(n int, v []string) int {
	om := make(map[string]int)
	em := make(map[string]int)
	for i := 0; i < n; i += 2 {
		em[v[i]]++
	}
	for i := 1; i < n; i += 2 {
		om[v[i]]++
	}
	return min(calc(n, em, om), calc(n, om, em))
}
func min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}
func calc(n int, a map[string]int, b map[string]int) int {
	k1, v1 := maxMap(n, a, "")
	_, v2 := maxMap(n, b, k1)
	return n - v1 - v2
}
func maxMap(n int, m map[string]int, ex string) (string, int) {
	mk := ""
	mv := 0
	for k, v := range m {
		if k != ex && mv < v {
			mv = v
			mk = k
		}
	}
	return mk, mv
}

func print(result ...interface{}) {
	for _, r := range result {
		kind := reflect.TypeOf(r).Kind()
		if kind == reflect.Array || kind == reflect.Slice {
			rv := reflect.ValueOf(r)
			cnv := make([]interface{}, rv.Len())
			for i := 0; i < rv.Len(); i++ {
				cnv[i] = rv.Index(i).Interface()
			}
			print(cnv...)
		} else {
			fmt.Println(r)
		}
	}
}

type io struct {
	sc *bufio.Scanner
}

func newIo(sc *bufio.Scanner) *io {
	i := new(io)
	i.sc = sc
	i.sc.Buffer([]byte{}, math.MaxInt64)
	i.sc.Split(bufio.ScanWords)
	return i
}

func (i *io) setSplit(f bufio.SplitFunc) {
	i.sc.Split(f)
}

func (i *io) nextIntSlice(y int, delim string) [][]int {
	result := make([][]int, y)
	for j := 0; j < y; j++ {
		line := i.next()
		result[j] = perseIntSlice(strings.Split(line, delim))
	}
	return result
}

func (i *io) next() string {
	i.sc.Scan()
	return i.sc.Text()
}

func (i *io) nextInt() int {
	return perseInt(i.next())
}

func (i *io) nextLong() int64 {
	return perseLong(i.next())
}

func perseInt(s string) int {
	in, _ := strconv.Atoi(s)
	return in
}

func perseLong(s string) int64 {
	in, _ := strconv.ParseInt(s, 10, 64)
	return in
}

func perseIntSlice(s []string) []int {
	var r = make([]int, len(s))
	for i := 0; i < len(s); i++ {
		r[i] = perseInt(s[i])
	}
	return r
}


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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n,cur,cnt;
  cin>>n;
  int a[n+1];
  int ans[n+1];
  cnt=0;
  for (int i=1;i<=n;++i)
  {
  	cin>>a[i];
  }
  for (int i=n;i>0;--i)
  {
  	cur=0;
  	for (int j=2;j*i<=n;++j)
  	{
  		cur+=ans[i*j];
  	}
  	if (cur%2==a[i]%2)
  	{
  		ans[i]=0;
  	}
  	else
  	{
  		ans[i]=1;
  		++cnt;
  	}
  }
  cout<<cnt<<"\n";
  for (int i=1;i<=n;++i)
  {
  	if (ans[i]==1)
  	{
  		cout<<i<<" ";
  	}
  }
  return 0;
}

Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

table = {}
s = 0
for num in a:
    if num not in table:
        table[num] = 1
    else:
        table[num] += 1
    s += num

for i in range(q):
    frm, to = b[i], c[i]
    if frm in table:
        s += (to - frm) * table[frm]
        if to not in table:
            table[to] = table[frm]
        else:
            table[to] += table[frm]
        table.pop(frm)
    print(s)



Measured memory_bytes: 86600
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var [n,arr]= input.trim().split("\n");
arr=arr.split(" ").map(Number);
for(var i=1;i<=100;i++){
  var sum=0;
  var flag = arr.every(v=>{
     sum = sum + v - i;
     return  (sum >= 0);
  });
  if(!flag)break;
}
console.log(i-1);


Measured memory_bytes: 15592
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h,a;
  cin >> h >> a;
  int ans = 0;
  bool sur = false;
  if(h%a != 0) {
    sur = true;
  }
  ans = h/a;
  if (sur) {
    ans += 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def Roll(c, lst) :
    if c == 'N' :
        lst[0], lst[1], lst[5], lst[4] = lst[1], lst[5], lst[4], lst[0]
    elif c == 'S' :
        lst[0], lst[1], lst[5], lst[4] = lst[4], lst[0], lst[1], lst[5]
    elif c == 'E' :
        lst[0], lst[2], lst[5], lst[3] = lst[3], lst[0], lst[2], lst[5]
    elif c == 'W' :
        lst[0], lst[2], lst[5], lst[3] = lst[2], lst[5], lst[3], lst[0]
    return lst
    
import copy
dice_pre = list(map(int, input().split()))
N = int(input())
for i in range(N) :
    final_top, final_front = map(int, input().split())
    dice = copy.copy(dice_pre)
    
    for i in range(4) :
        if dice[1] == final_front :
            break
        else :
            Roll('S', dice)
    if dice[1] != final_front :
        Roll('E', dice)
        for i in range(4) :
            if dice[1] == final_front :
                break
            else :
                Roll('S', dice)
    for i in range(4) :
        if dice[0] == final_top :
            break
        else :
            Roll('E', dice)
    
    print(dice[2])
    


Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + c > 21 ? "bust" : "win") << endl;

  return 0;
}


Measured memory_bytes: 256