akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#define N 1005
#define M 200005
using namespace std;
int read(){
	char c=getchar();
	while(c<'0'||c>'9'){
		continue;
	}
	int num=c^48;
	c=getchar();
	while(c>='0'&&c<='9'){
		num=num*10+(c^48);
		c=getchar();
	}
	return num;
}
vector<int> edge[N];
int p1[N][N];
void dfs1(int now,int p){
	for(vector<int>::iterator it=edge[now].begin();it!=edge[now].end();++it){
		int v=*it;
		if(p1[p][v]){
			continue;
		}
		p1[p][v]=p1[p][now];
		dfs1(v,p);
	}
}
int p2[N][N];
void dfs2(int now,int p){
	for(vector<int>::iterator it=edge[now].begin();it!=edge[now].end();++it){
		int v=*it;
		if(p2[p][v]){
			continue;
		}
		p2[p][v]=p2[p][now];
		dfs2(v,p);
	}
}
int u[M],v[M];
int main(){
	int n,m;
	n=read();
	m=read();
	for(int i=0;i<m;++i){
		u[i]=read();
		v[i]=read();
		edge[u[i]].push_back(v[i]);
	}
	for(int i=1;i<=n;++i){
		p1[i][i]=i;
		for(vector<int>::iterator it=edge[i].begin();it!=edge[i].end();++it){
			int v=*it;
			if(p1[i][v]){
				continue;
			}
			p1[i][v]=v;
			dfs1(v,i);
		}
		p2[i][i]=i;
		if(edge[i].begin()==edge[i].end()){
			continue;
		}
		for(vector<int>::iterator it=--edge[i].end();;--it){
			int v=*it;
			if(p2[i][v]){
				if(it==edge[i].begin()){
					break;
				}
				continue;
			}
			p2[i][v]=v;
			dfs2(v,i);
			if(it==edge[i].begin()){
				break;
			}
		}
	}
	for(int i=0;i<m;++i){
		int flag=0;
		if(p1[v[i]][u[i]]){
			flag^=1;
		}
		if(p1[u[i]][v[i]]!=p2[u[i]][v[i]]){
			flag^=1;
		}
		if(flag){
			printf("diff\n");
		}else{
			printf("same\n");
		}
	}
}

