akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define llu unsigned long long 
#define ll long long 
ll read() { ll  x; if (scanf("%lld", &x) == -1)exit(0); return x; }
#define vi vector<int>
#define vb vector<bool>
#define LOCAL_JUDGE
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

bool is_a_solution(vi& a, int k, int n) {
    return (k == n);
}


void construst_candidates(vi& a, int k, int n, int c[], int* candidates) {
    c[0] = 1;
    c[1] = 0;
    *candidates = 2;
}

double min_cost = 1e9;
int min_cost_int = 1e9 + 1;

void process_solution(vector<vi>& data, vi& cost, int x, vi& a, int k) {
    int m = data.size();
    int n = data[0].size();

    bool status = true;
    for (int j = 0; j < m; ++j) {
        int s = 0;
        for (int i = 1; i <= k; ++i) {
            if (a[i] == 1) {
                s += data[j][i - 1];
            }
        }
        if (s < x) {
            status = false;
            break;
        }
    }

    if (status) {
        int s = 0;
        for (int i = 1; i <= k; ++i)
            if (a[i] == 1) s += cost[i - 1];
        min_cost_int = min(min_cost_int, s);
    }
}

void backtrack(vector<vi>& data, vi& cost, int x, vi& a, int k, int input) {
    int c[2];
    int ncandidates;
    int i;

    if (is_a_solution(a, k, input)) {
        process_solution(data, cost, x, a, k);
    }
    else {
        k = k + 1;
        construst_candidates(a, k, input, c, &ncandidates);
        for (i = 0; i < ncandidates; ++i) {
            a[k] = c[i];
            backtrack(data, cost, x, a, k, input);
        }
    }
}

int main() {
    //c_p_c();
    int n = read(); int m = read();
    vector<vi> A; vi cost;A.resize(m);
    rep(i, 0, m) A[i].resize(n);
    int x = read();
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m + 1; j++) {
            if (j == 0) cost.push_back(read());
            else A[j - 1][i] = read();
        }
    }
    vi a; a.resize(n + 1);
    backtrack(A, cost, x, a, 0, n);
    if (min_cost_int == 1e9 + 1) cout << -1 << endl;
    else cout << min_cost_int << endl;
}



Measured memory_bytes: 3692
n,a,b = map(int,input().split())



def main():
    nsum = (a+b)
    #n<=(a+b)
    if(a==0):
        print(0)
        return

    if(n<=nsum):
        if(n<a):
            print(n)
        else:
            print(a)
        return
    else:
        div = n//nsum
        remain = n - div*nsum
        ans = div*a
        if(remain<=a):
            ans += remain
        else:
            ans += a
        print(ans)
        return
        
