akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

const int MAX = 200000;

int main(){
    int n, p[MAX];
    cin >> n;
    rep(i,n) cin >> p[i];

    int current_min = MAX + 10;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(p[i] <= current_min){
            ans++;
            current_min = p[i];
        }
    }

    cout << ans << endl;
}

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

int main()
{
        ll N, Y;
        cin >> N >> Y;

        for (int i = 0; i <= N; ++i) {

                for (int j = 0; j <= N; ++j) {

                        int k = N - i - j;
                        if (k < 0) continue;

                        ll sum = i * 10000 + j * 5000 + k * 1000;

                        if (sum == Y) {
                                cout << i << " " << j << " " << k << endl;
                                exit(0);
                        }


                }

        }
        cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/
void printYes(){
    cout<<"Yay!"<<endl;
    return;
}
void printNo(){
    cout<<":("<<endl;
    return;
}
/*------------------------------------*/

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

    int X,Y;
    cin>>X>>Y;
    int okane[4] = {0,300000,200000,100000};
    if(X > 3){
        X = 0;
    }
    if(Y > 3){
        Y = 0;
    }
    ll ans = okane[X] + okane[Y];
    if(X == 1&&Y==1)ans += 400000;
    cout<<ans<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i,n-1) cin >> b[i];
  
  int ans = b[0] + b[n-2];
  rep(i,n-2) ans += min(b[i],b[i+1]);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int sum = 0;
    for(int i = 1; i <= N; i++) {
        int j = i;
        int cnt = 0;
        while(j) {
            j = j / 10;
            cnt++;
        }
        if(cnt % 2 == 1) {
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn = 103;
const int inf = 1e9;

int n, m;
char t[maxn][maxn];
void read()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        cin >> t[i][j];
}

int dp[maxn][maxn];
void solve()
{
     if (t[1][1] == '#')
        dp[1][1] = 1;

     for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (i > 1 || j > 1)
        {
            dp[i][j] = inf;
            if (t[i][j] == '#')
            {
                if (i > 1)
                {
                    if (t[i-1][j] == '.')
                        dp[i][j] = min(dp[i][j], dp[i-1][j] + 1);

                    else
                        dp[i][j] = min(dp[i][j], dp[i-1][j]);
                }

                if (j > 1)
                {
                    if (t[i][j-1] == '.')
                        dp[i][j] = min(dp[i][j], dp[i][j-1] + 1);

                    else
                        dp[i][j] = min(dp[i][j], dp[i][j-1]);
                }
            }

            else
            {
                if (i > 1)
                    dp[i][j] = min(dp[i][j], dp[i-1][j]);

                if (j > 1)
                    dp[i][j] = min(dp[i][j], dp[i][j-1]);
            }
        }

    cout << dp[n][m] << endl;
}

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

    read();
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
ll bet[MAXN];
ll h[MAXN];
ll arr[MAXN];
ll tree[MAXN];
void upd(int ind, ll val){
    for(; ind <= n; ind += (ind& -ind))
        tree[ind] = max(tree[ind], val);
}
ll get(int ind){
    ll ans = 0;
    for(;ind > 0; ind -= (ind & -ind))
        ans = max(ans, tree[ind]);
    return ans;
}



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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;
    for(int i = 1; i <= n; i++){
        cin>>h[i];
    }
    for(int j = 1; j <= n; j++){
        cin>>bet[j];
    }
    for(int i = 1; i <= n; i++){
        ll mx = get(h[i] - 1);
        upd(h[i], mx + bet[i]);
    }
    cout<<get(n)<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

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

int N;
vector<int> G[100000];
int m[100000];

int flag = 0;

void dfs(int v, int p) {
	for(auto c : G[v]) {
		if(c == p) continue;
		dfs(c, v);
	}
	if(m[v] == 0) {
		m[v] = 1;
		if(p == -1 || m[p]) {
			flag = 1;
			return;
		}
		m[p] = 1;
	}
}

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

	cin >> N;
	for(int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	dfs(0, -1);

	if(flag) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}

}

Measured memory_bytes: 6272
#include<stdio.h>
 
int risi(int);
int main(void)
{
	int week,syakkin;

	scanf("%d",&week);
   
	syakkin=risi(week);
	printf("%d\n",syakkin);
	return 0;
}

