akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Stack;
import java.util.stream.Stream;

public class Main {
    private static int WHITE = 0;
    private static int GRAY = 1;
    private static int BLACK = 2;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int n = Integer.parseInt(sc.nextLine());
            int[][] m = new int[n][n];
            while (sc.hasNext()) {
                int[] u_k_vs = Stream.of(sc.nextLine().split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray();
                int u = u_k_vs[0];
                for (int i = 2; i < u_k_vs.length; i++) {
                    m[u - 1][u_k_vs[i] - 1] = 1;
                }
            }
            dfs(n, m);
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static void dfs(int n, int[][] m) {
        int[] colors = new int[n];
        Arrays.fill(colors, WHITE);
        int[] nt = new int[n];
        int[] d = new int[n];
        int[] f = new int[n];
        int tt = 0;
        for (int i = 0; i < n; i++) {
            if (colors[i] == WHITE) {
                tt = visitByDFS(i, n, tt, nt, colors, d, f, m);
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.printf("%d %d %d\n", i + 1, d[i], f[i]);
        }
    }

    private static int visitByDFS(
            int r,
            int n,
            int tt,
            int[] nt,
            int[] colors,
            int[] d,
            int[] f,
            int[][] m
    ) {
        for (int i = 0; i < n; i++) {
            nt[i] = 0;
        }
        Stack<Integer> s = new Stack<>();
        s.push(r);
        colors[r] = GRAY;
        d[r] = ++tt;

        while (!s.empty()) {
            int u = s.peek();
            int v = next(n, u, nt, m);
            if (v != -1) {
                if (colors[v] == WHITE) {
                    colors[v] = GRAY;
                    d[v] = ++tt;
                    s.push(v);
                }
            } else {
                s.pop();
                colors[u] = BLACK;
                f[u] = ++tt;
            }
        }
         return tt;
    }

    private static int next(int n, int u, int[] nt, int[][] m) {
        for (int i = nt[u]; i < n; i++) {
            nt[u] = i + 1;
            if (m[u][i] == 1) {
                return i;
            }
        }
        return -1;
    }
}



Measured memory_bytes: 32740
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
         
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
        const int N=300006;
        int unread[N],d[N];
        signed main()
        {
        	string s;
        	cin>>s;
        	int n=s.size();
        	int f=0;
        	for(int i=0;i<n/2;i++)
        	{
                
        		if(s[i]!=s[n-i-1])
        		{
        			cout<<"No";
        			return 0;
				}
			}
			if(!f)
			{
				int l=n/2;
				for(int i=0;i<l/2;i++)
				{
					if(s[i]!=s[l-i-1])
					{
                     
						cout<<"No";
						return 0;
					}
				}
                int i=n/2+1;
                int j=n-1;
				for(;i<n;i++,j--)
				{
					if(s[i]!=s[j])
					{
                        //cout<<i;
						cout<<"No";
						return 0;
					}
				}
			}
			cout<<"Yes";
		}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

class Dice {
public:
        int face[6];

        void rotate(string str);
};

void Dice::rotate(string str)
{
        int tmp;

        for (size_t i = 0; i < str.length(); i++) {
                tmp = face[0];
                switch (str[i]) {
                case 'N':
                        face[0] = face[1];
                        face[1] = face[5];
                        face[5] = face[4];
                        face[4] = tmp;
                        break;
                case 'S':
                        face[0] = face[4];
                        face[4] = face[5];
                        face[5] = face[1];
                        face[1] = tmp;
                        break;
                case 'W':
                        face[0] = face[2];
                        face[2] = face[5];
                        face[5] = face[3];
                        face[3] = tmp;
                        break;
                default:
                        face[0] = face[3];
                        face[3] = face[5];
                        face[5] = face[2];
                        face[2] = tmp;
                        break;
                }
        }
}

int main()
{
        Dice dice;

        for (int i = 0; i < 6; i++) {
                cin >> dice.face[i];
        }
        string com;
        cin >> com;
        dice.rotate(com);
        cout << dice.face[0] << endl;

        return 0;
}

Measured memory_bytes: 1208
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let a:usize =read!();
    let mut v:Vec<usize>=Vec::new();
    for i in 0..a {
        let s:usize=read!();
        v.push(s);
    }
    let mut ans=0;
    for i in 0..a-2 {
        if min(v[i],min(v[i+1],v[i+2]))!=v[i+1]&&max(v[i],max(v[i+1],v[i+2]))!=v[i+1] {ans+=1 }
    }
    println!("{}",ans)
}

Measured memory_bytes: 2172
(defvar l '(kihbr kihbra kihbar kihbara kihabr kihabra kihabar kihabara akihbr akihbra akihbar akihbara akihabr akihabra akihabar akihabara))
(defvar s (read))
(princ (if (find-if (lambda (x) (eq s x)) l) "YES" "NO"))

Measured memory_bytes: 6756
#include<stdio.h>
int main(void){
    int r,c,i,j,s=0,f=0;
    int a[100][100],b[100]={0};
    scanf("%d %d",&r,&c);
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            printf("%d ",a[i][j]);
            s+=a[i][j];
            b[j]+=a[i][j];
        }
        printf("%d\n",s);
        s=0;
    }
    for(i=0;i<c;i++){
        printf("%d ",b[i]);
        f+=b[i];
    }
    printf("%d\n",f);
    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
typedef long long 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 REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* 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 H;
ll tmp;
ll ret = 0;

void input() {
  IN(N);
  IN(H);
  ll left = H;
  ll mv = 0;
  FOR(i, 1, N) {
    IN(H);
    if (left >= H) {
      left = H;
      mv += 1;
      ret = max(mv, ret);
    } else {
      left = H;
      mv = 0;
    }
  }
  ret = max(mv, ret);
}

void solve() {
  PRINT(ret);
}

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


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;
vector<int> visited;
vector<int> res;
vector<vector<int>> G;

int main(){
  ll n,m;
  cin >> n >> m;
  visited.resize(n+1);
  res.resize(n+1);
  G.resize(n+1);
  
  rep(i,n+1) visited[i]=-1;
  rep(i,n+1) res[i]=0;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  queue<int> que;
  que.push(1);
  res[1]=0;
  visited[1]=1;
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

    for (int nv : G[v]) {
      if (visited[nv] != -1) continue;
      else visited[nv]=1;
      que.push(nv);
      res[nv] = v;
    }
  }
    
