akhauriyash/Code-Regression huggingface dataset:
import std.stdio,std.string,std.conv,std.algorithm,std.array;

void main(){
    while(true){
        auto cards=readln.chomp.split(",").map!(to!int).array;
        if(!cards.length)break;
        cards.sort.yaku.writeln;
    }
}

string yaku(int[] c){
    if(c[0]==c[1]&&c[1]==c[2]&&c[2]==c[3]||c[1]==c[2]&&c[2]==c[3]&&c[3]==c[4]){
        return "four card";
    }else if(c[0]==c[1]&&c[1]==c[2]&&c[3]==c[4]||c[0]==c[1]&&c[2]==c[3]&&c[3]==c[4]){
        return "full house";
    }else if(c[0]==1&&c[1]==10&&c[2]==11&&c[3]==12&&c[4]==13||c[1]==c[0]+1&&c[2]==c[0]+2&&c[3]==c[0]+3&&c[4]==c[0]+4){
        return "straight";
    }else if(c[0]==c[1]&&c[1]==c[2]||c[1]==c[2]&&c[2]==c[3]||c[2]==c[3]&&c[3]==c[4]){
        return "three card";
    }else if(c[0]==c[1]&&c[2]==c[3]||c[0]==c[1]&&c[3]==c[4]||c[1]==c[2]&&c[3]==c[4]){
        return "two pair";
    }else if(c[0]==c[1]||c[1]==c[2]||c[2]==c[3]||c[3]==c[4]){
        return "one pair";
    }else{
        return "null";
    }
}

Measured memory_bytes: 1088
a, b = map(int, input().split())
def make_divisors(N):
	divisors = []
	for i in range(1, int(N**0.5)+1):
		if N % i == 0:
			divisors.append(i)
			if i != N // i:
				divisors.append(N//i)

	return divisors
import math
def is_prime(n):
	if n == 1:
		return False
	
	for k in range(2, int(math.sqrt(n)) + 1):
		if n%k == 0:
			return False
	return True
yakua = make_divisors(a)
yakub = make_divisors(b)
s = set(yakua) & set(yakub)
ans = []
for i in list(s):
	if is_prime(i):
		ans.append(i)
print (len(ans)+1)


Measured memory_bytes: 5260
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn calc_comb(n: usize, r: usize) -> usize {
    let mut num = 1;
    for i in 1..r + 1 {
        num = num * (n - i + 1) / i;
    }
    num
}

fn main() {
    input! {
    n: chars,
    k: usize,
    }
    let n = n.iter().map(|x| x.to_digit(10).unwrap() as usize).collect::<Vec<usize>>();
    let mut l = n.len();
    if l < k {println!("{}", 0); return}
    let mut k = k;
    let mut ans: i64 = 0;
    for i in n {
        if k == 0 || l < k { break; };
        if i != 0 && l >= k + 1 {
            ans += (9usize.pow(k as u32) * calc_comb(l - 1, k)) as i64;
        }
        if i != 0 {
            k -= 1;
            ans += (9usize.pow((k) as u32) * calc_comb(l - 1, k) * (i - 1)) as i64;
        }
        l -= 1;
        if k == 0 && i == 0 { ans -= 1 };
        if l < k {ans -= 1};
    }
    ans += 1;

    println!("{}", ans);
}


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

K = int(input())
q = []
r = []
for i in range(1,K+1):
    for j in range(1,K+1):
        q.append(gcd(i,j))
for i in range(1,K+1):
    for j in q:
        r.append(gcd(i,j))
print(sum(r))

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

int rec(int index, const std::vector<int>& h, std::vector<int>& result) {
    if (result[index] == -1) {
        result[index] = std::abs(h[index] - h[index - 1]) + rec(index - 1, h, result);    
        if (index > 1) {
            result[index] = std::min(
                    result[index], std::abs(h[index] - h[index - 2]) + rec(index - 2, h, result));
        }
    }
    return result[index];
}

int main() {
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> h[i];
    }
    std::vector<int> result(n, -1);
    result[0] = 0;
    std::cout << rec(n - 1, h, result);
    return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   int a[100],b[100];
   rep(i,m){cin >> a[i];cin >> b[i];}
   int num[110] = {0};

   rep(i,m){
      num[a[i]]++;
      num[b[i]]++;
   }

   rep(i,n){
      cout << num[i+1] << endl;
   }


   return 0;
}

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

