akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long n;
  std::vector<long> ys;
  Solver() {
    S002 reader;
    reader >= n >n>= ys;
  }
  long sign(long x) {
    if( x > 0 ) return 1;
    if( x < 0 ) return -1;
    return 0;
  }
  long solve1() {
    std::vector<long> xs = ys;
    long sum = 0;
    long res = 0;
    for(long i = 0; i < n; ++i) {
      if( i % 2 == 0 ) {
        if( sum + xs[i] >= 0 ) {
          res += std::abs(sum + xs[i] + 1);
          xs[i] = xs[i] - (sum + xs[i] + 1);
        }
      }
      else {
        if( sum + xs[i] <= 0 ) {
          res += std::abs(-(sum + xs[i]) + 1);
          xs[i] = xs[i] + (-(sum + xs[i]) + 1);
        }
      }
      sum = sum + xs[i];
      dumpll(i, sum);
    }
    return res;
  }
  long solve2() {
    std::vector<long> xs = ys;
    long sum = 0;
    long res = 0;
    for(long i = 0; i < n; ++i) {
      if( i % 2 == 0 ) {
        if( sum + xs[i] <= 0 ) {
          res += std::abs(-(sum + xs[i]) + 1);
          xs[i] = xs[i] + (-(sum + xs[i]) + 1);
        }
      }
      else {
        if( sum + xs[i] >= 0 ) {
          res += std::abs(sum + xs[i] + 1);
          xs[i] = xs[i] - (sum + xs[i] + 1);
        }
      }
      sum = sum + xs[i];
      dumpll(i, sum);
    }
    return res;
  }
  void solve() {
    long res = std::min(solve1(), solve2());
    printf("%ld\n", res);
  }    
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 1804
from bisect import bisect_left,bisect_right

n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for j in range(n):
    i = bisect_left(A, B[j])
    k = n - bisect_right(C, B[j])
    ans += i*k
print(ans)


Measured memory_bytes: 23072
program main
  implicit none
  character(len=10) :: S
  integer :: i,N
  logical :: flag
  read(*,*) S
  N = len_trim(S)
  if ( mod(N,2) == 1) then
     write(*,'(a)') 'No'
     stop
  else
     flag = .false.
     do  i = 1,N,2
        if (S(i:i+1) == "hi") then
           flag = .true.
        else
           flag = .false.
        end if
     end do
  end if
  if ( flag )then
     write(*,'(a)') 'Yes'
  else 
     write(*,'(a)') 'No'
  end if
end program main


Measured memory_bytes: 640
# -*- coding: utf-8 -*-