main()        




Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int a[200000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	priority_queue<P>p;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		p.push(P{ u,v });
	}
	int t = 0;
	sort(a, a + n);
	while (!p.empty()&&t<n) {
		P k = p.top(); p.pop();
		if (a[t] >= k.cost) break;
		for (int i = 0; t + i < n && a[t + i] < k.cost && i < k.pos; i++) {
			a[t + i] = k.cost;
		}
		t += k.pos;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += a[i];
	}
	cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  int count = 0;
  for (int a = 1; a < n; a++) { 
    for (int b = 1; a*b < n; b++) {  // decrease number of loop by compare a*b<n, rather than b<n then if(a*b<n)
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3576
n = STDIN.gets.chomp.to_i

z = n.to_s(26)
#puts(z)

a = z.split(//)

k = false
mi = 0
ans = ''
a.reverse.each do |i|
    b = i.to_i(26)
    b = b - mi
    if k
        ans = 'z' + ans
    end
    if b == 0
        k = true
        mi = 1
    elsif b == -1
        k = false
        mi = 1
        ans = 'y' + ans
    else
        k = false
        mi = 0
        ans = b.to_s(26).tr("1-9a-p", "a-y") + ans
    end
end

puts ans


Measured memory_bytes: 14316
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	vector<int>a;
	bool b[1001];
	int n, k;
	int x, y;
	int m, s;
	while (true) {
		m = 0;
		s = 0;
		scanf("%d", &n);
		if (n == 0)return 0;
		a.clear();
		f(i, n) {
			scanf("%d %d", &x, &y);
			m = max(m, x);
			if (m == x)k = i;
			s += x;
			a.push_back(y);
		}
		if (2 * m <= s) {
			f(i, n)s += a[i];
			printf("%d\n", s);
}
		else {
			s = (2 * m) - s;
			f(i, 1001)b[i] = false;
			b[0] = true;
			f(i, n) {
				if (i != k) {
					for (int j = s - a[i]; j >= 0; j--) {
						if (b[j])b[j + a[i]] = true;
					}
				}
			}
			for (int j = s; j >= 0; j--) {
				if (b[j]) {
					s = 2 * m;
					f(i, n)s += a[i];
					s -= j;
					break;
				}
			}
			printf("%d\n", s);
		}
	}



	return 0;
}


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

int main(){
	int n = 0;
	while(cin >> n && n){
		int m = 0, henkan[10000] = {};
		char in, iin;
		for(int i = 0; i < n; i++){
			cin >> in >> iin;
			int ctoi = in, ctoii = iin;
			henkan[ctoi] = ctoii;
		}
		cin >> m;
		for(int i = 0; i < m; i++){
			cin >> in;
			int ctoi = in;
			if(henkan[ctoi])
				ctoi = henkan[ctoi];
			cout << (char)ctoi;
		}
		cout << endl;
	}
}

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

int main() {
    int N, T;
    cin >> N >> T;
    int c[N], t[N];
    for (int i=0; i<N; ++i) cin >> c[i] >> t[i];

    vector<int> res;
    for (int i=0; i<N; ++i) {
        if (t[i] <= T) {
            res.push_back(c[i]);
        }
    }

    sort(res.begin(), res.end());
    
    if (res.size() == 0) cout << "TLE" << endl;
    else cout << res[0] << endl;

}

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define repr(i, n) for(ll i = n;i >= 0;i--) // from n to 0
#define Repr(i, r, n) for(ll i = n;i >= r;i--) // from n to r
#define pb push_back
#define MOD 1000000007
#define PI (acos(-1))

bool is_prime(ll a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(ll i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  ll stringLength = s.size();
  ll series[stringLength+1];
  series[0] = 0;
  
  ll count = 0, sum = 0;
  rep(i, stringLength) {
    if(s[i] == '>') count = 0;
    else count++;
    series[i+1] = count;
  }
  count = 0;

  repr(i, stringLength-1) {
    if(s[i] == '<') count = 0;
    else count++;
    sum += max(series[i], count);
  }
  sum += series[stringLength];
  
  cout << sum << "\n";
  return 0;
}

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

int main()
{
    int a, b, x, y, z,hoge;
    cin >> a >> b;
    x = a + b;
    y = a - b;
    z = a * b;
    hoge = max({x, y, z});
    cout << hoge<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n;cin>>n;
  vector<int> t(n);
  int cnt=0;
  rep(i,n){
    cin>>t[i];
    cnt+=t[i];
  }
  int m;cin>>m;
  rep(i,m){
    int p,x;cin>>p>>x;
    int ans=cnt+x-t[p-1];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3604
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
        int n;
        cin >> n;
        int a[n + 1] = {};
        map<int, int> mp;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
            mp[i - a[i]]++;
        }

        int ans = 0;
        for(int i = 1; i <= n; i++)
            ans += mp[a[i] + i];

        cout << ans << '\n';
        
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



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

int main()
{
    long long int a,b,n;

    scanf("%lld %lld %lld",&a,&b,&n);

    long long int ans;

    if(b-1 > n)
        ans = (a*n)/b;
    else
        ans = (a*(b-1))/b;

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 1700
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <cmath>
#include <set>
#include <algorithm>

using namespace std;

int a[111111];

int main(){
    int n,h=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        if(a[i]==i&&a[i+1]==i+1){
            swap(a[i],a[i+1]);
            i++;
            h++;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]==i){
            h++;
        }
    }
    printf("%d\n",h);
    return 0;
}


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

int main()
{
    int sum[101];
    int min=100000000;
    int argmin = 1;
    int N;
    cin >> N;
    int X[N];
    int d[N];
    for(int i = 0; i < N; i++){
        cin >> X[i];
    }
    for(int p = 1; p < 101; p++){
        sum[p] = 0;
        for(int i = 0; i < N; i++){
            sum[p] = sum[p] + (X[i] - p) * (X[i] - p);
        }
        if(min > sum[p]){
            min = sum[p];
            argmin = p;
        }
    }
    cout << sum[argmin] << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
n = int(raw_input())
arr = map(int,raw_input().split())
dp = [float("inf")]*(n)
dp[0]=0
for i in range(n):
    for j in [i+1,i+2]:
        if j < n: 
            dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]))
print dp[n-1]

Measured memory_bytes: 12060
# ABC 93, C - same integers
import itertools

A = [int(el) for el in input().split(' ')]

y = max(A)
for x in itertools.count(max(A)):
    if (3*x - sum(A)) % 2 == 0:
        y = x
        break

k = (3*x - sum(A))/2
print(int(k))


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  priority_queue<P> pq;
  rep(i, n) {
    ll a, b; cin >> a >> b;
    pq.push(make_pair(-b, a));
  }
  ll sum = 0;

  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    ll a = p.second;
    ll b = -p.first;
    // debug2(a, b);

    sum += a;
    if (sum > b) {
      No();
      return;
    }
  }

  Yes();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 6384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 100005 ;
