akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int n = 0;
ll mns = 0, zero = 0, pls = 0;
ll a[(int)2e5 + 1];

ll lowpNum(ll x) { //x > 0
  ll sum = 0;
  {
    //int right = n - 1;
    for (int right = n - 1, left = mns + zero; left < n; left++) {
      while (left < right && a[left] * a[right] >= x)
        right--;
      sum += right - left;
      if (right == left) break;
    }
  }
  {
    //int left = 0;
    for (int left = 0, right = mns - 1; right >= 0; right--) {
      while (left < right && a[left] * a[right] >= x)
        left++;
      sum += right - left;
      if (right == left) break;
    }
  }
  return sum;
}

ll lowmNum(ll x) { //x < 0
  ll sum = 0;
  int pright = mns + zero;
  for (int mleft = 0; mleft < mns; mleft++) {
    while (pright < n && a[mleft] * a[pright] >= x)
      pright++;
    sum += n - pright;
  }
  return sum;
}
    

int main() {
  ll k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < 0) mns++;
    if (a[i] == 0) zero++;
    if (a[i] > 0) pls++;
  }
  sort(a, a + n);
  ll mpair = mns * pls;
  ll zpair = zero * (mns + pls) + zero * (zero - 1) / 2;
  if (k <= mpair) {
    //sign = -1;
    ll inf = -1e18 - 1, sup = -1;
    while (inf < sup - 1) {
      ll mid = (inf + sup) / 2;
      if (lowmNum(mid) < k) inf = mid;
      else sup = mid;
    }
    cout << inf << endl;
  } else if (k <= mpair + zpair) {
    //sign = 0;
    cout << 0 << endl;
  } else {
    //sign = 1;
    k -= mpair + zpair;
    ll inf = 1, sup = 1e18 + 1;
    while (inf < sup - 1) {
      ll mid = (inf + sup) / 2;
      if (lowpNum(mid) < k) inf = mid;
      else sup = mid;
    }
    cout << inf << endl;
  }
  return 0;
}

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

