akhauriyash/Code-Regression huggingface dataset:
import queue

def solve():
    h, w = map(int, input().split())

    block = '#'*(w+2)
    field = [block]
    field.extend(['#' + input() + '#' for _ in range(h)])
    field.append(block)

    dist = [[h*w*100 for i in range(w+1)] for j in range(h+1)]
    dist[1][1] = 1

    q = queue.Queue()
    q.put((1,1))

    while not q.empty() :
        (x,y) = q.get()
        nd = dist[x][y] + 1
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if field[nx][ny] == '.' and dist[nx][ny] > nd :
                dist[nx][ny] = nd
                q.put((nx,ny))

    if dist[h][w] >= h*w :
        return -1

    ans = h*w - dist[h][w]
    for v in field:
        ans -= v.count('#') - 2
    ans += w*2
    return ans

print(solve())


Measured memory_bytes: 4080
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin>>N;
  int P[100]={};
  for(int i=0;i<N;i++){
      int T;
      cin>>T;
      P[i]=T;
  }
  int M;
  cin>>M;
  int sum=0;
  int A;
  for(int i=0;i<M;i++){
      int Q,X;
      cin>>Q>>X;
      A=P[Q-1];
      P[Q-1]=X;
      for(int j=0;j<N;j++){
          sum+=P[j];
      }
      cout<<sum<<endl;
      P[Q-1]=A;
      sum=0;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
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();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int X;
  cin>>X;
  for(int i=179; i>=1; --i){
    if(360%i==0 && X%i==0){
      co(360/i);
      return 0;
    }
  }
}

Measured memory_bytes: 3632
// Problem : C - management
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;


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

    long n;
    cin >> n;
    vector<long> count(n+1, 0);
    for (long i = 1; i < n; i++) {
        long a;
        cin >> a;
        count[a]++;
    }
    for (long i = 1; i <= n; i++) cout << count[i] << "\n";
    
    return 0;
}


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

using namespace std;

int main()
{
	int A, B;

	cin >> A;
	cin >> B;

	if ((A*B) % 2 == 1) {
		cout << "Odd";
	}
	else {
		cout << "Even";
	}

	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include <climits>
using namespace std;
char s[10];
int main() {
    cin >> s;
    string ans;
    for(int i=0; i<10; ++i){
       if(s[i] == '0' || s[i] == '1'){
           ans += s[i];
       }
       if(s[i] == 'B' && ans.size() != 0){
            ans.pop_back();
       }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(H)]

ans = []

for i in range(H):
    for j in range(W):
        if a[i][j] % 2 == 1:
            if j < W-1:
                a[i][j+1] += 1
                a[i][j] -= 1
                ans.append((i, j, i, j+1))
            elif i < H-1:
                a[i+1][j] += 1
                a[i][j] -=1
                ans.append((i, j, i+1, j))  

print(len(ans))
for i, j, ni, nj in ans:
    print(i+1, j+1 , ni+1, nj+1)

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

void sort( int* a )
{
    for( int i = 0; i < 9; i++ )
        for( int j = i + 1; j < 10; j++ )
            if( a[i] < a[j] )
            {
                int x = a[i];
                a[i] = a[j];
                a[j] = x;
            }    
}

int main()
{
    int a[10], b[10];

    for( int i = 0; i < 10; i++ )
        cin >> a[i];
    
    for( int i = 0; i < 10; i++ )
        cin >> b[i];
    
    sort(a);
    sort(b);

    cout << a[0] + a[1] + a[2] << " " << b[0] + b[1] + b[2] << endl;
    return 0;
}


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

// C - Tax Increase
int main() {
    int A, B;
    cin >> A >> B;

    int X = B * 10;
    int result = -1;
    int tmp;
    for (int i = X; i <= X + 10; i++) {
        // cout << i << " : "; // debug
        tmp = i * 0.1;
        // cout << tmp << ", "; // debug
        if (tmp != B) break;
        tmp = i * 0.08;
        // cout << tmp << ", " << endl; // debug
        if (tmp == A) {
            result = i;
            break;
        }
    }
    cout << result;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			int[] a = new int[m];
			int[] b = new int[m];
			int[] c = new int[n];
			
			for(int i=0;i<n;i++) c[i] = i+1;
			for(int i=0;i<m;i++){
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
			}
			
			boolean flag, check;
			int temp;
			int rec = 0;
			while(true){
				flag = false;
				for(int i=0;i<m;i++){
					check = false;
					for(int j=0;j<n;j++){
						if(c[j]==b[i]){
							check = true;
							rec = j;
						}else if(c[j]==a[i]){
							if(check==true){
								temp = c[rec];
								c[rec] = c[j];
								c[j] = temp;
								flag = true;
							}
							break;
						}
					}
				}
				if(flag==false) break;
			}
			
			for(int i=0;i<n;i++) System.out.println(c[i]);
		}	
	}	
}

