akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5;  
const double pie = 3.14159265358979323846 ;
// limit for array size 
double dist(double Ax,double X,double Ay, double Y){
  double best = (Ax-Ay)*(Ax-Ay) + (X-Y)*(X-Y) ;
  best = sqrt(best) ;
  return best ;
}
int tests(){ 
  // vector <vector <int>> M(3,vector <int> (3,271)) ;
  string S ;
  cin >> S ;
  int Q ; cin >> Q ; 
  int t ; 
  int c= 0 ;  
  string T;
  int Sze = 2e5;
  int i;
  forn(i,0,Sze)
    T.push_back('.') ;
  forn(i,Sze,Sze+S.size())
    T.push_back(S[i-Sze]) ;
  while(i< 2*Sze)
    T.pb('.'),i++ ; 
       // 
  int L = Sze,R = Sze+S.size()-1;   
  int ok  = 1 ; 
  while(Q--){
    cin >> t ; 
    if(t == 1) 
      c++,ok = 1-ok; 
    else{
      cin >> t ;
      char a ; cin >> a ;  
      if(t == 2){  
        if(ok)
          T[++R] = a ;
        else 
          T[--L] = a ;      
      } 
      else {  
        if(ok)
          T[--L] = a ;
        else 
          T[++R] = a ;  
      }
    }
  }
  if(c&1)
    reverse(all(T)) ;

  forn(i,0,2*Sze)
    if(T[i] != '.')
      cout << T[i] ; 
  return 0 ;
}
int main(){
    I__O ;  
    int cases = 1 ;
    // cin >> cases ; 
    while(cases--)
      tests(); 
    return 0 ; 
}

Measured memory_bytes: 1236
use std::cmp::Reverse;
use std::cmp::max;
use std::collections::VecDeque;
use std::cmp::min;
use std::collections::BTreeSet;
use std::cmp::Ordering;
use std::fmt::Debug;

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_lines<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.trim().parse().ok().expect("Can't Parse"));
        buffer.clear();
    }
    vec
}
fn read_tabulate<R, T: Fn(&str)->R> (count: usize, transformer: T) -> Vec<R> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(transformer(buffer.trim()));
        buffer.clear();
    }
    vec
}
fn read_value<T: std::str::FromStr>() -> T {
    read_line().trim().parse().ok().unwrap()
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
macro_rules! freeze {
    ($($id:ident), *) => {
        $(let $id = $id;)*
    };
}
macro_rules! read {
    (mut $ident: ident: [$ty:ty]) => {
        let mut $ident = read_values::<$ty>();
    };
    ($ident: ident: [$ty:ty]) => {
        let $ident = read_values::<$ty>();
    };
    ($($token: tt)*) => {
        let mut iter = read_values::<String>().into_iter();
        read_from_iter!(iter; $($token)*);
    };
}
macro_rules! read_from_iter {
    ($iter:expr; mut $ident:ident:$ty:ty, $($rest:tt)*) => {
        let mut $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
        read_from_iter!($iter; $($rest)*);
    };
    ($iter:expr; $ident:ident:$ty:ty, $($rest:tt)*) => {
        let $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
        read_from_iter!($iter; $($rest)*);
    };
    ($iter:expr; mut $ident:ident:$ty:ty) => {
        let mut $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
    };
    ($iter:expr; $ident:ident:$ty:ty) => {
        let $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
    };
    ($iter: expr; ) => {};
}
struct KeyValue<K, V> {
    key: K,
    value: V
}
impl <K: PartialOrd, V> PartialEq for KeyValue<K, V> {
    fn eq(&self, other: &Self) -> bool {
        self.key.eq(&other.key)
    }
}
impl <K: PartialOrd, V> Eq for KeyValue<K, V> {}
impl <K: PartialOrd, V> PartialOrd for KeyValue<K, V> {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.key.partial_cmp(&other.key)
    }
}
impl <K: PartialOrd, V> Ord for KeyValue<K, V> {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.key.partial_cmp(&other.key).ok_or("Can't Compare").unwrap()
    }
}

fn main() {
    read!(x: i64, y: i64);
    println!("{}", if (x - y).abs() <= 1 {"Brown"} else {"Alice"});
}

