akhauriyash/Code-Regression huggingface dataset:
MOD = 1000000000 + 7


class DP2D(object):

    def __init__(self, item_n: int, border: int, initializer: int = 0):
        self.item_n = item_n
        self.border = border
        self.table = [[initializer for _ in range(self.item_n + 1)] for _ in range(self.border + 1)]

    def __str__(self):
        return "\n".join(list(map(lambda l:
                                  " ".join(list(map(str, l)))
                                  , self.table)))

    def __repr__(self):
        return "DynamicProgramming object:\n" + \
               "item_n: " + str(self.item_n) + ", border: " + str(self.border) + "\n" + \
               "table:\n" + self.__str__()

    def solve(self, expr: callable) -> list:
        raise NotImplementedError

    def fill_0_idx_with(self, value: int) -> "DP2D":
        self.table[0] = [value for _ in range(self.item_n + 1)]
        for i in range(1, self.border + 1):
            self.table[i][0] = value
        return self


class BitDP2D(DP2D):
    def __init__(self, item_n: int, border: int, bit_n: int):
        super(BitDP2D, self).__init__(item_n, border)
        self.bit_n = bit_n

    def solve(self, expr: callable) -> list:
        for sbj_i in range(1, self.border+1):
            for bit in range(2 ** self.bit_n):

                for item_idx in range(1, self.item_n):
                    if (bit >> item_idx) & 1 and (bit >> (item_idx-1)) & 1:
                        break
                else:

                    for item_idx in range(1, self.item_n + 1):
                        if item_idx > 1 and (bit >> (item_idx-2)) & 1:  # from L
                            self.table[sbj_i][item_idx] += self.table[sbj_i - 1][item_idx - 1]
                            self.table[sbj_i][item_idx] %= MOD
                        elif (bit >> (item_idx-1)) & 1:  # from R
                            self.table[sbj_i][item_idx] += self.table[sbj_i - 1][item_idx + 1]
                            self.table[sbj_i][item_idx] %= MOD
                        else:  # from center
                            self.table[sbj_i][item_idx] += self.table[sbj_i - 1][item_idx]
                            self.table[sbj_i][item_idx] %= MOD
        return self.table


if __name__ == '__main__':
    H, W, K = map(int, input().split())
    dp = BitDP2D(W, H, W-1)
    dp.table[0][1] = 1
    print(dp.solve(None)[H][K])


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

struct permutation{
  vector<int> v, idx;
  ll N;
  permutation(ll n){
    v.resize(n);
    idx.resize(n);
    N = n;
    init();
  }
  void init(){
    re(i, N) v[i] = i;
  }
  bool step(){
    return next_permutation(v.begin(), v.end());
  }
  void sorted(){
    re(i, N) idx[v[i]] = i;
  }
};

int main(int argc, char const *argv[]) {
  ll x, y, n, m;std::cin >> n >> m;
  permutation p(n);
  vvl eg = vv(n, n, 0, ll);
  re(i, m){
    std::cin >> x >> y;
    eg[x-1][y-1] = eg[y-1][x-1] = 1;
  }
  ll c = 0;
  do{
    p.sorted();
    bool flag = true;
    re(i, n-1) if(eg[p.idx[i]][p.idx[i+1]]==0) flag = false;
    if(p.idx[0] == 0 && flag) c++;
  }while(p.step());
  std::cout << c << '\n';
  return 0;
}


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

int main() {
    ll A, B, M;
    cin >> A >> B >> M;
    vector<ll> a(A);
    vector<ll> b(B);
    for (ll i=0; i<A; i++) cin >> a[i];
    for (ll i=0; i<B; i++) cin >> b[i];
    
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    pq.push(*min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end()));

    for (ll i=0; i<M; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        pq.push(a[x-1] + b[y-1] - c);
    }

    cout << pq.top() << endl;

    return 0;
}



Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, K;
    cin>>N>>K;
    vi A(N);
    REP(i, 0, N) cin >> A[i];
    REP(i, K, N){
        if(A[i] <= A[i-K]) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3992
# C - Unification
# https://atcoder.jp/contests/abc120/tasks/abc120_c
S = raw_input()

num1 = 0
num0 = 0

for s in S:
    if s == '1':
        num1 += 1
    else:
        num0 += 1

print '{}'.format(2*min(num0, num1))


Measured memory_bytes: 2692
n= int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = []
c = []
for i in range(n):
  b.append(a[i][0]+a[i][1])
  c.append(a[i][0]-a[i][1])
maxbc=[max(b)-min(b), max(c)-min(c)]
print(max(maxbc))

Measured memory_bytes: 61432
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    cout<<(n-2)*180<<endl;
    return 0;
}



