akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define    ll     long long int

int f(ll a, ll b)
{
    int da = log10(a) + 1;
    int db = log10(b) + 1;
    return max(da, db);
}

int main( )
{
    ll n, i, j, k;
    int mn = 12;
    cin >> n;
    ll root = sqrt(n);
    for (i = 1; i <= root; i++) {
        if (n % i == 0) {
            j = n / i;
            mn = min(mn, f(i, j));
        }
    }
    cout << mn << '\n';
    return 0;
}



Measured memory_bytes: 512
// AOJ 2232: Ennichi
// 2017.11.10 bal4u@uu

#include <stdio.h>
#include <string.h>

char m0[32][32]; int h, w, n;
char m[32][32], f[32][32];

int check()
{
	int r, c, k, x, g, rr, cc;

	while (1) {
		for (c = 0; c < w; c++) for (r = h-1; r > 0; r--) if (m[r][c] == '.') {
			for (rr = r-1; rr >= 0; rr--) if (m[rr][c] != '.') { m[r][c] = m[rr][c], m[rr][c] = '.'; break; }
		}
		for (c = 0; c < w; c++) if (m[h-1][c] != '.') break;
		if (c == w) return 1;

		memset(f, 0, sizeof(f));

		g = 0;
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) if ((k = m[r][c]) != '.') {
			for (x = 0, rr = r; rr <  h && m[rr][c] == k; rr++) x++;
			if (x >= n) { g = 1; for (rr = r; rr <  h && m[rr][c] == k; rr++) f[rr][c] = 1; }

			for (x = 0, cc = c; cc <  w && m[r][cc] == k; cc++) x++;
			if (x >= n) { g = 1; for (cc = c; cc <  w && m[r][cc] == k; cc++) f[r][cc] = 1; }
		}
		if (!g) return 0;
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) if (f[r][c]) m[r][c] = '.';
	}
	return 0;
}