  if(G[1].size()==0)
    cout << "No" << '\n';
  else{
    cout << "Yes" << '\n';
    for(int i=2;i<=n;i++)
      cout << res[i] << '\n';
  }
  return 0;
}








Measured memory_bytes: 10624
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int, h: "List[int]"):
    print(len(
        [i for i in h if i >= K]
    ))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12520
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    long a[n],sum=0;
    for(int i=0;i<n;i++){
        scanf("%ld",&a[i]);
        sum+=a[i];
    }
    int x[100000]={0};
    x[0]=sum;
    for(int i=1;i<n;i+=2){
        x[0]-=2*a[i];
    }
    printf("%d ",x[0]);
    for(int i=1;i<n;i++){
        x[i]=2*a[i-1]-x[i-1];
        printf("%d ",x[i]);
    }

    return 0;
}


Measured memory_bytes: 2432
#include <iostream>

using namespace std;
int main()
{
	int a;
	cin >> a;
	
	while(a>=0){
		if(a % 7 == 0){
			cout << "Yes" << endl;
			return 0;
		}
		a -= 4;
	}
	cout << "No" << endl;
	return 0;
}

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

using namespace std;

int n, k;
long long a[100005], b[100005];
int ida, idb;

void init() {
    cin >> n >> k;
    ida = 1, idb = 1;
    for(int i = 1 ; i <= n ; i++) {
        long long c; cin >> c;
        if(c >= 0) a[ida++] = c;
        else b[idb++] = -c;
    }
    reverse(b+1, b+idb);
}

void solve() {
    long long ans = 1e9;
    for(int i = 1, j = k-1 ; i < ida && j > 0 ; i++, j--) {
 //       cout << i << " " << j << " " << a[i] << " " << b[j] << endl;
        if(j < idb) ans = min(ans, a[i]*2+b[j]);
    }
    for(int i = 1, j = k-1 ; i < idb && j > 0 ; i++, j--) {
//        cout << i << " " << j << " " << a[i] << " " << b[j] << endl;
        if(j < ida) ans = min(ans, b[i]*2+a[j]);
    }
    if(ida > k) ans = min(ans, a[k]);
    if(idb > k) ans = min(ans, b[k]);
    
    cout << ans << "\n";
}

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


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

count = 0
flag = False
while True:
    for i in range(n):
        a[i] /= 2
        if a[i] % 1 > 0:
            print(count)
            flag = True
            break
    if flag:
        break
    count += 1

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
template<class T>
struct BIT{
    vector<T> d;
    BIT(size_t n):d(n+1){}
    T sum(size_t i){T s{};for(++i;i>0;i-=i&-i)s+=d[i];return s;}
    T sum(size_t i,size_t j){return i?sum(j)-sum(i-1):sum(j);}
    void add(size_t i,T x){for(++i;i<d.size();i+=i&-i)d[i]+=x;}
};

// 要素数ではなく空間計算量はO(値域)
// 値域を確認すること！！　座標圧縮は含まれていない。
ll inversion(vi a){ // n = a.size  O(n log n)
  BIT<int> bit(1000000);
  ll ret = 0;
  rep(i,a.size()){
    ret += i - bit.sum(a[i]);
    bit.add(a[i],1);
  }
  return ret;
}
int table[2001] = {};
int main(){
  ll ans = 0;
  ll n,k; cin >> n >> k;
  vi in;
  rep(i,n){
    int a; cin >> a;
    in.pb(a);
    for(int i = a+1; i < 2001;++i){
      table[i]++;
    }
  }
  ans += (1LL*inversion(in)*k);
  ans %= DIV;
  k %= DIV;
  rep(i,in.size()){
    ll add = ((1LL*k*(k-1)/2%DIV)*table[in[i]]) % DIV;
    //cerr << add << endl;
    ans += add;
    ans %= DIV;
  }
  cout << ans%DIV << endl;
}