int main()
{
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    if ((A-B+1) % 2 == 0){
        printf("Borys\n");
    }
    else{
        printf("Alice\n");
    }
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys
#import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

compo = []
cs = []
N = 0
M = 0
A = None
B = None
E = None

def main():
    global compo,cs,N,M,A,B,E
    N, M = rip()
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = rip()
        A[i] -= 1
        B[i] -= 1
    
    E = [[] for i in range(N)]
    for i in range(M):
        E[A[i]].append(B[i])
    
    compo = [-1] * N

    def dfs(cmp, route, hs):
        global compo,cs,N,M,A,B,E
        if(len(cs) > 0) : return
        now = route[len(route) - 1]
        for nxt in E[now]:
            if compo[nxt] == -1:
                compo[nxt] = cmp
                route.append(nxt)
                hs.add(nxt)
                dfs(cmp, route, hs)
                hs.remove(nxt)
                route.pop(-1)
            elif compo[nxt] == cmp:
                if nxt in hs:
                    cs = route[route.index(nxt):]
                return
            else:
                return


    cs = []
    c = 0
    for i in range(N):
        if(compo[i] != -1): continue
        c += 1
        a = []
        hs = set()
        a.append(i)
        hs.add(i)
        compo[i] = c
        dfs(c, a, hs)

    if len(cs) == 0:
        print(-1)
        sys.exit(0)
    
    l = cs
    while(True):
        di = dict()
        for i in range(len(l)):
            di[l[i]] = l[(i + 1) % len(l)]
        edx = -1
        for i in range(M):
            if A[i] in di and B[i] in di:
                if di[A[i]] != B[i]:
                    edx = i
                    break
        
        if edx == -1:
            print(len(l))
            print("\n".join([str(n + 1) for n in l]))
            sys.exit(0)
        
        di[A[edx]] = B[edx]
        nl = [A[edx], B[edx]]
        while True:
            nxt = di[nl[-1]]
            if nxt != nl[0]:
                nl.append(nxt)
            else:
                break
        l = nl

if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long int ll;

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

  int n, m;
  cin >> n >> m;
  vector < queue < int > > q(n + 1);
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      int a;
      cin >> a;
      q[i].push(a);
    }
  }

  vector < bool > used(m + 1, false);
  int mi = INT_MAX;
  for(int i = 1; i <= m; i++){
    vector < int > cnt(m + 1, 0);
    for(int j = 1; j <= n; j++){
      while(used[q[j].front()]) q[j].pop();
      cnt[q[j].front()]++;
    }
    int mx = INT_MIN, color = 0;
    for(int j = 1; j <= m; j++){
      if(!used[j] && cnt[j] > mx){
        mx = cnt[j];
        color = j;
      }
    }

    mi = min(mi, mx);
    used[color] = true;
  }

  cout << mi << '\n';
}


Measured memory_bytes: 768
main = do
  li <-getLine
  let [r,g,b,n] = map read $ words li
  let ans = compute r g b n
  print ans

compute :: Int -> Int -> Int -> Int -> Int
compute r g b n0 = length
  [ ()
  | x <- [0,r..n0], let n1 = n0-x
  , y <- [0,g..n1], let n2 = n1-y
  , mod n2 b == 0
  ]

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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    // x0 = 0 のとき
    long long offset = 0;
    for (int i = 0; i < N; ++i) offset = A[i] - offset;
    long long x = offset / 2;

    // 復元
    long long cur = x;
    for (int i = 0; i < N; ++i) {
        cout << cur*2 << " ";
        cur = A[i] - cur;
    }
    cout << endl;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e2 + 13;
int n, cnt[maxN], mx;
int main () {
    cin >> n;
    for (int i = 0; i < n; i++) {
	int a;
	cin >> a;
	cnt[a]++;
	mx = max(mx, a);
    }

    if (mx % 2 == 1) {
	int num = 0;
	if (cnt[mx / 2 + 1] != 2)
	    return cout << "Impossible" << endl, 0;
	for (int i = mx / 2 + 1; i <= mx; i++) {
	    num += cnt[i];
	    if (cnt[i] < 2)
		return cout << "Impossible" << endl, 0;
	}
	if (num != n)
	    return cout << "Impossible" << endl, 0;
	cout << "Possible" << endl;
    }

    else {
	int num = 1;
	if (cnt[mx / 2] != 1)
	    return cout << "Impossible" << endl, 0;
	for (int i = mx / 2 + 1; i <= mx; i++) {
	    num += cnt[i];
	    if (cnt[i] < 2)
		return cout << "Impossible" << endl, 0;
	}
	if (num != n)
	    return cout << "Impossible" << endl, 0;
	    
	cout << "Possible" << endl;
    }
}


Measured memory_bytes: 256
object Main extends App {
	val strAry = io.StdIn.readLine().split(' ')
	val longSec = strAry(0).toLong
	
	// 時を求める
	val h = longSec / 60 / 60
	val m = (longSec - (h * 60 * 60)) / 60
	val s = (longSec - (h * 60 * 60) - (m * 60))
	