int main()
{
	int r, c;

	scanf("%d%d%d", &h, &w, &n);
	for (r = 0; r < h; r++) scanf("%s", m0[r]);
	for (r = 0; r < h; r++) for (c = 0; c < w-1; c++) if (m0[r][c] != m0[r][c+1]) {
		memcpy(m, m0, sizeof(m));
		m[r][c+1] = m0[r][c], m[r][c] = m0[r][c+1];
		if (check()) { puts("YES"); return 0; }
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 1824
#include<iostream>

using namespace std;

long int abs_(long int x){
    if (x > 0) {
        return x;
    }else{
        return -x;
    }
    
}

int main(){
    int n;
    cin >> n;
    long int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    bool flag0 = false;
    int mcount = 0;
    long int sm = 0;
    long int mn = 1000000001;
    for(int i = 0; i < n; i++){
        if (a[i] == 0) {
            flag0 = true;
        }
        if (a[i] < 0) {
            mcount++;
        }
        if (abs_(a[i]) < mn) {
            mn = abs_(a[i]);
        }
        sm += abs_(a[i]);
    }
    // cout << mn << '\n';
    // cout << sm << '\n';
    // cout << mcount << '\n';
    if (flag0) {
        cout << sm << '\n';
    }else if (mcount % 2 == 0) {
        cout << sm << '\n';
    }else if (mcount % 2 == 1) {
        cout << sm - 2 * mn << "\n";
    }
    
    
    
}

Measured memory_bytes: 1024
import Data.List

ans i =
  let s = map sort i
      t = takeWhile (\[a,b,c] -> a+b > c) s
      n = filter (\[a,b,c] -> a*a+b*b == c*c) t
      e = filter (\[a,b,c] -> a*a+b*b >  c*c) t
      d = filter (\[a,b,c] -> a*a+b*b <  c*c) t
  in
    [length t, length n, length e, length d]

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  putStrLn $ unwords $ map show o

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

int main() {
  int N,Y;
  cin >> N >> Y;
  
  if (10000 * N == Y) {
    cout << N << ' ' << 0 << ' ' << 0 << endl;
    return 0;
  } else {
    for (int i = 0; i < N + 1; i++) {
      if (10000 * i + 5000 * (N - i)  == Y) {
        cout << i << ' ' << (N - i) << ' ' << 0 << endl;
        return 0;
      } else if (10000 * i < Y) {
        for (int j = 0; j < N + 1 - i; j++) {
          if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
            cout << i << ' ' << j << ' ' << (N - i - j) << endl;
            return 0;
          }
        }
      }
    }
  }
  
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;

  return 0;
}

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

char s[500010],t[500010];
int left[500010],right[500010];
int main(){
	scanf("%s%s",s,t);
	int sn=strlen(s);
	int tn=strlen(t);
	
	int cnt=0;
	for(int i=0;i<sn;i++){
		if(s[i]==t[cnt])cnt++;
		left[i]=cnt;
	}

	cnt=tn;
	right[sn]=tn;
	for(int i=sn-1;i>=0;i--){
		if(cnt&&s[i]==t[cnt-1])cnt--;
		right[i]=cnt;
	}
	
	if(left[sn-1]!=tn){
		puts("no");
		return 0;
	}
	
	for(int i=0;i<sn;i++)if(s[i]==t[left[i]-1]&&(i==0||left[i-1]!=left[i])){
		if(right[i+1]<left[i]){
			puts("no");
			return 0;
		}
	}
	
	puts("yes");
}


Measured memory_bytes: 6604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
  cin >> n;
  n %= 10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
    cout << "hon" << endl;
  }else if(n == 3){
    cout << "bon" << endl;
  }else{
    cout << "pon" << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define pii pair<int, int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-10;
const int maxn = 1e5 + 7;
const int maxm = 5e5 + 10;
ll w[maxn], v[maxn];
ll dp[maxn] = {0};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> w[i] >> v[i];
    for (int i = 0; i < n; ++i)
    {
        for (int j = m; j >= w[i]; --j)
        {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    cout << dp[m] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = m;
    for(int i = 0; i <= n - m; i++){
        int cnt = 0;
        for(int j = 0; j < m; j++){
            if(s[i + j] != t[j]){
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    println(max(a+b, max(a-b, a*b)))
    return 0;
}

Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  int ret = 1900 * m + (n - m) * 100;
  while (m--) ret *= 2;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
def is_kaibun(s):
    front = 0
    back = len(s) - 1
    for _ in range(len(s)//2):
        if s[front] != s[back]:
            return False
        front += 1
        back -= 1
    return True

s = input()
n = len(s)
if is_kaibun(s) and is_kaibun(s[0:int((n-1)/2)]) and is_kaibun(s[int((n+3)/2)-1:n+1]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    string s;cin>>s;
    string t;cin>>t;
    ll a=0;
    rep(i,0,s.size()-1){
        if(s[i]==t[i])a++;
    }
    cout<<a<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

//#include <set>
//#include <unordered_map>
//#include <stack>

using namespace std;

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

#define max_n 100
int M1, D1;
int M2, D2;


int main() {

	cin >> M1 >> D1;
	cin >> M2 >> D2;

	if(D2==1)cout << "1" << endl;
	else cout << "0" << endl;

	return 0;
}


Measured memory_bytes: 256
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  t.o((t.n()-1)*(t.n()-1))
}
main()

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll q, a, b, c = 0, n, sl = 0, sr = 0;
    priority_queue <ll, vll, greater <ll> > r;
    priority_queue <ll> l;
    cin >> q;
    while(q--)
    {
        cin >> n;
        if(n == 1)
        {
            cin >> a >> b;
            c += b;
            if(l.size() == r.size())
            {
                if(l.size() == 0)
                {
                    l.push(a);
                    sl += a;
                    continue;
                }
                if(r.top() >= a)
                {
                    l.push(a);
                    sl += a;
                }
                else
                {
                    ll t1 = r.top();
                    r.pop();
                    r.push(a);
                    sr += a - t1;
                    l.push(t1);
                    sl += t1;
                }
            }
            else
            {
                if(l.top() <= a)
                {
                    r.push(a);
                    sr += a;
                }
                else
                {
                    ll t1 = l.top();
                    l.pop();
                    l.push(a);
                    sl += a - t1;
                    r.push(t1);
                    sr += t1;
                }
            }
        }
        else
        {
            ll ans = sr - sl + (l.size() - r.size()) * l.top() + c;
            cout << l.top() << ' ' << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;


struct LCA{
  int ln;
  vvi *G, parent;
  vi depth;
  void dfs(int pos, int pre, int d){
    depth[pos] = d;
    each(itr, (*G)[pos]){
      if(pre == *itr) continue;
      parent[0][*itr] = pos;
      dfs(*itr, pos, d+1);
    }
  }
  int root(int a, int b){
    if(depth[a] > depth[b]) swap(a, b);
    int d = depth[b] - depth[a];
    FOR(i, 0, ln) if((1<<i)&d) b = parent[i][b];
    if(a == b) return a;
    FORR(i, ln-1, 0) if(parent[i][a] != parent[i][b]) a = parent[i][a], b = parent[i][b];
    return parent[0][a];
  }
  void build(vvi* G, int r){
    this->G = G;
    int n = sz(*G);
    for(ln = 0; (1<<ln) < n; ln++);
    parent = vvi(n);
    FOR(i, 0, ln) parent[i] = vi(n);
    depth = vi(n);
    dfs(r, -1, 0);
    FOR(i, 1, ln)FOR(j, 0, n) parent[i][j] = (parent[i-1][j] == -1 ? -1 : parent[i-1][parent[i-1][j]]);
  }
};

vvi G;
int n, a, b;
LCA lca;

int dfs(int pos, int pre){
  int ret = 1;
  each(itr, G[pos])if(*itr != pre) ret += dfs(*itr, pos);
  return ret;
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  G.resize(n);
  FOR(i, 1, n){
    cin >> a >> b;
    a--; b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  lca.build(&G, 0);
  int pos = n-1;
  FOR(i, 0, (lca.depth[n-1]-1)/2) pos = lca.parent[0][pos];
  int c = dfs(pos, lca.parent[0][pos]);
  cout << (n-c > c ? "Fennec" : "Snuke") << endl;
  return 0;
}


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


int A, B, M;
vector<int> a, b, c, x, y;


void input() {
    cin >> A >> B >> M;
    a = vector<int>(A);
    b = vector<int>(B);
    x = y = c = vector<int>(M);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, M) cin >> x[i] >> y[i] >> c[i];
}


int main() {
    input();
    int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    rep(i, M) {
        int v = a[x[i]-1] + b[y[i]-1] - c[i];
        ans = min(ans, v);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2176
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	a := getNextInt(scanner)
	b := getNextInt(scanner)
	c := getNextInt(scanner)

	ans := a + b + c
	max := a
	if max < b {
		max = b
	}
	if max < c {
		max = c
	}
	fmt.Fprintln(writer, ans+9*max)

	writer.Flush()
}


Measured memory_bytes: 640
# /user/bin/python
# -*- coding: utf-8 -*-
import sys
 
a,b,k = map(int, sys.stdin.readline().rstrip().split())
 
ans = []
 
for i in range(1, min(a,b)+1):
  if (a % i == 0) and (b % i == 0):
    ans.append(i)
 
print(ans[k*(-1)])


Measured memory_bytes: 2940
import sys

sys.setrecursionlimit(200000)

n, u, v = map(int, input().split())

# nodeの値を-1しておく
u = u-1
v = v-1

# Making Adjacency list
Adj_dict = {}
for i in range(n):
    new = {i: []}
    Adj_dict.update(new)

for _ in range(n-1):
    a, b = map(int, input().split())
    Adj_dict[a-1].append(b-1)
    Adj_dict[b-1].append(a-1)

def tree_distance(Adj_dict, start, Visited, distance, Dist_list):
    
    # 現在いる位置を Visited = True に変更する
    Visited[start] = True

    # 該当するnodeの距離を記録して、distanceを1加算する
    Dist_list[start] = distance
    distance += 1

    # 訪れていないnodeに対して、dfs
    for node in Adj_dict[start]:
        if Visited[node] == False:
            tree_distance(Adj_dict, node, Visited, distance, Dist_list)
    
    return


Dist_list = [0 for _ in range(n)]
Visited = [False for _ in range(n)]
distance = 0
tree_distance(Adj_dict, u, Visited, distance, Dist_list)
Taka = Dist_list

Dist_list = [0 for _ in range(n)]
Visited = [False for _ in range(n)]
distance = 0
tree_distance(Adj_dict, v, Visited, distance, Dist_list)
Aoki = Dist_list

Taka_num = 0
node = 0
ans = 0
for i in range(n):
    if Aoki[i] > Taka[i]:
        ans = max(ans, Aoki[i]-1)


print(ans)

Measured memory_bytes: 117084
import java.io.*;
import java.util.*;

public class Main {

	
	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		PrintWriter out=new PrintWriter(System.out);
	//	int t=in.nextInt();
	//	while(t-->0)
		solve(in,out);
		out.close();
	}

    static void solve(FastScanner in,PrintWriter out){
     int n=in.nextInt();
     int a[]=new int[n];
     a=in.readArray(n);
     sort(a);
     int ans=0;
     for(int i=0;i<n;i++){
         for(int j=i+1;j<n;j++){
             for(int k=j+1;k<n;k++){
                 if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]) ans++;
             }
         }
     }
     out.println(ans);
    }    
	



	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


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

N, M = map(int, input().split())
graph1 = [[False]*N for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph1[a-1][b-1] = True
    graph1[b-1][a-1] = True

graph = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i!=j and not graph1[i][j]:
            graph[i].append(j)


checked = [-1]*N
Color = [None]*N

def bfs(start):
    q = [start]
    checked[start] = start
    Color[start] = 0
    color = 0
    Cs = [1, 0]
    while q:
        qq = []
        color ^= 1
        for p in q:
            for np in graph[p]:
                if checked[np] == -1:
                    checked[np] = start
                    Color[np] = color
                    qq.append(np)
                    Cs[color] += 1
                elif checked[np] == start and color != Color[np]:
                    return [-1, -1]
        q = qq
    return Cs

def main():
    Dif = []
    for i in range(N):
        if checked[i] == -1:
            a, b = bfs(i)
            if a == -1:
                print(-1)
                return
            Dif.append(abs(a-b))
    dp = [False]*(N+1)
    dp[0] = True
    for d in Dif:
        for j in reversed(range(d, N+1)):
            dp[j] = dp[j] or dp[j-d]

    min_dif = 10**15
    S = sum(Dif)
    for j in range(N+1):
        if dp[j]:
            min_dif = min(min_dif, abs(S-j*2))
    
    t1 = (N+min_dif)//2
    t2 = (N-min_dif)//2
    print(t1*(t1-1)//2 + t2*(t2-1)//2)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20980
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int N = n;
        int sum = 0;
        while (0 < n) {
            sum += n % 10;
            n /= 10;
        }

        if(N % sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.InputMismatchException;

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

	public Main() {
		FasterScanner sc = new FasterScanner(System.in);

		long n = sc.nextLong();
		long k = sc.nextLong();
		n = n%k;
		HashSet<Long> done = new HashSet<Long>();
		long min = n;
		while(!done.contains(n)) {
			done.add(n);
			n = Math.abs(n-k);
			min = Math.min(n, min);
		}
		System.out.println(min);
				
		sc.close();
	}
	
	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void close() {
			try {
				mIs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


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

int main(){
  long long X;
  long long K;
  long long D;
  cin >> X >> K >> D;
  long long N = X/D;
  if(X < 0) X *= -1, N *= -1;
  if(D <= X/K) cout << X-K*D << endl;
  else{
    if((N-K)%2 == 0) cout << X%D << endl;
    else cout << D-X%D << endl;
  }
}

Measured memory_bytes: 3612
N=int(input())
S=[]
M=[]
A=[]
R=[]
C=[]
H=[]
for s in range(N):
    name = input()
    S.append(name)
for s in S:
    first=s[0]
    if first == "M":
        M.append(s)
    if first == "A":
        A.append(s)
    if first == "R":
        R.append(s)
    if first == "C":
        C.append(s)
    if first == "H":
        H.append(s)
m=len(M)
a=len(A)
r=len(R)
c=len(C)
h=len(H)
ans= m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(ans)

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

#define QUEUE_SIZE 10000
#define next(a) (((a)+1)%QUEUE_SIZE)
int queue[QUEUE_SIZE];
int front;
int rear;

int v[51];
void init(){
	for(int k=0;k<51;k++)v[k]=0;
}
int count(){
	int sum=0;
	for(int k=0;k<51;k++){
		if(v[k]==1)sum++;
	}
	return sum;
}
int main(void){
	int n,m,i,j,ans=0;
	scanf("%d%d",&n,&m);
	int a[m],b[m];
	for(i=0;i<m;i++)scanf("%d %d",&a[i],&b[i]);
	void dfs(int x,int y){
		int i;
		if(v[x]==1)return;
		v[x]=1;
		for(i=0;i<m;i++){
			if(i==y)continue;
			if(x==a[i])dfs(b[i],y);
			if(x==b[i])dfs(a[i],y);
		}
		return;
	}
	for(i=0;i<m;i++){
		//a[i]についてdfs
		init();
		dfs(a[i],i);
		//printf("count = %d\n",count());
		if(count()!=n){
			ans++;
			continue;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int a[105];

int main(){
    int n,x;
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
    sort(a,a+n);
    int ans;
    for(ans=0;ans<n && x>=a[ans];ans++) x-=a[ans];
    if(x>0 && ans==n) ans--;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

res = [0]*10
for i in range(10):
    cnt = C[i]
    while 1:
        prev = [cnt[j] for j in range(10)]
        for k in range(10):
            for l in range(10):
                a = prev[l]+C[l][k]
                if cnt[k] > a:
                    cnt[k] = a
        if prev == cnt or min(cnt[:i]+cnt[i+1:]) == cnt[1]:
            break
    res[i] = cnt[1]
ans = 0
for a in A:
    for x in a:
        if x != -1:
            ans += res[x]
print(ans)

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

int main()
{
    int N;
    cin >> N;
    int j[N],dp[N];
    for(int i=0;i<N;i++)
    {
        cin >> j[i];
    }
    memset(dp,0,sizeof(dp));

    dp[0]=0;
    dp[1]=abs(j[1]-j[0]);
    for(int i=2;i<N;i++)
    {
        dp[i] = min(dp[i-1] + abs(j[i] - j[i-1]), dp[i-2] + abs(j[i] - j[i-2])); 
    }

    cout << dp[N-1] << endl;
    
    return 0;
}

Measured memory_bytes: 4400
import java.util.Scanner;

public class Main {

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

        int inputInt;
        int i = 1;
        for (;;) {
            inputInt = Integer.parseInt(sc.nextLine());
            if (inputInt == 0) {
                break;
            }
            sb.append("Case " + i + ": " + inputInt + "\n");
            i++;
        }

        System.out.print(sb);
    }
}

Measured memory_bytes: 51192
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int mas[52][52] = {};

    int H,W;
    cin >> H >> W;

    rep(i,1,H+1){
        rep(j,1,W+1){
            char tmp;
            cin >> tmp;
            if(tmp == '#'){
                mas[i][j] = -1;
            }else{
                mas[i][j] = 0;
            }
        }
    }

    rep(i,1,H+1){
        rep(j,1,W+1){
            int cnt = 0;
            for(int a = i - 1; a <= i+1; a++){
                for(int b = j - 1; b <= j + 1; b++){
                    if(mas[a][b] == -1) cnt++;
                }
            }
            if(mas[i][j] != -1) mas[i][j] = cnt;
        }
    }

    rep(i,1,H+1){
        rep(j,1,W+1){
            if(mas[i][j] == -1){
                cout << "#";
            }else{
                cout << mas[i][j];
            }
        }
        cout << endl;
    }




    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// }}} 1

int main() {

    char a[100], b[100], c[100];

    scanf("%s %s %s", a, b, c);

    printf ("%c%c%c\n", a[0], b[0], c[0]);

    return 0;
}



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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  ll res = -1;
  int n;
  cin >> n;
  REP(i,100000){
    if((int)(i*1.08) == n)res = i;
  }
  res != -1 ? cout << res << endl : cout << ":(" << endl;

  


  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//セグメント木
//全て添字で扱うこと
template<typename T>
struct segment_tree {
  ll n; //vのサイズ
  ll m = 1; //葉の数
  vector<T> v;
  T id_e; //単位元

  //二項演算
  T seg_func(T a, T b) {
    return a + b;
  }

  //初期化関数
  void init(vector<T> a, T b) {
    id_e = b;
    while (m < a.size()) m *= 2;
    n = 2 * m - 1;
    vector<T> w(n);
    v = w;
    for (ll i = 0; i < a.size(); i++) v[m - 1 + i] = a[i];
    for (ll i = a.size(); i < m; i++) v[m - 1 + i] = id_e;
    for (ll i = m - 2; i >= 0; i--) {
      v[i] = seg_func(v[2 * i + 1], v[2 * i + 2]);
    }
  }

  //値の更新
  void change(ll a, T b) {
    a += m - 1;
    v[a] = b;
    while ((a - 1) / 2 != a) {
      a = (a - 1) / 2;
      v[a] = seg_func(v[2 * a + 1], v[2 * a + 2]);
    }
  }

  //区間和用の補助関数
  T subsub(ll a, ll b, ll cur, ll l, ll r) {
    if (a <= l && r <= b) return v[cur];
    if (r < a || b < l) return id_e;
    if (l < r) {
      return seg_func(
        subsub(a, b, 2 * cur + 1, l, (l + r) / 2),
        subsub(a, b, 2 * cur + 2, (l + r) / 2 + 1, r)
      );
    }
  }

  //区間[a, b]の和
  T subsum(ll a, ll b) {
    if (a == b) return v[m - 1 + a];
    T ans = id_e;
    ll cur = 0, l = 0, r = m - 1;
    ans = seg_func(ans, subsub(a, b, cur, l, r));
    return ans;
  }

  /*
  セグ木構築の際に用いたもとの配列 a が，
  a[i] == (集合内に存在する i + 1 の数) ならば，
  x_th_minを用いて O(logN) で集合の要素にランダムアクセスできる
  */
  ll submin(ll x, ll cur, ll l, ll r, ll flag) {
    if (l == r) return l;
    if (v[cur] == x) flag = 1;
    if (flag == 1) {
      if (v[2 * cur + 2] > 0) {
        return submin(x, 2 * cur + 2, (l + r) / 2 + 1, r, flag);
      }
      else {
        return submin(x, 2 * cur + 1, l, (l + r) / 2, flag);
      }
    }
    else {
      if (v[2 * cur + 1] == 0) {
        return submin(x, 2 * cur + 2, (l + r) / 2 + 1, r, flag);
      }
      if (v[2 * cur + 2] == 0) {
        return submin(x, 2 * cur + 1, l, (l + r) / 2, flag);
      }
      if (v[2 * cur + 1] >= x) {
        return submin(x, 2 * cur + 1, l, (l + r) / 2, flag);
      }
      else {
        return submin(x - v[2 * cur + 1], 2 * cur + 2, (l + r) / 2 + 1, r, flag);
      }
    }
  }

  //x番目に小さい要素を求める
  ll x_th_min(ll x) {
    ll cur = 0, l = 0, r = m - 1, flag = 0;
    return submin(x, cur, l, r, flag);
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vll a(n), b(n);
  for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
  segment_tree<ll> seg;
  vll x(100000, 0);
  seg.init(x, 0);
  for (ll i = 0; i < n; i++) {
    seg.change(a[i] - 1, x[a[i] - 1] + b[i]);
    x[a[i] - 1] += b[i];
  }
  cout << seg.x_th_min(k) + 1 << endl;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define N 105
int n,ans=0,cur[N],tot[N],pre[N],vis[N];
struct node
{
	int x,y;
	friend bool operator <(node t1,node t2){return t1.x<t2.x || t1.x==t2.x && t1.y<t2.y;}
 }a[N],b[N];
int s[N][N];
int dfs(int x)
{
	for(int i=1;i<=n;i++)
	{
		if(!vis[i] && s[x][i])
		{
			vis[i]=1;
			if(!pre[i] || dfs(pre[i])) {pre[i]=x;return 1;}
		}
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
	for(int i=1;i<=n;i++) scanf("%d%d",&b[i].x,&b[i].y);
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++) if(a[j].y<b[i].y && a[j].x<b[i].x) s[i][j]=1;
	}
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		if(dfs(i)) ans++;
	}
	cout<<ans<<endl;
} 

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, int b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

ll ryuka(int n)
{
    ll l0 = 2LL, l1 = 1LL;

    if (n == 0)
        return l0;
    else if (n == 1)
        return l1;
    else
    {

        for (int i = 2; i <= n; i++)
        {

            ll tmp = (l0 + l1);
            l0 = l1;
            l1 = tmp;
            // cout << l1 << endl;
        }
        return l1;
    }
}

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

    cout << ryuka(n) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	
	if(a==b&&a!=c) {
		printf("%d\n",c);
	}
	else if(a==c&&a!=b) {
		printf("%d\n",b);
	}
	else if(c==b&&b!=a) {
		printf("%d\n",a);
	}
	
	return 0;
}
	
	

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, X, D=0;
  std::cin >> N >> X;
  vvl blu = vv(N, 4, 0, ll);
  for(int i=0;i<N;i++) {
    std::cin >> blu[i][0] >> blu[i][1] >> blu[i][2];
    D -= blu[i][0] * blu[i][1];
    blu[i][3] = blu[i][0] * blu[i][1] + (X - blu[i][0]) * blu[i][2];
  }
  ll ans=1000000000000000;
  //sort
  sort(blu.begin(), blu.end(), [](vector<ll> &a, vector<ll> &b){
    return a[3] > b[3];
  });
  std::vector<ll> S(N+1);
  S[0] = 0;
  int over = N;
  if(D==0){
    std::cout << 0 << '\n';
    return 0;
  }
  for(int i=1;i<N+1;i++) {
    S[i] = S[i-1] + blu[i-1][3];
    if(S[i] + D >= 0) over = min(over, i);
  }
  for(int i=0;i<N;i++){
    ll itr, st=-1;
    if(over >= i+1) {
      if(lower_bound(S.begin(), S.end(), -D)!=S.end()){
        itr = lower_bound(S.begin(), S.end(), -D) - S.begin();
      }else continue;
      st = (itr==0?0:itr-1) * X;
      //std::cout << itr << '\n';
      if(S[itr] + D >= 0){
        ll at = abs(S[itr] + D - blu[i][3]);
        if(at<=blu[i][1]*blu[i][0]){
          st += at/blu[i][1] + (at%blu[i][1]==0?0:1);
        }else{
          st += blu[i][0];
          at -= blu[i][1] * blu[i][0];
          st += at/blu[i][2] + (at%blu[i][2]==0?0:1);
        }
        //std::cout << st << '\n';
        ans = (ans>=st?st:ans);
      }
    }else{
      itr = lower_bound(S.begin(), S.end(), -D - blu[i][3]) - S.begin();
      st = itr * X;
      //std::cout << itr << '\n';
      if(S[itr] + D + blu[i][3] >= 0){
        ll at = abs(S[itr] + D);
        if(at<=blu[i][1]*blu[i][0]){
          st += at/blu[i][1] + (at%blu[i][1]==0?0:1);
        }else{
          st += blu[i][0];
          at -= blu[i][1] * blu[i][0];
          st += at/blu[i][2] + (at%blu[i][2]==0?0:1);
        }
        //std::cout << st << '\n';
        ans = (ans>=st?st:ans);
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9344
import numpy as np

N=input().split()
A = list(map(int, input().split()))

A= np.array(A)

B = A[np.where(A%2==0, True, False)]
C = np.where(B%3==0,True, False) + np.where(B%5==0,True, False)

if C.all():
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 12504
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var z = Read();
		int h = z[0], w = z[1];
		var a = new int[h].Select(_ => Console.ReadLine()).ToArray();

		int sv = h + w, ev = sv + 1;
		var s = (i: 0, j: 0);
		var t = (i: 0, j: 0);

		var dag = new List<long[]>();
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				if (a[i][j] == 'o')
				{
					dag.Add(new[] { i, h + j, 1L });
					dag.Add(new[] { h + j, i, 1L });
				}
				else if (a[i][j] == 'S')
				{
					s = (i, j);
					dag.Add(new[] { sv, i, 1L << 60 });
					dag.Add(new[] { sv, h + j, 1L << 60 });
				}
				else if (a[i][j] == 'T')
				{
					t = (i, j);
					dag.Add(new[] { i, ev, 1L << 60 });
					dag.Add(new[] { h + j, ev, 1L << 60 });
				}

		Console.WriteLine(s.i == t.i || s.j == t.j ? -1 : MaxFlow(ev, sv, ev, dag.ToArray()));
	}

	static long MaxFlow(int n, int sv, int ev, long[][] dag)
	{
		var map = Array.ConvertAll(new int[n + 1], _ => new List<long[]>());
		foreach (var e in dag)
		{
			map[e[0]].Add(new[] { e[0], e[1], e[2], map[e[1]].Count });
			map[e[1]].Add(new[] { e[1], e[0], 0, map[e[0]].Count - 1 });
		}

		long Bfs()
		{
			var from = new long[n + 1][];
			var minFlow = new long[n + 1];
			Array.Fill(minFlow, long.MaxValue);
			var q = new Queue<long>();
			q.Enqueue(sv);

			while (q.TryDequeue(out var v))
			{
				if (v == ev) break;
				foreach (var e in map[v])
				{
					if (from[e[1]] != null || e[2] == 0) continue;
					from[e[1]] = e;
					minFlow[e[1]] = Math.Min(minFlow[v], e[2]);
					q.Enqueue(e[1]);
				}
			}

			if (from[ev] == null) return 0;
			for (long v = ev; v != sv; v = from[v][0])
			{
				var e = from[v];
				e[2] -= minFlow[ev];
				map[e[1]][(int)e[3]][2] += minFlow[ev];
			}
			return minFlow[ev];
		}

		long M = 0, t;
		while ((t = Bfs()) > 0) M += t;
		return M;
	}
}


Measured memory_bytes: 34088
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  int x=stoi(a+b);
  for(int i=1;i*i<=x;i++){
    if(i*i==x){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3604
import java.io.*;

public class Main{
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] line;
        String a, b;
        int scoreOfA = 0;
        int scoreOfB = 0;

        for(int i = 0; i < n; i++){
            line = br.readLine().split(" ");
            a = line[0];
            b = line[1];

            if(a.compareTo(b) > 0){
                scoreOfA += 3;
            }else if(a.compareTo(b) < 0){
                scoreOfB += 3;
            }else{
                scoreOfA++;
                scoreOfB++;
            }
        }
        System.out.println(scoreOfA + " " + scoreOfB);
    }
}

Measured memory_bytes: 25632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<ll,ll> >bc(m);
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    REP(i,m){
        ll b,c;
        cin >> b >> c;
        bc[i] = make_pair(c,b);
    }
    sort(ALL(bc));
    reverse(ALL(bc));
    sort(a,a+n);
    int i;
    int j = 0;
    int k = 0;
   
    for(i=0;i<n;i++){
        j+=bc[i].second;
        if(j > n-1||bc[i].first < a[j-1]){
            j-=bc[i].second;
            break;
        }
    }
    //cout << i << endl;
    ll answer = 0;

    REP(k,i){
        answer += bc[k].first * bc[k].second;
    }
   
    REP(k,bc[i].second){
        if(bc[i].first < a[j]){
            break;
        }
        j++;
        answer+=bc[i].first;
        if(j > n-1)break;
    }
    
    FOR(k,j,n){
        answer+=a[k];
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 2560
//27
//19
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int x[5000],y[5000];
  vector<int> xp(n),yp(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    xp[i]=x[i];
    yp[i]=y[i];
  }
  sort(xp.begin(),xp.end());
  sort(yp.begin(),yp.end());
  xp.erase(unique(xp.begin(),xp.end()),xp.end());
  yp.erase(unique(yp.begin(),yp.end()),yp.end());
  vector<vector<int> > g(yp.size(),vector<int>(xp.size()));
  for(int i=0;i<n;i++){
    g[lower_bound(yp.begin(),yp.end(),y[i])-yp.begin()]
      [lower_bound(xp.begin(),xp.end(),x[i])-xp.begin()]++;
  }
  vector<vector<int> > ag(yp.size()+1,vector<int>(xp.size()+1));
  for(int i=0;i<yp.size();i++){
    for(int j=0;j<xp.size();j++){
      ag[i+1][j+1]=ag[i][j+1]+ag[i+1][j]-ag[i][j]+g[i][j];
    }
  }
  while(m--){
    int xl,yl,xh,yh;
    cin>>xl>>yl>>xh>>yh;
    int xxl,yyl,xxh,yyh;
    xxl=lower_bound(xp.begin(),xp.end(),xl)-xp.begin();
    yyl=lower_bound(yp.begin(),yp.end(),yl)-yp.begin();
    xxh=upper_bound(xp.begin(),xp.end(),xh)-xp.begin();
    yyh=upper_bound(yp.begin(),yp.end(),yh)-yp.begin();
    cout<<ag[yyh][xxh]-ag[yyh][xxl]-ag[yyl][xxh]+ag[yyl][xxl]<<endl;
  }
  return 0;
}

Measured memory_bytes: 196892
//                     بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
//                   لآ اِلَهَ اِلّا اللّهُ مُحَمَّدٌ رَسُوُل اللّهِ





#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


int main()
{
    //ios::sync_with_stdio(0);cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x-b) > abs(x-a)) cout << "A" << endl;
    else cout << "B" << endl;

    return 0;
}


Measured memory_bytes: 3572
import Control.Monad
import Data.List

getList :: Read a => IO [a]
getList = fmap (map read . words) getLine

addSum :: [Int] -> [Int]
addSum xs = xs ++ [sum xs]

main :: IO ()
main = do
  [r, c] <- getList
  inputs <- replicateM r getList
  mapM_ putStrLn $ map (unwords . map show . addSum) inputs
  let inputst = transpose inputs
  putStrLn $ unwords $ map show $ addSum $ map sum $ inputst

Measured memory_bytes: 5832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S, T;
    cin >> S >> T;

    string S2 = S + S;
    long long int p = S2.find(T);
    if(p == S2.npos)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    long long sum = 0, a;
    for (int i = 0; i < m; i++) {
        cin >> a;
        sum += a;
    }
    if (n - sum >= 0) cout << n - sum << "\n";
    else puts("-1");
}


Measured memory_bytes: 3568
from math import gcd 
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
if(N == 1): print(abs(x[0] - X))
else:
  ans = gcd(abs(x[0] - X), abs(x[1] - X))
  for i in range(2, N):
  	ans = gcd(ans, abs(x[i] - X))
    
  print(ans)

Measured memory_bytes: 84952
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main() {
  int a;cin>>a;
  string s;cin>>s;
  cout << (a<3200?"red":s)<<endl;
  return 0;
}


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

int main(void){
	int n,ans=0,cnt=1;
	bool breaking=0;
	cin >> n;
	
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	
	for(int i=0; i<n; i++){
		if(cnt == a[i]){
			cnt++;
			continue;
		}else{
			ans++;
			breaking= 1;
		}
	}
	
	if(breaking == 1 && cnt==1){
		ans= -1;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
from numba import njit

n = int(input())

@njit
def solve():
    f = [1] * (n + 1)
    for i in range(2, n + 1):
        if f[i] != 1: continue
        m = i
        while m <= n:
            tmp = m
            cnt = 0
            while tmp % i == 0:
                tmp = tmp // i
                cnt += 1
            f[m] *= cnt + 1
            m += i
    ans = 0
    for i in range(1, n + 1):
        ans += i * f[i]
    return ans

print(solve())

Measured memory_bytes: 188704