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

using namespace std;

int main()
{
  double sum=0;
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; ++i)
  {
    cin >> a[i];
    sum+=a[i];
  }
  sum=sum/n;
  sum = round(sum);
  int ans=0;
  for(int i=0; i<n; ++i)
  {
    ans+=(a[i]-sum)*(a[i]-sum);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
	string in;
	while ( cin >> in )
	{
		bool ok = true;
		for ( int i = 0; ok && i < 3; i++ )
		{
			if ( in[i*3] != 's' && in[i*3] == in[i*3+1] && in[i*3+1] == in[i*3+2] )
			{
				cout << in[i*3] << endl;
				ok = false;
			}
		}
		for ( int i = 0; ok && i < 3; i++ )
		{
			if ( in[i] != 's' && in[i] == in[i+3] && in[i+3] == in[i+6] )
			{
				cout << in[i] << endl;
				ok = false;
			}
		}
		if ( ok && in[0] != 's' && in[0] == in[4] && in[4] == in[8] )
		{
			cout << in[0] << endl;
			ok = false;
		}
		if ( ok && in[2] != 's' && in[2] == in[4] && in[4] == in[6] )
		{
			cout << in[2] << endl;
			ok = false;
		}

		if ( ok )
			cout << "d" << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
a = list(map(int, input().split()))

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)



buff = 1

for i in range(N):
    buff = lcm(buff, a[i])
# print(buff)
ans = 0
for i in range(N):
    ans += (buff-1) % a[i]
print(ans)

Measured memory_bytes: 3316
// Author: Wenxing Mei
//   File: a.cpp
//   Date: 2019-03-11 22:39
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define per(i, b, a) for (int i = (int)b - 1; i >= (int)a; --i)
#define repv(ele, cont) for (auto &ele : cont)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// END OF TEMPLATE

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b / a >= c ? c : b / a);
    return 0;
}


Measured memory_bytes: 256
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   double t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>a>>b;
    m=a+b+n;
    {
       (m>=22)?cout<<"bust":cout<<"win"<<endl;
    }
}


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

int x,y;
int data[222][222];

void solve(int h, int w){

  if(data[h][w]) return;
  data[h][w] = h*h+w*w;

  if(h > 200 || w > 200) return;

  solve(h+1, w);
  solve(h, w+1);

}
int main(){

  solve(0, 0);
  
  int h, w;
  while(scanf("%d %d", &h, &w), h){

    x = 222, y = 222;
    for(int i=151;i>0;i--){
      for(int j=151;j>0;j--){
	if(i == h && j == w || i >= j || h*h+w*w > data[i][j] || h*h+w*w == data[i][j] && i <= h) continue;
	if(y*y+x*x == data[i][j] && y > i) x = j, y = i;
	if(y*y+x*x > data[i][j]) x = j, y = i;
      }
    }

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

Measured memory_bytes: 1396
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define all(x) (x).begin(),(x).end()

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int MOD = 1e9+7;

int main()
{
	int x,a,b;
	cin >> x >> a >> b;
	if(a >= b){
		cout << "delicious" << endl;
	}else if(b-a <= x){
		cout << "safe" << endl;
	}else{
		cout << "dangerous" << endl;
	}
}

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

class UnionFind {
private:
  vector<ll> data;

public:
  UnionFind(ll n): data(n, -1) {}

  ll size(ll i) { return -data[find(i)]; }
  bool root(ll i) { return data[i] < 0; }
  bool same(ll i, ll j) { return find(i) == find(j); }

  ll find(ll i) { return root(i) ? i : (data[i] = find(data[i])); }

  bool unite(ll i, ll j) {
    if(same(i, j)) return false;
    data[find(i)] += data[find(j)];
    data[find(j)] = find(i);
    return true;
  }
};

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> W(N);
  REP(i, 0, N) cin >> W[i];
  vector<ll> U(M), V(M), Y(M);
  REP(i, 0, M) cin >> U[i] >> V[i] >> Y[i], U[i]--, V[i]--;

  vector<ll> ord(M);
  REP(i, 0, M) ord[i] = i;
  sort(ord.begin(), ord.end(), [&](const ll i, const ll j) { return Y[i] < Y[j]; });

  ll ans = 0;
  vector<ll> sum(W), cnt(N, 0);
  UnionFind uf(N);

  for (ll i : ord) {
    if (!uf.same(U[i], V[i])) {
      sum[uf.find(U[i])] += sum[uf.find(V[i])];
      cnt[uf.find(U[i])] += cnt[uf.find(V[i])];
      cnt[uf.find(U[i])]++;
      uf.unite(U[i], V[i]);
    } else {
      cnt[uf.find(U[i])]++;
    }

    if (sum[uf.find(U[i])] >= Y[i]) {
      ans += cnt[uf.find(U[i])];
      cnt[uf.find(U[i])] = 0;
    }
  }

  cout << M - ans << endl;
}

Measured memory_bytes: 6528
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = ni(), m = ni();
		int[] a = na(m);
		int s = 0;
		for(int v : a) s += v;
		if(s > n) {
			out.println(-1);
		}
		else {
			out.println(n - s);
		}
	}
		
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 32684
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

