akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**5)

def main():
    N,M = map(int,input().split())
    use = [False for _ in range(N)]
    formula = 0
    
    I = [i for i in range(N)]
    rank = [1 for _ in range(N)]
    def root(x):
        if x == I[x]:
            return x
        I[x] = root(I[x])
        return I[x]
    
    def unite(x,y):
        px,py = root(x),root(y)
        rx,ry = rank[px],rank[py]
        if rx > ry:
            I[py] = px
        else:
            I[px] = py
            if rx == ry:
                rank[py] += 1

    for i in range(M):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        px,py = root(x),root(y)
        if px == py:
            continue
        else:
            unite(x,y)
            formula += 1

    print(N-formula)

if __name__ == "__main__":
    main()

Measured memory_bytes: 8600
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int arr[200000]={};
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int x=0;
    for(int i=0;i<n;i++){
        x^=arr[i];
    }
    for(int i=0;i<n;i++){
        cout<<(x^arr[i])<<' ';
    }

    return 0;

}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***



Measured memory_bytes: 4396
#[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 v = read_vec::<u32>();
    let m = v[0];
    let d = v[1];

    let mut count = 0;
    for i in 1..m+1 {
        for j in 1..d+1 {
            if j >= 10 {
                let a = j % 10;
                let b = j / 10;

                if a >= 2 && b >= 2 && a * b == i {
                    count += 1;
                }
            }
        }
    }
    println!("{}", count);
}


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

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

signed main(){
	int N, A, i, j, ans = 0;
	scanf("%lld", &N);
	vector<int> Anum(0);
	for(i = 0; i < N; i++){
		scanf("%lld", &A);
		while(Anum.size() <= A) Anum.push_back(0);
		Anum[A]++;
	}
	int Amax = Anum.size();
	vector<int> inv(Amax, 1);
	for(i = 2; i < Amax; i++) inv[i] = MOD(-(p / i) * inv[p % i]);
	vector<int> B(Amax, 0);
	for(i = Amax - 1; i >= 1; i--){
		for(j = i; j < Amax; j += i) B[i] += j * Anum[j];
		B[i] = MOD(B[i]) * MOD(B[i]);
		for(j = 2 * i; j < Amax; j += i) B[i] -= B[j];
		ans = MOD(ans + MOD(B[i]) * inv[i] - Anum[i] * i);
	}
	printf("%lld\n", MOD(ans * inv[2]));
	return 0;
}

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

#define N 100010

int main(){
   int n,m,h[N],ma[N];
   
   cin>>n>>m;
   
   for(int i=1;i<=n;i++){
      cin>>h[i];
	  ma[i]=0;
   }
   
   for(int i=0;i<m;i++){
      int a,b;
	  cin>>a>>b;
	  ma[a]=max(ma[a],h[b]);
	  ma[b]=max(ma[b],h[a]);
   }
   
   int ans=0;
   for(int i=1;i<=n;i++){
      ans += h[i]>ma[i];
   }
   
   cout<<ans<<endl;
   return 0;
}
 

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

