akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 2e5 + 5 , inf = 1e13;
int a[40][40] , d;
int dis(int x , int y ){
	int ans = 0 ; 
	for ( int i = 1 ; i<=d ; i++){
		ans += ( a[x][i] - a[y][i]) * ( a[x][i] - a[y][i]) ;
	}
	return ans ;
}
signed main(){
	int n  , cnt = 0 ;
	cin >> n >> d ;
	for ( int i = 1 ; i<=n ; i++){
		for ( int j = 1 ; j<=d ; j++){
			cin >> a[i][j] ;
		}
	}

	for ( int i = 1 ; i<=n ; i++){
		for ( int j = i+1 ; j<=n ; j++){
			if( (int)sqrt(dis(i,j)) * (int)sqrt(dis(i,j)) == dis(i,j) ) cnt++ ;
		}
	}
	cout << cnt << endl ;
}

Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    let mut v: Vec<usize> = vec![0; n];
    for i in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        v[i] = s.trim().parse().unwrap();
    }
    v.sort();
    let x = v.iter().fold(0, |x, y| x + y);
    if x % 10 != 0 {println!("{}", x); return}
    for i in &v {
        if *i % 10 != 0 {println!("{}", x - *i); return}
    }
    println!("0");
}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
typedef long long lint;
#ifdef DEBUG
  #define dprint(...) fprintf(stderr, __VA_ARGS__)
#else
  #define dprint(...)
#endif

int main() {
  //blue card
  int N;
  cin >> N; string s[N];
  rep(i,N) cin >> s[i];

  //red card
  int M;
  cin >> M; string t[M];
  rep(i, M) cin >> t[i];

  int ans = 0;

  rep(i, N) {
    int point = 0;
    rep(j, N) if (s[i] == s[j]) point++;
    rep(j, M) if (s[i] == t[j]) point--;
    ans = max(ans, point);
  }

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

Measured memory_bytes: 256
H, W = map(int, input().split())
a = [input() for i in range(H)]
b = []
for i in range(H):
    if '#' in a[i]:
        b.append(a[i])
        
ans = zip(*[i for i in zip(*b) if '#' in i])
 
for j in ans:
    print(*j, sep='')

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;



int main(){
    int a, b; cin>>a >>b;
    rep(i,10200){
        if(floor(i * 0.08) == a && floor(i * 0.10) == b){
            cout<< i <<endl;
            return 0;
        }
    }
    cout<< -1 <<endl;
}


Measured memory_bytes: 3600
#include <stdio.h>
#define N 100000

int partition(int *,int,int);

int main(){
  int B[N];
  int i,j,n,A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  int  a= partition(A,0,n-1);
  
  for(i=0;i<n;i++){
    if(i>=1)printf(" ");
    if(i==a)printf("[");
    printf("%d",A[i]);
    if(i==a)printf("]");
  }printf("\n");
  return 0;
}

int partition(int A[],int p,int r){
  int tmp,j;
  int  x=A[r];
  int i = p-1; //partition ( A, p, r )　配列 A[ p..r ] 
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i++;
      tmp =A[j];
     A[j]=A[i];
     A[i]=tmp;
     }
 } tmp =A[i+1];
     A[i+1]=A[r];
     A[r]=tmp;
     return i+1;
}





Measured memory_bytes: 2248
d, n = map(int, input().split())

if d == 0:
    if n != 100:
        print(n)
    else:
        print(n + 1)
elif d == 1:
    if n != 100:
        print(n * 100)
    else:
        print(n * 100 + 100)
else:
    if n != 100:
        print(n * 10000)
    else:
        print(n * 10000 + 10000)


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

template<typename M>
struct segment_tree{
	typedef function<M(M, M)> F;
	int size;//2冪
	vector<M> val;//1-indexed
	F f;//結合関数
	M e;//単位元

	segment_tree(int N, vector<M> &data, F f, M e) : f(f), e(e){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, e);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = N; i < size; i++) val[size + i] = e;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	//k番目の要素をxに変更する
	void update(int k, M x){
		k += size;
		val[k] = x;
		while(k /= 2) val[k] = f(val[2 * k], val[2 * k + 1]);
	}

	//[l, r)の演算の結果を返す
	M query(int l, int r){
		M L = e, R = e;
		for(l += size, r += size; l < r; l /= 2, r /= 2){
			if(l & 1) L = f(L, val[l++]);
			if(r & 1) R = f(val[--r], R);
		}
		return f(L, R);
	}
};




//(int, sum, 0)
int my_or(int x, int y){
	return x | y;
}

int bit_count(int x){
	if(x == 0){
		return 0;
	}
	else{
		return (x & 1) + bit_count(x >> 1);
	}
}