Measured memory_bytes: 13920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramB
    {
        static void Main()
        {
            int n = NextInt, x = NextInt;
            var l = IntList;
            for (int i = 0; i < l.Count - 1; i++)
            {
                l[i + 1] += l[i];
            }

            System.Console.WriteLine(l.TakeWhile(y => y <= x).Count() + 1);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];

int main(){
    int N, K;
    int red, blue;
    cin >> N >> K;
    red = N - K;
    blue = K;

    // C[0][0] = 1;
    // パスカルの三角形で求める
    for(int i = 0; i <= 2000; i++){
        for(int j = 0; j <= i; j++){
            if(j == 0 || i == j){
                C[i][j] = 1;
            }else{
                C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
            }
        }
    }

    for(int i = 1; i <= K; i++){
        // cout << C[100][10] << endl;
        // cout << C[K-1][i-1] << endl;

        ll a = C[N-K+1][i];
        ll b = C[K-1][i-1];
        cout << (a * b) % mod << endl; 
    }
}


Measured memory_bytes: 30208
if __name__ == "__main__":
    line = input()

    S1 = []
    S2 = []
    total = 0

    for k, v in enumerate(line):
        if v == '\\':
            S1.append(k)
        elif v == '/' and len(S1) > 0:
            left_pos = S1.pop()
            area = k - left_pos
            total += area

            while True:
                if len(S2) < 1 or S2[-1][0] < left_pos:
                    S2.append([left_pos, area])
                    break
                else:
                    btm_area = S2.pop()
                    area += btm_area[1]

    print(total)
    indiv = [str(v[1]) for v in S2]
    indiv.insert(0, str(len(S2)))
    print(' '.join(indiv))



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

int main(){
    int N, D;
    // vector<int> vp;
    int vp[12][12];

    cin >> N >> D;
    for (int j=0; j<N; j++){
        for (int i=0; i<D; i++){
            cin >> vp[j][i];
        }
    }

    int res = 0;
    int dist_sq;
    float dist;

    for (int i=0; i<N-1; i++){
        for (int j=i+1; j<N; j++){
            dist_sq = 0;
            for (int d=0; d<D; d++){
                dist_sq += (vp[i][d] - vp[j][d]) *
                           (vp[i][d] - vp[j][d]) ;
                // printf("i:%d j:%d dist_sq:%d\n", vp[i][d], vp[j][d], dist_sq); //debug
            }
        
            if (dist_sq == 0){ res++; continue; }
            // printf("dist_sq: %d\n", dist_sq); //debug
            dist = sqrt((float)dist_sq);
            if (dist <= floor(dist)){ res++; continue; }
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 764
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

W, H, N = map(int, input().split())
L = [[int(v) for v in input().split()] for _ in range(N)]
m = [[0 for _ in range(W)] for _ in range(H)]

for x, y, a in L:
    for i in range(H):
        for j in range(W):
            if a == 1 and j < x:
                m[i][j] += 1
            elif a == 2 and j >= x:
                m[i][j] += 1
            elif a == 3 and i < y:
                m[i][j] += 1
            elif a == 4 and i >= y:
                m[i][j] += 1

ans = 0
for v in m:
    ans += len([p for p in v if p == 0])

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;

int main(){
  int n,t,l,b,tmp;
  int g[110];
  long double p[110][110];

  while(scanf("%d%d%d%d",&n,&t,&l,&b),(n||t||l||b)){
    for(int i=0;i<=t;i++){
      g[i] = 0;
      for(int j=0;j<=n;j++)p[i][j] = 0;
    }
    p[0][0] = 1;

    for(int i=0;i<l;i++){
      scanf("%d",&tmp);
      g[tmp] = 1;
    }
    for(int i=0;i<b;i++){
      scanf("%d",&tmp);
      g[tmp] = 2;
    }

    for(int i=0;i<t;i++){
      for(int j=0;j<n;j++){
	for(int k=1;k<=6;k++){
	  int nxt = j+k;
	  if(nxt>n)nxt = 2*n-nxt;
	  if(g[nxt]==2)nxt = 0;
	  if(g[nxt]!=1)p[i+1][nxt] += p[i][j]/6;
	  else if(i+2<=t)p[i+2][nxt] += p[i][j]/6;
	}
      }
      p[i+1][n] += p[i][n];
    }
    printf("%.10Lf\n",p[t][n]);
  }
}

Measured memory_bytes: 1248
#include<stdio.h>
int main(){
    int h,w;
    scanf("%d %d",&h,&w);
    int i;
    for(i=1;i<=h;i++){
        char s[w];
        scanf("%s\n",s);
        printf("%s\n",s);
        printf("%s\n",s);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
int a[n];
map<int,int> m;
ll sum=0;
for(int i=0;i<n;i++)
{
	cin>>a[i];
	m[a[i]]++;
	sum+=a[i];
}
int q;
cin>>q;
while(q--)
{
	int x,y;
	cin>>x>>y;
	sum-=(ll)m[x]*x;
	int z=m[x];
	m[x]=0;
	m[y]+=z;
	sum+=(ll)z*y;
	cout<<sum<<endl;
}
return 0;
}
// Problem : D - Replacing
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



Measured memory_bytes: 8420
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] ary = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
		Arrays.sort(ary);
		System.out.println(ary[0] + ary[1]);
	}
}


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

#define lint long long
#define P pair<int, int>

int main(){
    int A, B;
    cin >> A >> B;
    
    if(B % A == 0){
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }
}


Measured memory_bytes: 256
A, B, M=map(int,input().split())
list_A=list(map(int,input().split()))
list_B=list(map(int,input().split()))
list_1=[list(map(int,input().split())) for i in range(M)]
L=min(list_A)+min(list_B)
list_2=[]
for k in range(M):
  cost=list_A[list_1[k][0]-1]+list_B[list_1[k][1]-1]-list_1[k][2]
  list_2.append(cost)
if L>=min(list_2):
  print(min(list_2))
else:
  print(L)

Measured memory_bytes: 42408
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
int n,d;
int x[20][20];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>d;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=d;j++)
			cin>>x[i][j];
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int tot=0;
			for(int k=1;k<=d;k++)
				tot+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			if((int)sqrt(tot)*(int)sqrt(tot)==tot)
				cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


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

int main() {
    int n;
    while (cin >> n) {
        string s;
        while (n--) {
            char c; cin >> c; s += c;
        }
        int ans = 0;
        while (s.find(to_string(ans)) != string::npos) ans++;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3272
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort(reverse = True)
    ans = 0
    for i in range(N):
        ans += A[2 * i + 1]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 37084
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int sum = 0;
        for(int i = 0 ; i < m ; i++){
            int a = scanner.nextInt();
            sum += a;
        }
        if(n - sum < 0){
            System.out.println("-1");
        }else {
            System.out.println(n - sum);
        }

    }

}

Measured memory_bytes: 46220
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll x; cin >> x;
    ll div;
    ll div2;
    for(int i=100;i>=1; i--){
        div = i;
        div2 = pow(div, 5);
        if (x%div2 == 0){
            break;
        }
    }
    x /= div2;
    dump(x)
    ll limit = 1000;
    for(int b=limit*-1; b<limit; b++){
        for(int a=limit*-1; a<limit; a++){
            if (pow(a, 5) - pow(b, 5) == x){
                cout << a*div << " " << b*div << endl;
                return 0;
            }
        }
    }
    return 1;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;



int main() {
  ll n; cin >> n;
  Vp p(n);
  rep(i, 0, n){
    cin >> p[i].second >> p[i].first;
  }

  sort(ALL(p), greater<pair<ll, ll>>());

  ll t = p[0].first;
  rep(i, 0, n){
    if(t > p[i].first) t = p[i].first;
    t -= p[i].second;
  }

  if(t < 0) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
//#define ll long long int32_t 
#define int long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=1000000000000000003;
const int32_t LOG=21;
const int MOD=MOD1;
int dp[105][100005];
int weight[105];
int val[105];
int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
         int n,w;
         cin>>n>>w;
         rep(i,1,n+1)cin>>weight[i]>>val[i];
         rep(i,1,n+1)
         {
         	rep(j,0,w+1)
         	{
         		if(weight[i]<=j)
         		dp[i][j]=max(dp[i-1][j],val[i]+dp[i-1][j-weight[i]]);	
         	    else
         	    dp[i][j]=dp[i-1][j];	
         	}
         }
         cout<<dp[n][w]<<endl;
      }
      return 0;     
}


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

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> A(H+2,vector<char>(W+2,'.'));
  int counter=0;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>A.at(i).at(j);
      if(A.at(i).at(j)=='#'){
        counter++;
      }
    }
  }
  if(counter==H+W-1){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    if (n == 3 or n == 5 or n == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

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

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn =  (int) 1.32e5;

int pr[maxn], prc[maxn];
int n;

vector<vector<int> > es;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  es = vector<vector<int> >(n);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", pr + i, prc + i);
    --pr[i];
    es[pr[i]].pb(i);
  }
  return 1;
}

