akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair< string,int > p;

vector<p> book;

int main() {
  string s;
  int P;
  while(cin >> s >> P) {
    p temp;
    temp.first = s;
    temp.second = P;
    book.push_back(temp);
  }
  sort(book.begin(),book.end());
  bool r;
  string now = "";
  for(unsigned int i=0;i<book.size();i++) {
    if(now != book[i].first) {
      if(i!=0) cout << endl;
      now = book[i].first;
      cout << now << endl;
      r = false;
    }
    if(r) {
      cout << " ";
    }
    cout << book[i].second;
    r = true;
  }
  cout << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  long long a[n],b[n];
  long long sa=0,sb=0;
  REP(i,n){
    cin>>a[i];
    sa += a[i];
  }
  REP(i,n){
    cin>>b[i];
    sb += b[i];
  }
  if(sa<sb){
    cout<<-1<<endl;
    return 0;
  }
  vector<long long> c(n);
  long long ans=0;
  long long comp=0;
  REP(i,n){
    c[i] = a[i]-b[i];
    if(c[i]<0){
      ans++;
      comp += abs(c[i]);
    }
  }
  sort(c.begin(),c.end(),greater<long long>());
  REP(i,n){
    if(comp>0){
      comp -= c[i];
      ans++;
    }else{
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    int M;
    cin >> M;
    cout << 24 + 24 - M << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int x,y;
  cin>>x>>y;
  for(int i=0;i<=x;i++){
    if(i*2+(x-i)*4==y){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int cnt = 0;
  for (int i = 0; i < N - 2; ++i) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ++cnt;
  }
  cout << cnt << endl;
}


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

#define ll long long 
using vt = int; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

int main() {
	double l;
	cin >> l;
	l /= 3;
	l = l * l * l;
	cout << fixed << setprecision(7) << l;
	return 0;
}

Measured memory_bytes: 256
let [|H;W;K|] =
    stdin.ReadLine().Split()
    |> Array.map int
let c =
    [|1..H|]
    |> Array.map (fun _ ->
        stdin.ReadLine().ToCharArray()
        |> Array.map (fun x ->
            match x with
            | '.' -> 0
            | '#' -> 1))

let f hs ws =
    c
    |> Array.scan (fun (hs',sum) value ->
        let a = hs'&&&1
        let v =
            value
            |> Array.scan (fun (ws',sum') x ->
                let b = ws'&&&1
                (ws'>>>1,sum'+x*a*b)) (ws,0)
            |> ((fun x -> x.[W]) >> (fun (_,s) -> s))
        (hs'>>>1,sum+v)) (hs,0)
    |> ((fun x -> x.[H]) >> (fun (_,s) -> s))

[|1..int(2.0**float(H))-1|]
|> Array.sumBy (fun x ->
    [|1..int(2.0**float(W))-1|]
    |> Array.sumBy ((f x) >> (fun y ->
        if y=K then 1
        else 0)))
|> stdout.WriteLine

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

  int main() {
    int N;
    cin >> N;
    int x = 0;
    for (int i = 0; i < N; i++) {
      int l, r;
      cin >> l >> r;
      x = x + r - l + 1;
    }
    cout << x;
  }


Measured memory_bytes: 3628
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B
import           Debug.Trace

readInt' :: B.ByteString -> Int
readInt' bs | Just (n, _) <- B.readInt bs = n

data Queue a =
    Queue [a]
          [a]
    deriving (Show)

enqueue :: a -> Queue a -> Queue a
enqueue x (Queue fs bs) = Queue fs (x:bs)

dequeue :: Queue a -> Maybe (a, Queue a)
dequeue (Queue [] []) = Nothing
dequeue (Queue [] (b:bs))
    | (c:cs) <- reverse (b : bs) = Just (c, Queue cs [])
dequeue (Queue (f:fs) bs) = Just (f, Queue fs bs)

isEmpty :: Queue a -> Bool
isEmpty (Queue [] []) = True
isEmpty _             = False

fromList :: [a] -> Queue a
fromList xs = Queue xs []

solve :: Int -> Queue (B.ByteString, Int) -> IO ()
solve quontum queue = go 0 queue
  where
    go c que =
        case dequeue que of
            Nothing -> return ()
            Just ((name, time), que') -> do
                if time <= quontum
                    then do
                        putStrLn $ B.unpack name ++ " " ++ show (c + time)
                        go (c + time) que'
                    else do
                        go (c + quontum) (enqueue (name, time - quontum) que')

main :: IO ()
main = do
    [n, q] <- fmap readInt' . B.words <$> B.getLine
    ps <- fmap ((\[a, b] -> (a, readInt' b)) . B.words)
          . B.lines <$> B.getContents
    let que = fromList ps
    solve q que



Measured memory_bytes: 11612
import sys
from bisect import *
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    
    N,M,V,P=map(int,input().split())
    A=sorted(list(map(int,input().split())))
    
    def solve(mid):
        point=A[mid]+M
        z=0
        c=0
        i=1
        while c<P-1:
            if N-i!=mid:
                z+=max(min(M+A[N-i]-point,M),0)
                c+=1
            i+=1
        for i in range(N):
            if i!=mid:
                z+=min(M,max(point-A[i],0))
        if point>=A[N-P] and z>=M*(V-1):
            return True
        else:
            return False
        
    print(N-nibutan(N-1,-1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 62576
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
        mut b: [usize; n],
    }

    // let mut a = vec![1; 99_999];
    // for _ in 0..100_000 {
    //     a.push(2);
    // }
    // a.push(3);
    // let mut b = vec![1; 100_000];
    // for _ in 0..100_000 {
    //     b.push(2);
    // }
    // let n = a.len();

    b.reverse();
    let mut pos1 = n;
    let mut pos2 = n;
    let mut found = false;
    for i in 0..n {
        if a[i] == b[i] {
            if !found {
                pos1 = i;
                found = true;
            } 
            pos2 = i;
        }
    }
    if !found {
        println!("Yes");
        for b in b {
            print!("{} ", b)
        }
        return;
    }
    let pivot = a[pos1];
    let mut p = pos1;
    let lower = min(pos1, a.lower_bound(&pivot));
    let upper = max(pos2+1, a.upper_bound(&pivot));
    for i in 0..lower {
        if p > pos2 {
            break;
        }
        if b[i] == a[pos1] {
            break;
        }
        b.swap(i, p);
        p += 1;
    }
    for i in (upper..n).rev() {
        if p > pos2 {
            break;
        }
        if b[i] == a[pos1] {
            break;
        }
        b.swap(i, p);
        p += 1;
    }
    for i in 0..n {
        if a[i] == b[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
    for b in b {
        print!("{} ", b);
    }

}


Measured memory_bytes: 7828
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;

int n, ans;
char s[100];

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(n), scanf("%s", s + 1);
    for (R int i = 1; i <= n - 2; ++i)
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ++ans;
    cout << ans << endl;
    return 0;
}

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

int main() {
  size_t x = 0, y = 0, z = 0, k = 0;
  cin >> x >> y >> z >> k;
  
  vector<long long int> a(x, 0);
  for (size_t i = 0; i < a.size(); ++i) {
    cin >> a[i];
  }
  
  vector<long long int> b(y, 0);
  for (size_t i = 0; i < b.size(); ++i) {
    cin >> b[i];
  }
  
  vector<long long int> c(z, 0);
  for (size_t i = 0; i < c.size(); ++i) {
    cin >> c[i];
  }
  
  vector<long long int> plus_ab(a.size() * b.size(), 0);
  for (size_t i = 0; i < a.size(); ++i) {
    for (size_t j = 0; j < b.size(); ++j) {
      plus_ab[y * i + j] = a[i] + b[j];
    }
  }
  
  sort(plus_ab.begin(), plus_ab.end(), greater<long long int>());
  // for (int i = 0; i < plus_ab.size(); ++i) {
  //   cout << "plus_ab[" << i << "] = " << plus_ab[i] << endl;
  // }
  // return 0;
  
  vector<long long int> e(min(k, plus_ab.size()), 0);
  for (size_t i = 0; i < e.size(); ++i) {
    e[i] = plus_ab[i];
  }
  
  vector<long long int> plus_ec(e.size() * c.size(), 0);
  for (size_t i = 0; i < e.size(); ++i) {
    for (size_t j = 0; j < c.size(); ++j) {
      plus_ec[z * i + j] = e[i] + c[j];
    }
  }
  
  sort(plus_ec.begin(), plus_ec.end(), greater<long long int>());
  // for (int i = 0; i < plus_ec.size(); ++i) {
  //   cout << "plus_ec[" << i << "] = " << plus_ec[i] << endl;
  // }
  // return 0;
  
  for (int i = 0; i < k; ++i) {
    cout << plus_ec[i] << endl;
  }
}

Measured memory_bytes: 31616
#include <cstdio>
#include <iostream>
using namespace std;
int N, A[200005];
long long result;

int main()
{
    scanf("%d", &N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    }
    int l, r, hap = 0;
    l = 0;
    r = 0;
    while(l <= r && l < N)
    {
        if(r < N && (hap & A[r]) == 0)
        {
            result++;
            hap += A[r++];
        }
        else
        {
            result += r - l - 1;
            hap -= A[l++];
        }
    }
    printf("%lld", result);
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
using namespace std;

void outputPattern(int length, int offset) {
    int times = length/2;

    for (int i = 0; i < times; ++i) {
        cout << (i+offset+1) << " " << (length-i+offset) << endl;
    }
}

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

    outputPattern(M, 0);
    outputPattern(M+1, M);

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  s += "a";
  vector<int> p(n+1);
  int c = 0;
  int x = 0;
  if (s[0] == '0') c++;
  else x++;
  int se = 1;
  FOR(i, 1, n+1) {
    if ((int)s[i]-48 == x) se++;
    else {
      p[c] = se;
      c++;
      x ^= 1;
      se = 1;
    }
  }
  if (k >= c/2) {
    cout << n << endl;
    return 0;
  }
  int ans = 0;
  rep(i, (c/2)-k+1) {
    int st = 0;
    FOR(j, i*2, (i+k)*2+1) {
      st += p[j];
      ans = max(ans, st);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

int main(){
    int N,C,K;
    cin>>N>>C>>K;
    vector<int> T(N);
    for(auto &t:T) cin>>t;
    sort(T.begin(), T.end());
    int cnt = 0;
    int arrive = -K;
    int passangeer = 0;
    for(auto t:T){
        if(t-arrive>K||passangeer>=C){
            cnt++;
            arrive=t;
            passangeer=1;
        }else{
            passangeer++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  vi v(n);
  int x;
  fi(0, n - 1) {
    cin >> x;
    v[x-1]++;
  }
  // v[0]++;
  for(int y: v) {
    cout << (y) << endl;
    // cout << (y == 0? 0 :y - 1) << endl;
  }
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back


pii topdown(int x){
  int top=0;
  for (int i=1;i<=100000;i*=10){
    int tmp;
    tmp=x/i;
    if (tmp==0){
      break;
    }
    top=tmp;
  }
  
  auto ans=make_pair(top,x%10);
  return ans;
}





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

  vector<vector<int>> count(10,vector<int>(10,0));
  

  for (int i=1;i<=n;i++){
    int a=topdown(i).first;
    int b=topdown(i).second;
    count.at(a).at(b)++;
  }
  
  int answer=0;
  
  for (int i=1;i<=9;i++){
    for (int j=1;j<=9;j++){
      answer+=count.at(i).at(j)*count.at(j).at(i);
    }
  }
  
  cout<<answer<<endl;
  

}




















Measured memory_bytes: 256
while True:
    dataset = input().split(" ")
    m = int(dataset[0])
    f = int(dataset[1])
    r = int(dataset[2])

    if m==-1 and f==-1 and r==-1:
        break

    grade = ""
    if m==-1 or f==-1:
        grade = "F"
    elif (m+f) >= 80:
        grade = "A"
    elif (m+f) >= 65:
        grade = "B"
    elif (m+f) >= 50:
        grade = "C"
    elif (m+f) >= 30:
        if r >= 50:
            grade = "C"
        else:
            grade = "D"
    else:
        grade = "F"

    print(grade)



Measured memory_bytes: 5596
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
  if (a < b) std::swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
  llong g = gcd(a, b);
  return a * b / g;
}
//ここまで共通
int main() {
	int A, B;
	cin >> A >> B;
	if (1 <= A && A <= 9 && 1 <= B && B <= 9) {
		cout << A * B << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	double v0[2], v1[2], v2[2], p[2];	//[0]にx座標、[1]にy座標

	while (cin >> v0[0] >> v0[1] >> v1[0] >> v1[1] >> v2[0] >> v2[1] >> p[0] >> p[1])
	{
		double v0v1[2] = {v1[0]-v0[0], v1[1]-v0[1]},
			   v1v2[2] = {v2[0]-v1[0], v2[1]-v1[1]},
			   v2v0[2] = {v0[0]-v2[0], v0[1]-v2[1]},
			   v0p[2]  = {p[0]-v0[0],  p[1]-v0[1]},
			   v1p[2]  = {p[0]-v1[0],  p[1]-v1[1]},
			   v2p[2]  = {p[0]-v2[0],  p[1]-v2[1]},

			   vv0 = v0v1[0]*v0p[1] - v0v1[1]*v0p[0],
			   vv1 = v1v2[0]*v1p[1] - v1v2[1]*v1p[0],
			   vv2 = v2v0[0]*v2p[1] - v2v0[1]*v2p[0];

		if((vv0>0 && vv1>0 && vv2>0) || (vv0<0 && vv1<0 && vv2<0)) {
			cout << "YES" << endl;
		}else{
			cout << "NO"  << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main()
{
int A,B;
cin>>A>>B;
if(A-B>A*B&&A-B>A+B){cout << A-B << endl;}
if(A+B>=A*B&&A+B>=A-B){cout << A+B << endl;}
if(A*B>A+B&&A*B>A-B){cout << A*B << endl;}
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  int n;
  cin >> n;
  VL a(n);
  map<ll, int> freq;
  REP(i, 0, n) {
    cin >> a[i];
    if (freq.count(a[i]) == 0) {
      freq[a[i]] = 0;
    }
    freq[a[i]] += 1;
  }
  VL pool;
  for (auto t: freq) {
    REP(i, 0, t.second / 2) {
      pool.push_back(t.first);
    }
  }
  sort(pool.rbegin(), pool.rend());
  if (pool.size() < 2) {
    cout << 0 << endl;
  } else {
    cout << pool[0] * pool[1] << endl;
  }
}


Measured memory_bytes: 7296
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, M = ZZ()
    edge = [ZZ() for _ in range(M)]
    E = defaultdict(list)
    for a, b in edge:
        E[a].append(b)
        E[b].append(a)

    color = [0] * (N+1)

    def is_bi(v, c):
        color[v] = c
        for to in E[v]:
            if color[to] == c: return False
            if color[to] == 0 and not is_bi(to, -c): return False
        return True

    if is_bi(1, 1):
        x = color.count(1)
        output = x * (N - x) - M
    else: output = N * (N - 1) // 2 - M
    print(output)

    return

if __name__ == '__main__':
    main()


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

#define ll long long

int main(){
    int k;
    scanf("%d", &k);

    int ai = 7;
    for(int i=1;i<=k;i++){
        if(ai%k==0){
            printf("%d\n", i);
            return 0;
        }
        ai = (ai*10+7)%k;
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 1700
using System;

namespace _0521
{
    class Program
    {
        static void Main(string[] args)
        {
            /* int weyuieqwyuiqwe = 0;
             int a;
             int a1 = 0;
             int a2= 0;
             int a3 = 0;
             int a4 = 0,a5 = 0;
             while (true)
             {
                 weyuieqwyuiqwe = int.Parse(Console.ReadLine());
                 if (weyuieqwyuiqwe == 0) { break; }
                 a = 1000 - weyuieqwyuiqwe;
                 a1 = a / 500;
                 a = a - a1 * 500;
                 a2=a/ 100;
                 a = a - a2 * 100;
                 a3 =a/50;
                 a = a - a3*50;
                 a5 = a % 10;
                 a4 = (a-a5) / 10;
                 Console.WriteLine(a1 + a2 + a3 + a4 + a5);
                 a1 = a2 = a3 = a4 = a5 = a = 0;
             }*/
            Console.WriteLine("1");
            Console.WriteLine("6");
            Console.WriteLine("11");
            Console.WriteLine("13");
            Console.WriteLine("9");
        }
    }
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

int dis(int x1, int y1, int x2, int y2) {
  return abs(x1 - x2) + abs(y1 - y2);
}

void solve() {
  int n;
  cin >> n;
  vector<int> t(n + 1), x(n + 1), y(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];
    int dt = t[i] - t[i - 1];
    int dd = dis(x[i], y[i], x[i - 1], y[i - 1]);
    if (!(dt >= dd && (dt - dd) % 2 == 0)) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009

ll gcm(ll a,ll b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcm(a%b,b);
}

ll lcm(ll a,ll b){
  return a*b/gcm(a,b);
}

int main(){
  string s;
  cin >> s;
  ll bnum = 0;
  ll ans = 0;
  for(int i = s.size()-1;i >= 0;i--){
    if(s[i] == 'B'){
      ans += s.size()-1-i-bnum;
      bnum++;
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 640
#include <stdio.h>
#define N 10000
int linearSearch(int,int);
int S[N];
int main(){
  int i,j=0,n,q,T[N],cunt = 0;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&T[i]);
  }
  
  /*
  for(i = 0;i < n;i++){
    for(j = 0;j < q;j++){
      if(S[i] == T[j]){
	T[j] = N+1;
	cunt++;
      }
    }
  }
  */
  for(i = 0;i < q;i++){
    cunt += linearSearch(T[i],n);
  }
  
  printf("%d\n",cunt);
  return 0;
}
int linearSearch(int key,int n){
  int i,j;
  for(i = 0;i < n;i++){
      if(S[i] == key){
	return 1;
      }
  }
  return 0;
}



Measured memory_bytes: 2080
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef long long ll;

int asc(const void* a, const void* b) {return *(int*)a - *(int*)b; }

int main() {
	ll n, a[100], count = 0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (int i = 0; i < n; i += 2) {
		if (a[i] % 2 == 1) count++;
	}
	printf("%lld", count);

	return 0;
}

Measured memory_bytes: 2156
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>

using namespace std;

int main() {
    
    
    int n, m;
    cin >> n >> m;
    
    vector<vector<vector<pair<int, int>>>> g(n, vector<vector<pair<int, int>>>(3, vector<pair<int, int>>()));
    vector<vector<bool>> c(n, vector<bool>(3, 0));
    
    for (int i = 0; i < m; ++i)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u][0].push_back(make_pair(v, 1));
        g[u][1].push_back(make_pair(v, 2));
        g[u][2].push_back(make_pair(v, 0));
    }
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    
    queue<pair<pair<int, int>, int>> q;
    q.push(make_pair(make_pair(s, 0), 0));
    
    bool f = 0;
    int ret = -1;
    
    while (q.size() > 0)
    {
        pair<pair<int, int>, int> currente = q.front();
        pair<int, int> current = currente.first;
        int depth = currente.second;
        
        if (c[current.first][current.second])
        {
            q.pop();
            continue;
        }
        
        c[current.first][current.second] = 1;
        q.pop();
        
        for (int i = 0; i < g[current.first][current.second].size(); ++i)
        {
            pair<int, int> next = g[current.first][current.second][i];
            if (next.first == t && next.second == 0)
            {
                f = 1;
                ret = depth + 1;
                break;
            }
            q.push(make_pair(next, depth + 1));
        }
        if (f)
        {
            break;
        }
    }
    if (ret == -1)
    {
        cout << ret << endl;
    }
    else
    {
        cout << ret / 3 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;
const ll N =1e5;

ll mod_pow(ll x,ll n,ll mod){

  if(n==0)return 1;

  ll res=mod_pow( x*x%mod , n/2 , mod );

  if( n & 1 )res = res*x%mod;

  return res;

}



ll fact[N];

ll infact[N];



void make_factorial(void){

  fact[0] = 1;

  for( ll i = 1 ; i < N ; i++ ){

    fact[i] = fact[i-1] * i;

    fact[i] %= MOD;

  }

  for( ll i = 0 ; i < N ; i++ ){

    infact[i] = mod_pow( fact[i] , MOD-2 , MOD );

  }

}



ll comb(ll a,ll b){

  if(a == 0 && b == 0)return 1;

  if(a < b || a < 0)return 0;

  ll tmp = infact[a-b]* infact[b] % MOD;

  return tmp * fact[a] % MOD; 

}

ll f(ll n,ll k){
  ll res=0;
  for(int i=1;i<=k;i++){
	ll ex=1;
	for(int j=0;j<n;j++)ex=(ex*i)%MOD;
  
	ll tmp=(comb(k,i)*ex)%MOD;
	if((k-i)%2)res+=(MOD-tmp)%MOD;
	else res+=tmp;
	res%=MOD;
  }
  return res;
}

int main(){
  ll n,k;
  cin>>n>>k;
  if(n<k){
	cout<<0<<endl;
	return 0;
  }
  make_factorial();
  cout<<f(n,k)<<endl;
  return 0;
}



Measured memory_bytes: 4700
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]

dp = [[0, 0, 0] for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])

print(max(dp[-1]))


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

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

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
	int A,B,K,i,j;
	int a[100];
	scanf("%d %d %d",&A,&B,&K);
	i=A;
	j=0;
	while(i>0){
		if(A%i==0 && B%i==0){
			a[j]=i;
			j++;
		}
		i--;
	}
	printf("%d\n",a[K-1]);
	return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  bool room[n+1];
  for(int i=0;i<n+1;i++) room[i]=true;
  int ans[n+1];
  queue<int>q;
  q.push(1);
  vector<vector<int>>path(n+1);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  while(!q.empty()){
    int now=q.front();
    q.pop();
    int bound=path[now].size();
    for(int i=0;i<bound;i++){
      if(room[path[now][i]]){
        room[path[now][i]]=false;
        ans[path[now][i]]=now;
        q.push(path[now][i]);
      }
    }
  }
  cout<<"Yes"<<endl;
  for(int i=2;i<=n;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 10356
use std::io;
use std::io::Write;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut iter = input.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let l: usize = iter.next().unwrap().parse().unwrap();
    let mut v = Vec::with_capacity(n);
    for _ in 0..n {
        let mut line = String::with_capacity(l);
        io::stdin().read_line(&mut line).unwrap();
        let len = line.len();
        line.truncate(len - 1);
        v.push(line)
    }
    v.sort();
    let out = io::stdout();
    let mut out = out.lock();
    for i in v {
        write!(out, "{}", i).unwrap();
    }
    write!(out, "\n").unwrap();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N = 2e5 + 7;

int n, k, a[N], val[19];
int l[19][N], r[19][N];
int pref[1 << 19], suf[1 << 19], mis[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int bit = 0, sv = k;
	while(sv > 0){
		val[bit++] = sv;
		sv /= 2;
	}
	val[bit++] = 0;
	int pos = 1;
	for(int i = 0; i < bit; i++){
		pos = 1;
		for(int j = 1; j <= n; j++){
			if(pos < j) pos = j;
			while(pos < n && a[pos + 1] - a[pos] <= val[i]) pos++;
			r[i][j] = pos;
		}
		pos = n;
		for(int j = n; j >= 1; j--){
			if(pos > j) pos = j;
			while(pos > 1 && a[pos] - a[pos - 1] <= val[i]) pos--;
			l[i][j] = pos;
		}
	}
	for(int mask = 0; mask < (1 << bit); mask++) suf[mask] = n + 1;
	for(int i = 1; i <= n; i++) mis[i] = n + 1;
	for(int mask = 0; mask < (1 << bit); mask++){
		for(int i = 0; i < bit; i++){
			if((mask & (1 << i))) continue;
			pref[mask ^ (1 << i)] = max(pref[mask ^ (1 << i)], r[i][min(n, pref[mask] + 1)]);
			suf[mask ^ (1 << i)] = min(suf[mask ^ (1 << i)], l[i][max(1, suf[mask] - 1)]);
		}
	}
	int msk = (1 << bit) - 1;
	bool ok = false;
	for(int mask = 0; mask < (1 << bit); mask++){
		if(!(mask & (1 << 0))) continue;
		int rv = (msk ^ mask);
		int now = (mask ^ (1 << 0));
		if(pref[now] + 1 >= suf[rv] - 1) ok = true;
		else mis[pref[now] + 1] = min(mis[pref[now] + 1], suf[rv] - 1);
	}
	for(int i = n - 1; i >= 1; i--) mis[i] = min(mis[i], mis[i + 1]);
	for(int i = 1; i <= n; i++){
		if(ok || mis[l[0][i]] <= r[0][i]) cout << "Possible\n";
		else cout << "Impossible\n";
	}
}


Measured memory_bytes: 37760
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		//秒単位の時間Sをh:m:sの形に直す
		Scanner sc=new Scanner(System.in);
		int S=sc.nextInt();
		int h=S/3600;//秒を時間に
		int h_amari=S%3600;//余りを出す
		int m=h_amari/60;//余りの秒を分に
		int s=h_amari%60;//余りを秒に
		System.out.println(h+":"+m+":"+s);
	}

}



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



int main() {
  int N, M; cin >> N >> M;
  double A[N];
  int t = 0;
  rep(i,N){
    cin >> A[i];
    t+= A[i];
  }
  int c = 0;
  rep(i,N){
    if(A[i]*4*M>=t)c++;
  }

  if(c >= M)cout << "Yes" << endl;
  else cout << "No" << endl;


	return 0;
}



Measured memory_bytes: 3728
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.n = n
        self.e = e
        self.s = s
        self.w = w
        self.u = u
        self.d = d
    def roll(self,dir):
        if (dir == "N"):
            tmp = self.n
            self.n = self.u
            self.u = self.s
            self.s = self.d
            self.d = tmp
        elif (dir == "E"):
            tmp = self.e
            self.e = self.u
            self.u = self.w
            self.w = self.d
            self.d = tmp
        elif (dir == "S"):
            tmp = self.s
            self.s = self.u
            self.u = self.n
            self.n = self.d
            self.d = tmp
        elif (dir == "W"):
            tmp = self.w
            self.w = self.u
            self.u = self.e
            self.e = self.d
            self.d = tmp

spots = raw_input().split()
operations = raw_input()

dice = Dice(*spots)
for i in operations:
    dice.roll(i)

print dice.u

Measured memory_bytes: 6456
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(c-a)<=d)||((abs(c-b)<=d)&&(abs(a-b)<=d)))
        cout<<"Yes";
    else
        cout<<"No";
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair



int main() {
  int n;
  cin >> n;
  vl x(n), y(n);
  bool gu = false, ki = false;
  rep (i, n) {
    cin >> x[i] >> y[i];
    if ((x[i] + y[i]) % 2 == 0) {
      gu = true;
    }
    else {
      ki = true;
    }
  }
  if (gu && ki) {
    cout << -1 << endl;
    return 0;
  }
  int m = 40;
  vl d(m);
  if (gu) {
    d[m - 1] = 1;
    d[m - 2] = 1;
    rrep1 (i, m - 2) {
      d[i - 1] = d[i] * 2;
    }
  }
  else {
    d[m - 1] = 1;
    rrep1 (i, m - 1) {
      d[i - 1]  = d[i] * 2;
    }
  }
  cout << m << endl;
  rep (i, m) {
    cout << d[i] << " ";
  }
  cout << endl;
  rep (j, n) {
    ll u = x[j] + y[j], v = x[j] - y[j];
    ll now_x = 0, now_y = 0;
    string w;
    rep (i, m) {
      if (now_x <= u && now_y <= v) {
        w.push_back('R');
        now_x += d[i];
        now_y += d[i];
      }
      else if (now_x <= u && now_y > v) {
        w.push_back('U');
        now_x += d[i];
        now_y -= d[i];
      }
      else if (now_x > u && now_y > v) {
        w.push_back('L');
        now_x -= d[i];
        now_y -= d[i];
      }
      else {
        w.push_back('D');
        now_x -= d[i];
        now_y += d[i];
      }
    }
    cout << w << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      
      int n = sc.nextInt();
      int k = sc.nextInt();
      String s = sc.next();
      String ss[];
      ss = new String[n];
      for(int i=0;i<n;i++){
        ss[i]=s.substring(i,i+1);
      }
      if("A".equals(ss[k-1])){
        ss[k-1]="a";
      }
      if("B".equals(ss[k-1])){
        ss[k-1]="b";
      }
      if("C".equals(ss[k-1])){
        ss[k-1]="c";
      }
      String ans="";
      for(int j=0;j<n;j++){
        ans+=ss[j];
      }
      // 出力
      System.out.println(ans);
	}
}

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

int main(void){
  int N, ans;
  string s,t;
  cin >> N;
  ans = 2*N;
  cin >> s >> t;
  //[i ~ N)まで切り取れる
  for(int i=0;i<N;i++){
    if(s.substr(i,N-i+1) == t.substr(0,N-i)){
      ans = min(2*N - (N-i),ans);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
s = input()

ans = "WA"
if s[0] == "A" and s[2:-1].count("C") == 1 and s[1] != "C" and s[-1] != "C":
    s2 = s.replace("A","a").replace("C","c")
    if s2 == s.lower():
        ans = "AC"

print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
int n, m, q;
int v[100000][100];
int c[100000];
int g[100000];

int id = 1;

void dfs (int s) {
    int i;
    g[s] = id;
    for ( i = 0; i < c[s]; i++){
        if ( g[v[s][i]] == 0)
               dfs(v[s][i]);
    }
}

int main () {
    int i, x, y;
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; i++) {
        scanf("%d%d", &x, &y);
        v[x][c[x]++] = y;
        v[y][c[y]++] = x;
    }
    for ( i = 0; i < n; i++ ){
        if (g[i] == 0){
            dfs(i);
            id++;
        }
    }
    scanf("%d",&q);
    for(i = 0; i < q; i++){
        scanf("%d%d", &x, &y);
        if ( g[x] == g[y])
            printf("yes\n");
        else printf ("no\n");
    }
    return 0;
}


Measured memory_bytes: 44628
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,m;
bool f[25][25],vis[25][25];
struct node{
	int h,l;int step;
};
queue<node> q;
int fx[4][2]={
	0,1,
	0,-1,
	1,0,
	-1,0
};
int bfs(int x,int y,int zx,int zy){
	while(!q.empty())q.pop();
	node cur,t;
	cur.h=x;cur.l=y;cur.step=0;
	q.push(cur);
	memset(vis,0,sizeof(vis));
	while(!q.empty()){
		cur=q.front();q.pop();
		x=cur.h;y=cur.l;
		if(x<1||x>n||y<1||y>m)continue;
		if(f[x][y])continue;
		if(vis[x][y])continue;
		vis[x][y]=1;
		if(zx==x&&zy==y){
			return cur.step;
		}
		FOR(i,0,3){
			t.h=x+fx[i][0];t.l=y+fx[i][1];t.step=cur.step+1;
			q.push(t);
		}
	}
	return -2147483647;
}
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	char c;cin>>n>>m;
	for(int i=1;i<=n;i++){
		FOR(j,1,m){
			cin>>c;
			if(c=='#')f[i][j]=1;
		}
	}
	int maxi=0;
	FOR(i,1,n){
		FOR(j,1,m){
			FOR(i1,1,n){
				FOR(j1,1,m){
					maxi=max(maxi,bfs(i,j,i1,j1));
				}
			}
		}
	}
	cout<<maxi;
	return 0;
}




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

N = int(input())
a = [int(i) for i in input().split()]

color = [0] * 8
over = 0
for i in range(N) :
    if a[i] >= 3200 :
        over += 1
    else :
        color[a[i]//400] += 1

m = 8 - color.count(0)
print(max(1, m), m + over)

Measured memory_bytes: 38384
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	static List<int[]> trans, stats;

	static int mkstate() {
		int r = trans.size();
		int ctrans[] = new int[26];
		fill(ctrans, -1);
		trans.add(ctrans);
		stats.add(new int[27]);
		return r;
	}

	static void solve() throws Exception {
		int n = scanInt();
		String s[] = new String[n];
		trans = new ArrayList<>();
		stats = new ArrayList<>();
		mkstate();
		for (int i = 0; i < n; i++) {
			s[i] = scanString();
			int cur = 0;
			for (int j = s[i].length() - 1; j >= 0; j--) {
				int c = s[i].charAt(j) - 'a';
				int ctrans[] = trans.get(cur);
				if (ctrans[c] < 0) {
					ctrans[c] = mkstate();
				}
				cur = ctrans[c];
			}
			++stats.get(cur)[26];
		}
		go(0);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			int cur = 0;
			for (int j = s[i].length() - 1; j > 0; j--) {
				int c = s[i].charAt(j) - 'a';
				int ctrans[] = trans.get(cur);
				cur = ctrans[c];
			}
			ans += stats.get(cur)[s[i].charAt(0) - 'a'] - 1;
		}
		out.print(ans);
	}

	static void go(int cur) {
		int ctrans[] = trans.get(cur), cstats[] = stats.get(cur);
		for (int i = 0; i < 26; i++) {
			if (ctrans[i] >= 0) {
				go(ctrans[i]);
				int nstats[] = stats.get(ctrans[i]);
				for (int j = 0; j < 27; j++) {
					cstats[j] += nstats[j == i ? 26 : j];
				}
			}
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<string> s(N);
    vector<string> ab, b, a, x;
    for (int i = 0; i < N; ++i) {
        cin >> s[i];
        for (char &c : s[i]) {
            c = tolower(c);
        }
        if (s[i][0] == 'b' && s[i].back() == 'a') {
            ab.push_back(s[i]);
        } else if (s[i][0] == 'b') {
            b.push_back(s[i]);
        } else if (s[i].back() == 'a') {
            a.push_back(s[i]);
        } else {
            x.push_back(s[i]);
        }
    }

    string res;
    if (!a.empty()) {
        res += a[0];
    }
    for (const string &t : ab) {
        res += t;
    }
    int i, j;
    for (i = 0, j = 1; i < (int)b.size() && j < (int)a.size(); ++i, ++j) {
        res += b[i];
        res += a[j];
    }
    for (; i < (int)b.size(); ++i) {
        res += b[i];
    }
    for (; j < (int)a.size(); ++j) {
        res += a[j];
    }
    for (const string &t : x) {
        res += t;
    }
    //cout << res << endl;
    int cnt = 0;
    for (int i = 0; i + 1 < (int)res.size(); ++i) {
        cnt += res[i] == 'a' && res[i + 1] == 'b';
    }
    cout << cnt << "\n";

    return 0;
}

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


int main(int argc, char const *argv[])
{
    int n; cin >> n;
    int ws[n];
    for (int i=0; i<n; i++) cin >> ws[i];
    
    int diff = INT32_MAX;
    for (int i=0; i<n; i++) {
        int s1 = 0;
        int s2 = 0;
        for (int j=0; j<i; j++) {
            s1 += ws[j];
        }
        for (int j=i; j<n; j++) {
            s2 += ws[j];
        }
        diff = min(abs(s1 - s2), diff);
    }
    cout << diff << endl;
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect, bisect_left
from collections import Counter
from functools import reduce
from itertools import accumulate
from operator import itemgetter, xor, mul

import sys
#input = sys.stdin.readline

def inpl(): return list(map(int, input().split()))
A, B, C, D, E, F = inpl()
waters = [100*A*a + 100*B*b for a in range(30//A + 1) for b in range((30-A*a)//B + 1)]
sugars = [C*c + D*d for c in range(3000//C + 1) for d in range((3000-C*c)//D + 1)]

waters = sorted(set(waters))[1:]
sugars = sorted(set(sugars))


def check(m):
    if m > E:
        return False, None, None
    for water in waters:
        sugar_ix = bisect_left(sugars, m*water/(100-m))
        if (sugar_ix == len(sugars)):
            continue
        sugar = sugars[sugar_ix]
        if sugar + water <= F and sugar <= water*E//100:
            return True, sugar, water
    else:
        return False, None, None

OK = 0
NG = E + 1

for _ in range(1000):
    mid = (OK+NG)/2
    if check(mid)[0]:
        OK = mid
    else:
        NG = mid

_, sugar, water = check(OK)
print(sugar+water, sugar)

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string s;
    cin >> s;

    if(s == "A") cout << "T" << endl;
    else if(s == "T") cout << "A" << endl;
    else if(s == "C") cout << "G" << endl;
    else cout << "C" << endl;
}

Measured memory_bytes: 256