	println(h + ":" + m + ":" + s)
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef pair<int ,int > pii;
typedef long long LL;
const long long oo = 1e9 + 7;

double N;
double n , h ,w;

int main() {
  //  freopen("test.txt","r",stdin);
    cin >> N;
    for (int i = 1 ; i <= 3500; i++) {
        for (int j = 1 ; j<= 3500 ; j++) {
            long long t1 = 4 * i * j - N *j - N* i;
            long long t2 = N*i*j;
            if ( t1 > 0 && t2 % t1 == 0) {
                cutiii(i,j, t2/t1)
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
class ModInt {
  static int MOD;
  long long x;

 public:
  static void mod(int m) { MOD = m; }

  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }

  long long val() { return x; }
};
int ModInt::MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> C(N, 0);

  for (int i = 0; i < (int)(N); ++i) {
    int A;
    cin >> A;
    C[A] += 1;
  }

  auto ans = [&]() -> ll {
    for (int i = 0; i < (int)(N); ++i) {
      if (i == 0 && (N % 2) && C[i] == 1) continue;
      if (((N % 2) ^ (i % 2)) && C[i] == 2) continue;
      if (C[i] == 0) continue;
      return 0;
    }
    return ModInt(2).pow(N / 2).val();
  };

  cout << ans() << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL INF=1e18;

vector<P> vec[1001];

int main(){
    int N,M;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        int a,b;
        LL c;
        cin >> a >> b >> c;
        vec[a].push_back(make_pair(b,-c));
    }
    LL dist[N+1];
    fill(dist,dist+N+1,INF);
    dist[1]=0;
    for(int loop=0;loop<N;loop++){
        for(int i=1;i<=N;i++){
            for(int j=0;j<vec[i].size();i++){
                P p=vec[i][j];
                if(dist[p.first]>dist[i]+p.second){
                    dist[p.first]=dist[i]+p.second;
                }
            }
        }
    }
    bool ch[N+1];
    memset(ch,false,sizeof(ch));
    for(int loop=0;loop<N;loop++){
        for(int i=1;i<=N;i++){
            for(int j=0;j<vec[i].size();j++){
                P p=vec[i][j];
                if(dist[p.first]>dist[i]+p.second){
                    dist[p.first]=dist[i]+p.second;
                    ch[p.first]=true;
                }
            }
        }
    }
    if(ch[N]) puts("inf");
    else cout << -dist[N] << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;

class node{
public:
  int num;
};

class edge{
public:
  node b,e;
  int cost;
};

class graph{
public:
  vector<node> nodes;
  vector<edge> edges;
  int n;
  int e;

  void set(void){
    nodes.clear();
    edges.clear();
    n = 0;
    e = 0;
  }

  void Nadd(node a){
    if(n==0){
      nodes.push_back(a);
      n++;
    }else{
      int i = 0;
      while(nodes[i].num < a.num && i<n)i++;
      nodes.insert(nodes.begin()+i,a);
      n++;
    }
  }

  void Eadd(edge a){
    if(e==0){
      edges.push_back(a);
      e++;
    }else{
      int i = 0;
      while(edges[i].cost < a.cost && i<e)i++;
      edges.insert(edges.begin()+i,a);
      e++;
    }
  }

  bool Nexist(node a){
    for(int i=0;i<n;i++){
      if(a.num == nodes[i].num)return true;
    }
    return false;
  }

  graph prim(void){
    graph res;

    res.set();

    if(!e)return res;
    else{
      res.Eadd(edges[0]);
      res.Nadd(edges[0].b);
      res.Nadd(edges[0].e);

      while(res.n < n){
	for(int i=0;i<e;i++){
	  if(res.Nexist(edges[i].b) && !res.Nexist(edges[i].e)){
	    res.Eadd(edges[i]);
	    res.Nadd(edges[i].e);
	    i = 0;
	  }else if(!res.Nexist(edges[i].b) && res.Nexist(edges[i].e) ){
	    res.Eadd(edges[i]);
	    res.Nadd(edges[i].b);
	    i = 0;
	  }
	}
      }
      return res;
    }
  }

};

int main(){
  int n,m;
  int ans;
  graph map,prim;
  node tmp;
  edge tmp2;

  while(1){
    cin >> n;
    if(!n)break;

    map.set();
    for(int i=0;i<n;i++){
      tmp.num = i;
      map.Nadd(tmp);
    }
    
    cin >> m;
    for(int i=0;i<m;i++){
      scanf("%d,%d,%d",&tmp2.b.num,&tmp2.e.num,&tmp2.cost);
      map.Eadd(tmp2);
    }

    prim = map.prim();   

    ans = 0;
    for(int i=0;i<prim.e;i++)ans += prim.edges[i].cost - 100;

    cout << ans/100 << endl;
    
  }
  return 0;
}

Measured memory_bytes: 0
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

#define LL long long int
#define MOD 1000000007ll

int N;

LL ans = 0;

void solve(){
	const int A = 0;
	const int G = 1;
	const int C = 2;
	const int T = 3;
	LL dp[N+1][4][4][4];
	for(int i=0;i<=N;i++){
		for(int Z=0;Z<4;Z++){
			for(int Y=0;Y<4;Y++){
				for(int X=0;X<4;X++) dp[i][Z][Y][X] = 0;
			}
		}
	}
	//長さiの文字列で、
	//i,i-1,i-2番目がそれぞれ文字X,Y,Zを付加したときの
	//条件を満たす文字列の数を
	//dp[i][Z][Y][X]とおく。
	for(int Z=0;Z<4;Z++){
		for(int Y=0;Y<4;Y++){
			for(int X=0;X<4;X++){
				if(
					(Z==A && Y==G && X==C) ||
					(Z==G && Y==A && X==C) ||
					(Z==A && Y==C && X==G)
				) continue;
				dp[3][Z][Y][X] = 1;
			}
		}
	}
	for(int i=4;i<=N;i++){
		for(int Z=0;Z<4;Z++){
			for(int Y=0;Y<4;Y++){
				for(int X=0;X<4;X++){
					for(int m=0;m<4;m++){
						if(
							(Z==A && Y==G && X==C) ||
							(Z==G && Y==A && X==C) ||
							(Z==A && Y==C && X==G) ||

							(m==A && Z==G && X==C) ||
							(m==A && Y==G && X==C)
						) continue;
						dp[i][Z][Y][X] += dp[i-1][m][Z][Y] % MOD;
						dp[i][Z][Y][X] = dp[i][Z][Y][X] % MOD;
					}
				}
			}
		}
	}
	for(int Z=0;Z<4;Z++){
		for(int Y=0;Y<4;Y++){
			for(int X=0;X<4;X++){
				ans += dp[N][Z][Y][X] % MOD;
				ans = ans % MOD;
			}
		}
	}
}
 
int main(){
	cin >> N;
 
	solve();

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int b = int.Parse(input[2]);
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
        int min = n+m;
        min = Min(min,m+b);
        min = Min(min,n+b);
        WriteLine(min);
    }
}

Measured memory_bytes: 11092
N = int(input())

result=[0,0,0,0]

for i in range(N):
  S=input()
  if S == "AC":
    result[0] += 1
  elif S == "WA":
    result[1] += 1
  elif S == "TLE":
    result[2] += 1
  else:
    result[3] += 1

print("AC x " + str(result[0]))
print("WA x " + str(result[1]))
print("TLE x " + str(result[2]))
print("RE x " + str(result[3]))

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

int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}

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


Measured memory_bytes: 512
// Author - Abhishek giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 100000000007
#define V(type) vector<type> 
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)

/*##################################################################################*/


/*
bitset<10000000> prime ;
void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 10000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 10000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/

bool isprime(long n)
{
    for(int i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}


/*
ll fib(int n) 
{ 
  ll a = 0, b = 1, c, i; 
  if( n == 0) 
    return a; 
  for (i = 2; i <= n; i++) 
  { 
    c = (a + b); 
    a = b; 
    b = c; 
  } 
  return b; 
}
*/


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


ll findgrouplcm(ll arr[], ll n) 
{ 
    ll ans = arr[0]; 
  
    for (ll i = 1; i < n; i++) 
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));
  
    return ans; 
}