const long long infll = 1e18;

typedef vector<pair<long long, long long> > T;

void cut(T &a) {
  int nsz = 0;
  for (int i = 0; i < sz(a); ++i) {
    if (nsz) {
      assert(a[nsz - 1] <= a[i]);
      if (a[nsz - 1].first == a[i].first) {
        continue;
      }
      if (a[nsz - 1].second <= a[i].second) {
        continue;
      }
    }
    a[nsz++] = a[i];
  }
  a.resize(nsz);
}

T dfs(int v, long long mx, long long depth) {
  //eprintf("v = %d, %lld\n", v, depth);
  if (!sz(es[v])) {
    return {mp(depth, depth)};
  }
  assert(sz(es[v]) == 2);
  auto a = dfs(es[v][0], mx, depth + prc[es[v][0]]);
  auto b = dfs(es[v][1], mx, depth + prc[es[v][1]]);
  if (sz(a) > sz(b)) {
    swap(a, b);
  }
  T res;
  for (int i = 0, j = 0; i < sz(a); ++i) {
    long long need = (mx - (a[i].second - depth)) + depth;
    while (j < sz(b) && b[j].first <= need) {
      ++j;
    }
    if (j) {
      auto toadd = mp(a[i].first, b[j - 1].second);
      res.pb(toadd);
    }
  }
  cut(res);
  T final;
  for (int i = 0, j = sz(res) - 1; i < sz(res) || j >= 0;) {
    auto curi = i == sz(res) ? mp(infll, infll) : res[i], curj = j < 0 ? mp(infll, infll) : res[j];
    swap(curj.first, curj.second);

    if (curi < curj) {
      final.pb(curi);
      ++i;
    } else {
      final.pb(curj);
      --j;
    }
  }
  cut(final);
  return final;
}

bool check(long long mx) {
  //eprintf("check(mx = %lld)\n", mx);
  const auto &got = dfs(0, mx, 0);
  return sz(got) > 0;
}