int main(int argc, char const *argv[])
{
	//freopen("input.txt" , "r" , stdin) ;

	int a , b, c ;

	cin >> a >> b >> c ;

	int ans = b/a ;

	printf("%d\n", min(ans, c));

	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	sort(v.rbegin(), v.rend());
	long long int ans = 0;
	for (int i = 1; i < N; i++) {
		ans += v[i / 2];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

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

int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(0);

	for (int i = 0; i < 5; i++) {
		int k; cin >> k;
		if (k == 0) { cout << (i + 1) << endl; }
	}

	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;

int main(int argc,char const* argv[])
{
  int a,b;
  cin >> a >> b;
  cout << a*b-a-b+1 << endl;
  return 0;
}


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

using ll = long long;
const ll INF = 1LL<<60;
const ll MOD = 1000000007LL;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP2(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく


void solve() {
	int A1,A2,A3;
    cin >> A1 >> A2 >> A3;
	
    int B=A1+A2+A3;
    
  	puts(B>21?"bust":"win");

	return;
}

signed main() {
    

    solve();

    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int main() {
	int a,b,h;
	cin >> a >> b >> h;
	

	cout << (a+b)*h/2 << endl;
	return 0;
}

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

using namespace std;

int main(){
    int n; cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll y = n/i;
        ans += (y * (y + 1) * i) / 2;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3680
package main

import "fmt"

func main() {
	var x [2]int
	fmt.Scan(&x[0], &x[1])
	ans := 0
	for i := 0; i < len(x); i++ {
		if x[i] == 1 {
			ans += 300000
		} else if x[i] == 2 {
			ans += 200000
		} else if x[i] == 3 {
			ans += 100000
		}
	}
	if x[0] == 1 && x[1] == 1 {
		ans += 400000
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,a,b = list(map(int, input().split()))
dif = b-a-1
if dif%2==0:
    ans = "Borys"
else:
    ans = "Alice"
print(ans)

Measured memory_bytes: 61920
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let h = i.read_vec::<usize>(n);

    let mut count = 0;
    let mut h_max = 0;
    for h in h {
        if h >= h_max {
            count += 1;
            h_max = h;
        }
    }

    writeln!(o, "{}", count).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


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

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
	}

int main(){
	int N,nn;
	int A[200005];
	int flag=0;
	
	scanf("%d",&N);
	
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
		
	qsort( A, N, sizeof(int), cmp );
	
	for(int i=0;i<N;i++){
		if(A[i]==A[i+1]){
			flag =1;
			break;
		}
	}
	
	if(flag == 1){
		printf("NO");
	}
	else printf("YES");

	return 0;
}


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#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;
int main()
{
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i,n){
    cin >> s[i];
  }

  sort(s.begin(), s.end());
  string res = "";
  rep(i,n){
    res += s[i];
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0
                
for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == 0:
        print("Yes")
        exit()
for j in range(3):
    if A[0][j] == A[1][j] == A[2][j] == 0:
        print("Yes")
        exit()
if A[0][0] == A[1][1] == A[2][2] == 0:
    print("Yes")
    exit()
if A[0][2] == A[1][1] == A[2][0] == 0:
    print("Yes")
    exit()
    
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#define maxn 1000000
using namespace std;
int prime[maxn],number[maxn];
void getprime()
{
    int m=sqrt(maxn+0.5);
    for(int i=2;i<=m;i++)
    {
        if(!prime[i])
        {
            for(int j=i+i;j<maxn;j+=i)
            {
                prime[j]=1;
            }
        }
    }
    int sum = 0;
    for(int i=2;i<maxn;i++)
    {
        if(!prime[i])
        {
            sum++;
        }
        number[i]=sum;
    }
}
int main ()
{
    int n;
    getprime();
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",number[n]);
    }
}
/**
--------------------- 
???zhaiqiming2010 
???CSDN 
???https://blog.csdn.net/zhaiqiming2010/article/details/62281598 
?????????????????????????
**/


Measured memory_bytes: 10944
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

int n;
vector<vector<int>> edge;
vector<int> x;

P dfs(int v){
    vector<P> vp;
    for(int u : edge[v]){
        vp.push_back(dfs(u));
    }

    vector<vector<int>> dp(SZ(vp) + 1, vector<int>(5001, INF));
    dp[0][0] = 0;
    rep(i, SZ(vp)){
        rep(j, 5000){
            if(j + vp[i].first <= 5000){
                dp[i+1][j+vp[i].first] = min(dp[i+1][j+vp[i].first], dp[i][j] + vp[i].second);
            }
            if(j + vp[i].second <= 5000){
                dp[i+1][j+vp[i].second] = min(dp[i+1][j+vp[i].second], dp[i][j] + vp[i].first);
            }
        }
    }

    int ans = -1;
    for(int i = 0; i <= x[v]; i++){
        if(dp[SZ(vp)][i] < INF){
            //cout << v << " " << i << " " << dp[SZ(vp)][i] << endl;
            ans = dp[SZ(vp)][i];
        }
    }
    //cout << endl;

    if(ans == -1){
        cout << "IMPOSSIBLE" << endl;
        exit(0);
    }

    //cout << v << " " << x[v] << " " << ans << endl;
    return {x[v], ans};
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    edge = vector<vector<int>>(n + 1, vector<int>());
    for(int i = 2; i <= n; i++){
        int p;
        cin >> p;
        edge[p].push_back(i);
    }
    x = vector<int>(n + 1);
    rep(i, n) cin >> x[i+1];

    dfs(1);
    cout << "POSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 39424
def run(n, s):
    '''
    文字列sを半分に分けて、右半分を逆順に並び替える
    さらに色の塗分けを逆にすると、左半分と右半分は
    同じになる
    '''
    sl = s[0:n]
    sr = s[n:2*n][::-1]

    keys1 = [c[0]+'-'+c[1] for c in comb(sl)]
    keys2 = [c[0]+'-'+c[1] for c in comb(sr)]
    dict = {}
    for key1 in keys1:
        if key1 in dict:
            dict[key1] += 1
        else:
            dict[key1] = 1
    cnt = 0
    for key2 in keys2:
        if key2 in dict:
            cnt += dict[key2]
    return cnt


def comb(s):
    if len(s) == 1:
        return [(s, ''), ('', s)]
    else:
        ret = []
        for c in comb(s[0:len(s)-1]):
            ret.append((c[0]+s[-1], c[1]))
            ret.append((c[0], c[1]+s[-1]))
        return ret


def read_line():
    n = int(input())
    s = input()
    return (n, s)


def main():
    n, s = read_line()
    print(run(n, s))


if __name__ == '__main__':
    main()


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

main() {
    string S; cin >> S;
    int N,M=0;
    N=stol(S); rep(i,S.size()) M+=S[i]-'0';
    if(N%M==0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main() {
	int K, A, B;
	cin >> K >> A >> B;
	for (int i = A; i <= B; i++) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}

Measured memory_bytes: 3624
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
typedef long long ll;
const int mod=1e9+7;
#define lol(i,n) for(int i=0;i<n;i++)

using namespace std;
int n,a[100010],b[100010];
//vector<pair<int,int>> a;
ll sum=0,s=0;
int main() {
    cin >>n;
    lol(i,n){
        //int x,y;
        cin >>a[i]>>b[i];
       // a.push_back(make_pair(x,y));
    }
    //sort(a.begin(),a.end());
    sort(a,a+n);
    sort(b,b+n);
    int x,y;
    x=0;
    lol(i,n){
        sum++;
        while(b[x]<=a[i]){
            sum--;
            x++;
        }
        s=max(sum,s);
    }
    cout << s<< endl;
}



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 63 - 1;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

  ll ans = INFL;
  for (int a = 0; a < n - 1; a++) {
    for (int b = a + 1; b < n; b++) {
      for (int c = 0; c < n - 1; c++) {
        for (int d = c + 1; d < n; d++) {
          ll satan = min(x[a], x[b]), utan = max(x[a], x[b]);
          ll katan = min(y[c], y[d]), jotan = max(y[c], y[d]);
          int count = 0;
          for (int i = 0; i < n; i++)
            count += (satan <= x[i] && x[i] <= utan && katan <= y[i] && y[i] <= jotan);
          if (count >= k) {
            ans = min(ans, (utan - satan) * (jotan - katan));
          }
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string a,b,c;
    cin>>a>>b>>c;
    cout<<a.at(0)<<b.at(1)<<c.at(2)<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <utility>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
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 FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)

int n, w;
vector<pair<int, int> > wv;
ll dp[100100][101];

int main(){
	REP(i, 100100) REP(j, 101) dp[i][j] = INF;
	cin >> n >> w;
	REP(i, n){
		int a1, a2;
		cin >> a1 >> a2;
		wv.push_back(make_pair(a2,a1));
	}
	dp[0][0] = 0;
	REP(i, n) REP(j, 100100){
		chmin(dp[j][i+1], dp[j][i]);
		if (j - wv[i].first >= 0){
			chmin(dp[j][i+1], dp[j - wv[i].first][i] + wv[i].second);
		}
	}
	int ans_max = 0;
	for (int i = 0;i < 100100;i++){
		if (dp[i][n] <= w) ans_max = i;
	}
	cout << ans_max << endl;

}

Measured memory_bytes: 79232
m,k=map(int,input().split())
if k>=2**m:
    print(-1)
elif m==0:
    print('0 0')
elif m==1:
    if k==0:
        print('0 0 1 1')
    else:
        print(-1)
elif k<2**m:
    l=[i for i in range(2**m)]
    l.remove(k)
    l_=l.copy()
    l_ = l_ + [k] + l_[::-1] + [k]
    print(' '.join(map(str,l_)))
else:
    print('-1')

Measured memory_bytes: 28424
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int Ans = 0;
  int x = 0;
  for (int i=0 ; i < S.size() ; i++){
    if (S.at(i) == 'A'){
      x++;
    }
    else if (S.at(i) == 'C'){
      x++;
    }
    else if (S.at(i) == 'G'){
      x++;
    }
    else if (S.at(i) == 'T'){
      x++;
    }
    else{
      x = 0;
    }
    if (x > Ans){
      Ans = x;
    }
    //cout << Ans << endl;
  }
  cout << Ans << endl;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    complex<double> p[4];
    for (int i = 0; i < 4; ++i) {
      double x, y;
      cin >> x >> y;
      p[i] = complex<double>(x, y);
    }
    complex<double> v1 = p[1] - p[0], v2 = p[3] - p[2];
    double a = abs(v1.real() * v2.imag() - v1.imag() * v2.real());
    cout << ((a < 1e-10) ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 1232
Q = int(input())

def derive_k(n):#n/k - n/(k+1) >= 1となる最大のkを求める。ただしn>=2
  if n == 1:
    return 0
  lt = 1
  rt = n
  while rt - lt > 1:
    ct = (lt + rt) // 2
    if n >= ct * (ct+1):
      lt = ct
    else:
      rt = ct
  return lt  
  
for _ in range(Q):
  A, B = map(int,input().split())
  k = derive_k(A*B) #A*B/k - A*B/(k+1) >= 1となる最大のkを求める
  ans = k + (A*B-1)//(k+1) - 1
  #print(A, B, k, (A*B-1)//(k+1))
  if k+1 == A and k*(k+1) < A*B:
    ans += 1
  print(ans)
  


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int arr[n], val[n];
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	val[n-1] = 0;
	val[n-2] = abs(arr[n-2]-arr[n-1]);

	for(int i = n-3; i>=0; i--)
		val[i] = min(abs(arr[i]-arr[i+1]) + val[i+1], abs(arr[i]-arr[i+2]) + val[i+2]);
	cout << val[0];
}

Measured memory_bytes: 1024
N = int(raw_input())
S = raw_input()

count_white = [0]*N

for i in range(N):
    if S[i] == ".":
        count_white[i] = count_white[i-1] + 1
    else:
        count_white[i] = count_white[i-1]

white_total = count_white[-1]
ans = 10**9
for i in range(N):
    num_black_left = i+1 - count_white[i]
    num_white_right = white_total - count_white[i]

    ans_temp = num_black_left + num_white_right

#    print i, ans_temp                                                                                                                                    

    ans = min(ans, ans_temp)

print min(ans, white_total)




Measured memory_bytes: 15564
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int disitsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int res = 0;
    For(i,1,n+1){
        int c = disitsum(i);
        if(a<=c&&c<=b){
            res+=i;
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    pre = ""
    post = ""
    for _ in range(n):
        l = input().strip().split()
        pre += l[0]
        post += l[1]
    m = int(input())
    data = ""
    for _ in range(m):
        data += input().strip()
    print(data.translate(str.maketrans(pre, post)))

Measured memory_bytes: 7880
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
  int N;
  cin >> N;
  vector<int> ans(N);
  vector<int> A(N-1);
  rep(i,N-1){
    cin >> A.at(i);
    ans.at(A.at(i)-1) ++; 
  }
  rep(i,N){
    cout << ans.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 4768
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int a, b, t, x;

int main(){
    cin >> a >> b >> t;
    for(int i = 0; i < t+0.5; i = i + a){
        x = x + b;
    }

    cout << x - b;

}


//g++ -std=c++14 comp.cpp; ./a.exe


Measured memory_bytes: 256
N = int(input())
hs =[list(map(int, input().split())) for i in range(N)]
a = []
b = []
c = []
for i, j, k in hs:
    a.append(i)
    b.append(j)
    c.append(k)
adp = [a[0]] + [0]*(N-1)
bdp =[b[0]] + [0]*(N-1)
cdp = [c[0]] + [0]*(N-1)
for i in range (1, N):
    adp[i] = max(bdp[i-1] + a[i], cdp[i-1]+a[i])
    bdp[i] = max(adp[i-1] + b[i], cdp[i-1]+b[i])
    cdp[i] = max(bdp[i-1] + c[i], adp[i-1]+c[i])
print(max(adp[N-1], bdp[N-1], cdp[N-1]))

Measured memory_bytes: 45568
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	ll x; cin >> x;
	ll ans = x / 11;
	if (x % 11 == 0)cout << ans * 2 << endl;
	else if (x % 11 <= 6) cout << ans * 2 + 1 << endl;
	else cout << ans * 2 + 2 << endl;
	return 0;
}

Measured memory_bytes: 256
A = [0]
N = int(input())
A.extend(list(map(int, input().split())))
A.append(0)
ALL = 0
for i in range(1, N+2):
    ALL += abs(A[i-1] - A[i])
for i in range(1, N+1):
    print(ALL - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]))


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

int main(){
    ll n,m;
    scanf("%lld%lld",&n,&m);
    vector<pair<ll,ll>> dr(n);
    for(int i = 0; i < n; i++){
        scanf("%lld%lld",&dr[i].first,&dr[i].second);
    }
    sort(dr.begin(),dr.end());
    ll cnt = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += (min((dr[i].first * (m - cnt)),dr[i].first * dr[i].second));
        cnt += dr[i].second;
        if(cnt >= m)
        break;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
struct answer{int x1,y1,x2,y2;};
int main(){
	int h,w;
	cin>>h>>w;
	int coin[h+2][w+2]={};
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>coin[i][j];
			coin[i][j]%=2;
		}
	}
	vector<int> x1,y1,x2,y2;
	int x=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<w;j++){
			if(coin[i][j]==1){
				x1.push_back(i);
				y1.push_back(j);
				x2.push_back(i);
				y2.push_back(j+1);
				x++;
			}
			coin[i][j+1]=(coin[i][j]+coin[i][j+1])%2;
		}
	}
	for(int i=1;i<h;i++){
		if(coin[i][w]==1){
			x1.push_back(i);
			y1.push_back(w);
			x2.push_back(i+1);
			y2.push_back(w);
			x++;
		}
		coin[i+1][w]=(coin[i][w]+coin[i+1][w])%2;
	}
	cout<<x<<endl;
	for(int i=0;i<x;i++){
		cout<<x1[i]<<" "<<y1[i]<<" "<<x2[i]<<" "<<y2[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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++)
ll PowMod(ll N, ll P, ll M) {   // Calc N^P mod M ()
    if(P == 0) return 1;
    if(P%2 == 0) {
        ll t = PowMod(N, P/2, M);
        return (t%M)*(t%M);
    }
    return N*PowMod(N, P-1, M)%M;
} 


int main() {
    ll N;
    cin >> N;

    ll ret;

    if(N%2) {
        ret = N/2 + 1;
    } else {
        ret = N/2;
    }

    cout << ret << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int inputInt = scanner.nextInt();
        int bigCoins = inputInt / 500;
        int nokori = inputInt % 500;
        int smallCoins = nokori / 5;
        System.out.println(bigCoins * 1000 + smallCoins * 5);
    }
}


Measured memory_bytes: 21844
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[210000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		scanf("%d",p+i);
	}
	p[b]=p[0]+a;
	int ret=0;
	for(int i=0;i<b;i++){
		ret=max(ret,p[i+1]-p[i]);
	}
	printf("%d\n",a-ret);
}

Measured memory_bytes: 896
#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;

int n,h,w;  
string s,t;

int main() {
  cin >> s;
  s.insert(4," ");
  cout << s << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

#include<unistd.h>
struct Buffer{
    int idx;
    enum { chunk = 1 << 16 };
    char buf[chunk];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, chunk); }
    void check(){ if(idx == chunk){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};

string ans;
void out(int num){
    if(!num){
        // putchar('0');
        ans += '0';
        return;
    }
    char buf[16];
    int idx = 0;
    while(num){
        auto ret = div(num, 10);
        buf[idx] = ret.rem + '0';
        num = ret.quot;
        idx++;
    }
    for(int i = idx - 1; i >= 0; i--){
        // putchar(buf[i]);
        ans += buf[i];
    }
}

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    Buffer buf;
    const int lim = 1e5;
    vector<char> prime(lim + 1, true);
    prime[0] = prime[1] = false;
    for(int i = 2; i <= lim; i++){
        if(prime[i]){
            for(int j = i + i; j <= lim; j += i){
                prime[j] = false;
            }
        }
    }
    vector<int> accs(lim + 1);
    // for(int i = 1; i <= lim; i++){
    //     accs[i] = accs[i - 1] + (i & 1 && prime[i] && prime[(i + 1) >> 1]);
    // }
    for(int i = 1; i <= lim; i += 2){
        accs[i] = prime[i] && prime[(i + 1) >> 1];
    }
    for(int i = 1; i <= lim; i++){
        accs[i] += accs[i - 1];
    }
    // printd(accs[lim]);
    // int q; cin >> q;
    int q = buf.next();
    // stringstream ss;
    ans.reserve(4 * q);
    for(int i = 0; i < q; i++){
        // int l, r;
        // cin >> l >> r;
        int l = buf.next(), r = buf.next();
        // cout << accs[r] - accs[l - 1] << '\n';
        // ss << accs[r] - accs[l - 1] << '\n';
        out(accs[r] - accs[l - 1]);
        // putchar('\n');
        ans += '\n';
    }
    // cout << ss.str();
    cout << ans;
    // write(1, ans.data(), ans.size());
}


Measured memory_bytes: 1536
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=N-c_min
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==N:
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)

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

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

int main()
{
    string s;
    int out=700;
    cin >> s;
    int cnt;
    cnt = count(s.begin(),s.end(),'o');
    out += cnt*100;
    cout << out << endl;
    return 0;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n, k;
  cin >> n >> k;
  priority_queue<pii> pq1;
  vector<int> ts(n, 0);
  REP(i, n) {
    int t, d;
    cin >> t >> d;
    t--;
    pq1.push(make_pair(d, t));
  }

  ll base = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq2;
  REP(i, k) {
    auto x = pq1.top();
    pq1.pop();
    pq2.push(x);
    ts[x.second]++;
    base += x.first;
  }

  ll p = 0;
  vll ans(n + 1, 0LL);
  REP(i, n) if (ts[i] > 0) p++;
  ans[p] = base + p * p;

  while (!pq2.empty()) {

    auto y = pq2.top();
    pq2.pop();
    if (ts[y.second] <= 1)
      continue;

    while (!pq1.empty()) {

      auto x = pq1.top();
      pq1.pop();

      if (ts[x.second] > 0)
        continue;

      ts[y.second]--;
      ts[x.second]++;
      base -= y.first;
      base += x.first;
      p++;

      ans[p] = base + p * p;
      break;
    }
  }

  ll a = 0;
  REP(i, n + 1) {
    // cout << i << " : " << ans[i] << endl;
    a = max(a, ans[i]);
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 5232
n, m = [int(x) for x in input().split(" ")]
MOD = int(1e9 + 7)


fact = [0 for _ in range(m + 1)]
fact[0] = 1
for i in range(1, m + 1):
    fact[i] = fact[i-1] * i % MOD

finv = [0 for _ in range(m + 1)]
finv[m] = pow(fact[m], MOD-2, MOD)
for i in range(m-1, -1, -1):
    finv[i] = finv[i+1] * (i + 1) % MOD

def nCk(n, k):
    return fact[n] * finv[k] * finv[n-k] % MOD

def nPk(n, k):
    return fact[n] * finv[n-k] % MOD

ans = 0
for k in range(0, n + 1):
    tmp = nCk(n, k) * nPk(m, k) * (nPk(m-k, n-k) ** 2)
    if k % 2 == 0:
        ans += tmp
    else:
        ans -= tmp
    ans = ans % MOD

print(ans)



Measured memory_bytes: 48432
import scala.util.control.Breaks
object Main {
  def main(args: Array[String]) {
    var str1_check_flg:Array[Int] = Array.fill(26)(0)
    var str2_check_flg:Array[Int] = Array.fill(26)(0)
    val break = new Breaks

    val str1 = scala.io.StdIn.readLine()
    val str2 = scala.io.StdIn.readLine()
    val ascii_change = 'a'.toByte
    var check = true

    break.breakable {
      for(i <- 0 until str1.length) {
        val str1_ascii = str1(i) - ascii_change
        val str2_ascii = str2(i) - ascii_change
        
        str1_check_flg(str1_ascii) += 1
        str2_check_flg(str2_ascii) += 1
        if(!(str1_check_flg(str1_ascii) == str2_check_flg(str2_ascii))) {
          check = false
          break
        }
      }
    }

    if(check) {
      println("Yes")
    }
    else {
      println("No")
    }
  }
}

Measured memory_bytes: 29468
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int N, d[50];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}



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

void solve() {
    ll n;
    cin >> n;

    ll ab = 0, ans = 0;
    for (ll a = 1; a*a < n; a++) {
        ab = a;
        ans += (n-1) / a;
    }
    cout << 2*ans - ab*ab << endl;

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, T, ans = 0;
    cin >> N >> T;
    vector<int64_t> t(N);
    for (int i = 0; i < N; i++) {
        cin >> t.at(i);
    }
    for (int i = 0; i < N - 1; i++) {
        ans += min(T, t.at(i + 1) - t.at(i));
    }
    cout << ans + T << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
    #define debug(x) cerr<<#x<<":"<<x<<endl
    const int maxn=(int)1e6+5;
    int main(){
        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
        int n1,n2;
        vector<int> v1,v2;
        cin>>n1;
        rep(i,1,n1){int x;cin>>x; v1.push_back(x);}
        cin>>n2;
        rep(i,1,n2){int x;cin>>x; v2.push_back(x);}
        cout<<lexicographical_compare(v1.begin(),v1.end(),v2.begin(),v2.end())<<endl;
    }


Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

int main(void)
{
	vector<bool> a(30);
	for (int i = 0; i < 28; i++)
	{
		a[getInt() - 1] = true;
	}
	for (int i = 0; i < 30; i++)
	{
		if(!a[i]) cout << i + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<cstring>
using namespace std;
#define INF int(1e9)
#define maxn 16

#define bset(n, bit) (n | 1<<bit)
#define bclr(n, bit) (n & ~(1<<bit))

int dp[1<<maxn][maxn];
int n,E;
int dist[maxn][maxn];

int path(int S,int v)
{
    if(dp[S][v]>=0){
        return dp[S][v];
    }
    if((S==0) && (v==0)){
        return dp[S][v]=0;
    }
    int res = INF;
    for(int u=0; u<n; u++){
        if(((S>>u)&1) == 1 && u!=v){
            res=min(res, path(bclr(S, u), u) + dist[u][v]);
        }
    }
    return dp[S][v]=res;
}

int main()
{
    cin>>n>>E;
    memset(dist,0x3f,sizeof(dist));
    for(int i=0;i<E;i++){
        int a,b,c;
        cin>>a>>b>>c;
        dist[a][b]=c;
    }
    memset(dp,-1,sizeof(dp));
    int ans = path((1<<n) - 1, 0);
    if(ans==INF) ans=-1;
    cout<<ans<<endl;
}



Measured memory_bytes: 7224
import Text.Parsec
import Data.List
import qualified Data.ByteString as B
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy.Char8 as BLC
import Control.Applicative hiding ((<|>))
-- learning parsec..
-- {{{ data
data Command = Forward Int
             | Backward Int
             | TurnRight
             | TurnLeft deriving (Show)

type Loc = (Int, Int)
type Vec = (Int, Int)

turnRight :: Vec -> Vec
turnRight (x,y) = (y,-x)
turnLeft :: Vec -> Vec
turnLeft (x,y) = (-y,x)

data Robot = Robot {
           _loc :: Loc,
           _dir :: Vec,
           _field :: (Int,Int)
}
instance Show Robot where
    show (Robot (x,y) _ _) = unwords. map show $ [x,y]
initRobot :: Int -> Int -> Robot
initRobot x y = Robot (1,1) (0,1) (x,y)

(*:) :: Int -> Vec -> Vec
n *: (x,y) = (n*x, n*y)
(+:) :: Vec -> Vec -> Vec
(x,y) +: (z,w) = (x+z,y+w)
fitIn :: Int -> Int -> Int
fitIn x w = if x <= 0 then 1 else min x w
stayInside :: Vec -> Vec -> Vec
stayInside (x,y) (w,h) = (x `fitIn` w, y `fitIn` h)

data Input = Input Int Int [Command] deriving (Show)
-- }}}
-- {{{ parser
num :: Parsec ByteString u Int
num = read <$> many1 digit

command :: Parsec ByteString u Command
command = Forward <$> (string "FORWARD" *> spaces *> num)
      <|> Backward <$> (string "BACKWARD" *> spaces *> num)
      <|> const TurnRight <$> string "RIGHT"
      <|> const TurnLeft <$> string "LEFT"

singleInput :: Parsec ByteString u Input
singleInput = Input <$> (spaces *> num)
                    <*> (spaces *> num <* spaces)
                    <*> command `sepEndBy` spaces
                    <* string "STOP"
inputs :: Parsec ByteString u [Input]
inputs = (singleInput <* spaces) `manyTill` (char '0' *> spaces *> char '0')
-- }}}
-- {{{ solver
applyCmd :: Robot -> Command -> Robot
applyCmd r@(Robot l d s) (Forward n) =
        r {_loc = (l +: (n *: d)) `stayInside` s}
applyCmd r@(Robot l d s) (Backward n) =
        r {_loc = (l +: ((-n) *: d)) `stayInside` s}
applyCmd r@(Robot{_dir=d}) TurnRight = r {_dir = turnRight d}
applyCmd r@(Robot{_dir=d}) TurnLeft = r {_dir = turnLeft d}

solve :: Input -> Robot
solve (Input x y cmds) = let r = initRobot x y in
    foldl' applyCmd r cmds
-- }}}
main = B.getContents >>=
    mapM_ (BLC.putStrLn . BLC.pack . show . solve)
        . (\(Right r) -> r) . parse inputs ""
-- vim:fdm=marker

Measured memory_bytes: 4920
N=int(input())
cs=input()

l=[]
for c in cs:
    l.append(1 if c=='R' else 0)

iW=0
iR=N-1
ans=0
while True:
    #iW
    while l[iW]!=0:
        iW+=1
        if iW > N-1:
            break
    #iR
    while l[iR]!=1:
        iR-=1
        if iR<0:
            break
    if iW<iR:
        l[iW],l[iR]=l[iR],l[iW]
        ans+=1
    else:
        break
print(ans)

Measured memory_bytes: 10928
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
vector<ll> g[200005];
ll value[200005]={0};
void dfs(ll pre,ll tmp,ll sum){
  value[tmp]+=sum;
  for(auto out:g[tmp]) if(out!=pre) dfs(tmp,out,value[tmp]);
}
int main(){
  ll n,q;
  cin>>n>>q;
  rep(i,n-1){
    ll a,b;cin>>a>>b;a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(i,q){
    ll a,b;cin>>a>>b;a--;
    value[a]+=b;
  }
  dfs(-1,0,0);
  rep(i,n){
    cout<<value[i]<<' ';
  }
  cout<<endl;
}

Measured memory_bytes: 24320
import sys
read = lambda: sys.stdin.readline().rstrip()
 
def main():
    INF = 10 ** 20
 
    n,k = map(int,input().split())
    height = tuple(map(int,read().split()))
    dp = [INF]*(n+1)
    dp[0] = 0
 
    for target in range(1, n):
        for step in range(1, k + 1):
            if target-step >= 0: dp[target] = min(dp[target], dp[target - step] + abs(height[target] - height[target - step]))
 
    print(dp[n-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 56800
a,b,c,d = list(map(int,input().split()))
a = c-a
b = d-b
print('R'*a+'U'*b+'L'*a+'D'*(b+1)+'R'*(a+1)+'U'*(b+1)
    +'L'+'U'+'L'*(a+1)+'D'*(b+1)+'R')

Measured memory_bytes: 3060
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	cin>>n;
	string s[n],tmp;
	bool check=false;
	rep(i,n){
		cin>>s[i];
	}
	cin>>m;
	rep(i,m){
		cin>>tmp;
		bool uk=true;
		rep(j,n){
			if(tmp==s[j]){
				cout<<((check)?"Closed":"Opened")<<" by "<<s[j]<<endl;
				uk=false;
				check=!check;
				break;
			}
		}
		if(uk)cout<<"Unknown "<<tmp<<endl;
	}
	return 0;
}

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

using namespace std;

const int N = 210005;

int n;
int top, fi[N], ne[N << 1], to[N << 1];
int mv[N], size[N], d[N], q[N], c[N];

void add(int u, int v);
void calcu(int t, int fa, int val);
void dfs1(int t, int fa);
void dfs2(int t, int fa);

int main() {
  scanf("%d", &n);
  for (int i = 2, u, v; i <= n; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  dfs1(1, 0), dfs2(1, 0);
  for (int i = 2; i <= n; ++i) printf("%d ", c[i]);
  puts("");
  return 0;
}

void add(int u, int v) {
  ne[++top] = fi[u], fi[u] = top, to[top] = v;
}

void calcu(int t, int fa, int val) {
  q[t] = 1;
  for (int i = fi[t]; i; i = ne[i]) {
    if (to[i] == fa || to[i] >= val) continue;
    calcu(to[i], t, val);
    q[t] += q[to[i]];
  }
}

void dfs1(int t, int fa) {
  mv[t] = max(t, mv[fa]);
  size[t] = 1;
  for (int i = fi[t]; i; i = ne[i]) {
    if (to[i] == fa) continue;
    dfs1(to[i], t);
    size[t] += size[to[i]], d[t] += d[to[i]];
  }
  if (mv[t] == t) {
    calcu(t, fa, mv[fa]);
    d[t] = -size[t];
  }
  if (mv[fa] == fa) 
    d[t] += size[t];
}

void dfs2(int t, int fa) {
  if (fa) {
    if (mv[t] == t) c[t] += q[t];
    else if (mv[fa] == fa) c[t] -= q[t], c[t] += d[t];
    c[t] += c[fa];
  }
  for (int i = fi[t]; i; i = ne[i]) 
    if (to[i] != fa) dfs2(to[i], t);
}


Measured memory_bytes: 18304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

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

struct Combination{
    vector<long long> _fac,_finv,_inv;
    const int m = MOD;

    Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){
        _fac[0] = _fac[1] = 1;
        _finv[0] = _finv[1] = 1;
        _inv[1] = 1;
        for(int i = 2; i <= sz; i++){
            _fac[i] = _fac[i-1]*i%m;
            _inv[i] = m-_inv[m%i]*(m/i)%m;
            _finv[i] = _finv[i-1]*_inv[i]%m;
        }
    }

    inline long long fac(int n){return _fac[n];}
    inline long long inv(int n){return _inv[n];}
    inline long long finv(int n){return _finv[n];}

    long long comb(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return _fac[n]*(_finv[k]*_finv[n-k]%m)%m;
    }
};



int main(){
    int N; cin >> N;
    string S; cin >> S;
    int cnt = 0;
    ll ans = 1;
    Combination C(200000);
    rep(i,2*N){
        if(cnt % 2 == 0){
            if(S[i] == 'W'){
                ans *= cnt;
                ans %= MOD;
                cnt--;
            }
            else{
                cnt++;
            }
        }
        else{
            if(S[i] == 'W'){
                cnt++;
            }
            else{
                ans *= cnt;
                ans %= MOD;
                cnt--;
            }
        }
    }
    if(cnt != 0){
        cout << 0 << endl;
        return 0;
    }
    ans *= C.fac(N);
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 5252
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int w = scanner.nextInt();
		int h = scanner.nextInt();
		int n = scanner.nextInt();
		int nowx = scanner.nextInt();
		int nowy = scanner.nextInt();
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			if ((nowx < x && nowy < y) || (nowx > x && nowy > y)) {
				ans += Math.max(Math.abs(y - nowy), Math.abs(x - nowx));
			} else {
				ans += Math.abs(y - nowy) + Math.abs(x - nowx);
			}
			nowx = x;
			nowy = y;
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 25556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  int A[101][101]={0};
  rep(i,N) rep(j,N) if((N%2==1&&i+j!=N-2)||(N%2==0&&i+j!=N-1)) A[i][j]=1;
  cout<<N*(N-1)/2-N/2<<endl;
  rep(i,N) rep(j,N) if(i<j&&A[i][j]) cout<<i+1<<" "<<j+1<<endl;
}

Measured memory_bytes: 256