int risi(int n)
{
	int amari,price;
	if(n == 0)
		return 100000;
	else 
		price = (risi(n-1)*1.05);
		amari = price % 1000;
		if(amari > 0){
			price = ((price / 1000) + 1) * 1000;
		}
		return price;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n,a,b,c,l[20],ans=1e9;
    cin>>n>>a>>b>>c;
    rep(i,n) cin>>l[i];
    rep(i,pow(4,n)){
        int p=i,A=0,B=0,C=0,m=-30,x[8];
        rep(j,n) x[j]=p%4,p=p/4;
        rep(j,n){
            if(x[j]==1) A+=l[j],m+=10;
            if(x[j]==2) B+=l[j],m+=10;
            if(x[j]==3) C+=l[j],m+=10;
        }
        if(A==0||B==0||C==0) continue;
        m+=abs(A-a)+abs(B-b)+abs(C-c);
        if(ans>m) ans=m;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

struct UnionFind {
	vector<int> par;
	UnionFind(int x) : par(x, -1) {}
	void init(int x) { par.assign(x, -1); }
	int root(int x) {
		if (par[x] <= -1) return x;
		else return root(par[x]);
	}
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	int size(int x) {
		return -par[root(x)];
	}
};
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int a[51], b[51];
    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    int ans = 0;
    rep(i, M) {
        UnionFind UF(N);
        rep(j, M) {
            if (i == j) continue;
            UF.merge(a[j], b[j]);
        }
        if(UF.size(0) != N) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
struct Point{
    double x;
    double y;
};
void koch(int,Point,Point);
int main(void){
    Point a,b;
    int n;
    cin >> n;
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;
    cout << a.x <<' ' <<  a.y << '\n';
    koch(n,a,b);
    cout << b.x << ' ' << b.y << '\n';
    return 0;
}
void koch(int n,Point a,Point b){
    if(n==0){
        return;
    }
    else{
        Point s,t,u;
        double th = M_PI * 60.0 /180.0;
        s.x = (2.0 * a.x + 1.0 *b.x) /3.0;
        s.y = (2.0 * a.y + 1.0 *b.y) /3.0;
        t.x = (1.0 * a.x + 2.0 *b.x) /3.0;
        t.y = (1.0 * a.y + 2.0 *b.y) /3.0;
        u.x = (t.x - s.x) *cos(th) - (t.y-s.y) * sin(th) + s.x;
        u.y = (t.x - s.x) *sin(th) + (t.y-s.y) * cos(th) + s.y;
        koch(n-1,a,s);
        cout << s.x << ' ' << s.y << '\n';
        koch(n-1,s,u);
        cout << u.x << ' '<< u.y << '\n';
        koch(n-1,u,t);
        cout << t.x << ' ' <<t.y << '\n';
        koch(n-1,t,b);
    }
}


Measured memory_bytes: 3288
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] t = new int[n];
		int total = 0;
		for(int i = 0; i < n; i++){
			t[i] = scanner.nextInt();
			total += t[i];
		}
		int m = scanner.nextInt();
		for(int i = 0; i < m; i++){
			int p = scanner.nextInt();
			int x = scanner.nextInt();
			int sub = t[p-1] - x;
			System.out.println(total-sub);
		}
	}
}

Measured memory_bytes: 23252
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {   //引数は挿入する値
    Node *y = NIL;    //xの親
    Node *x = root;   //Tの根
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));   //追加する値の定義。与えられた順番に追加していくので、左右の子は存在しない
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while ( x != NIL ) {   //xがNILにたどり着いた時終了、その時のyがzの親となる
        y = x;   //親の設定(=root)、zの親の候補として1つ前の節点yを保持
        if ( z->key < x->key ) {   //x->keyにはrootの値が保持
            x = x->left;   //左の子へ移動
        } else {
            x = x->right;   //右の子へ移動
        }
    }
    
    z->parent = y;
    if ( y == NIL ) {   //Tが空の場合、最初に挿入した値を根とする
        root = z;
    } else {
        if ( z->key < y->key ) {
            y->left = z;   //zをyの左の子にする
        } else {
            y->right = z;   //zをyの右の子にする 
        }
    }
}

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

//探したい値がない場合、NILを返却。あった場合はその値を返却
Node * find(Node *u, int k) {
    while ( u != NIL && k != u->key ) {
        if ( k < u->key ) u = u->left;
        else u = u->right;
    }
    return u;
}