void solve() {
  long long left = -1, right = 1e18;
  while (left + 1 < right) {
    auto mid = (left + right) / 2;
    if (check(mid)) {
      right = mid;
    } else {
      left = mid;
    }
  }
  printf("%lld\n", right);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main(){
    int N, L;
    cin >> N >> L;
    vector<int> a(N);
    for(int i=0; i<N; i++)
        a[i] = L + i;
    
    int min;
    for(int i=0; i<N; i++){
        if(i == 0)
            min = a[0];
        else if(abs(a[i]) < abs(min))
            min = a[i];
    }

    int sum = 0;
    for(int i=0; i<N; i++){
        sum += a[i];
    }

    cout << sum - min << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <bitset>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  int n,m,alla=0;
  cin >> n >> m;
  vector<int> A(n);
  rep(i,n){
    cin >> A[i];
    alla += A[i];
  }
  int tmp = 0;
  rep(i,n){
    if(A[i] >= 1.*alla/(4*m)) tmp++;
  }
  if(tmp>=m) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define bit(n) (1LL<<(n))

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

lint dp[bit(20)];

int main() {
    lint n, m;
    cin >> n >> m;

    vector<bitset<20>> c(m);
    vector<lint> a(m);
    for(lint i=0; i<m; i++) {
        lint b;
        cin >> a[i] >> b;
        for(lint k=0; k<b; k++) {
            lint box;
            cin >> box;
            c[i].set(--box);
        }
    }

    fill(begin(dp), end(dp), 1e18);
    dp[0] = 0;

    for(lint i=0; i<m; i++)
    for(lint elems=0; elems<bit(n); elems++) {
        // 使う
        bitset<20> bs(elems);
        bs |= c[i];
        lint next = bs.to_ullong();
        chmin(dp[next], dp[elems] + a[i]);

        // 使わない
        chmin(dp[elems], dp[elems]);
    }

    lint ans = dp[bit(n)-1];
    cout << (ans == 1e18 ? -1 : ans) << endl;
}

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

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int w,h;
char map[22][22];

int dfs(int y,int x){
	int i,res=1;
	if(map[y][x]=='#')return 0;
	map[y][x]='#';
	for(i=0;i<4;i++)
		res += dfs(y+dy[i],x+dx[i]);
	return res;
}
int main(){
	int i,j;
	int sy,sx;
	while(scanf("%d%d",&w,&h)==2&&(w|h)){
		memset(map,'#',sizeof(map));
		scanf("\n");
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				scanf("%c",&map[i][j]);
				if(map[i][j]=='@'){
					sy=i;
					sx=j;
				}
			}
			scanf("%*c");
		}
		printf("%d\n",dfs(sy,sx));
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int e[m];
	int integer[n+1]={0};
	for(int i=0;i<m;i++){
		cin >> e[i];
	}
	for(int i=m-1;i>=0;i--){
		if(integer[e[i]]==0){
			cout << e[i] << endl;
			integer[e[i]]=1;
		}
	}
	for(int i=1;i<=n;i++){
		if(integer[i]==0)
			cout << i << endl;
	}

}

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

int main()
{
    int h, w; cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }

    int n = 0;
    vector<vector<int>> ans;

    for (int i = 0; i < h; i++) {
        if (i % 2 == 0) {
            for (int j = 0; j < w - 1; j++) {
                if (a[i][j] % 2 == 1) {
                a[i][j + 1] += a[i][j];
                ans.push_back({i, j, i, j + 1});
                n++;
                }
            }
            if (a[i][w - 1] % 2 == 1 && i != h - 1) {
                a[i + 1][w - 1] += a[i][w - 1];
                ans.push_back({i, w - 1, i + 1, w - 1});
                n++;
            }
        } else {
            for (int j = w - 1; j >= 1; j--) {
                if (a[i][j] % 2 == 1) {
                a[i][j - 1] += a[i][j];
                ans.push_back({i, j, i, j - 1});
                n++;
                }
            }
            if (a[i][0] % 2 == 1 && i != h - 1) {
                a[i + 1][0] += a[i][0];
                ans.push_back({i, 0, i + 1, 0});
                n++;
            }
        }
    }

    cout << n << endl;
    for (int i = 0; i < ans.size(); i++) {
        for (int j = 0; j < ans[i].size() - 1; j++) {
            cout << ans[i][j] + 1 << " ";
        }
        cout << ans[i][ans[i].size()-1] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 9904
#include <stdio.h>

typedef struct {
	int d;
	int m;
	int k;
	int result;
} kensa_t;

int main(void) {
	int result[300];
	kensa_t kensa[1000];
	int a,b,c;
	int all;
	int i;
	int N;
	while(1) {
		scanf("%d %d %d",&a,&b,&c);
		if(a==0 && b==0 && c==0)break;
		scanf("%d",&N);
		all=a+b+c;
		for(i=0;i<all;i++)result[i]=2;
		for(i=0;i<N;i++) {
			scanf("%d %d %d %d",
				&kensa[i].d,&kensa[i].m,&kensa[i].k,&kensa[i].result);
			kensa[i].d--;
			kensa[i].m--;
			kensa[i].k--;
		}
		for(i=0;i<N;i++) {
			if(kensa[i].result) {
				result[kensa[i].d]=1;
				result[kensa[i].m]=1;
				result[kensa[i].k]=1;
			}
		}
		for(i=0;i<N;i++) {
			if(!kensa[i].result) {
				if(result[kensa[i].d]==1 && result[kensa[i].m]==1)
					result[kensa[i].k]=0;
				if(result[kensa[i].m]==1 && result[kensa[i].k]==1)
					result[kensa[i].d]=0;
				if(result[kensa[i].k]==1 && result[kensa[i].d]==1)
					result[kensa[i].m]=0;
			}
		}
		for(i=0;i<all;i++)printf("%d\n",result[i]);
	}
	return 0;
}

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

const int M = int(1e9) + 7;

string S;

int main() {
	cin >> S;
	S = '.' + S;
	vector< vector<int> > dp (S.length() + 1, vector<int> (13, 0) );
	//--
    dp[0][0] = 1;
    //
	for(int i = 1; i < S.length(); i++) {
		if(S[i] == '?') {
			for(int d = 0; d < 10; d++){
				for(int m = 0; m < 13; m++){
					dp[i][(m*10+d)%13] += dp[i-1][m];
					dp[i][(m*10+d)%13] %= M;
				}
			}
		} else {
			for(int m = 0; m < 13; m++){
				dp[i][(m*10+(S[i]-'0'))%13] = dp[i-1][m];
				dp[i][(m*10+(S[i]-'0'))%13] %= M;
			}
		}
	}
	//
	// for(int i = 0; i < 13; i++){
    //     for(int j = 0; j < S.length(); j++) {
    //         cout << dp[j][i] << ' ';
    //     }
    //     cout << endl;
    // }
    cout << dp[S.length()-1][5];
}

Measured memory_bytes: 8956
#include <bits/stdc++.h>
#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()

using namespace std;
signed main (){
  int a,b;
  cin>>a>>b;
  if(a==1 || b==1){
    cout<<1<<endl;
  }
  else if(a%2==1 && b%2==1){
    cout<<(a*b+1)/2<<endl;
  }
  else{
    cout<<a*b/2<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

ll N;

int main(){
    cin>>N;

    ll ans=0;
    ll n=N;
    for(int i=2;i<=sqrt(N);i++){
        ll cnt=0;
        if(n%i==0){
            while(n%i==0){
                n/=i;
                cnt++;
            }
            //cout<<i<<' '<<cnt<<endl;
            //cout<<ceil((-1+sqrt(1+8*cnt))/2.0)<<endl;
        }
        ans+=floor((-1+sqrt(1+8*cnt))/2.0);
    }
    if(n!=1) ans++;

    cout<<ans<<endl;
}

Measured memory_bytes: 3680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] vals = Console.ReadLine().Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            
            if (vals[3] <= vals[0]) {
                Console.WriteLine(vals[3]);
            }
            else if (vals[3] <= vals[0] + vals[1])
            {
                Console.WriteLine(vals[0]);
            }
            else {
                Console.WriteLine(2*vals[0]+vals[1]-vals[3]);
            }


        }
    }
}