template<typename T>
T absi(T x) {
    if (x < static_cast<T>(0)) {
        x *= static_cast<T>(-1);
    }
    return x;
}

int main()
{
    int64_t N;
    std::cin >> N;

    int64_t total = 0;

    std::vector<int64_t> sum;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        total += t;
        sum.push_back(total);
    }

    int64_t min  = INT64_MAX;

    for (size_t i = 0; i < N-1; ++i) {
        auto x = sum[i];
        auto y = total - x;
        min = std::min(min, absi(x - y));
    }
    std::cout << min << std::endl;

    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, h[100000], m = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < n-1; i++) {
        if (h[n - 2 - i] - h[n - 1 - i] > 1) {
            m++;
            break;
        }
        else if (h[n - 2 - i] - h[n - 1 - i] == 1) h[n - 2 - i]--;
    }
    if (m) cout << "No" << endl;
    else cout << "Yes" << endl;



}

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int L,R,d;

signed main(){
	cin>>L>>R>>d;
	int ans=0;
	for(int i=L;i<=R;i++){
		if(i%d==0){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> ans;
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      if (N % 2) {
        if (i + j == N) continue;
        ans.emplace_back(i, j);
      } else {
        if (i + j == N + 1) continue;
        ans.emplace_back(i, j);
      }
    }
  }
  cout << ans.size() << endl;
  for (auto x : ans) {
    cout << x.first << " " << x.second << endl;
  }

  return 0;
}

Measured memory_bytes: 384
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    pts = []

    def cp(i,j,r):
        xi,yi = i
        xj,yj = j
        cx = (xi+xj)/2
        cy = (yi+yj)/2
        vecx = yj-yi
        vecy = xi-xj
        d = math.sqrt(vecx**2+vecy**2)/2
        kt = math.sqrt(vecx**2+vecy**2)
        vecx /= kt
        vecy /= kt
        if d > r:
            return []
        else:
            d2 = math.sqrt(r**2-d**2)
            return [(cx+vecx*d2,cy+vecy*d2),(cx-vecx*d2,cy-vecy*d2)]

    def dist(i,j,r):
        xi,yi = i
        xj,yj = j
        return math.sqrt((xj-xi)**2+(yj-yi)**2) <= r

    for _ in range(n):
        pts.append(tuple(map(int,ipt().split())))

    l = 0
    r = 1000
    while r-l > 10**(-7):
        mid = l+(r-l)/2
        f = False
        for i in pts:
            for j in pts:
                if i == j:
                    continue
                for li in cp(i,j,mid):
                    f = True
                    for k in pts:
                        if k == i or k == j:
                            continue
                        if not dist(li,k,mid):
                             f = False
                    if f:
                        break
                if f:
                    break
            if f:
                break
        if f:
            r = mid
        else:
            l = mid
    print(l)

    return

if __name__ == '__main__':
    main()


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

int main() {
  int K;
  string S;
  cin >> K >> S;
    size_t size = S.length();
  if (size <= K){
     cout << S << endl;
  }
  else {
     cout << S.erase(K) << "..."<< endl;
  }
}

Measured memory_bytes: 3624
n = gets.to_i
m = gets.to_i
target = gets.split.map(&:to_i)
score = [0] * n 

m.times {|k|
    vote = gets.split.map(&:to_i)
    (0..n-1).each{|i|
        j = (vote[i] == target[k]) ?
            i :
            target[k] - 1 
        score[j] += 1
    }   
}

puts score