int main() {
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ) {
        cin >> com;
        if ( com == "find" ) {
            scanf("%d", &x);
            Node *t = find(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else if ( com == "insert" ) {
            scanf("%d", &x);
            insert(x);
        } else if ( com == "print" ) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 22096
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define MAXN 507
#define mo 19930726
#define ll long long
#define int ll
using namespace std;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int n,X,D,ans,num,dp[125500];
int w[MAXN],val[MAXN],pos[MAXN],head[MAXN];
int tot,V[MAXN*MAXN],W[MAXN*MAXN],cnt;
struct po
{
	int nxt,to;
}edge[MAXN<<1];
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void add_edge(int from,int to)
{
	edge[++num].nxt=head[from];
	edge[num].to=to;
	head[from]=num;
}
void dfs(int u)
{
	val[u]=1;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		dfs(v);
		w[u]+=w[v];val[u]+=val[v];
	}
	cnt+=val[u]*n; pos[u]=u;
}
inline bool cmp(int x,int y){return val[x]*w[y]>val[y]*w[x];}
main()
{
	n=read();X=read();D=read();
	w[1]=read();
	for(re int i=2;i<=n;i++){
		w[i]=read();int x=read();
		add_edge(x,i);
	}
	dfs(1);
	sort(pos+1,pos+n+1,cmp);
	int tmp=min(n,D);
	for(re int i=1;i<=cnt;i++) dp[i]=inf;
	for(re int i=1;i<=n;i++){
		int len=1,lim=tmp;
		while(lim>=len){
			V[++tot]=len*val[pos[i]];
			W[tot]=len*w[pos[i]];
			lim-=len,len<<=1;
		}
		if(lim) V[++tot]=lim*val[pos[i]],W[tot]=lim*w[pos[i]];
	}
	for(int i=1;i<=tot;i++)
		for(int j=cnt;~j;j--){
			if(j>=V[i]) dp[j]=min(dp[j],dp[j-V[i]]+W[i]);
		}
	int ans=0;
	for(int i=0;i<=cnt;i++){
		if(dp[i]>X) continue;
		int ret=i,left=X-dp[i];
		for(int j=1;j<=n;j++){
			int tem=pos[j],used=min(max(D-n,0ll),left/w[tem]);
			if(tem==1) used=left/w[tem];
			left-=w[tem]*used;
			ret+=val[tem]*used;
		}
		ans=max(ans,ret);
	}
	cout<<ans;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  if (abs(n - m) > 1)
    cout << 0 << endl;
  else {
    ll a = 1, b = 1;
    rep(i, n) a = a * (i + 1) % MOD;
    rep(i, m) b = b * (i + 1) % MOD;
    ll ans = a * b % MOD;
    if (a == b) ans = ans * 2 % MOD;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int n = sc.nextInt();
    int[] ac = new int[w];
    for(int i=0;i<w;i++){
      ac[i]=i+1;
    }
    for(int i=0;i<n;i++){
      String s=sc.next();
      String[] ab=s.split(",");
      int a=Integer.valueOf(ab[0]);
      int b=Integer.valueOf(ab[1]);
      int temp = ac[a-1];
      ac[a-1] = ac[b-1];
      ac[b-1] = temp; 
    }
    for(int i=0;i<w;i++){
      System.out.println(ac[i]);
    }
  }
}


Measured memory_bytes: 25836
package main

import "fmt"

func main() {
	var N, from, to int
	fmt.Scan(&N)
	as := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&as[i])
	}
	to = 1
	for i := 1; i < N; i++ {
		from = to
		to = as[from-1]
		if to == 2 {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;
const int N_MAX = 100001;
const int modint = 1000000007;

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main() {
  int n, k;
  cin >> n >> k;
  ll ans = -INF;
  int p[n], c[n];
  rep(i,n)cin >> p[i];
  rep(i,n)cin >> c[i];
  rep(i,n)p[i]--;

  rep(i,n){
    int cnt = 0;
    ll total = 0;
    int v = i;
    vector<int> s;
    while(true){
      v = p[v];
      cnt++;
      s.push_back(c[v]);
      total += c[v];
      if (v == i)break;
    }

    ll tmp = 0;
    rep(j, cnt){
      tmp += s[j];
      if(j+1 > k)break;
      ll now = tmp;
      if(total >= 0){
        now += total * ((k-(j+1)) / cnt);
      }
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3700
class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if(x == y):
            return
        
        if(self.parents[x] > self.parents[y]):
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, input().split())
uf = Unionfind(N)
f = [0 for _ in range(N)]
n = [0 for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)
    
    f[a] += 1
    f[b] += 1
    
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if(uf.same(c, d)):
        n[c] += 1
        n[d] += 1
    
ans = []
for i in range(N):
    ans.append(uf.size(i)-f[i]-n[i]-1)
    
print(*ans)

Measured memory_bytes: 19024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n, temp;
    cin >> n;

    temp = n;
    int s = 0;

    while(temp > 0)
    {
        s += temp % 10;
        temp /= 10;
    }
    cout << (n%s == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, a[N], ans = 1, x;

int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    int n, c;
    cin>>n>>c;




    int a[n][2], b[c][2];


    for(int i = 0; i<n; i++)
    {
      cin>>a[i][0]>>a[i][1];
    }
    for(int i = 0; i<c; i++)
    {
      cin>>b[i][0]>>b[i][1];
    }

    


    int d ;
    int min[n] ;

    for(int i = 0; i<n; i++)
    {
        int m = INT_MAX;
        int checkpoint = -1;
      for(int j = 0; j<c; j++)
      {
  
          d = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]);
    
          if(d < m)
          {
            m = d;
            checkpoint = j+1;
          }
      }
      min[i] = checkpoint ;
    }

    for(int i =0; i<n; i++)
    cout<<min[i]<<"\n";


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;


int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	long long int  s[200][200];
	//cout << fixed << setprecision(10);
	long long int n, m, k, p, q, r, a[200005], sum[200005] = {}, dp[200005] = {}, res = 999999999;
	cin >>n>>m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		sum[a[i]]++;
	}
	dp[0] = 1;
	if (sum[1] == 0) { dp[1] = 1; }
	for (int i = 2; i <= n; i++) {
		if (sum[i] == 0) { dp[i] = dp[i - 1] + dp[i - 2]; dp[i] %= mod; }
	}
	cout << dp[n];
}


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

int main()
{
	int a, b;
	char op;
	while(1) {
		scanf("%d %c %d",&a, &op, &b);
		switch(op) {
		case '+':
			printf("%d\n", a + b);
			break;
		case '-':
			printf("%d\n", a - b);
			break;
		case '*':
			printf("%d\n", a * b);
			break;
		case '/':
			printf("%d\n", a / b);
			break;
		case '?':
		default:
			goto term;
		}
	}
term:
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n,m,X,Y;
  cin>>n>>m>>X>>Y;
  int x[n],y[m];
  rep(i,n) cin>>x[i];
  rep(i,m) cin>>y[i];
  sort(x, x + n);
  sort(y, y + m);
  int xmax = x[n-1];
  int ymin = y[0];
  bool flag = false;
  if(xmax < ymin) {
    if(xmax < Y && X < ymin) flag = true;
  }
  if(flag) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int k, n, i, min;
    scanf("%d %d", &k, &n);

    int A[2*n];
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
        A[i+n] = k + A[i];
    }
    min = (1e+6)+1;

    for (i = 0; i < n; i++) {
        if (min > A[i+n-1]-A[i]) min = A[i+n-1]-A[i];
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 3e3 + 3;
ll a[N][N];
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s, t, c;
    ll i, j;
    cin >> s >> t;
    for (i = 0; i < s.size(); i++)
        for (j = 0; j < t.size(); j++)
            if (s[i] == t[j])
                a[i + 1][j + 1] = 1 + a[i][j];
            else
                a[i + 1][j + 1] = max(a[i][j + 1], a[i + 1][j]);
    while (i && j)
    {
        if (s[i - 1] == t[j - 1])
            c += s[--i], j--;
        else if (a[i][j - 1] > a[i - 1][j])
            j--;
        else
            i--;
    }
    reverse(c.begin(), c.end());
    cout << c;
}

Measured memory_bytes: 70656
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
int main(void){

	while(1){
		bool flag=false;
		long long int t,d,l;
		long long int last=0;
		long long int first=0;
		long long int total=0;

		cin>>t>>d>>l;
		if(t==0&&d==0&&l==0){
			break;
		}
		vector<long long int> x(t+1);
		LFOR(i,1,t){
			cin>>x[i];
		}

		FOR(i,1,t){
			if(x[i]>=l){
				if(flag==false){
					first=i;
					last=i+d;
					flag=true;
				}else{
					last=i+d;
				}
			}
			if(last<=i&&flag==true){
				if(last>t){
					last=t;
				}
				total+=last-first;
				flag=false;
			}
		}

		if(flag){
			total+=t-first;
		}

		cout<<total<<endl;


	}

}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int n,m,c; cin>>n>>m>>c;
        vi b(m);
        rep(i,m)cin>>b[i];
        int ans=0;
        rep(i,n)
        {
                int t=c;
                int a;
                rep(i,m)
                {
                        cin>>a;
                        t+=a*b[i];
                }
                ans+=t>0;
        }
        cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
const ll INF = 1e18 +9;

void solve(){
	string a,b;
	cin >> a  >> b;
	vector<vector<ll>> hash((ll)a.size()+1,vector<ll> ((ll)b.size()+1,0));
	for(int i = 1;i<=(ll)a.size();++i)
	{
		for(int j = 1;j<=(ll)b.size();++j)
		{
			if(a[i-1]==b[j-1])
				hash[i][j] = hash[i-1][j-1]+1;
			else
				hash[i][j] = max(hash[i][j-1],hash[i-1][j]);
		}
	}
	int i = a.size();
	int j = b.size();
	string q = "";
	while(i != 0 && j != 0)
	{
		if(hash[i][j] == hash[i][j-1])
		{
			j--;
		}
		else if(hash[i][j] == hash[i-1][j])
		{
			i--;
		}
		else
		{
			q+=a[i-1];
			i--;
			j--;
		}
	}
	reverse(q.begin(),q.end());
	cout << q << ' ';
}
int main() {
    int t = 1;
    while(t--) solve();
}


Measured memory_bytes: 70784
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int n; scanf("%d", &n);
    int map[100100] = {0};
    for (int i = 0; i < n; ++i) {
        int a; scanf("%d", &a);
        ++map[a];
        if (a > 0) ++map[a + 1];
        if (a < 100100) ++map[a - 1];
    }

    int ans = 0;
    for (int i = 0; i < 100100; ++i) ans = max(ans, map[i]);

    printf("%d\n", ans);

    return 0;
}

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

int main(){
    int n,A,B,total;
    cin>>n>>A>>B;
    total = 0;
    string s;
    cin>>s;
    int b = 0;
    for(int i=0;i<n;i++){
        if(s[i] == 'c' || total >= A+B ){
            cout<<"No"<<endl;
        }else if(s[i] == 'b' && b >= B){
            cout<<"No"<<endl;
        }else if(s[i] == 'b'){
            cout<<"Yes"<<endl;
            total++;
            b++;
        }else{
            cout<<"Yes"<<endl;
            total++;
        }
    }
}


Measured memory_bytes: 3692
n, k = map(int, input().split())
a = list(map(int, input().split()))
m, f = 0, 0
for i in range(40, -1, -1):
  _sum = sum(map(lambda x: (x >> i) & 1, a))
  _min = min(_sum, n-_sum) << i
  _max = max(_sum, n-_sum) << i
  s = 0 if _sum > n//2 else 1 << i
  if s > max(k - m, 0):
    f += _min
  elif s > 0:
    m += s
    f += _max
  else:
    f += _max
print(f)

Measured memory_bytes: 14620
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main(void) {
	int r, d, x = 2000;
	cin >> r >> d>>x;
	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
char a[101][101];

void solveTest(){
	int h,w;
	cin>>h>>w;
	for(int i=0;i<=h+1;i++){
		for(int j=0;j<=w+1;j++){
			a[i][j] = '#'; 
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			char x;
			cin>>x;
			a[i][j] = x;
		}
	}
	for(int i=0;i<=h+1;i++){
		for(int j=0;j<=w+1;j++){
			cout<<a[i][j];	
		}
		cout<<endl;
	}
	
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll ans;
int a[5];
int main() {
	int n;
	cin>>n;
	int a,b,c;
	for(int i=n; i<=999; i++) {
		a=i%10;
		b=i/10%10;
		c=i/100;
		if(a==b&&b==c){
			cout<<i<<endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	string s,t;
	
	cin>>s>>t;
	int n=t.size();
	
	
	if(t.substr(0,n-1)==s)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
 } 

Measured memory_bytes: 3592
n = int(input())
h = list(map(int, input().split()))

dp = [0 for i in range(n)] 
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[n - 1])


Measured memory_bytes: 13928
import Data.List (permutations)

data ExprTree = Node Char ExprTree ExprTree
              | Leaf Int

main = do
    ns <- (map read . words) `fmap` getLine
    if all (==0) ns then return () else do
        putStrLn (solve ns)
        main

solve :: [Int] -> String
solve ns = toString' $ maybeHead $ filter equals10 $
            concatMap exprTrees $ permutations ns
    where
    toString' Nothing = "0"
    toString' (Just t) = toString t

    maybeHead [] = Nothing
    maybeHead (x:xs) = Just x

    equals10 t = evaluate t == 10

exprTrees :: [Int] -> [ExprTree]
exprTrees [n] = [Leaf n]
exprTrees ns = concatMap exprTrees' [1..(length ns - 1)]
    where exprTrees' p = [Node op left right|
                            let (nsLeft,nsRight) = splitAt p ns,
                            op <- ['+','-','*'],
                            left <- exprTrees nsLeft,
                            right <- exprTrees nsRight]

evaluate :: ExprTree -> Int
evaluate (Leaf value) = value
evaluate (Node '+' left right) = (evaluate left) + (evaluate right)
evaluate (Node '-' left right) = (evaluate left) - (evaluate right)
evaluate (Node '*' left right) = (evaluate left) * (evaluate right)

toString :: ExprTree -> String
toString (Leaf value) = show value
toString (Node op left right) =
    "(" ++ (toString left) ++ [' ',op,' '] ++ (toString right) ++ ")"

Measured memory_bytes: 4160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

//C

int main(void) {
	string s, t;
	cin >> s >> t;
	string ans = string(s.length(), 'z');
	bool existAnswer = false;
	rep(0, s.length()) {
		int index = i;
		for (int j = 0; j < t.length(); j++) {
			char si = s[index];
			char tj = t[j];
			if (si == '?' || si == tj) {
				index++;
				if (j == t.length() - 1) {
					string candidate = s;
					index = i;
					for (int k = 0; k < t.length(); k++) {
						candidate[index] = t[k];
						index++;
					}
					for (int l = 0; l < candidate.length(); l++) {
						if (candidate[l] == '?') candidate[l] = 'a';
					}
					if (ans > candidate)ans = candidate;
					existAnswer = true;
				}
			}
			else break;
		}
	}
	if(existAnswer) cout << ans << endl;
	else cout << "UNRESTORABLE" << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
#define f(n) for(long long int i=0;i<n;i++)
#define g(n) for(long long int j=0;j<n;j++)
#define ff(a,n) for(long long int i=a;i<n;i++)
#define gg(a,n) for(long long int j=a;j<n;j++)
#define t(a) long long int a;cin>>a
#define test(te) t(te); while(te--)
#define all(a) a.begin(),a.end()
#define ent "\n"
#define pri(a,n) f(n){cout<<a[i]<<" ";}cout<<ent
#define cas(i) "Case #"<<i+1<<": "
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007  
#define ll long long 
#define lli long long int
#define op std::ios_base::sync_with_stdio(false);cin.tie(NULL)
//using namespace boost::multiprecision;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
int main(int argc, char const *argv[])
{
	t(a);
	long double b=1.0;
	cin>>b;
	b*=a;
	cout<<(lli)b;

	return 0;
}
/*
int main(int argc, char const *argv[])
{
    op;
    t(n);
    lli ans=1;
    bool flag=true;
    f(n)
    {
    	t(a);
    	ans*=a;
    	if(ans>1000000000000000000 || ans<0)
    	{
    		flag=false;
    		break;
    	}
    }
    if(!flag)
    	ans=-1;
    cout<<ans;
    return 0;
}*/

Measured memory_bytes: 3732
N = int(input())
A = [int(_) for _ in input().split()]

absmin = float('inf')
minusnum = 0
ans = 0

for i in A:
    ans += abs(i)
    if abs(i) < absmin:
        absmin = abs(i)
    if i < 0:
        minusnum += 1

if minusnum % 2 == 0:
    print(ans)
else:
    print(ans - 2*absmin)

Measured memory_bytes: 14284
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll a, b, d;
int main() {
    while(cin>>a>>b>>d, a||b||d){
        ll x=inf, y=inf, sum=inf;

        REP(i, 0, 50001){
            if((i*a+d)%b == 0){
                ll xx=i, yy=(i*a+d)/b;
                if(xx+yy < x+y || (xx+yy == x+y && a*xx+b*yy < sum)){
                    x=xx;
                    y=yy;
                    sum=a*x+b*y;
                }
            }

            if((i*b+d)%a == 0){
                ll yy=i, xx=(i*b+d)/a;
                if(xx+yy < x+y || (xx+yy == x+y && a*xx+b*yy < sum)){
                    x=xx;
                    y=yy;
                    sum=a*x+b*y;
                }
            }

            if((d-i*a)%b==0){
                ll xx=i, yy=(d-i*a)/b;
                if(xx<0 || yy<0) continue;

                if(xx+yy < x+y || (xx+yy == x+y && a*xx+b*yy < sum)){
                    x=xx;
                    y=yy;
                    sum=a*x+b*y;
                }
            }

        }

        cout<<x<<" "<<y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
typedef long long int ll;
typedef pair<int, int> P;
 
const long long INF = 3e18 + 12;
const int inf = 1e9;
 
int calcNumOfCombination(int n, int r) {
  double num = 1;
  for (int i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}
int main() {
  int a, b;
  cin >> a >> b;
 
  int c = 0;
  if (a >= 2 && b >= 2) {
    c = calcNumOfCombination(a, 2) + calcNumOfCombination(b, 2);
  } else if (a >= 2 && b < 2) {
    c = calcNumOfCombination(a, 2);
  } else if (a < 2 && b >= 2) {
    c = calcNumOfCombination(b, 2);
  }
  cout << c << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    int n; cin >> n;
    int ans = 0;
    int xors[n+5];
    for(int i = 0; i < n ; i++){
        cin >> xors[i];
        ans ^= xors[i];
    }
    for(int i = 0; i < n; i++){
        int x = ans^xors[i];
        cout << x << " ";
    }
    
}
//new line is printed in main()

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        // printf("\n");
    }
    return 0;
}


Measured memory_bytes: 4344
#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;

/*Node treeMinimum(Node x){
  

}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



  }*/

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(y == NIL)root = z;
    else if(z->key < y->key)y->left = z;
    else y->right = z;

   
}

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

void preorder(Node u){
  int i=0;
 if(u != NIL){
   printf(" ");
   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] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      } else*/ if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } /*else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }*/
  }

  return 0;
}




Measured memory_bytes: 25152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n,m;
  cin>>n>>m;
  vector<int>h(n),a(m),b(m),d(n,1);
  rep(i,n) cin>>h[i];
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
  }
  rep(i,m){
    if(h[a[i]]<h[b[i]])
      d[a[i]]=0;
    else if(h[a[i]]>h[b[i]])
      d[b[i]]=0;
    else{
      d[a[i]]=0;d[b[i]]=0;
    }
  }
  int ans=0;
  rep(i,n){
    if(d[i])
      ans++;
  }
  cout<<ans<<endl;
}

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