Measured memory_bytes: 28176
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n = 3;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
  	cin >> a[i];
  }

  sort(a.begin(), a.end());
  cout << a[2] - a[0];
}

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

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

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 256
T = int(input())

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

def solve(A, B, C, D):
    if A < B:
        return False
    if D < B:
        return False
    if C >= B:
        return True
    s = A % B
    d = D % B
    n = B - C
    if d == 0:
        return s <= C
    else:
        g = gcd(d, B)
        n = (B - 1 - s) // g
        m = s + n * g
        return m <= C

ABCD = [[int(_) for _ in input().split()] for i in range(T)]

for A, B, C, D in ABCD:
    if solve(A, B, C, D):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i + k) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()

    print()  # データセットの区切り


Measured memory_bytes: 7000
import math
N = int(input())
XY = []
for i in range(N):
  XY.append( list(map(int,input().split())) )

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a =0 
for i in range(N-1):
  a+=combinations_count(N-2,i)*math.factorial(i)*math.factorial(N-2-i)
a *= 2
ans = 0
for i in range(N):
  for j in range(N):
    if i < j:
      x2 = (XY[i][0] - XY[j][0])**2
      y2 = (XY[i][1] - XY[j][1])**2
      ans +=  math.sqrt(x2+y2)  * a
print(ans/math.factorial(N))

  