ll powerwithmod(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t =1;
    //cin>>t;
    while(t--)
    {
        ll k,a,b;
        in(k)>>a>>b;
        if(a % k == 0){
            cout<<"OK";
        }
        else{
            ll rem = a % k;
            int num = a - rem;
            if(b >= num + k){
                cout<<"OK";
            }
            else{
                cout<<"NG";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
fun main(args : Array<String>) {
    val (a, b, c) = readLine()!!.split(" ").map { it.toLong() }

    if (a % 2L == 0L || b % 2L == 0L || c % 2L == 0L) {
        println(0)
        return
    }

    val ab = a * b * (c - c / 2L) - a * b * (c / 2L)
    val bc = b * c * (a - a / 2L) - b * c * (a / 2L)
    val ca = c * a * (b - b / 2L) - c * a * (b / 2L)

    println(Math.min(Math.min(ab, bc), ca))
}

Measured memory_bytes: 36008
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void s(const string&a,const string&b,vector<bool>&ab){
    int x=a.length(),y=b.length();
    ab.assign(x+1,false);
    fr(i,x+1){
        int w=max(x,i+y);
        fr(t,w){
            char C{'?'};
            if(t<x&&a[t]!='?') C=a[t];
            if(i<=t&&t<i+y&&b[t-i]!='?'){
                if(C=='?') C=b[t-i];
                else if(C!=b[t-i]){
                    ab[i]=true;
                    break;
                }
            }
        }
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    string a,b,c;
    int x,y,z;
    in>>a>>b>>c;
    x=a.length(),y=b.length(),z=c.length();
    vector<bool> ab,ac,ba,bc,ca,cb;
    s(a,b,ab);
    s(a,c,ac);
    s(b,a,ba);
    s(b,c,bc);
    s(c,a,ca);
    s(c,b,cb);
    int ans{INT_MAX};
    for(int i=-z-y;i<=x+z;++i) for(int j=-y-z;j<=x+y;++j){
        bool f=true;
        if(-y<=i&&i<0&&ba[-i]) f=false;
        if(0<=i&&i<=x&&ab[ i]) f=false;
        if(-z<=j&&j<0&&ca[-j]) f=false;
        if(0<=j&&j<=x&&ac[ j]) f=false;
        if(i<=j&&j<=i+y&&bc[j-i]) f=false;
        if(j<=i&&i<=j+z&&cb[i-j]) f=false;
        if(f) ans=min(ans,max({x,i+y,j+z})-min({0,i,j}));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long int ll;

#define rep(i,n) for(int i = 0;i<n;++i)
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
#define MySort(conta) sort(conta.begin(),conta.end(), z::LessA)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

struct z{
	ll x;
	ll y;
	bool solved;
	static bool LessA(const z& rLeft, const z& rRight)
		{ return rLeft.x < rRight.x; } 
	static bool MoreY(const z& rLeft, const z& rRight)
		{ return rLeft.y > rRight.y; }
};

int main() {
	cin.tie(0);
        ios::sync_with_stdio(false);	
	ll n;
	cin >> n;
	vector<z> red(n);
	vector<z> blue(n);
	rep(i,n){
		cin >> red[i].x >> red[i].y;
	}
	rep(i,n){
		cin >> blue[i].x >> blue[i].y;
	}
	MySort(blue);
	sort(red.begin(),red.end(),z::MoreY);
	ll ans = 0;
	repi(itr,blue){
		repi(itr2,red){
			if(itr2->solved)continue;
			if(itr->x>itr2->x&&itr->y>itr2->y){
				itr2->solved = true;
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
    int n, k; cin >> n >> k;
    int cnt = 0;
    vector<int> a(200000);
    vector<int> memo(200000+1, 0);
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(memo[a[i]]==0){
            cnt++;
        }
        memo[a[i]]++;
    }
    sort(memo.begin(), memo.end());
    int ans = 0;
    int del=0;
    if(cnt <= k){ cout << 0 << endl; return 0;}
    else del = cnt-k;
    for(int i=1; i<=200001; i++){
        if(memo[i]==0) continue;
        else{
            ans += memo[i];
            del--;
            if(del == 0) break;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 4848
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B,H,M;
const double PI=3.141592653589793238;
double Abs(double x){
    if(x<0)return -x;
    return x;
}
int main(){
    cin>>A>>B>>H>>M;
    double rad=Abs((60*H+M)/2.0-6*M);
    if(rad>180.0)rad=360-rad;
    rad*=PI/180.0;
    double si=A*sin(rad);
    double co=A*cos(rad);

    cout<<setprecision(15)<<sqrt(si*si+(B-co)*(B-co))<<endl;

    return 0;
}

Measured memory_bytes: 4012
#define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main(){
	double v;
	
	while( cin >> v ){
		double t=v/9.8;
		double y=4.9*t*t;
		double n=0;
		while(1){
			if(5*n-5 > y){
				break;
			}
			n=n+1;
		}
		cout << n << endl;
	}
	return 0;
}

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

int main (void){
  long long int n = 0,a = 0;

  cin >> n;

  vector<long int> num(n,0);
  vector<long int> mem(n + 1,0);

  for(int i = 0; i < n - 1;i++){
    cin >> num[i];
    mem[num[i]]++;
  }

  for(int i = 1; i <= n;i++){
    cout << mem[i] << endl;
  }

  return 0;

}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    string s;cin>>s;
    map<char,int>a;
    rep(i,3){
        a[s[i]]++;
    }
    if(a.size()==2)cout<<"Yes"<<endl;
    if(a.size()==1)cout<<"No"<<endl;
}

Measured memory_bytes: 256
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    match std::io::stdin().read_line(&mut line) {
        Ok(0) => return Err("eof".to_string()),
        Ok(_) => (),
        Err(err) => return Err(format!("{:?}", err)),
    }

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

fn shuffle(s: String, h: usize) -> String {
    let (left, right) = s.split_at(h);
    let mut right = right.to_string();
    right.push_str(left);
    right
}

fn main() {
    // println!("{}", shuffle("abcdeefab", 4))
    loop {
        let sv = read_parameters::<String>().unwrap();
        let mut s = sv[0].to_owned();

        if s == "-" {
            break;
        }

        let mv = read_parameters::<usize>().unwrap();
        let m = mv[0];
        for _ in 0..m {
            let hv = read_parameters::<usize>().unwrap();
            let h = hv[0];
            s = shuffle(s, h);
        }
        println!("{}", s);
    }
}



Measured memory_bytes: 5036
input_str = input().split(' ')
W = int(input_str[0])
H = int(input_str[1])
x = int(input_str[2])
y = int(input_str[3])
r = int(input_str[4])

print('Yes' if x-r >= 0 and x+r <= W and y-r >= 0 and y+r <= H else 'No')

Measured memory_bytes: 7720
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  long long sum = 0;
  for (int i = 0; i < N; i++){
    sum += A[i];
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++){
    mp[A[i]]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int B, C;
    cin >> B >> C;
    sum += (long long) (C - B) * mp[B];
    mp[C] += mp[B];
    mp.erase(B);
    cout << sum << endl;
  }
}

Measured memory_bytes: 6688
#include<stdio.h>
int main(){
    char s[20];
    char ans[20];
    int ans_i=0;
    scanf("%s",s);

    int cnt=0;
    for(int i=0;s[i]!='\0';i++){
        if(s[i]=='0'){
            ans[ans_i++]='0';
        }else if(s[i]=='1'){
            ans[ans_i++]='1';
        }else{
            if(ans_i-1>=0)ans_i--;
        }
    }
    ans[ans_i]='\0';
    printf("%s\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
#define prDouble(x) cout<<fixed <<setprecision(10)<<x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
 ll dp[3001][3001][2];
 
ll solve(vector<int>&Deq,int i,int j,bool turn)
{
   if(i>j)
   return 0;
 
   if(dp[i][j][turn]!=-1)
   return dp[i][j][turn];
 
   if(turn==1)
   return dp[i][j][turn]=max((Deq[i]+solve(Deq,i+1,j,0))
                              ,(Deq[j]+solve(Deq,i,j-1,0)));
    
    else return dp[i][j][turn]=min(solve(Deq,i+1,j,1),solve(Deq,i,j-1,1));
}
int main()
{
    int n;
    cin>>n;
    vector<int>Deq(n+1);
    memset(dp,-1,sizeof dp);
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>Deq[i];
        sum+=Deq[i];
    }
    ll scoreX=solve(Deq,1,n,1);
    ll scoreY=(sum-scoreX);
 
    cout<<scoreX-scoreY;
    return 0;
}

Measured memory_bytes: 141184
ans = []
while True:
    n, x = map(int, input().split())
    cnt = 0
    if n == 0 and x == 0:
        break

    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i+j+k == x:
                    cnt += 1
    
    ans.append(cnt)

for i in range(len(ans)):
    print(ans[i])



Measured memory_bytes: 5596
// AOJ DSL_2_C Range Search (kD Tree)
// 2018.5.17 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	if (c == '-') { c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

#define MAX_N  500005

typedef struct { int id; int p[2], child[2], min[2], max[2]; } NODE;
NODE kdTree[MAX_N];

int root;       // root of kd tree
int ans[102], len;
int s[2], t[2];

int mkKdTree(int l, int r, int k)
{
	int i, j, c;
	int m, x;
	NODE t;

	m = (l+r)>>1;

	t = kdTree[m], x = t.p[k], kdTree[m] = kdTree[r], kdTree[r] = t;
	i = l-1;
	for (j = l; j < r; j++) {
		if (kdTree[j].p[k] < x) {
			if (++i != j) t = kdTree[++i], kdTree[i] = kdTree[j], kdTree[j] = t;
		}
	}
	t = kdTree[r], kdTree[r] = kdTree[m], kdTree[m] = t;

	kdTree[m].child[0] = (l == m)? 0: mkKdTree(l, m-1, k);
	kdTree[m].child[1] = (m == r)? 0: mkKdTree(m+1, r, k);

	for (i = 0; i < 2; i++) {
		kdTree[m].min[i] = kdTree[m].max[i] = kdTree[m].p[i];
		for (j = 0; j < 2; j++) if (c = kdTree[m].child[j]) {
			if (kdTree[m].min[i] > kdTree[c].min[i]) kdTree[m].min[i] = kdTree[c].min[i];
			if (kdTree[m].max[i] < kdTree[c].max[i]) kdTree[m].max[i] = kdTree[c].max[i];
		}
	}
	return m;
}

void printRange(int node)
{
	int c;

	if (kdTree[node].p[0] >= s[0] && kdTree[node].p[0] <= t[0] &&
		kdTree[node].p[1] >= s[1] && kdTree[node].p[1] <= t[1]) {
		ans[len++] = kdTree[node].id;
	}

	if ((c = kdTree[node].child[0]) &&
		kdTree[c].min[0] <= t[0] && s[0] <= kdTree[c].max[0] &&
		kdTree[c].min[1] <= t[1] && s[1] <= kdTree[c].max[1])
			printRange(c);

	if ((c = kdTree[node].child[1]) &&
		kdTree[c].min[0] <= t[0] && s[0] <= kdTree[c].max[0] &&
		kdTree[c].min[1] <= t[1] && s[1] <= kdTree[c].max[1])
			printRange(c);
}

int kdcmp(NODE *a, NODE *b) { if (a->p[0]-b->p[0]) return a->p[0]-b->p[0]; return a->p[1]-b->p[1]; }

void insertion_sort(int n, int *a)
{
	int i, j, key;

	for (i = 1; i < n; i++) {
		key = a[i];
		j = i-1;
		while (j >= 0 && a[j] > key) a[j+1] = a[j], j--;
		a[j+1] = key;
	}
}

int main()
{
	int n, q, i;

	n = in();
	for (i = 1; i <= n; i++) {
		kdTree[i].id = i-1, kdTree[i].p[0] = in(), kdTree[i].p[1] = in();
	}
	qsort(kdTree+1, n, sizeof(NODE), kdcmp);
	root = mkKdTree(1, n, 0);

	q = in();
	while (q--) {
		s[0] = in(), t[0] = in();
		s[1] = in(), t[1] = in();
		len = 0;
		printRange(root);
		insertion_sort(len, ans);
		for (i = 0; i < len; i++) out(ans[i]);
		pc('\n');
	}
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
//#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




void smain() {

    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    for(int i=0;i<=1000;i++){
        if(a[0]%2==1||a[1]%2==1||a[2]%2==1){
            cout<<i;
            return;
        }
        int b[3];
        b[0]=a[1]/2+a[2]/2;
        b[1]=a[0]/2+a[2]/2;
        b[2]=a[0]/2+a[1]/2;
        a[0]=b[0];
        a[1]=b[1];
        a[2]=b[2];
    }
    cout<<-1;

}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef long long ll;
static const ll Z = 1 << 21;
#define rep(i,s,n)for(ll i = s;i<n;i++)
char s[Z];

int main() {
	cin >> s;
	char* S = &s[0];
	ll b[26] = { 0 };
	while (*S) 	b[*S++ - 'a']++;

	rep(i, 0, 26) {
		if (b[i] % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

const MOD: i64 = 1_000_000_007;
const MAX: i64 = 1_000_000_001;

fn main() {
    input! {
        n: usize,
        k: usize,
        mut a: [i64; n],
    }

    a.sort();

    let mut negatives: Vec<i64> = Vec::new();
    let mut positives: Vec<i64> = Vec::new();

    for v in a {
        if v < 0 {
            negatives.push(v);
        } else {
            positives.push(v);
        }
    }

    positives.reverse();

    let mut ans = 1;
    let mut cur = 0;
    let mut neg_cur = 0;
    let mut pos_cur = 0;

    if positives.len() == 0 && k % 2 == 1 || k == n {
        negatives.reverse();

        while cur < k {
            let neg_v = negatives.get(neg_cur).unwrap_or(&MAX);
            let pos_v = positives.get(pos_cur).unwrap_or(&MAX);

            if neg_v.abs() < pos_v.abs() {
                ans = ans * neg_v % MOD;
                neg_cur += 1;
            } else {
                ans = ans * pos_v % MOD;
                pos_cur += 1;
            }

            cur += 1;
        }
    } else {
        while cur < k {
            let neg_v1 = negatives.get(neg_cur);
            let neg_v2 = negatives.get(neg_cur + 1);
            let pos_v1 = positives.get(pos_cur);
            let pos_v2 = positives.get(pos_cur + 1);

            let neg_v = if neg_v1.and(neg_v2).is_some() {
                neg_v1.unwrap() * neg_v2.unwrap()
            } else {
                -MAX * MAX
            };

            let pos_v = if pos_v1.and(pos_v2).is_some() {
                pos_v1.unwrap() * pos_v2.unwrap()
            } else {
                -MAX * MAX
            };

            if neg_v < pos_v || cur == k - 1 {
                ans = ans * pos_v1.unwrap() % MOD;
                pos_cur += 1;
                cur += 1;
            } else {
                ans = ans * (neg_v % MOD) % MOD;
                neg_cur += 2;
                cur += 2;
            }
        }
    }

    if ans < 0 {
        println!("{}", ans + MOD);
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 8032
def solver(stones, **_):
  dp = [0 for _ in range(len(stones))]

  dp[1] = abs(stones[1] - stones[0])

  # i番目までの石について部分解を求める
  for i in range(len(stones) - 2):
    dp[i + 2] = min(
      dp[i] + abs(stones[i] - stones[i + 2]),
      dp[i + 1] + abs(stones[i + 1] - stones[i + 2])
    )

  return dp[len(stones) - 1]

if __name__ == "__main__":
  _ = input()
  stones = list(map(int, input().split()))

  print(solver(**locals()))

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<int> l(n*2);
	for (int i=0;i<n*2;i++){
		cin>>l[i];
	}
	sort(l.begin(), l.end());
	int v=0;
	for (int j=n*2-2;j>=0;j-=2){
		v+=l[j];
	}
	cout<<v<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
//#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
ll dp[N];
ll p1=0;
ll z=0;
void dfs(ll v,ll p,ll k){
    multiset <int> s;
    for (auto u : g[v]){
        if (u==p) continue;
        dfs(u,v,k);
        s.insert(dp[u]+1);
        if (dp[u]+1>k){
            p1=1;
            return ;
        }
    }
    if (p1) return ;
   // if (v==1) cout << s.size() << " end " << endl;
   vector <int> y;
    while(s.size()>1){
        auto t=s.end();
        t--;
        ll val1=*t;
        s.erase(t);
        if (*s.begin()+val1>k){

                y.pb(val1);
                continue;
        }
        t=s.upper_bound(k-val1);
        t--;
        s.erase(t);
        z++;
    }
    if (s.size()){
        y.pb(*s.begin());
    }
    if (y.size()>2){
        p1=1;
        return ;
    }
    if (v==1 && y.size()>1) p1=1;
    if (y.size()){
        sort(y.begin(),y.end());
        for (int i=1;i<y.size();i++) z++;
        dp[v]=y[0];
        if (v==1) z++;
    }
    if (dp[1]>k) p1=1;
}
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    ll l=0,r=n+10;
    while(r-l>1){
        memset(dp,0,sizeof dp);
        p1=0;
        ll mid=(r+l)/2;
        z=0;
        dfs(1,1,mid);
        if (!p1) r=mid;
        else l=mid;
        //cout << z << " f " << mid << endl;
    }memset(dp,0,sizeof dp);
    z=0;
    p1=0;
    dfs(1,1,r);
    cout << z << " " << r << endl;
}


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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
import numpy as np
n=int(input())
a = np.array([int(i) for i in input().split()])

ans=0
for i in range(60):
    cnt=np.count_nonzero(a&1)
    ans+=(n-cnt)*cnt*(2**i)
    if ans>=10**9+7:
        ans%=(10**9+7)
    a>>=1
print(ans)

Measured memory_bytes: 66500
a = []
b = []
N,H = map(int,input().split())
for i in range(N):
    ca,cb = map(int,input().split())
    a.append(ca)
    b.append(cb)
count = 0
ma = max(a)
b.sort(reverse = True)
def ans():
    global N,H,count
    for i in range(N):
        if b[i] < ma:
            break
        H -= b[i]
        count += 1
        if H <= 0:
            return count
    count += H//ma
    if H%ma != 0:
        count += 1
    return count
print(ans())

Measured memory_bytes: 11296
p, *q = open(0)
h, w, k = map(int, p.split())
s = [list(i.strip()) for i in q]
c = 1
r = range
for y in r(h):
    # 番号
    for x in r(w):
        if s[y][x] == "#":
            s[y][x] = c
            c += 1
        else:
            s[y][x] = 0
    # 左から右
    for x in r(w):
        if s[y][x] == 0 and x:
            s[y][x] = s[y][x - 1]
    # 右から左
    for x in r(w):
        if s[y][-x-1] == 0 and x:
            s[y][-x-1] = s[y][-x]
for x in r(w):
    # 上から下
    for y in r(h):
        if s[y][x] == 0 and y:
            s[y][x] = s[y - 1][x]
    # 下から上
    for y in r(h):
        if s[-y-1][x] == 0 and y:
            s[-y-1][x] = s[-y][x]
for i in s:
    print(*i)

Measured memory_bytes: 7632
import math
n=int(input())
lists=list(map(int,input().split()))
sums=[0 for i in range(n)]
c=0
for i in range(n):
    c+=lists[i]
    sums[i]=c
#累積和
ans=10**10
for i in range(1,n-2):
    a=sums[i]
    b=sums[n-1]-sums[i]

    #aが左側の分割、bが右側の分割
    a_left=0
    a_right=i-1
    b_left=i
    b_right=n-1
    for j in range(20):
        c=(a_left+a_right)/2
        if 2*sums[math.floor(c)]>a:
            a_left=a_left
            a_right=math.floor(c)
        elif 2*sums[math.floor(c)]<=a:
            a_left=math.floor(c)
            a_right=a_right
    for j in range(20):
        d=(b_left+b_right)/2
        if 2*(sums[math.floor(d)]-sums[i])>b:
            b_left=b_left
            b_right=math.floor(d)
        elif 2*(sums[math.floor(d)]-sums[i])<=b:
            b_left=math.floor(d)
            b_right=b_right

    A1=sums[a_left]
    A2=sums[a_left+1]
    B1=sums[b_left]
    B2=sums[b_left+1]
    J=abs(max(a-A1,A1,a+b-B1,B1-a)-min(a-A1,A1,a+b-B1,B1-a))
    K=abs(max(a-A2,A2,a+b-B2,B2-a)-min(a-A2,A2,a+b-B2,B2-a))
    L=abs(max(a-A2,A2,a+b-B1,B1-a)-min(a-A2,A2,a+b-B1,B1-a))
    M=abs(max(a-A1,A1,a+b-B2,B2-a)-min(a-A1,A1,a+b-B2,B2-a))
    ans=min(J,K,L,M,ans)
print(ans)

Measured memory_bytes: 96032