Measured memory_bytes: 4224
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;
#define EPS (1e-6)
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef pair<int,int> P;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);
  int INF = 1000000;

  int N;
  cin >> N;
  REP(t,N){
    double x1,y1,r1,x2,y2,r2;
    cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;

    double dis = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
    if( dis > r1+r2 )
      cout << 0 << endl;
    else if( r2 > r1+dis )
      cout << -2 << endl;
    else if( r1 > r2+dis )
      cout << 2 << endl;
    else
      cout << 1 << endl;
  }

  return 0;
}

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

int main(){
  int n;
  cin >> n;
  if(n < 1200 ){cout << "ABC" << endl;}
  if (n < 2800 && 1200 <= n){cout << "ARC" << endl;}
  if(2800 <= n){cout << "AGC" << endl;}
  return 0;
}


Measured memory_bytes: 256
N = int(input())
D = [list(map(str,input().split())) for _ in range(N)]
for i in range(N):
  D[i].append(i+1)
sorted_d = sorted(D, key = lambda x: (x[0], -int(x[1])))
for i in range(N):
  print(sorted_d[i][2])

Measured memory_bytes: 9116
#include<iostream>
#include<limits.h>
using namespace std;
int inf=INT_MAX;
int dat[400004];
int n,q;
void init(int n_){
  n=1;
  while(n < n_) n*=2;
  for(int i=0;i<2*n-1;i++) dat[i]=inf;
}
void update(int k,int a){
  k+=n-1;
  dat[k]=a;
  while(k>0) {
    k=(k-1)/2;
    dat[k]=min(dat[k*2+1],dat[k*2+2]);
  }
}
int query(int a,int b, int k,int l,int r){
  //cout << a<< b<< k<<l<<r <<endl;
  if(r<=a||b<=l) return inf;
  if(a<=l && r <= b) return dat[k];
  else{
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    //cout << vl << ":" <<vr << endl;
    return min(vl,vr);
  }
}

int find(int x,int y){
  return query(x,y,0,0,n);
}
int main(){
  int n_;
  cin >> n_ >> q;
  init(n_);
  //cout << n <<endl;
  int i,j;
  for(i=0;i<q;i++){
    int com,x,y;
    cin >> com >> x >> y;
    if(com==0) update(x,y);
    else cout << find(x,y+1) << endl;
  }
  return 0;
}

Measured memory_bytes: 2184
/*  ex7_1
    Acro   */
#include <stdio.h> 

typedef struct point
{
    int x_elem;
    int y_elem;
}point;
/* vec1を支点としてvec2を反時計回り90°回転させた点を返す*/
point shift_point(point vec1, point vec2)
{
    point new_vec;
    /* 支点の移動 */
    new_vec.x_elem = vec2.x_elem - vec1.x_elem;
    new_vec.y_elem = vec2.y_elem - vec1.y_elem;
    /* 回転 */
    new_vec.x_elem = new_vec.y_elem*(-1);
    /* new_vec.y_elem = new_vec.x_elem */
    new_vec.y_elem = vec2.x_elem - vec1.x_elem;
    /* 支点を戻す */
    new_vec.x_elem += vec1.x_elem;
    new_vec.y_elem += vec1.y_elem;

    return new_vec;
}

int main(void){
    point vec1,vec2,vec3,vec4;
    /* 入力 */
    scanf("%d %d %d %d",&vec1.x_elem,&vec1.y_elem,&vec2.x_elem,&vec2.y_elem);
    /* 順番に注意 */
    vec4 = shift_point(vec1,vec2);
    vec3 = shift_point(vec4,vec1);
    /* 出力 */
    printf("%d %d %d %d\n",vec3.x_elem, vec3.y_elem, vec4.x_elem, vec4.y_elem);
    return 0;
}

Measured memory_bytes: 1692
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		double r = stdIn.nextDouble();
		int ans = 0;
		ans = 3 * (int)Math.pow(r, 2);
		System.out.println(ans);
		stdIn.close();
	}
}

Measured memory_bytes: 37436
n,k = gets.split.map &:to_i
x = gets.split.map &:to_i

minus = x.select{|i|i < 0}.reverse
plus = x.select{|i|i >= 0}

result = 1e9

#左に行くだけ
if minus.size >= k
    result = -minus[k-1]
end

#右に行くだけ
if plus.size >= k
    result = [result, plus[k-1]].min
end

#左に行ってから右に行く
(0..(minus.size)).each do |i|
    if minus[i] && plus[k-i-2]
        temp = 0
        temp -= minus[i] * 2
        temp += plus[k-i-2]
        if temp <= result
            result = temp
        end
    end
end

#右に行ってから左に行く
(0..(plus.size)).each do |i|
    if plus[i] && minus[k-i-2]
        temp = 0
        temp += plus[i] * 2
        temp -= minus[k-i-2]
        if temp <= result
            result = temp
        end
    end
end

puts result

Measured memory_bytes: 9996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int a, b, c, d, p;

int main(){
	cin >> a >> b >> c >> d >> p;
	int ans = 0;
	if (p > c)ans = min(a*p, b + (p - c)*d);
	else ans = min(a*p, b);
	cout << ans << endl;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void){
    int a,b;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?'){
            break;
        }
        else if(op=='+'){
            printf("%d\n",a+b);
        }
        else if(op=='-'){
            printf("%d\n",a-b);
        }
        else if(op=='*'){
            printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }
    }
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