int main(){
	int N, Q;
	scanf("%d", &N);
	string S;
	cin >> S;
	vector<int> data(N, 0);
	for(int i = 0; i < N; i++){
		data[i] = (1 << (S[i] - 'a'));
	}
	segment_tree<int> t(N, data, my_or, 0);
	scanf("%d", &Q);
	while(Q--){
		int type;
		scanf("%d", &type);
		if(type == 1){
			int i;
			char c;
			scanf("%d %c", &i, &c);
			i--;
			t.update(i, 1 << (c - 'a'));
		}
		else{
			int l, r;
			scanf("%d%d", &l, &r);
			l--;
			printf("%d\n", bit_count(t.query(l, r)));
		}
	}
	return 0;
}

Measured memory_bytes: 7044
#include <iostream>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0){
        cout << "Possible" << endl;
    }else if((a + b) % 3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

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

int calc(vector<int> &is_add, vector<int> &s_vec){
    int ans = 0;
    ans += s_vec[0];
    for (int i = 0; i < 3; i++)
    {
        if(is_add[i]==1)
            ans = ans + s_vec[i+1];
        else 
            ans = ans - s_vec[i+1];
    }
    //cout << ans << endl;
    return ans;
}

void print_result(vector<int> &is_add, vector<int> &s_vec){
    string s;
    s += to_string(s_vec[0]);
    for (int i = 0; i < 3; i++)
    {
        if(is_add[i]==1){
            s.push_back('+');
        } else {
            s.push_back('-');
        }
        s += to_string(s_vec[i+1]);
    }
    s += "=7";
    cout << s << endl;
}

int main() {
    string s; cin >> s;
    vector<int> s_vec(4);
    for (int i = 0; i < 4; i++)
    {
        s_vec[i] = (int) s[i] - '0';
    }
    vector<int> is_add(3);
    for (int i = 0; i < 2; i++)
    {
        is_add[0] = i;
        for (int j = 0; j < 2; j++)
        {
            is_add[1] = j;
            for (int k = 0; k < 2; k++)
            {
                is_add[2] = k;                
                if(calc(is_add, s_vec) == 7){
                    print_result(is_add, s_vec);
                    return 0;
                }
            }
        }
    }
}

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

int main(void)
{
	int i, n;
	scanf("%d", &n);
    char s[n][100];
    int t[n];
    char x[100];
    
	for(i=0; i<n; i++){
        scanf("%s%d",s[i],&t[i]);
	}
	
    scanf("%s", x);

    i = 0;
    while(i < n)
    {
        if(strcmp(s[i], x) == 0)
            break;
        i++;
    }

    int time = 0;
    while(++i < n)
    {
        time += t[i];
    }

    printf("%d", time);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e5+10;
const ll INF = 1e18;
const ll M = 998244353;

vector<int> a[MAX];

int main()
{
    ll n,k,i,j,p,q,x,y;
    cin >> n >> k;
    ll dp[n+1],h[n+1];
    for(i=0;i<=n;i++)
        dp[i] = INF;
    for(i=1;i<=n;i++)
        cin >> h[i];
    dp[1]=0;
    for(i=2;i<=n;i++)
    {
        j = i;p = 0;
        while(j>=1 and p<k)
        {
            j--;p++;
            dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
        }
    }
    //for(i=1;i<=n;i++)
        //cout << dp[i] << "\n";
    cout << dp[n];
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

int main() {

    ll s;
    cin >> s;

    ll x1 = 0, y1 = 0, x2 = 1000000000ll, y2 = 1, y3 = (s + x2 - 1) / x2, x3 = 0ll - (s - (y3 * x2));

    printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define f first
#define s second
#define mod 1000000007
#define inf 1<<30
#define mp(a,b) make_pair(a,b)
#define len(u,N) u.begin(),u.begin()+N

ll N;
vector<ll> a(100010);
vector<ll> ctl(100010);

int main() {
    cin >> N;
    rep(i,N) cin >> a[i];
    rep(i,N){
        ctl[a[i]]++;
        ctl[a[i]+1]++;
        ctl[a[i]+2]++;
    }
    ll res = 0;
    rep(i,100010){
        res = max(res,ctl[i]);
    }
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int maxn=10000+9;
int main(){
	int n;
	int a;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;++i){
		cin>>a;
		while((a&1)==0){
			ans+=1;
			a>>=1;
		}
	}
	printf("%d",ans);
	return 0;
}


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

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

using namespace std;


// data
struct Node
{
    Node()
    {
        parent = -1;
        depth = 0;
    }
    int parent;
    vector<int> children;
    int depth;
};
vector<Node> tree;

void calDepth(int id){
    int iid = id;
    while (tree[iid].parent != -1)
    {
        tree[id].depth++;

        iid = tree[iid].parent; 
    }
}

int main(){
    int n;
    cin >> n;
    tree.resize(n);

    rep(i, n){
        int id, childNum, childId;
        cin >> id >> childNum;
        rep(j, childNum){
            cin >> childId;

            tree[id].children.push_back(childId);
            tree[childId].parent = id;
        }
    }
    
    rep(i, n){
        calDepth(i);
    }

    rep(i, n){
        printf("node %d: parent = %d, depth = %d, ",
            i, tree[i].parent, tree[i].depth
        );
        
        if(tree[i].parent == -1)
            cout << "root, ";
        else if (tree[i].children.size() > 0)
            cout << "internal node, ";
        else
            cout << "leaf, ";

        cout << "[";
        int cnum = tree[i].children.size();
        rep(j, cnum)
            cout << tree[i].children[j] << (j < cnum-1?", ":"");
        cout << "]\n";
    }

}


Measured memory_bytes: 7536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N+1,0);
    vector<int> C(N+1,0);
    rep(i, N) {
        cin >> A[i];
    }
    rep(i,N){
        B[i+1]=max(A[i],B[i]);//i番目より左にあるもののなかで一番大きいもの
        C[N-i-1]=max(C[N-i],A[N-i]);
    }
    rep(i,N)cout<<max(B[i],C[i])<<endl;
}

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

otoshidama = 0
for i in range(N):
	x[i][0] = float(x[i][0])
	if x[i][1] == "BTC":
		x[i][0] = x[i][0] * 380000.0
	otoshidama += x[i][0]

print(otoshidama)

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

int N;
const int MAX_N = 200000;
int A[MAX_N], B[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int A_in;
        cin >> A_in;
        B[i] = - A_in + (i+1);
    }

    sort(B, B+N);

    int b;
    if (N % 2 == 0) b = B[N/2];
    else b = B[N/2];

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(B[i] - b);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Control.Monad.State

main :: IO ()
main = do
  [w, h] <- map read <$> words <$> getLine
  unless (w == 0 && h == 0) $ do
    solve w h >>= printPos
    main

solve :: Int -> Int -> IO Status
solve w h = evalStateT (walk w h) ((1, 1), N)

walk :: Int -> Int -> StateT Status IO Status
walk w h = do
  st <- get
  cs <- lift $ words <$> getLine
  case cs of
   ["FORWARD", sd] -> do
     put $ forward w h (read sd) st
     walk w h
   ["BACKWARD", sd] -> do
     put $ backward w h (read sd) st
     walk w h
   ["RIGHT"] -> do
     put $ right st
     walk w h
   ["LEFT"] -> do
     put $ left st
     walk w h
   _ -> return st
   
type Status = ((Int,Int), Dir)

data Dir = N | E | S | W

right :: Status -> Status
right (p, N) = (p, E)
right (p, E) = (p, S)
right (p, S) = (p, W)
right (p, W) = (p, N)

left :: Status -> Status
left = right . right . right

forward :: Int -> Int -> Int -> Status -> Status
forward w h d ((i, j), N) = ((i, min (j+d) h), N)
forward w h d ((i, j), E) = ((min (i+d) w, j), E)
forward w h d ((i, j), S) = ((i, max (j-d) 1), S)
forward w h d ((i, j), W) = ((max (i-d) 1, j), W)

backward :: Int -> Int -> Int -> Status -> Status
backward w h d (p, N) = let (p', _) = forward w h d (p, S) in (p', N)
backward w h d (p, E) = let (p', _) = forward w h d (p, W) in (p', E)
backward w h d (p, S) = let (p', _) = forward w h d (p, N) in (p', S)
backward w h d (p, W) = let (p', _) = forward w h d (p, E) in (p', W)

printPos :: Status -> IO ()
printPos ((i,j), _) = putStrLn . unwords . map show $ [i, j]



Measured memory_bytes: 4128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int min =Integer.MAX_VALUE;
		for (int a =1;a<=N/2;a++) {
			int b = N-a;
			char c[]= String.valueOf(a).toCharArray();
			char d[]= String.valueOf(b).toCharArray();
			int sum =0;
			for (int i=0;i<c.length;i++) {
				sum +=c[i]-'0';
			}
			for (int i=0;i<d.length;i++) {
				sum +=d[i]-'0';
			}
			if (min>sum) {
				min =sum;
			}
		}
		System.out.println(min);
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(z->parent == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
      if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 25156
/* 
 * Author: pawanmsr
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //

// Functions //

// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    int s, w;
    cin >> s >> w;
    if (s > w) cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}


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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	string s, t;
	cin >> s >> t;
	int n = s.size();

	int cnt = 0;

	REP(i, n)
		if (s[i] != t[i])
			cnt++;

	cout << cnt << '\n';
	return 0;
}

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

int main() {
    int N;
    std::cin >> N;

    std::vector<std::pair<int, int>> v(N);
    for (int i = 0; i < N; i++) {
        int A, B;
        std::cin >> A >> B;
        v[i] = std::make_pair(B, A);
    }

    std::sort(v.begin(), v.end());

    long long t = 0;
    for (int i = 0; i < N; i++) {
        t += v[i].second;
        if (v[i].first < t) {
            std::cout << "No\n";
            return 0;
        }
    }
    std::cout << "Yes\n";
}

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

void fnInput(int &a_riElementCnt, vector<int> &a_rviElement, 
             int &a_riTargetCnt , vector<int> &a_rviTarget )
{
  cin >> a_riElementCnt;

  a_rviElement.resize(a_riElementCnt);
  for (int i = 0; i < a_riElementCnt; i++)
    cin >> a_rviElement[i];

  cin >> a_riTargetCnt;

  a_rviTarget.resize(a_riTargetCnt);
  for (int i = 0; i < a_riTargetCnt; i++)
    cin >> a_rviTarget[i];
}

int fnRcsSearch(int a_iPos, const vector<int> &a_cnrviElement, int a_iTarget)
{
  if (!a_iTarget)  return 1;
  if (++a_iPos == a_cnrviElement.size())  return 0;
  
  int iRtn0 = fnRcsSearch(a_iPos, a_cnrviElement, a_iTarget);
  if (iRtn0)  return iRtn0;

  int iRtn1 = fnRcsSearch(a_iPos, a_cnrviElement, a_iTarget - a_cnrviElement[a_iPos]);
  return iRtn1;
}

void fnExhSearch(const vector<int> &a_cnrviElement, const vector<int> &a_cnrviTarget)
{
  for (int i = 0; i < a_cnrviTarget.size(); i++)
  {
    int iTarget = a_cnrviTarget[i];
    int iPos, iRtn0, iRtn1;
    iPos = 0;

    if (fnRcsSearch(iPos, a_cnrviElement, iTarget))
    {
      cout << "yes" << endl;
      continue;
    }

    if (fnRcsSearch(iPos, a_cnrviElement, iTarget - a_cnrviElement[iPos]))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}

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

  int iElementCnt, iTargetCnt;
  vector<int> viElement, viTarget;

  fnInput(iElementCnt, viElement, iTargetCnt, viTarget);
  fnExhSearch(viElement, viTarget);

  return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;

int n, k;
int card[10];
bool b[10];
set<string>ans;
void solve(string sum, int rest) {
	if (!rest) {
		ans.insert(sum);
		return;
	}
	for (int i = 0; i < n; i++) {
		if (!b[i]){
			b[i] = true;
			solve(sum + to_string(card[i]), rest - 1);
			b[i] = false;
		}
	}
}
int main(){
	while (scanf("%d%d", &n, &k), n){
		ans.clear();
		memset(b, 0, sizeof(b));
		for (int i = 0; i < n; i++)
			scanf("%d", &card[i]);
		solve("\0", k);
		printf("%d\n", ans.size());
	}
	return 0;
}

Measured memory_bytes: 3512
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

typedef long long ll;

using namespace std;

int main(){

    ll n;
    cin>>n;
    vector<ll> a1,a2;
    for(ll i=0;i<n;i++){
        ll b;
        cin>>b;
        a1.push_back(b);
    }
    for(ll i=0;i<n;i++){
        ll b;
        cin>>b;
        a2.push_back(b);
    }

    vector<ll> sum1(n+1,0),sum2(n+1,0);
    for(ll i=0;i<n;i++){
        sum1[i+1]=sum1[i]+a1[i];
        sum2[i+1]=sum2[i]+a2[i];
    }

    vector<ll> candy;
    for(ll i=0;i<n+1;i++){
        candy.push_back(sum1[i]+(sum2[n]-sum2[i-1]));
    }

    sort(candy.begin(),candy.end());

    cout<<candy[n]<<endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    ll r = 1;
    double t = 1;
    int b = 0;

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

        if (a == 0) {
            cout << 0 << endl;
            exit(0);
        }

        if (b) continue;
        r *= a;
        t *= a;
        if (t > 2e+18) b = 1;
    }

    if (r > (ll)1e+18) b = 1;
    cout << (b ? -1 : r) << endl;

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
	db w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << fixed << setprecision(2);
	cout << w * h / 2 << " " << (w / 2 == x && h / 2 == y ? 1 : 0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNext()) {
			train_calc();
		}

	}

	private static void train_calc() {
		String[] strs = sc.nextLine().split(",");
		int[] l_i = new int[10];
		double l_sum = 0.0;
		int v_1 = Integer.parseInt(strs[10]);
		int v_2 = Integer.parseInt(strs[11]);

			for (int i = 0; i < 10; i++) {
				l_i[i] = Integer.parseInt(strs[i]);
				l_sum += l_i[i];
			}

		double t = l_sum / ( v_1 + v_2 );
		double d = v_1 * t;
		int index = 0;

			for (int i = 0; d > 0; i++) {
				d -= l_i[i];
				index = i + 1;
			}

		System.out.println(index);

	}

}



Measured memory_bytes: 25736
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        s: String
    }
    let ymd: Vec<i32> = s.split("/").flat_map(|x| x.parse()).collect();
    let mut iter = ymd.iter();
    let answer;
    match *iter.next().unwrap() {
        y if y < 2019 => answer = "Heisei",
        y if y > 2019 => answer = "TBD",
        _ => match *iter.next().unwrap() {
            m if m < 4 => answer = "Heisei",
            m if m > 4 => answer = "TBD",
            _ => match *iter.next().unwrap() {
                d if d <= 30 => answer = "Heisei",
                _ => answer = "TBD",
            }
        }
    }
    println!("{}", answer);
}


Measured memory_bytes: 4352
#include<stdio.h>
char a[109];
int main(){
	int n;
	int n1 = 0,n2 = 0;
	scanf("%d",&n);	getchar();
	for(int i = 0;i<n;i++){
		scanf("%c",&a[i]);
	}
	for(int i = 0;i<n;i++){
		if(a[i]=='('){
			n1++;
		}
		else if(a[i]==')'){
			n2++;
			if(a[i]==')'&&n1>0){
				n1--;
				n2--;
			}	
		} 
	}
	for(int i = 0;i<n2;i++){
		printf("(");
	}
	for(int i = 0;i<n;i++){
		printf("%c",a[i]);
	}
	for(int i = 0;i<n1;i++){
		printf(")");
	}
	printf("\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int N = 1000000+10;

vector<int>prime_table(N);

void sieve(){
    rep(i, N)   prime_table[i] = i;
    prime_table[0] = -1;
    prime_table[1] = -1;
    for(int i = 2; i*i < N; i++){
        if(prime_table[i] == i) for(int j = 2; i*j<N; j++)  prime_table[i*j] = i;
    }
}

bool pair_check(vector<int>a){
    sieve();
    map<int, int>m;
    rep(i, a.size()){
        while(a[i] != 1){
            int tmp = prime_table[a[i]];
            m[tmp]++;
            while(tmp == prime_table[a[i]]) a[i] = a[i]/prime_table[a[i]];
        }
    }
    rep(i, N){
        if(m[i] > 1)    return false;
    }
    return true;
}

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

bool set_check(vector<int>a){
    int tmp = gcd(a[0], a[1]);
    for(int i = 2; i < a.size(); i++){
        tmp = gcd(tmp, a[i]);
    }
    if(tmp == 1)    return true;
    else            return false;
}

int main(){
    int n;  cin >> n;
    vector<int>a(n);
    rep(i, n)   cin >> a[i];
    if(pair_check(a)){
        puts("pairwise coprime");
    }else if(set_check(a)){
        puts("setwise coprime");
    }else{
        puts("not coprime");
    }
}


Measured memory_bytes: 61696
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif


const int mxn=1e5+1;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll t=1;
  //cin>>t;
    while(t--){
            ll n,x,i,ans,d;
    cin>>n>>d;
    ans=0;
    fr(i,0,n)
    {
        cin>>x;
        ans=__gcd(ans,abs(x-d));
    }
    cout<<ans;

    }
  return 0;
  }



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

int main()
{
	int x, y;
	int S[] = { 0,1,3,1,2,1,2,1,1,2,1,2,1, };
	cin >> x >> y;
	if (S[x] == S[y])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(10);

	ll n;
	cin >> n;
	ll ga, sa, ba;
	cin >> ga >> sa >> ba;
	ll gb, sb, bb;
	cin >> gb >> sb >> bb;

	if (ga>gb && sa>sb && ba>bb) {
		swap(ga,gb);
		swap(sa,sb);
		swap(ba,bb);
	}

	ll res = 0;
	for (ll i=0; i<=n; i+=ga) {
		for (ll j=0; i+j<=n; j+=sa) {
			ll k = ((n-i-j)/ba) * ba;
			if (ba>bb) k = 0;
			res = max(res, i/ga*gb + j/sa*sb + k/ba*bb + n-i-j-k);
		}
	}
	n = res;

	swap(ga,gb);
	swap(sa,sb);
	swap(ba,bb);
	while (ga<gb) {
		swap(ga,sa);
		swap(gb,sb);
		swap(sa,ba);
		swap(sb,bb);
	}

	res = 0;
	for (ll i=0; i<=n; i+=sa) {
		ll j = ((n-i)/ba) * ba;
		if (ba>bb) j = 0;
		res = max(res, i/sa*sb + j/ba*bb + n-i-j);
	}
	cout << res << nl;

	return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
 
# define x first    
# define y second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector         
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  
 
using namespace std;
 
typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;
 
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int n;
       
int a[Sz], b[Sz];
                   
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n;      
  for (int i = 1; i <= n; i++) {
    int x; cin >> x;
    a[x] = b[x] = i;
  }
  int ptr = 1;                     
  for (int i = 1; i <= n*n; i++) {
    if (a[i]) {  
      for (int j = 1; j < b[i]; j++) {
        while (a[ptr] && ptr < i)
          ptr++;
        if (ptr >= i) {
          cout << "No"; return 0;
        }    
        a[ptr] = b[i];
      }
    }
  }
  ptr = n * n;
  for (int i = n*n; i >= 1; i--) {
    if (b[i]) {
      for (int j = 1; j <= n - b[i]; j++) {
        while (a[ptr] && ptr >= i)
          ptr--;
        if (ptr < i) {
          cout << "No"; return 0;
        }
        a[ptr] = b[i];
      }
    }
  }                

  cout << "Yes" << endl; 
  for (int i = 1; i <= n*n; i++)
    cout << a[i] << ' ';         
 
 
  return 0;
}
 
 
 
 
 
 
// Coded by Z..

Measured memory_bytes: 3968
N, M = map(int, input().split())
H = list(map(int, input().split()))
bad_towers = set()
for _ in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        bad_towers.add(B)
    elif H[A-1] < H[B-1]:
        bad_towers.add(A)
    else:
        bad_towers.add(A)
        bad_towers.add(B)
print(N - len(bad_towers))


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

int main() {
  int N;
  cin >> N;
  bool judge = false;
  while (N > 0) {
    if (N % 10 == 7) {
      judge = true;
    }
    N /= 10;
  }
  
  if (judge)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3624
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define endl '\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define ls t[root << 1]
#define rs t[root << 1 | 1]
#define tr t[root]
#define lowbit(x) x &(-x)
#define all(x) (x).begin(), (x).end()
#define sf(x) scanf("%d", &x)
#define pf(x) printf("%d", x)
#define debug(x) cout << x << endl
#define mod(x) (x % mod + mod) % mod

template <typename T>
void read(T &x)
{
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch))
    {
        if (ch == '-')
            f *= -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}

const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 5e5 + 7;
const int maxm = 1e3 + 7;
const int mod = 1e9 + 7;

#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    int d,t,s;
    cin>>d>>t>>s;
    if (d<=t*s)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3624
use proconio::input;
use proconio::marker::Usize1;
use std::collections::BinaryHeap;
use std::cmp::Reverse;
fn main() {
    input! {
        n: usize,
        es: [(Usize1, Usize1, usize); n-1],
        q: usize, k: Usize1,
        qs: [(Usize1, Usize1); q]
    };
    let mut edges: Vec<Vec<(usize, usize)>> = vec![Vec::new(); n];
    for (a,b,c) in es {
        edges[a].push((b,c));
        edges[b].push((a,c));
    }
    let inf = std::usize::MAX;
    let mut d = vec![inf; n];
    let mut heap = BinaryHeap::new();
    d[k] = 0;
    heap.push(Reverse((0, k)));
    while  !heap.is_empty() {
        let (dist, i) = heap.pop().unwrap().0;
        if d[i] < dist {
            continue;
        }
        for &(j, w) in &edges[i] {
            if d[j] > d[i] + w {
                d[j] = d[i] + w;
                heap.push(Reverse((d[j], j)));
            }
        }
    }
    for (x,y) in qs {
        println!("{}", d[x]+d[y]);
    }
}

Measured memory_bytes: 16756
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    let n = s.len() as usize;

    let mut dp = vec![vec![0i64; 13]; n];

    for i in 0..n {
        if i == 0 {
            if s[i] == '?' {
                for j in 0..10 {
                    dp[i][j] = 1;
                }
                for j in 10..13 {
                    dp[i][j] = -1;
                }
            } else {
                let c = s[i] as usize - '0' as usize;
                for j in 0..13usize {
                    if j == c  {
                        dp[i][j] = 1;
                    } else {
                        dp[i][j] = -1;
                    }
                }
            }
        } else {
            if s[i] == '?' {
                for j in 0..10 {
                    for k in 0..13 {
                        if dp[i-1][k] != -1 {
                            dp[i][(k * 10 + j) % 13] += dp[i - 1][k]
                        }
                    }
                }
            } else {
                let c = s[i] as usize - '0' as usize;
                for k in 0..13 {
                    if dp[i-1][k] != -1 {
                        dp[i][(k * 10 + c) % 13] += dp[i - 1][k];
                    }
                }
            }
        }

        for j in 0..13 {
            dp[i][j] %= 1000000007;
            //println!("({}, {}): {}", i, j, dp[i][j]);
        }
    }
    if dp[n-1][5] == -1 {
        println!("{}", 0);
    } else {
        println!("{}", dp[n - 1][5]);
    }
}


Measured memory_bytes: 18684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		//入力データを変数で受け取る
		int n = sc.nextInt();
		int[] array = new int[n];

		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		//入力データを処理して、結果を出力
		int output = 1;
		int updown = 0;

		for(int i = 1; i < n; i++) {
			if(updown == 0) {
				if(array[i - 1] < array[i]) {
					updown = 1;
				} else if(array[i - 1] > array[i]) {
					updown = 2;
				}
			}else {
				if(array[i - 1] < array[i] && updown == 2) {
					updown = 0;
					output++;
				} else if(array[i - 1] > array[i] && updown == 1) {
					updown = 0;
					output++;
				}
			}
		}

		System.out.println(output);

	}
}

Measured memory_bytes: 59608
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll x;
  cin >> x;
  cout << !x << endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#define vi vector<int>
#define lli long long int
#define fo(i,n) for(int i=1;i<=n;i++)
#define foo(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
#define vii vector<lli>

#define ok ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#define vp vector<pair<lli,lli>>
#include <map>           
lli mod=1000000007;         


/*int main(){
  lli n,x,t;
  cin>>n>>x>>t;
  if(n%x == 0){
  	cout<<(n/x * t);
  }
  else cout<<((n/x + 1)*t);
//  cout<<(n%x==0)?(n/x * t):(n/x + 1)*t;
}*/

/*int main(){
	string s;
	cin>>s;
	lli sum=0;
	for(char c:s){
		sum+=(c-'0');
	}
	if(sum%9) cout<<"No";
	else cout<<"Yes";
}*/

int main(){
	lli n,mxx,s=0;
	cin>>n;
	vi v(n),mx(n);
	foo(i,n) cin>>v[i];
	mxx=v[0];
//	cout<<mxx;

    foo(i,n){
    	if(v[i]>mxx)
    	mxx=v[i];
    	s+=abs(mxx-v[i]);
	}

/*	for(int i=1;i<=n-1;i++)
	{
		if(v[i]>mxx)
		mx[i]=v[i],mxx=v[i];
		else mx[i]=mxx;
	}
	foo(i,n){
		s+=abs(v[i]-mx[i]);
	}*/
	
//	foo(i,n) cout<<mx[i]<<" ";
	cout<<s;
}







Measured memory_bytes: 4844
#include <cstdio>
#include <vector>
#include <algorithm>
int p[200001], N, d[200001], q[200001], D, vi[200001], sg[200001], cir[200001], L, w1[200001], w2[200001], w[200001];
std::vector < int > E[200001];
bool NiroBC(int start)
{
	w[1] = start;
	for (int i = 2; i <= L; i++)
		w[i] = w[i - 1] == w1[i] ? w2[i] : w1[i];
	return w[1] == (w[L] == w1[1] ? w2[1] : w1[1]);
}
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
	{
		scanf("%d", p + i);
		E[p[i]].push_back(i);
		d[p[i]]++;
	}
	for (int i = 1; i <= N; i++)
		if (!d[i])
			q[++D] = i;
	while (D)
	{
		int u = q[D--];
		for (int v : E[u])
			vi[sg[v]] = 1;
		while (vi[sg[u]])
			sg[u]++;
		for (int v : E[u])
			vi[sg[v]] = 0;
		if (!--d[p[u]])
			q[++D] = p[u];
	}
	for (int i = std::find(d + 1, d + N + 1, 1) - d; d[i] == 1; i = p[i])
		d[cir[++L] = i] = -1;
	for (int i = 1; i <= L; i++)
	{
		int u = cir[i];
		for (int v : E[u])
			if (d[v] != -1)
				vi[sg[v]] = 1;
		while (vi[w1[i]])
			w1[i]++;
		w2[i] = w1[i] + 1;
		while (vi[w2[i]])
			w2[i]++;
		for (int v : E[u])
			if (d[v] != -1)
				vi[sg[v]] = 0;
	}
	puts(NiroBC(w1[1]) || NiroBC(w2[1]) ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 17152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    private int N;
    private void Scan()
    {
        N=int.Parse(Console.ReadLine());
    }
    
    private bool C(long i,long j,long k)
    {
        long bunsi=(i*j+j*k+k*i);
        long bunbo=i*j*k;
        return bunsi*N>=bunbo*4;
    }
    private bool B(long i,long j,long k)
    {
        long bunsi=(i*j+j*k+k*i);
        long bunbo=i*j*k;
        return bunsi*N==bunbo*4;
    }
    
    
    private void Calc()
    {
            for(int i=1;i<=3500;i++)
            {
                for(int j=1;j<=3500;j++)
                {
                    int min=1;
                    int max=3501;
                    while(max-min>1)
                    {
                        int mid=(min+max)/2;
                        if(C(i,j,mid))
                        {
                            min=mid;
                        }
                        else
                        {
                            max=mid;
                        }
                    }
                    if(B(i,j,min))
                    {
                        //Console.WriteLine($"{4.0/N} {1.0/i+1.0/j+1.0/min}");
                        Console.WriteLine($"{i} {j} {min}");
                        return;
                    }
                }
            }
    }
    
    public void Solve()
    {
        Scan();
        Calc();
    }
    
    static void Main()
    {
        new Program().Solve();
    }
}

static class MyMath
{
    static public long GCD(long a,long b)
    {
        if(a<b)
        {
            var t=a;
            a=b;
            b=t;
        }
        while(b>0)
        {
            long r=a%b;
            a=b;
            b=r;
        }
        return a;
    }
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;


int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int H,W,h,w;cin>>H>>W>>h>>w;

  cout<<(H-h)*(W-w)<<endl;

  return 0;
}


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

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

	int n, x, cnt = 0, place = 0;
	vector<int> a;
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> x;
		a.push_back(x);
	}
	for (int i = 0; i < n; ++i){
		cnt++;
		place = a[place]-1;
		if (place == 1){
			cout << cnt << endl;
			return 0;
		}
	}
	cout << "-1" << "\n";
	return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if (L > R){
  	cout << "Left" << endl;
  }
  else if (L < R){
    cout << "Right" << endl;
  }
  else{
  	cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 3600
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		int a = in.nextInt(), b = in.nextInt();
		
		if (Math.abs(a-b)%2 == 1) out.println("IMPOSSIBLE");
		else {
			int dif = Math.abs(a-b)/2;
			out.println(Math.max(a,b)-dif);
		}
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll  n;
 	cin>>n;
 	ll temp=n;
 	ll len=0;
 	ll ml=26;
 	ll cur=0;
 	ll prev=0;
 	while(temp>0)
 	{
 		temp-=ml;
 		++len;
 		prev=cur;
 		cur+=ml;
 		ml=ml*26;
 	}
 	if(len>1)
 	{
 		n-=prev;
	}
 	n--;
 	// cout<<n<<endl;
 	string ans="";
 	for(ll i=0;i<len;i++)
 	{
 		char c = n%26+'a';
 		n/=26;
 		ans+=c;
 	}
 	reverse(ans.begin(),ans.end());
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a >> b;
	if (a + b < 10) {
		cout << a+b << "\n";
	}
	else if (a + b >= 10) {
		cout << "error" << "\n";
	}
	std::cin >> e;
}

Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int fr=0, fp=0, sr=0, sp=0;
		for (char ch : sc.next().toCharArray()) {
			switch (ch) {
				case 'g': sr++; break;
				case 'p': sp++; break;					
			}
			if (fp+1<=fr && sp<=sr) fp++;	
			else fr++;
		}
		System.out.println((fp-sp>0) ? fp-sp : 0);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 39696
#include <iostream>
#include <string>
using namespace std;
int main(){
  char a[50];
  char b[50];
  int check = 0;
  for(int i = 0; i < 50; i++){
    cin >> a[i] >> b[i];
    if(a[i] == 'L'){
      cout << "No" << endl;
      exit(0);
    }
    if(b[i] == 'R'){
      cout << "No" << endl;
      exit(0);
    }
  }
  if(check == 0){
  	cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ri register int
#define sid 105

int H, W, n, id;
int col[sid][sid], ord[sid * sid];

int main() {
    scanf("%d%d%d", &H, &W, &n);
    for(ri i = 1; i <= n; i ++) {
        int x; scanf("%d", &x);
        while(x --) ord[++ id] = i;
    }
    id = 0;
    for(ri i = 1; i <= H; i ++)
    for(ri j = 1; j <= W; j ++)
    col[i][j] = ord[++ id];
    for(ri i = 2; i <= H; i += 2)
    reverse(col[i] + 1, col[i] + W + 1);
    for(ri i = 1; i <= H; i ++, printf("\n"))
    for(ri j = 1; j <= W; j ++)
    printf("%d ", col[i][j]);
    return 0;
}

Measured memory_bytes: 384