def calc_dist(x1, x2, y1, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5


def main():
    from itertools import permutations

    n = int(input())
    xy = [list(map(int, input().split())) for _ in range(n)]
    total = 0

    m = len(list(permutations(range(n))))

    for p in permutations(range(n)):
        for i in range(len(p) - 1):
            a = p[i]
            b = p[i + 1]
            total += calc_dist(xy[a][0], xy[b][0], xy[a][1], xy[b][1])

    print(total / m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8052
from itertools import product
N,M=map(int,input().split())
x,y,z = [0]*N, [0]*N, [0]*N
for i in range(N):
    x[i],y[i],z[i] = map(int,input().split())

pat= product([1,-1],repeat=3)
ans=0
for v in pat:
    s = [ (v[0]*x[i]+v[1]*y[i]+v[2]*z[i]) for i in range(N)]
    s.sort(reverse=True)
    tmp=sum(s[:M])
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 9356
X, Y, A, B, C = map(int, input().split())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
list = list(map(int, input().split()))

Alist.sort(reverse = True)
Blist.sort(reverse = True)

for i in range(X):
    list.append(Alist[i])
for i in range(Y):
    list.append(Blist[i])
list.sort(reverse = True)

ans =0
for i in range(X + Y):
    ans += list[i]
    
print(ans)

Measured memory_bytes: 23328
#include <iostream>
#include <string.h>
#define MAXN 100005
using namespace std;

int n, ps[MAXN];
string s;
bool valid(int k){
	memset(ps, 0, sizeof ps);
	int tmp = 0;
	for(int i = 0; i <= n - k; i++){
		tmp += ps[i];
		int now = (s[i]	- '0') ^ (tmp % 2);
//		cout << i << " # " << tmp << " \n";
		if(!now) continue;
		ps[i+1]++;
		ps[min(i+k, n)]--;
	}
	int r = n - k;
	for(int i = n - k + 1; i < n; i++){
		tmp += ps[i];
		int now = (s[i]	- '0') ^ (tmp % 2);
		if(now) break;
		r = i;
	}
//	cout << k << " -> " << r << "\n";
	return r + 1 >= k;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	
	cin >> s;
	n = s.length();
	int l = 1;
	int r = s.length();
	int k = (l + r + 1) / 2;
	while(l < r){
		if(valid(k)) l = k;
		else r = k - 1;
		k = (l + r + 1) / 2;
	}
	cout << l << "\n";
	return 0;
}

Measured memory_bytes: 848
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


ll a[222222];
int main(void) {
  cin >> n;
  FOR(i, 0, n) {
	cin >> a[i];
  }

  if (a[0] != 0) {
	cout << "-1" << endl;
	return 0;
  }

  ok = true;
  FOR(i, 1, n) {
	if (a[i] == a[i - 1] + 1) {
	  ans++;
	}
	else if(a[i] -a[i-1] > 1){
	  ok = false;
	  break;
	}
	else {
	  ans += a[i];
	}
  }

  if (ok) {
	cout << ans << endl;
  }
  else {
	cout << "-1" << endl;
  }

  return 0;
}

Measured memory_bytes: 1792
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()

x = readInts()
a = x[0]
b = x[1]
c = x[2]
d = x[3]

while 1:
	c-=b
	if c<=0:
		print("Yes")
		break
	a-=d
	if a<=0:
		print("No")
		break

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

struct point{double px; double py;};

double x, y, s;
int i,j;

int main(){
	point p[21];	
	char k;

	while(cin>>x>>k>>y){
		if(cin.eof())break;
		p[i].px = x;
		p[i].py = y;
		i++;
	}
	p[i].px = p[0].px;
	p[i].py = p[0].py;

	for(; j<i; j++)	s += (p[j].px-p[j+1].px)*(p[j].py+p[j+1].py);

	cout<<setiosflags(ios::fixed)<<setprecision(6)<<s/2<<"\n";
	return 0;
}

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

using namespace std;

int main(void) {
	int i, n, m, a = 0, ans = 0;
	cin >> n >> m;
	vector<pair<int, int>> d(m);
	for (i = 0; i < m; i++)
		scanf("%d%d", &d[i].second, &d[i].first);
	sort(d.begin(), d.end());
	for (i = 0; i < m; i++) {
		if (a < d[i].second) {
			ans++;
			a = d[i].first - 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1152
#12:36
n = int(input())
peer = [[] for _ in range(n)]
for i in range(1,n):
  j = int(input())-1
  peer[i].append(j)
  peer[j].append(i)
pre = [0 for _ in range(n)]
pre[0] = 10**6
seen = [0 for _ in range(n)]
seen[0] = 1
rank = []
now = [0]
while now:
  rank.append(now)
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if seen[y] == 0:
        seen[y] = 1
        pre[y] = x
        now.append(y)
#print(pre)
#print(rank)
pstd = [[] for _ in range(n)]
rank.reverse()
l = len(rank)
for k in range(l):
  if k == 0:
    for z in rank[k]:
      pstd[pre[z]].append(0)
    continue
  for z in rank[k]:
    pstz = pstd[z]
    pstz.sort()
    tmp = -1
    for w in pstz:
      if tmp >= w:
        tmp += 1
      else:
        tmp = w
    if k != l-1:
      pstd[pre[z]].append(tmp+1)
    else:
      print(tmp+1)
  #print(pstd)

Measured memory_bytes: 77600
#include<bits/stdc++.h>
using namespace std;
int x;
int main(){
    cin>>x;
    if(x % 10 == 7 || x / 10 % 10 == 7 || x / 100 == 7){
        puts("Yes");
    }
    else puts("No");
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<int,int>
#define iii pair<ii, int>
#define se second
#define ld long double
#define mod 1000000007
#define popcount __builtin_popcountll
#define PI acos(-1.0)
using namespace std;

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    if((a+b+c)>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}


Measured memory_bytes: 256
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let s: String = sc.read();
    let k: u64 = sc.read();
    let mut cnt = 1;

    for c in s.as_str().chars() {
        if c != '1' || cnt == k {
            println!("{}", c);
            break;
        } else {
            cnt += 1;
        }
    }
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


Measured memory_bytes: 4352
use std::cmp::max;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let arr: Vec<usize> = (0..n).map(|_| read::<usize>() + 1).collect();
    let mut s = vec![0; n + 1];
    for i in 0..n {
        s[i + 1] = s[i] + arr[i];
    }
    let mut res = 0;
    for i in 0..=n - k {
        res = max(res, s[i + k] - s[i]);
    }
    println!("{}", res as f64 / 2.0);
}


Measured memory_bytes: 5228
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int k;
string s;

int main(){
    
    IN s >> k;
    set<string> se;

    rep(i,0,sz(s)){
        string t = "";
        rep(j,i,min(sz(s),i+k)){
            t += s[j];
            se.it(t);
        }
    }

   // for(auto i : se)P(i);
    int c   = 0;
    for(auto i : se){
        c++;
        if(c >= k){
            P(i);
            ret 0;
        }
    }
    
	return  0;
}

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

int w, h;
vector<string> p;
bool used[60][10];
bool ans;

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

int dfs(int x, int y, char num, int& cnt){

    int left = 11;
    int right = -1;
    int sum = 0;
    cnt = 0;

    if(used[y][x]){
        return 0;
    }

    queue<pair<int, int>> q;
    vector<pair<pair<int, int>, int>> child;

    q.push(make_pair(x, y));
    used[y][x] = true;
    sum = x;
    cnt++;

    while(!q.empty()){
        auto temp = q.front();
        q.pop();
        int tempX = temp.first;
        int tempY = temp.second;

        char ground;
        if(tempY == h - 1){
            ground = '#';
        }
        else{
            ground = p[tempY + 1][tempX];
        }

        if(ground != '.' && ground != num){
            left = min(left, tempX);
            right = max(right, tempX);
        }

        for(int i = 0; i < 4; i++){
            int nx = tempX + dx[i];
            int ny = tempY + dy[i];

            if(0 <= nx && nx < w && 0 <= ny && ny < h){
                if(!used[ny][nx]){
                    if(p[ny][nx] == num){
                        sum += nx;
                        used[ny][nx] = true;
                        q.push(make_pair(nx, ny));
                        cnt++;
                    }
                    else if(i == 3 && p[ny][nx] != '.'){
                        int childNum = p[ny][nx] - '0';
                        child.push_back(make_pair(make_pair(nx, ny), childNum));
                    }
                    else if(p[ny][nx] == '.'){
                        used[ny][nx] = true;
                    }
                }
            }
        }
    }

    for(int i = 0; i < (int)child.size(); i++){
        int childCnt;
        auto childData = child[i];
        int childX = childData.first.first;
        int childY = childData.first.second;
        char childNum = '0' + childData.second;
        sum += dfs(childX, childY, childNum, childCnt);
        cnt += childCnt;
    }

    if(2 * sum <= (2 * left - 1) * cnt || (2 * right + 1) * cnt <= 2 * sum){
        //cout << x << " " << y << " " << num << endl;
        //cout << left << " " << right << " " << sum << " " << cnt << endl;
        ans = false;
    }

    return sum;
}

int main(){

    while(1){
        cin >> w >> h;
        if(w == 0){
            break;
        }

        p.resize(h);

        for(int i = 0; i < h; i++){
            cin >> p[i];
        }

        ans = true;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                used[i][j] = false;
            }
        }

        vector<pair<int, int>> v;
        char num = 0;
        for(int i = 0; i < w; i++){
            if(p[h - 1][i] != '.'){
                num = p[h - 1][i];
                v.push_back(make_pair(i, h - 1));
            }
        }

        int cnt;

        for(int i = 0; i < (int)v.size(); i++){
            dfs(v[i].first, v[i].second, num, cnt);
        }

        if(ans){
            cout << "STABLE" << endl;
        }
        else{
            cout << "UNSTABLE" << endl;
        }
    }    

    return 0;
}


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

int d;
vector<int> c;
vector<vector<int>> s;

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

int main() {
    cin >> d;
    c.resize(26);
    s.resize(d, vector<int>(26));
    for (int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int> last(26, 0);
    vector<int> ans(d);
    for (int i = 0; i < d; i++) {
        int happiness_max = INT_MIN;
        for (int j = 0; j < 26; j++) {
            int happiness = 0;
            for (int k = 0; k < 26; k++) {
                if (j == k) {
                    happiness += s[i][k];
                } else {
                    happiness -= c[k] * (i - last[k]);
                }
            }
            if (chmax(happiness_max, happiness)) {
                ans[i] = j;
            }
        }
    }
    for (int i = 0; i < d; i++) {
        cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 3692
#include <stdio.h>

int
main(void)
{
	char line[80];
	int a;
	int b;

	if (gets(line)) {
		if (sscanf(line, "%d %d", &a, &b) == 2) {
			printf("%d %d\n", a*b, 2*(a+b));
		}
	}

	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

signed main(){
    int h,w;
    scanf("%lld%lld",&h,&w);
    int ans = INF;

    REP1(i,h){
        int s1,s2,s3;
        s1 = i*w;
        if(w%2){
            s2 = (h-i) * (w+1)/2;
            s3 = (h-i) * (w-1)/2;
        } else {
            s2 = s3 = (h-i) * w/2;
        }
        int smax,smin;
        smax = MAX(s1,s2,s3);
        smin = MIN(s1,s2,s3);
        if(smax-smin<ans) ans = smax-smin;

        if((h-i)%2){
            s2 = ((h-i+1)/2) * w;
            s3 = ((h-i-1)/2) * w;
        } else {
            s2 = s3 = ((h-i)/2) * w;
        }
        smax = MAX(s1,s2,s3);
        smin = MIN(s1,s2,s3);
        if(smax-smin<ans) ans = smax-smin;
    }
    
    swap(h,w);

    REP1(i,h){
        int s1,s2,s3;
        s1 = i*w;
        if(w%2){
            s2 = (h-i) * (w+1)/2;
            s3 = (h-i) * (w-1)/2;
        } else {
            s2 = s3 = (h-i) * w/2;
        }
        int smax,smin;
        smax = MAX(s1,s2,s3);
        smin = MIN(s1,s2,s3);
        if(smax-smin<ans) ans = smax-smin;

        if((h-i)%2){
            s2 = ((h-i+1)/2) * w;
            s3 = ((h-i-1)/2) * w;
        } else {
            s2 = s3 = ((h-i)/2) * w;
        }
        smax = MAX(s1,s2,s3);
        smin = MIN(s1,s2,s3);
        if(smax-smin<ans) ans = smax-smin;
    }

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
f = lambda: list(map(int,input().split()))
f_ = lambda: [int(x)-1 for x in input().split()]

n,k = f()
d = []
for _ in range(n):
    a,b = f()
    d.append((a,b))
d.sort(key=lambda x: x[0])
count = 0
for x,y in d:
    count += y
    if count >= k:
        break
print(x)

Measured memory_bytes: 18268
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

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

class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int get_num_vertices(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};

map<P, int> res;
int maxColor = 0;


void dfs(int u, int prev, int c, Graph& g){
    int color = 1;
    for(auto e: g[u]){
        if(e.vertice == prev)   continue;
        if(c == color){
            color++;
        }
        res[P(min(u, e.vertice), max(u, e.vertice))] = color;
        maxColor = max(maxColor, color);
        dfs(e.vertice, u, color, g);
        color++;
    }
}



int main(){
    int n;  cin >> n;
    Graph g(n);
    vector<P> edgeInfo(n-1);
    for(int i = 0; i < n-1; i++){
        int a, b;   cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
        g.add_edge(b, a);
        edgeInfo[i] = P(min(a, b), max(a, b));
    }

    dfs(0, 0, 0, g);
    cout << maxColor << endl;
    for(int i = 0; i < n-1; i++){
        cout << res[edgeInfo[i]] << endl;
    }


    return 0;
}


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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int N; cin >> N;
  int a[1001];
  rep(i, N) cin >> a[i];
  int ans = -1;
  rep(i, N) {
    rep(j, N) {
      if(i == j) continue;
      string s = to_string(a[i]*a[j]);
      bool flag = true;
      rep(k, s.size()-1) {
	if(s[k]+1 != s[k+1]) flag = false;
      }
      if(flag) ans = max(ans, a[i]*a[j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3304
def main():
	H = int(input())
	cnt = 0
	if H==1:
		print(1)
		exit()
	while 1:
		if H==1:
			break
		else:
			H = H//2
			cnt += 1
	ans = 0
	for i in range(cnt):
		ans += 2**i
	ans += 2**(i+1)
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

    public static boolean isPrime(int source) {
        for (int i = 2; i < source; i++) {
            if (source % i == 0) {
                return true;
            }
        }
        return false;
    }

    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int p = Integer.parseInt(sc.next());
        while(isPrime(p)) {
            p++;
        }

        System.out.println(p);
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;

int main(){
  int n; cin>>n;
  vector<P> vec(n);
  for(int i=0;i<n;i++){
    int a,b; cin>>a>>b;
    vec[i]=P(b,a);
  }
  sort(vec.begin(),vec.end());
  long long now=0;
  for(int i=0;i<n;i++){
    now+=vec[i].second;
    if(now>vec[i].first){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 1792
n = int(input())
a = [0]*n


class card:
    def __init__(self, s, input_idx):
        self.m = s.split()[0]
        self.num = int(s.split()[1])
        self.t = s
        self.input_idx = input_idx
 
for i in range(n):
    a[i] = card(input(), i)
    
def partition(A, p, r):
    x = A[r].num
    i = p-1
    for j in range(p,r):
        if A[j].num <= x:
            i = i+1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    
    return i+1

def quickSort(A, p, r):
   if p < r:
     q = partition(A, p, r)
     quickSort(A, p, q-1)
     quickSort(A, q+1, r)

quickSort(a, 0, n-1)

stable = True
for i in range(1, n):
    if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:
        stable = False
        
if stable:
    print('Stable')
else:
    print('Not stable')
    
for item in a:
    print(item.t)



Measured memory_bytes: 35096
from collections import Counter


def solve(string):
    n, *aqbc = map(int, string.split())
    a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:]
    s = sum(a)
    t = Counter(a)
    ans = []
    for b, c in zip(*[iter(bc)] * 2):
        if c in t.keys():
            t[c] += t[b]
        else:
            t[c] = t[b]
        s += (c - b) * t[b]
        del t[b]
        ans.append(s)
    return "\n".join(map(str, ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

int main(void){
    int n;
    cin >> n;
    int a[n],sum = 0;
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 1;i < n-1;i++){
        int b[3] = {a[i-1],a[i],a[i+1]};
        sort(b,b+3);
        if(b[1] == a[i])sum++;
    }
    cout << sum;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main (String[] args) throws java.lang.Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    int n = Integer.parseInt(br.readLine());
	    long money = 100000;
	    while(n!=0){
	        money *= 1.05;
	        if(money%1000>0){
	        	money+=1000;
	        }
	        money /= 1000;
	        money *= 1000;
	        --n;
	    }
        System.out.println(money);
	}
}

Measured memory_bytes: 24124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

class TEAM{
  public:
    ll solved;
    ll wrong;
    ll pen;
    ll id;
    vector<int> problem;
    TEAM(ll n){
      solved = 0;
      wrong = 0;
      pen = 0;
      problem = vector<int>(n, 0);
    }
    bool operator<(const TEAM &a)const{
      if(solved == a.solved){
        if(pen == a.pen){
          return id < a.id;
        }else{
          return pen < a.pen;
        }
      }else{
        return solved > a.solved;
      }
    }
    bool operator==(const TEAM &a)const{
      return solved == a.solved && pen == a.pen;
    }
};

int main(void){
  ll T, P, R;
  while(cin >> T >> P >> R, T | P | R){
    vector<TEAM> team(T, TEAM(P));
    for(ll i=0; i < T; i++){
      team[i].id = i+1;
    }
    while(R--){
      ll tID, pID, time; string message;
      cin >> tID >> pID >> time >> message;
      tID--; pID--;
      if(message == "CORRECT"){
        team[tID].solved++;
        team[tID].pen += team[tID].problem[pID] * 1200 + time;
      }else{
        team[tID].problem[pID]++;
      }
    }
    stable_sort(team.begin(), team.end());
    for(ll i=0;  i< T; i++){
      cout << team[i].id << " " << team[i].solved << " " << team[i].pen << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
string s;
char t[N],d[N];
ll n,q;
ll chk(ll p){
    for(ll i=1;i<=q;i++){
        if(t[i]==s[p]){
            if(d[i]=='L')p--;
            else p++;
            if(p<0 || p>=n)return p;
        }
    }
    return p;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>q>>s;
    for(ll i=1;i<=q;i++)cin>>t[i]>>d[i];
    ll ans = n;
    ll s=0,e=n-1;
    while(s<=e){
        ll mid=(s+e)>>1;
        if(chk(mid)<0)s=mid+1;
        else e=mid-1;
    }
    ans-=s;
    s=0,e=n-1;
    while(s<=e){
        ll mid=(s+e)>>1;
        if(chk(mid)>=n)e=mid-1;
        else s=mid+1;
    }
    ans-=(n-1-e);
    cout<<ans;
}

Measured memory_bytes: 976
#include <iostream>
#include <cmath>

using namespace std;

int main(){

    char  str;

    cin >> str;

    if((str>='a') && (str<='z')){
        cout<<"a"<<endl;
    }
    else if((str>='A') && (str<='Z')){
        cout<<"A"<<endl;
    }
}



Measured memory_bytes: 3588
#include <stdio.h>
int main(){
	int a[4]={0},i,n,count=0;
    while(scanf("%d",&n)!=EOF){
		while(a[0]<=9) {
			if (a[0]+a[1]+a[2]+a[3]==n)
				count++;
			a[3]++;
			for (i=3;i>0;i--) {
				if(a[i]==10){
					a[i-1]++;
					a[i]=0;
				}
			}
		}
		printf("%d\n",count);
		for (i=3;i>=0;i--)
				a[i]=0;
		count=0;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define P push_back
#define L(x) ((x)&-(x))
using namespace std;
const int N=100005;
vector<int>e[N];
int n,m,s[N],a;
void U(int x,int u){while(x<=n)s[x]+=u,x+=L(x);}
int Q(int x){int r=0;while(x)r+=s[x],x-=L(x);return r;}
int main(){
	scanf("%d%d",&m,&n);
	for(int i=1,l,r;i<=m;i++)scanf("%d%d",&l,&r),e[r-l+1].P(l);
	for(int d=1;d<=n;d++){a=m;for(int i=d;i<=n;i+=d)a+=Q(i);for(int u:e[d])U(u,1),U(u+d,-1),m--;printf("%d\n",a);}
	return 0;
}

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

int main(){
int a,b,c,d,e,k;
bool flag=0;
int ary[10]={0};//0で初期化
cin >>a >>b >>c >>d >>e >>k;
    ary[0]=b-a;
    ary[1]=c-a;
    ary[2]=d-a;
    ary[3]=e-a;
    ary[4]=c-b;
    ary[5]=d-b;
    ary[6]=e-b; 
    ary[7]=d-c; 
    ary[8]=e-c;
    ary[9]=e-d;
    for(int i=0; i<10;i++){
        if(ary[i]>k)flag=1;//直接通信出来ないアンテナあり
    }
    if(flag==0)//組が存在しない->直接通信可能
     cout <<"Yay!" <<endl;
    else cout <<":(" <<endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int s = sc.nextInt();

		// 計算
		int result = 1;
		int next = s;
		HashSet<Integer> hs = new HashSet<Integer>();
		hs.add(next);
		while(true){
		    result++;
		    if(next%2 == 0){
		        next /= 2;
		    }else{
		        next = 3 * next + 1;
		    }
		    if(hs.contains(next)){
		        break;
		    }else{
		        hs.add(next);
		    }
		}

		// 出力
		System.out.println(result);
        
	}
}


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

using namespace std;

template<typename T>
bool chmax(T& a, const T& b){
  if(a < b){
    a = b;
    return true;
  }else return false;
}

int main(){
  int H, W, M;
  cin >> H >> W >> M;
  
  vector<pair<int, int>> targets(M);
  vector<int> r(H, 0), c(W, 0);
  for(int i = 0; i < M; i++){
    int h, w;
    cin >> h >> w;
    targets[i] = {--h, --w};
    ++r[h]; ++c[w];
  }
  
  int max_r = 0, max_c = 0;
  int max_r_idx = -1, max_c_idx = -1;
  
  for(int h = 0; h < H; h++){
    if(chmax(max_r, r[h])) max_r_idx = h;
  }
  
  for(int w = 0; w < W; w++){
    if(chmax(max_c, c[w])) max_c_idx = w;
  }
  
  long long max_r_num = 0, max_c_num = 0;
  
  for(int h = 0; h < H; h++){
    if(r[h] == max_r) ++max_r_num;
  }
  
  for(int w = 0; w < W; w++){
    if(c[w] == max_c) ++max_c_num;
  }
  
  long long max_rc_num = 0;
  for(int i = 0; i < M; i++){
    auto [h, w] = targets[i];
    
    if(r[h] == max_r && c[w] == max_c) ++max_rc_num;
  }
  
  if(max_rc_num < max_r_num * max_c_num) cout << max_r + max_c << endl;
  else cout << max_r + max_c - 1 << endl;
  
  return 0;
}

Measured memory_bytes: 7988
n,a,b = map(int,input().split())
s = list(input())
cnt = 0
fcnt = 0
ans = []
for i in s:
  if i=="a":
    cnt +=1
    if cnt <=(a+b):
      ans.append("Yes")
    else:
      cnt -=1
      ans.append("No")
  if i=="b":
    cnt +=1
    fcnt +=1
    if cnt<=(a+b) and fcnt <=b:
      ans.append("Yes")
    else:
      cnt -=1
      fcnt -=1
      ans.append("No")
  if i=="c":
    ans.append("No")

for k in ans:
  print(k)

Measured memory_bytes: 5480
n = int(input())
xy_array = [list(map(int, input().split())) for _ in range(n)]

th = pow(10, 9)
z_max = -th
z_min = th
w_max = -th
w_min = th

for x, y in xy_array:
    z_max = max(x + y, z_max)
    z_min = min(x + y, z_min)
    w_max = max(x - y, w_max)
    w_min = min(x - y, w_min)

ans = max(z_max - z_min, w_max - w_min)
print(ans)

Measured memory_bytes: 45376
N, M = list(map(int, input().split()))
data = [[] for _ in range(N+1)]

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

def dfs(x, been):
    ans = 0
    if len(been) == N:
        return 1
    else:
        for i in data[x]:
            if been.count(str(i)) == 0:
                been += str(i)
                ans += dfs(i, been)
                been = been[:-1]

    return ans

been = '1'
print(dfs(1, been))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e6+100;
struct poi
{
    double x,y;
};

int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    if(s.size()%2){
        printf("No\n");
    }else{
        int n=s.size()/2;
        bool vis=true;
        for(int i=0;i<n;i++){
            if(s[i]!=s[i+n]){
                vis=false;
                break;
            }
        }
        if(vis)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/


void rotate2(vector<int> &A, int b, int e, int t){
    for(int k=0; k<e-b; k++){
        swap(A[b+k], A[t+k]);
    }
}

int main()
{
    int n; cin >> n;
    vector<int> A(n);
    rep(i,n){
        int Ai; cin >> Ai;
        A[i] = Ai;
    }
    int q; cin >> q;
    rep(i,q){
        int b, e, t; cin >> b >> e >> t;
        rotate2(A, b, e, t);
    }
    rep(i,n){
        cout << A[i];
        if(i != n-1) cout << " ";
    }
    cout << endl;
}


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

int main(){
  
  	int a;
    cin >> a;
	vector<long long> A(a);
  
  	for(int i=0; i<a; i++) cin >> A.at(i);
 
  int count=0;
 
  while(true){
  
   bool flag = true;   
    
  	for(int i = 0; i<a; i++){
    	if (A.at(i)%2 == 0) A.at(i) /= 2;
    		else flag = false;}
    
    if(flag == false) break;
    count++;
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
use utf8;
use warnings;
use strict;
use feature qw/say/;

chomp(my $n = <>);
chomp(my $l2 = <>);
my @p = split(/ /, $l2);

my $k = 0;
for (1..$n) {
    $k++ unless $p[$_-1] == $_; 
}
$k <= 2 ? say "YES" : say "NO";

Measured memory_bytes: 768
#![allow(unused_imports)]
#[macro_use]
mod reader {





    #![allow(dead_code)]
    use std;
    macro_rules! read_line((  ) => {
                           {
                           let mut input = String :: new (  ) ; std :: io ::
                           stdin (  ) . read_line ( & mut input ) . unwrap (
                           ) ; input } } ;);

    pub fn read_parse<T: std::str::FromStr>() -> T {
        read_line!().trim().parse().ok().unwrap()
    }
}

use reader::*;
fn main() {
    let n = read_parse::<u64>();
    let mut input: Vec<u64> = Vec::new();
    for _ in 0..5 { input.push(read_parse()); }
    let min = input.iter().min().unwrap();
    println!("{}" , (n + min - 1) / min + 4);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

int N, M, L, Q;
#define MAX_V 500
#define INF (1e9 + 1) // * 100000000LL)

int V;
ll d[MAX_V][MAX_V];

void warshal_floyd(void){
    for (int k = 0; k < V; k++)
        for (int i = 0; i < V; i++)
            for (int j = 0; j < V; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    return;
}


int main() {
    
    string S[100];
    int H, W;
    cin >> H >> W;
    V = H * W;
    
    rep(i, V)rep(j, V)d[i][j] = INF;
    rep(i, H){
        cin >> S[i];
        
    }
    rep(now, H * W){
        //now = 4;
        int i = now/W;
        int j = now%W;
        d[now][now] = 0;
        if (S[i][j] == '.'){
            if (now /W >= 1 && S[i - 1][j] != '#'){
                d[now][now - W] = 1;
                d[now - W][now] = 1;
                //fprintf(stderr, "%d, %d\n", now, now - W);
            }
            if (now /W < H - 1 && S[i + 1][j] != '#'){
                d[now][now + W] = 1;
                d[now + W][now] = 1;
                //fprintf(stderr, "%d, %d\n", now, now + W);
            }
            if (now %W >= 1 && S[i][j - 1] != '#'){
                d[now][now - 1] = 1;
                d[now - 1][now] = 1;
                //fprintf(stderr, "%d, %d\n", now, now - 1);
            }
            if (now % W < W - 1 && S[i][j + 1] != '#'){
                d[now][now + 1] = 1;
                d[now + 1][now] = 1;
                //fprintf(stderr, "%d, %d\n", now, now + 1);
            }
        }
        
    }
    
    // �S�_�ԍŏ�����(Warshall-Floyd)
    warshal_floyd();
    
    int ans = -1;
    rep(i, H * W)rep(j, H * W){
         //fprintf(stderr, "%d, %d -> %d\n", i, j, d[i][j]);
        if (d[i][j] != INF &&
            d[i][j] >= ans){
            ans = d[i][j];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Linq;

public class ABC166C {
	private static void Main(string[] args) {
		var inputs = ReadIntsAsArray();
		var n = inputs[0];
		var m = inputs[1];
		var h = ReadIntsAsArray();
		var isPeakArray = Enumerable.Repeat(true, n).ToArray();

		for (var i = 0; i < m; i++) {
			inputs = ReadIntsAsArray();
			var a = inputs[0];
			var b = inputs[1];

			if (h[a-1] <= h[b-1]) isPeakArray[a-1] = false;
			if (h[b-1] <= h[a-1]) isPeakArray[b-1] = false;
		}

		var answer = isPeakArray.Count(isPeak => isPeak);
		Console.WriteLine(answer);
	}

	private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
}

Measured memory_bytes: 49500
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int N;
  cin >> N;
  int wari = 0;
  wari = 200*(N/15);
  cout << 800*N - wari << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int main() {
  int i;
  char S[100010];
  scanf("%s", S);
  int N = strlen(S);
  int ans = 0;
  char now = S[0];
  for (i = 1; i < N; i++) {
    if (now != S[i]) {
      ans += 1;
      now = S[i];
    }
  }
  printf("%d", ans); 
  return 0;
}


Measured memory_bytes: 256
/* 
 * Author: aps
 * Time: 2019-10-19 20:19:41
**/
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll inf = 1e18;
const ll mod = 1e9+7;
 
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll gcd(ll x, ll y) { return x == 0 ? y : gcd(y % x, x); }
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}


int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n, ans = 0; cin >> n;

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

    sort(a,a+n);
    for(int i=0;i<n;i++) {
        for(int j=i+1;j<n;j++) {
            int l = j, h = n-1, idx = n-1, x = a[i] + a[j];
            
            while(l <= h) {
                int m = (l+h)/2;
                if(a[m] < x) {
                    l = m+1;
                    idx = m;
                } else h = m-1;
            }

            ans += (idx-j);
        }
    }

    cout << ans << "\n";
    
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  rep(i, n) {
    cin >> a[i];
    c[i] = a[i];
  }
  rep(i, n) cin >> b[i];
  sort(c, c + n);
  int x = 0, y = 0, xc, yc, cnt = 0;
  do{
    xc = 0, yc = 0;
    rep(i, n){
      if(a[i] == c[i]) xc++;
      if(b[i] == c[i]) yc++;
    }
    if(xc == n) x = cnt;
    if(yc == n) y = cnt;
    cnt++;
  }while(next_permutation(c, c + n));
      
  
  cout << abs(x - y) << endl;
  
    
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n,m;cin >> n >> m;
  if(n % 2 == 0) {
    int a = 1;
    int b = n;
    rep(i,m) {
      if((n/2) % 2 == 0 && i == m/2 + 1) b--;
      if((n/2) % 2 == 1 && i == m/2) b--;
      cout << a << " " << b << "\n";
      a++; b--;
    }
  }
  else {
    rep1(i,m) {
      cout << i << " ";
      cout << n - i << "\n";
    }
  }
  return 0;
}


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

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

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

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    int a = 0;
    int b = 0;
    for (char c : s) {
        if (c == 'A')
            a++;
        if (c == 'B')
            b++;
    }
    if (a > 0 && b > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Linq;

namespace solution
{
  class Class1
  {
    static void Main()
    {
      string s = Console.ReadLine();
      char[] c = s.ToCharArray();
      for (int i = 0; i < c.Length; i++)
      {
        if (System.Char.IsUpper(c[i])) c[i] = char.ToLower(c[i]);
        else if (char.IsLower(c[i])) c[i] = char.ToUpper(c[i]);
      }
      Console.WriteLine(c);
    }
  }
}


Measured memory_bytes: 9100
#include<stdio.h>
int main(){
	int	N;
	int K;
	int X;
	int Y;
	int W;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N < K) W = N*X,printf("%d\n",W);
	else W = K*X + (N-K)*Y,printf("%d\n",W);
return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long a,n,m,k,s=0,p,ar[101][101],ar1[100001],i,j,c=0,r,t;
int main()
{
	cin>>a>>n>>m;
	k=a*100+n*10+m;
	if(k%4==0) cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 256
from collections import defaultdict
from heapq import heappop, heappush

N, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort(key=lambda x: x[1])
pq = []
f_x = 0
ctr = defaultdict(int)
appeared = 0
for _ in range(K):
    t, d = X.pop()
    heappush(pq, (d, t))
    appeared += int(ctr[t] == 0)
    f_x += d
    ctr[t] += 1

res = f_x + appeared ** 2
while pq or X:
    while pq:
        d, t = heappop(pq)
        if ctr[t] > 1:
            ctr[t] -= 1
            f_x -= d
            break

    if not pq:
        break

    while X:
        t_x, d_x = X.pop()
        if ctr[t_x] == 0:
            heappush(pq, (d_x, t_x))
            f_x += d_x
            ctr[t_x] += 1
            appeared += 1
            res = max(res, f_x + appeared ** 2)
            break

print(res)


Measured memory_bytes: 103596