int main() {
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if (a+b > c+d)
    cout << "Left" << endl;
  else if (a+b == c+d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int a, b;
	cin>>a>>b;
	if(a%2==1 && b%2==1){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  bool ans = false;
  for (int i = 0; i <= N - 1; i++){
    long long ub = D * i - C * (N - 1 - i);
    long long lb = C * i - D * (N - 1 - i);
    if (A + lb <= B && B <= A + ub){
      ans = true;
    }
  }
  if (ans){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  int a[26];fill(a,a+26,0);
  for(int i=0;i<h;i++){
    string s;cin>>s;
    for(int j=0;j<w;j++)a[s[j]-'a']++;
  }
  if(w==1||h==1){
    for(int i=0;i<max(h,w)/2;i++){
      int r=0;
      for(int j=0;j<26;j++){
        if(a[j]>=2){
          a[j]-=2;
          r=1;
          break;
        }
      }
      if(r==0){
        cout<<"No"<<endl;
        return 0;
      }
    }
    cout<<"Yes"<<endl;
    return 0;
  }
  for(int i=0;i<(h/2)*(w/2);i++){
    int c=0;
    for(int j=0;j<26;j++){
      if(a[j]>=4){
        a[j]-=4;
        c=1;
        break;
      }
    }
    if(c==0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  if(h%2==0&&w%2==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(h%2==0||w%2==0){
    if(h%2==1)swap(h,w);
    for(int i=0;i<h/2;i++){
      int cc=0;
      for(int j=0;j<26;j++){
        if(a[j]>=2){
          a[j]-=2;
          cc=1;
          break;
        }
      }
      if(cc==0){
        cout<<"No"<<endl;
        return 0;
      }
    }
    cout<<"Yes"<<endl;
    return 0;
  }
  for(int i=0;i<w/2;i++){
    int d=0;
    for(int j=0;j<26;j++){
      if(a[j]>=2){
        a[j]-=2;
        d=1;
        break;
      }
    }
    if(d==0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  for(int i=0;i<h/2;i++){
    int d=0;
    for(int j=0;j<26;j++){
      if(a[j]>=2){
        a[j]-=2;
        d=1;
        break;
      }
    }
    if(d==0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}
  

    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int main() {
     string s;
     string t;
     cin >> s >> t;
     
     int m = s.length();
     int n = t.length();
     int dp[m+5][n+5];
     for(int i=0;i<=m;i++){
          for(int j=0;j<=n;j++){
               if(i==0 || j==0){
                    dp[i][j]=0;
                    continue;
               }
               if(s[i-1]==t[j-1]){
                    dp[i][j] =  dp[i-1][j-1]+1;
               }else{
                    dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
               }
          }
     }
     // cout << dp[s.length()][t.length()];
     int i = s.length(), j = t.length();
     char ans[dp[i][j] + 1];
     ans[dp[i][j]] = '\0';
     
     int k = dp[s.length()][t.length()] - 1;
     while (i >= 0 && j >= 0)
     {
          if(dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
               ans[k--] = s[i-1];
               i--;
               j--;
          }else if (dp[i][j] == dp[i-1][j]){
               i--; 
          }
          else{ 
               j--;
          }
     }
     cout << ans << endl;
}


Measured memory_bytes: 38836
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;

static ll a[110][110], b[110][110], c[110][110];

int main(int argc, char **argv)
{
	ll n, m, l, i, j, k;
	const char *sp;
	scanf("%d %d %d", &n, &m, &l);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			scanf("%d", &b[i][j]);
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			for (k = 0; k < m; k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	for (i = 0; i < n; i++) {
		sp = "";
		for (j = 0; j < l; j++) {
			printf("%s%ld", sp, c[i][j]);
			sp = " ";
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    string S;
    cin >> S;
    REP(i,S.size()-1){
        if(S[i]==S[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    REP(i,S.size()-2){
        if(S[i]==S[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}   


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer x;
  for(x = nil->next;x!=nil;x=x->next){
  if(x->key==key)return x;
  }
  return NULL;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){


  t->next->prev=t->prev;
  t->prev->next=t->next;

  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if (t==nil)return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t=listSearch(key);
  if(t==NULL)return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;


}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 33116
#include<iostream>
#include<cstdio>
#include<cstring>
int i,j,n,m;
bool s[101][101];
char t[101][101];
main(){
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++){
            std::cin>>t[i][j];
            if(t[i][j]=='#')s[i][j]=1;
        }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(t[i][j]=='#'){
                printf("#");
                continue;
            }
            printf("%d",s[i-1][j-1]+s[i-1][j]+s[i-1][j+1]+s[i][j-1]+s[i][j+1]+s[i+1][j-1]+s[i+1][j]+s[i+1][j+1]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static int counter;

  public static void main(String[] args) {
    Scanner scanInt = new Scanner(System.in);
    int N = scanInt.nextInt();
    int i;
    for(i = 0; i < N; i++){
      prime(scanInt.nextInt());
    }
    System.out.println(counter);
  }

  public static void prime(int num){
    int mini_c = 0;
    for(int j=2; j <= Math.sqrt(num); j++){
      if(num % j == 0) mini_c++;
    }
    if(mini_c == 0) counter++;
  }
}







Measured memory_bytes: 43008
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    long long A[N];
    for (int i = 0; i < N; i++) cin >> A[i];
    string S;
    cin >> S;
    int ans = 0;
    vector<long long> bases;
    for (int i = N - 1; i >= 0; i--) {
      for (auto b : bases) A[i] = min(A[i], A[i] ^ b);
      if (A[i]) {
        if (S[i] == '1') {
          ans = 1;
          break;
        }
        bases.push_back(A[i]);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
class Solution
{
    static void Main(String[] args)
    {
 
        var s = Console.ReadLine().Split();
        var n = Convert.ToInt32(s[0]);
        var m = Convert.ToInt32(s[1]);
        Console.WriteLine(((n*(n-1))/2)+((m*(m-1))/2));
        
 
 
 
 
 
 
    }
 
}

Measured memory_bytes: 11220
n,k=map(int,input().split())
cnt=[0]*100001

for i in range(n):
    ai,bi=map(int,input().split())
    cnt[ai]+=bi
    
for ans in range(1,len(cnt)):
    if cnt[ans]>=k:
        print(ans)
        break
    k-=cnt[ans]

Measured memory_bytes: 5744
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    vector<int> A(N);
    REP(i,N){
        cin>>A[i];
    }    
    int now;
    now=A[0];
    REP1(i,N-1){
        now=gcd(A[i],now);
    }
    cout<<now<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
using ll=long long;

const int N_MAX=(100001);
ll a[N_MAX],b[N_MAX],N,H,amax,ct;

int main(){
    cin>>N>>H;
    for(int i=0;i<N;i++){
        cin>>a[i]>>b[i];
    }
    sort(a,a+N,greater<ll>());
    sort(b,b+N,greater<ll>());

    amax=a[0];
    ct=0;
    for(int i=0;((b[i]>amax)&&(H>0))&&i<N;i++){
        H-=b[i];
        ct++;
    }
    //cout<<ct<<" "<<H<<endl;
    if(H>0){
        ct+=((H+amax-1)/amax);

    }
    //ct+=max(0LL, (H + amax - 1) / amax);

    cout<<ct<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int cnt;
pair<string,int> t[1000];
int main(){
  for(cnt=0;cin>>t[cnt].first>>t[cnt].second;cnt++);
  sort(t,t+cnt);
  cout<<t[0].first<<endl<<t[0].second;
  for(int i=1;i<cnt;i++){
    if(t[i-1].first==t[i].first)cout<<' '<<t[i].second;
    else cout<<endl<<t[i].first<<endl<<t[i].second;
  }
  cout<<endl;
  return 0;
}

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

int main(void)
{
  char s[105];
  int n, cnt = 0;
  scanf("%s", s);
  n = strlen(s);
  
  for (int i = 0; i < n/2; i++)
    if (s[i] != s[n-i-1])
      cnt++;
  
  printf("%d", cnt);
  
  return 0;
}


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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

int H,W;
vt<vc> board(1001, vc(1001));
int dp[1001][1001];


bool isSafe(int i,int j) {
    return i>=1 && i<=H && j>=1 && j<=W && board[i][j]=='.';
}

int go(int i,int j) {
    if (i == H and j == W) {
        return 1;
    }
    
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    
    int ans = 0;
    if (isSafe(i,j+1)) {
        ans = (ans%mod + go(i,j+1)%mod)%mod;
    }
    if (isSafe(i+1,j)) {
        ans = (ans%mod + go(i+1,j)%mod)%mod;
    }
    
    return dp[i][j] = ans;
}

void solve() {
    cin>>H>>W;
    rep (i,1,H+1) {
        rep (j,1,W+1) {
            cin>>board[i][j];
        }
    }
    memset(dp, -1, sizeof dp);
    int ans = go(1,1);
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}

Measured memory_bytes: 12604
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

ll trinum(ll n){
	return n*(n+1)/2;
}
void Main()
{
	ll X;
  	cin >> X;
    ll n = 1;
    while(1){
		if(trinum(n-1) < X && trinum(n) >= X){break; }
        else{ n++; }
    }
    
	cout << n << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi = vector<int>;
using vl= vector<ll>;
using vs=vector<string>;

ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a);}
ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}
ll power(ll a,ll b) {ll i,p=1; for(i=0;i<b;i++){p*=a;} return p;}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    for(int p=0;p<testcase;p++){
	ll n=0;
	cin>>n;
	ll k=0;
cin>>k;
ll array[n]={0};
for(ll i=0;i<n;i++){
cin>>array[i];
}
sort(array,array+n);
ll sum=0;
for(int i=0;i<k;i++){
sum+=array[i];
}
cout<<sum;
        }

    return 0;
}


Measured memory_bytes: 3680
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<usize>()[0];
    let line = read_as_vec::<u64>();
    let (a, b) = (line[0], line[1]);
    let p =  read_as_vec::<u64>();

    let p1 = p.iter().filter(|x| **x <= a).count();
    let p2 = p.iter().filter(|x| a < **x && **x <= b).count();
    let p3 = p.iter().filter(|x| b < **x).count();

    println!("{}", cmp::min(cmp::min(p1, p2), p3));
}


Measured memory_bytes: 4352
//In the name of God
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5 + 10 , LG = 22;
int n , q , l , x[N] , sp[N][LG];

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        for(int i=0 ; i < n ; i++)
                cin >> x[i];
        cin >> l;
        for(int i=0 ; i < n ; i++)
                sp[i][0] = upper_bound(x , x + n , x[i] + l) - x - 1;
        for(int j=1 ; j < LG ; j++)
                for(int i=0 ; i < n ; i++)
                        sp[i][j] = sp[sp[i][j-1]][j-1];
        cin >> q;
        while(q--){
                int a , b;
                cin >> a >> b;
                if(a > b)
                        swap(a , b);
                a-- , b--;
                int res = 0;
                for(int i=LG-1 ; ~i ; --i)
                        if(sp[a][i] < b)
                                a = sp[a][i] , res |= (1<<i);
                cout << ++res << '\n';
        }
        return 0;
}


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

int main() {
  int N, A, B, ans;
  cin >> N >> A >> B;
  ans = N * A;
  if (ans >= B) {
  cout << B << endl;
  }  
  else if (ans <= B) {
    cout << ans << endl;
  }
  else {
    cout << ans << endl;
  }
}


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

int main()
{
    long long N, M, K;
    cin >> N >> M >> K;
    long long A[N], B[M];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }
    long long a[N + 1], b[M];
    a[0] = 0;
    b[0] = B[0];
    for (int i = 0; i < N; i++)
    {
        a[i + 1] = a[i] + A[i];
    }
    for (int i = 1; i < M; i++)
    {
        b[i] = b[i - 1] + B[i];
    }
    int max_book = 0;
    for (int i = 0; i <= N; i++)
    {
        long long t_book = K - a[i];
        if (t_book < 0)
            continue;
        int up = upper_bound(b, b + M, t_book) - b;
        max_book = max(max_book, i + up);
    }
    cout << max_book << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<string> S(N);
    REP(i,N) cin >> S[i];

    int M; cin >> M;
    vector<string> T(M);
    REP(i,M) cin >> T[i];

    int ans = 0;
    REP(i,N){
        int cnt = 0;
        REP(j,N){
            if(S[i] == S[j]) cnt++;
        }
        REP(j,M){
            if(S[i] == T[j]) cnt--;
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>

#define CHAR_TO_LOWER(c) {if(c>='A' && c<='Z') c+='a'-'A';}
#define STR_TO_LOWER(s) {for(auto& c : s)CHAR_TO_LOWER(c)}

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

    std::string w;
    std::cin >> w;
    STR_TO_LOWER(w);
    int cnt = 0;
    while(true){
        std::string t;
        std::cin >> t;
        if(t=="END_OF_TEXT") break;
        STR_TO_LOWER(t);
        if(t==w) ++cnt;
    }
    std::cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
LL h,w;
int main() {
  ios::sync_with_stdio(false);
  cin>>h>>w;
  if(h==1){
    return cout<<1,0;
  }
  if(w==1){
    return cout<<1,0;
  }
  swap(h,w);
  LL a=h/2+(h&1);
  cout<<1ll*(w/2)*(a+h/2)+(w&1?a:0);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
	    int length = scanner.nextInt();
		int A[] = new int[length];
        for(int i = 0; i < length; i++)
        	A[i] = scanner.nextInt();
   
        out_put(A);
		int key=1000;
		for (int j = 1; j < length; j++) {
			key = A[j];
			int l = j - 1;
			while (l >= 0 && A[l] > key) {
				A[l + 1] = A[l];
				l--;
			}
			A[l + 1] = key;
			out_put(A);
		}
		
	}
	private static void out_put(int A[]){
		 
        System.out.printf("%d", A[0]);
 
        for(int i = 1; i < A.length; i++){
            System.out.printf(" %d", A[i]);
        }
        System.out.printf("\n");
    }

}



Measured memory_bytes: 40864
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            var main = new Program();
            main.solve();
        }

        void solve()
        {
            int[] nm = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray();
            int n = nm[0];
            int m = nm[1];

            int[] As = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray();
            int sum = As.Sum();
            int count = 0;
            for(int i = 0;i < As.Length;i++)
            {
                if (As[i] >=((double) sum / (double)(4*m))) count++;
            }
            Console.WriteLine(count >= m ? "Yes" : "No");
        }
    }

    struct Vector2
    {
        public Vector2(long x, long y)
        {
            this.x = x;
            this.y = y;
        }
        public long x;
        public long y;
    }

    struct Vector3
    {
        public int x;
        public int y;
        public int z;
    }
}


Measured memory_bytes: 11348
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt();
    int x = -1;
    int y = -1;
    int z = -1;
    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N - i; j++) {
        int k = N - i - j;
        int total = 10000 * i + 5000 * j + 1000 * k;
        if (total == Y) {
          x = i;
          y = j;
          z = k;
        }
      }
    }
    System.out.println(x + " " + y + " " + z);
  }
}

Measured memory_bytes: 23892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()	
	{	
		string[] args = Console.ReadLine().Split(' ');
		int ab = Int32.Parse(args[0] + args[1]);

		int sqrt = (int)Math.Sqrt(ab);
		Console.WriteLine(((ab % sqrt) == 0) ? "Yes" : "No");
	}
}





Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc162_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();
      var ans = Enumerable.Range(1, N).Where(e => e % 3 != 0 && e % 5 != 0).Sum(e => (long)e);
      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 28444
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;
typedef long double Double;

typedef complex<Double> P;
struct C {
  P p; Double r;
  C(const P &p, Double r) : p(p), r(r) { }
  C() {}
};
bool p1(const C &a, const C &b) {
  return a.p.real() != b.p.real() ? a.p.real() < b.p.real() : a.p.imag() < b.p.imag();
}
bool p2(const C &a, const C &b) {
  return a.p.imag() != b.p.imag() ? a.p.imag() < b.p.imag() : a.p.real() < b.p.real();
}

C circle[100000];
Double minR;

Double solve(int s, int t) {
  if (s+1>=t) return INF;
  Double m1 = solve(s, (s+t)/2);
  Double m2 = solve((s+t)/2, t);
  Double mid = (circle[(s+t)/2-1].p.real() + circle[(s+t)/2].p.real()) / 2;
  Double d = min(m1, m2) + 2*minR+1;
  int start = lower_bound(circle+s, circle+t, C(P(mid-d, -INF), 0), p1) - circle;
  int end = upper_bound(circle+s, circle+t, C(P(mid+d, INF), 0), p1) - circle;
  vector<C> v;
  //cout << s << " " <<t << endl;
  for (int i=start; i<end; ++i) {
    v.push_back(circle[i]);
    //cout << circle[i].p << endl;
  }
  sort(ALL(v), p2);
  Double res = min(m1, m2);
  for (int i=0; i<v.size(); ++i) {
    for (int k=i+1; k<v.size() && (v[k].p.imag()-v[i].p.imag())<d; ++k) {
      res = min(res, abs(v[k].p-v[i].p)-v[k].r-v[i].r);
    }
  }
  //cout << res << endl;
  return res;
}

int main() {
  int n;
  while(cin>>n,n) {
    minR = INF;
    REP(i,n) {
      Double x, y, r;
      cin >> r >> x >> y;
      circle[i] = C(P(x,y),r);
      minR = min(minR, r);
    }
    sort(circle, circle+n, p1);
    printf("%.6Lf\n", solve(0, n));
  }
}

Measured memory_bytes: 8168
main(n,h,w){
  scanf("%d%d%d",&n,&h,&w);
  int a[1001],b[1001];
  int i,s=0;
  for(i=0;i<n;i++){
    scanf("%d%d",&a[i],&b[i]);
    if((a[i]>=h)&&(b[i]>=w))s++;
  }
  printf("%d",s);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout <<H * W -  (h * W + w * H - h * w) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).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;}



int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<P> py;
    map<int, map<int, int>> mmp;
    rep(i,m){
        int p,y;cin>>p>>y;
        py.push_back({p,y});
        mmp[p][y] = -1;
    }
    for(auto a : mmp){
        int idx = 1;
        for(auto b : a.second){
            mmp[a.first][b.first] = idx;
            idx++;
        }
    }
    for(auto a : py){
        printf("%06d", a.first);
        printf("%06d", mmp[a.first][a.second]);
        printf("\n");
    }
}

Measured memory_bytes: 16372
use proconio::*;
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        K: usize,
    }
    let mut ans = 0;
    for i in 1..K + 1 {
        for j in 1..K + 1 {
            for k in 1..K + 1 {
                ans += gcd3(i, j, k);
            }
        }
    }
    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
    if a < b {
        return gcd(b, a);
    }
    let (mut a, mut b) = (a, b);
    let mut r: usize;
    while a % b != 0 {
        r = a % b;
        a = b;
        b = r;
    }
    b
}

fn gcd3(a: usize, b: usize, c: usize) -> usize {
    gcd(gcd(a, b), c)
}


Measured memory_bytes: 2168
import bisect

A, B, Q = map(int, input().split())

INF = 10 ** 18
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]

for i in range(Q):
  x = int(input())
  b = bisect.bisect_right(s, x)
  d = bisect.bisect_right(t, x)
  dist = INF
  for sb in [s[b - 1], s[b]]:
    for td in [t[d - 1], t[d]]:
      d1, d2 = abs(x - sb) + abs(sb - td), abs(x - td) + abs(td - sb)
      dist = min(dist, d1, d2)
  print(dist)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n,m,d;
	int ans = 0;
	vector<int> ds;
	cin >> d;
	if(d == 0 ) break;
	cin >> n >> m;
	ds.PB(0);
	ds.PB(d);
	REP(i,n-1){
	    int temp;
	    cin >> temp;
	    ds.PB(temp);
	    ds.PB(temp+d);
	}
	sort(ALL(ds));
	REP(i,m){
	    int t;
	    cin >> t;
	    int p1 = lower_bound(ALL(ds),t) - ds.begin();
	    if(p1 > 0 && abs(ds[p1]-t) > abs(ds[p1-1]-t)) p1 -= 1;
	    /*
	    if(ds[p1] < t){
		ans += min(t-ds[p1],d+ds[p1]-t);
	    }else{
		ans += min(d+t-ds[p1],ds[p1]-t);
	    }
	    */
	    ans += abs(t-ds[p1]);
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  map<char,int>mp;
  vector<int>A(0);
  for(int X=0;X<S.size();X++){
    mp[S[X]]++;
  }
  for(auto p:mp){
    auto V=p.second;
    A.push_back(V);
  }
  if(A.size()==2&&A[0]==2&&A[1]==2){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '

int main() {
    vvi data(3001, vi(2));
    int rowlength = 0;
    F(i, 0, 3001){
        F(j, 0, 2){
            cin >> data[i][j];
        }
        if(data[i][0] == 0 && data[i][1] == 0) {
            rowlength = i;
            break;
        }
        if(data[i][0] > data[i][1]){
            swap(data[i][0], data[i][1]);
        }
    }

    F(i, 0, rowlength){
            cout << data[i][0] << space << data[i][1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3180
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	ans := ""
	tl := len(t)
	for i := 0; i <= len(s)-tl; i++ {
		for j := 0; j < tl; j++ {
			if s[i+j] != byte('?') && s[i+j] != t[j] {
				break
			} else if j == tl-1 {
				ans = s[:i] + t + s[i+tl:]
			}
		}
	}
	if ans == "" {
		fmt.Println("UNRESTORABLE")
	} else {
		ans = strings.Replace(ans, "?", "a", -1)
		fmt.Println(ans)
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  int Alice,Bob=0;
  for(int i = 0;i<N;i++){
    if(i%2 == 0){
      Alice += A.at(i);
    }else{
      Bob += A.at(i);
    }
  } 
  cout << Alice-Bob << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int n = in.ni();
    int[] result = new int[n + 1];
    for (int i = 2; i <= n; i++) {
      int next = in.ni();
      result[next]++;
    }
    for (int i = 1; i <= n; i++) {
      out.println(result[i]);
    }
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 55588
#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <math.h>
using namespace std;


int  main(){
  int n;
  cin>>n;
  int data[200000];
  for(int i=0;i<n;i++){
    scanf("%d",&data[i]);
  }
  int ans,mindata;

  ans=data[1]-data[0];
  mindata=min(data[0],data[1]);

  for(int i=2;i<n;i++){
    ans=max(ans,data[i]-mindata);
    mindata=min(mindata,data[i]);
  }

  cout<<ans<<endl;
  

  

  return 0;
}



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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF       numeric_limits<int>::max()
#define NINF      numeric_limits<int>::min()
#define MOD       1000000007

using namespace std;
using Int = long long;

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

    string w;
    std::cin >> w;

    vector<int> table(27, 0);
    REP(i, w.size()) {
        table[w[i] - 'a']++;
    }

    bool is_beautiful = true;
    for(const auto& v : table) {
        if(v % 2 == 1) {
            is_beautiful = false;
            break;
        }
    }

    if(is_beautiful) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
    fastio();

    int a, b;
    cin >> a >> b;
    if(a >= b){
    	for(int i = 0; i < a; ++i)
    		cout << b;
    }
    else if(a < b){
    	for(int i = 0; i < b; ++i)
    		cout << a;
    }

    return 0;
}

/*

*/

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

bool check(vector<int>&a , int n,int k,int sum,int m){
  if(k==n){
    if(sum==m)return true;
    else return false;
  }
  bool bl=check(a,n,k+1,sum,m);
  if(bl)return true;
  sum+=a[k];
  bool bm=check(a,n,k+1,sum,m);
  return bm;
}

int main() {
  int n,q;
  cin >>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  cin >>q;
  for(int i=0;i<q;i++){
    int m;
    cin>>m;
    if(check(a,n,0,0,m))cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3108
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DKnight solver = new DKnight();
        solver.solve(1, in, out);
        out.close();
    }

    static class DKnight {
        static final int mod = (int) 1e9 + 7;

        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            if ((x % 3 == 0 && y % 3 == 0) || (x % 3 == 1 && y % 3 == 2) || (x % 3 == 2 && y % 3 == 1)) {
                int need1 = 0;
                int need2 = 0;
                for (int i = 0; i <= x; i++) {
                    int rest = x - i;
                    if (rest % 2 == 0) {
                        int need = rest / 2;
                        if (i * 2 + need == y) {
                            need1 = i;
                            need2 = need;
                            break;
                        }
                    }
                }
                if (need1 == 0 && need2 == 0) {
                    out.println(0);
                    return;
                }
                long[] fact = new long[2000001];
                fact[0] = 1;
                for (int i = 1; i < 2000001; i++) {
                    fact[i] = (fact[i - 1] * i) % mod;
                }
                out.println((fact[need1 + need2] * (pow((fact[need1] * fact[need2]) % mod, mod - 2, mod))) % mod);
            } else {
                out.println(0);
            }
        }

        static int pow(long x, long y, int p) {
            long res = 1;
            x = x % p;

            while (y > 0) {
                if ((y & 1) == 1)
                    res = (res * x) % p;
                y = y >> 1;
                x = (x * x) % p;
            }
            return (int) res;
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 39508
#include<stdio.h>
int main(void)
{
    int i,a[5],b[5],c,d;
	char mise[5]={'A','B','C','D','E'};
	while(1){
	    c=0;
		scanf("%d %d",&a[0],&b[0]);
	    if(a[0]==0&&b[0]==0) break;
		for(i=1;i<5;i++){
		    scanf("%d %d",&a[i],&b[i]);
		}
		for(i=0;i<5;i++){
		    if(c<a[i]+b[i]){
			    c=a[i]+b[i];
				d=i;
			}
		}
		printf("%c %d\n",mise[d],c);
	}
	return 0;
}

Measured memory_bytes: 2672