using namespace std ;

int n, m, a[N], b[N] ;

bool cmp(int x, int y) {
	return (x & 1) > (y & 1) ;
}

int main() {
	scanf("%d%d", &n, &m) ;
	rep(i, 1, m) {
		scanf("%d", &a[i]) ;
	}
	sort(a + 1, a + m + 1, cmp) ;
	if (m > 2 && (a[3] & 1)) {
		printf("Impossible\n") ;
		return 0 ; 
	}
	if (m == 1) {
		rep(i, 1, m) printf("%d ", a[i]) ;
		if (n == 1) printf("\n%d\n%d\n", 1, 1) ; else
			printf("\n%d\n%d %d\n", 2, 1, n - 1) ;
		return 0 ;
	}
	if (m > 1) swap(a[2], a[m]) ;
	rep(i, 1, m) printf("%d ", a[i]) ;
	rep(i, 1, m) b[i] = a[i] ;
	-- b[1], ++ b[m] ;
	if (!b[1]) {
		rep(i, 1, m - 1) b[i] = b[i + 1] ;
		-- m ;
	}
	printf("\n%d\n", m) ;
	rep(i, 1, m) printf("%d ", b[i]) ;
	return 0 ; 
}

Measured memory_bytes: 256
n,a,b,c = map(int,input().split())
abc = {'A':a,'B':b,'C':c}
ans = []

if a+b+c==0:
    for _ in range(n):
        s = input()
    print('No')
elif a+b+c==1:
    for _ in range(n):
        s = input()
        x,y = s[0],s[1]
        if abc[x]==abc[y]:
            print('No')
            break
        elif abc[x]==1:
            abc[x] -=1
            abc[y] +=1
            ans.append(y)
        else:
            abc[x] +=1
            abc[y] -=1
            ans.append(x)
elif a+b+c==2:
    s = input()
    x,y = s[0],s[1]
    if abc[x]==0 and abc[y]==0:
        print('No')
    else:
        for _ in range(n-1):
            s_ = input()
            x_,y_ = s_[0],s_[1]
            if abc[x]==abc[y]:
                if x==x_ or (x!=x_ and y!=y_ and x == 'B'):
                    abc[x] +=1
                    abc[y] -=1
                    ans.append(x)
                else:
                    abc[x] -=1
                    abc[y] +=1
                    ans.append(y)
            elif abc[x]>=1:
                abc[x] -=1
                abc[y] +=1
                ans.append(y)
            else:
                abc[x] +=1
                abc[y] -=1
                ans.append(x)
            x,y=x_,y_
        if abc[x]>=abc[y]:
            ans.append(y)
        else:
            ans.append(x)
else:
    s = input()
    x,y = s[0],s[1]
    if abc[x]==0 and abc[y]==0:
        print('No')
    else:
        for _ in range(n-1):
            if abc[x]>=abc[y]:
                abc[x] -=1
                abc[y] +=1
                ans.append(y)
            else:
                abc[x] +=1
                abc[y] -=1
                ans.append(x)
            s = input()
            x,y = s[0],s[1]
        if abc[x]>=abc[y]:
            ans.append(y)
        else:
            ans.append(x)
                
if len(ans)==n:
    print('Yes')
    print('\n'.join(ans))