Measured memory_bytes: 256
//
//  main.cpp
//  temp
//
//  Created by tolemy on 2019/08/04.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    
    unsigned long sum = 0;
    
    //1からn-1までの和
    if(n > 1)
    {
        unsigned long a = 0;
        unsigned long b = 0;
        if(n%2==0)
        {
            a = n / 2;
            b = n - 1;
        }
        else
        {
            a = n;
            b = (n - 1)/2;
        }
        
        sum = a * b;
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()

    ret = 0
    for n in range(1, N-1):
        if P[n-1] < P[n] < P[n+1] or P[n-1] > P[n] > P[n+1]:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10156
// Vicfred
// https://atcoder.jp/contests/abc047/tasks/abc047_a
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;

void main() {
    int[] candies = readln.split.map!(to!int).array;
    candies.sort();

    if(candies[0]+candies[1] == candies[2])
        "Yes".writeln;
    else
        "No".writeln;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(( int)i = 0; i< n; i++);
#define repr(i,n) for( (int)i = n-1 ; i>=0 ;i--);
#define pb push_back
#define pi 3.141592653589793
#define sll signed long long int // -10^9 to 10^9
#define ll long long int// for 0 to 10^18
#define ull unsigned long long int // for 0 to 10^18
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define MOD 1000000007
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
typedef vector<int> vi;
/* 
ll sum_ofGP_modM(ll a , ll n, ll mod)  //// (1 + A^1 +A^2 + A^3 + A^4 + -------+ A^N) % M  usually here n= Total terms in series-1
////and  if series is something for eg 3^2 + 3^4 here a= 9,r=9  our ans can be found out as 
// let a1= first term 3^2 just do ans = a1*sum_ofGP_modM(9 , N-1, ull mod)
	if(n == 0) return 1;
	if(n == 1) return (1 + a) % mod;
	ll res;
	if(n % 2)
		res = (a + 1) * GPSumWithMod((a*a) % mod , (n-1)/2);
	else{ res = (a + 1) * GPSumWithMod((a*a) % mod , n/2 - 1);res %= mod;res = (res * a) + 1;}
    return res % mod;
}
//Whenever we have (a/b)%P == (a * fast_pow(b,P-2))%P
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
} */



int main() {
  ll n,t=0,x=0,y=0,pt,px,py,nt,nx,ny,k;cin>>n;
	while(n--){
    cin>>nt>>nx>>ny;
		pt=nt-t;px=abs(nx-x);py=abs(ny-y);
		k=pt-px-py;
		if((k<0)||(k&1)){cout<<"No";return 0;}
		t=nt;x=nx;y=ny;
	}
	cout<<"Yes";
  return 0;
}


Measured memory_bytes: 256
function main()
          a = parse.(split(readline()))
          b = sort(a)
          l = length(b)
  		  m = 0
          sum = 0  
  		if l % 2 == 0
          	m=b[convert(Int, l/2)]
          else
            m=b[convert(Int, (l+1)/2)]
          end
  		  for i in 1:l
    		sum += abs(a[i]-m)
  end
  			print(sum)
        end
        main()

Measured memory_bytes: 121728
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
  int key;
  struct node *p;       //親
  struct node *left;    //左の子
  struct node *right;   //右の子
} tree;
void insert(tree *);
void Inorder(tree *);
void Preorder(tree *);
void find(tree *,int);
void delete(int);
tree *Successor(tree *);
tree *t = NULL;

int main(){
  int n,i,k;
  char function[10];
  tree *new;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",function);
    if(function[0] == 'f'){
      scanf("%d",&k);
      find(t,k);
    }
    else if(function[0] == 'p'){
      Inorder(t);
      printf("\n");
      Preorder(t);
      printf("\n");
    }
    else if(function[0] == 'i'){
      scanf("%d",&k);
      new=malloc(sizeof(struct node));
      new->key=k;
      insert(new);
    }
    else if(function[0] = 'd'){
      scanf("%d",&k);
      delete(k) ;
    }
  }
  return 0;
}

void Preorder(tree *x){
  if(x == NULL) return;
  else  printf(" %d",x->key);
  if(x->left != NULL) Preorder(x->left);
  if(x->right != NULL) Preorder(x->right);
}
void Inorder(tree *x){
  if(x == NULL) return;
  if(x->left != NULL) Inorder(x->left);
  if(x != NULL) printf(" %d",x->key);
  if(x->right != NULL) Inorder(x->right);
}

void insert(tree *new){
  tree *x;
  tree *y;
  
  y=NULL;
  x=t;
  
  while(x != NULL){
    y=x;
    if(x->key > new->key) x=x->left;
    else x=x->right;
  }
  new->p = y;
  
  if(y == NULL){
    t=new;
    new->left = NULL;
    new->right = NULL;
  }
  else if(y->key > new->key){
    y->left = new;
    new->left = NULL;
    new->right = NULL;
  }
  else{
    y->right = new;
    new->left = NULL;
    new->right = NULL;
  }
}

void find(tree *t,int key){
  if(t == NULL){
    printf("no\n");
    return;
  }
  if(t->key == key){
    printf("yes\n");
    return;
  }
  if(t->key > key){
    find(t->left,key);
    return;
  }
  else{
    find(t->right,key);
    return;
  }
}