Measured memory_bytes: 18492
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define REP(i,n) for(ULL i=0, i##_len=(n); i<i##_len; ++i)

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <LL MOD=1000000007> class MODLL {
public:
  LL x;
  MODLL(const LL _x) : x(_x % MOD) {};
  MODLL operator+(const MODLL rhs) const { return MODLL(*this) += rhs; }
  MODLL operator-(const MODLL rhs) const { return MODLL(*this) -= rhs; }
  MODLL operator*(const MODLL rhs) const { return MODLL(*this) *= rhs; }
  MODLL operator/(const MODLL rhs) const { return MODLL(*this) /= rhs; }
  MODLL& operator+=(const MODLL rhs) { x += rhs.x; x %= MOD; return *this; }
  MODLL& operator-=(const MODLL rhs) { x -= rhs.x; x %= MOD; if(x<0) x += MOD; return *this; }
  MODLL& operator*=(const MODLL rhs) { x *= rhs.x; x %= MOD; return *this; }
  MODLL inv() const {
    if(x == 0) { throw "does not have inverse"; }
    LL a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return MODLL(u);
  }
  MODLL& operator/=(const MODLL rhs) { (*this) *= rhs.inv(); return *this; }
  MODLL pow(ULL n) const {
    MODLL res = 1;
    MODLL a = x;
    while (n > 0) {
      if (n & 1) res *= a;
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef MODLL<> ML;


void test() {
  {
    ML x = 3;
    assert(x.pow(45).x == 644897553);
  }
  {
    for(int i=1; i<13; i++) {
      MODLL<13> x = i;
      assert( (x.inv().x * i) % 13 == 1 );
    }
  }
}


int main() {

  LL N,M;
  cin >> N >> M;

  std::vector<int> A(N,0);

  REP(m, M) {
    int k;
    cin >> k;
    REP(j, k) {
      int n;
      cin >> n;
      A[n-1] |= 1 << m;
    }
  }

  int p = 0;
  REP(m,M) {
    int x;
    cin >> x;
    p |= x << m;
  }

  LL ans = 0;
  REP(i, 1<<N) {
    int state = p;
    REP(n,N) { // s'th switch
      if( i & (1<<n) ) {
        state ^= A[n];
      }
    }
    if(state == 0) { ans++; }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int D,T,S;
      cin >> D >> T >> S;
      
      if((double)D/(double)S < T ||(double)D/(double)S == T ){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
      
    }

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<int> A(N);
        for(int i=0;i<N;i++) cin>>A[i];
        string S;cin>>S;
        for(int i=0;i<S.size();i++){
            for(int j=0;j<A[i%N];j++){
                if(S[i]=='a') S[i]='Z';
                else if(S[i]=='A') S[i]='z';
                else S[i]--;
            }
        }
        
        cout<<S<<endl;
    }
}



Measured memory_bytes: 3192
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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


int y[1000];
int x[1000];
vector<int> children[1000];
bool update(int i){
	bool buf[2][5001]={};
	auto cur=buf[0];
	auto nex=buf[1];
	for(int v=0;v<=x[i];v++){
		cur[v]=false;
	}
	cur[0]=true;
	int s=0;
	for(auto c:children[i]){
		if(!update(c)){
			return false;
		}
		s+=x[c]+y[c];
		for(int v=0;v<=x[i];v++){
			nex[v]=false;
			if(v>=x[c]){
				nex[v]|=cur[v-x[c]];
			}
			if(v>=y[c]){
				nex[v]|=cur[v-y[c]];
			}
		}
		swap(nex,cur);
	}
	for(int v=x[i];v>=0;v--){
		if(cur[v]){
			y[i]=s-v;
			return true;
		}
	}
	return false;
}

int main() {
	int N;
	cin >> N;
	for(int i=1;i<N;i++){
		int p;
		cin >> p;
		p--;
		children[p].push_back(i);
	}
	for(int i=0;i<N;i++){
		cin >> x[i];
	}
	if(update(0)){
		cout << "POSSIBLE" << endl;
	}
	else{
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}



Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int l[10],L[11],v[2];
int main(void){
  while(cin>>l[0]){
    getchar();
    for(int i=1; i<10; i++){
      cin >> l[i];
      getchar();
    }
    cin >> v[0];
    getchar();
    cin >> v[1];
    L[0] = 0;
    for(int i=1;i<=10; i++)
      L[i] = L[i-1] + l[i-1];
    double con = (double)v[0]/(v[0]+v[1]) * L[10];
    for(int i=0;i<10;i++){
      if(con==0) {
cout << 1 << endl;
break;
}
      if(i==9){
        cout << 10 << endl;
        break;
      }
      if(L[i] < con && con <= L[i+1]){
        cout << (i+1) << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll t; t=1; while(t--)
typedef long long int ll;
int main() {
    FIO;
    test{
        ll r;
        cin>>r;
        long double ans,pi;
        pi=3.1415926535897932;
        ans=2*pi;
        ans*=double(r);
        cout<<fixed<<setprecision(6)<<ans<<endl;
    }
	return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "YES";
const string NO = "NO";

int main(){
    int n;
    cin >> n;
    vi p(n), t(n);
    rep(i, n) cin >> p[i];
    rep(i, n) t[i] = i+1;
    bool can = false;
    if (p == t) can = true;
    rep(i, n-1) for (int j=i+1; j<n; ++j) {
        swap(p[i], p[j]);
        if (p == t) can = true;
        swap(p[i], p[j]);
    }
    cout << (can?YES:NO) << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*; 
 
class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
		String k=sc.next();
        String l=sc.next();
  		String m=l.substring(0,l.length()-1);
    
 	if(k.equals(m)){
    		System.out.println("Yes");
    	}else{
     		System.out.println("No");
   	 }
 
    }
}

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

using namespace std;

int main() {
    string w;
    vector<int> freq(26);
    cin >> w;
    for (auto c : w) {
        int cur = c - 'a';
        freq[cur] = freq[cur] + 1;
    }
    for (auto i : freq) {
        if (i % 2 != 0) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef rd
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}


void solve() {
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int bee=(h2-h1)*60+m2-m1;
	if(bee<k) {
		cout<<0<<endl;
	} else
		cout<<bee-k<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(8);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int sx, sy, tx, ty;
signed main() {
	cin >> sx >> sy >> tx >> ty;
	for (int i = 0; i < ty - sy; i++)cout << "U";
	for (int i = 0; i < tx - sx; i++)cout << "R";
	for (int i = 0; i < ty - sy; i++)cout << "D";
	for (int i = 0; i < tx - sx; i++)cout << "L";
	cout << "L";
	for (int i = 0; i <= ty - sy; i++)cout << "U";
	for (int i = 0; i <= tx - sx; i++)cout << "R";
	cout << "DR";
	for (int i = 0; i <= ty - sy; i++)cout << "D";
	for (int i = 0; i <= tx - sx; i++)cout << "L";
	cout << "U" << endl;
	endre;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

int main()
{
  int n;
  int i,j;
  string str;
  int alph[26]={};

  cin>>str;
  n=str.size();

  rep(i,n)
    alph[str[i]-'a']++;

  rep(i,26)
    if(alph[i]%2){
      cout<<"No"<<endl;
      return 0;
    }
  cout<<"Yes"<<endl;
}


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

using namespace std;

int main(){
  int i,N,M,sum,all;
  long ans;
  bool can;
  int A[100];
  can=false;
  //  string S,A;
  
  cin>>N;

  ans=0;
  
  for(i=1;i<N+1;i++){
    if(0!=(i%3) and 0!=(i%5)){
      ans+=i;
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}


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

int main() {
    int N;
    int a[110];

    cin >> N;
    for(int i=0; i<N; ++i) cin >> a[i];
    
    sort(a, a+N, greater<int>());

    int A = 0;
    int B = 0;
    for(int i=0; i<N; ++i){
        if (i % 2 == 0) {
            A += a[i];
        }
        else {
            B += a[i];
        }
    }

    cout << A - B << endl;

}


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

#define M 1046933
#define NIL (-1)
#define L 14

char H[M][L];

int char2key(char ch) {
    if (ch == 'A') {
        return 1;
    }
    else if (ch == 'C') {
        return 2;
    }
    else if (ch == 'G') {
        return 3;
    }
    else if (ch == 'T') {
        return 4;
    }
    else {
        return 0;
    }
}

int getKey(char str[]) {
    int i = 0;
    int p = 1;
    int s, sum = 0;
    while (i < strlen(str)) {
        s = char2key(str[i]);
        sum += p * s;
        i++;
        p *= 5;
    }
    return sum;
}

int h1(int key) {
    return key % M;
}

int h2(int key) {
    return 1 + (key % (M - 1));
}

void insert(char str[]) {
    // cout << "insert" << endl;
    int i = 0, h;
    int key = getKey(str);
    while (1) {
        h = (h1(key) + i * h2(key)) % M;
        if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            break;
        }
        else {
            i++;
        }
    }
}

int find(char str[]) {
    // cout << "find" << endl;
    int i = 0, h;
    int key = getKey(str);
    while (1) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) {
            return 1;
        }
        else if (strlen(H[h]) == 0) {
            return 0;
        }
        else {
            i++;
        }
    }
}

int main() {
    int n;
    char com[10];
    char str[L];
    for (int i = 0; i < M; i++) {
        H[i][0] = '\0';
    }

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> com >> str;

        if (com[0] == 'i') {
            // cout << getKey(str) << endl;
            insert(str);
        }
        else if (com[0] == 'f') {
            // cout << getKey(str) << endl;
            if (find(str) == 1) {
                cout << "yes" << endl;
            }
            else if (find(str) == 0) {
                cout << "no" << endl;
            }
        }
    }
}



Measured memory_bytes: 17392
#include<stdio.h>
#include<math.h>
int main()
{
    long long x,y;
    long long mul=0;
    scanf("%lld %lld",&x,&y);
    while(x<=y)
    {
        mul+=1;
        x*=2;
    }
    printf("%lld",mul);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>


void main()
{
	int W, N;
	int value[1000], size[1000];
	int total[1001], choice[1001];
	int total_bk;
	int max_i;
	int count, i, j;


	count = 0;
	while(1){
		scanf("%d", &W);
		if(W == 0)
			break;

		scanf("%d", &N);

		for(i = 0; i < N; i++)
			scanf("%d,%d", &value[i], &size[i]);

		// 初期化
		for(i = 0; i <= W; i++){
			total[i] = 0;
			choice[i] = -1;
		}


		// 風呂敷にお宝をつめていく
		max_i = 0;
		for(i = 0; i < N; i++){
			for(j = W; j >= size[i]; j--){
				total_bk = total[j - size[i]] + value[i];
				if(total_bk > total[j]){
					total[j] = total_bk;
					choice[j] = i;
					if(total_bk > total[max_i])
						max_i = j;
				}
			}
		}
		while(total[max_i] == total[max_i - 1])
			max_i--;

		printf("Case %d:\n", count + 1);
		printf("%d\n%d\n", total[max_i], max_i);

		count++;
	}

}


Measured memory_bytes: 2052
#include<stdio.h>
#include<math.h>
int main(void)
{
    int a,b,h,m;
    scanf("%d%d%d%d",&a,&b,&h,&m);
    double hour,min;
    long double angle;
    hour = 30*h + ((double)m/2);
    min = 6*m;
    angle = hour - min;
    if(angle<0)
    {
        angle = 0 - angle;
    }
    if(angle>180)
    {
        angle = 360 - angle;
    }
    angle = (angle/180)*M_PI;
    long double c;
    c=(long double)pow(a,2)+(long double)pow(b,2)-2*a*b*(long double)cos(angle);
    printf("%.20lf",sqrt(c));
}


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

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

int main(){

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  int ind = 0;
  int cur = 0;
  int cursum = 0;
  int sum = 0;
  while(ind < n){
    if (cur != a[ind]){
      if (cursum < cur){
        sum += cursum;
      } else {
        sum += cursum - cur;
      }
      cur = a[ind];
      cursum = 1;
    } else {
      cursum += 1;
    }
    ind += 1;
  }
  if (cursum < cur){
    sum += cursum;
  } else {
    sum += cursum - cur;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;
#define int long long
#define f(i,n) for(int i=0;i<n;i++)

signed main(){
	int k,n;
	cin>>k>>n;
	int maxD=0;

	int dummy1;
	cin>>dummy1;
	int first=dummy1;
	int dummy2;
	f(i,n-1){
		cin>>dummy2;
		if(dummy2-dummy1>maxD)
			maxD=dummy2-dummy1;
		dummy1=dummy2;
	}
	if(first+(k-dummy2)>maxD)
		maxD=first+(k-dummy2);
	cout<<k-maxD<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
bool a[400][12];
typedef long long ll;
ll s=0;
ll cnt(ll y,ll m,ll d){
	if(d<13){
		m--;
		if(m==0) m=12,y--;
	}
	m--;
	ll ret=(y/400)*s;
	y%=400;
	rep(i,400) rep(j,12){
		if(a[i][j]) ret++;
		if(i==y&&j==m) goto hoge;
	}
	hoge:
	return ret;
}
int main(){
	rep(tt,7){
		rep(i,400) rep(j,12) a[i][j]=0;
		s=0;
		int t=tt;
		rep(i,400) rep1(j,12){
			if(t==0) a[i][j-1]=1,s++;
			if(j==1||j==3||j==5||j==7||j==8||j==10||j==12) t=(t+31)%7;
			else if(j!=2) t=(t+30)%7;
			else if(i%4==0&&(i==0||i%100>0)) t=(t+29)%7;
		}
		if(a[15][2]) break;
	}
	ll y,m,d,Y,M,D;
	cin>>y>>m>>d>>Y>>M>>D;
	cout<<cnt(Y,M,D)-cnt(y,m,d-1)<<endl;
}


Measured memory_bytes: 1164
s = str(input())
if s == 'SUN':
    print('7')
elif s == 'MON':
    print('6')
elif s == ('TUE'):
    print('5')
elif s == ('WED'):
    print('4')
elif s == ('THU'):
    print('3')
elif s == ('FRI'):
    print('2')
else:
    print('1')

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>v;
void bfs()
{
    queue<ll>q;
    for(ll i=1;i<=9;i++)
        q.push(i);
        ll cnt=0;
    while(!q.empty() && v.size()<=1e6)
    {
        ll a=q.front();
        v.push_back(a);
        q.pop();
        ll d=a%10;
        q.push(a*10+d);
        if(d==0)
            q.push(a*10+d+1);
        else if(d==9)
            q.push(a*10+d-1);
        else
        {
           q.push(a*10+d+1);
           q.push(a*10+d-1);
        }
    }
    sort(v.begin(),v.end());
}
int main()
{
    bfs();
    ll k;cin>>k;
    cout<<v[k-1]<<endl;
}


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

int main() {
    int n, x;
    cin >> n >> x;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] + a[i + 1] <= x) continue;
        int d = a[i] + a[i + 1] - x;
        ans += d;
        a[i + 1] = max(0, a[i + 1] - d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
main(){
  double a,b,c,d,e,f,x,y;
  int x5,y5;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
    x=(c*e-f*b)/(a*e-d*b);
    y=(a*f-d*c)/(a*e-d*b);

    x5=x*10000;
    y5=y*10000;

    x5%=10;
    y5%=10;

    if(x5>=5){
      x+=0.001;
    }
    if(y5>=5){
      y+=0.001;
    }

    printf("%.3f %.3f\n",x+0,y);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

vector<vector<int>> to;

void dfs(int v, vi& dist,int p=-1) {
    for (auto u : to[v]) {
        if (u == p) continue;
        dist[u] = dist[v] + 1;
        dfs(u, dist, v);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    to.resize(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].pb(b);
        to[b].pb(a);
    }
    vi dist_t(n), dist_a(n);
    dfs(u, dist_t);
    dfs(v, dist_a);
    int ans = -2;
    rep(i, n) {
        if (dist_t[i] < dist_a[i]) chmax(ans, dist_a[i] - 1);
    }
    cout << ans << endl;
}

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

int main(){
  int X; 
  cin >> X;
  
  int sum /*f(X)*/ = 0;
  int unk = X;
  for (int i=0; i<9; i++){
    sum += unk % 10;
    unk /= 10; 
  }
  
  if (X % sum == 0)
    cout << "Yes" << endl;
  else if (X % sum != 0)
    cout << "No" << endl;
}


Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main(void){
    int n,k,x[120],s=0;
    cin>>n>>k;
    
    for(int i=1;i<=n;i++){
        cin>>x[i];
    }
    for(int i=1;i<=n;i++){
        if(x[i]>k-x[i]) s+=2*(k-x[i]);
        else s+=2*x[i];
    }
    cout<<s<<endl;
    // Here your code !
    return 0;
}


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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)

int main()
{
    long t = 1;
    //cin >> t;

    while (t--) {
        long n, m;
        cin >> n >> m;

        long ans = n*(n-1)/2 + m*(m-1)/2;
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 3760
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    String ans = "NO";
    if(c % gcd(b, a % b) == 0) ans = "YES";
    System.out.println(ans);
  }

  public static int gcd(int x, int y) {
    if(y == 0) return x;
    return gcd(y, x % y);
  }
}

Measured memory_bytes: 22868
n,m=map(int,input().split())
lst=[[]for i in range(n)]
for i in range(n):
    lst[i]=list(map(int,input().split()))
lst2=[[]*1 for i in range(m)]
for i in range(m):
    lst2[i]=int(input())
for i in range(n):
    x=0
    for j in range(m):
        x=x+lst[i][j]*lst2[j]
    print("%d"%(x))



Measured memory_bytes: 5984
import math




def solve(n):
    ans = 0
    for i in range(2, int(math.sqrt(n) + 2)):
        if n % i == 0:
            times = 0
            needed = 1
            while n % i ==0:
                times += 1
                if times>= needed:
                    times = 0
                    needed += 1
                    ans += 1
                n //= i
    if not n == 1:
        print(ans+1)
    else:
        print(ans)
    return



n = int(input())
solve(n)


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

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 N;
int D[105][2];

signed main(){
    cin>>N;
    int cnt=0;
    int tmp=0;
    for(int i=0;i<N;++i){
        int d1,d2;
        cin>>d1>>d2;
        if(d1==d2)tmp++;
        else tmp=0;
        chmax(cnt,tmp);
    }
    if(cnt>=3)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i<n; i++)

using namespace std;

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

    vector<string> subs;
    rep(i, 5) subs.push_back({'z'+1});

    rep(start, s.size()) {
        rep(li, k) {
            string si = s.substr(start, li+1);
            auto it = lower_bound(subs.begin(), subs.end(), si);
            if (*it == si) continue;

            subs.insert(it, si);
            subs.resize(k+1);
        }
    }
    cout << subs[k-1] << endl; 
}


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

int main() {
	int N,A,remainder;
	cin >> N >> A;
	remainder = N % 500;
	if ( remainder == 0) cout << "Yes" << endl;
	else if ( A >= remainder ) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, x, *a;
    cin >> N >> x;
    a = new int[N];
    for (int i = 0; i < N; i++)
        cin >> a[i];

    sort(a, a+N);

    int ans = 0;
    int sum = 0;

    int i = 0;
    for (; i < N; i++) {
        if (x >= sum + a[i]) {
            sum += a[i];
            ans++;
        }
    }
    if (ans != N || sum == x)
        cout << ans << endl;
    else 
        cout << N-1 << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[1000][1000]={};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<a*b<<'\n';

    return 0;

}

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

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


Measured memory_bytes: 3648
N = int(input())
Alist = list(map(int, input().split()))

def dq(N, Alist):
    Blist = [0]*(N//2+1)+Alist[N//2:]
    Alist = [0]+Alist
    for ind in range(N//2, 0, -1):
        total = 0
        for i in range(ind, N+1, ind):
            total += Blist[i]
        if total%2 != Alist[ind]:
                Blist[ind] = 1
    retnum = 0
    retind = []
    for ind, bi in enumerate(Blist):
        if bi == 1:
            retnum +=1
            retind.append(str(ind))
    print(retnum)
    if retnum > 0:
        print(" ".join(retind))
dq(N,Alist)

Measured memory_bytes: 18612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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(){
    ll n,m; cin>>n>>m;
    string s; cin>>s;
    ll loc=n, cnt=0;
    vector<ll> ans(1);
    while(loc>0){
        rep(i,m){
            if(loc-m<=0){
                ans.push_back(loc); loc=0; break;
            }
            if(s[loc-m+i]=='0'){
                loc=loc-m+i; ans.push_back(m-i); break;
            }
            if(i==m-1){
                cout<<-1<<endl; return 0;
            }
        }
    }
    rep(i,ans.size()-1){
        cout<<ans[ans.size()-i-1]<<' ';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1528
#include <stdio.h>
#include <stdlib.h>
int main(){
	int x1,x2,x3,x4;
	int y1,y2,y3,y4;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	int dif_x,dif_y;
	dif_x = x2- x1;
	dif_y =y1-y2;
	x3 = x2+ dif_y;
	x4 = x1+ dif_y;
	y3 = y2 + dif_x;
	y4 = y1 + dif_x;
	printf("%d %d %d %d\n",x3,y3,x4,y4);


}

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

using namespace std;
typedef long long ll ;
#define forl(i,n) for(int i=0 ; i<n ; i++)

ll n,l;
vector<ll> w,v ;
ll dp[100][(int)1e5+1] ;

ll solve(ll p,ll x)
{
	if(dp[p][x]!=-1)
		return dp[p][x] ;
	if(p>0)
	{
		dp[p][x]=solve(p-1,x) ;
	if(x>=w[p])
		dp[p][x]=max(dp[p][x],v[p]+solve(p-1,x-w[p])) ; //dp[p-1][x-w[p]]) ;
	}
	else
	{
		dp[p][x]=0 ;
		if(x>=w[p])
			dp[p][x]=v[p] ;
	}
	return dp[p][x] ;
}

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		cin>>n>>l ;
		w.resize(n) ;
		v.resize(n) ;
		for(int i=0 ; i<100 ; i++)
			for(int j=0 ; j<=1e5 ; j++)
				dp[i][j]=-1 ;
	
		for(int i=0 ; i<n ; i++)
			cin>>w[i]>>v[i] ;

		ll ans=solve(n-1,l) ;
		cout<<ans<<endl ;
	}
	return 0;
}

Measured memory_bytes: 81724
# 2019-11-15 00:35:39(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *p = [int(x) for x in sys.stdin.read().split()]

    compare = []
    for i in range(n-1):
        if p[i] < p[i+1]:
            compare.append('<')
        else:
            compare.append('>')

    count = 0
    for i in range(1, n-1):
        if compare[i-1] == compare[i] == '<' or compare[i-1] == compare[i] == '>':
            count += 1

    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
const ll mod=1e9+7;
using namespace std;


int main()

{
    int n;cin>>n;
    ll dp[n+1];
    for(int i=0;i<=n;i++)dp[i]=0;
	int m;cin>>m;
    for(int i=0;i<m;i++)
    {
    	int u;
    	cin>>u;
    	dp[u]=-1;
	}
	dp[0]=1;
	if(n==1)
	{
		cout<<1;
		return 0;
	}
	if(dp[1]!=-1)
	{
		dp[1]=1;
	}
	for(int i=2;i<=n;i++)
	{
		
		if(dp[i]!=-1)
		{
		
		if(dp[i-1]!=-1)
		{
			dp[i]=(dp[i]+dp[i-1]) % mod;
		}
		if(dp[i-2]!=-1)
		{
			dp[i]=(dp[i]+dp[i-2]) %mod;
		}}
		
	}
	cout<<dp[n];
    
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int l,r,d; cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0) ans++;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3620
// ???????????????
#include<vector>
#include<algorithm>
std::vector<int> answer;
// ?????°
const int MAX_N = 500000;
const int NIL = -1;
// ???
struct Vertex {int label, x, y;};
struct Node {int left_child, right_child;};
// ?????°
int root;
Node node[MAX_N];
Vertex vertex[MAX_N];
// ?????????
class Compare {
public:
  Compare(int d) : d(d) {}
  bool operator()(const Vertex& lhs, const Vertex& rhs) const {return d & 1 ? lhs.y < rhs.y : lhs.x < rhs.x;}
private:
  int d;
};
// ?§????
int build(int low, int high, int depth) {
  if(!(low < high)) return NIL;
  std::sort(vertex + low, vertex + high, Compare(depth));
  int middle = (low + high) / 2;
  node[middle].left_child = build(low, middle, depth ^ 1);
  node[middle].right_child = build(middle + 1, high, depth ^ 1);
  return middle;
}
// ?????¢?????????????????°?????????????????°??¨???????????¢???????????§?¨????????????§?¨??????????
void search(int index, int sx, int sy, int tx, int ty, int depth) {
  if(index == NIL) return;
  if(sx <= vertex[index].x && vertex[index].x <= tx && sy <= vertex[index].y && vertex[index].y <= ty) answer.push_back(vertex[index].label);
  if(depth & 1) {
    if(sy <= vertex[index].y) search(node[index].left_child, sx, sy, tx, ty, depth ^ 1);
    if(vertex[index].y <= ty) search(node[index].right_child, sx, sy, tx, ty, depth ^ 1);
  } else {
    if(sx <= vertex[index].x) search(node[index].left_child, sx, sy, tx, ty, depth ^ 1);
    if(vertex[index].x <= tx) search(node[index].right_child, sx, sy, tx, ty, depth ^ 1);
  }
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    vertex[i] = Vertex({i, x, y});
  }
  root = build(0, n, 0);
  int q;
  cin >> q;
  for(int i = 0; i < q; ++i) {
    int sx, tx, sy, ty;
    cin >> sx >> tx >> sy >> ty;
    answer.clear();
    search(root, sx, sy, tx, ty, 0);
    sort(begin(answer), end(answer));
    for(auto a: answer) cout << a << "\n";
    cout << "\n";
  }
}

Measured memory_bytes: 10808
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace<'a>) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());
	let num: usize = iter.read();
	let b: usize = iter.read();

	if num <= 5 {
		println!("0");
	} else if num <= 12 {
		println!("{}", b / 2);
	} else {
		println!("{}", b);
	}
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main()
{
  string S;
  cin >> S;
  int count = 0;
  int mass = 0;
  for(auto s: S){
    int next = s - 'A';
    if(next <= mass){
      count++;
    }
    mass = next;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3156
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	ll S=0;
	REP(i,N){
		ll V=i+1;
		if(V%3 && V%5) S+=V;
	}
	out(S);
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long

const int N = 100010;

ll n, a[N], cnt[N], pre[N];

int main(){
	scanf("%I64d", &n);
	ll sum = 0, one = n * (n + 1) / 2;
	for (int i = 0; i < n; ++ i){
		scanf("%I64d", &a[i]);
		sum += a[i];
	}
	if (sum % one){
		return printf("NO\n"), 0;
	}
	ll times = sum / one;
	for (int i = n - 2; i >= 0; -- i){
		ll x = a[i] - (a[n - 1] - times * (n - 1 - i));
		if (x % n){
			return printf("NO\n"), 0;
		}
		cnt[i] = x / n - pre[i + 1];
		if (cnt[i] < 0){
			return printf("NO\n"), 0;
		}
		pre[i] = pre[i + 1] + cnt[i];
	}
	return printf("YES\n"), 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; 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(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    string s; cin >> s;
    if(s.length()==3) reverse(ALL(s));
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 384
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

import Debug.Trace

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ d, g ] <- readInts
	[ p, c ] <- transpose <$> replicateM d readInts
	print $ fromJust $ solve [ 100, 200 .. ] p c [] g

solve _ [] [] rest g
	| g <= 0 = Just 0
	| otherwise = solve2 rest g
solve ( s : ss ) ( p : ps ) ( c : cs ) rest g = min' res1 res2
	where
		solve' = solve ss ps cs 
		res1 = ( 0 + ) <$> solve' ( ( s, p - 1 ) : rest ) g
		res2 = ( p + ) <$> solve' rest ( g - s * p - c )

solve2 [] g = Nothing
solve2 ( ( s, p ) : rest ) g
	| g <= 0 = Just 0
	| g <= s * p = Just $ ( g + s - 1 ) `div` s
	| otherwise = ( p + ) <$> solve2 rest ( g - s * p )

min' ( Just a ) Nothing = Just a
min' Nothing ( Just b ) = Just b
min' a b = min <$> a <*> b

Measured memory_bytes: 764
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <vector>
#include <iostream>
#include <set>
#include <iomanip>
#include <map>
#include <algorithm>
#include <queue>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int N=1e6;


int main(){
	fastio;
	int n; string s;
	cin>>s;
	n = sz(s)+1;
	ll A[N];
	A[0]=0;
	For(i,1,n) if(s[i-1]=='>') A[0]=i;
		else break;
	For(i,1,n){
		if(s[i-1]=='<' && s[i]=='>'){
			For(cont,i+1,n) if(s[cont-1]=='>') A[i]=cont-i;
				else break;
			if((A[i-1]+1)>A[i]){
				A[i+1]=A[i]-1;
				A[i]=A[i-1]+1;
				i++;
			}
		}else{
			if(s[i-1]=='<') A[i]=A[i-1]+1;
			else A[i]=A[i-1]-1;
		}
	}
	ll acum=0;
	For(i,0,n){
		acum+=A[i];
	}
	cout<<acum<<endl;
	return 0;
}

Measured memory_bytes: 6556
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;



int main()
{
    FAST
    ll n;cin>>n;
    if(n>=30) cout<<"Yes\n";
    else cout<<"No\n";
}


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

const int maxN=301;

int n;
char a[maxN][maxN*2];

void ReadData()
{
    //freopen("Symmetry.inp","r",stdin);
    //freopen("Symmetry.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n;
    for (int i=0; i<n; ++i)
        cin>>a[i];
}

bool Check (int k)
{
    for (int i=0; i<n-1; ++i)
        for (int j=1; j<n; ++j)
            if (a[i][j+k]!=a[j][i+k]) return false;
    return true;
}

void Solve()
{
    int cnt=0;
    for (int i=0; i<n; ++i)
        for (int j=n; j<2*n; ++j) a[i][j]=a[i][j-n];
    for (int i=0; i<n; ++i)
        if (Check(i)) ++cnt;
    cout<<cnt*n;
}

int main()
{
    ReadData();
    Solve();
    return 0;
}


Measured memory_bytes: 384
import sys

N, M = [int(i) for i in input().split()]
map = {k: [] for k in range(1, N + 1)}

for _ in range(M):
  a, b = (int(i) for i in input().split())
  map[a].append(b)


for i in map[1]:
  if N in map[i]:
    print('POSSIBLE')
    sys.exit()


print('IMPOSSIBLE')


Measured memory_bytes: 48516
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		
		if (N%500<=A) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 21972