akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    ll s = 0, t = 0;
    for (auto &&i : v) scanf("%d", &i), s += i;
    ll ans = s;
    for (int i = 0; i < n; ++i) {
        s -= v[i]; t += v[i];
        ans = min(ans, abs(s-t));
    }
    cout << ans << "\n";
    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<ll,ll>;

const ll MAX = 1e18;

int main(void){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  rep(i,n){
    if(MAX / ans < a[i]){
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int sum=0;
  int n;
  int a[200005];
  cin >> n;
  
  rep(i, n){
    cin >> a[i];
    sum = sum^a[i];
  }

  rep(i, n){
    int ans = sum^a[i];
    cout << ans << " ";
  }
  return 0;
}


Measured memory_bytes: 4400
use std::io::*;
use std::str::FromStr;

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

use std::cmp::min;

fn main() {
    let mut n: usize = read();
    let mut dp: Vec<i64> = vec![0; 100_001];

    dp[1] = 1;
    for i in 2..dp.len() {
        dp[i] = 1 + dp[i - 1];
    }

    let mut sixn = 6;
    while sixn < dp.len() {
        for i in 2..dp.len() {
            if i < sixn {
                continue;
            }

            dp[i] = min(dp[i], dp[i - sixn] + 1);
        }
        sixn *= 6;
    }
    let mut ninen = 9;
    while ninen < dp.len() {
        for i in 2..dp.len() {
            if i < ninen {
                continue;
            }

            dp[i] = min(dp[i], dp[i - ninen] + 1);
        }
        ninen *= 9;
    }
    // println!("{:?}", dp);
    println!("{}", dp[n]);
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define forr(i, b, e)     for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
#define tam 220000
typedef pair<ii,int> iii;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    int valor;
    priority_queue<int > cola;
    forr(i,0,n)
    {
        cin>>valor;
        cola.push(valor);
    }    
    while(!cola.empty()&& m--)
    {
        valor=cola.top();cola.pop();
        cola.push(valor/2);
    }
    ll tot=0;
    while(!cola.empty())
    {
        tot+=cola.top();cola.pop();
    }
    cout<<tot<<endl;
}
// PLUS ULTRA!


Measured memory_bytes: 892
#include <iostream>
#include <map>
#include <ctime>
using namespace std;


void solve()
{
    int N; cin >> N;
    map<int,int> M;
    for (int i = 0; i < N; ++i){
        int a; cin >> a;
        M[a]++;
    }
    
    long long ans = 0;
    for (auto m: M){
        if (m.first > m.second) ans += m.second;
        else ans += abs(m.first - m.second);
    }

    cout << ans << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    // input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 8000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;



int main() {
    int n; cin >> n;
    vector<int> a,b,c;
    for(int i = 0;i < n;i++){
        int x; cin >> x; a.push_back(x);
    }
    for(int i = 0;i < n;i++){
        int x; cin >> x; b.push_back(x);
    }
    for(int i = 0;i < n-1;i++){
        int x; cin >> x; c.push_back(x);
    }
    
    int ans = 0;
    for(int i = 0;i < a.size();i++){
        ans += b[a[i]-1];
        if(i >= 1 && a[i] == a[i-1]+1) ans+=c[a[i-1]-1];
    }
    
    cout << ans;
}


Measured memory_bytes: 3608
n = int(input())
s = list(input())
ans = []
for i in range(len(s)):
  if (ord(s[i])+n)<=ord('Z'):
    ans.append(chr(ord(s[i])+n))
  else:
    ans.append(chr(ord(s[i])+n-26))
print(''.join(ans))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int r ;
  cin >> r;
  cout << 3*r*r << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline bool check(string s)
{
	if(s.size()%2!=0)
		return false;
	string s1=s.substr(0,s.size()/2),s2=s.substr(s.size()/2,s.size()/2);
	if(s1==s2)
		return true;
	else
		return false;
}
int main()
{
	string s;
	cin>>s;
	for(int i=s.size()-1;i>=1;i--)
	{
		string res=s.substr(0,i);
		if(check(res))
		{
			cout<<res.size()<<endl;
			return 0;
		}
	}
}

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

int main(void){
	string S;
	cin >> S;
	int ans=0;
	int l=0;
	rep(i,S.size()){
		if (S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T') l++;
		else {
			ans = max(ans,l);
			l = 0;
		}
	}
	ans = max(ans,l);
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3556
nums = list(map(int, input().split()))
x = (nums[2] - nums[0])
y = (nums[3] - nums[1])
# kyori = sqrt((x*x) + (y*y))
n1 = nums[2] - y
n2 = nums[3] + x
print(n1, end="")
print(" ", end="")
print(n2, end="")
print(" ", end="")
print(n1 - x, end="")
print(" ", end="")
print(n2 - y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using namespace std;
signed main (){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b;
}

Measured memory_bytes: 3596
public class Main {

    public static void main(String[] args) {
	// write your code here
        for(int i = 1; i <= 9; i++){
            for(int n = 1; n <= 9; n++){
                System.out.println(i + "x" + n + "=" + i*n);
            }
        }
    }
}

Measured memory_bytes: 24060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;


void solve() {
	int n, k; string s; cin >> n >> k >> s;
	ll d = k / 2;
	int mi = 100;
	rep(i, n) {
		mi = min(mi, s[i] - 'a');
	}
	string ansg = s;
	int mlen = 0;
	if (k > 28) {
		rep(i, n) {
			cout << char('a' + mi);
		}
		cout << endl; return;
	}
	rep(i, n) {
		int le = i;
		while (i + 1 < n&&s[i] == s[i + 1])i++;
		if (s[i] - 'a' != mi)continue;
		int len = i - le + 1;
		if (i == n - 1) {
			ll tim = (1 << k);
			if (tim*len >= n) {
				rep(j, n) {
					cout << char('a' + mi);
				}
				cout << endl;
				return;
			}
			string nex;
			rep(j, tim*len) {
				nex.push_back('a' + mi);
			}
			//cout << "?" << nex.size() << endl;
			int cur = le-1;
			while (nex.size() < n) {
				nex.push_back(s[cur]); cur--;
			}
			ansg = min(ansg, nex);

		}
		else {
			ll tim = (1 << k-1);
			if (tim*len > n) {
				rep(j, n) {
					cout << char('a' + mi);
				}
				cout << endl;
				return;
			}
			string c;
			rep(j, tim*len) {
				c.push_back('a' + mi);
			}
			int cur = i + 1;
			while (c.size() < n) {
				int id = cur;
				if (cur >= n)id = 2 * n - 1 - cur;
				c.push_back(s[id]);
				cur++;
			}
			ansg = min(ansg, c);
		}
	}
	cout << ansg << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val len1 = StdIn.readInt
    val arrayA = StdIn.readLine().split(" ").map(_.toInt)
    val len2 = StdIn.readInt
    val arrayB = StdIn.readLine().split(" ").map(_.toInt)

    var count = 0
    for (value <- arrayB) {
      count += searchA(value, arrayA)
    }
    println(count)
  }

  def searchA(value: Int, array: Array[Int]): Int = {
    for (valueA <- array) {
      if (value == valueA) return 1
    }
    return 0
  }
}

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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


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

int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
}


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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int N;
long a;

int main()
{
	cin >> N;
	long res = 0;
	rep(i, N) {
		cin >> a;
		for (;a != 0 && (a & 1) == 0;a /= 2) res++;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

unsigned long long a[20];


unsigned long long len(long long k){
	unsigned long long ans=0;
	int dig=0;
	unsigned long long tmp=1;
	for(int i=1;i<20;i++){
		if(k>=tmp)dig=i;
		tmp *= 10;
	}
	ans += a[dig-1];
	tmp = 1;
	for(int i=1;i<dig;i++){
		tmp *= 10;
	}
	unsigned long long fizz = k/3 - (tmp-1)/3;
	unsigned long long buzz = k/5 - (tmp-1)/5;
	unsigned long long fizzbuzz = k/15 - (tmp-1)/15;
	ans += dig * (k-tmp+1) + (4-dig)*(fizz-fizzbuzz) + (4-dig)* (buzz-fizzbuzz) + (8-dig)*fizzbuzz;
	return ans;
}

long long binary_search(long long n){
	long long ok = 0;
	long long ng = n;
	while(abs(ok-ng)>1){
		long long mid = (ok+ng)/2;
		if(len(mid)<n){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	return ok;
}



int main(){
	unsigned long long tmp = 10;
	unsigned long long fizz,buzz,fizzbuzz;
	a[0] = 0;
	for(int i=1;i<19;i++){
		fizz = (tmp-1)/3 - (tmp/10-1)/3;
		buzz = (tmp-1)/5 - (tmp/10-1)/5;
		fizzbuzz = (tmp-1)/15 - (tmp/10-1)/15;
		a[i] = a[i-1] + i*(tmp-1-tmp/10+1) + (4-i)*(fizz-fizzbuzz) + (4-i)* (buzz-fizzbuzz) + (8-i)*fizzbuzz;
		tmp *=10;
	}
	long long s;
	cin >> s;
	long long p = binary_search(s);
	long long k = len(p);
	string S;
	for(long long i=p+1;i<p+20;i++){
		bool flag = 1;
		if(i%3==0){
			S+= "Fizz";
			flag = 0;
		}
		if(i%5==0){
			S += "Buzz";
			flag = 0;
		}
		if(flag){
			S += to_string(i);
		}
	}
	for(long long i=0;i<100;i++){
		if(k+i+1>=s&&k+i+1<s+20){
			cout << S[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#define ll long long;

using namespace std;


int main() {
	int a, b, c;
	double s, l, h;
	cin >> a >> b >> c;
	s = 0.5*a*b*sin(c*3.141592652589/180);
	l = a + b + sqrt(a*a+b*b-2*a*b*cos(c*3.141592652589/180));
	h = 2*s / a;
	printf("%.8f\n%.8f\n%.8f\n", s, l, h);
}

Measured memory_bytes: 3404
# 尺取法ver

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum, bsum = [0], [0]
for i in range(n):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
b_count = len(bsum)-1
for a_count in range(len(asum)):
  while asum[a_count] + bsum[b_count] > k:
    b_count -= 1
  ans = max(ans, a_count + b_count)
print(ans)


Measured memory_bytes: 40476
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
int solve(int A, int K){
  int d, n, r;
  if(A%K==0){
    return A/K;
  }
  r = A % K;
  d =divup_L(A,K);
  n =divup_L(r,d);
  return solve(A - n*d, K);
}
int main(){
  int A, K, Lj4PdHRW, N, res=0;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(A);
    rd(K);
    res ^= solve(A,K);
  }
  if(res){
    wt_L("Takahashi");
    putchar_unlocked('\n');
  }
  else{
    wt_L("Aoki");
    putchar_unlocked('\n');
  }
  return 0;
}
// cLay varsion 20180208-1

// --- original code ---
// int solve(int A, int K){
//   int r, d, n;
//   if(A%K==0) return A/K;
// 
//   r = A % K;
//   d = A /+ K;
//   n = r /+ d;
//   return solve(A - n*d, K);
// }
// 
// {
//   int N, A, K;
//   int res = 0;
//   
//   rd(N);
//   rep(N){
//     rd(A,K);
//     res ^= solve(A,K);
//   }
//   if(res) wt("Takahashi"); else wt("Aoki");
// }


Measured memory_bytes: 256
N, M = map(int, input().split())

ans = ['' for _ in range(N)]

for _ in range(M):
    s, c = map(str, input().split())
    if (ans[int(s)-1] != '') and (ans[int(s)-1] != c):
        print("-1")
        break
    else:
        ans[int(s)-1] = c
else:
    if (N > 1) and (ans[0] == ''):
        ans[0] = '1'
    ans = ['0' if s == '' else s for s in ans]

    if (N > 1) and (ans[0] == '0'):
        print("-1")
    else:
        print(''.join(ans))


Measured memory_bytes: 3064
N, W = [int(n) for n in input().split()]

values = [[] for n in range(4)]
w, v = [int(n) for n in input().split()]
w_0 = w
values[0].append(v)

sum_values = [[0] for n in range(4)]


for i in range(1, N):
  w, v = [int(n) for n in input().split()]
  values[w-w_0].append(v)

for i in range(4):
  values[i].sort(reverse=True)
  s = 0
  for j in range(len(values[i])):
    s += values[i][j]
    sum_values[i].append(s)

res = 0
for i in range(len(values[0])+1):
  for j in range(len(values[1])+1):
    for k in range(len(values[2])+1):
      for l in range(len(values[3])+1):
        if (i*w_0 + j*(w_0+1) + k*(w_0+2) + l*(w_0+3))<=W:
          res = max(res, sum_values[0][i]+sum_values[1][j]+sum_values[2][k]+sum_values[3][l])


print(res)

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
x = int(input())

l1 = [500*i for i in range(0, a+1)]
l2 = [100*i for i in range(0, b+1)]
l3 = [50*i for i in range(0, c+1)]

count = 0
for i in l1:
   for j in l2:
      y = x - i - j
      if (y in l3):
         count += 1
print(count)


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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(){
	int n;
	cin>>n;
	string str;
	while(n--){
		int out = 3;
		int score = 0;
		int f,s,t;
		f=s=t=0;
		while(out){
			cin>>str;
			stringstream ss;
			ss <<str;
			string tmp;
			ss >>tmp;
			if(tmp=="HIT"){
				if(t){
					score++;
					t = 0;
				}
				if(s){
					s = 0;
					t = 1;
				}
				if(f){
					s = 1;
					f = 1;
				}else{
					f=1;
				}
			}else if(tmp=="HOMERUN"){
				//cout <<"tmp = "<<tmp<<endl;
				score+=(t+s+f+1);
				//cout <<score<<endl;
				t=s=f=0;
			}else{
				out--;
			}
		}
		cout <<score<<endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>

int main(){
    int N;
    std::cin>>N;
    int tmp=0,max=0,A;
    for(int i=0;i<N;i++){
        std::cin>>A;
        if(A==1) tmp++;
        else tmp=0;
        if(tmp>max) max=tmp;
    }

    std::cout<<max+1<<"\n";

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
//just see queue data structure, solve it like 600 rating problem.
ll power(ll a, ll b){
    ll res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int main(){
    SPEED;
    ll n, m;
    cin>>n>>m;
    if(n==m){
        cout<<"Yes";
    }
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
//file_name:ABC60_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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

    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])yn;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
string s[1010];

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		REP(i,n)
			cin>>s[i];
		for(int i=n-1;i>=1;i--){
			for(int j=1;j<s[i].size();j++){
				if(s[i][j]!='.'&&s[i][j]!='|'){
					s[i][j-1]='+';
					for(int k=i-1;k>=1;k--){
						if(s[k][j-1]!='.')break;
						s[k][j-1]='|';
					}
					for(int k=0;k<s[i].size();k++){
						if(s[i][k]=='.')s[i][k]=' ';
					}
					break;
				}
			}
		}
		REP(i,n)cout<<s[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3884
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const long long mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for(int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k; 
ll INF = 10000000000000000;



int main(){
    int N;
    string S;
    cin >>N>>S;
    vi abc(26,0);
    rep(i,N){
        abc[S[i]-'a']++;
    }
    ll ans=1;
    rep(i,26){
        ans *= abc[i]+1;
        ans %= mod;
    }
    cout <<ans-1<<endl;
}

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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  string s;
  cin >> s;
  if (s[s.size() - 1] == 's') {
    cout << s << "es" << endl;
  } else {
    cout << s << "s" << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll x, y;
    cin >> x >> y;
    y /= 2;
    cout << x + y << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

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

  if(a * b % 2 == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;

  return 0;
}


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

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      if(i!=1) ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  auto nres = divisor(n);
  auto n_res = divisor(n-1);
  ll ans = 0;
  for(auto i : nres){
    ll tn = n;
    while(tn%i==0) tn/=i;
    if((tn-1)%i==0) ans++;
  }
  ans += n_res.size();
  cout << ans << endl;

  return 0;
    

}


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

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

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int i = s.size();
	while (i >= 1) {
		i--;
		if (i >= 6) {
			string t = s.substr(i - 6, 7);
	
			if (t == "dreamer") {
				i -= 6;
				continue;
			}
		}
		 if (i >= 5) {
			string t = s.substr(i - 5, 6);
		
			if (t == "eraser") {
				i -= 5;
				continue;
			}
		}
		if (i >= 4) {
			string t = s.substr(i - 4, 5);
		
			if (t == "erase") {
				i -= 4;
				continue;
			}
			else if (t == "dream") {
				i -= 4;
				continue;
			}

		}
		
			cout << "NO" << endl;
			goto hoge;

	}
	cout << "YES" << endl;
	hoge:
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N - 1000 * a) / 100;
  c = (N - 1000 * a - 100 * b) / 10;
  d = N % 10;
  if ((a == b && b == c) || (b == c && c==d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {

    int i, a, b, c, d;

    d = 0;

    scanf("%d", &a); scanf("%d", &b); 
    scanf("%d", &c);

    for (i = a; i <= b; i++) {

        if (c % i == 0) {
            d += 1;
        }

    }

    printf("%d\n", d);

    return 0;

}



Measured memory_bytes: 2140
n =int(input())
A = list(map(int, input().split()))

ans = [0]*n
for i in reversed(range(n)):
    j = i+1
    b = 0
    while j <= n:
        b += ans[j-1]
        j += (i+1)
    if b%2 == A[i]:
        ans[i] = 0
    else:
        ans[i] = 1
print(sum(ans))
B = []
for i in range(len(ans)):
    if ans[i] != 0:
        B.append(i+1)
print(*B)

Measured memory_bytes: 92980
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		if (n == 0) {
			System.out.println(0);
			return;
		}

		List<Integer> list = new ArrayList<>();
		while (n != 1) {
			if (n < 0) {
				list.add(-n % 2);
				n = (-n + 1) / 2;
			} else {
				list.add(n % 2);
				n = -(n / 2);
			}
		}
		System.out.print(1);
		Collections.reverse(list);
		for (int i : list) {
			System.out.print(i);
		}
		System.out.println();
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	string s,t;
	cin >> s >> t;

	sort(all(s));
	sort(all(t), greater<char>());

	bool f = s < t;
	cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
 
int run_test(){
      string s, t;
      cin >> s >> t;
      int ans = 10000;
      for(int i=0; i<=s.length() - t.length(); i++){
            int j = 0, k = i;
            int count = 0;
            while(j < t.length()){
                  if(s[k] == t[j]){
                        k++; j++; continue;
                  }
                  count++; k++; j++;
            }
            ans = min(ans, count);
      }
      cout << ans << "\n";
      return 0;
}
 
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}


Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C;
    int rem;
    
    cin >> A >> B >> C;
    if (A >= B+C)
    { 
      cout << 0 << endl;
    }   
	else 
	{
		cout << B+C-A << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

typedef long long ll;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	static int U[200000],V[200000],deg[100000];
	rep(i,m){
		scanf("%d%d",U+i,V+i), U[i]--, V[i]--;
		int u=U[i],v=V[i];
		deg[u]++;
		deg[v]++;
	}

	static bool del[100000]; // 選ばない頂点
	static int sz[100000]; // sz[u] := ( 頂点 u と平等な ( u の代わりに選んでもいい ) 頂点の個数 )
	rep(u,n) sz[u]=1;
	rep(i,m){
		int u=U[i],v=V[i];
		if(deg[u]<deg[v] || deg[u]==deg[v] && u<v) del[v]=true;
		else                                       del[u]=true;

		if(deg[u]==deg[v]) sz[u]++, sz[v]++;
	}

	int ans1=0;
	ll ans2=1;
	rep(u,n) if(!del[u]) {
		ans1++;
		ans2=ans2*sz[u]%1000000009;
	}
	printf("%d\n%lld\n",ans1,ans2);

	return 0;
}

Measured memory_bytes: 3464
//https://atcoder.jp/contests/dp/tasks/dp_a
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

const int N=1e5+7;
ll dp[N];
ll arr[N];

int main(){
  nimble;
  int tt=1;//cin>>tt;
  while(tt--){
    int n;
    cin>>n;
    rep(i,0,n)
      cin>>arr[i];
    dp[0]=0;dp[1]=abs(arr[1]-arr[0]);
    rep(i,2,n)
      dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    cout<<dp[n-1]<<nl;
  }
  return 0;
}


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


def bingo(M):
    for i in range(3):
        if M[i][0] and M[i][1] and M[i][2]:
            return True
    
        if M[0][i] and M[1][i] and M[2][i]:
            return True

    if (M[0][0] and M[1][1] and M[2][2] or
        M[0][2] and M[1][1] and M[2][0]):
        return True

    return False


P = {}

for i in range(3):
    for j, a in enumerate(map(int, input().split())):
        P[a] = (i,j)


N = int(input())
M = [[False]*3 for _ in range(3)]

for _ in range(N):
    b = int(input())
    if b in P:
        p = P[b]
        M[p[0]][p[1]] = True

print('Yes' if bingo(M) else 'No')



        
    


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


int main() {
    int n , m ; cin >> n >> m;
    int nmmax = 55;
    int a[nmmax] , b[nmmax];

    for (int i = 0;i < m; i++) {
        cin >> a[i] >> b[i];
    }

    int road[nmmax];
    for (int i = 0;i < n; i++) {
        road[i] = 0;
    }

    for (int i = 0;i < m; i++) {
        road[a[i] - 1] += 1;
        road[b[i] - 1] += 1;
    }
    for (int i = 0;i < n; i++) {
        cout << road[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int a[8], b[8], c[8], K;
    cin >> a[0] >> b[0] >> c[0] >> K;
    for (int i = 1; i < 8; i++) {
        a[i] = a[i - 1] * 2;
        b[i] = b[i - 1] * 2;
        c[i] = c[i - 1] * 2;
    }
    bool ans = false;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; i + j <= K; j++) {
            for (int k = 0; i + j + k <= K; k++) {
                if (b[j] > a[i] && c[k] > b[j]) {
                    ans = true;
                }
            }
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>	
#include <utility>
#include <cinttypes>
using namespace std;
int main(){
    int r,g,b,n;
    scanf("%d %d %d %d",&r,&g,&b,&n);
    int counter = 0;
    for (int i=0;i<=n/r;i++){
        for (int j=0;j<=(n-r*i)/g;j++){
            if ((n-r*i-g*j)%b == 0){
                counter ++;
            }
        }
    }
    printf("%d\n",counter);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>


char X[101], Y[101];

int main(){
  int n, i;
  scanf("%d", &n);
  scanf("%s", X);
  scanf("%s", Y);
  for (i=0; i<n; i++){
    printf("%c%c", X[i], Y[i]);
  }
  printf("\n");
}


Measured memory_bytes: 128
while nums = gets
  a, b, c, d, e, f = nums.chomp.split.map(&:to_f)
  x = ((a*e - b*d).zero? || (c*e - b*f).zero?) ? 0 : (c*e - b*f) / (a*e - b*d)
  y = ((-a*x + c).zero? || b.zero?) ? 0 : (-a*x + c) / b
  puts "#{'%.3f' % x} #{'%.3f' % y}"
end

Measured memory_bytes: 6148
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>
#include <tuple>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b){
	if(a<b){
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b){
	if(a>b){
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) {return std::vector<T>(len, elem);}
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i] <<std:: endl;
		else std::cout << da[i] << ' ';
	}
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;


int main(){
	ll n;
	cin >> n;
	ll ans = 0, co = 1;
	while(n){
		ans += co;
		n /= 2;
		co *= 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val (x,n) = f.readLine().split(" ").map{it.toInt()}
	if(n == 0){
		println(x)
		return
	}
	val array = f.readLine().split(" ").map{it.toInt()}.toIntArray().toHashSet()


	var ans = -2
	var min = 105

	for(k in -1..101){
		if(!array.contains(k)){
			if(abs(k-x) < min){
				ans = k
				min = abs(k-x)
			}
		}
	}

	println(ans)
}


Measured memory_bytes: 40268
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main(){
	int ary[100];
	int hikaku[100];
	int n;
	int a = 0;
	
	for(int i = 1; i <= 100; i++){
		ary[i] = i;
		hikaku[i] = 0;
	}

	while(scanf("%d",&n) != EOF){

		for(int i = 1; i <= 100; i++){

			if(ary[i] == n){
				hikaku[i]++;
				a = max(a,hikaku[i]);
			}
		}

	}

	for(int i = 1; i <= 100; i++){
		
		if(a == hikaku[i]){
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) (x)*(x)
#define matrix vector < vector<int> >

using namespace std;

const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9+7;
const int N = int (2e5+7);
    
int n, av, a[500];
ll dp[5000][500], ans;

int main () { 
   	//freopen("input.txt", "r", stdin);
   	//freopen("output.txt", "w", stdout);  
   	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> av;
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	dp[0][0] = 1;
	for(int i = 0; i < n; i ++) {
		for(int j = 50 * n; j >= 0; j --) {
			for(int k = i; k >= 0; k --) {
				dp[j + a[i]][k + 1] += dp[j][k];
				//if(k == 1 && dp[j][k])
				//	cout << i << " " << j << endl;
			}
		}
	}
	for(int i = 1; i <= n; i ++) {
		ans += dp[i * av][i];
		//cout << i << " " << dp[i * av][i] << endl;
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, X = 0;
    cin >> N;
  
  for(int i = 0; i < N; i++){
  	int l, r;
    cin >> l >> r;
    X += r - l + 1;
  }
  cout << X << endl;
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main() {
    int K, S;
    cin >> K >> S;
    
    long long int ans=0;
    if(2*K>=S) {
        if(K<=S) {
            ans = K*K + 2*K*(S-K) - 2*(S-K)*(S-K) + 3*K + 2;
            ans /= 2;
        } else {
            ans = S*S + 3*S + 2;
            ans /= 2;
        }
    } else {
        ans = (3*K-S)*(3*K-S) + 3*(3*K-S) + 2;
        ans /= 2;
    }
    
    cout << ans << endl;



    return 0;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void) {
    string str;
    cin>>str;
    ll ans = 0;
   	int n = str.length();
   	int cnt = 0;
   	for (int i = 0;i < n;++i) {
   		if (str[i] == 'A')
   			++cnt;
   		else {
   			if (str[i] == 'C')
   				cnt = 0;
   			else
   			if (str[i] == 'B') {
   				if (i == n - 1 || str[i + 1] != 'C')
   					cnt = 0;
   				else
   					ans += cnt,i += 1;
   			}
   		}
   	}
   	cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long INF = 10000000000000;
int main(){
  vector<pair<char, long long>> A;
  while (1){
    char c;
    cin >> c;
    if (c == '$'){
      break;
    }
    int l;
    cin >> l;
    A.push_back(make_pair(c, l));
  }
  vector<pair<char, long long>> B;
  while (1){
    char c;
    cin >> c;
    if (c == '$'){
      break;
    }
    int l;
    cin >> l;
    B.push_back(make_pair(c, l));
  }
  vector<pair<char, long long>> C;
  while (1){
    char c;
    cin >> c;
    if (c == '$'){
      break;
    }
    int l;
    cin >> l;
    C.push_back(make_pair(c, l));
  }
  int N = A.size();
  A.push_back(make_pair('$', INF));
  int M = B.size();
  long long sum = 0;
  for (int i = 0; i < M; i++){
    sum += B[i].second;
  }
  bool ok = false;
  for (int i = 0; i < N; i++){
    if (A[i].first == B[0].first && A[i].second >= B[0].second){
      vector<pair<char, long long>> S;
      S.push_back(B[0]);
      long long L = B[0].second;
      int p = i + 1;
      while (1){
        if (L + A[p].second > sum){
          if (sum - L > 0){
            S.push_back(make_pair(A[p].first, sum - L));
          }
          break;
        } else{
          S.push_back(A[p]);
          L += A[p].second;
          p++;
        }
      }
      if (S == B){
        vector<pair<char, int>> T;
        for (int j = 0; j < i; j++){
          T.push_back(A[j]);
        }
        if (B.size() > 1){
          if (A[i].second > B[0].second){
            T.push_back(make_pair(A[i].first, A[i].second - B[0].second));
          }
          for (auto P : C){
            T.push_back(P);
          }
        } else {
          for (auto P : C){
            T.push_back(P);
          }
          if (A[i].second > B[0].second){
            T.push_back(make_pair(A[i].first, A[i].second - B[0].second));
          }
        }
        if (p < N){
          T.push_back(make_pair(A[p].first, A[p].second - (sum - L)));
        }
        for (int j = p + 1; j < N; j++){
          T.push_back(A[j]);
        }
        int K = T.size();
        vector<pair<char, int>> ans;
        ans.push_back(T[0]);
        for (int j = 1; j < K; j++){
          if (T[j].first == T[j - 1].first){
            ans.back().second += T[j].second;
          } else {
            ans.push_back(T[j]);
          }
        }
        int m = ans.size();
        for (int j = 0; j < m; j++){
          cout << ans[j].first << ' ' << ans[j].second << ' ';
        }
        cout << '$' << endl;
        ok = true;
        break;
      }
    }
  }
  if (!ok){
    for (int i = 0; i < N; i++){
      cout << A[i].first << ' ' << A[i].second << ' ';
    }
    cout << '$' << endl;
  }
}


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#define ll long long
#define inf 0x7fffffff;
#define maxn 200005
using namespace std;
ll k;
ll n,num,ans,sum;
ll a[maxn],vis[maxn],de[maxn],cnt1[maxn];
stack<int>s;
ll read()
{
    ll l=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
        w=-1;
        else
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        l*=10;
        l+=ch-'0';
        ch=getchar();
    }
    return l*w;
}
void dfs(int x,int step)
{	
	if(vis[x]==1)
	{
		num=de[x];
		ans=step-de[x];
		return ;
	}
	de[x]=step;
	vis[x]=1;
	dfs(a[x],step+1);
}
int main()
{
	n=read(),k=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	de[1]=0,vis[1]=1;
	dfs(a[1],1);
	ll x=1;
	if(k<=num)
	{
		for(int i=1;i<=k;i++)
		x=a[x];
		printf("%lld\n",x);
		return 0;
	}
	for(int i=1;i<=num;i++)
	x=a[x];
	k-=num;
	sum=k%ans;
	for(int i=1;i<=sum;i++)
	x=a[x];
	printf("%lld\n",x);
	return 0;
}


Measured memory_bytes: 8396
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

void merge(int n[], int left, int mid, int right)
{
    int num = right - left;
    int *tmp = new int[num];

    int iw = 0;
    int il = left;
    int ir = mid;

    while (il < mid && ir < right)
    {
        if (n[il] <= n[ir])
        {
            tmp[iw++] = n[il++];
        }
        else
        {
            tmp[iw++] = n[ir++];
        }
    }

    while (il < mid)
        tmp[iw++] = n[il++];
    while (ir < right)
        tmp[iw++] = n[ir++];

    for (int i = 0; i < num; i++)
        n[left + i] = tmp[i];

    delete[] tmp;
}

void merge_sort_sub(int n[], int left, int right)
{
    if (right - left <= 1) return;
    int mid = left + (right - left) / 2;
    merge_sort_sub(n, left, mid);
    merge_sort_sub(n, mid, right);

    merge(n, left, mid, right);
}

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

    merge_sort_sub(d, 0, N);
    cout << d[N / 2] - d[N / 2 -1] << endl;
}


Measured memory_bytes: 1212
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut c: Vec<i64> = a.iter().enumerate().map(|x| x.1 - (x.0 + 1) as i64).collect();
    c.sort();

    let ans: i64 = c.iter().map(|x| (x - c[n / 2]).abs()).sum::<i64>();
    ans.to_string()
}


Measured memory_bytes: 7604
# 動的計画法(DP)
s=input()
words = {"dream", "dreamer", "erase", "eraser"}

dp = dict()
dp[0] = 1
for i in range(0, len(s)):
    if not dp.get(i):
        continue
    for word in words:
        if s[i:i+len(word)] == word:
            dp[i+len(word)] = 1

print("YES" if dp.get(len(s)) else "NO")

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

typedef long long int in; 

double dp[3005],ans;

int main() 
{
    in n,i,j;
    cin>>n;
    
    double p[n+1];
    
    for(i=1;i<=n;++i)
    {
        cin>>p[i];
    }
    
    dp[0]=1;
    
    for(i=1;i<=n;++i)
    {
        for(j=i;j>0;--j)
        dp[j]=dp[j-1]*p[i]+dp[j]*(1-p[i]);
    
        dp[0]=dp[0]*(1-p[i]);
    }
    
    for(i=1;i<=n;++i)
    {
        if(i>n-i)
        ans+=dp[i];
    }
    
    cout<<fixed<<setprecision(10)<<ans;
    
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int n;
double p[3050],ans,dp[3050][3050];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%lf",&p[i]);
	dp[0][0]=1;
	for (int i=1;i<=n;i++){
		dp[i][0]=dp[i-1][0]*(1-p[i]);
		for (int j=1;j<=i;j++)dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
	}
	for (int i=(n+1)/2;i<=n;i++)ans+=dp[n][i];
	printf("%.10lf\n",ans);
}

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

bool dp[110000];
int main(){
    int n,k;cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];

    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-a[j]>=0)dp[i]|= !dp[i-a[j]];
            //右辺はi-a[j]が個の時負けの状態なら 1(勝ちの状態)になる  みたいな感じ
        }
    }
    if(dp[k])cout<<"First"<<endl;
    else cout<<"Second"<<endl; 

}

Measured memory_bytes: 3740