void delete(int k){
  tree *x;  //目的の場所
  tree *y;  //消す場所
  tree *z;  //繋ぎ用
  x = t;
  while(1){
    if(x == NULL) return;
    if(x->key == k) break;
    else if(x->key > k) x=x->left;
    else x=x->right;
  }

  //子の数は？
  if(x->left == NULL || x->right == NULL) y=x;
  else y=Successor(x);
  //消すやつの子は？
  if(y->left != NULL) z=y->left;
  else z=y->right;
  //その子が空でないならその子の親は消すやつの親
  if(z != NULL) z->p = y->p;
  //親がいないならそれは頂点
  //自分が左の子なら親の左の子は自分の子
  //自分が右の子なら親の右の子は自分の子
  if(y->p == NULL) t=z;
  else if(y == y->p->left) y->p->left = z;
  else y->p->right = z;
  //子を２つもってる場合
  if(x != y) x->key=y->key;


  free(y);
}

tree *Successor(tree *x){
  tree *y;
  if(x->right != NULL){
    x=x->right;
    while(x->left != NULL) x=x->left;
    return x;
  }
  else{
    y=x->p;
    while(y != NULL && y->right == x){
      x=y;
      y=y->p;
    }
    return y;
  }
}

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

struct Edge {
  int to, weight;
  Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int dp[100010];

int main() {
  int N,i,u,v,w;
  cin >> N;
  Graph G(N);
  queue<int> q;
  
  for(i=0; i<N-1; i++) {
    cin >> u >> v >> w;
    G[u-1].push_back(Edge(v-1, w));
    G[v-1].push_back(Edge(u-1, w));
  }
  dp[0] = 0;
  q.push(0);

  while(!q.empty()) {
    int v = q.front();
    q.pop();

    for(auto nv : G[v]) {
      if(nv.to==0 || dp[nv.to]!=0)
        continue;
      dp[nv.to] = dp[v]+nv.weight;
      q.push(nv.to);
    }
  }

  for(i=0; i<N; i++) {
    if(dp[i]%2 == 0)
      cout << 1;
    else
      cout << 0;
    cout << endl;
  }
}

Measured memory_bytes: 6784
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
ll n,m,k,ar[N],br[N];
string s,s1;
//Variables End

int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
		cin>>n>>m;

		n=(n*(n-1))/2;
		m=(m*(m-1))/2;
		cout<<n+m<<endl;        
    }
    return 0;
        
}

Measured memory_bytes: 256
fun main (args:Array<String>){
    var(cokkieT, cokkieA, loopT) = readLine()!!.split(" ").map(String::toLong)
    if(cokkieT + cokkieA <= loopT){
        print("0 0")
        return
    }
    if(cokkieT >= loopT){
        cokkieT -= loopT
        print("$cokkieT $cokkieA")
        return
    }
    cokkieA -= loopT - cokkieT
    print("0 $cokkieA")
}


Measured memory_bytes: 36376
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[10];
	for (int i = 0; i < 10; i++){
		cin >> a[i];
	}
	sort(a,a + 10);
	cout << a[9] << endl;
	cout << a[8] << endl;
	cout << a[7] << endl;
	return 0;
}

Measured memory_bytes: 1176
open Batteries
open Tuple
module EnumL = Enum.Labels
module ListL = List.Labels

let dbg x = Printf.eprintf "[debug]%s\n" @@ dump x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = List.range n `To (pred m)

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then Enum.empty ()
  else
    List.map (fun _ -> scan fmt f) (List.range 1 `To n)
    |> List.enum

let scan_list cnv =
  String.split_on_char ' ' @@ read_line ()
  |> List.map cnv