int main() {

	std::priority_queue<int> vprices;
	int N;
	int price;
	int sum = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> price;
		vprices.push(price);
	}

	for (int i = 0; i < N; i++) {
		price = vprices.top();
		if (i == 0) {
			price /= 2;
		}
		sum += price;
		vprices.pop();
	}

	   
	cout << sum << endl;


	return 0;

}


Measured memory_bytes: 256
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#include<unordered_map>
#define FR first
#define SC second
#define MP make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline int pow(int a,int b,int c)
{
    if (a==0)return 0;
	b=(b%(c-1)+c-1)%(c-1);
	int d=1;
    while (b)
    {
        if (b&1) d=(1LL*d*a)%c;
        a=1LL*a*a%c;b>>=1;
    }
    return d;
}
inline void read(int &x)
{
	char ch;
	while ((ch=getchar())<=32);
	x=ch-48;
	while ((ch=getchar())>32) x=x*10+ch-48;
}
inline int random(int n) { return 1LL*rand()*rand()%n+1;}
//-------------template------------
const int N=200010,M=600000,p=1000000007,inf=100000000;
const int inv2=(p+1)/2;
inline void up(int &x,int y) { x+=y;if (x>=p) x-=p;if (x<0) x+=p;}
struct Edge{int y,ne;};
int n;
int a[N];
//void add(int x,int y) { e[++num]=(Edge){y,last[x]};last[x]=num;}
int main()
{
	scanf("%d",&n);
	LL ans=0;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=n;i>=1;i--)
	{
		if (a[i]>=i) { ans=-1;break;}
		if (i<n&&a[i]<a[i+1]-1) { ans=-1;break;}
		if (i==n||a[i]+1!=a[i+1]) ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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

vector<bool> p(100002, true);

int main(){
  int q;
  cin >> q;
  vector<int> l(q), r(q);
  rep(i, q) cin >> l[i] >> r[i];
  p[0] = false;
  p[1] = false;
  for(int i = 2; i <= 100001; ++i){
    if(p[i]){
      for(int j = i + i; j <= 100001; j += i){
        p[j] = false;
      }
    }
  }
  p[2] = true;

  vector<int> s(100003, 0);
  s[0] = 0;
  for(int i = 0; i <= 100000; ++i){
    s[i] = s[i - 1];
    if(p[i] && p[(i + 1) / 2]){
      s[i]++;
    }
  }

  for(int i = 0; i < q; ++i){
    int ans = s[r[i]] - s[l[i] - 1];

    cout << ans << endl;
   }


}


Measured memory_bytes: 1792
use std::io;

fn main() {
    let mut ab = String::new();
    io::stdin().read_line(&mut ab).unwrap();
    let mut ab = ab.split_whitespace();
    let a: u32 = ab.next().unwrap().parse().unwrap();
    let b: u32 = ab.next().unwrap().parse().unwrap();

    let mut cnt = 0;

    for i in 1..a {
        for j in 1..32 {
            if i == j {
                cnt += 1;
            }
        }

    }

    if a <= b {
        cnt += 1;
    }

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

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

int main(){
  string s;
  cin>>s;

  string tmpa,tmpb;
  int ans=0,len=0;
  len=s.length();
  
  do{
    s.erase(len-2);
    len=s.length();
    tmpa=s.substr(0,len/2);
    tmpb=s.substr(len/2,len/2);
  }while(tmpa!=tmpb);
  
  cout<<len<<endl;
  
  return 0;
}

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

class Main {

	static Node[] node = null;
	static StringBuilder pre = new StringBuilder();
	static StringBuilder in = new StringBuilder();
	static StringBuilder post = new StringBuilder();

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		node = new Node[n];

		for (int i=0; i<n; i++) {
			node[i] = new Node();
		}

		for (int i=0; i<n; i++) {
			String line = br.readLine();
			String[] str = line.split(" ");
			int id = Integer.parseInt(str[0]);
			int left = Integer.parseInt(str[1]);
			int right = Integer.parseInt(str[2]);
			node[i].id = i;
			if (left != -1 && right != -1) {
				node[id].degree = 2;
				node[id].left = node[right].sibling = left;
				node[id].right = node[left].sibling = right;
				node[left].parent = node[right].parent = id;
				node[id].type = "internal node";
			}else if (left != -1) {
				node[id].degree = 1;
				node[id].left = left;
				node[id].right = node[left].sibling = -1;
				node[left].parent = id;
				node[id].type = "internal node";
			}else if (right != -1) {
				node[id].degree = 1;
				node[id].right = right;
				node[id].left = node[right].sibling = -1;
				node[right].parent = id;
				node[id].type = "internal node";
			}else {
				node[id].degree = 0;
				node[id].left = node[id].right = -1;
				node[id].type = "leaf";
			}
		}

		for (int i=0; i<n; i++) {
			if (node[i].parent == -1) {
				setDH(node[i],0);
				node[i].type = "root";
				node[i].sibling = -1;
				Preorder(node[i]);
				Inorder(node[i]);
				Postorder(node[i]);
				break;
			}
		}

		System.out.println("Preorder");
		System.out.println(pre);
		System.out.println("Inorder");
		System.out.println(in);
		System.out.println("Postorder");
		System.out.println(post);

		br.close();
	}

	static int setDH(Node nd,int depth){
		nd.depth = depth;
		if (nd.left != -1 && nd.right != -1) {
			int lh = setDH(node[nd.left],depth+1);
			int rh = setDH(node[nd.right],depth+1);
			nd.height = lh > rh ? lh : rh;
		}else if (nd.left != -1) {
			nd.height = setDH(node[nd.left],depth+1);
		}else if (nd.right != -1) {
			nd.height = setDH(node[nd.right],depth+1);
		}else {
			nd.height = 0;
		}
		return nd.height+1;
	}

	static void Preorder(Node nd) {
		pre.append(" ").append(nd.id);
		if (nd.left != -1)
			Preorder(node[nd.left]);
		if (nd.right != -1)
			Preorder(node[nd.right]);
	}

	static void Inorder(Node nd) {
		if (nd.left != -1)
			Inorder(node[nd.left]);
		in.append(" ").append(nd.id);
		if (nd.right != -1)
			Inorder(node[nd.right]);
	}

	static void Postorder(Node nd) {
		if (nd.left != -1)
			Postorder(node[nd.left]);
		if (nd.right != -1)
			Postorder(node[nd.right]);
		post.append(" ").append(nd.id);
	}

	static class Node{
		int id;
		int parent = -1;
		int sibling;
		int degree;
		int depth;
		int height;
		String type;
		int right;
		int left;
	}
}

Measured memory_bytes: 17052