class BIT {
    public:
        int size;
        vector<int> node;

        BIT(int n, long long init_num) {
            size = n;
            for (int i = 0; i <= size; i++){
                node.pb(init_num);
            }
        }

        void add(int i, long long x) {
            while (i <= size) {
                node[i] += x;
                i += i & -i;
            }
        }

        long long sum(int i) {
            long long ret = 0;
            while (i > 0) {
                ret += node[i];
                i -= i & -i;
            }
            return ret;
        }
};

int n, k;
int a[200000 + 5];
int s[200000 + 5];
vector<pair<int, int>> pa;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
        a[i] -= k;
        s[i + 1] = s[i] + a[i];
        pa.push_back({s[i + 1], i + 1});
    }
    sort(all(pa));
    BIT bit(n, 0);
    ll ans = 0;
    rep(i, n) {
        bit.add(pa[i].se, 1);
        ans += bit.sum(pa[i].se);
        if (pa[i].fi < 0) ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 10732
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
using ll = long long;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=int(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1000000007;
using namespace std;

int main() {
    int N; cin >> N;
    int bucket[100001]={0};
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        bucket[a]++;
        a--;
        bucket[a]++;
        a+=2;
        bucket[a]++;
    }
    sort(bucket, bucket+100001);
    cout << bucket[100000] << endl;
	return 0;
}

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

int main(){
    int N , M , sum = 0;
    cin >> N >> M;
    vector<int> work(M);
    for(int i = 0 ; i < M ; ++i){
        cin >> work.at(i);
    }
    for(int i = 0 ; i < M ; ++i){
        sum += work.at(i);
    }
    if(N -sum >= 0)cout << N - sum <<endl;
    else cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <climits>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_N = 200000;

template<typename T> class LazyRMQ {
    public:
    int n;
    T inf = INT_MAX;
    vector<T> data, lazy;
    
    LazyRMQ(int m, T init_value=INT_MAX){
        // 2のべき乗にする
        n = 1;
        while(n < m) n <<= 1;
        data.assign(2*n-1, init_value);
        lazy.assign(2*n-1, 0);
        inf = init_value;
    }

    void eval(int k, int kl, int kr){
        if(data[k] == inf) data[k] = 0;
        if(lazy[k] == 0) return;
        data[k] += lazy[k];
        if(kr - kl > 1){
            lazy[2*k+1] += lazy[k];
            lazy[2*k+2] += lazy[k];
        }
        lazy[k] = 0;
    }

    // [s,t)
    void add(int s, int t, T x, int k, int kl, int kr){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return;
        if(s <= kl && kr <= t){
            lazy[k] += x;
            eval(k, kl, kr);
            return;
        }
        int kc = (kl+kr)/2;
        add(s, t, x, 2*k+1, kl, kc);
        add(s, t, x, 2*k+2, kc, kr);
        data[k] = max(data[2*k+1], data[2*k+2]);
    }

    void add(int s, int t, T x) {
        add(s, t, x, 0, 0, n);
    }

    // [s,t)
    T find(int s, int t, int k, int kl, int kr){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return inf;
        if(s <= kl && kr <= t) return data[k];
        int kc = (kl+kr)/2;
        T vl = find(s, t, 2*k+1, kl, kc);
        T vr = find(s, t, 2*k+2, kc, kr);
        return max(vl, vr);
    }

    T find(int s, int t) {
        return find(s, t, 0, 0, n);
    }
};

int main() {
    int n,m,l,r; ll a;
    cin >> n >> m;
    vector<pair<int, ll>> ranges[n+1];
    for(int i=0;i<m;++i) {
        cin >> l >> r >> a;
        ranges[r].emplace_back(l, a);
    }

    LazyRMQ<ll> tree(n+2, -(1<<30));
    for(int i=1;i<=n;++i) {
        ll opt = tree.find(0, i);
        tree.add(i, i+1, opt);
        for(pair<int, ll> p: ranges[i]) {
            tree.add(p.first, i+1, p.second);
        }
    }

    cout << tree.find(0, n+1) << endl;
}

Measured memory_bytes: 19328
m = int(input())
dc =  [list(map(int,input().split())) for _ in range(m)]
flag = 0
ans = -1
x = 0
for i in range(m):
  x += dc[i][0]*dc[i][1]
  ans += dc[i][1]
if x % 9 == 0:
  ans += x//9-1
else:
  ans += x//9
print(ans)

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

const int INF = 1001001001;
int a[12][12];

int main() {
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> c(n);
    rep(i,n) {
        cin >> c[i] ;
        rep(j, m) cin >> a[i][j];
    }
    
    int ans = INF;
    rep(s,1<<n) {
        int cost = 0;
        vector<int> d(m);
        rep(i,n) {
            if(s>>i&1) {
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j, m) if (d[j] < x) ok = false;
        if (ok) ans = min(ans, cost);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
import sys

N,A,B=(int(x) for x in input().split())

x=[int(t.strip()) for t in input().split()]

gap=[]
for i in range(N-1):
	gap.append(x[i+1]-x[i])

total=0
for i in range(N-1):
	if gap[i]*A < B :
		total += gap[i]*A
	else:
		total += B
		
print(total)

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

using namespace std;

int main()
{
    int n , m ;
    cin>>n>>m ;
    int cost[n] , weight[n] ;
    vector< pair<int , int> >vp ;
    for(int i = 0 ; i < n ; ++i)
    {
        cin>>cost[i]>>weight[i] ;
        vp.push_back({cost[i] , i}) ;
    }
    sort(vp.begin() , vp.end());
    long long ans = 0ll ;
    for(int i = 0 ; i < n ; ++i)
    {
        int idx = vp[i].second ;
        long long x = min(m , weight[idx]);
        m -= x ;
        ans += cost[idx] * 1ll * x * 1ll;
        if(m <= 0)
            break;
    }
    return cout<<ans<<"\n" , 0 ;
}


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

int main(){
  int x,a,b,c,d;
  cin >> x >> a >> b;
  if(x<a){
    c=a-x;
  }
  else{
    c=x-a;
  }
  if(x<b){
    d=b-x;
  }
  else{
    d=x-b;
  }
  if(c<d){
    cout << "A" << endl;
  }
  else{
    cout << "B" << endl;
  }
}


Measured memory_bytes: 256
import sys
i = 0
x = []
for line in sys.stdin:
    if i==0:
        x.append(int(line))
    else:
        s1 = 'SHCD'.index(line[0])
        s2 = int(line[2:])
        x.append((s1,s2))
    i = 1
 
r4 = range(4)
r13 = range(13)
lx = x.pop(0)
cards = [[0 for i in r13] for j in r4]
for j,i in x: cards[j][i-1] = 1
 
for j in r4:
    for i in r13:
        if cards[j][i]==0: print 'SHCD'[j],str(i+1)



Measured memory_bytes: 4660
using System;

class Program
{
  static void Main(string[] args)
  {
    int N = int.Parse(Console.ReadLine());
    string[] vals = Console.ReadLine().Split();
    int[] A = new int[N];
    for (int i = 0; i < N; ++i) {
      A[i] = int.Parse(vals[i]);
    }

    bool ok = true;
    for (int i = 1; i < N; ++i) {
      if (A[i-1] < A[i]) {
        --A[i];
      }
      else if (A[i-1] > A[i]) {
        ok = false;
        break;
      }
    }

    if (ok) {
      Console.WriteLine("Yes");
    }
    else {
      Console.WriteLine("No");
    } 
  }
}


Measured memory_bytes: 24668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 1;
  sort(a.begin(), a.end());
  // if(n == 1 && a[0] == 0){
  //   cout << 1 << endl;
  //   return 0;
  // }
  if(a.size() % 2 == 1){
    if(a[0] == 0) a.erase(a.begin());
    else {
      cout << 0 << endl;
      return 0;
    }
  }

  int cur;
  if(n % 2) cur = 2;
  else cur = 1;

  for(int i = 0; i < a.size() - 1; i += 2){
    if(i + 1 >= a.size()) {
      break;
    }
    if(a[i] == a[i + 1] && a[i] == cur){
      ans *= 2;
      ans %= mod;
      cur += 2;
    } else {
      
      ans = 0;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.IO;
class Test{
  static void Main() {
  var arr = Console.ReadLine().Split(' ');
var n = int.Parse(arr[0]);
var m = int.Parse(arr[1]);
int big;
int small;
if(n>=m) {
big=n;
small=m;
}else{
big=m;
small=n;
}
string s = "";
for(int i =0;i<big;i++) {
 s+= small.ToString();
}

Console.WriteLine(s);
}
}

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

struct Card{
    char suit,value;//suit=S,H,C,Dのアルファベット value=1~9の数値
};

void bubble(Card A[],int N){
    for (int i=0; i<N; i++){
        for (int j=N-1; j>i; j--){
            if (A[j].value < A[j-1].value){
                Card t=A[j];
                A[j]=A[j-1];
                A[j-1]=t;
            }
        }
    }
}

void selection(Card A[],int N){
    for (int i=0; i<N; i++){
        int minj=i;
        for (int j=i; j<N; j++){
            if (A[j].value < A[minj].value) minj=j;
        }
        Card t=A[i];
        A[i]=A[minj];
        A[minj]=t;
    }
}

void print(struct Card A[],int N){
    for (int i=0; i<N; i++){
        if (i>0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

//バブルソートと選択ソートの結果を比較
bool isStable(Card C1[],Card C2[],int N){
    for (int i=0; i<N; i++){
        if (C1[i].suit!=C2[i].suit) return false;
    }
    return true;
}

int main(){
    Card C1[100],C2[100];
    int N; 
    char ch;

    cin >> N;
    for (int i=0; i<N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }

    for (int i=0; i<N; i++) C2[i]=C1[i];

    bubble(C1,N);
    selection(C2,N);

    print(C1,N);
    cout << "Stable" << endl;

    print(C2,N);
    if (isStable(C1,C2,N)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    return 0;
}


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

int main() {
  
  string s;
  cin>>s;
  int64_t a=0;
  for(int i=0; i<s.size(); i++){
    a=a+s.at(i)-48;
  }
  
  if(a%9==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}
  
  

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

int main() {
	long long n, k, ans = 0; cin >> n >> k;
	for (long long b = k + 1,m; b <= n; b++) {
		m = n / b;
		ans += (b - k) * m + max(n - (b * m + k - 1), 0LL) - (k == 0 ? 1 : 0);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
Y = [-1,0,1,0]; X = [0,-1,0,1]
H, W = gets.split.map(&:to_i)
areas = [] << Array.new(W+2, "@")
H.times do
  areas << ["@"] + gets.chomp.split('') + ["@"]
end
areas << Array.new(W+2, "@")
# areas.each do |a|
#   p a
# end

1.upto(H) do |i|
  1.upto(W) do |j|
    if areas[i][j] == "#"
      check = false
      4.times do |k|
        nexy = i + Y[k]
        nexx = j + X[k]
        nexarea = areas[nexy][nexx]
        if nexarea == "#" || nexarea == "!"
          nexarea = "!" if nexarea == "#"
          check = true
        end
      end
      if check
        areas[i][j] = "!"
      else
        puts "No"
        exit
      end
    end
  end
end
puts "Yes"

Measured memory_bytes: 3964
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 20001;

int G[101][101];
int color[101], d[101], p[101];

int main(void)
{
	int n, m, mincost, u, min = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> m;
			if (m == -1)
				G[i][j] = MAX;
			else
				G[i][j] = m;
		}
	}
	for (int i = 0; i < n; i++) {
		color[i] = 0;
		d[i] = MAX;
	}
	d[0] = 0;
	p[0] = -1;
	while (1) {
		mincost = MAX;
		for (int i = 0; i < n; i++) {
			if (color[i] != 2 && d[i] < mincost) {
				mincost = d[i];
				u = i;
			}
		}
		if (mincost == MAX)
			break;
		min += mincost;
		color[u] = 2;
		for (int v = 0; v < n; v++) {
			if (color[v] != 2) {
				if (G[u][v] < d[v]) {
					d[v] = G[u][v];
					p[v] = u;
					color[v] = 1;
				}
			}
		}
	}
	cout << min << endl;
	return 0;
}


Measured memory_bytes: 3132
#include<iostream>
using namespace std;
string s;
int a,b,c,d;
int main (void){
	cin>>s;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	if (a+b+c+d==7) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
	else if (a+b+c-d==7) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
	else if (a+b-c+d==7) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
	else if (a+b-c-d==7) cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
	else if (a-b+c+d==7) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
	else if (a-b+c-d==7) cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
	else if (a-b-c+d==7) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
	else if (a-b-c-d==7) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
	else cout<<"No Answer!"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  while(true){
    string S;
    cin>>S;
    if(S=="0"){
      return 0;
    }
    int sum =0;
    int len=S.size();
    for(int i=0;i<len;i++){
      sum+=S[i]-'0';
    }
    cout<<sum<<endl;
  }
  return 0;
}



Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        int q = partition(a, 0, n-1);
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            if(i == q){
                sb.append("[").append(a[i]).append("] ");
            }else{
                sb.append(a[i]).append(" ");
            }
        }
        sb.deleteCharAt(sb.length()-1);
        
        System.out.println(sb);
    }
    
    static int partition(int[] a, int p, int r){
        
        int x = a[r];
        int i = p-1;
        for(int j = p; j < r; j++){
            if(a[j] <= x){
                i++;
                int k = a[i];
                a[i] = a[j];
                a[j] = k;
            }
        }
        int k = a[i+1];
        a[i+1] = a[r];
        a[r] = k;
        return i+1;
    }
}


Measured memory_bytes: 70012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =1e5+100;

int main()
{
    int n,s,ans[N];
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&s);
            ans[s] =i+1;
        }
        for(int i=1;i<=n;i++)
            printf("%d ",ans[i]);
        printf("\n");
    }
    return 0;
}


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

int main(void){
	int N,M;
	char *blue[100],*red[100];
	char s[100][10],t[100][10];
	
	scanf("%d",&N);
	int i;
	for(i=0;i<N;i++){	//各行の開始アドレスの代入
		blue[i]=s[i];
	}	
	for(i=0;i<N;i++){	//ポインタ配列を使った文字列の入力
		scanf("%s",blue[i]);
	}
	scanf("%d",&M);
	for(i=0;i<M;i++){
		red[i]=t[i];
	}
	for(i=0;i<M;i++){
		scanf("%s",red[i]);
	}

	int X,tmp=0;
	int j;
	for(j=0;j<N;j++){
		X=0;
		for(i=0;i<N;i++){
			if(strcmp(blue[j],blue[i])==0)	X++;
		}
		for(i=0;i<M;i++){
			if(strcmp(blue[j],red[i])==0)	X--;
		}
		if(X<tmp)	X=tmp;
		tmp=X;
	}
	
	printf("%d",X);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define MAX 251
int main(){
  int j,n,d[MAX];
  scanf("%d", &n);
  for(j=1;j<=n;j++) scanf("%d", &d[j]);
  for(j=1;j<=n;j++){
    printf("node %d: key = %d, ", j, d[j]);
    if(j/2) printf("parent key = %d, ", d[j/2]);
    if(2*j<=n) printf("left key = %d, ", d[2*j]);
    if(2*j+1<=n) printf("right key = %d, ", d[2*j+1]);
    printf("\n");
  }
  return 0;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	int ret=(a-1);
	if(a<=b) ret++;
	cout << ret << endl;
	return 0;
}


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

int main() {
string s; cin>>s;
  int red=0;
  int blue=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){red++;}
    else blue++;
  }
  
  cout<<2*min(red,blue)<<endl;
  
  
}

Measured memory_bytes: 512
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=1;
  cin>>n;
  string s;
  cin>>s;
  vector<ll>v(2*n,0);
  vector<ll>a(2*n,0);
  for(ll i=0;i<2*n;i++){
    if(s[i]=='B')v[i]=1;
  }
  ll tmp=0;
  for(ll i=0;i<2*n;i++){
    if(v[i]^tmp){
      a[i]=1;//開始
    }
    tmp^=1;
  }
  ll aa=0,bb=0,f=0;
  ll k=0;
  for(ll i=0;i<2*n;i++){
    if(a[i])aa++;
    else bb++;
    if(aa<bb)f=1;
  }
  if(aa!=bb)f=1;
  if(f){
    cout<<0<<endl;
    return 0;
  }
  for(ll i=0;i<2*n;i++){
    if(a[i])k++;
    else{
      ans=ans*k%MOD;
      k--;
    }
  }
  for(ll i=1;i<=n;i++){
    ans=ans*i%MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3716
#include<iostream>
#include<map>

using namespace std;

void print(int from, int to){
  cout << endl;
  for(int i = 0; i < from; i++) cout << " ";
  for(int i = from; i < to; i++) cout << "^";
}

int main(){

  int p,q;
  while(cin >> p >> q){
    map<int,int> M;
    int cnt = 0;
    bool f = false;

    while(1){
      int a = p/q;
      int b = p%q;

      if(f) cout << a;
      f = true;

      p = b*10;
      if(b == 0) break;
   
      if(M[b] == 0) M[b] = ++cnt;
      else{
	print(M[b]-1, cnt);
	break;
      }
      
    }
    cout << endl;
  }
  return 0;
}

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

string w[110];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> w[i];
  }

  bool ans = true;
  for (int i = 0; i < N - 1; i++) {
    if (w[i][w[i].length()-1] != w[i+1][0]) {
      ans = false;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (w[i] == w[j]) {
        ans = false;
      }
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
a=-1,A=65,d;
char
*N="GKSOCNWLDFVTBRXHAJUPEMQI",
*E="PHLTIDOXQAGWECSUMBKVJFNR",
s[9];
main(c)
{
for(;c-48&&scanf("%s",s);a+=d/4+1)
(c=*s)<A?~a&&printf("%d\n",a),a=d=0:0,
d=(c==78?d=N[d]:
c==69?d=E[d]:
c==83?d=N[N[N[d]-A]-A]:
c==87?d=E[E[E[d]-A]-A]:d+A)-A,
//c==82?d=d&28|d%4+1&3:d,c==76?d=d&28|d%4+3&3:d;
d=c==82|c==76?d&28|d%4+3-c/80*2&3:d;
}

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

using namespace std;

int main() {
    
    int v[3];
    cin >> v[0] >> v[1] >> v[2];

    swap(v[0], v[1]);
    swap(v[0], v[2]);

    for (int i = 0; i < 3; ++i)
        cout << v[i] << " ";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define S str[ima]
#define A a,b,c,d,e,f,g,h,i,j,k
using namespace std;
int ima;
string str;
int cnt = 0;
//2^11= 2048

int formula(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k){
  int val,val2;
  
  while(S=='T'||S=='F'||('a'<=S && S<='k')||S=='-'||S=='('){
    if(('a' <= S && S<='k')||S=='T'||S=='F') {
      if(S=='a') val=a;
      else if(S=='b') val=b;
      else if(S=='c') val=c;
      else if(S=='d') val=d;
      else if(S=='e') val=e;
      else if(S=='f') val=f;
      else if(S=='g') val=g;
      else if(S=='h') val=h;
      else if(S=='i') val=i;
      else if(S=='j') val=j;
      else if(S=='k') val=k;
      else if(S=='T') val=1;
      else if(S=='F') val=0;
      ima++;
    }
    else if(S=='-'&&str[ima+1] != '>'){
      ima++;
      val = formula(A);
      if(val==1) val = 0;
      else if(val==0) val = 1;
    }
    else if(S=='('){
      ima++;
      val = formula(A);
      if(S == '*'){
	ima++;
	val2 = formula(A);
	if(val==0||val2==0) val = 0;
	else val = 1;
      }
      else if(S=='+'){
	ima++;
	val2 = formula(A);
	if(val==0 && val2==0) val=0;
	else val = 1;
      }
      else if(S=='-'&&str[ima+1]=='>'){
	ima+=2;
	val2 = formula(A);
	if(val==1 && val2 == 0) val = 0;
	else val = 1;
      }
      ima++;
    }

    return val;
  }
  
}

int main() {

  while(1){
    cin >> str;
    if(str == "#") break;

    int flg = 0;
    ima = 0;
    for(int i=0;i<2048;i++){
      int j=10, n = i, a[11] = {};
      while(n != 0) a[j] = n%2,n/=2,j--;
      ima = 0;
      int val = formula(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10]);
      ima++;
      int val2 = formula(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10]);
      /*      if(val != val2){
	for(int i=0;i<11;i++) cout << a[i];
	cout <<endl;
	cout <<val<<" " <<val2 << endl;
	cout <<str.size()<<" "<<ima<<endl;
	} */
      if(val != val2) {
	flg = 1;
	break;
      } 
    }
    if(flg == 1) cout <<"NO"<<endl;
    else cout <<"YES"<<endl;
  }
    
  
  return 0;
}

Measured memory_bytes: 1308
#include <vector>
#include <iostream>

using namespace std;

int main() {
    int N, M;
    vector<string> s, t;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        string a;
        cin >> a;
        s.push_back(a);
    }
    cin >> M;
    for (int i = 0; i < M; ++i) {
        string b;
        cin >> b;
        t.push_back(b);
    }
    int max = 0;
    for (int i = 0; i < N; ++i) {
        string target = s[i];
        int cnta = 0;
        int cntb = 0;
        for (int j = 0; j < N; ++j) {
            if (target == s[j]) {
                cnta++;
            }
        }
        for (int j = 0; j < M; ++j) {
            if (target == t[j]) {
                cntb++;
            }
        }
        int earn = cnta - cntb;
        if (max < earn) {
            max = earn;
        }
    }
    cout << max << endl;
}

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

int ans = 0;

void trace(vector<int> a, int n)
{
    for(int i=0; i<n; i++){
        if (i == a.size()-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
}

void BubbleSort(vector<int> &a, int n)
{
    bool flag = true;
    while(flag){
        flag = false;
        for(int i=n-1; i>0; i--){
            if (a[i] < a[i-1]){
                flag = true;
                swap(a[i], a[i-1]);
                ans++;
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    BubbleSort(a, n);
    trace(a, n);
    cout << ans << endl;;
    return 0;
}


Measured memory_bytes: 3160
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,k = map(int, input().split())
h = np.zeros(n, dtype = int)
for i in range(n):
    h[i] = int(input())

h.sort()
# eprint(h)
ll = np.zeros(n-k+1,dtype=int)
for i in range(n-(k-1)):
    ll[i] = abs(h[i] - h[i+(k-1)])
    
# eprint(ll)
print(ll.min())
    
    
# sorted(h)
# np.sort(h)
# h.sort()
# print(h)




Measured memory_bytes: 14940
module SSet = Set.Make(String);;
Scanf.(Array.(scanf" %s %s"@@fun s t->
	let open Printf in
	let k,l = String.length s,String.length t in
	print_endline@@
		if k<l then "UNRESTORABLE"
		else try
			let st = ref SSet.empty in
			for i=0 to k-l do
				(* printf "[%d %d]\n" i (i+l-1); *)
				let f = ref true in
				for j=i to i+l-1 do
					(* printf "  %c  %c\n" s.[j] t.[j-i]; *)
					if s.[j]='?' || s.[j]=t.[j-i] then () else f:=false;
				done;
				if !f then st := SSet.add (
					init k (fun j ->
						if i<=j && j<=i+l-1 then t.[j-i]
						else if s.[j] = '?' then 'a'
						else s.[j]
					) |> map (String.make 1) |> Array.to_list |> String.concat ""
				) !st;
			done;
			!st |> SSet.min_elt
		with Not_found -> "UNRESTORABLE"
))

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int *A = new int[n];
	for (int i = 0; i < n; i++)
		cin >> A[i];
	int count = 0;
	for(int i=0;i<n-1;i++)
		for(int j=n-1;j>i;j--)
			if (A[j] < A[j - 1])
			{
				swap(A[j], A[j - 1]);
				count++;
			}
	for (int i = 0; i < n; i++)
		if (i != n - 1)
			cout << A[i] << " ";
		else
			cout << A[i] << endl;
	cout << count << endl;
	delete[] A;
}


Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"


using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> N;
	vector<int>x(N);
	vector<int>y(N);
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		x[i] = L - R;
		y[i] = L + R;
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	cout << max(x.back() - x.front(), y.back() - y.front()) << endl;
}

Measured memory_bytes: 4780
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0) break;
		int* s = new int[n];
		int sum = 0;
		for(int i = 0; i < n; i++){
			cin >> s[i];
			sum += s[i];
		}
		double m = static_cast<double>(sum) / n;
		double vn = 0;
		for(int i = 0; i < n; i++){
			vn += pow(s[i] - m, 2);
		}
		double v = vn / n;
		cout << fixed << setprecision(8) << sqrt(v) << endl;
	}
	return 0;
}

Measured memory_bytes: 1260
#include <cstdio>
#include <cstring>
typedef long long int64;
static const int MAXN = 5004;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS
static const int INV2 = 5e8 + 4;

int n, l;
char s[MAXN];
int64 f[MAXN][MAXN] = {{ 0 }};

int main()
{
    scanf("%d%s", &n, s);
    l = strlen(s);

    f[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= i; ++j) if (f[i][j] > 0) {
            (f[i + 1][j + 1] += f[i][j] * 2)__;
            (f[i + 1][j > 0 ? j - 1 : 0] += f[i][j])__;
        }

    int64 ans = f[n][l];
    for (int i = 0; i < l; ++i) (ans *= INV2)__;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 193792