Measured memory_bytes: 38384
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[30][30][30][30];
char str[30][30];
int calc(int a,int b,int c,int d){
	if(a>=b||c>=d)return 0;
	if(dp[a][b][c][d]!=-1)return dp[a][b][c][d];
	int val[64];
	for(int i=0;i<64;i++)val[i]=0;
	for(int i=a;i<b;i++)for(int j=c;j<d;j++){
		if(str[i][j]=='X')continue;
		int tmp=0;
		tmp^=calc(a,i,c,j);
		tmp^=calc(i+1,b,c,j);
		tmp^=calc(a,i,j+1,d);
		tmp^=calc(i+1,b,j+1,d);
		val[tmp]=1;
	}
	for(int i=0;i<64;i++)if(!val[i])return dp[a][b][c][d]=i;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	for(int i=0;i<30;i++)for(int j=0;j<30;j++)for(int k=0;k<30;k++)for(int l=0;l<30;l++)
		dp[i][j][k][l]=-1;
	int ret=calc(0,a,0,b);
	if(ret)printf("First\n");
	else printf("Second\n");
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    int n;
    cin >> n;
    vector<int> vai(n);
    vector<int> vbi(n);
    REP(i, n)
    cin >> vai[i] >> vbi[i];
    sort(ALL(vai));
    sort(ALL(vbi));
    if (n % 2 == 0) {
        cout << vbi[n / 2] + vbi[n / 2 - 1] - (vai[n / 2] + vai[n / 2 - 1]) + 1 << endl;
    } else {
        cout << vbi[n / 2] - vai[n / 2] + 1 << endl;
    }
}

Measured memory_bytes: 4720
// -*- coding:utf-8-unix -*-

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
// const MOD: i64 = 1000000007;
const MOD: i64 = 998244353;

use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[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 readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuu() -> (usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuuu() -> (usize, usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(unused_macros)]
macro_rules! debug {


    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn solve() {
    let n: usize = read();
    let mut cnt = 0 as usize;
    for i in 0..n {
        let (a, b) = readuu();
        if (a == b) {
            cnt += 1;
        } else {
            cnt = 0;
        }
        if (cnt == 3) {
            println!("Yes");
            return;
        }
    }
    println!("No");

    return;
}
fn main() {
    solve()
}


Measured memory_bytes: 2140
program main
	implicit none
    character(10) A, B, C
	read(*, *) A, B, C
	if(A(len_trim(A):len_trim(A))==B(1:1) .AND. B(len_trim(B):len_trim(B)) == C(1:1)) then
		write(*, *) 'YES'
	else
		write(*, *) 'NO'
	end if
end program main

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf 10000000000000000ll
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-9
#define endl "\n"
/*ll gcd(ll a,ll b)
{
    if(a==0){return b;}
    return gcd(b%a,a);
}
ll modexp(ll x,ll y,ll p)
{
    ll res=1;x%=p;
    while(y>0)
    {   if(y%2==1){res=(res*x)%p;}
        y=y>>1;x=(x*x)%p;
    }return res;
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,a,b;cin>>n>>a>>b;
    cout<<min(n*a,b)<<"\n";



    return 0;

    /*check for long long or int*/
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

        int[] cnt = new int[26];
        for(int i=0; i<w.length(); i++){
            int idx = (int)w.charAt(i) - (int)'a';
            cnt[idx] = cnt[idx] ^ 1;
        }

        int check=0;
        for(int i=0; i<26; i++){
            check += cnt[i];
        }

        if(check == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 20820
#include<cstdio>
#include<algorithm>
//#include<iostream>
//#include<cstring>
//#include<cmath> 
//#include<map>
//#include<queue>
#define rg register

//using namespace std;

inline void read(int &x){
	rg char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-48;
		ch=getchar();
	}
}

inline bool cmp(int a,int b){return a>b;}

const int N=200;
int T,n,a[N],m,sum;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]), sum+=a[i];
	int minn=sum/(m<<2); if(sum%(m<<2))++minn;
	std::sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;++i)
	 if(a[i]<minn){printf("No\n");return 0;}
	printf("Yes\n");
	return 0;
}

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

