akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
	int K,S,X,Y,Z,i=0;
	scanf("%d %d",&K,&S);
	if(3*K<S){
		printf("0");
		return 0;
	}
	if(3*K==S){
		printf("1");
		return 0;
	}
	for(X=0;X<=K;X++){
		if(X>S)break;
		for(Y=X+1;Y<=K;Y++){
			if(X+Y>S)break;
			for(Z=Y+1;Z<=K;Z++)
			{
				if(X+Y+Z>S)break;
				if(X+Y+Z==S)i=i+6;
			}
		}
	}
	
	for(X=0;X<=K;X++){
		for(Z=0;Z<=K;Z++){
			if(X*2+Z>S)break;
			if(X==Z)continue;
			if(2*X+Z==S)i=i+3;
		}
	}
    for(X=0;X<=K;X++){
    	if(3*X>S)break;
    	if(3*X==S)i++;
	}
	printf("%d\n",i);
	return 0;
}

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

int A, B, C;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> A >> B >> C;

    bool f = false;
    for (int i = 1; i < B; i++) {
        if (i * A % B == C) {
            f = true; break;
        } 
    }

    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int res = 0;
    if(A<=K) {
        res += A;
        K-=A;
    } else {
        res += K;
        K = 0;
    }
    K -= B;
    if(C<=K) {
        res -= C;
    } else if(K>0) {
        res -= K;
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    N, M = [int(x) for x in sys.stdin.readline().split()]
    pS_list = [[x for x in sys.stdin.readline().split()] for _ in range(M)]

    aced_list = [False for _ in range(N)]
    penal_list = [0 for _ in range(N)]
    for p, s in pS_list:
        p = int(p) - 1
        if s == 'AC':
            aced_list[p] = True
        else:
            if not aced_list[p]:
                penal_list[p] += 1

    for i in range(N):
        if not aced_list[i]:
            penal_list[i] = 0

    print(sum(aced_list), sum(penal_list))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 5
1 WA
1 AC
2 WA
2 AC
2 WA"""
        output = """2 2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100000 3
7777 AC
7777 AC
7777 AC"""
        output = """1 0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6 0"""
        output = """0 0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2 5
1 WA
1 AC
2 WA
2 WA
2 WA"""
        output = """1 1"""
        self.assertIO(input, output)

Measured memory_bytes: 82100
#include <stdio.h>
#include <stdlib.h>
long min_l(long n, long m);

int main(void)
{
	long n, m, p1, p2, q1, q2, l;
	int err;
	char *s, *t;
	err=scanf("%ld%ld", &n, &m);
	if (err!=2) exit(1);
	s = (char *)malloc(sizeof(char)*(int)n);
	t = (char *)malloc(sizeof(char)*(int)m);
	err=scanf("%s\n%s", s, t);
	if (err!=2) exit(1);

	l=min_l(n, m);
	p1=l/n;
	q1=l/m;
	p2=0;
	q2=0;
	while((q2<n)&&(p2<m))
	{
		if (s[q2]!=t[p2])
		{
			printf("%d\n", -1);
			return 0;
		}
		p2+=p1;
		q2+=q1;
	}
	printf("%ld\n", l);
	free(s);
	free(t);
	return 0;
}

long min_l(long n, long m){
	long answer, a, b, r = 1;
	if (n >= m)
	{
		a = n;
		b = m;
	}else
	{
		a = m;
		b = n;
	}
	while (r != 0)
	{
		r = a%b;
		a = b;
		b = r;
	}
	answer = n * m / a;
	return answer;
}

Measured memory_bytes: 352
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < N; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  int d[N];
  REP(i, N) cin >> d[i];

  sort(d, d + N, greater<int>());
  int ans = 1;
  REP(i, N - 1) {
    if (d[i] > d[i + 1]) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  rep(i,s.size()-1){
    if(s[i]=='A' && s[i+1]=='C'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
return 0;}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n, x; scanf("%d%d", &n, &x);
  if (x == 1 || x == n*2-1) {
    puts("No");
    return;
  }
  puts("Yes");
  if (n == x) {
    for (int i = 1; i <= 2*n-1; ++i)
      printf("%d\n", i);
  } else if (x > n) {
    for (int i = 1; i < n; ++i)
      printf("%d\n", i);
    printf("%d\n%d\n%d\n", x, n*2-1, n);
    for (int i = n+1; i < n*2-1; ++i)
      if (i != x)
	printf("%d\n", i);
  } else if (x < n) {
    for (int i = 2; i < n; ++i)
      if (i != x)
	printf("%d\n", i);
    printf("%d\n1\n%d\n", n, x);
    for (int i = n+1; i <= n*2-1; ++i)
      printf("%d\n", i);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

int main(){
    int r;
    int d;
    int x;
    cin >> r >> d >> x ;
    int c = 0;

    for(int i=0;i<10;i++){
        c = r*x - d ;
        cout << c << endl;
        x = c;
    }
    
    


    }


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

int main() {

	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);

	rep(i, n) {
		cin >> x[i];
	}

	vector<ll> ans(n - k + 1, 0);
	ll l, r;
	rep(i, n - k + 1) {
		l = x[i];
		r = x[i + k - 1];
		ans[i] = min(abs(l), abs(r)) + abs(r - l);
	}
	sort(ans.begin(), ans.end());

	cout << ans[0];

	return 0;
}


ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

Measured memory_bytes: 8944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int cnt = 0;
	char zeroichi[100007];
	scanf("%s",zeroichi);
	for (int i = 1; i < strlen(zeroichi); ++i)
	{
		if(zeroichi[i - 1] == zeroichi[i]){
			switch(zeroichi[i - 1]){
				case '0':
					zeroichi[i] = '1';
					break;
				case '1':
					zeroichi[i] = '0';
					break;
			}
			++cnt;
		}
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 256
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))
seen=[False]*N
cnt=0
now=0
while(True):
    if(seen[now]):
        print(-1)
        exit()
    elif(now==1):
        print(cnt)
        exit()
    else:
        seen[now]=True
        cnt+=1
        now=a[now]-1

Measured memory_bytes: 7852
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>

using namespace std;

int main(){
	int n;
	cin >> n;
	string s[n],t;
	vector<int> d(n,0);
	
	for(int i=0;i<n;i++){
		cin >> s[i] >> d[i];	
	}
	
	cin >> t;
	
	int slp,sum=0;
	bool flg=false;
	for(slp=0;slp<n;slp++){
		if(flg){
			sum+=d[slp];
		}
		if(t==s[slp]){
			flg=true;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
function main(arg) {
	arg = arg.split("\n").map(Number)
	var data = [
		arg[0],arg[1],arg[2],arg[3],arg[4]
	]
	data.sort((a, b) => {
		var _a = a % 10
		var _b = b % 10
		if (_a == 0) {
			_a = 10
		}
		if (_b == 0) {
			_b = 10
		}
		return Number(_b) - Number(_a)
	})
	var sum  = 0
	for (var i = 0;i < data.length;i++) {
		var ans = Math.ceil(data[i] / 10)
		// console.log(ans)
		if (i === data.length - 1) {
			sum += data[i]
		} else {
			sum += ans * 10
		}
	}

	console.log(sum)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>

using namespace std;
int main()
{
    int x,z,y;
    int temp;
    cin>>x;
    cin>>y;
    cin>>z;
    if(x>=1&&x<=100&&y>=1&&y<=100&&z>=1&&z<=100)
    {
     temp=x;

     x=y;
     y=temp;

     temp=x;
      x=z;
      z=temp;


    }
    cout<<x;
        cout<<" ";
    cout<<y;
        cout<<" ";
    cout<<z;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int m=min(min(a,b),c);
  int M=max(max(a,b),c);
  int n=a+b+c-m-M;
  cout << M-m << endl;
}


 
 
 


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

const ll INF = 1LL << 60;

ll N;
vector<ll> A, B;

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    cin >> N;
    A.resize(N);
    B.resize(N);

    rep(i, N) cin >> A[i] >> B[i];

    map<P, ll> group;

    // grouping
    rep(i, N) {
        ll a, b;
        a = A[i], b = B[i];

        if (a == 0 && b == 0){
            group[P(0, 0)]++;
        } else if (a == 0) {
            group[P(0, 1)]++;
        } else if (b == 0) {
            group[P(1, 0)]++;
        } else {
            ll gcd = __gcd(a, b);
            a /= gcd;
            b /= gcd;
            if (a < 0) {
                a = -a;
                b = -b;
            }
            group[P(a, b)]++;
        }
    }

    // 計算
    mint ans = 1;
    mint zero = 0;
    for (auto v : group) {
        // 0, 0 | 1匹でいることしか出来ない
        if (v.first.first == 0 && v.first.second == 0) {
            zero = v.second;
            continue;
        }

        P p = v.first;
        ll s = v.second;

        ll a = p.first;
        ll b = p.second;

        // cout << a << " " << b << endl;

        ll t;
        // 対となる相方
        if (b < 0) {
            t = group[P(-b, a)];
            group.erase(P(-b, a));
            // cout << t << endl;
        } else {
            t = group[P(b, -a)];
            group.erase(P(b, -a));
        }

        // 2 ^ s - 1 + 2 ^ t - 1 + 1;
        mint now = 1;
        now += mint(2).pow(s) - 1;
        now += mint(2).pow(t) - 1;
        // cout << s << " " << t << " " << now << endl;
        ans *= now;

        group.erase(p);
    }

    cout << ans + zero - 1 << endl;
}

Measured memory_bytes: 18708
(defun abc129b ()
  (let* ((n (read))
	 (sa 10000)
	 (wn (loop repeat n
		collect (read))))
    (loop for i from 1 below n
       do (let* ((wa1 (apply #'+ (subseq wn 0 i)))
		 (wa2 (apply #'+ (subseq wn i)))
		 (sai (abs (- wa1 wa2))))
	    (when (> sa sai)
	      (setf sa sai))))
    (format t "~d~%" sa)))

(abc129b)

Measured memory_bytes: 16228
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a > b)
    printf("a > b\n");
    else if(a < b)
    printf("a < b\n");
    else if(a == b)
    printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;

}

Measured memory_bytes: 256
// abc151_a
#include <iostream>
#include <math.h>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>

#define US unsigned short
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long
#define ULL unsigned long long
using namespace std;

int main(int argc, char const *argv[])
{
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
  	var out = 0;
  	var temp = 0;
  	for (var i = 0; i < input[0]; i++) {
    	temp=1/tmp[i]+temp;
    }
  	out = 1/temp;
	//出力
	console.log('%d',out);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let a: usize = sc.cin();
    let b: usize = sc.cin();

    let mut ans = 0;

    for i in 0..n {
        let t: usize = sc.cin();
        if t < a || b <= t {
            ans += 1;
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


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

int N;

class DAG {
public:
  vector<int> topologicalSorted;
  bool valid;

  DAG(vector<vector<int>> G) {
    int V = G.size();
    vector<int> inDegree(G.size(), 0);
    for(int u = 0; u < V; u++) {
      for(auto v: G[u]) inDegree[v]++;
    }
    stack<int> s;
    for(int u = 0; u < V; u++) if(inDegree[u] == 0) s.push(u);

    while(!s.empty()) {
      int u = s.top();
      s.pop();
      topologicalSorted.push_back(u);
      for(auto &v: G[u]) {
        inDegree[v]--;
        if(inDegree[v] == 0) s.push(v);
      }
    }

    valid = static_cast<int>(topologicalSorted.size()) == V;
  }
};

vector<int> offset;
vector<vector<int>> G;

int index(int x, int y) {
  int l = min(x,y), r = max(x,y);
  return offset[l] + (r - l - 1);
}

vector<int> d;
int dfs(int i) {
  if(d[i] != -1) return d[i];

  d[i] = 1;
  for(int j: G[i]) {
    d[i] = max(d[i], 1 + dfs(j));
  }
  return d[i];
}

int main () {
  cin >> N;

  offset.resize(N, 0);
  for(int i = 1; i < N; i++) {
    offset[i] = offset[i-1] + N - i;
  }

  int M = N*(N-1)/2;
  G.resize(M);

  rep(i,N) {
    int a;
    cin >> a;
    int idx = index(i, a-1);
    rep(j,N-2) {
      cin >> a;
      int nidx = index(i,a-1);
      G[idx].push_back(nidx);
      idx = nidx;
    }
  }

  DAG dag(G);
  if(!dag.valid) {
    cout << "-1" << endl;
    return 0;
  }

  d.resize(M, -1);
  int ans = M;
  for(int i: dag.topologicalSorted) dfs(i);

  cout << *max_element(all(d)) << endl;

  return 0;
}


Measured memory_bytes: 58996
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,h;
	m=0;
	string s,t;
	cin>>n>>s;
	t=s;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			for(int k=i;k<n;k++){
				if(s.at(j)==s.at(k)){
					m++;
					for(int l=i;l<n;l++){
						if(s.at(l)==s.at(j)){
							s.at(l)='!';
						}
					}
					break;
				}
			}
		}
		s=t;
		if(i==0)h=m;
		if(m>h)h=m;
		m=0;
	}
	cout<<h<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

int main(){

	string N;
	cin>>N;
	int K;
	cin>>K;
	vector<vector<vector<long long>>> dp(N.size()+1,vector<vector<long long>> (K+1,vector<long long>(2,0)));
	
	dp[0][0][0] = 1;
	
	for(int i=0;i<N.size();i++){
		for(int j=0;j<=K;j++){
			if(N[i] == '0'){
				dp[i+1][j][1] += dp[i][j][1];
				dp[i+1][j][0] += dp[i][j][0];
			}
			else{
				dp[i+1][j][1] += dp[i][j][0]+dp[i][j][1];
			}
			
			if(j!=K){
				dp[i+1][j+1][1] += dp[i][j][1] * 9;
				int x = N[i]-'0'-1;
				if(x>=0)dp[i+1][j+1][1] += dp[i][j][0] * x;
				if(N[i]>='1'){
					dp[i+1][j+1][0] += dp[i][j][0];
				}
			}
		}
	}
	
	cout<<dp.back().back()[0] + dp.back().back()[1]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  final int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 126252
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
int main(void)
{
    int X;
    cin >> X;
    vector<int> m = {100, 101,  102,  103,  104,  105};
    map<int, int> m0, m1;
    m0[0] = 0;
    REP(i, 1002){
        if(i&1){
            m0.clear();
            for(auto && i : m1){
                for (int j = 0; j < 6; j++) {
                    if(i.fi + m[j] > X) continue;
                    if(i.fi + m[j] == X){
                        pr(1);
                        return 0;
                    }
                    m0[i.fi + m[j]] = 1;
                }
            }
        }else{
            m1.clear();
            for(auto && i : m0){
                for (int j = 0; j < 6; j++) {
                    if(i.fi + m[j] > X) continue;
                    if(i.fi + m[j] == X){
                        pr(1);
                        return 0;
                    }
                    m1[i.fi + m[j]] = 1;
                }
            }
        }
    }
    pr(0);
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define f first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()

const int N = 1000 + 144, mod = 1e9 + 7, inf = 1e9 + 7;
int n, m;
char a[N][N];
int dp[N][N];

ll bp(ll x, ll y){
    if(y == 0)
        return 1;
    if(y & 1)
        return (x * bp(x, y - 1));
    ll z = bp(x, y / 2);
    return (z * z) % mod;
}

int main(){
    boost;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(i == 1 && j == 1 || a[i][j] == '#')
                continue;
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            dp[i][j] %= mod;
        }
    }
    cout << dp[n][m];
    return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <string>

using namespace std;

const int INF = 100000000;

int main(){
	string step;
	int dp[2][2][3][3];
	while(cin >> step){
		if(step == "#") break;
		for(int i=0;i<2;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					dp[0][i][j][k] = dp[1][i][j][k] = (j <= k ? 0 : INF);
		for(int i=0;i<step.size();i++){
			int cur = i%2, next = 1-cur;
			for(int j=0;j<3;j++)
				for(int k=j;k<3;k++)
					dp[next][0][j][k] = dp[next][1][j][k] = INF;
			int line = (step[i]-'1')%3;
			for(int j=0;j<3;j++){
				for(int k=j;k<3;k++){
					if(line <= k)
						dp[next][0][line][k] = min(dp[next][0][line][k], min(dp[cur][1][j][k], dp[cur][0][j][k]+1));
					if(j <= line)
						dp[next][1][j][line] = min(dp[next][1][j][line], min(dp[cur][1][j][k]+1, dp[cur][0][j][k]));
				}
			}
		}
		int ans = INF;
		for(int i=0;i<2;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					ans = min(ans, dp[step.size()%2][i][j][k]);
		cout << ans << endl;
	}
}

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

int main() {
  int N;
  cin >> N;
  int v[N];
  for(int i=0; i<N; i++) cin >> v[i];
  sort(v, v+N);
  double ans = v[0] + v[1];
  for(int i=2; i<N; i++) ans += v[i] * pow(2, i-1);
  cout << ans/pow(2, N-1) << endl;
}


Measured memory_bytes: 256
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 4e5 + 5;
const long long MNN = 1e5 + 1;
const long long MOD = 10;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong a, b;
vector<llong> v;

llong gcd(llong a, llong b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int main(){
    ios;
    cin >> a >> b;
    llong x = gcd(a, b);
    v.pb(1);
    for(int i = 2; i <= sqrt(x); i++){
        while(x % i == 0){
            x /= i;
            if(v[v.size() - 1] != i){
                v.pb(i);
            }
        }
    }
    if(x > 1) v.pb(x);
    cout << v.size();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
using namespace std;
const int nmax = 8;
int N = nmax;
bool graph[nmax][nmax];

int dsf(int v,bool visited[nmax]){
	int i;
	for(i = 0;i < N;++i)if(!visited[i])break;
	if(i == N)return 1;
	int ret=0;
	for (i = 0; i < N; ++i)
	{
		if(visited[i])continue;
		if(!graph[v][i])continue;
		visited[i]=true;
		ret+=dsf(i,visited);
		visited[i]=false;
	}
	return ret;
}

int main(){
	int n,m,a,b;
	
	cin >> N >> m;
	for(int i = 0;i < m;i++){
		cin >> a >> b;
		graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
	}
	bool visited[nmax]={0};
	visited[0] = true;
	cout << dsf(0,visited) << endl;
}

Measured memory_bytes: 256
class SegTree
  attr_accessor(:node, :op, :e, :offset)
  
  def initialize(n, op, e)
    @op = op
    @e = e

    ofs = 1
    while ofs < n
      ofs <<= 1
    end
    
    @node = Array.new((ofs << 1) - 1, @e) # 0-indexed
    @offset = ofs - 1 # log2(n).ceil - 1
  end

  def update(i, x) # 一点更新
    i += @offset
    @node[i] = x
    
    while i > 0
      i = (i - 1) >> 1
      @node[i] = @op.call(@node[(i << 1) + 1], @node[(i << 1) + 2])
    end
  end

  def query(l, r) # [l, r)
    l += @offset
    r += @offset

    res = @e
    while l < r
      if l & 1 == 0
        res = @op.call(res, @node[l])
      end
      if r & 1 == 0
        res = @op.call(res, @node[r - 1])
      end
      l = l >> 1
      r = (r - 1) >> 1
    end
    return res
  end
end

m = 3 * (10 ** 5)
chmax = -> (x, y) { (x > y)? x : y }
n, k = $stdin.readline.chomp.split.map(&:to_i)
seg = SegTree.new(m + 1, chmax, 0)

res = 0
n.times do
  a = $stdin.readline.to_i
  l = (a - k > 0)? (a - k) : 0
  r = (a + k < m)? (a + k) : m
  t = seg.query(l, r + 1) + 1
  res = (res < t)? t : res
  seg.update(a, t)
end
puts res


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


int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  vector<int> j(n+1,0);
  
  rep(i,n-1){
    if(a[i]<=a[i+1]){
      j[i+1]=1;      
    }
  }
  
  ll ans=1000;
  ll k=0;
  rep(i,n){
    if(j[i]==0&&j[i+1]==1){
      k+=ans/a[i];
      ans=ans-(ans/a[i])*a[i];
    }else if(j[i]==1&&j[i+1]==0){
      ans+=a[i]*k;
      k=0;
    }
  } 
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void)
{
  int i,n,p;
  char S[101];
  scanf("%s",S);
  i=0;
  while(S[i]!=NULL){
    i++;
  }
  n=i;
  p=0;
  for(i=0;i<=(n-2)/2;i++){
    if(S[i]!=S[n-i-1]){
      p++;
    }
  }
  
  printf("%d",p);
  
  return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		static double mc = 100;
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int A = in.nextInt(), B = in.nextInt(), C = in.nextInt(), D = in.nextInt();
			int E = in.nextInt(), F = in.nextInt();

			double ans = 0;
			double answa = -1;
			double anssu = -1;
			for (double i = 0; i <= mc; i++) {
				for (double j = 0; j <= mc; j++) {
					for (double k = 0; k <= mc; k++) {
						for (double l = 0; l <= mc; l++) {
							if (i == 0 && j == 0 && k == 0 && l == 0) {
								continue;
							}
							if ((A*i+B*j)*E >= (C*k+D*l) && 100*(A*i+B*j)+(C*k+D*l) <= F) {
								if (ans <= (C*k+D*l)/(100*(A*i+B*j)+(C*k+D*l))) {
									ans = (C*k+D*l)/(100*(A*i+B*j)+(C*k+D*l));
									answa = 100*(A*i+B*j)+C*k+D*l;
									anssu = C*k+D*l;
								}
							}
						}
					}
				}
			}
			out.println((int)answa +" "+(int)anssu);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

int main(){

    double a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f){
        double x = (e*c - b*f) / (e*a - d*b);
        double y = (a*f - d*c) / (e*a - d*b);
        if(x==0)x=0;
        if(y==0)y=0;
        cout << fixed << setprecision(3) << x << " " << y << endl;
    }

    return 0;
}

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

using namespace std;

const int MOD = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<string> S(2);
  for (int i = 0; i < 2; i++)
    cin >> S[i];

  int res = 1, pos = 0;
  bool prev;
  if (S[0][0] == S[1][0]) {
    res = 3LL * res;
    pos++;
    prev = true;
  } else {
    res = 6LL * res;
    pos += 2;
    prev = false;
  }

  while (pos < N) {
    if (S[0][pos] == S[1][pos]) {
      if (prev) res = 2LL * res % MOD;
      prev = true;
      pos++;
    } else {
      if (prev)
        res = 2LL * res % MOD;
      else
        res = 3LL * res % MOD;
      prev = false;
      pos += 2;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=4100;
int n,tr[N],tb[N],tg[N];
char s[5000];
bool r,b,g;
long long ans;
signed main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for (int i=n;i>=1;i--)
	{
		tr[i]=tr[i+1];
		tb[i]=tb[i+1];
		tg[i]=tg[i+1];
		if (s[i]=='R') tr[i]++;
		if (s[i]=='B') tb[i]++;
		if (s[i]=='G') tg[i]++;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			if (s[i]==s[j]) continue;
			r=b=g=0;
			if (s[i]=='R') r=1;
			if (s[i]=='B') b=1;
			if (s[i]=='G') g=1;
			if (s[j]=='R') r=1;
			if (s[j]=='B') b=1;
			if (s[j]=='G') g=1;
			if (r==0)
			{
				ans+=(long long)tr[j+1];
				if (2*j-i<=n && s[2*j-i]=='R') ans--;
			}
			if (b==0)
			{
				ans+=(long long)tb[j+1];
				if (2*j-i<=n && s[2*j-i]=='B') ans--;
			}
			if (g==0)
			{
				ans+=(long long)tg[j+1];
				if (2*j-i<=n && s[2*j-i]=='G') ans--;
			}
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3884
#include <stdio.h>

int main(void){
	char str[100000];
	char* str1=(char*)str;
	char mem=0;
	int ans=0;
	scanf("%s",str);
	do{
		if(mem!=*str1)ans++;
		mem=*str1;
		
		
	}while(*(++str1));
	printf("%d\n",ans-1);
	return 0;
}

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


cnt2 = 0
cnt4 = 0

for i in range(n):
    if A[i] % 4 == 0:
        cnt4 += 1
    elif A[i] % 2 == 0:
        cnt2 += 1

        
if cnt4*2 + cnt2 >= n or (cnt4 * 2 + 1) >= n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
typedef long long int64;
static const int MAXN = 52;
static const int MAXM = 202;
static const int MAXK = 102;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS

template <typename T> inline T gcd(const T a, const T b) { return b == 0 ? a : gcd<T>(b, a % b); }

int64 fact[MAXM + MAXK], fact_inv[MAXM + MAXK];
inline int64 fpow(int64 base, int exp)
{
    int64 ans = 1;
    for (; exp; exp >>= 1, (base *= base)__) if (exp & 1) (ans *= base)__;
    return ans;
}
inline void preprocess()
{
    fact[0] = 1;
    for (int i = 1; i < MAXM + MAXK; ++i) fact[i] = fact[i - 1] * i _;
    fact_inv[MAXM + MAXK - 1] = fpow(fact[MAXM + MAXK - 1], MODULUS - 2);
    for (int i = MAXM + MAXK - 2; i >= 0; --i) fact_inv[i] = fact_inv[i + 1] * (i + 1)_;
}
inline int64 binom(int n, int m)
{
    if (n < m) return 0; else return fact[n] * fact_inv[n - m]_ * fact_inv[m]_;
}

int n, m, k;
int head[MAXN], dest[MAXM], next[MAXM];

inline void add_edge(int u, int v)
{
    static int w = 0;
    dest[w] = v; next[w] = head[u]; head[u] = w++;
}

int dfn[MAXN], low[MAXN];
int stk[MAXM], top = 0;
std::vector<int> bcc[MAXN];
int bcc_ct = 0;

void dfs_bcc(int u, int p = -1)
{
    static int epoch = 0;
    dfn[u] = low[u] = epoch++;
    for (int w = head[u]; w != -1; w = next[w]) if (dest[w] != p) {
        if (dfn[dest[w]] == -1) {
            stk[top++] = w;
            dfs_bcc(dest[w], u);
            if (low[dest[w]] >= dfn[u]) {
                do bcc[bcc_ct].push_back(stk[--top]); while (stk[top] != w);
                ++bcc_ct;
            }
            low[u] = std::min(low[u], low[dest[w]]);
        } else if (dfn[dest[w]] < dfn[u]) {
            stk[top++] = w;
            low[u] = std::min(low[u], dfn[dest[w]]);
        }
    }
}

inline bool check_cycle(const std::vector<int> &block)
{
    std::set<int> s;
    for (int w : block) { s.insert(dest[w]); s.insert(dest[w ^ 1]); }
    return s.size() == block.size();
}

int main()
{
    preprocess();

    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < n; ++i) head[i] = -1;
    int u, v;
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &u, &v); --u, --v;
        add_edge(u, v);
        add_edge(v, u);
    }

    for (int i = 0; i < n; ++i) dfn[i] = -1;
    for (int i = 0; i < n; ++i) if (dfn[i] == -1) dfs_bcc(i, -1);

    int64 ans = 1;
    for (int i = 0; i < bcc_ct; ++i) {
        //for (int w : bcc[i]) printf(" %d-%d", dest[w], dest[w ^ 1]); putchar('\n');
        if (bcc[i].size() == 1u) {
            (ans *= k)__;
        } else if (check_cycle(bcc[i])) {
            int sz = bcc[i].size();
            int64 cur = 0;
            for (int i = 0; i < sz; ++i) cur += fpow(k, gcd(i, sz));
            ans = ans * cur _ * fpow(sz, MODULUS - 2)_;
        } else {
            int sz = bcc[i].size();
            (ans *= binom(sz + k - 1, k - 1))__;
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    if (a == b) {
        cout << 0 << endl;
        ret();
    }


    ll sum = accumulate(a.begin(), a.end(), 0ll);

    ll ans = INF;
    rep(i, n) {

        if (a[i] > b[i]) {
            cmin(ans, b[i]);
        }

    }
    cout << sum - ans << endl;

}


Measured memory_bytes: 3628
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buffer = Console.ReadLine().Split();
            var N = int.Parse(buffer[0]);

            long ans = 0;
            long before = -1;
            foreach (var v in Console.ReadLine().Split())
            {
                if (before == -1)
                {
                    before = long.Parse(v);
                    continue;
                }

                var tmp = long.Parse(v);
                long add = 0;
                if (before > tmp)
                    ans += add = before - tmp;

                before = tmp + add;
            }

            Console.WriteLine(ans);
        }
    }
}


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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, m; cin >> n >> m;
    vi x(m); rep(i,m) cin >> x[i];
    sort(all(x));

    if(n >= m) cout << 0 << '\n';
    else {
        vi d(m-1); rep(i,m-1) d[i] = x[i+1] - x[i];
        sort(all(d));

        int cnt = 0;
        rep(i,m-n) cnt += d[i];
        cout << cnt << '\n';
    }
}


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

int main() {
  int N,sa=0;
  cin >> N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(i%2==0){
      sa+=a.at(i);
    }else{
      sa-=a.at(i);
    }
  }
  cout << sa << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    using namespace std;
    std::string S;
    cin >> S;
    int l = S.size();
    int mid = (l-1)/2;
    bool yes = true;
    for (int i=0;i<mid;i++){
        if ((S.at(i) == S.at(l-1-i)) && (S.at(i) == S.at(mid-i-1))) continue;
        else {
            yes = false;
            break;
        }
    }
    if (yes) cout << "Yes";
    else cout << "No";
}

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

using namespace std;

int func(int x){
    while(x!=0){
        if(x%10==3){
            return 1;
        }else{
            x/=10;
        }
    }
    return 0;
}

int main()
{
    int n;
    cin >> n;
    for(int i =1;i<=n;i++){
        if(i%3 ==0 ) {printf(" %d",i);}
        else if(func(i)){
            printf(" %d",i);
        }
    }
    printf("\n");
 

    return 0;
}




Measured memory_bytes: 3228
#include <iostream>

#define REP(loop, n) for(int i = (loop) ; i < n ; ++i)

using namespace std;

int main(void)
{
	long A, B, V, W, T;
	cin >> A >> V;
	cin >> B >> W;
	cin >> T;

	// 距離
	long dst = abs(A - B);

	// 速度差
	long diff = V - W;

	if (V > W && dst <= T * diff)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	rewind(stdin);
	getchar();
	return 0;
}


Measured memory_bytes: 3592
K=input()
N=50
a=range(N)
a=map(lambda x:x+(K/N),a)
m=K%N

for i in range(m):
	a[i]+=N
	for j in range(N):
		if i!=j:
			a[j]-=1
print N

for i in a:
	print i,

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

int A[100000], P[100000];

int main() {
  int N, K, Q;
  int i, d;
  scanf ("%d %d %d", &N, &K, &Q);
  
  for (i=0;i<N;i++) P[i]=K-Q;
  
  for (i=0;i<Q;i++) {
      scanf("%d", &d);
      P[--d]++;
  }
  
  for (i=0;i<N;i++) {
    printf("%s", P[i]>0 ? "Yes\n" : "No\n");
  }
  return 0;
}




Measured memory_bytes: 896
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


void solve() {
	int N; cin >> N;
	vector<int>ans;
	if (N == 0) {
		print(0); return;
	}
	int c = 0;
	int now = 1;
	int cum = 2;
	while (N != 0) {
		//print(N);
		if (abs(N) % cum != 0) {
			ans.push_back(1);
			N -= now;
		}
		else ans.push_back(0);
		now *= -2;
		cum *= 2;
	}
	VREVERSE(ans);
	REP(i, ans.size())cout << ans[i];
	cout << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


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

int main(void){

  double x1, y1, x2, y2;
  double result;

  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  result = sqrt ((x1 - x2)*(x1 - x2) +  (y1 - y2)*(y1 - y2));
  printf ("%lf\n", result);

  return 0;

}

Measured memory_bytes: 652