akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    cout << fixed << setprecision(10);
    int64_t n, m, d;
    cin >> n >> m >> d;

    int64_t a = (n - d) * (m - 1);
    if (d != 0) {
        a *= 2;
    }
    cout << (double)a / n / n << endl;
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
S = input()
L = []
L = [list(map(int, input().split())) for _ in range(q)]
A = [0, 0]
for i in range(n-1):
    A += A[-1]+(S[i:i+2] == "AC"),
for l, r in L: print(A[r]-A[l])

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s, t;
    cin >> s >> t;
    rep (i, 26) {
        string u = s;
        u += ('a' + i);
        if (u == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 3656
#include <iostream>
using namespace std;

int main() {
    int n=100;
    int k[n];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>k[i];
    }
    
    for(int i=0; i<n; i++){
        int v = k[i];
        int j = i-1;
        while(j>=0 && k[j]>v){
            k[j+1]=k[j];
            j--;
        }
        k[j+1]=v;
        for(int m=0;m<n;m++){
            cout << k[m] << (m+1<n ? " " : "\n");
            //printf("%d",k[m]);
            //printf(" ");
        }
    }
    return 0;
}

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

int main(){
	std::vector<int> a(4), b(4);
	int hit_num, blow_num;
	
	while(std::cin >> a[0] >> a[1] >> a[2] >> a[3]){
		std::cin >> b[0] >> b[1] >> b[2] >> b[3];
		hit_num = 0;
		blow_num = 0;
		
		for(int i = 0; i < 4; ++i){
			if(a[i] == b[i]) ++hit_num;
			blow_num += std::count(a.begin(), a.end(), b[i]);
		}
		
		blow_num -= hit_num;
		std::cout << hit_num << " " << blow_num << std::endl;
	}
}

Measured memory_bytes: 1192
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 100001
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,a[N];
int main()
{
	re(n);
	for(int i=1;i<=n;++i)re(a[i]);
	sort(a+1,a+n+1);
	if(a[1]==1)puts("first");
	else if(a[1]==a[n])puts(a[1]&1?"first":"second");
	else
	{
		int ans=0;
		for(int i=1;i<=n;++i)
			ans|=a[i]&1;
		puts(ans?"first":"second");
	}
}
/*
1 2
3 3
1000
1

*/


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  int a[M],b[M],c[N];
  for(int i = 0;i < N;i++){
    c[i] = 0;
  }
  for(int i = 0;i < M;i++){
    scanf("%d %d",&a[i],&b[i]);
    c[a[i] - 1]++;
    c[b[i] - 1]++;
  }
  for(int i = 0;i < N;i++){
    printf("%d\n",c[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  int n;cin>>n;
  vector<int> t(n);rep(i,n)cin>>t[i];
  int m;cin>>m;
  vector<int> p(m),x(m);rep(i,m)cin>>p[i]>>x[i];

  rep(i,m) {
    int ans = 0;
    rep(j,n) {
      if (j+1==p[i]) {
        ans += x[i];
      } else {
        ans += t[j];
      }
    }
    cout << ans << endl;
  }  
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

ll gcd(ll a,ll b){
  if(a%b==0)return b;
  return gcd(b,a%b);
}

ll board[3][3]={0};
ll num[3][3]={0};

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

  rep(i,0,3)rep(j,0,3)std::cin>>num[i][j];

  ll n;
  std::cin>>n;

  rep(i,0,n){
    ll s;
    std::cin>>s;

    rep(j,0,3)rep(k,0,3)if(num[j][k]==s)board[j][k]=1;
  }

  rep(i,0,3){
    if(board[i][0]&&board[i][1]&&board[i][2]){
      std::cout<<"Yes\n";
      return 0;
    }
  }


  rep(i,0,3){
    if(board[0][i]&&board[1][i]&&board[2][i]){
      std::cout<<"Yes\n";
      return 0;
    }
  }


  if(board[0][0]&&board[1][1]&&board[2][2]){
    std::cout<<"Yes\n";
    return 0;
  }

  if(board[0][2]&&board[1][1]&&board[2][0]){
    std::cout<<"Yes\n";
    return 0;
  }

  std::cout<<"No\n";

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

#define int long long




signed main(){
  
    ios::sync_with_stdio(false);
    cin.tie(0);
	//cin高速化


    int a,b,c,d;
    cin>>a>>b>>c>>d;

    if(a+b>c+d){
        cout<<"Left"<<endl;
    }else if(a+b<c+d){
        cout<<"Right"<<endl;
    }else if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

def f(i, j, t):
    global ans
    if j == n:
        c = 0
        for ss in s:
            if t[ss[1] - 1] - t[ss[0] - 1] == ss[2]:
                c += ss[3]
        ans = max(ans, c)
        return
    for k in range(i, m + 1):
        t[j] = k
        f(k, j + 1, t)

n, m, q = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(q)]
t = [1] * n
ans = 0
f(1, 0, t)
print(ans)

Measured memory_bytes: 80664
import numpy as np
 
n = int(input())
n_s = int(np.sqrt(n))
 
b = n
a = 1
 
for i in range(2, n_s+1):
  if n % i == 0:
    a = i
    b = n//i
 
print(int(max(np.log10(a), np.log10(b)))+1)

Measured memory_bytes: 14516
#include<bits/stdc++.h>
using namespace std;
int N,p,f,ans;
int main(){
    cin>>N;
    for(int i{1};i<=N;++i){
        cin>>p;
        if(p==i&&!f)++ans,f=1;
        else f=0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    vector<vector<pair<ll,ll>>> t(n);
    rep(i,n-1){
        int a,b;ll c;cin>>a>>b>>c;a--;b--;
        t[a].push_back({b,c});
        t[b].push_back({a,c});
    }
    int q,k;cin>>q>>k;k--;
    priority_queue<pair<ll,int>> que;
    que.push({0,k});
    vector<bool> used(n,false);
    vector<ll> d(n,1e+18);
    d[k]=0;
    while(que.size()){
        int v=que.top().second;que.pop(); 
        used[v]=true;
        rep(i,t[v].size()){
            int y=t[v][i].first;ll c=t[v][i].second;
            if(chmin(d[y],d[v]+c))que.push({d[y],y});
        }
    }
    rep(i,q){
        int x,y;cin>>x>>y;x--;y--;
        ll res=d[x]+d[y];
        cout<<res<<endl;
    }
}

Measured memory_bytes: 11120
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int t[100001];
	int a[100001];
	for(int i = 0; i < n; i++){
		cin >> t[i];
	}
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<pair<int, int> > ansv;
	for(int i = 0; i < n; i++){
		if(i > 0 && t[i] == t[i - 1]){
			ansv.push_back(make_pair(1, t[i] + 1));
		} else {
			ansv.push_back(make_pair(t[i], t[i] + 1));
		}
	}
	for(int i = n - 1; i >= 0; i--){
		int nowl = ansv[i].first;
		int nowr = ansv[i].second;
		if(i < n - 1 && a[i] == a[i + 1]){
			ansv[i] = make_pair(max(nowl, 1), min(nowr, a[i] + 1));
		} else {
			ansv[i] = make_pair(max(nowl, a[i]), min(nowr, a[i] + 1));
		}
	}
	long long int ans = 1;
	for(int i = 0; i < n; i++){
		ans =(ans * max(0, ansv[i].second - ansv[i].first)) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2168
<?php
fscanf(STDIN, '%d %d', $N, $K);
$V = array_map('intval', explode(' ', trim(fgets(STDIN))));

$max = 0;
for($i = 0; $i <= min($K, $N); $i++) { // 全部で$i個取る場合を考える
    for($left = 0; $left <= $i; $left++) { // 左から$left個取る
        $right = $i - $left; // 右から$right個取る

        $have = array_merge(
            array_slice($V, 0, $left),
            array_slice($V, -$right, $right)
        );

        for($j = 0; $j < $K - $i; $j++) {
            if (empty($have)) break;
            $min = min($have);
            if ($min < 0) array_splice($have, array_search($min, $have), 1);
            else break;
        }
        $max = max($max, array_sum($have));
    }
}
echo $max . PHP_EOL;

Measured memory_bytes: 4604
#include<stdio.h>

int main()
{
  int x,y;
  scanf("%d %d",&x,&y);
  if((x==1||x==3||x==5||x==7||x==8||x==10||x==12) &&
     (y==1||y==3||y==5||y==7||y==8||y==10||y==12))
    printf("Yes");
  else if((x==4||x==6||x==9||x==11) && (y==4||y==6||y==9||y==11))
    printf("Yes");
  else if(x == 2 && y== 2)
    printf("Yes");
  else
    printf("No");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
struct edge { int to, cap, rev; };
const int MAX_V = 100000;
 
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
 
void add_edge(int from, int to, int cap){
  //printf("add %d -> %d (%d)\n", from, to, cap);
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, 0, G[from].size()-1});
}
void bfs(int s){
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while(!que.empty()){
    int v = que.front(); que.pop();
    for(int i = 0; i < G[v].size(); i++){
      edge &e = G[v][i];
      if(e.cap > 0 && level[e.to] < 0){
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}
 
int dfs(int v, int t, int f){
  if(v == t) return f;
  for (int &i = iter[v]; i < G[v].size(); i++){
    edge &e = G[v][i];
    if(e.cap > 0 && level[v] < level[e.to]){
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
 
int Denic(int s, int t){
  int flow = 0;
  while(true){
    bfs(s);
    if(level[t] < 0) break;;
    memset(iter, 0, sizeof(iter));
    int f;
    while((f = dfs(s, t, INF)) > 0){
      flow += f;
    }
  }
  return flow;
}
int main(){
  int N;
  while(cin>>N && N){
    REP(i, MAX_V) G[i].clear();
    int M; cin>>M;
    vector<int> myday;
    REP(i, M){
      int t; cin>>t;
      myday.push_back(t);
    }
    sort(myday.begin(), myday.end());
    REP(i, N){
      int M2;
      cin>>M2;
      while(M2--){
        int t; cin>>t;
        if(binary_search(myday.begin(), myday.end(), t)){
          int idx = lower_bound(myday.begin(), myday.end(), t) - myday.begin();
          add_edge(i, N + idx, 1);
        }
      }
    }
    const int S = N + M;
    const int G = S + 1;
    REP(i, N){
      add_edge(S, i, 1);
    }
    REP(i, M){
      add_edge(N + i, G, 1);
    }
    cout<<Denic(S, G)<<endl;
  }
  return 0;
}


Measured memory_bytes: 6232
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
abc = [LIST() for _ in range(N-1)]
Q, K = MAP()
xy = [LIST() for _ in range(Q)]

connection = [[] for _ in range(N)]
for a, b, c in abc:
	connection[a-1].append((b-1, c))
	connection[b-1].append((a-1, c))

#print(connection)

step = [-1]*N
step[K-1] = 0
q = deque([K-1])

while q:
	p = q.pop()
	for X, C in connection[p]:
		if step[X] == -1:
			step[X] = step[p] + C
			q.append(X)

#print(step)

for x, y in xy:
	print(step[x-1] + step[y-1])




Measured memory_bytes: 89632
from statistics import median

n = input()
a = input().split()
a = list(map(int, a))

b = []

for i, v in enumerate(a):
    b.append(v - (i + 1))

median = int(median(b))

c = 0

for v in b:
    c = c + abs(v - median)

print(c)


Measured memory_bytes: 27244
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufRead, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;($($r :tt ) *) =>{let mut s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .expect ("Parse error" ) } ;}
#[allow(unused_macros)]
macro_rules !dbg {($($a :expr ) ,*) =>{writeln !(&mut stderr () ,concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) .unwrap () ;} }
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        k: i64,
        n: usize,
        a: [i64; n],
    }
    let mut ans: i64 = a[n - 1] - a[0];
    for i in 1..n {
        ans = min(ans, a[i - 1] + k - a[i]);
    }
    println!("{}", ans);
}

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

int main(){
    long long N, K;
    scanf("%lld%lld", &N, &K);
    vector<pair<long long, long long>> ss(N);
    for(auto& i : ss)scanf("%lld%lld", &i.second, &i.first);
    sort(ss.rbegin(), ss.rend());

    vector<long long> cnt(N + 1);
    long long ans(0), tmp(0), x(0);
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;
    for(long long i = 0; i < K; ++i){
        tmp += ss[i].first;
        if(!cnt[ss[i].second])++x;
        else pq.push(ss[i]);
        ++cnt[ss[i].second];
    }

    ans = max(ans, tmp + x * x);
    for(auto i = K; i < N && x <= K; ++i){
        if(cnt[ss[i].second])continue;
        if(pq.empty())break;
        auto t = pq.top();
        pq.pop();
        tmp -= t.first;
        --cnt[t.second];
        tmp += ss[i].first;
        ++cnt[ss[i].second];
        ++x;
        ans = max(ans, tmp + x * x);
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}

int main(){
    dcl(n);
    cout<<n/11*2+(n%11!=0?n%11>6?2:1:0)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, X, T;
    cin >> N >> X >> T;
    cout << (N + X - 1) / X * T << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
    long long int i=0,j,k,n,val,sum=0;
    scanf("%lld %lld",&n,&k);
    for(i=0;i<n;i++){
        scanf("%lld",&val);
        sum=sum+val;
        if(val<j || i==0)
            j=val;
    }
    k=k-sum;
    printf("%lld\n",n+k/j);



    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(void)
{
	int a[28];
	for (int i = 0; i < 28; i++)
	{
		cin >> a[i];
	}

	sort(a, a + 28);

	int p[2];
	p[0] = 0;
	p[1] = 0;
	int co = 0;
	for (int i = 0; i < 28; i++)
	{
		if (a[i] != i + 1 + co)
		{
			p[co] = i + 1 + co;
			co++;
		}
	}
if (p[1] == 0)
{
    p[1] = 30;
}
	cout << p[0] << endl << p[1] << endl;
}




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

using P = pair<ll,ll>;
#define v first
#define w second

// v高い順（vが同じならw軽い方優先）
bool comp(P a, P b){
    return a.v == b.v ? a.w < b.w : a.v > b.v;
}

int main(void){
    ll N,W;
    cin>>N>>W;
    vector<P> a(N);
    rep(i,N){
        ll v,w;
        cin>>v>>w;
        a[i] = {v,w};
    }
    vector<P> dp = {{0,0}};

    rep(i,N){
        vector<P> tmp;
        for(P s : dp){
            tmp.push_back(s);
            tmp.push_back({s.v + a[i].v, s.w + a[i].w});
        }

        sort(all(tmp),comp);
        dp.clear();
        ll w_border = W+1;
        for(P s : tmp){
            if( w_border > s.w){
                w_border = s.w;
                dp.push_back(s);
            }
        }
        assert((ll)dp.size() <= N*N*2);
    }
    cout<<dp[0].v<<endl;
    return 0;
}



Measured memory_bytes: 3216
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		while (true) {
			String str = sc.next();
			if (str.equals("-")) {
				break;
			}
			int m = sc.nextInt();
			for (int i = 0; i < m; i++) {
				int h = sc.nextInt();
				str = str.substring(h) + str.substring(0, h);
			}
			System.out.println(str);
		}
		sc.close();
	}

}


Measured memory_bytes: 26568
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 1e5 + 10;
ll cnt[MAX_N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    ll sum = 0;
    cin >> n;
    for(ll i = 0; i < n; i ++) {
        ll a;
        cin >> a;
        cnt[a] ++;
        sum += (ll)a;
    }
    ll q;
    cin >> q;
    for(ll i = 0; i < q; i ++) {
        ll b, c;
        cin >> b >> c;
        sum -= cnt[b] * b;
        sum += cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    return 0;
}




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

// 文字列長
int nagasa(string s) {
   return (int)(s.length());
}

int main() {
   string t;
   cin >> t;
   int n = nagasa(t);
   for (int i=0; i<n; i++) {
      if(t[i] == '?') {
         t[i] = 'D';
      }
   }
   cout << t << endl;
   return 0;
}

Measured memory_bytes: 3920
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

long long N, A, B, C, D;

int main() {
    cin >> N >> A >> B >> C >> D;
    for (int i = 0; i < N; i++) {
        long long mn = A + i * C - (N - 1 - i) * D, mx = A + i * D - (N - 1 - i) * C;
        if (mn <= B && B <= mx) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

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


int main() {
	
	string s;
	cin >> s;
	bool yymm=0;
	bool mmyy=0;
	
	if(stoi(s.substr(0,2))<=12&&stoi(s.substr(0,2))!=0) mmyy=1;
	if(stoi(s.substr(2,2))<=12&&stoi(s.substr(2,2))!=0) yymm=1;
	if(mmyy&yymm) cout << "AMBIGUOUS" << endl;
	if(mmyy&!yymm) cout << "MMYY" << endl;
	if(yymm&!mmyy) cout << "YYMM" << endl;
	if(!yymm&!mmyy) cout << "NA" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    A=sorted(list(map(int,input().split())),reverse=True)

        

    m=n
    m-=2
    p,q=divmod(m,2)
    if q==0:
        ans=2*sum(A[:p+1])
        ans-=A[0]
    else:
        ans=2*sum(A[:p+2])
        ans-=A[0]
        ans-=A[p+1]
    print(ans)





    
resolve()

Measured memory_bytes: 104632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int t = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = Integer.parseInt(sc.next());

		double abs;
		int ans = 0;
		double min = 100000.0;
		for (int i = 0; i < n; i++) {
			abs = Math.abs(a - (t - h[i] * 0.006));
			if (abs < min) {
				min = abs;
				ans = i + 1;
			}
		}
      
		System.out.println(ans);
		
		sc.close();
	}
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
	
using namespace std;
	
#define endl "\n"
#define ll long long
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

vi arr(200010);

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

	int n;
	cin >> n;
	int mn = INT_MAX;
	int ans = 0;
	forn(i, n){
		cin >> arr[i];
		if(arr[i] <= mn){
			ans++;
		}
		mn = min(mn, arr[i]);
	}
	cout << ans << endl;


	return 0;
}


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

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int maxx=-101;
  int miny=101;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    maxx = max(x, maxx);
  }
  for(int i=0; i<M; i++){
    int y;
    cin >> y;
    miny = min(y, miny);
  }
  maxx = max(maxx, X);
  miny = min(miny, Y);
  if(maxx < miny) cout << "No War" << endl;
  else cout << "War" << endl;
}

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

int main() {
  int x, y, z; cin >> x >> y >> z;
  cout << z << " " << x << " " <<  y << endl;
  return 0;
}


Measured memory_bytes: 256
A, B, C, K = map(int, input().split())
sum = 0

if K >= A:
	sum = A
	K = K - A
else:
	sum = K
	K = 0
if K >= B and K >= 1:
	K = K - B
else:
	K = 0
if K >= C and K >= 1:
	sum = sum - C
else:
	sum = sum - K

print(sum)

Measured memory_bytes: 9100
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

void solve (int n)
{
    int m;
    cin >> m;

    vll pos(n);
    forn (i, n) if (i != 0)
    {
        int a;
        cin >> a;
        pos[i] = pos[i - 1] + a;
    }

    vvi cost(n, vi(m));
    forn (i, n) forn (j, m) cin >> cost[i][j];

    vector<vll> pref(n + 1, vll(n + 1));

    forn (j, m)
    {
        vii active;
        vi lft(n, -1), rgt(n, n);
        forn (i, n)
        {
            while (!active.empty() && cost[i][j] > active.back().fst)
            {
                rgt[active.back().snd] = i;
                active.pop_back();
            }
            lft[i] = (active.empty() ? -1 : active.back().snd);
            active.pb(mp(cost[i][j], i));
        }

        forn (i, n)
        {
//            int pl = i - 1, pr = i + 1;
//            while (pl >= 0 && cost[pl][j] < cost[i][j])
//                --pl;
//            while (pr < n && cost[pr][j] < cost[i][j])
//                ++pr;
//            lft[i][j] = pl;
//            rgt[i][j] = pr;

            // (lft[i][j], rgt[i][j])
            assert(lft[i] + 1 <= rgt[i] - 1);
            // add to [lft[i][j] + 1, i] x [i, rgt[i][j] - 1]
            int l1 = lft[i] + 1, r1 = i + 1;
            int l2 = i, r2 = rgt[i];
            pref[r1][r2] += cost[i][j];
            pref[r1][l2] -= cost[i][j];
            pref[l1][r2] -= cost[i][j];
            pref[l1][l2] += cost[i][j];
        }
    }

    for (int i = n; i > 0; i--)
    for (int j = n; j > 0; j--)
    {
        pref[i][j - 1] += pref[i][j];
        pref[i - 1][j] += pref[i][j];
        pref[i - 1][j - 1] -= pref[i][j];
    }

    ll ans = 0;
    forn (j, n) forn (i, j + 1)
    {
        // val at [i, j]
        ll cur = pref[i + 1][j + 1];
        cur -= pos[j] - pos[i];
        ans = max(ans, cur);
    }

    cout << ans << '\n';
}

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

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 200064
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 100005;

int n;
int cost[N][3];
int memo[N][3];

int go(int i, int wtf) {
	if(i >= n)
		return 0;

	if(memo[i][wtf] != -1)
		return memo[i][wtf];

	int &ans = memo[i][wtf];

	rep(j,3) {
		if(j == wtf) continue;
		ans = max(ans, cost[i][j] + go(i+1, j));
	}
	return ans;
}

int32_t main() {

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

    cin >> n;

    rep(i,n) {
    	rep(j,3) {
    		cin >> cost[i][j];
    		memo[i][j] = -1;
    	}
    }

    cout << max({go(0,0),go(0,1),go(0,2)}) << '\n';
}

Measured memory_bytes: 12800
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(){
    int n,m;
    scanf("%d %d", &n, &m);
    int in;
    int i=0;
    REP(i, m){
        SCD(in);
        n-=in;
    }
    if(n>=0){
        printf("%d",n);
    } else{
        printf("-1");
    }

}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int n, a[1000005], u[1000005];

int main() {

    scanf("%d", &n);
    int g = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        g = __gcd(g, a[i]);
        for (int j = 2; j * j <= a[i]; j++) {
            if (a[i] % j == 0) {
                u[j]++;
                while (a[i] % j == 0)a[i] /= j;
            }
        }
        u[a[i]]++;
    }
    if (g > 1) {
        cout << "not coprime\n";
        return 0;
    }
    for (int i = 2; i <= (int) 1e6; i++) {
        if (u[i] > 1) {
            cout << "setwise coprime\n";
            return 0;
        }
    }
    cout << "pairwise coprime\n";
    return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stack>

using namespace std;

int d[101][101];
int h,w,n;
int a[10201];

void dp(int tate,int yoko,int color,int sum)
{
  if(a[color]==0) color++;
  if(d[tate][yoko]==0)
    {
      d[tate][yoko]=color;
      a[color]--;
      sum++;
    }
  if(sum<h*w)
    {
      if(yoko+1<=w && tate%2 == 1) dp(tate,yoko+1,color,sum);
      else if(tate%2 ==1 && yoko==w) dp(tate+1,yoko,color,sum);
      else if(tate%2 == 0 && yoko > 1 && yoko <=w) dp(tate,yoko-1,color,sum);
      else if(tate%2 == 0 && yoko ==1) dp(tate+1,yoko,color,sum);
    }
}

int main(void)
{
  cin >> h >> w;
  cin >> n;
  for(int i=1;i<=n;i++)
    {
      cin >> a[i];
    }
  for(int i=1;i<=h;i++)
    {
      for(int j=1;j<=w;j++)
	{
	  d[i][j]=0;
	}
    }
  dp(1,1,1,0);
  for(int i=1;i<=h;i++)
    {
      for(int j=1;j<=w;j++)
	{
	  cout << d[i][j] << ' ';
	}
      cout << endl;
    }
  return 0;
  
}


Measured memory_bytes: 384
import bisect
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

A.sort()
C.sort()
ans=0
for b in B:
    ans+=bisect.bisect_left(A,b)*(len(C)-bisect.bisect_right(C,b))
print(ans)


Measured memory_bytes: 23360
#include<bits/stdc++.h>
using namespace std;
int main(){
  long h,n;
  cin>>h>>n;
  long a[n],s=0;
  for(long i=0;i<n;i++){
    cin>>a[i];
    s+=a[i];
  }
  if((h-s)<=0){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split()]
flag = 1
for ai in a:
    if (ai % 2 == 0) and (ai % 3 != 0 and ai % 5 != 0):
        flag = 0
if flag:
    print('APPROVED')
else:
    print('DENIED')

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

using namespace std;

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

    bool flag = 1;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if(x % 2 == 0) {
            flag &= x % 3 == 0 or x % 5 == 0;
        }
    }

    puts(flag ? "APPROVED" : "DENIED");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    ll N;
    cin >> N;
    int res = 100;
    for (ll i = 1; i*i <= N; i++) {
        if (N % i == 0) {
            ll B = N / i;
            int digit = 0;
            while (B != 0) {
                digit++;
                B /= 10;
            }
            res = digit < res ? digit : res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y)
{
    int res = 1;
    x = x % M;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % M;
        y = y>>1;
        x = (x*x) % M;
    }
    return res;
}
int main()
{
	IOS;
	int n;
	cin>>n;
	set<int>s;
	rep(i,0,n)
	{
		int x;
		cin>>x;
		s.insert(x);
	}
	if(s.size()==n)
	cout<<"YES";
	else
	cout<<"NO";
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 3001
#define MOD 1000000007
#define int ll
int N,M;
string S;

int A[maxn];

int dp[maxn][maxn];
int ss[maxn];

inline pi inter(pi i,pi j){
	return pi(max(i.f,j.f),min(i.s,j.s));
}
inline int sz(pi i){
	return i.s - i.f + 1;
}


inline int qry(pi i){
	if (i.f == 0) return ss[i.s];
	return ss[i.s] - ss[i.f-1];
}


int dpf(int i,int j,int k){
	//cout<<i<<' '<<j<<' '<<k<<'\n';
	if (k > sz(pi(i,j))) return 0;
	if (k < 0) return 0;
	if (A[i] > j){
		k += qry(pi(j + 1, A[i]));
		j = A[i];
	}
	
	if (dp[i][k] != -1) return dp[i][k];
	
	
	
	
	
	if (i == N) return 1;
	
	
	


	if (k > 0) return dp[i][k] = (dpf(i+1,j,k-1) + dpf(i+1,j,k)) % MOD;
	else return dp[i][k] = dpf(i+1,j,k);
}

int32_t main(){
	fast;
	
	cin>>N>>M>>S;

	stack <pi> st;
	
	FOR(i,0,M-1){
		int a,b; cin>>a>>b;
		
		while (!st.empty() && sz(inter(st.top(),pi(a,b))) == sz(st.top())) st.pop();

		if (!st.empty() && sz(inter(st.top(),pi(a,b))) == sz(pi(a,b))) continue;
		st.push(pi(a,b));
	}
	
	M = st.size();
	FOR(i,0,N-1) A[i] = i;
	
	DEC(i,M-1,0){
		A[st.top().f - 1] = st.top().s - 1;
		st.pop();
	}
	
	if (S[0] == '1') ss[0] = 1;
	else ss[0] = 0;
	
	FOR(i,1,N-1){
		if (S[i] == '1') ss[i] = ss[i-1] + 1;
		else ss[i] = ss[i-1];
	}
	mem(dp,-1);
	
	cout<<dpf(0,A[0],qry(pi(0,A[0])));
	
	
	
	
}



Measured memory_bytes: 70784
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
t = 0
t1 = 0
t2 = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for l in range(j,K+1):
            if i == j == l:
                t = t + i
            elif i == j or j ==l or l ==i:
                t = t + 3 * gcd(i, j,l)
            else:
                t = t + 6 * gcd(i,j,l)
             
           
           
print(t)

Measured memory_bytes: 9632
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

while True:
    N = input()
    if N == 0:
        break
    lst = []
    for i in range(N):
        x, y = map(int, raw_input().split())
        lst.append((x, y))
    x0, y0 = lst[0]
    x_pre, y_pre = lst[0]
    lst.append((x0, y0))
    sq_list = []
    for i in range(1, N):
        x, y = lst[i]
        if y != y_pre:
            flag = ((x > x0) ^ (y > y_pre))
            sq_list.append((min(x, x0),max(x, x0),min(y, y_pre),max(y, y_pre),flag))
        x_pre = x
        y_pre = y
    sq = []
    for i in range(4):
        x, y = map(int, raw_input().split())
        sq.append((x, y))
    sq.sort()
    sq = (sq[0][0], sq[3][0], sq[0][1], sq[3][1])
    ans = 0
    for s in sq_list:
        S = (s[1] - s[0]) * (s[3] - s[2])
        x1 = max(sq[0], s[0])
        x2 = min(sq[1], s[1])
        y1 = max(sq[2], s[2])
        y2 = min(sq[3], s[3])
        if y2 - y1 > 0 and x2 - x1 > 0:
            S -= (y2 - y1) * (x2 - x1)
        if s[4]:
            S *= -1
        ans += S
    print ans




Measured memory_bytes: 5040
#include <stdio.h>
#define N 100

main()
{
  int n,i,j;
  int temp,count=0,minj;
  int A[N];
  
  scanf("%d",&n);
  
  for( i = 0 ; i < n ; i++ ){

    scanf("%d",&A[i]);

  }
  
  for(i = 0 ; i < n - 1 ; i++){
    minj = i;
    
    for(j = i ; j < n ; j++){
      
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(i != minj){
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    count++;
  }
    
  }
  
  for( i = 0 ; i < n ; i++ ){
    if(i != 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int Z = 700;
  for (int i = 0;i < S.size();i++) {
    if (S.at(i) == 'o') {
      Z += 100;
    }    
  }
  cout << Z << endl;
}





Measured memory_bytes: 764
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val H = sc.nextInt()
    val N = sc.nextInt()
    val A = mutableListOf<Int>()
    val B = mutableListOf<Int>()
    repeat(N) { A.add(sc.nextInt()); B.add(sc.nextInt()) }

    val dp = Array(H + 1) { Int.MAX_VALUE }
    dp[0] = 0

    for (i in 0..H) {
        if (dp[i] == Int.MAX_VALUE) {
            continue
        }
        for (j in 0 until N) {
            val ni = Math.min(H, i + A[j])
            dp[ni] = Math.min(dp[ni], dp[i] + B[j])
        }
    }
    println(dp[H])
}


Measured memory_bytes: 66312
#include <iostream>
using namespace std;

int N;

int v1[100010] = {};
int v2[100010] = {};

int main() {
    cin >> N;
    for(int i = 0; i < N; ++i) {
        int v;
        cin >> v;
        if(i % 2 == 0) {
            v1[v]++;
        } else {
            v2[v]++;
        }
    }
    int f1 = -1, i1 = -1, n1 = -1;
    int f2 = -1, i2 = -1, n2 = -1;
    for(int i = 0; i < 100010; ++i) {
        if(f1 < v1[i]) {
            n1 = f1;
            f1 = v1[i];
            i1 = i;
        } else if(n1 < v1[i]) {
            n1 = v1[i];
        }

        if(f2 < v2[i]) {
            n2 = f2;
            f2 = v2[i];
            i2 = i;
        } else if(n2 < v2[i]) {
            n2 = v2[i];
        }
    } 
    if(i1 == i2) {
        cout << min((N - f1 - n2), (N - f2 - n1)) << endl;
    } else {
        cout << N - f1 - f2 << endl;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define forup(i,a,b) for(int i=(a);i<=(b);i++)
#define fordown(i,a,b) for(int i=(a);i>=b;i--)
#define maxn 1000005
#define pb push_back
using namespace std;
int n;
int a[maxn];
int main()
{  cin>>n;
   forup(i,1,n) scanf("%d",&a[i]);
    int ans=1;
   int dire=0,las=a[1];
   forup(i,2,n)
   {if(dire==0)
     {if(las==a[i])  {las=a[i];dire=0;continue;}
	  if(las<a[i])   {las=a[i];dire=1;continue;}
	  if(las>a[i])   {las=a[i];dire=-1;continue;}
 	 }
 	if(dire==1)
	 {if(las<=a[i])  {las=a[i];continue;}
	  else            {las=a[i];dire=0;ans++;continue;}
	 } 
   if(dire==-1)
     { if(las>=a[i]) {las=a[i]; continue;}
      else          {las=a[i];dire=0;ans++;continue;}
	 }
   }
  cout<<ans<<endl;

return 0;
}


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

int main()
{
int a,b,c; cin>>a>>b>>c;

for(int i = 0 ; i < 100 ; i++)
{
if ((b*i + c)%a == 0)
{
cout<<"YES";
return 0;
}
}
cout<<"NO";
return 0;
}

Measured memory_bytes: 256