let scan_array cnv = Array.of_list @@ scan_list cnv

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (List.range 0 `To (pred n))
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  List.enum % ListL.map ~f:List.enum @@ aux @@ List.of_enum l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let n = scan "%d" id
let routes = Array.of_enum @@ scan_lines n "%f %f" Tuple2.make

let () =
  let perms = permutations (0 --^ n) in
  EnumL.map (Enum.clone perms) ~f:(fun perm ->
      let r = EnumL.map (Enum.clone perm) ~f:(Array.get routes) in
      junk perm;
      EnumL.map (Enum.combine (r, EnumL.map perm ~f:(Array.get routes)))
        ~f:(fun ((x0, y0), (x1, y1)) ->
            Float.sqrt ((Float.pow (x0 -. x1) 2.0) +.  (Float.pow (y0 -. y1) 2.0)))
      |> Enum.fsum
    )
  |> Enum.fsum
  |> (fun f -> f /. (Float.of_int @@ Enum.count perms))
  |> Printf.printf "%f\n"


Measured memory_bytes: 21248
# CODE FESTIVAL 2016 Final
# B - Exactly N points
# https://atcoder.jp/contests/cf16-final/tasks/codefestival_2016_final_b
N = int(input())
for i in range(1, N+1):
    if i*(i+1)//2 >= N:
        k = i
        break


S = k*(k+1)//2
sub = S-N
for i in range(1, k+1):
    if i == sub:
        continue
    print(i)
1


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int sx, sy, tx, ty;
	
	cin >> sx >> sy >> tx >> ty;
	
	rep(i, tx - sx)
		cout << "R";
		
	rep(i, ty - sy)
		cout << "U";
	
	rep(i, tx - sx)
		cout << "L";
		
	rep(i, ty - sy)
		cout << "D";
		
	cout << "D";
	
	rep(i, tx - sx + 1)
		cout << "R";
		
	rep(i, ty - sy + 1)
		cout << "U";
		
	cout << "LU";
	
	rep(i, tx - sx + 1)
		cout << "L";
		
	rep(i, ty - sy + 1)
		cout << "D";
		
	cout << "R";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define dmin(x, y) ((x) < (y) ? (x) : (y))
#define dmax(x, y) ((x) > (y) ? (x) : (y))
#define checkmax(x, y) ((x) < (y) ? ((x) = (y)) : (x))
#define checkmin(x, y) ((x) > (y) ? ((x) = (y)) : (x))
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
  int aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
ll rdll() {
  ll aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
int x, y, z;
inline void work() {
  x = rdint(), y = rdint(), z = rdint(), swap(x, y), swap(x, z);
  printf("%d %d %d\n", x, y, z);
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

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

  for( int i = a ; i <= b ; i++ ){
    if( i % k == 0 ){
      printf("OK\n");
      break;
    }else if( i >= b ){
      printf("NG\n");
    }
  }

}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n;cin>>n;

  ll ans=0;
  rep(i,1,n+1){
    if(i%3==0&&i%5==0)continue;
    if(i%3==0)continue;
    if(i%5==0)continue;
    ans+=i;
  }


  out(ans);


  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>


int main(void) {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	int ans = fmin(b, d) - fmax(a, c);
	printf("%d", ans >= 0 ? ans : 0);

	return 0;
}

Measured memory_bytes: 128
// not solved by myself
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int As[] = new int[N];

        for(int i = 0;i < N;i++){
            As[i] = sc.nextInt();
        }

        HashMap<Integer,Integer> maps = new HashMap<>();
        for(int a : As) {
            if (maps.keySet().contains(a)) {
                int nums = maps.get(a);
                maps.put(a, nums + 1);
            } else {
                maps.put(a, 1);
            }
        }

        int cuts = 0;
        for(int a: maps.keySet()){
            int nums = maps.get(a);
            if(nums < a)
                cuts += nums;
            else
                cuts += (nums - a);
        }

        System.out.println(cuts);

    }

     public static long max(int[] ar,int size){
        long max = 0;
        for(int i = 0; i< size;i++)
            if(max < ar[i])
                max = ar[i];
        return max;
    }


    public static long max(List<Long> ar){
        long max = 0;
        for(int i = 0; i< ar.size();i++)
            if(max < ar.get(i))
                max = ar.get(i);
        return max;
    }

    public static Integer min(List<Integer> ar){
        int min = 10000;
        int index = 0;
        for(int i = 0; i< ar.size();i++){
            if(min > ar.get(i)){
                min = ar.get(i);
                index = i;
            }
        }
        return min;
    }


    public static long gcd(long m, long n) {
        if(m == 0)
            return n;
        if(n == 0)
            return m;
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}





Measured memory_bytes: 55212
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N, M = map(int, input().split())
    graph = defaultdict(list)

    for _ in range(M):
        A, B = map(int, input().split())
        graph[A].append(B)
        graph[B].append(A)

    route = deque()
    used = set()
    route.appendleft(1)
    used.add(1)
    for n in graph[1]:
        route.append(n)
        used.add(n)
        break

    while True:
        start, end = route[0], route[-1]
        start_ok = True
        for n in graph[start]:
            if n not in used:
                start_ok = False
                route.appendleft(n)
                used.add(n)
                break

        end_ok = True
        for n in graph[end]:
            if n not in used:
                end_ok = False
                route.append(n)
                used.add(n)
                break

        if start_ok and end_ok:
            break

    print(len(route))
    print(*route, sep=" ")


if __name__ == '__main__':
    main()


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

int main(){
  int n; cin >>n; long long s=0,t=0;
  vector<string>a(n);
  for(int i=0; i<n; i++)
  {cin >>a[i]; sort(a[i].begin(),a[i].end());}
  sort(a.begin(),a.end());
  for(int i=0; i<n-1; i++)
  {
    if(a[i]==a[i+1]){t++; s+=t;}
    else t=0;
  }
  cout <<s;
return 0;}

Measured memory_bytes: 7296
#include<stdio.h>
#include<string.h>
int main(){
  
 int k,m,l;
 char s[101],c[101];
  
  scanf("%d",&k);
  scanf("%s",s);
  
  m=strlen(s);

  if (m <= k)
  {
    printf("%s",s);
  } else {
  strncpy(c,s,k);
  c[k]='.';
    c[k+1]='.';
      c[k+2]='.';
        c[k+3]='\0';
    
    
  printf("%s",c);
  
  }
  return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, m, x;
  std::cin >> n >> m >> x;
  std::vector<int64_t> c(n);
  std::vector<std::vector<int64_t>> a(n, std::vector<int64_t>(m));

  for (int64_t i = 0; i < n; i++) {
    std::cin >> c[i];
    std::cin >> a[i];
  }

  int64_t ans = -1;

  for (int64_t i = 1; i < (1 << n); i++) {
    std::vector<int64_t> und(m, 0);
    int64_t price = 0;
    for (int64_t j = 0; j < n; j++) {
      if (((1 << j) & i) != 0) {
        price += c[j];
        for (int64_t k = 0; k < m; k++) {
          und[k] += a[j][k];
        }
      }
    }

    bool flag = true;
    for (const auto u : und) {
      if (u < x) {
        flag = false;
      }
    }

    if (flag) {
      if (ans != -1) {
        ans = std::min(ans, price);
      } else {
        ans = price;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3604
n = int(input())
sum = float('inf')

for i in range(1, n):
    k = 0
    for j in range(len(str(i))):
        k += float(str(i)[j])
    for l in range(len(str(n-i))):
        k += float(str(n-i)[l])
    sum = min(sum, k)

print(int(sum))

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

using namespace std;

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

    vector <int> arr(n+1, 0);
    for(int i = 1; i <= n; i++)
        cin >> arr[i];

    vector <int> dp(n + 1);
    dp[2] = abs(arr[2] - arr[1]);
    for(int i = 3; i <= n; i++)
        dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
                              dp[i - 2] + abs(arr[i] - arr[i - 2]));

    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
//dfs树的灵活运用
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 2010
#define inf 2147483647
using namespace std;

struct edge{int x, y, next;}a[4010010];
int n, w[N], l, p[N], flag[N], fa[N], S, mnp, b[N], du[N], ans[N];
vector<int>son[N], son1[N];

inline int gcd(int a, int b){return b?gcd(b, a%b):a;}
inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}

inline void dfs(int x){
	flag[x]=1; son1[x].clear();
	for(int i=p[x]; i; i=a[i].next)if(!flag[a[i].y])son1[x].push_back(a[i].y);
	int mnp; w[0]=inf;
	while(1){
		mnp=0;
		for(int i=0; i<son1[x].size(); i++)if(!flag[son1[x][i]]&&w[mnp]>w[son1[x][i]])mnp=son1[x][i];
		if(!mnp)break;
		fa[mnp]=x; dfs(mnp);
	}
}

inline void solve(){
	l=0; memset(p, 0, sizeof(p)); memset(du, 0, sizeof(du));
	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++)if(gcd(b[i], b[j])!=1){add(i, j); du[j]++;}
	memset(flag, 0, sizeof(flag));
	for(int i=1; i<=n; i++)if(!du[i])flag[i]=1;
	int mnp; b[0]=-inf;
	for(int i=1; i<=n; i++){
		mnp=0;
		for(int j=1; j<=n; j++)if(flag[j]&&b[mnp]<b[j])mnp=j;
		ans[i]=b[mnp]; flag[mnp]=0;
		for(int j=p[mnp]; j; j=a[j].next){du[a[j].y]--; if(!du[a[j].y])flag[a[j].y]=1;}
	}
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)scanf("%d", &w[i]);
	S=n+1; w[n+1]=0;
	l=0; memset(p, 0, sizeof(p));
	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++)if(gcd(w[i], w[j])!=1){add(i, j); add(j, i);}
	for(int i=1; i<=n; i++){add(S, i); add(i, S);}
	memset(flag, 0, sizeof(flag));
	fa[S]=0; dfs(S);
	for(int i=1; i<=S; i++)son[i].clear();
	for(int i=1; i<=n; i++)son[fa[i]].push_back(i);
	memset(flag, 0, sizeof(flag)); flag[S]=1; l=-1;
	for(int i=1; i<=S; i++){
		mnp=0; w[0]=inf;
		for(int j=1; j<=S; j++)if(flag[j]&&w[mnp]>w[j])mnp=j;
		b[++l]=w[mnp]; flag[mnp]=0;
		for(int j=0; j<son[mnp].size(); j++)flag[son[mnp][j]]=1;
	}
	solve();
	for(int i=1; i<=n-1; i++)printf("%d ", ans[i]); printf("%d", ans[n]);
	return 0;
}

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

int main() {
	int time;
	int sec,min, hour;
	std::cin >> time;
	sec=time % 60;
	min = (time/60)%60;
	hour= (time/3600);
	std::cout << hour<<":"<< min<<":"<<sec <<std::endl;
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll x,y;
    cin >> x >> y;
    cout << (abs(x - y) <= 1 ? "Brown" : "Alice") << endl;

}

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int,input().split())))
M = max(A)
 
t = 7+10**9
m = M/2
p = 0
for k in range(N):
    if abs(m-A[k]) < t:
        t = abs(m-A[k])
        p = k
print(M,A[p])

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

int main(){
	int N;
	scanf("%d\n", &N);
	int ruiseki[N + 1];
	ruiseki[0] = 0;
	for (int i = 1; i <= N; ++i){
		char tmp;
		scanf("%c", &tmp);
		ruiseki[i] = tmp == 'E' ? ruiseki[i - 1] + 1 : ruiseki[i - 1];
	}
	int answer = N;
	for (int i = 1; i <= N; ++i){
		int turn = i - 1 - ruiseki[i - 1] + ruiseki[N] - ruiseki[i];
		if(turn < answer) answer = turn;
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cmath>
#include <cassert>
using namespace std;

bool is_powernum[1001];

void init() {
    for (int i = 0; i <= 1000; i++) is_powernum[i] = false;
    is_powernum[1] = true;
    for (int b = 2; b <= 1000; b++) {
        for (int n = b * b; n <= 1000; n *= b) {
            is_powernum[n] = true;
        }
    }
}

int main() {
    init();
    int x; scanf("%d", &x);
    
    assert(x >= 1);
    for (int i = x; i >= 1; --i) {
        if (is_powernum[i]) {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int adj[101][101],d[101],f[101],visited[101],n,time;

void DFS(int s){
	if(visited[s])return;

	int i;
	++time;
	d[s]=time;	visited[s]=1;

	for(i=1;i<=n;i++){
		if(adj[s][i]==1)DFS(i);
	}

	++time;
	f[s]=time;
}

int main(){
	int i,j,u,k,v;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d",&v);
			adj[u][v]=1;
		}
	}

	for(i=1;i<=n;i++)DFS(i);

	for(i=1;i<=n;i++){
		printf("%d %d %d\n",i,d[i],f[i]);
	}

	return 0;
}



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

int main() {
    vector<vector<int>>bingo(3,vector<int>(3));
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            cin >> bingo.at(i).at(j);
        }
    }    
    int N;
    cin >> N;   
    vector<int>B(N);
        for (int i=0; i<N; i++){
            cin >> B.at(i);
        }
    for (int i=0; i<N; i++){
        for (int &X : bingo.at(0)){
            if(X == B.at(i)){
                X = 0;
            }
        }
    
        for (int &X : bingo.at(1)){
            if(X == B.at(i)){
                X = 0;
            }
        }
        for (int &X : bingo.at(2)){
            if(X == B.at(i)){
                X = 0;
            }
        }
    }
    int ans=0;
    for (int i=0; i<3; i++){
        if(bingo.at(i).at(0) == 0 && bingo.at(i).at(1) == 0 && bingo.at(i).at(2) == 0){
            ans ++;
        }
        if(bingo.at(0).at(i) == 0 && bingo.at(1).at(i) == 0 && bingo.at(2).at(i) == 0){
            ans ++;
        }
    }    
    if(bingo.at(0).at(0) == 0 && bingo.at(1).at(1) == 0 && bingo.at(2).at(2) == 0){
        ans ++;
    }
     if(bingo.at(0).at(2) == 0 && bingo.at(1).at(1) == 0 && bingo.at(2).at(0) == 0){
        ans ++;
    }
    if (ans > 0){
        cout << "Yes" << endl;
    }
    if (ans == 0){
        cout << "No" << endl;
    }

}
    



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> mp;
    char cnt = 'A';
    for (int i = 0; i < 26; i++)
    {
        mp[i] = cnt;
        cnt++;
    }
    map<int, char> pm;
    int tnc = 0;
    for (char i = 'A'; i <= 'Z'; i++)
    {
        pm[i] = tnc;
        tnc++;
    }
    for (auto &x : s)
    {
        int j = pm[x];
        j = (j + n) % 26;
        x = mp[j];
        cout << x;
    }
    cout << endl;
}

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

int main() {
  long long N,A,B;
  cin >> N >> A >> B;
  long long p = N / (A + B);
  long long q = N % (A + B);
  if (q < A) {
    	cout << p * A + q << endl;
  	}
  else {
    	cout << (p + 1) * A << endl;
  } 
}


Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))

A_sum_list = [A_list[N-1]]
ans = A_list[N-1]*A_list[N-2]
sum_temp_old = A_list[N-1]

for i in range(N-1, 1, -1):
    sum_temp = sum_temp_old + A_list[i-1]
    sum_temp_old = sum_temp
    ans += (sum_temp * A_list[i-2])

#print(A_sum_list)
print(ans%(10**9 + 7))


Measured memory_bytes: 31440
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;cin >> s;
  int N = s.size();
  string ans = "No";
  for (int i = 0; i < N; i++) {
    if (s.at(i) == 'C') {
      for (int j = i + 1; j < N; j++) {
        if (s.at(j) == 'F') {
          ans = "Yes";
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  if (N % 500 == 0 || N % 500 <= A) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN


int main(void){
	ll A,B,C,K,ans;
	scanf("%lld%lld%lld%lld",&A,&B,&C,&K);
	if(A>B){
		if(A>C){
			rep(i,K)A*=2;
		}else{
			rep(i,K)C*=2;
		}
	}else{
		if(B>C){
			rep(i,K)B*=2;
		}else{
			rep(i,K)C*=2;
		}
	}
	ans=A+B+C;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int countA=0;
  for(int i=0; i<S.size() ; ){
    if(S.at(i)=='1'){
      countA=countA+1;
    }
    else{
    }
    
    if( i+1 >=  S.size()){
      break;
    }
    else{
      
    if(S.at(i+1)=='0'){
      countA=countA+1;
    }
    else{
    }
    i=i+2;
    }
  }
  int countB;
  countB=S.size()-countA;
  cout << min(countA,countB) << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int x,y,i,tmp;
	while(1){
		scanf("%d %d",&x,&y);
		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}

		if(x==0&&y==0)break;
		printf("%d %d\n",x,y);
	}
	
	return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int[] m = new int[n];
    int min = 100000;
    int total = 0;
    for(int i = 0;i<n;i++){
      m[i] = sc.nextInt();
      min = Math.min(m[i],min);
      total += m[i];
    }
    x -= total;
    int count = n + x/min;
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	
	ll N, H;
	cin >> N >> H;
	vll a(N), b(N);
	rep(i, N) cin >> a[i] >> b[i];

	sort(all(a)), sort(all(b));
	ll p = a.back();
	vll qs;
	ll q_sum = 0;
	for (auto it = upper_bound(all(b), p); it != b.end(); ++it) {
		qs.push_back(*it);
		q_sum += *it;
	}

	ll ans = 0;
	if (q_sum <= H) {
		ll tmp = H - q_sum;
		ans += (ll)ceil((double)tmp / p);
		H = H - ans * p;
	}
	ford(i, 0, qs.size()) {
		H -= qs[i];
		++ans;
		if (H <= 0) break;
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,i,j;
    vector<long long int>vec;
    map<long long int,long long int>mp;
    map<long long int,long long int>::iterator it;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        vec.push_back(a);
        mp[vec[i]]++;
    }
    a=0;
    for(it=mp.begin();it!=mp.end();it++)
    {
       a+=(it->second*(it->second-1))/2;
    }
    for(i=0;i<n;i++)
    {
        cout<<a-(mp[vec[i]]-1)<<endl;
    }

    return 0;
}


Measured memory_bytes: 11120
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=200005;

int n;
int a[N];
vector<int> v;
bool inc()
{
	for(int i=2;i<=n;i++)
		if(a[i-1]>=a[i]) return 0;
	return 1;
}
inline bool ok(int x)
{
	int p[10005];
	memset(p,0,sizeof(p));
	for(int i=1;i<=v[0];i++)
		p[i]=1;
	for(int i=1;i<v.size();i++)
	{
		if(v[i]>v[i-1])
		{
			for(int j=v[i-1]+1;j<=v[i];j++)
				p[j]=1;
			continue;
		}
		for(int j=v[i]+1;j<=v[i-1];j++)
			p[j]=0;
		int u=-1;
		for(int j=v[i];j>=1;j--)
			if(p[j]!=x)
			{
				u=j;
				break;
			}
		if(u==-1) return 0;
		p[u]++;
		for(int j=u+1;j<=v[i];j++)
			p[j]=1;
	}
	return 1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	if(inc()) return cout<<"1\n",0;
	for(int i=1;i<=n;i++)
		if(a[i]<=10000) v.pb(a[i]);
	n=v.size();
	
	int l=1,r=n;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(ok(mid)) r=mid-1;
		else l=mid+1;
	}
	cout<<l<<'\n';
	
	return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int sx,sy,tx,ty;
int main(void){
    cin>>sx>>sy>>tx>>ty;
    for(int i=0;i<(tx-sx);i++){
        cout<<'R';
    }
    for(int i=0;i<(ty-sy);i++){
        cout<<'U';
    }
    for(int i=0;i<(tx-sx);i++){
        cout<<'L';
    }
    for(int i=0;i<(ty-sy);i++){
        cout<<'D';
    }
    cout<<'D';
    for(int i=0;i<(tx-sx+1);i++){
        cout<<'R';
    }
    for(int i=0;i<(ty-sy+1);i++){
        cout<<'U';
    }
    cout<<'L';
    cout<<'U';
    for(int i=0;i<(tx-sx+1);i++){
        cout<<'L';
    }
    for(int i=0;i<(ty-sy+1);i++){
        cout<<'D';
    }
    cout<<'R'<<endl;

}



Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

int main(){
	int t;
	while(~scanf("%d",&t)){
		for(int i=0;i<t;i++){
			int n,k;
			scanf("%d %d",&n,&k);

			int homes[100000];
			for(int j=0;j<n;j++){
				scanf("%d",&homes[j]);
			}

			vector<int> diff;
			for(int j=0;j+1<n;j++){
				diff.push_back(homes[j+1]-homes[j]);
			}
			
			sort(diff.begin(),diff.end(),greater<int>());

			int len = homes[n-1]-homes[0];

			for(int j=0;j<k-1 && j < diff.size();j++){
				len -= diff[j];
			}

			printf("%d\n",len);
		}
	}
}

Measured memory_bytes: 2448
#include<iostream>
#include<vector>
using namespace std;
 
class ModInt{
private:
  long long val;
  static const int default_mod = 1e9 + 7;
  static int mod;
  static vector<ModInt> facts;
public:
  ModInt(long long val)
  {
    if(mod == 0){
      mod = default_mod;
    }
    this->val = ((val % mod) + mod) % mod;
  }
  ModInt()
    : ModInt(0)
  {
  }
  static void setMod(int mod){
    if(ModInt::mod != 0){
      throw "The modulo is already set.";
    }
    ModInt::mod = mod;
  }

  const ModInt operator* (const ModInt& another) const{
    return ModInt(val * another.val);
  }
  ModInt operator+ (const ModInt& another){
    return ModInt(val + another.val);
  }
  ModInt operator- (const ModInt & another){
    return ModInt(val - another.val + mod);
  }
  ModInt operator/(const ModInt& rhs){
    return (*this) * rhs.inv();
  }
  ModInt& operator*=(const ModInt& rhs){
    (*this) = (*this) * rhs;
    return *this;
  }
  ModInt& operator+=(const ModInt& rhs){
    (*this) = (*this) + rhs;
    return *this;
  }
  ModInt& operator-=(const ModInt& rhs){
    (*this) = (*this) - rhs;
    return *this;
  }
  ModInt& operator/=(const ModInt& rhs){
    (*this) = (*this) / rhs;
    return *this;
  }
  ModInt pow(long long exponent) const{
    exponent %= mod;
    if(exponent == 0){
      return ModInt(1);
    }else{
      if(exponent % 2){
        return ((*this) * (*this)).pow(exponent / 2) * (*this);
      }else{
        return ((*this) * (*this)).pow(exponent / 2);
      }
    }
  }
  ModInt inv() const{
    return this->pow(mod - 2);
  }
  static ModInt fact(long long n){
    if(n >= mod){
      return 0;
    }
    if(facts.size() < static_cast<size_t>(n + 1)){
      if(facts.size() == 0){
        facts.push_back(1);
      }
      for(int i = facts.size(); i <= n; i++){
        facts.push_back(facts[i - 1] * i);
      }
    }
    return facts[n];
  }
  static ModInt comb(long long n, long long r){
    if(r > n){
      return 0;
    }
    return ModInt::fact(n) * ModInt::fact(r).inv() * ModInt::fact(n - r).inv();
  }
 
  friend ostream& operator<< (ostream& os, const ModInt& modint){
    os << modint.val;
    return os;
  }
  friend istream& operator>>(istream& is, ModInt& modint){
    long long val;
    is >> val;
    modint.val = val % modint.mod;
    return is;
  }
  friend ModInt operator*(const long long lhs, const ModInt& rhs){
    return ModInt(lhs) * rhs;
  }
};
int ModInt::mod = 0;
vector<ModInt> ModInt::facts;


int main(){
  long long n, k;
  cin >> n >> k;

  ModInt ans = 0;
  if(k >= n){
    ans = ModInt::comb(2 * n - 1, n - 1);
  }else{ // k < n
    vector<ModInt> facts(n + 1), facts_inv(n + 1);
    facts[0] = 1;
    for(int i = 1; i <= n; i++){
      facts[i] = facts[i - 1] * i;
    }
    facts_inv[n] = facts[n].inv(); // 1 / (n!)
    for(int i = n - 1; i >= 0; i--){
      facts_inv[i] = (i + 1) * facts_inv[i + 1];
    }
    facts_inv[0] = 1;
    //cout << facts_inv[1] << endl;

    for(int p = 0; p <= k; p++){
      ans += (facts[n] * facts_inv[p] * facts_inv[n - p]) * (facts[n - 1] * facts_inv[p] * facts_inv[n - 1 - p]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if (-self.parents[x]) < (-self.parents[y]):
            self.parents[y] += self.parents[x]
            self.parents[x] = y
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x

    def size(self, x):
        return -self.parents[self.root(x)]

    def same(self, x, y):
        return self.root(x) == self.root(y)

N, M, K = map(int,input().split())

uf = UnionFind(N)
friends = [0] * N
blocks = [0] * N

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)
    friends[a] += 1
    friends[b] += 1

for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c, d):
        blocks[c] += 1
        blocks[d] += 1

for i in range(N):
    print(uf.size(i) - friends[i] - blocks[i] - 1, end=" ")
print("")

Measured memory_bytes: 97368
// Aizu 1131: Unit Fraction Partition
// 2017.10.24 bal4u@uu

#include <stdio.h>
#include <math.h>

#define EPS 1e-9
double tbl[12005];
int ans, a;

int bsch(double v)
{
	int m, l = 0, r = 12001;

	while (l < r) {
		m = (l + r) >> 1;
//		if (fabs(tbl[m] - v) <= EPS) return m;
		if (tbl[m] > EPS + v) l = m + 1; else r = m;
	}
	if (l <= 0) l = 1;
	return l;
}

void rec(double v, int k, int n, int aa)
{
	int i, l, r;

	if (aa > a) return;
	if (fabs(v) <= EPS) { ans++; return; }
	if (n == 0) return;

	l = bsch(v), r = bsch(v/n);
	if (l < k) l = k;
//	if ((double)n/l + EPS < v) return;
	k = a / aa;
	if (k < r) r = k;
	for (i = l; i <= r; i++) rec(v - 1.0 / i, i, n - 1, aa*i);
}

int main()
{
	int p, q, n, i, l, r;
	double v;

	for (i = 1; i <= 12002; i++) tbl[i] = 1.0 / i;
	while (scanf("%d%d%d%d", &p, &q, &a, &n) && n > 0) {
		v = (double)p / q;
		if (fabs(v-n) <= EPS) { puts("1"); continue; }
		if (v > n) { puts("0"); continue; }
		l = bsch(v), r = bsch(v/n);
		for (ans = 0, i = l; i <= r; i++) rec(v-1.0/i, i, n-1, i);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1828
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, K, NOW = 1, ANS = 0;
	cin >> N >> K;
	while (N >= NOW) {
		NOW += (NOW + K - 1) / K;
		ANS++;
	}
	cout << ANS << endl;
}


Measured memory_bytes: 3084