akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  i64 ans = 1e18;
  auto f = [&](int sum) -> i64 {
    i64 cnt = 0;
    reps(i, n - 1) {
      if (sum > 0) {
        if (sum + a[i] >= 0) {
          cnt += abs(sum + a[i]) + 1;
          sum = -1;
        } else {
          sum += a[i];
        }
      } else {
        if (sum + a[i] <= 0) {
          cnt += abs(sum + a[i]) + 1;
          sum = 1;
        } else {
          sum += a[i];
        }
      }
    }
    return cnt;
  };
  if (a[0] == 0) {
    amin(ans, f(1) + 1);
    amin(ans, f(-1) + 1);
  } else {
    amin(ans, f(a[0]));
    amin(ans, f(a[0] > 0 ? -1 : 1) + abs(a[0]) + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
h,w = map(int,input().split())
temp = []
for _ in range(h):
  l = list(input())
  if l.count('#')!=0:
    temp.append(l)
h = len(temp)
#print(temp)
cols = []
for j in range(w):
  valid = False
  for i in range(h):
    if temp[i][j]=='#':
      valid = True
  if not valid:
    cols.append(j)
for i in range(h):
  for j in range(w):
    if j not in cols:
    	print(temp[i][j],end='')
  print()

Measured memory_bytes: 4596
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    int n,k,l = 0; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> acnt(n);
    
    sort(a.begin(),a.end());
    int cnt = 1;
    rep(i,n){
        if(a[i+1] == a[i]) cnt++;
        else{
            acnt[l] = cnt;
          //cout << acnt[l] << endl;  
          l++;
            cnt = 1;
        }
      //cout << cnt  << endl;
    }
  //cout << acnt[3];
  //rep(i,n) cout << acnt[i] << endl;
    ll ans = 0;
    sort(acnt.begin(),acnt.end());
    reverse(acnt.begin(),acnt.end());
    for(int i = k; i < n;i++){
        ans += acnt[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner  sc=new Scanner(System.in);
	
	          int n=sc.nextInt();
	          int ma=sc.nextInt();
	          int mb=sc.nextInt();
	       int a[]=new int[n];
	       int b[]=new int[n];
	       int c[]=new int[n];
	       for(int i=0;i<n;i++) {
	       	int x=sc.nextInt();
	       	int y=sc.nextInt();
	       	int z=sc.nextInt();
	       	a[i]=x;
	       	b[i]=y;
	       	c[i]=z;
	       }
	       int dp[][][]=new int[n+1][501][501];
	     int max=100000;
	       for(int i=0;i<=n;i++) {
	       	for(int j=0;j<=500;j++) {
	       		for(int k=0;k<=500;k++) {
	       			dp[i][j][k]=max;
	       		}
	       	}
	       }
	       dp[0][0][0]=0;
	       for(int i=1;i<=n;i++) {
	       	for(int j=0;j<=500;j++) {
	       		for(int k=0;k<=500;k++) {
	       			dp[i][j][k]=dp[i-1][j][k];
	       			if(j-a[i-1]>=0 && k-b[i-1]>=0 && dp[i-1][j-a[i-1]][k-b[i-1]]!=max)
	       			dp[i][j][k]=Math.min(	dp[i-1][j-a[i-1]][k-b[i-1]]+c[i-1],dp[i][j][k]);
	       			
	       		}
	       	}
	       }
	       int ans=max;
	      
	       	for(int j=1;j<=500;j++) {
	       		for(int k=1;k<=500;k++) {
	       			if(dp[n][j][k] !=max) {
	       		if((j*mb)==(k*ma)) {
	       			ans=Math.min(ans,dp[n][j][k]);
	       		}
	       		}
	       		}
	       	}
	       if(ans==max) {
	       	System.out.println(-1);
	       }else {
	       	System.out.println(ans);
	       }
	       
	       
	       
	       
	       
	       
	       
	       

		}
	static boolean isValid(int i,int j,int r,int c ) {
			return i>=0&&j>=0&&i<r&&j<c;
	}
	static int[] arr(int n,Scanner sc) {
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		return a;
}
	}


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

int main(){
    while(true){
        int w, h;
        int ver[30][29], hor[29][30];
        int maze[30][30] = {0};
        queue<pair<int, int> > pos;
        int route=0;
        cin >> w >> h;
        if(!(w||h)) break;
        for(int i=0;i<h-1;++i){
            for(int j=0;j<w-1;++j){
                cin >> ver[i][j];
            }
            for(int j=0;j<w;++j){
                cin >> hor[i][j];
            }
        }
        for(int j=0;j<w-1;++j){
            cin >> ver[h-1][j];
        }
        pos.push(make_pair(0,0));
        maze[0][0] = 1;
        while(!pos.empty()){
            int x=pos.front().first, y=pos.front().second;
            if(x==w-1 && y==h-1){
                route = maze[y][x];
                break;
            }
            pos.pop();
            if(x+1<w && ver[y][x]==0 && maze[y][x+1]==0){
                pos.push(make_pair(x+1, y));
                maze[y][x+1] = maze[y][x]+1;
            }
            if(y+1<h && hor[y][x]==0 && maze[y+1][x]==0){
                pos.push(make_pair(x, y+1));
                maze[y+1][x] = maze[y][x]+1;
            }
            if(x-1>=0 && ver[y][x-1]==0 && maze[y][x-1]==0){
                pos.push(make_pair(x-1, y));
                maze[y][x-1] = maze[y][x]+1;
            }
            if(y-1>=0 && hor[y-1][x]==0 && maze[y-1][x]==0){
                pos.push(make_pair(x, y-1));
                maze[y-1][x] = maze[y][x]+1;
            }
        }
        cout << route << endl;
    }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a, b, c;
	cin >> a >> b >> c;
	int pos_a = 0, pos_b = 0, pos_c = 0, turn = 0;
	while(1) {
		if (turn == 0) {
			if (pos_a == a.size()) {
				cout << "A" << endl;
				return 0;
			}
			turn = int(a[pos_a] - 'a');
			pos_a++;
		}
		else if (turn == 1) {
			if (pos_b == b.size()) {
				cout << "B" << endl;
				return 0;
			}
			turn = int(b[pos_b] - 'a');
			pos_b++;
		}
		else {
			if (pos_c == c.size()) {
				cout << "C" << endl;
				return 0;
			}
			turn = int(c[pos_c] - 'a');
			pos_c++;
		}
	}
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    rep(i, 50000){
        if(floor(i*1.08) == N){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}

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

int main(){
    string s; cin>>s;
    for(int i=0,j=s.size()-1; i<j; i++, j--) if(s[i] != s[j]){
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    FOR(i, 1, 10) {
        FOR(j, 1, 10) {
            if (i * j == N) {
                cout << "Yes" << endl;
                exit(0);
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer>plane = new ArrayList<>();
		ArrayList<Integer> reverse = new ArrayList<>();
		
		int n = sc.nextInt();
		int i = 0;
		int input;
		
		while(i < n) {
			input = sc.nextInt();
			plane.add(input);
			i++;
		}
		
		i = 0;
		while(i < n) {
			reverse.add(plane.get(n-1-i));
			i++;
		}
		
		for(i = 0; i < n; i++) {
			if(i == n - 1) {
				System.out.printf("%d", reverse.get(i));
			} else {
				System.out.printf("%d ", reverse.get(i));
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 26420
#include <iostream>

int main() {

    long long int n,m;

    std::cin >> n >> m;

    long long int ans = 0;

    if(n >= m/2){
        ans += m/2;
    }
    else{
        ans += n;
        m -= 2*n;
        ans += m/4;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string st;
int dp[310][310][310],K;
int dfs(int l,int r,int x){
    if(r<l)return 0;
    if(l==r)return 1;
    if(dp[l][r][x]!=-1)return dp[l][r][x];
    int res=max(dfs(l+1,r,x),dfs(l,r-1,x));
    if(st[l]==st[r])res=max(res,dfs(l+1,r-1,x)+2);
    if(x)res=max(res,dfs(l+1,r-1,x-1)+2);
    return dp[l][r][x]=res;
}
int main(){
    cin>>st>>K;
    memset(dp,-1,sizeof(dp));
    cout<<dfs(0,st.size()-1,K)<<endl;
    return 0;
}

Measured memory_bytes: 116608
#include<bits/stdc++.h>
#define db(x) cerr<<#x<<" = "<<x<<endl;
using namespace std;
int f[200005][3];
char ch[200005];
int main(){
	scanf("%s",ch+1);
	//db(ch);
	int len=strlen(ch+1);
	f[0][1]=f[0][2]=0;
	for(int i=1;i<=len;++i){
		if(i>2){
			f[i][1]=max(f[i][1],f[i-1][2]+1);
		}
		if(i>=2){
			f[i][2]=max(f[i][2],f[i-2][1]+1);
		}
		if(ch[i]!=ch[i-1]){
			f[i][1]=max(f[i][1],f[i-1][1]+1);
		}
		if(i>3){
			if(ch[i]!=ch[i-2]||ch[i-1]!=ch[i-3]){
				f[i][2]=max(f[i][2],f[i-2][2]+1);
			}
		}
		//cout<<i<<' '<<f[i][1]<<' '<<f[i][2]<<endl;
	}
	cout<<max(f[len][1],f[len][2]);
	return 0;
}

Measured memory_bytes: 2816
/*input
20
xxzaffeeeeddfkkkkllq
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 1;
    rep(i, n-1) {
        if (s[i] != s[i+1]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

	int X, A, B; cin >> X >> A >> B;

	if (A - B >= 0){
		cout << "delicious" << endl;
	}else{
		if (B - A > X){
			cout << "dangerous" << endl;
		}else{
			cout << "safe" << endl;
		} // end if
	} // end if

	return 0;
}

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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (r <= x && x <= W - r && r <= y && y <= H - r) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3116
import java.util.Scanner;
import java.util.Stack;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		for(;;){
			String s = sc.nextLine();
			if(s.equals("."))break;
			Stack<Integer>stack=new Stack<Integer>();
			boolean f = true;
			for(int i=0;i<s.length();i++){
				if(s.charAt(i)=='('){
					stack.add(1);
				}
				else if(s.charAt(i)=='['){
					stack.add(2);
				}
				else if(s.charAt(i)==')'){
					if(stack.size()==0||stack.pop()!=1){
						f=false;
					}
				}
				else if(s.charAt(i)==']'){
					if(stack.size()==0||stack.pop()!=2){
						f=false;
					}
				}
			}
			if(stack.size()==0){
				if(f){
					System.out.println("yes");
				}
				else{
					System.out.println("no");
				}
			}
			else{
				System.out.println("no");
			}
		}

	}

}

Measured memory_bytes: 32760
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
         public static long GCM(long x,long y)
        {
            if (x < y)  GCM(y, x);


            while (y > 0)
            {
                var z = y;
                y = x % y;
                x = z;
            }
            
            return x;
        }

        



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var hw = Reads();
            long h = hw[0], w = hw[1];
            var a = new char[h][];
            for (int i = 0; i < h; i++)
            {
                a[i] = ReadLine().ToCharArray();
            }
            bool[] x = new bool[h], y = new bool[w];
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (a[i][j] == '#') x[i] = true;
                }
            }
            for (int i = 0; i < w; i++)
            {               
                for (int j = 0; j < h; j++)
                {
                    if (a[j][i] == '#') y[i] = true;
                }
            }
            for (int i = 0; i < h; i++)
            {
                if (!x[i]) continue;
                for (int j = 0; j <w; j++)
                {
                    if (!y[j]) continue;
                    Write(a[i][j]);
                }
                WriteLine();
            }

            






            Console.Out.Flush();
        }
    }
}




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

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    int counter = 0;
    for (int i = 1; i <= N; i++)
    {
        if (i < 10 && i / 10 == 0)
            counter++;
        else if ((i >= 100 && i <= 999) && i / 1000 == 0)
            counter++;
        else if ((i >= 10000 && i <= 99999) && i / 100000 == 0)
            counter++;
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

const int mod = 1e9+7;

int dp[110][10];

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  dp[0][0] = 1;
  rep(i,h) {
    rep(j,w) {
      rep(bit,1<<(w-1)) {
        bool ok = true;
        rep(k,w-2) {
          if ((bit & 1 << k) && (bit & 1 << (k+1))) ok = false;
        }
        if (ok) {
          if (j >= 1 && (bit & 1<<(j-1))) {
            (dp[i+1][j-1] += dp[i][j]) %= mod;
          } else if (j <= w-2 && (bit & 1<<j)) {
            (dp[i+1][j+1] += dp[i][j])%= mod;
          } else {
            (dp[i+1][j] += dp[i][j]) %= mod;
          }
        }
      }
    }
  }
  cout << dp[h][k-1] << endl;
  return 0;
} 

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

int main(){
 int n;
 bool ok = true;
 cin >> n;
 vector<long long int> mon(n);
  for(int i=0;i<n;i++){
   cin >> mon[i];
  }

  sort(mon.begin(),mon.end());
  while(mon[n-2]!=0){

     for(int i=0;i<n;i++){
     if(mon[i]!=0 && ok){
       ok=false;
       for(int j=i+1;j<n;j++){
     mon[j]=mon[j]%mon[i];
   }
   }
 }
 ok=true;
 sort(mon.begin(),mon.end());
}

  cout << mon[n-1] << endl;
}

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


int main() {
    int n, x, t;
    cin >> n >> x >> t;

    if (n % x == 0) {
        int y = n / x;
        cout << y * t << endl;
    }
    else {
        int y = n / x + 1;
        cout << y * t << endl;
    }

    return 0;
}


Measured memory_bytes: 3620
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		k: usize,
		sxy: [(isize, isize); n],
	}

	let mut x = vec![0usize; n];
	let mut y = vec![0usize; n];
	for i in 0..n {
		x[i] = (sxy[i].0 + 1000000000) as usize;
		y[i] = (sxy[i].1 + 1000000000) as usize;
	}

	let mut xs = x.clone();
	let mut ys = y.clone();
	xs.sort();
	ys.sort();

	let mut ans = (xs[n-1] - xs[0])*(ys[n-1] - ys[0]);

	for xi in 0..n-1 {
		for xj in xi+1..n {
			for yi in 0..n-1 {
				for yj in yi+1..n {
					let mut count = 0;
					for i in 0..n {
						if xs[xi] <= x[i] && x[i] <= xs[xj] && ys[yi] <= y[i] && y[i] <= ys[yj] {
							count += 1;
						}
					}
					if count >= k {
						ans = min(ans, (xs[xj]-xs[xi])*(ys[yj]-ys[yi]));
					}
				}
			}
		}
	}
	println!("{}", ans);
}



Measured memory_bytes: 2188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,ans=0,t;
    cin>>n;
    ll a[n+1];
    for(ll i=0; i<n ; i++)
    {
        cin>>a[i];
    }
    for(int i=1; i<n ; i++)
    {
        if(a[i]<a[i-1])
        {
            t=(a[i-1]-a[i]);
            ans+=t;
            a[i]=a[i]+t;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

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

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

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

	string ss[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
	REP(i,8) {
		if(s == ss[i]) {
			cout << 7-i << endl;
			return 0;
		}
	}

}




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

int main(){
    
    int x, i;
    
    for(i = 1; ; i++){
        
        cin >> x;
        
        if(x == 0) break;
        
        cout << "Case " << i << ": " << x << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m;

int main() {
	ll h, w, d, q, l, r, buf;
	cin >> h >> w >> d;
	ll dist[d][h*w/d+1][3];
	
	for(ll i = 1; i <= h; i++){
		for(ll j = 1; j <= w; j++){
			cin >> buf;
			dist[buf%d][buf/d][1] = i;
			dist[buf%d][buf/d][2] = j;
		}
	}
	for(ll i = 1; i <= h*w; i++){
		ll d1 = i%d;
		ll d2 = i/d;
		if(d2 == 0){
			dist[d1][d2][0] = 0;
		}
		else{
			dist[d1][d2][0] = dist[d1][d2-1][0]+abs(dist[d1][d2][1]-dist[d1][d2-1][1])+abs(dist[d1][d2][2]-dist[d1][d2-1][2]);
		}	
	}

	cin >> q;
	for(ll i = 0; i < q; i++){
		cin >> l >> r;
		cout << dist[r%d][r/d][0]-dist[l%d][l/d][0] <<endl;
	}
	return 0;
}

Measured memory_bytes: 4608
#include <stdio.h>

char stack[100];
int sp=0;

int main(int argc, char* argv[]){
	char a, prev='.';

	while(scanf("%c",&a)){
		if(a=='\n') continue;
		switch(a){
			case '(': stack[sp]='('; sp++; break;
			case '[': stack[sp]='['; sp++; break;
			case ')':
				if(sp>0 && stack[sp-1]=='(') sp--;
				else { while(a!='.') scanf("%c",&a); sp=0; printf("no\n"); }
				break;
			case ']':
				if(sp>0 && stack[sp-1]=='[') sp--;
				else { while(a!='.') scanf("%c",&a); sp=0; printf("no\n"); }
				break;
			case '.':
				if(prev=='.') return 0;
				if(sp==0) printf("yes\n"); else printf("no\n"), sp=0;
		}
		prev=a;
	}
}

Measured memory_bytes: 0
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout << setprecision(12)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cin4(x, y, z, _) cin >> x >> y >> z >> _
#define cin5(x, y, z, p, q) cin >> x >> y >> z >> p >> q
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t; cin1(_t); rep(w, 0, _t)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cntv(v,a) count(v.begin(),v.end(),a)
struct point{    int x, y, ind;   char ch;  };
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
bool cmp(point A, point B){   if(A.x != B.x) ret(A.x < B.x);  ret(A.y < B.y);   }
// head collected
// Don't use variable name as --> prev, time, _t, w, y1

ll t, n, k, _, __,ans, re, m;
string str;
ll ara[100007];
priority_queue < ll > pq;

start;

    cin2(n, m);

    rep(i, 0, n){
        cin1( _ );
        pq.push( _ );
    }

    rep(i, 0, m){
        _ = pq.top() / 2;
        pq.pop();
        pq.push( _ );
    }

    while ( ! pq.empty() ) {
        ans += pq.top();
        pq.pop();
    }

    coul(ans);

finish


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int INF = (int)1e9;
int X;

int minTime()
{
	int num = 0;
	for(int i = 1; i <= 50000; ++i)
	{
		num += i;
		if(num >= X)
			return i;
	}
	assert(false);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> X;

	cout << minTime() << endl;

	return 0;
}

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 {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		Judge judge = new Judge('o', 'x');
		
		while(true){
			String str = br.readLine();
			
			if(str == null){
				break;
			}
			
			System.out.println(judge.decideWinner(str));
		}
	}

}

class Judge {
	private char player1;
	private char player2;
	private char draw = 'd';
	
	public Judge(char p1, char p2){
		player1 = p1;
		player2 = p2;
	}
	
	public char decideWinner(String str){
		char[] players = {player1, player2};
		char winner = draw;
		char[] cArray = str.toCharArray();
		
		for(int i = 0; i < players.length ; i++){
			for(int j = 0; j < 3; j++){
				if(cArray[j*3]==players[i] && cArray[j*3 + 1]==players[i] && cArray[j*3 + 2]==players[i]){
					return players[i];
				}
			}
			
			for(int j = 0; j < 3; j++){
				if(cArray[j]==players[i] && cArray[j+3]==players[i] && cArray[j+6]==players[i]){
					return players[i];
				}
			}
			
			if(cArray[0]==players[i] && cArray[4]==players[i] && cArray[8]==players[i]){
				return players[i];
			}

			if(cArray[2]==players[i] && cArray[4]==players[i] && cArray[6]==players[i]){
				return players[i];
			}

		}
		
		return winner;
	}
}

Measured memory_bytes: 24216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
typedef long long ll;
typedef std::pair<ll, int> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
  return firstElof.first < secondElof.first;
}

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;

  vector<P> ab(N);
  
  for (int i = 0; i < N; i++) {
    ll a;
    int b;
    cin >> a >> b;
    ab[i].first = a;
    ab[i].second = b;    
  }

  sort(ab.begin(), ab.end(), pairCompare);
  //cout << ab[0].second;

  ll ans = 0;

  for (int i = 0; i < N; i++) {
    if (ab[i].second >= M) {
      ans += M * ab[i].first;
      break;
    }
    else {
      ans += ab[i].second * ab[i].first;
      M -= ab[i].second;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  string s,t;int count=0;
  cin>>s>>t;
  string ::iterator ptr1,ptr2;
  for(ptr1=s.begin(),ptr2=t.begin();ptr1!=s.end();ptr1++,ptr2++)
  {
    if(*ptr1!=*ptr2)count++;
  }
  cout<<count<<endl;
}
  

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

int main(void){
  int n;
  long sum;

  cin >> n;
  
  int a[n];

  for( int i = 0; i < n; i++ ){
    cin >> a[i];
    sum += a[i];
  }
  
  sort(a,a+n);
  cout << a[0] << " " << a[n-1] << " " << sum << endl;
  
  return 0;
}

Measured memory_bytes: 3148
n = int(input())
A = [int(i) for i in input().split()]
B = []

for i in range(n):
    b = A[i] - ( i + 1)
    B.append(b)
    
B.sort()
ans = 0
for i in range(n):
    ans += abs(A[i] - (B[len(B) // 2] + i + 1))

print(ans)

Measured memory_bytes: 25196
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

int main(void) {
    string s1, s2;
    int a1, a2;
    cin >> s1 >> s2;
    cin >> a1 >> a2;
    
    string aa;
    cin >> aa;
    if (aa == s1)
        a1--;
    else 
        a2--;

    cout << a1 << ' ' << a2 << endl;
    
    return 0;
}



Measured memory_bytes: 256
import sys

init = ''.join(sys.stdin.read().split())

generated_state = {init: 0}

def bfs(root):
    s = 0
    configure = [root]
    while '123456780' not in configure:
        q = iter(configure)
        configure = []
        s += 1
        for c in q:
            i = c.find('0')
            if 0 <= i <= 5:
                t = str.maketrans('0' + c[i+3], c[i+3] + '0')
                t_c = c.translate(t)
                if t_c not in generated_state:
                    generated_state[t_c] = s
                    configure.append(t_c)
            if i >= 3:
                t = str.maketrans('0' + c[i-3], c[i-3] + '0')
                t_c = c.translate(t)
                if t_c not in generated_state:
                    generated_state[t_c] = s
                    configure.append(t_c)
            if i == 0 or i == 1 or i == 3 or i == 4 or i == 6 or i == 7:
                t = str.maketrans('0' + c[i+1], c[i+1] + '0')
                t_c = c.translate(t)
                if t_c not in generated_state:
                    generated_state[t_c] = s
                    configure.append(t_c)
            if i == 1 or i == 2 or i == 4 or i == 5 or i == 7 or i == 8:
                t = str.maketrans('0' + c[i-1], c[i-1] + '0')
                t_c = c.translate(t)
                if t_c not in generated_state:
                    generated_state[t_c] = s
                    configure.append(t_c)
            if '123456780' in generated_state:
                break
    print(s)

bfs(init)

Measured memory_bytes: 37408
#include<iostream>
#include<vector>
#include<cmath>

int main(){
	int n;
	std::vector<std::vector<int>> inList;
	std::vector<std::vector<int>> dpList;

	std::cin>>n;
	
	inList.resize(n);
	dpList.resize(n);

	for(int i=0; i<n; i++){
		inList[i].resize(3, 0);
		dpList[i].resize(3, 0);
	}

	for(int i=0; i<n; i++)
		std::cin>>inList[i][0]>>inList[i][1]>>inList[i][2];

	dpList[0][0]= inList[0][0];
	dpList[0][1]= inList[0][1];
	dpList[0][2]= inList[0][2];


	for(int i=1; i<n; i++){
		dpList[i][0]= inList[i][0] + std::max(dpList[i-1][1], dpList[i-1][2]);
		dpList[i][1]= inList[i][1] + std::max(dpList[i-1][0], dpList[i-1][2]);
		dpList[i][2]= inList[i][2] + std::max(dpList[i-1][0], dpList[i-1][1]);
	}

	std::cout<< std::max(std::max(dpList[n-1][0], dpList[n-1][1]), dpList[n-1][2])<<std::endl;

	return 0;
}

Measured memory_bytes: 11136
n,m = map(int,input().split())

road = {k:[] for k in range(1,n+1)}
for _ in range(m):
  a,b = map(int,input().split())
  road[a].append(b)
  road[b].append(a)


next_visited = [1]
visited = {1:None}
temp_next = []

visit_num = {}
count = 0

while True:
  temp_next = []
  for room in next_visited:
    ava_room = road[room]
    for r in ava_room:
      try:
        visited[r]
      except:
        visit_num[r] = room
        temp_next.append(r)
        visited[r] = None
        
  if temp_next == []:
    break
  next_visited = temp_next

if len(visit_num) != n-1:
  print('No')

else:
  print('Yes')
  for v in sorted(visit_num.items()):
    print(v[1])

  
 

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

using namespace std;

const ll Mod = 1e9 + 7;

ll Rec(ll i,ll Mask);

ll n;
ll a[22][22];
ll Dp[22][1<<22];

int main()
{
    memset(Dp,-1,sizeof(Dp));

    cin>>n;

    for(ll i=0;i<n;i++)
        for(ll j=0;j<n;j++)
            scanf("%I64d",&a[i][j]);

    cout<<Rec(0,0);
}

ll Rec(ll i,ll Mask)
{
    if(i==n)    return 1;

    if(Dp[i][Mask]+1)   return Dp[i][Mask];

    ll Res = 0;

    for(ll j=0;j<n;j++)
        if(!(Mask&(1<<j))&&a[i][j])
            Res += Rec(i+1,Mask|(1<<j));

    return Dp[i][Mask] = Res%Mod;
}

Measured memory_bytes: 721152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int i = 0;
        int x;

        x = sc.nextInt();

        while (x != 0) {
            System.out.printf("Case %d: %d\n", ++i, x);
            x = sc.nextInt();
        }
    }
}


Measured memory_bytes: 62048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N, M, A=0, temp, ans;
    cin >> N >> M;
    for (int i = 0; i < M;i++)
    {
        cin >> temp;
        A += temp;
    }
    if(A>N)
        ans = -1;
    else
        ans = N - A;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
using namespace std;
using Int = int64_t;
constexpr long long int mod = 1e9 + 7;

///aとbの最大公約数を求める関数。計算量はO(log min(a, b))
Int Gcd(Int a, Int b) {
	if (a % b == 0)return b;
	else return Gcd(b, a % b);
}

//aとbの最小公倍数を求める関数。計算量はO(log min(a, b)) 上のGcdとセットでコピペしてね
Int Lcm(Int a, Int b) {
	return a * b / Gcd(a, b);
}

int main() {

	Int A, B; cin >> A >> B;
	cout << Lcm(A, B) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>=b){
    for(int i=0;i<a;i++){
      cout<<b;
    }
  }
  else{
    for(int i=0;i<b;i++){
      cout<<a;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
char s[20];
int main()
{
	scanf("%s",s);
	if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')
		puts("Yes");
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int mi=min(n,m);
    int ma=max(n,m);
    int c=ma;
    int mmi=mi;
    c--;
    while(c--){
        mi*=10;
        mi+=mmi;
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main(){
  int i,j,n,A[100],tmp,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
     count++;
      }
    }
  }

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

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int n,a;
double k,i;
int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin>>n;
   if(n%2==0){
       a=n/2;
       k=double(n);
       i=double(a);
       cout<<fixed<<setprecision(10)<<(double)(i)/n;

   }
   else{
       a=n/2;
       k=double(n);
       i=double(a);
       cout<<fixed<<setprecision(10)<<(double)((i+1)/k);
   }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }
    println!("{}", (n - 1 + k - 2) / (k - 1));
}


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

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

    static class AHaiku {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            out.println(in.string().replace(',', ' '));
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

    }
}



Measured memory_bytes: 22868
until (n = gets.chomp) == "0"
  if n.chr == "-"
    n.slice!(0)
    head = nil
  else
    head = n.slice!(-1).to_i
  end
  n.reverse!

  result = []
  until n.empty?
    result << 10 - n.slice!(0).to_i
    result << 1 + n.slice!(0).to_i
  end
  (0...result.size).each do |i|
    next if result[i] < 10
    result[i] -= 10
    result[i + 1] = 0 unless result[i + 1]
    result[i + 2] = 0 unless result[i + 2]
    if result[i + 1] > 0
      result[i + 1] -= 1
    else
      result[i + 1] += 9
      result[i + 2] += 1
    end
  end

  result.unshift(head) if head
  p (result.reverse*"").to_i
end

Measured memory_bytes: 6116
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	long n, k, q;
	cin >> n >> k >> q;
	int correct[100000];
	for (int i = 0 ; i < n; i++)
	{
		correct[i] = 0;
	}

	for (int i = 0; i < q; i++)
	{
		int tmp;
		cin >> tmp;
		correct[tmp - 1]++;
	}

	int count = 0;
	for (int i = 0; i < n; i++)
	{
		if (k - (q - correct[i]) > 0)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 32256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, m: usize,
        h: [i64; n],
        ab: [(usize1, usize1); m],
    }
    let mut deg = vec![0; n];
    for &(a, b) in &ab {
        if h[a] <= h[b] {
            deg[a] += 1;
        }
        if h[a] >= h[b] {
            deg[b] += 1;
        }
    }
    puts!("{}\n", deg.iter().filter(|&&x| x == 0).count());
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

string word[4]={"dream","dreamer","erase","eraser"};

int main() {
   string S;
   cin>>S;
   reverse(S.begin(),S.end());
   for(int i=0;i<4;i++) reverse(word[i].begin(),word[i].end());
   bool cut=false;
   for(int i=0;i<S.size();){
       cut=false;
       for(int j=0;j<4;++j){
       string w=word[j];
           if(S.substr(i,w.size())==w){
               i+=w.size();
               cut=true;
           }
       }
       if(!cut){
           cout<<"NO"<<endl;
           return 0;
       }
   }
   cout<<"YES"<<endl;
}

Measured memory_bytes: 512
while True:
    n = int(raw_input())
    if n == 0: break
    ans = [0]*7
    for i in xrange(n):
        age = int(raw_input())
        if age <= 9:
            ans[0] += 1
        elif age <= 19:
            ans[1] += 1
        elif age <= 29:
            ans[2] += 1
        elif age <= 39:
            ans[3] += 1
        elif age <= 49:
            ans[4] += 1
        elif age <= 59:
            ans[5] += 1
        else:
            ans[6] += 1
    for c in ans:
        print c

Measured memory_bytes: 4220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n; cin >> n;
	vi h(n); rep(i,n) cin >> h[i];
	int ans = 0;
	int cnt = 0;
	rep2(i,1,n){
		if(h[i-1]>=h[i]){
			cnt++;
			ans = max(ans,cnt);
		}else cnt = 0;
	}
	out(ans);
}




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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            //ここから

            var N = IO.ReadLineToInt();
            var S = IO.ReadLineToString();

            var sum = 1;
            for(int i = 0; i < N-1; i++)
            {
                if (S[i] != S[i + 1])
                {
                    sum++;
                }
            }

            //ここまで
            Console.WriteLine(sum);
            Console.ReadKey();
        }
    }

    static class Func
    {
        static long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); }
        static public int Conbin(int n, int m) { return Factorial(n) / (Factorial(n - m) * Factorial(m)); }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < (long)Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringArray() { return Console.ReadLine().Split(' ').ToList(); }
        static public int[] ReadLineToIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    }
}

Measured memory_bytes: 11232