Measured memory_bytes: 2136
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(int i=k;i<n;++i)
using namespace std;
int N,A,B,P,c[3]={0};
int main(void){
    // Your code here!
    cin>>N;
    cin>>A>>B;
    rep(0,i,N){
        cin>>P;
        if(A>=P){
            ++c[0];
        }else if(A<P &&P<=B){
            ++c[1];
        }else{
            ++c[2];
        }
    }
    cout<<min(c[0],min(c[1],c[2]));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
  
int main(){
    ll k, a, b; cin >> k >> a >> b;
    if(a + 2 >= b){
        cout << 1 + k << endl;
        return 0;
    }
    ll ans = a + (k - (a - 1)) / 2 * (b - a);
    if((k - (a - 1)) % 2)cout << ans + 1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    d = ii()
    s = 'Christmas'
    for _ in range(25 - d):
      s += ' Eve'
    print(s)


if __name__ == "__main__":
    main()


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

int main(){
    int n,a,b,c,d;
    int space = 0,stone = 0,max_sp = 0,max_st = 0;
    string s;

    cin >> n >> a >> b >> c >> d >> s;

    for(int i = b - 2;i <= d;i++){
       if(s[i] == '.')space++;
       else {
           max_sp = max(max_sp,space);
           space = 0;
       }
    }
    max_sp = max(max_sp,space);

     for(int i = a - 1;i < max(c,d);i++){
       if(s[i] == '#')stone++;
       else {
           max_st = max(max_st,stone);
           stone = 0;
       }
    }
    max_st = max(max_st,stone);

    if(d < c && max_sp <= 2 ||max_st >= 2)cout << "No" << endl;
    else cout << "Yes" << endl;

}


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

int n, a[60], b[60], vis[60], cnt, used[60];
long long ans;

void Dfs(int x, int up) {
  if(vis[x]) return;
  vis[x] = 1;
  for(int i = 1; i < up; i++)
    Dfs(x % i, up);
  for(int i = 1; i <= cnt; i++)
    Dfs(x % used[i], up);
}

bool HavetoAdd(int x) {
  for(int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    Dfs(a[i], x);
    if(!vis[b[i]]) return 0;
  }
  return 1;
}

int main(void) {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) 
    scanf("%d", &a[i]);
  for(int i = 1; i <= n; i++) 
    scanf("%d", &b[i]);
  for(int i = 50; i >= 1; i--) {
    if(HavetoAdd(i)) continue;
    //cerr << i << endl;
    used[++cnt] = i;
    ans += 1LL << i;
    if(!HavetoAdd(i)) return puts("-1"), 0;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	double m,s,r;
	
	
	scanf("%lf",&r);
	((0<r)&&(r<100));
	m = 2 * 3.1415926535897932384626433832795028841971 * r ;
	
	s = r * r * 3.1415926535897932384626433832795028841971 ;
	printf("%f %f\n",s,m);
	
	return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (i > 0)
    {
      if (S[i - 1] == S[i])
      {
        ans++;
      }
    }
  }
  ans += 2 * K;
  ans = min(ans, N - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	int N = a;
	vector<int>s(a);
	for (int i = 0; i < a; i++) {
		cin >> s[i];
	}
	if (a == b)cout << 1 << endl;
	else {
		if ((a - b) % (b - 1) == 0)cout << 1 + (a - b) / (b - 1) << endl;
		else cout << 2 + (a - b) / (b - 1) << endl;
	}
	return 0;
}


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

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

int main() {
	int n;
	cin>>n;
	vector<int> d(n);
	rep(i,n) cin>>d[i];
	set<int> s;
	rep(i,n) s.insert(d[i]);
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[M];
    for (int i = 0; i < M; i++) A[i] = sc.nextInt();
    sc.close();

    long sum = 0;
    for (int i = 0; i < M; i++) sum += A[i];

    long ans = -1;
    if (sum <= N) ans = N - sum;
    System.out.println(ans);
  }
}


Measured memory_bytes: 46072
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (A, B, M) = (input[0], input[1], input[2])
let a = readLine()!.characters.split(" ").map{Int(String($0))!}
let b = readLine()!.characters.split(" ").map{Int(String($0))!}
let m = (0..<M).map{_ in readLine()!.characters.split(" ").map{Int(String($0))!}}

var ans = a.minElement()! + b.minElement()!
for i in m {
  ans = min(ans, a[i[0]-1]+b[i[1]-1]-i[2])
}

print(ans)

Measured memory_bytes: 10712
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int X;
    cin >> X;
    vector<int> m = {100, 101,  102,  103,  104,  105};
    map<int, int> m0, m1;
    m0[0] = 0;
    REP(i, 1002){
        if(i&1){
            m0.clear();
            for(auto && i : m1){
                for (int j = 0; j < 6; j++) {
                    if(i.fi + m[j] > X) continue;
                    if(i.fi + m[j] == X){
                        pr(1);
                        return 0;
                    }
                    m0[i.fi + m[j]] = 1;
                }
            }
        }else{
            m1.clear();
            for(auto && i : m0){
                for (int j = 0; j < 6; j++) {
                    if(i.fi + m[j] > X) continue;
                    if(i.fi + m[j] == X){
                        pr(1);
                        return 0;
                    }
                    m1[i.fi + m[j]] = 1;
                }
            }
        }
    }
    pr(0);
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

#define INF 1000000

int main() {
  int N, T, index = 0;
  double A, near_A = INF;
  cin >> N >> T >> A;

  int H[N+1];
  for(int i=0; i<N; ++i)
    cin >> H[i];

  for(int i=0; i<N; ++i) {
    double ondo = T-H[i]*0.006;
    if(abs(ondo-A) < abs(near_A-A)) {
      near_A = ondo;
      index = i;
    }
  }

  cout << index+1 << endl;

  return 0;
}

Measured memory_bytes: 256
N, L = [int(x) for x in input().split()]

aji = []
min_abs = 1000000000000000
min_abs_index = 0
for i in range(1, N + 1):
    if min_abs > abs(L + i - 1):
        min_abs = abs(L + i - 1)
        min_abs_index = i - 1
    aji.append(L + i - 1)

print(sum(aji) - aji[min_abs_index])


Measured memory_bytes: 3060
/*
 * ALDS1_6_B.cpp
 *
 *  Created on: Apr 30, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>

using namespace std;

int partition(int* A, int l, int r) {
	int x = A[r];
	int i = l - 1;
	for(int j=l; j<r; j++) {
		if(A[j] <= x) {
			i++;
			std::swap(A[i], A[j]);
		}
	}
	swap(A[i+1], A[r]);
	return i+1;
}

int main() {
	int n;
	int A[100000];

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

	int c = partition(A, 0, n-1);

	if(c == 0) {
		cout << "[" << A[0] << "]";
	}
	else {
		cout << A[0];
	}
	for(int i=1; i<n; i++) {
		cout << " ";
		if(c == i) {
			cout << "[" << A[i] << "]";
		}
		else {
			cout << A[i];
		}
	}
	cout << endl;
}





Measured memory_bytes: 3404
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;


class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    UF(int n): num(n) {
        par.resize(n);
        siz.resize(n);
        int i;
        for(i=0; i<n; i++) {
            par[i]=i; siz[i]=1;
        }
    }
	
    int find(int x) {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(siz[x]<siz[y]) {
            par[x]=y;
            siz[y]=siz[x]+siz[y];
        }
        else {
            par[y]=x;
            siz[x]=siz[x]+siz[y];
        }
    }

    bool same(int x, int y) {
        return find(x)==find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup() {
        int count=0;
        int i;
        for(i=0; i<num; i++) {
            if(par[i]==i) count++;
        }
        return count;
    }
};


int main(int argc, char* argv[])
{
    int n, m;
    scanf("%d%d", &n, &m);

    UF uf(n);

    int i;
    for(i=0; i<m; i++) {
        int a,b,c;
        scanf("%d%d%d", &a, &b, &c);
        uf.unite( a-1, b-1 );
    }

    int ans = uf.ngroup();
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll t;
ll ret = 0;
ll A = 0, B = 0, C = 0;
string S, T, U;


void input() {
  IN(S);
  IN(T);
  IN(A);
  IN(B);
  IN(U);
}

void solve() {
  if (S == U) {
    cout << A-1 << " " << B << endl;
  } else if (T == U) {
    cout << A << " " << B-1 << endl;
  }
}

int main(void){
  input();
  solve();
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,x,t;
    cin>>n>>x>>t;
    cout << (x+n-1)/x * t << endl;
    return 0;
}

Measured memory_bytes: 3592
from itertools import permutations
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

adjm = [[0]*N for _ in range(N)]
for abi in ab:
    adjm[abi[0]-1][abi[1]-1] = 1
    adjm[abi[1]-1][abi[0]-1] = 1

cnt = 0
order = list(range(1, N))
for v in permutations(order):
    last = 0
    for i in v:
        if adjm[last][i] == 1:
            last = i
        else:
            break
    else:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  deque<char> Q;
  for(int i=0;i<S.size();i++){
    if(!Q.empty() && S.at(i)=='B'){
      Q.push_back(S.at(i));
      Q.pop_back();
      if(!Q.empty())
        Q.pop_back();
      }
    if(S.at(i)!='B')
      Q.push_back(S.at(i));
  }
  for(int j=0;j<Q.size();j++){
    cout << Q.at(j);
   
  }
  cout << endl;
}
        

Measured memory_bytes: 256
import java.util.*;


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

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] r = new int[9];
        for (int i = 0; i < n; ++i) {
            int a = sc.nextInt();
            if (a > 3199) {
                r[8]++;
            } else {
                r[a/400]++;
            }
        }
        
        int c = 0;
        for (int i = 0; i < 8; ++i) {
            if (r[i] > 0) {
                c++;
            }
        }

        System.out.println((c > 0 ? c : 1) + " " + (c + r[8]));
    }
}

Measured memory_bytes: 22612
#include<stdio.h>
int main()
{
	int b=0,n,i,j,p=0,A[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&A[i]);
	for(i=0;i<n;i++)
	{
		if(A[i]>b)
		b=A[i];
	}
	for(i=0;i<n;i++)
	{
		p+=A[i];
	}
	p=p-b/2;
	printf("%d",p);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
typedef long long ll;
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=2e5+10;
unordered_map<int,bool> mp[maxn];
int f[maxn];
struct point{
	int x,y;
}a[maxn];
int main(){
	int h=read(),w=read(),n=read();
	REP(i,1,n) a[i].x=read(),a[i].y=read(),mp[a[i].x][a[i].y]=1;
	REP(i,1,h){
		f[i]=f[i-1];
		if(!mp[i][f[i]+1]) ++f[i];
	}
	int ans=h;
	REP(i,1,n) if(f[a[i].x-1]>=a[i].y) chkmin(ans,a[i].x-1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 33024
n = int(input())
s = [input().split() for i in range(n)]
x = input()
for i, ti in enumerate(s):
  #print(i, ti)
  s[i][1] = int(s[i][1])
#print(n,s,x)
sum_t = 0
ind = 0

# xのindexを探索
for i, music in enumerate(s):
  #print(music)
  #print(x in music)
  if x in music:
    ind = i
    break
#print(ind)

# 経過時間計算
for i, music in enumerate(s):
  if i > ind:
    sum_t += music[1]
print(sum_t)

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

int main(){
    char C;
    cin >> C;

    if((C == 'a') || (C == 'i') || (C == 'u') || (C == 'e') || (C == 'o')){
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
///who is the king ??? *** << t.mohammad >> *** ///
/*
                  00                                                                                                            00
                 00                               00                                                                           00
            0000000000                           00                                                                           00
           0000000000   000       000           00                        000       000  000       000                       00
              00       0000     0000           00         000000         0000     0000  0000     0000   000000              00
             00       00 00   00 00    000    00        00000000        00 00   00 00  00 00   00 00  00000000       00000000
            00       00  00 00  00   00000   000000    00    000       00  00 00  00  00  00 00  00  00    000     0000000000
           00       00   000   00  00   00  00000000  00    0000      00   000   00  00   000   00  00    0000    00     0000
          00       00         00  00   00  00    00  00    00 00     00         00  00         00  00    00 00   00     00 00
         00  00   00         00   00000   00    00  00000000  00    00         00  00         00  00000000  00  000000000  00
        00  00   00         00    000    00    00   000000    00   00         00  00         00   000000    00  0000000    00
*/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std ;
#define int long long int
typedef long double ld ;
#define ff first
#define ss second
#define setp(t) cout << setprecision(t) << fixed ; 
int const N = 1e5 + 100 ;
int a[N] , dp[N] ;
int32_t main() {
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
	int n ;
	cin >> n ;
	for (int i = 0 ; i < n ; i++) {
		cin >> a[i] ;
	}
	dp[1] = abs(a[0] - a[1]) ;
	for (int i = 2 ; i < n ; i++) {
		dp[i] = min(dp[i - 2] + abs(a[i - 2] - a[i]) , dp[i - 1] + abs(a[i - 1] - a[i])) ;
	}
	return cout << dp[n - 1] , 0 ;
}


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

int main() {
  int t1,t2;ll a1,a2,b1,b2,p,q;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  p = (a1-b1)*t1;q = (a2-b2)*t2;
  if(p > 0){p *= -1;q *= -1;}
  if(p+q < 0){cout << 0 << endl;return 0;}
  else if(p+q == 0){cout << "infinity" << endl;return 0;}
  else{
    ll s = -p/(p+q),t = (-p)%(p+q);
    if(t != 0) cout << s*2+1 << endl;
    else cout << s*2 << endl;
  }
}

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

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

    int N;
    cin >> N;

    vector<pair<int, int>> T(N);

    rep(i,N) cin >> T[i].second >> T[i].first;
    sort(T.begin(), T.end());

    ll t = 0;
    bool ans = true;
    rep(i,N) {
        t += T[i].second;
        if (t > T[i].first) {
            ans = false;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


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

struct p
{
	double x;
	double y;
} typedef point;

double sin60;
double cos60;

void koch(int d, point p1, point p2)
{
	point s, u, t;
	
	if(d == 0)
	{
		printf("%.8f %.8f\n", p2.x, p2.y);
		return;
	}
	
	s.x = (2 * p1.x + p2.x) / 3;
	s.y = (2 * p1.y + p2.y) / 3;
	t.x = (p1.x + 2 * p2.x) / 3;
	t.y = (p1.y + 2 * p2.y) / 3;
	u.x = (t.x - s.x) * cos60 - (t.y - s.y) * sin60 + s.x;
	u.y = (t.x - s.x) * sin60 + (t.y - s.y) * cos60 + s.y;
	
	koch(d - 1, p1, s);
	koch(d - 1, s, u);
	koch(d - 1, u, t);
	koch(d - 1, t, p2);
}

int main()
{
	int d;
	point p1, p2;
	
	p1.x = 0;
	p1.y = 0;
	p2.x = 100;
	p2.y = 0;
	scanf("%d", &d);
	
	sin60 = sin(M_PI / 3);
	cos60 = cos(M_PI / 3);
	printf("%.8f %.8f\n", p1.x, p1.y);
	koch(d, p1, p2);
	
	return 0;
}

Measured memory_bytes: 640
import numpy

N,M = map(int, input().split())
H = list(map(int, input().split()))
l = numpy.ones(N)

for i in range(M):
    A, B = map(int, input().split())

    if H[A-1] - H[B-1] > 0:
        l[B-1] = 0
    elif H[A-1] - H[B-1] < 0:
        l[A-1] = 0
    else:
        l[A-1] = 0
        l[B-1] = 0

print(list(l).count(1))

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

int main()
{
    int N;

    while ( cin >> N, N != 0 ) {
        int cnt[10] = {};
        for ( int i = 0; i < N; i++ ) {
            int a;
            cin >> a;
            cnt[a]++;
        }
        for ( int i = 0; i < 10; i++ ) {
            if ( cnt[i] == 0 ) {
                cout << "-" << endl;
            } else {
                for ( int j = 0; j < cnt[i]; j++ ) {
                    cout << "*";
                }
                cout << endl;
            }
        }
    }

    return ( 0 );
}



Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
typedef long long LL;
char s[MAXN], t[MAXN];


int main() {
	LL n, m; bool flag = true;
	scanf("%lld %lld", &n, &m);
	scanf("%s %s", s, t);
	LL ans = __gcd(n, m);
	for(LL i = 0; ; ++i) {
		LL cnt1 = n / ans * i;
		LL cnt2 = m / ans * i;
		//printf("%d %d %d\n", i, cnt1, cnt2);
		if(cnt1 >= n || cnt2 >= m) break;
		//puts("$$");
		if(s[cnt1] != t[cnt2]) {
			flag = false;
			break;
		}
	}
	if(flag) printf("%lld\n", n * m / ans);
	else puts("-1");
	return 0;
} 

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	var a int
	var s string
	fmt.Scan(&a, &s)
	if a >= 3200 {
		fmt.Println(s)
	} else {
		fmt.Println("red")
	}
}


Measured memory_bytes: 512
// Problem : C - Marks
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
int main()
{
	ll i,j,k,m,n,t;
	cin>>n>>k;
	ll ar[n];
	for(i=0;i<n;i++)
	cin>>ar[i];
	for(i=0;i+k<n;i++)
	if(ar[i]<ar[i+k])
	cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll a[k+1];
    for(int i=1;i<=k;i++){
    	ll num=k/i;
    	a[i]=modpow(num,n);
    }
    for(int i=k;i>=1;i--){
    	for(int j=i*2;j<=k;j+=i){
    		(a[i]-=a[j])%=mod;
    	}
    }
    ll ans=0;
    for(int i=1;i<=k;i++){
    	(ans+=(a[i]*i)%mod)%=mod;
    }
    ans+=mod;
    ans%=mod;
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 4424
a = input()
if a[len(a) - 1:len(a)] == "2" or a[len(a) - 1:len(a)] == "4" or a[len(a) - 1:len(a)] == "5" or a[len(a) - 1:len(a)] == "7" or a[len(a) - 1:len(a)] == "9":
    print("hon")
elif a[len(a) - 1:len(a)] == "0" or a[len(a) - 1:len(a)] == "1" or a[len(a) - 1:len(a)] == "6" or a[len(a) - 1:len(a)] == "8":
    print("pon")
elif a[len(a) - 1:len(a)] == "3":
    print("bon")

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

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = max(a+b, a-b);
    ans = max(ans, a*b);
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int i,j, cnt=0;
	for(i=1;i*i<=n;i++)
	{
		for(j=1;j*j<=n;j++)
		{
			if(i*j>=n)continue;
			cnt++;
		}
	}
	int x= sqrt(n);
	for(i=x+1; i<n;i++)
	{
		for(j=1;j*j<=n;j++){
			if(i*j >= n)continue;
			cnt+=2;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  int max = 0;
  int x   = 0;
  for(int i=0; i<S.size(); i++){
    if(S[i]=='I')
      x++;
    else
      x--;
    if( x > max )
      max = x;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x,y,sum =0;
    cin>>x>>y;
    int arr[x];
    for(int i = 0 ; i < x ; i++)
    {
        cin>>arr[i];
    }
    for(int m = 0 ; m < y ; m++)
    {
        int mini = -1;
        bool check = true;
        int index = -1;
        for(int i = 0 ; i < x; i++)
        {
            if(arr[i] > 0 && check)
            {
                mini = arr[i];
                check = false;
                index = i;
            }
            if(arr[i] < mini && arr[i] > 0)
            {
                mini = arr[i];
                index = i;
            }
        }
        arr[index] = -1;
        sum+=mini;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3604
from collections import Counter #ハッシュ法
N = int(input())
s_list = [input() for i in range(N)]

#出現するアルファベットをカウントしていく
al_list = [chr(ord('a') + i) for i in range(26)]

num_list = []
count_by_kw = Counter()
for _s in s_list:
    num = ''
    for _al in al_list:
        num += str(_s.count(_al))
    
    num_list.append(num)

count_list = list(Counter(num_list).values()) 

ans = 0
for i in range(len(count_list)):
    k = count_list[i]
    ans += k * (k - 1) / 2

print(int(ans))


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

 
int main() {


    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;


    //垂直ベクトル
    int xv=-(y2-y1);
    int yv=x2-x1;

    cout<<x2+xv<<' '<<y2+yv<<' '<<x1+xv<<' '<<y1+yv<<endl;


 	return 0;
}


Measured memory_bytes: 3600
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		  int n1 = sc.nextInt();
		  int n2 = sc.nextInt();
      int div;
		  while(n2 != 0){
			  div = n1 % n2;
		  	n1 = n2;
		  	n2 = div;
		  }
		System.out.println(n1);
	  }
	}
}


Measured memory_bytes: 26016
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int q;
  cin>>q;
  deque<Int> d;
  for(Int i=0;i<q;i++){
    Int t;
    cin>>t;
    if(t==0){
      Int a,x;
      cin>>a>>x;
      if(a) d.emplace_back(x);
      else  d.emplace_front(x);
    }
    if(t==1){
      Int p;
      cin>>p;
      cout<<d[p]<<endl;
    }
    if(t==2){
      Int a;
      cin>>a;
      if(a) d.pop_back();
      else  d.pop_front();
    }
  }
  return 0;
}



Measured memory_bytes: 6228
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
    ll k, a[55];
    cin >> k;

    REP(i, 50) a[i] = 49 + k / 50;
    REP(i, 50 - k % 50) a[i] -= k % 50;
    FOR(i, 50 - k % 50, 50) a[i] += 50 - k % 50 + 1;

    cout << 50 << endl;
    cout << a[0];
    for (int i = 1; i < 50; i++) cout << " " << a[i];
    cout << endl;
    return 0;
}

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

int N;

int main()
{
    cin >> N;
    int ans = 0;
    bool flag = false;
    for (int i=1; i<=N; i++)
    {
        int tmp;
        cin >> tmp;
        if (flag) flag = false;
        else if (tmp == i)
        {
            ans++;
            flag = true;                
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n";
#define CNO cout << "No" \
                 << "\n";
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

int main()
{
    int n;
    cin >> n;
    vector<long> v(n);
    map<long, long> m;
    for (size_t i = 0; i < n; i++)
    {
        long a;
        cin >> a;
        m[a]++;
        v[i] = a;
    }

    long sum = 0;
    for (auto &&p : m)
    {
        sum += p.second * (p.second - 1) / 2;
    }

    for (size_t i = 0; i < n; i++)
    {
        if (m[v[i]] <= 1)
        {
            cout << max(sum, 0L) << "\n";
        }
        else
        {
            cout << max(sum - m[v[i]] + 1, 0L) << "\n";
        }
    }
}

Measured memory_bytes: 11008
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 22 00:34:54 2020

@author: Kanaru Sato
"""

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

if n%2 != 0:
    print(0)
else:
    d.sort()
    print(d[n//2]-d[n//2-1])

Measured memory_bytes: 14396
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(gcd(c2 - c1, c3 - c2))
        return min(gcds)

print(get_res(cities))

Measured memory_bytes: 14252
strin = [input(), input(), input()]
l = ['a','b','c']
cnt, nxt = [0, 0, 0], 0
while True:
    lttr = strin[nxt][cnt[nxt]]
    cnt[nxt] += 1
    nxt = l.index(lttr)
    if cnt[nxt] >= len(strin[nxt]):
        print(l[nxt].upper())
        break


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

int n,k,s;

int dfs(int i, int k, int s) {
    if (k == 0 && s == 0) return 1;
    if (i > n || k == 0 && s != 0 || s < i*k+k-1) return 0;
    return dfs(i+1,k,s)+dfs(i+1,k-1,s-i);
}

int main(void){
    while (1) {
        cin >> n >> k >> s;
        if (n == 0 && k == 0 && s == 0) break;
        
        cout << dfs(1,k,s) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a, b; cin >> a >> b;
	if(count(b.begin(), b.end(), '1') == 0){
		if(a == b) cout << 0 << endl;
		else cout << -1 << endl;
		return 0;
	}
	int len = a.size();
	vector<int> to_left(len, len), to_right(len, len);
	for(int i = 0; i < len; i++){
		for(int j = 0; j < len; j++){
			if(b[(i - j + len)%len] == '1'){
				to_left[i] = j;
				break;
			}
		}
		for(int j = 0; j < len; j++){
			if(b[(i + j)%len] == '1'){
				to_right[i] = j;
				break;	
			}
		}
	}
	int ans = len * len;
	for(int i = 0; i < len; i++){
		int flips = 0;
		vector<pair<int,int>> q;
		for(int j = 0; j < len; j++){
			if(a[j] != b[(i + j)%len]){
				flips++;
				if(to_right[j] <= i);
				else {
					q.push_back({to_right[j] - i, to_left[j]});
				}
			}
		}
		q.push_back({0, len});
		q.push_back({len, 0});
		sort(q.begin(), q.end());
		int add = len;
		int sz = q.size();
		for(int i = sz - 2; i >= 0; i--) q[i].second = max(q[i].second, q[i + 1].second);
		for(int i = 0; i < sz - 1; i++){
			add = min(add, q[i].first * 2 + q[i+1].second * 2);
		}
		ans = min(ans, i + flips + add);
	}
	for(int i = 0; i < len; i++){
		int big_step = 0, flips = 0;
		vector<pair<int,int>> q;
		for(int j = 0; j < len; j++){
			if(a[j] != b[(j - i + len)%len]){
				flips++;
				if(to_left[j] <= i);
				else {
					q.push_back({to_right[j], to_left[j] - i});
				}
			}
		}
		q.push_back({0, len});
		q.push_back({len, 0});
		sort(q.begin(), q.end());
		int add = len;
		int sz = q.size();
		for(int i = sz - 2; i >= 0; i--) q[i].second = max(q[i].second, q[i + 1].second);
		for(int i = 0; i < sz - 1; i++){
			add = min(add, q[i].first * 2 + q[i+1].second * 2);
		}
		ans = min(ans, i + flips + add);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<int> a(N+2);
  a[0]=0;
  REP(i,N)cin>>a[i+1];
  a[N+1]=0;
  int sum=0;
  for(int i=1;i<=N+1;i++){
    sum+=abs(a[i]-a[i-1]);
  }
  for(int i=1;i<=N;i++){
    if((a[i-1]<=a[i]&&a[i]<=a[i+1])||(a[i-1]>=a[i]&&a[i]>=a[i+1])){
      cout<<sum<<endl;
    }else{
      cout<<sum-2*min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i]))<<endl;
    }
  }
}


Measured memory_bytes: 1664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main()
{
  while(true){
    ll N; cin>>N; if(N==0) break;
    vector<vector<pair<ll,double>>> graph(N,vector<pair<ll,double>>(0));
    
    //grid作成
    vector<pair<ll,ll>> grid(N);
    rep(i,N){
      ll b; cin>>b; b--;
      ll x,y; cin>>x>>y;
      grid.at(b)={x,y};
    }
    
    //重み付きグラフつくる
    rep(i,N){
      for(int j=i+1;j<N;j++){
        ll xi,yi,xj,yj;
        tie(xi,yi)=grid.at(i);
        tie(xj,yj)=grid.at(j);
        if((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj)<=2500){
          graph.at(i).push_back({j,sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj))});
          graph.at(j).push_back({i,sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj))});
        }
      }
    }
    
    //bfs
    ll M; cin>>M;
    vector<double> table;
    vector<ll> memo;
    rep(i,M){
      table=vector<double>(N,INF);
      memo=vector<ll>(N);
      ll s,g; cin>>s>>g; s--; g--;
      queue<ll> que;
      que.push(s);
      table.at(s)=0;
      while(!que.empty()){
        auto node=que.front();;
        que.pop();
        for(auto hoge:graph.at(node)){
          ll p; double cost;
          tie(p,cost)=hoge;
          if(chmin(table.at(p),table.at(node)+cost)){
            memo.at(p)=node;
            que.push(p);
          }
        }
      }
      if(table.at(g)==INF) {cout<<"NA"<<endl; continue;}
      vector<ll> vec(1,g);
      while(true){
        if(vec.at(vec.size()-1)==s) break;
        ll n=vec.at(vec.size()-1);
        vec.push_back(memo.at(n));
      }
      reverse(vec.begin(),vec.end());
      ll sz=vec.size();
      rep(i,sz){
        if(i!=0) cout<<" ";
        cout<<vec.at(i)+1;
      }
      cout<<endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3040
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  for (auto& e : p) cin >> e;
  sort(begin(p), end(p));
  int m = INT_MAX, ans = INT_MAX;
  for (int i = -100; i <= 100; ++i) {
    if (binary_search(cbegin(p), cend(p), X + i)) continue;
    if (m <= abs(i)) continue;
    m = abs(i);
    ans = X + i;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void){
  int n,x,m;
  int a;
  int i;
  int cost0=0;
  int costN=0;
  
  scanf("%d %d %d",&n,&m,&x);
  
  for( i=0; i<m; i++){
    scanf("%d",&a);
    if( a < x ) cost0++;
    else        costN++;
  }
  
  if( cost0 < costN ) printf("%d\n",cost0);
  else                printf("%d\n",costN);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
	int n;

	cin >> n;

	vector<ll>a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];

	}
	ll ans = -20000000000;
	ll minv = a[0];
	ll maxv = -20000000000;
	for (int i = 1;i < n;i++) {
		ans = max(ans, a[i] - minv);
		minv = min(minv, a[i]);
	}


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




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

int main() {
  int M, D;
  cin >> M >> D;

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 2; j <= D; j++) {
      if ((i == (j / 10) * (j % 10)) && j / 10 >= 2 && j % 10 >= 2) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

template <class T>
inline void read(T &x) {
	static char ch; 
	static bool opt; 
	while (!isdigit(ch = getchar()) && ch != '-'); 
	x = (opt = ch == '-') ? 0 : ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
	if (opt)
		x = ~x + 1; 
}

template <class T>
inline void putint(T x) {
	static char buf[45], *tail = buf; 
	if (!x) {
		putchar('0'); 
	} else {
		if (x < 0)
			putchar('-'), x = ~x + 1; 
		for (; x; x /= 10) *++tail = x % 10 + '0'; 
		for (; tail != buf; --tail) putchar(*tail); 
	}
}

using namespace std; 

const int MaxN = 2e5 + 5; 
const int mod = 1e9 + 7; 

int n; 
int a[MaxN]; 

int main() {
	read(n); 

	int sum = 0, sum2 = 0; 
	for (int i = 1; i <= n; ++i) {
		read(a[i]); 
		sum = (sum + a[i]) % mod; 
		sum2 = (sum2 + 1LL * a[i] * a[i]) % mod; 
	}

	cout << (1LL * sum * sum + mod - sum2) % mod * (mod + 1 >> 1) % mod << '\n'; 

	return 0; 
}

Measured memory_bytes: 4396
// SeeAlso: https://atcoder.jp/contests/abc056/tasks/abc056_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 50
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

char a, b;

int main() {
    cin >> a >> b;
    bool flag;
    if(a=='H') {
        flag = (b=='H');
    } else {
        flag = (b!='H');
    }
    print(flag ? 'H' : 'D');
    return 0;
}


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

int main(){
  char A[12],B[12],C[12];
  scanf("%s %s %s",A,B,C);
  int a=strlen(A),b=strlen(B);
  if(A[a-1]==B[0] && B[b-1]==C[0]) printf("YES\n");
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 1640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	F, _ := strconv.Atoi(sc.Text())
	fmt.Println((F - 30) /2)
}


Measured memory_bytes: 1092