Measured memory_bytes: 6116
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,k,a[20];
signed main(){
  cin>>n>>k;rep(i,n)cin>>a[i];
  int ans = INF;
  rep(bit, 1<<n){
    int cnt = 0, sum = 0, max = 0;
    rep(i,n)if(bit&(1<<i))cnt++;
    if(cnt != k)continue;
    rep(i,n){
      if(bit&(1<<i)){
        if(max < a[i]){
          max = a[i];
        }else{
          max++;
          sum += max - a[i];
        }
      }else{
        chmax(max, a[i]);
      }
    }
    chmin(ans, sum);
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n;
pair<int,int> p[N];
int tr[N],r[N],l[N],dp[N];
const int mod=1e9+7;
vector<int> v;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&p[i].first,&p[i].second),v.push_back(p[i].second);
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++) p[i].second=lower_bound(v.begin(),v.end(),p[i].second)-v.begin()+1;
    sort(p+1,p+n+1);l[n+1]=1e9+9;tr[n+1]=1e9+9;
    for(int i=1;i<=n;i++) r[i]=max(r[i-1],p[i].second);
    for(int i=n;i>=1;i--) l[i]=min(l[i+1],p[i].second);
    long long tot=1;
    dp[0]=1;r[0]=l[1]-1;l[n+1]=r[n]+1;
    for(int i=1,p=0;i<=n+1;i++){
        while(r[p]+1<l[i]) tot-=dp[p],p++;
        dp[i]=tot%mod;tot+=dp[i];
    }
    cout<<(dp[n+1]+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 5876
def how_many_times(k, i)
  x = i
  c = 0
  
  while x < k do
    x *= 2
    c += 1
  end
  
  return c
end

def main(argv)
  (n, k) = gets.chomp.split(' ').map(&:to_i)
  
  s = 0.0
  (1..n).each do |i|
    x = how_many_times(k, i)
    s += (0.5 ** x)
  end
  
  puts (s / n.to_f).round(12).to_s
end
 
if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
N=int(input())
from collections import defaultdict
p=defaultdict(int)
def f(n):
    for i in range(2,int(n**.5)+1):
        x=0
        while n%i==0:
            n//=i
            x+=1
        if x:
            p[i]+=x
    if n>1:
        p[n]+=1
for i in range(2,N+1):
    f(i)
from functools import reduce
print(reduce(lambda x,y:x*(y+1),p.values(),1)%(10**9+7))

Measured memory_bytes: 9716
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, m = IN()
	#s = input()
	nokori = [0]*n
	max_path_from = [0]*n
	path = []
	tl = [[] for _ in range(n)]
	for _ in range(m):
		f, t = IN()
		f,t=f-1, t-1
		path.append((f,t))
		nokori[t] += 1
		tl[f].append(t)
	sl=[i for i, v in enumerate(nokori) if v == 0]
	mp=0
	while len(sl) > 0:
		next_l = []
		for v in sl:
			for t in tl[v]:
				nokori[t] -= 1
				if nokori[t] == 0:
					next_l.append(t)
		sl = next_l
		mp+=1
	print(mp-1)
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 68768
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * size
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        """
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x

    def sum(self, i):
        """
        [0, i) の合計
        :param int i:
        """
        ret = 0
        while i > 0:
            ret += self._bit[i - 1]
            i -= i & -i
        return ret

    def __len__(self):
        return self._size


def argsort(li, key=None, reverse=False):
    return [i for _, i in sorted(
        [(a, i) for i, a in enumerate(li)], key=(lambda t: key(t[0])) if key else None, reverse=reverse
    )]


N, M, Q = list(map(int, sys.stdin.buffer.readline().split()))
LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
PQ = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]

LR.sort(reverse=True)
idx = argsort(PQ, reverse=True)
PQ.sort(reverse=True)

lri = 0
bit = BinaryIndexedTree(size=N + 1)
ans = [0] * Q
for i, (p, q) in enumerate(PQ):
    while lri < len(LR) and LR[lri][0] >= p:
        l, r = LR[lri]
        bit.add(r, 1)
        lri += 1
    ans[idx[i]] = bit.sum(q + 1)
print(*ans, sep='\n')


Measured memory_bytes: 102620
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	long long A,B,K;
	cin >> A >> B >> K;

	if(A+B<=K){
		cout << "0" << " " << "0" << endl;
	}
	else{
		if(A>=K){
			cout << A-K << " " << B << endl;
		}
		else{
			cout << "0" << " " << B-(K-A) << endl;
		}
	}
}

Measured memory_bytes: 384
class BIT(object):

    def __init__(self, n):
        self.n=n
        self.lst=[0]*(n+1)

    def put(self, i):
        while(i<=self.n):
            self.lst[i]+=1
            i+=(i&-i)

    def get(self, i):
        ret=0
        while(i!=0):
            ret+=self.lst[i]
            i-=(i&-i)
        return ret

if __name__ == '__main__':
    ipt=input().split(' ')
    n=int(ipt[0])
    k=int(ipt[1])
    a=[(0,1)]
    for i in range(n):
        a.append((a[-1][0]+int(input())-k, i+2))
    a.sort()
    bit=BIT(n+1)
    ret=0
    for e in a:
        ret+=bit.get(e[1])
        bit.put(e[1])
    print(ret)


Measured memory_bytes: 33268
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

ll A;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	cin >> A;
		
	for (ll B = 1; B <= 3500; B++)
		for (ll C = B; C <= 3500; C++) {
			ll Z = 4 * B * C - A * (B + C);
			ll Q = A * B * C;
			if (Z > 0 && Q % Z == 0) {
				cout << B << " " << C << " " << Q / Z << endl;
				return 0;
			}
		}
	throw;

	return 0;
}


Measured memory_bytes: 256
x, y = gets.chomp.split(' ').map(&:to_i)
while x != 0 || y != 0
    if x < y
        x=x.to_s
        y=y.to_s
        puts (x+' '+y)
    else
        x=x.to_s
        y=y.to_s
        puts (y+' '+x)
    end
    x, y = gets.chomp.split(' ').map(&:to_i)
end

Measured memory_bytes: 8808
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int x,y;

int main(){
    read2i(x,y);
    if(x % y == 0) return cout <<-1, 0;
    lp(i,2,infi) if(1ll * i * x % y) return cout <<1ll * i * x, 0;
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  char moji[10010];
  int i,joi,ioi;
  while(scanf("%s",moji)==1)
  {
    joi=0;
    ioi=0;
    for(i=1;moji[i+1];i++)
    {
      if(moji[i]=='O'&&moji[i+1]=='I')
      {
        if(moji[i-1]=='J')joi++;
        if(moji[i-1]=='I')ioi++;
      }
    }
    printf("%d\n",joi);
    printf("%d\n",ioi);
  }
  return 0;
}



Measured memory_bytes: 2036
/*-------------------------------*
| Name: Ayush Kumar              |
| Site: atcoder                  |
| Email: ayushkr667@gmail.com    |
*-------------------------------*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define INF (ll) 1e18
const double PI = 3.141592653589793238460;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, k;
    cin>>n>>k;
    ll arr[n+1];
    for (ll i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    ll dp[n+1];
    dp[1] = 0;
    for (ll i = 2; i <= n; i++)
    {
        dp[i] = INF;
        for (ll j = 1; j <= k; j++)
        {
            if( i-j >= 1)
            {
                dp[i] = min(dp[i], (dp[i-j] + abs(arr[i] - arr[i-j])));
            }
        }
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 5208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const int INF = 1e9;
int dp[100010];

int main(){
  int n;
  cin >> n;
  rep(i,n+1) dp[i] = INF;
  dp[0] = 0;
  for (int i = 0; i <= n;i++){
    for (int pow6 = 1; pow6 + i <= n;pow6*=6){
      dp[i + pow6] = min(dp[i + pow6],dp[i] + 1);
    }
    for (int pow9 = 1; i + pow9 <= n;pow9*=9){
      dp[i + pow9] = min(dp[i + pow9],dp[i] + 1);
    }
  }
  cout << dp[n] << endl;
  
  

  
  return 0;
  
}


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

int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/

	int n, cnt = 0;
	cin >> n;

	long long a[n], sum = 0, mini = LLONG_MAX;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += abs(a[i]);
		if(a[i] < 0)
			cnt++;
		mini = min(mini, abs(a[i]));
	}
	if(cnt % 2)
		sum = sum - 2 * mini;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
stack<char> s;
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	ll n;
	slld(n);
	while(n>0){
		n--;
		s.push('a'+(n%26));
		n/=26;
	}
	while(! s.empty()){
		cout << s.top();
		s.pop();
	}
	return 0;
}

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

int main() {
  char s;
  int a = 0;
  for (int i=0; i<4; i++) {
    cin >> s;
    if (s == '+') {
      a += 1;
    }else {
      a -= 1;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll k,x;
  cin >> k >> x;
  for(int i=x-k+1;i<=x+k-1;i++){
    cout << i<<" ";
  }
  cout << endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    a = list(map(int, readline().split()))
    S = sum(a)
    b = list(map(lambda x: abs(S - N * x), a))
    print(b.index(min(b)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62048
#include<stdio.h>
int main()
{
    int i,n,k;
    scanf("%d%d",&n,&k);
    int ara[n];
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    }
    int count=0;
    for(i=0;i<n;i++){
        if(ara[i]>=k)
            count++;
    }
    printf("%d\n",count);

}


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

int main(void){
    int n,ans=0 ;
    cin >> n ;
    ans+=min(n,9) ;
    ans+=max(0,min(n-99,900)) ;
    ans+=max(0,min(n-9999,90000));
    cout << ans << endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
 
typedef long long ll;

int main(){
	int N,M;
	cin>>N>>M;
	ll a[N],b[N];
	ll c[M],d[M];
	REP(i,N)cin>>a[i]>>b[i];
	REP(i,M)cin>>c[i]>>d[i];
	REP(i,N){
		ll dist = 1e9;
		int id = -1;
		REP(j,M){
			if(dist>abs(a[i]-c[j])+abs(b[i]-d[j])){
				dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
				id = j;
			}
		}
		cout<<id+1<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define MOD 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;

	vector<ll> V1, V2;
	V1.pb(0);
	V1.pb(0);
	V2.pb(0);
	for(int i = 1; i < S.size(); i ++){
		V1.pb(V1[i]);
		if(S[i] == 'C' && S[i - 1] == 'A')V1[i + 1] ++;
	}
	for(int i = 0; i < S.size() - 1; i ++){
		V2.pb(V2[i]);
		if(S[i] == 'A' && S[i + 1] == 'C')V2[i + 1] ++;
	}
	V2.pb(V2[S.size() - 1]);

	int l, r;
	for(int i = 0; i < Q; i ++){
		cin >> l >> r;
		cout << V1[r] - V2[l - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 2740
#!python3.4
# -*- coding: utf-8 -*-
# panasonic2020/panasonic2020_c
import sys
from math import sqrt

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))


def main():
    a, b, c = i2nn()
    if a + b >= c:
        print('No')
        return
    if 4 * a * b < (c - a - b)**2:
        print('Yes')
    else:
        print('No')
    return

main()


Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
    int a,b,c,d,e,f,g,h,i,j,k;
    b=0,c=0,d=0,e=0,f=0,g=0,h=0;
      for(;;){
            b=0,c=0,d=0,e=0,f=0,g=0,h=0;
            scanf("%d",&j);
            if(j==0)break;
        for(i=0;i<j;i++){
            scanf("%d",&a);
            if(0<=a&&a<=9){
                b=b+1;
            }else if(10<=a&&a<=19){
                c=c+1;
            }else if(20<=a&&a<=29){
                d=d+1;
            }else if(30<=a&&a<=39){
                e=e+1;
            }else if(40<=a&&a<=49){
                f=f+1;
            }else if(50<=a&&a<=59){
                g=g+1;
            }else if(60<=a){
                h=h+1;
            }
        }
    printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",b,c,d,e,f,g,h);

      }

return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
#define ll long long
string s1, s2, s3;
ll n1, n2;
ll a[200005], f;
int main()
{
	cin >> n1;
	for(int i = 1; i <= n1; i++) cin >> a[i];
	sort(a + 1, a + 1 + n1);
	for(int i = 1; i < n1; i++)
	{
		if(a[i] == a[i + 1])
		{
			f = 1;
			break;
		}
	}
	if(f == 1) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

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

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


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans[] = fibo(n);
		System.out.println(ans[n]);
	}

	public static long[] fibo(int n) {
		long memo[] = new long[n + 1];
		memo[0] = 1;
		memo[1] = 1;
		for (int i = 2; i < memo.length; i++) {
			memo[i] = memo[i - 1] + memo[i - 2];
		}
		return memo;
	}
}



Measured memory_bytes: 26344
#include<stdio.h>
int main(){
    long long int a,b,k;
    scanf("%llu %llu %llu",&a,&b,&k);
    if(a<k){
        k=k-a;
        a=0;
        if(b<k){
            b=0;
        }else{
            b=b-k;
        }
    }else{
        a=a-k;
    }
    printf("%llu %llu\n",a,b);
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main(){
    int N,M,a,b;
    cin >> N >> M;
    vector<int> vc(N);
    for(int i=0;i<M;i++){
        cin >> a >> b;
        vc[a-1]++;
        vc[b-1]++;
    }
    for(int i=0;i<vc.size();i++){
        cout << vc[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define hell 1000000007
using namespace std;
void solve( ll n)
{
  ll m,i,j,k,c=0,y=0,ans=0,a,b;
  string s;
  cin>>n>>k;
  rep(i,0,n)

  {
      cin>>a>>b;
      if(a*a+b*b<=k*k) ans++;
  }
  cout<<ans;


}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    solve(t);
}


Measured memory_bytes: 3648
def main():
    n, k = map(int, input().split())
    s = []
    ans_temp = [i for i in range(1, n+1)]
    for _ in range(k):
        d = int(input())
        As = map(int, input().split())
        s.extend(As)
    ans = len(set(ans_temp)) - len(set(s))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
import java.util.*;
public class Main  {
   public static void main(String[] args)  {
      Scanner sc = new Scanner(System.in);
      
      int n = sc.nextInt();
      
      int a[] = new int[n];
      
      for (int i = 0; i < n; i++) {
         a[i] = 0;
      }

      for (int j = 0; j < n - 1; j++) {
         int b = sc.nextInt();
         a[b-1] += 1;
      }
      
      for (int k = 0; k < n; k++) {
         System.out.println(a[k]);
      }
   }
}


Measured memory_bytes: 60776
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct edge{int to,cost;};
vector<edge>es[20];
int all_cost;
int min_cost;
void get_all_cost(int at_pos,int prev_pos,int prev_cost){
    bool end_flag=true;
    for(int i=0;i<es[at_pos].size();i++){
        edge &e=es[at_pos][i];
        if(e.to==prev_pos)continue;
        end_flag=false;
        get_all_cost(e.to,at_pos,e.cost);
    }
    if(!end_flag)all_cost+=prev_cost*2;
}
void get_min_cost(int at_pos,int prev_cost,int sum_cost){
    bool end_flag=true;
    for(int i=0;i<es[at_pos].size();i++){
        edge &e=es[at_pos][i];
        if(e.to==prev_cost)continue;
        end_flag=false;
        get_min_cost(e.to,at_pos,sum_cost+e.cost);
    }
    if(!end_flag){
        min_cost=min(min_cost,all_cost-sum_cost);
    }
}
int main(){
    int n;
    while(scanf("%d",&n),n){
        for(int i=0;i<n;i++)es[i].clear();
        all_cost=0;
        for(int i=0;i<n-1;i++){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            a--;b--;
            es[a].push_back((edge){b,c});
            es[b].push_back((edge){a,c});
        }
        get_all_cost(0,-1,0);
        min_cost=all_cost;
        get_min_cost(0,-1,0);
        printf("%d\n",min_cost);
    }
    return 0;
}

Measured memory_bytes: 1052
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2017
#define LL long long
#define INF 0x3f3f3f3f
#define MAXN 200005
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
int main()
{

    int n, m, k;
    cin >> n >> m >> k;
    int i;
    for (i = n; i < n+k && i <= m; i++) {
        cout << i << endl;
    }
    for (int j = max(i, m-k+1); j <= m; j++) {
        cout << j << endl;
    }
    return 0;
}



Measured memory_bytes: 256
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    string s;
    cin >> s;
    array<string, 7> t = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    auto i = distance(t.begin(), find(t.begin(), t.end(), s));
    cout << 7 - i << endl;
    return 0;
}


Measured memory_bytes: 3588
#DP-E
def main():
    import sys, copy
    N, W = map(int, sys.stdin.readline().split())
    L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
    #print(L)
    #価値テーブルを作成
    dp =[[10**11+1 for _ in range(10**5+1)] for _ in range(N)]
    dp[0][L[0][1]] = L[0][0] #初期設定
    #print(dp)
    for i in range(1, N):
        #1. 前回のコピー
        dp[i] = copy.copy(dp[i-1]) 
        w, v = L[i][0], L[i][1]
        #print(w, v)
        #2. 今回の荷物の更新
        dp[i][v] = min(w, dp[i][v])
        #3. 前回の荷物 + 今回の荷物の更新
        for j in range(10**5+1-v):
            if dp[i-1][j] !=0:
                dp[i][v+j] = min(dp[i][v+j], w + dp[i-1][j])
    
    
    
    ans = 0
    for v1,w1 in enumerate(dp[-1]):
        if w1 <= W:
            if ans < v1:
                ans = v1
            #print(v1, w1)
    print(ans)

if __name__ =='__main__':
    main()

Measured memory_bytes: 205064
#include <iostream>

#define SIZE 100

int H, W, N;
int a[SIZE*SIZE];
int board[SIZE][SIZE];

void debug() {
    std::cout << "Debug: \n";
    for (int h=0; h<H; ++h) {
        for (int w=0; w<W; ++w) {
            std::cout << board[h][w] << ' ';
        }
        std::cout << '\n';
    }
}

void solve() {
    int color = 1;
    int dw = 1, w=0, h=0;
    while (a[N-1] != 0) {
        // debug();
        board[h][w] = color;
        --a[color-1];
        // Change Direction
        if ((dw == 1 && w == W-1) || (dw == -1 && w == 0)) {
            w += dw;
            dw = (-1)*dw;
            ++h;
        }
        w += dw;
        if (a[color-1] == 0) ++color;
    }
    for (h=0; h<H; ++h) {
        for (w=0; w<W; ++w) {
            std::cout << board[h][w] << ' ';
        }
        std::cout << '\n';
    }
}

int main() {
    std::cin >> H >> W
             >> N;
    for (int i=0; i<N; ++i) std::cin >> a[i];
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int lli;
typedef pair<int, int> P;

int main() {
	int H, W;
	cin >> H >> W;
	char s[50][50];
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) cin >> s[i][j];
	}
	//最初に#の個数をカウント
	int sh = 0;
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) {
			if (s[i][j] == '#') sh++;
		}
	}

	//ゴールまでの最短距離を幅優先探索で見つける
	//d[i][j]で(i,j)までの最短距離
	int d[50][50];
	//移動のベクトルを決めておく
	int dx[4] = { 1,0,-1,0 };
	int dy[4] = { 0,1,0,-1 };

	queue<P> que;
	//最短距離を-1で初期化
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) d[i][j] = -1;
	}
	//スタートをキューに入れて距離0に
	que.push(P(0, 0));
	d[0][0] = 0;
	//キューにものがなくなるまでループ
	while (que.size()) {
		//先頭を取り出す
		P p = que.front();
		que.pop();
		//これがゴールなら終わり
		if (p.first == H - 1 && p.second == W - 1) break;
		//移動の4方向をループ
		for (int i = 0;i < 4;i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (0 <= nx && nx < H && 0 <= ny && ny < W && s[nx][ny] == '.' && d[nx][ny] == -1) {
				//移動可能ならキューにいれて距離を確定させる
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	int min = d[H - 1][W - 1];
	if (min == -1) cout << min;
	else cout << H * W - sh - min - 1;
}

Measured memory_bytes: 256
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T>
void in(T& x) {
    std::cin >> x;
}

template <typename T>
void out(const T H) {
    std::cout << (H);
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << (H) << " "; out(T...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << v.first << " " << v.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    int n = (int) v.size();
    for (int i = 0; i < n - 1; ++i) os << v[i] << ' ';
    return os << v[n - 1];
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define err(args...)      eout(#args, args)

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "No\n"
#define yes               std::cout << "Yes\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 1000*1000*1000 + 7;

int solve();
int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    //std::cout.tie(0);

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

int solve() {
    inn(n);
    vi h(n); rep(i, n) in(h[i]);

    --h[0]; repr(i, 1, n) if (h[i] > h[i - 1]) --h[i];

    bool ans = 1;
    rep(i, n - 1) {
        ans &= (h[i] <= h[i + 1]);
    }
    ans ? yes : no;

    return 0;
}


Measured memory_bytes: 640
// D - People on a Line

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

struct Edge {
	int to;
	int dist;
};

struct Node {
	vector<Edge> edges;
	int x = INF;
	int visited = false;
};

Node nodes[100000];

bool dfs(int i) {
	if (nodes[i].visited) return true;
	else nodes[i].visited = true;

	for (Edge e : nodes[i].edges) {
		if (nodes[e.to].visited) {
			if (nodes[e.to].x == nodes[i].x + e.dist) continue;
			return false;
		} else {
			nodes[e.to].x = nodes[i].x + e.dist;
			if (dfs(e.to) == false) {
				return false;
			}
		}
	}

	return true;
}

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

	for (int i=0; i<M; i++) {
		int L, R, D;
		cin >> L >> R >> D;
		L--;
		R--;
		nodes[L].edges.push_back(Edge{R, D});
		nodes[R].edges.push_back(Edge{L, -D});
	}

	bool result = true;

	for (int i=0; i<N; i++) {
		if (dfs(i) == false) {
			result = false;
			break;
		}
	}

	if (result == true) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}

int main() {
  int64_t n, a, b;
  cin >> n >> a >> b;
  if ((b-a)%2 == 0) {
    cout << (b-a)/2 << endl;
  } else {
    cout << min(a-1, n-b) + 1 + (b-a-1)/2 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int n,m,p[100005],c[100005],cn[100005],cnt;
vector <int> ve[100005];
void dfs(int x,int nc){
	c[x]=nc;
	for (int i=0;i<ve[x].size();i++){
		if (!c[ve[x][i]]){
			dfs(ve[x][i],nc);
		}
	}
}
int main(){
	int nc=0;
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;i++) cin>>p[i];
	for (int i=0;i<m;i++){
		int f,t;
		cin>>f>>t;
		ve[f].push_back(t);
		ve[t].push_back(f);  
	}
	for (int i=1;i<=n;i++) if (!c[i]) dfs(i,++nc);
	for (int i=1;i<=n;i++){
		cn[p[i]]=c[i];
	}
	for (int i=1;i<=n;i++){
		if (cn[i]==c[i]) cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <algorithm>
#include <list>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cfloat>
#include <climits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <numeric>
#include <functional>
#include <utility>
#include <iomanip>
#include <iterator>
#include <stack>
#include <limits>
#include <sstream>
#include <fstream>
#include <ostream>
#include <bitset>
#include <queue>
#include <ctime>
#include <utility>

#define ms(a,n) (memset(a,n,sizeof(a)))
#define msv(a,v,n) for(int _a;_a<=n;_a++) a[_a]=v;
#define all(res) res.begin(),res.end()
#define mp(a,b) (make_pair(a,b))
#define pb(n) push_back(n)
#define mod 1000000007

using namespace std;

template<class T1> void deb(T1 e){cout<<e<<'\n';}
template<class T1,class T2> void deb(T1 e1,T2 e2){cout<<e1<<" "<<e2<<'\n';}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3){cout<<e1<<" "<<e2<<" "<<e3<<'\n';}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<'\n';}
template<class T> inline T gcd(T a,T b) {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

typedef long long ll;
typedef pair< int, int> PII;
typedef vector< int> VI;
typedef vector< vector<int> > VVI;
typedef map< string, int> MSI;

ostream_iterator<int> screen(cout," ");
//copy(all(res),screen);

const int  sz=2*1000*100+10;
const int inf=INT_MAX>>1;
const ll big=(1LL<<62);
const double pi =acos(-1.0);
int dx[]={0,0,1,-1,1,1,-1,-1},dy[]={1,-1,0,0,1,-1,1,-1};
VI res;

ll powermod(ll n,ll p)
{
    ll x=1,y=n%mod;
    while(p)
    {
        if(p&1LL)
            x=(y*x)%mod;
        y=(y*y)%mod;
        p=p>>1LL;
    }
    return x;
}

int main()
{
    //std::ios_base::sync_with_stdio(false);
    int arr[5],brr[5];
    while(cin>>arr[0])
    {
        int a1=0,a2=0;
        for(int i=1;i<4;i++)
            cin>>arr[i];
        for(int i=0;i<4;i++)
            cin>>brr[i];
        for(int i=0;i<4;i++)
            if(arr[i]==brr[i])
                a1++;
        for(int i=0;i<4;i++)
            for(int j=0;j<4;j++)
                if(i!=j&&arr[i]==brr[j])
                    a2++;
        cout<<a1<<' '<<a2<<endl;
    }

    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='S')
        cout<<"Cloudy"<<endl;
    if(s[0]=='C')
        cout<<"Rainy"<<endl;
    if(s[0]=='R')
        cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 256