int main(){
    string s, p;
    getline(cin, s);
    getline(cin, p);
    s += s;
    if(s.find(p) != string::npos){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3208
x = int(input())

import bisect

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

primess = primes(100010)
idx = bisect.bisect_left(primess,x)
print(primess[idx])

Measured memory_bytes: 4200
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector> 
using namespace std;
typedef long long ll;
ll  num[100005];
int vis[100005];
vector<int>  G[100005];
int flag=0;
void dfs(int a,int b)
{
	vis[b]=1;
	int cnt=G[b].size();
	for(int i=0;i<cnt;i++)
	{
		int v=G[b][i];
		if(vis[v]==0)
		{
		   if(num[v]>=num[a])
		   {
		   	 flag=-1;
		   	 return;
			}
		}
	}
}
int main()
{
	int n,m;
	cin>>n>>m;
	int i,j,k,a,b;
	for(i=1;i<=n;i++) cin>>num[i];
	for(i=1;i<=m;i++)
	{
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
    }
    int ans=0;
    for(i=1;i<=n;i++)
    {
    	flag=0;
    	memset(vis,0,sizeof(vis));
       dfs(i,i);
	   if(flag==0) ans++;	
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9788
date = input()
if date == "SUN":
    print(7)
elif date =="SAT":
    print(1)
elif date == "FRI":
    print(2)
elif date == "THU":
    print(3)
elif date == "WED":
    print(4)
elif date == "TUE":
    print(5)
elif date == "MON":
    print(6)

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

typedef pair<int, int> P;
vector<int> h_idx;
vector<int> w_idx;

int main()
{
    int H, W, M;
    cin >> H >> W >> M;
    set<P> s;
    vector<int> row(H);
    vector<int> col(W);
    rep(i, M) {
        int h, w;
        cin >> h >> w;
        h--;
        w--;
        row[h]++;
        col[w]++;
        s.insert(make_pair(h, w));
    }

    int max_row = 0;
    int max_col = 0;
    rep(i, H) max_row = max(max_row, row[i]);
    rep(i, W) max_col = max(max_col, col[i]);

    rep(i, H) {
        if (row[i] == max_row) h_idx.push_back(i);
    }
    rep(i, W) {
        if (col[i] == max_col) w_idx.push_back(i);
    }

    int ans = max_row + max_col;
    for (auto i : h_idx) {
        for (auto j : w_idx) {
            if (s.count(make_pair(i, j)) == 0) {
                cout << ans << endl;
                return 0;
            }
        }
    }

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


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

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

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
    return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
    return y;
}

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

/* 削除する節点yを決定する */
  if(z->left == NIL || z->right == NIL) y = z;/* zが子を最大１つ持つ場合は入力節点のz */
  else y = treeSuccessor(z);/* z が子を2つ持つ場合はzの次節点 */

/*xをyのNILではない子またはyが子を持たない場合はNILに設定 */
  if(y->left != NIL) x = y->left;
  else x = y->right;

/*yの親とxのポインタを変更しyを削除する*/
/*xがNILまたはyが根のときの境界条件を処理*/
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

/* zの次節点が削除されたときにyの内容をzに移動する*/
  if(y != z) z->key = y->key;
}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

 while(x != NIL){
   y = x;
   if(z->key < x->key) x = x->left;
   else x = x->right;
 }
 
 z->parent = y;
 if(y == NIL){
   root = z;
   // printf("root = %d\n" ,z->key);
 }
 else if(z->key < y->key) {
   y->left = z;
   // printf("key = %d yl = %d\n" ,z->key,y->key);
 }
 else {
   y->right = z; 
   // printf("key = %d yr = %d\n" ,z->key,y->key);
 }
 
 
}

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


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

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T> 
struct BIT {
    vector<T> dat;

    BIT (int n) { dat.assign(n + 1, 0); }

    void add(int k, T x) {
        for (++k; k < dat.size(); k += k & -k) dat[k] += x;
    }

    T query(int k) {
        T sum = 0;
        for (++k; k > 0; k -= k & -k) sum += dat[k];
        return (sum);
    }

    int lower_bound(T x) {
        int l, r;
        l = -1, r = dat.size();
        while (l + 1 < r) {
            int m = (l + r) / 2;
            if (query(m) >= x) r = m;
            else l = m;
        }
        return (r);
    }
};

int main() {
    ll N, D, A; cin >> N >> D >> A;
    vector<Pl> dat(N);
    BIT<ll> field(N + 10);

    for (int i = 0; i < N; i++) cin >> dat[i].first >> dat[i].second;
    sort(begin(dat), end(dat));
    
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll sub = field.query(i);
        if (dat[i].second - sub > 0) {
            ll val = dat[i].second - sub;
            ll num = (val + A - 1) / A;
            ans += num;
            field.add(0, num * A);
            field.add(lower_bound(begin(dat), end(dat), Pl(dat[i].first + D * 2 + 1, -LLINF)) - begin(dat), -num * A);
        }
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 4992
/*--ILRS-- sr4saurabh  */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define popb pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+6;
#define M_PI           3.14159265358979323846
//--------------------------------------------



//--------------------------------------------





//============================================
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
       freopen ("INPUT.txt" , "r" , stdin);
       freopen ("OUTPUT.txt", "w" , stdout);
    #endif

	//THE WATER WAS DEEP, I DROWNED AND THEN CAME FLOATING UP,DEAD!!

       	double d,t,s;
       	cin>>d>>t>>s;

       	double time = d/s;
       	if(time <= t)
       		cout<<"Yes";
       	else
       		cout<<"No";










return 0;
}

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

string X,ans;
stack<char> stc;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    cin>>X;
    for(int i = 0;i < X.length();i++){
        if(stc.empty()){
            stc.push(X[i]);
        }
        else if(!(stc.top() == 'S' && X[i] == 'T')){
            stc.push(X[i]);
        }
        else {
            stc.pop();
        }
    }
    cout<<stc.size()<<endl;
}


Measured memory_bytes: 3788
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int s[60][40];
int tizu[60][40][60];

int main() {
	int n;
	while(n=in()){
		int f;
		memset(s,0,sizeof(s));
		int i,j,k;
		for(i=0;i<n;i++){
			cin>>f;
			for(j=0;j<f;j++){
				cin>>k;
				s[i][k]=1;
			}
		}
		int m;
		for(m=0;m<n;m++)tizu[m][0][m]=1;
		for(i=1;i<=30;i++){
			for(j=0;j<n;j++){
				for(m=0;m<n;m++){
					tizu[m][i][j]=tizu[m][i-1][j];
				}
			}
			for(j=0;j<n;j++){
				if(s[j][i]!=1)continue;
				for(k=j+1;k<n;k++){
					if(s[k][i]!=1)continue;
					for(m=0;m<n;m++){
						if(tizu[m][i-1][k]){
							tizu[m][i][j]=1;
						}
						if(tizu[m][i-1][j]){
							tizu[m][i][k]=1;
						}
					}
				}
			}
			bool ok;
			for(j=0;j<n;j++){
				ok=true;
				for(m=0;m<n;m++){
//cout<<m<<" "<<i<<" "<<j<<" "<<tizu[m][i][j]<<endl;
					if(tizu[m][i][j]==0)ok=false;
				}
				if(ok)goto aaa;
			}
		}
		aaa:;
		if(i==31)cout<<-1<<endl;
		else cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 1384
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  size_t n;
  scanf("%zu", &n);
  
  std::vector<int> a(n), b(n);
  for (int &a_i: a) scanf("%d", &a_i);
  for (int &b_i: b) scanf("%d", &b_i);
  
  int res=0;
  int sum1=0, sum2=0;
  for (size_t i=0; i<n; ++i) sum2+=b[i];
  
  for (size_t i=0; i<n; ++i) {
    sum1 += a[i];
    res = std::max(res, sum1+sum2);
    sum2 -= b[i];
  }
  printf("%d\n", res);
}
  

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


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((c>=a && c<=b) || (c<=a && c>=b)){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

int n;
vi a;

int main()
{
    cin >> n;
    a.resize(n); rep(i,n) cin >> a[i];
    double s=0;
    rep(i,n) s+= a[i];
    s /= (double)n;
    int m = round(s);
    int ans = 0;
    rep(i,n){
        ans += (a[i]-m)*(a[i]-m);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256