Measured memory_bytes: 10416
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var N, M int
	con.Scan(&N, &M)
	A := make([]string, N)
	B := make([]string, M)
	for i := 0; i < N; i++ {
		con.Scan(&A[i])
	}
	for i := 0; i < M; i++ {
		con.Scan(&B[i])
	}
	for i := 0; i+M <= N; i++ {
		for j := 0; j+M <= N; j++ {
			ok := true
			for k := 0; ok && k < M; k++ {
				for l := 0; ok && l < M; l++ {
					if A[i+k][j+l] != B[k][l] {
						ok = false
					}
				}
			}
			if ok {
				con.Println("Yes")
				return nil
			}
		}
	}
	con.Println("No")
	return nil
}


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

tmp = sum(b) - sum(a)
numa, numb = 0, 0
for i in range(N):
    if a[i] > b[i]:
        numb += a[i] - b[i]
    elif a[i] < b[i]:
        numa += (b[i] - a[i] + 1) // 2

if numa <= tmp and numb <= tmp:
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;

struct edge {
    ll src, dst, cost;
    edge() {}
    edge(ll a, ll b, ll c) : src(a), dst(b), cost(c) {}
};

int main() {
    ll L, r = 1;
    ll N = 0, M;
    vector<edge> G;

    cin >> L;

    while (r <= L) {
        r *= 2;
        N++;
    }
    for (ll i = 1; i < N; i++) {
        G.push_back( edge(i, i+1, 0) );
        G.push_back( edge(i, i+1, (1<<(i-1))) );
    }

    ll remain = L - (1<<(N-1));

    for (ll i = N-1; i >= 1; i--) {
        if (!remain) { break; }

        if ( remain >= (1 << (i-1)) ) {
            G.push_back( edge(i, N, L-remain) );
            remain -= (1 << (i-1));
        }
    }

    M = G.size();

    cout << N << " " << M << endl;

    for (auto &e: G) {
        cout << e.src << " " << e.dst << " " << e.cost << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
int main()
{
	int n,m,s;
	std::cin>>n;
	if(n%1000==0){
		std::cout<<0<<std::endl;
	}
	else
	{
		m=n/1000;
		s=(m+1)*1000;
		std::cout<<s-n<<std::endl;
	}
	return 0;
}

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

int main(){
	int a,b,c,sum=0;

	cin >> a >> b >> c;
    for (int x = a; x <= b; x++){
        if(c%x == 0){
            sum++;
        }
    }
    cout << sum << endl;
	
	return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int cx = 10,cy = 10;
		int v[21][21];
		REP(i, 21) {
			REP(j, 21) {
				v[i][j] = 0;
			}
		}
		int n, m,cnt=0;
		cin >> n;
		if (!n) break;
		REP(i, n) {
			int x, y;
			cin >> x >> y;
			v[x][y] = 1;
		}
		cin >> m;
		REP(i, m) {
			char d;
			int L;
			cin >> d >> L;
			int dx, dy;
			if (d == 'N') {
				dx = 0;dy = 1;
			}
			else if (d == 'E') {
				dx = 1;dy = 0;
			}
			else if(d=='W'){
				dx = -1;dy = 0;
			}
			else {
				dx = 0;dy = -1;
			}
			FOR(j,1, L+1) {
				if (v[cx + j*dx][cy + j*dy] == 1) {
					cnt++;
					v[cx + j*dx][cy + j*dy] = 0;
				}
			}
			cx += L*dx;cy += L*dy;
		}
		if (cnt == n) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

map<string, int> s, t;

signed main()
{
    int N, M;
    cin >> N;
    REP(i, N) {
        string tmp;
        cin >> tmp;
        s[tmp]++;
    }
    cin >> M;
    REP(i, M) {
        string tmp;
        cin >> tmp;
        t[tmp]++;
    }
    int ans = 0;
    for(auto& p : s) {
        int cand = p.second - t[p.first];
        ans = max(ans, cand);
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define ll long long
#define llong long long
#define REP(i,n) for(auto i=0;i<n;++i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define FOR(i,a,b) for(auto i=a;i<b++i)
#define ALL(v) v.begin(),v.end()
#define pb push_back

using namespace std;

int main(){
  vector<int> a;
  for(int i = 0; i < 10; i++){
    int x; cin >> x;
    a.pb(x);
  }
  sort(ALL(a));
  for(int i = 9; i >= 7; i--){
    cout << a[i] << endl;
  }

  return 0;
}




Measured memory_bytes: 3132
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w,a,b=LI()
  field=[[0]*w for _ in range(h)]

  for i in range(b):
    for j in range(a):
      field[i][j]=1

  for i in range(b,h):
    for j in range(a,w):
      field[i][j]=1

  for x in field:
    print(''.join([str(y) for y in x]))

main()
# print(main())


Measured memory_bytes: 13992
import sys
input = sys.stdin.readline

# ユニオンファインド
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m= map(int, input().split())
a= [list(map(int, input().split())) for i in range(m)]
uf = UnionFind(n)
ans1=[n*(n-1)//2]
ans=n*(n-1)//2
for i in range(m-1,0,-1):
    a[i][0]-=1
    a[i][1]-=1
    x=uf.size(a[i][0])
    z=uf.size(a[i][1])
    uf.union(a[i][0],a[i][1])
    y=uf.size(a[i][0])
    if x==y:
        ans1.append(ans)
    else:
        ans-=(y*(y-1)-x*(x-1)-z*(z-1))//2
        ans1.append(ans)

for i in range(m):
    print(ans1[-1-i])

Measured memory_bytes: 112092
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 200005;
const int K = 1000000;
int ans[N];
string ask(int l, int r, int p = 0){
    cout << "? ";
    fflush(stdout);
    for (int i = l; i <= r; i++){
        if (i == p) continue;
        cout << i << " ";
        fflush(stdout);
    }
    if (p < 0) cout << -p << " ";
    cout << endl;
    fflush(stdout);
    string s;
    cin >> s;
    return s;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int l = 1;
    int r = n + 1;
    string s0 = ask(1, n);
    while(r - l > 1){
        int mid = (r + l) / 2;
        if (s0 == ask(mid, mid + n - 1)) l = mid; else r = mid;
    }
    ans[l] = 0;
    ans[l + n] = 1;
    for (int i = l + 1; i < l + n; i++){
        string t = ask(l, l + n, i);
        if (t == s0) ans[i] = 1; else ans[i] = 0;
    }
    for (int i = 1; i < l; i++){
        string t = ask(l + 1, l + n - 1, -i);
        if (t == s0) ans[i] = 0; else ans[i] = 1;
    }
    for (int i = l + n + 1; i <= n + n; i++){
        string t = ask(l + 1, l + n - 1, -i);
        if (t == s0) ans[i] = 0; else ans[i] = 1;
    }
    if (s0 == "Red"){
        cout << "! ";
        fflush(stdout);
        for (int i = 1; i <= n + n; i++){
            if (ans[i] == 0) cout << "R"; else cout << "B";
            fflush(stdout);
        }
    } else{
        cout << "! ";
        fflush(stdout);
        for (int i = 1; i <= n + n; i++){
            if (ans[i] == 0) cout << "B"; else cout << "R";
            fflush(stdout);
        }
    }
}


Measured memory_bytes: 724
def rotateRight(msg):
    if len(msg) == 1:
        return msg
    return msg[-1] + msg[:-1]

def rotateLeft(msg):
    if len(msg) == 1:
        return msg
    return msg[1:] + msg[0]

def swapHalf(msg):
    if len(msg) == 1:
        return msg
    H = len(msg) // 2
    if len(msg) % 2 == 0:
        return msg[H:] + msg[:H]
    else:
        return msg[H+1:] + msg[H] + msg[:H]

def increment(msg):
    arr = [ c for c in msg ]
    for i in range(len(arr)):
        if arr[i].isdigit():
            arr[i] = str((int(arr[i]) + 1) % 10)
    return "".join(arr)

def decrement(msg):
    arr = [ c for c in msg ]
    for i in range(len(arr)):
        if arr[i].isdigit():
            if arr[i] == '0':
                arr[i] = '9'
            else:
                arr[i] = str(int(arr[i]) - 1)
    return "".join(arr)

if __name__ == '__main__':
    N = int(input())

    for _ in range(N):
        order = input()
        msg = input()

        for i in range(len(order) - 1, -1, -1):
            c = order[i]
            if c == 'J':
                msg = rotateRight(msg)
            elif c == 'C':
                msg = rotateLeft(msg)
            elif c == 'E':
                msg = swapHalf(msg)
            elif c == 'A':
                msg = msg[::-1]
            elif c == 'P':
                msg = decrement(msg)
            elif c == 'M':
                msg = increment(msg)
        
        print(msg)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	ll a,b;
	cin >> a >> b;
	ll cnta = 0;
	ll cntb = 0;
	ll buff = 1;
	ll waru = 2;
	a;
	b++;
	ll ans = 0;
	for(int i = 0;i<61;i++)
	{
		cnta = a/waru*waru/2;
		cntb = b/waru*waru/2;
		cnta += max(0LL,a%waru-waru/2);
		cntb += max(0LL,b%waru-waru/2);
		waru *= 2;
		////cout<<waru<<endl;
		//cout<<cnta<<';'<<cntb<<endl;
		if((cnta-cntb)%2)
		{
			ans += buff;
		}
		buff*=2;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

class RollingHash {
 private:
  const uint64_t mod = (UINT64_C(1) << 61) - 1;
  static inline uint64_t base = std::random_device()();
  std::vector<uint64_t> hashes, pows;

  inline uint64_t add(uint64_t a, uint64_t b) const {
    a += b;
    if (a >= mod) a -= mod;
    return a;
  }

  inline uint64_t sub(uint64_t a, uint64_t b) const {
    if (a < b) a += mod;
    a -= b;
    return a;
  }

  inline uint64_t mul(uint64_t a, uint64_t b) const {
    uint64_t ah = a >> 31, al = a & ((UINT64_C(1) << 31) - 1), bh = b >> 31,
             bl = b & ((UINT64_C(1) << 31) - 1), m = ah * bl + al * bh,
             v = (ah * bh << 1) + (m >> 30) +
                 ((m & ((UINT64_C(1) << 30) - 1)) << 31) + al * bl;
    v = (v & ((UINT64_C(1) << 61) - 1)) + (v >> 61);
    return v;
  }

 public:
  template <typename T>
  RollingHash(const T &S) : hashes(S.size() + 1, 0), pows(S.size() + 1, 0) {
    pows[0] = 1;
    for (size_t i = 0; i < S.size(); i++) {
      pows[i + 1] = mul(pows[i], base);
      hashes[i + 1] = add(mul(hashes[i], base), S[i]);
    }
  }

  // S[l, r)
  uint64_t slice(int l, int r) const {
    return sub(hashes[r], mul(hashes[l], pows[r - l]));
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  vector<int> S(N), T(N);
  for (int i = 0; i < N; i++) {
    S[i] = A[i] ^ A[(i + 1) % N];
    T[i] = B[i] ^ B[(i + 1) % N];
  }
  for (int i = 0; i < N; i++) {
    S.emplace_back(S[i]);
  }
  RollingHash rhs(S), rht(T);
  for (int i = 0; i < N; i++) {
    if (rhs.slice(i, i + N) == rht.slice(0, N)) {
      cout << i << ' ' << (A[i] ^ B[0]) << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 16988
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
#define LL long long
LL a,b;
int main()
{
	scanf("%lld%lld",&a,&b);
	printf("%s",((a-b)<2&&(a-b)>-2)?"Brown":"Alice");
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	int n;
	cin >> n;

	map<string, int> m;
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;

		m[s] = m[s] + 1;
		c = max(c, m[s]);
	}

	for (auto p : m)
	{
		if (c == p.second)
		{
			println(p.first);
		}
	}
}


Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

struct vote {
  string name;
  int count;
  
  bool operator<(const vote &another) const{
    return count < another.count;
  };
};

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  map<string, int> m{};
  for(int i = 0; i < N; i++) {
    cin >> S.at(i);
    m[S.at(i)]++;   
  }
  vector<vote> v;
  for(auto i : m) {
    v.push_back({i.first, i.second});
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  vector<string> ans;
  for(int i = 0; i < v.size(); i++) {
    if(i == 0) {
      ans.push_back(v.at(i).name);
    } else {
      if(v.at(i).count == v.at(i - 1).count) {
        ans.push_back(v.at(i).name);
      } else {
        break;
      }
    }
  }
  sort(ans.begin(), ans.end());
  for(int i = 0; i < ans.size(); i++) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 34032
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
 
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        h: usize, w: usize, a: usize, b: usize,
    }
    for h_ in 0..b {
        for i in 0..w {
            if a<= i {
            	print!("1");
            } else {
                print!("0");
            }
        }
        println!("");
    }
    
    for h_ in b..h {
        for i in 0..w {
            if a<= i {
            	print!("0");
            } else {
                print!("1");
            }
        }
        println!("");
    }
}

Measured memory_bytes: 5372
import math

I = lambda: list(map(int, input().split()))
n, d, a = I()
l = []
for _ in range(n):
	x, y = I()
	l.append([x,y])
l.sort()

j = 0
limit = []
for i in range(n):
	while l[j][0] - l[i][0] <= 2*d:
		j+=1
		if j == n: break
	j-=1
	limit.append(j)

ans = 0
num=[0]*(n+1)
cnt=0
for i in range(n):
	l[i][1]-=(ans-cnt)*a
	damage_cnt=max(0,(l[i][1]-1)//a + 1)
	ans+=damage_cnt
	num[limit[i]]+=damage_cnt
	cnt+=num[i]
print(ans)

Measured memory_bytes: 53588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct UnionFind {
	vector<int>d;

	UnionFind(int N) :d(N, -1){}

	int find(int x) {
		if (d[x] < 0)return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return false;
		if (d[x] > d[y])swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return -d[find(x)];
	}
};

int main() {
	init();

	int N, M, K; cin >> N >> M >> K;
	UnionFind fr(N), br(N);
	vector<int>cnt(N, 0);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		--a; --b;
		cnt[a]++;
		cnt[b]++;
		fr.unite(a, b);
	}
	Graph G(N);
	rep(i, 0, K) {
		int a, b; cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i, 0, N) {
		int ans = fr.size(i) - 1 - cnt[i];
		for (auto p : G[i]) {
			if (fr.same(i, p))--ans;
		}
		cout << ans << (i == N - 1 ? "\n" : " ");
	}

	return 0;
}

Measured memory_bytes: 7168
from itertools import accumulate
 
 
def main():
    n, k = map(int, input().split())
    s = input()
 
    # 配列を下記で変換
    # '11000' = [2, 3, 0]
    # '1'の長さで始まり、'1'の長さで終わるようにする
    s = s.replace('01', '0,1').replace('10', '1,0')
    len_list = [len(string) for string in s.split(',')]
    if s[0] == '0':
        len_list = [0] + len_list
    if s[-1] == '0':
        len_list = len_list + [0]
 
    if 2 * k + 1 >= len(len_list):
        print(n)
        return
 
    sum_list = [0] + list(accumulate(len_list))
    max_len = 0
    for i in range(0, len(len_list) - (2 * k + 1) + 1, 2):
        handstand_len = sum_list[i + (2 * k + 1)] - sum_list[i]
        if max_len < handstand_len:
            max_len = handstand_len
    print(max_len)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 9408
sub f{
	$_[$i+1]=$_[$i-1]^$_[$i]^$s[$i]while++$i<@s;
	$i="@_"==pop&&($_[-1]^"@_"^"@s")==$_[1]&&print map$_?W:S,@_
}
<>;@s=<>=~y/ox/01/r=~/./g;
f(0,0)||f(0,1)||f(1,0)||f(1,1)||print-1


Measured memory_bytes: 29464
a,b,c,d=map(int,input().split())
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

def lcm(x,y):
    return x*y//gcd(x,y)
p=lcm(c,d)
def f(n):
    return b//n-(a-1)//n
ans=b-a+1-f(c)-f(d)+f(p)
print(ans)


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	n, m := readInt(), readInt()
	tot := 0
	for i := 0; i < m; i++ {
		tot += readInt()
	}

	if tot <= n {
		fmt.Println(n - tot)
	} else {
		fmt.Println(-1)
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1804
#include<stdio.h>
int main(void) {
  int n;
  scanf("%d",&n);
  int a[n]; 
  for(int b=0;b<n;b++){
    scanf("%d",&a[b]);
  }

  for(int c=n-1;c>=0;c--){
    printf("%d",a[c]);
    if(c==0) printf("\n");
    else printf(" ");
  }    
return 0;
}


Measured memory_bytes: 2108
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();int m=in();
	map<int,bool> o,e;
	int u,v;
	for(int i=0;i<m;i++)
	{
		u=in();v=in();
		if(u==1)o[v]=1;
		else if(u==n)e[v]=1;
		if(v==1)o[u]=1;
		else if(v==n)e[u]=1;
	}
	
	bool ok=0;
	for(auto i:o)
	{
		if(e[i.first])ok=1;
	}
	if(ok)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	
}


Measured memory_bytes: 22436
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    String S=scan.nextLine();
    if(S.length()==3){
      StringBuffer s=new StringBuffer(S);
      System.out.println(s.reverse().toString());
    }
    else if(S.length()==2){
      System.out.println(S);
    }
  }
}

Measured memory_bytes: 22100
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    char[] s = br.readLine().toCharArray();
    if (s[2] == s[3] && s[4] == s[5]){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 300
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on
int N;

struct edge {
  int to, cap, rev;
};
vector<edge> G[MAX_N];

void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

bool used[MAX_N];

int dfs(int v, int t, int f) {
  if (v == t) return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if (!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, inf);
    if (f == 0) return flow;
    flow += f;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  vector<int> a(N), b(N), c(N), d(N);
  REP(i, N) cin >> a[i] >> b[i];
  REP(i, N) cin >> c[i] >> d[i];

  // 点が 2 x 2 (N=2) だとすると
  // 0: soruce
  // 1: 赤1
  // 2: 赤2
  // 3: 青1
  // 4: 青2
  // 5: sink

  // 点が 3 x 3 (N=3) だとすると
  // 0: soruce
  // 1: 赤1
  // 2: 赤2
  // 3: 赤3
  // 4: 青1
  // 5: 青2
  // 6: 青3
  // 7: sink

  REP(i, N) add_edge(0, i + 1, 1);
  REP(i, N) add_edge(N + i + 1, 2 * N + 1, 1);

  // 0 と 2N+1 をそれぞれ s と t とする
  REP(i, N) {
    REP(j, N) {
      // 赤 a[i] < c[j] かつ,b[i] < d[i]のとき、i + 1 と N + j + 1 に辺を張る
      if (a[i] < c[j] && b[i] < d[j]) {
        add_edge(i + 1, N + j + 1, 1);
      }
    }
  }
  printf("%d\n", max_flow(0, 2 * N + 1));
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	intt X; std::cin >> X;
	std::vector<intt> a(X);
	std::map<intt, intt> MAP;
	for (auto& r : a) {
		std::cin >> r;
		++MAP[r];
		++MAP[r - 1];
		++MAP[r + 1];
	}
	intt max = 0;
	for (auto& r : MAP) {
		max = std::max(max, r.second);
	}
	std::cout << max << std::endl;


	return 0;
}

Measured memory_bytes: 10020
import java.util.*;

public class Main {
  public static void main(String[] args) {
      
    // 標準入力から値を取得してinputに入れる
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();       // データ数
    int K = sc.nextInt();       // 移動範囲
    int smallestNum = 1;   // 最小値
    int operationNum = 0;  // 操作回数
    ArrayList<Integer> numData = new ArrayList<Integer>();
    
    for (int i = 0; i < N; i++) {
      numData.add(sc.nextInt());
    }
    
    // 最小値の場所を検索
//    int smallNumAddress = numData.indexOf(smallestNum);
    
    // 開始位置を検索
//    if (smallNumAddress < K || N - smallNumAddress <= K) {
      operationNum = (N - 1) / (K - 1);
      if ((N - 1) % (K - 1) != 0) {
        operationNum += 1;
      }
      
//    } else {
//      operationNum = (smallNumAddress / (K - 1)) + 
//                       ((N - smallNumAddress - 1) / (K - 1));
      
//      if (smallNumAddress % (K - 1) != 0) {
//        operationNum += 1;
//      }
//      if ((N - smallNumAddress - 1) % (K - 1) != 0) {
//        operationNum += 1;
//      }
      
//    }
    
    System.out.println(operationNum);
    sc.close();
  }
}


Measured memory_bytes: 56588
W, H, N = map(int, input().split())
X, Y = 0, 0

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    X = max(X, x)
  elif a == 2:
    W = min(W, x)
  elif a == 3:
    Y = max(Y, y)
  elif a == 4:
    H = min(H, y)
    
if (W-X) < 0 or (H-Y) < 0:
  print(0)
else:
  print((W-X)*(H-Y))


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  rep(i, 10000) {
    if (i%2 == 0) {
      c -= b;
      if (c <= 0) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    else {
      a -= d;
      if (a <= 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#define REP(i, n) for(int i = 0; i < n; i++)
//#define REPR(i, n) for(int i = n; i >= 0; i--)
//#define FOR(i, m, n) for(int i = m; i < n; i++)
//#define INF 1e9
// template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
// template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

int main() { //int argc, const char * argv[]
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k, cnt=0;
    double tmp;
    cin >> n >> k;
    tmp = (double)n;

    while(tmp>=1){
        tmp = tmp/k;
        cnt ++;
    }
    
    cout << cnt;
}


Measured memory_bytes: 256