akhauriyash/Code-Regression huggingface dataset:
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,t,a[100005];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(;i<n;t+=a[i],i++)cin>>a[i];
	sort(a,a+n);
	if(a[n-m]*4*m<t)cout<<"No";
	else cout<<"Yes";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <set>
using namespace std;
typedef long long i64;
typedef pair<int, int> pii;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 6e2+5;
int n, d1, d2, c[N][N], tot;
void solve(int d)
{
    int t = 0; while(!(d&3)) ++t, d >>= 2;
    if((d&3) == 1) 
    {
        for(int i = 0; i < n<<1; ++i)
            for(int j = 0; j < n<<1; ++j)
                c[i][j] |= ((i>>t)+(j>>t))&1; 
    }
    else
    {
        for(int i = 0; i < n<<1; ++i)
            for(int j = 0; j < n<<1; ++j)
                c[i][j] |= (i>>t)&1;      
    }
}
int main()
{
    n = read(), d1 = read(), d2 = read(), solve(d1), solve(d2);
    for(int i = 0; i < n<<1; ++i)
        for(int j = 0; j < n<<1; ++j)
            if(!c[i][j]&&++tot <= n*n) printf("%d %d\n", i, j);
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){

  int n;
  cin >> n;
  string line;
  cin >> line;

  int l = 0;
  int count = 0;

  for (int i = 0; i < line.size(); i++) {
    if (line[i] == '(') {
      count -= 1;
    } else {
      count += 1;
      l = max(l, count);
    }
  }

  int r = 0;
  count = 0;
  for (int i = line.size()-1; i >= 0; i--) {
    if (line[i] == '(') {
      count += 1;
      r = max(r, count);
    } else {
      count -= 1;
    }
  }
  string a = string(l, '(') + line + string(r, ')');
  
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
v=int(input())
d=int(input())
e=int(input())
k=int(input())

if b-a>k:
  print(':(')
elif v-a>k:
  print(':(')
elif d-a>k:
  print(':(')
elif e-a>k:
  print(':(')
elif v-b>k:
  print(':(')
elif d-b>k:
  print(':(')
elif e-b>k:
  print(':(')
elif d-v>k:
  print(':(')
elif e-v>k:
  print(':(')
elif e-d>k:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long a,b,n;
    cin>>n>>a>>b;
    if((b-a)%2==0){
        cout<<(b-a)/2;
    }
    else{
        cout<<min(a-1,n-b)+1+(b-a-1)/2;
    }
}


Measured memory_bytes: 256
module Main where

import Data.Functor
import Data.Maybe

main :: IO ()
main =  do
  { [x,o,y] <- getWords
  ; if (o == "?") then done
    else print (readOp o (read x) (read y)) >> main
  }

done :: IO ()
done = return ()

type Op = Int -> Int -> Int

ops :: [(String,Op)]
ops = [("+",(+)),("-",(-)),("*",(*)),("/",div)]

readOp :: String -> Op
readOp s = maybe undefined id (lookup s ops)

getWords :: IO [String]
getWords = words <$> getLine

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define ldb long double
#define clr(x) memset(x,0,sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
const int size1 = 1e5+7;
const int size2 = 1e4;
const ll mod = 1e9+7;
 
// ll fact[size1];
 
ll pw(ll x,ll y,ll md)
{
    if(y==0)return 1;
    ll p =pw(x,y/2,md);
    p = (p*p)%md;
    if(y%2==1)p = (p*x)%md;
    return p;
}
// ll gcd(ll a,ll b)
// {
//  if(b==0)return a;
//  a = a%b;
//  return gcd(b,a);
// }
// ll inverse(ll x,ll mod)
// {
//     return pw(x,mod-2,mod);
// }
// ll ncr(ll n,ll r,ll mod)
// {
//     ll num = fact[n];
//     ll den = (fact[r] * fact[n-r])%mod;
//     den = inverse(den,mod);
 
//     ll ans = (num*den)%mod;
//     return ans;
// }
// vector<ll> adj1[size1];
// vector<ll> adj[size1];
// ll d[size1];
// ll n,m;
// void dikstra(ll s)
// {
//     for(ll i=1;i<=n;i++)d[i]=1e9;
//     d[s] = 0;
//     priority_queue<pll, vector<pll>, greater<pll>> q;
//     q.push({0, s});
//     while(!q.empty())
//     {
//         ll v = q.top().ss;
//         ll d_v = q.top().ff;
//         q.pop();
//         if(d_v!=d[v])continue;
//         for(auto to:adj1[v])
//         {
//             ll len = 1;
//             if(d[v] + len < d[to])
//             {
//                 d[to] = d[v]+len;
//                 q.push({d[to],to});
//             }
//         }
//     }
// }
 
// ll smallestPrimeFactor[size1];
 
// void seive(){
//     clr(smallestPrimeFactor);
 
//     for(ll i=2;i<size1;i++){
//         if(smallestPrimeFactor[i]!=0)continue;
//         smallestPrimeFactor[i] = i;
//         for(ll j=2*i;j<size1;j+=i){
//             smallestPrimeFactor[j]=i;
//         }
//     }    
// }

int main()
{
    //cout<<setprecision(12)<<fixed;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    
    ll T;
    //cin>>T;
    T = 1;
    while(T--)
    {
        //cout<<"Case #"<<cas<<": ";cas++;
        ll n;cin>>n;

        if(n==1){cout<<0<<endl;continue;}

        ll dp[4];

        // for n = 2;
        dp[0] = 64;
        dp[1] = 17;
        dp[2] = 17;
        dp[3] = 2;

        for(ll i=3;i<=n;i++){
            ll curr[4];
            curr[0] = (dp[0]*8)%mod;
            curr[1] = (dp[0]+ (dp[1]*9)%mod)%mod;
            curr[2] = (dp[0]+ (dp[2]*9)%mod)%mod;
            curr[3] = ( dp[1] + dp[2] + (dp[3]*10)%mod ) %mod;

            dp[0] = curr[0];
            dp[1] = curr[1];
            dp[2] = curr[2];
            dp[3] = curr[3];
        }

        cout<<dp[3]<<endl;

    }
}

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

void solve(long long N, std::vector<long long> a) {
    set<ll> colorset;
    ll cnt = 0;
    rep(i, N) {
        ll r = a[i];
        if (r >= 3200) {
            cnt++;
        } else {
            colorset.insert(r / 400);
        }
    }
    if (colorset.size() == 0) {
        cout << 1 << " " << cnt << endl;
    } else {
        cout << colorset.size() << " " << (ll)colorset.size() + cnt << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

public class Program
{
    static void Main()
    {
        var str = Console.ReadLine();
        var count = 0;
        var buf = str[0];
        for (int i = 1; i < str.Length; i++)
        {
            if (buf != str[i])
            {
                buf = str[i];
                count++;
            }
        }

        Console.WriteLine(count);
    }
}


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

struct UnionFind {
    vector<ll> par;
    ll count = 0;
    UnionFind(ll n) : par(n) {
        for (ll i = 0; i < n; i++) {
            par[i] = i;
            if (i == 0) count = n;
        }
    }
  
    ll root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
  
    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        count --;
    }
  
    bool same(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll ans() {
        return count-1;
    }
};

int main () {
    ll n, m;
    cin >> n >> m;

    UnionFind tree(n);

    for (ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        tree.unite(a,b);
    }

    cout << tree.ans() << endl;
}

Measured memory_bytes: 3956
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
from scipy.misc import comb
from collections import Counter
n, m = map(int, input().split())
c = Counter(prime_factorize(m))
l = [i[1] for i in c.most_common()]
ans = 1
for i in l:
    ans *= comb(i + n - 1, i, exact=True)
    ans %= 10 ** 9 + 7
print(int(ans))

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

int main() {
  int N, a, b, c, d, e, f, p, q, r, s, t, u;
  cin >> N;
  
  int lowest = 200;
   
  for (int i = 2; i < N/2+2; i++) {
    
    a = i/100000; 
    b = (i-a*100000)/10000; 
    c = (i-a*100000-b*10000)/1000; 
    d = (i-a*100000-b*10000-c*1000)/100;
    e = (i-a*100000-b*10000-c*1000-d*100)/10;
    f = i-a*100000-b*10000-c*1000-d*100-e*10;
    
    int j = N - i;
    
    p = j/100000; 
    q = (j-p*100000)/10000; 
    r = (j-p*100000-q*10000)/1000; 
    s = (j-p*100000-q*10000-r*1000)/100;
    t = (j-p*100000-q*10000-r*1000-s*100)/10;
    u = j-p*100000-q*10000-r*1000-s*100-t*10;
    
    int sum = 0;
    sum = a+b+c+d+e+f+p+q+r+s+t+u;       
    
    if ( sum <= lowest ) {
      lowest = sum;
    }
    else {
    }
    
  }
  
  cout << lowest << endl;
    
}

Measured memory_bytes: 256
n = gets.to_i
array = []
n.times do
  array << gets.chomp.to_s
end

ans = array.group_by(&:itself).map{|k, v| [k, v.count]}.sort_by{|k,n| -n}
ans_name = [ans[0][0]]

ans_cut = ans[1..-1]
ans_cut.each do |x|
    if ans[0][1] == x[1]
        ans_name << x[0]
    else
        break
    end
end

puts ans_name.sort


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

using namespace std;

int main(){
    long long n, k, ans = 0, cur = 0;
    cin >> n >> k;
    vector<long long> v;
    for(long long i = 0; i < n; ++i){
        long long tmp; cin >> tmp;
        v.push_back(tmp);
    }
    while(cur < n){
        if(ans == 0) cur += k;
        else cur += (k - 1);
        ans++;
    }
    cout << ans;
    return 0;

}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int main()
{
    int i,j;
    int H,N;

    scanf("%d %d", &H, &N);

    int sum = 0;
    for( i=0; i<N; i++)
    {
        int a;
        scanf("%d", &a);
        sum += a;
    }
    if(sum >= H)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 256
import java.nio.file.*;
import java.nio.charset.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int p = 0;
        for(int i=a;i<b+1;i++){
            String str = String.valueOf(i);
            if(str.charAt(0) == str.charAt(4)
        && str.charAt(1) == str.charAt(3)){
                p += 1;
            }
        }
        System.out.println(p);
    }
}

Measured memory_bytes: 27472
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
priority_queue<int> Q[3];
int a[500010];

int F(int bef,int aft){
    int cnt=0;
    while(true){
        int pnt=(3+aft-bef)%3;
     if(Q[pnt].empty())break;
     cnt++;
     Q[pnt].pop();
     if(!Q[0].empty()){
      while(!Q[0].empty()){
       cnt++;
       Q[0].pop();
      }
     }
     bef=aft;
     if(aft==1)aft=2;
     else if(aft==2)aft=1;
    }
    if(!Q[0].empty()||!Q[1].empty()||!Q[2].empty())cnt++;
    return cnt;
}

int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
     Q[a[i]%3].push(a[i]);   
    }
    int ans=F(0,1);
    for(int i=0;i<3;i++){
     while(!Q[i].empty())Q[i].pop();   
    }
    for(int i=0;i<n;i++){
     Q[a[i]%3].push(a[i]);   
    }
    ans=max(ans,F(0,2));
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 6992
import sys
readline = sys.stdin.buffer.readline

n,q= map(int,readline().split())


class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

uf = WeightedUnionFind(n)

for i in range(q):
    s = readline().rstrip().decode('utf-8')
    if s[0] == "0":
        com,a,b,w = map(int,s.split())
    else:
        com,a,b = map(int,s.split())
    if com:
        if uf.same(a,b):
            print(uf.diff(a,b))
        else:
            print("?")
    else:
        uf.union(a,b,w)


Measured memory_bytes: 12496
from collections import defaultdict
from itertools import product

H,W,N = map(int,input().split())

covered = defaultdict(int)
vector = [[-1,-1],[-1,0],[-1,1],[1,0],[1,1],[0,0],[0,-1],[0,1],[1,-1]]

for _ in range(N):
    a,b = map(int,input().split())
    for dx,dy in vector:
        x = a+dx-1
        y = b+dy-1
        if 1 <= x < H-1 and 1 <= y < W-1:
            covered[(x,y)] += 1

values = [0]*10
for i in covered.values():
    values[i] += 1

values[0] = (H-2)*(W-2) - sum(values)

for v in values:
    print(v)


Measured memory_bytes: 166860
#include <iostream>
using namespace std;
int main(){
  long long A,B,K;
  cin >> A >> B >> K;
  for(int i = 0; K > i; i++){
    if(i % 2 == 0){
      if(A % 2 == 1) A--;
      A /= 2;
      B += A;
    } else {
      if(B % 2 == 1) B--;
      B /= 2;
      A += B;
    }
  }
  cout << A << " " << B << endl;
  return 0;
}

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

using ll = long long;

int main() {
    int N;  cin >> N;
    vector<ll> A(N + 1), B(N);
    for (int i = 0; i < N + 1; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i];


    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += min(B[i], A[i]);
        B[i] = max(B[i] - A[i], 0LL);
        ans += min(B[i], A[i + 1]);
        A[i + 1] = max(A[i + 1] - B[i], 0LL);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4860
Scanf.scanf "%d %d %d" (fun n m c ->
    let b = Array.init m (fun _ -> Scanf.scanf " %d" (fun b -> b)) in

    let rec loop i acc =
        if i = n then acc else
            let a = Array.init m (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
            let rec loop2 j acc4 =
                if j = m then acc4 else loop2 (j + 1) (acc4 + b.(j) * a.(j))
            in
            loop (i + 1) (if loop2 0 c > 0 then acc + 1 else acc)
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
 
const int maxn = 20;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ll a,b,k; cin >> a >> b >> k;
    ll val =  max(1LL * 0, b + a - k);
    if(val <= b){
        cout << 0 << ' ' << val << '\n';
    }else{
        cout << val - b << ' ' << b << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

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

const int DIM = 10005;

deque<pair<int, int>> arr;

char str1[DIM], str2[DIM];
int psm[DIM], psl[DIM], psr[DIM], val[DIM];

int cost(int x, int y, int d)
{
    int l = min(0, d) - x, r = max(0, d) + y;
    return 2 * (r - l) - abs(d);
}

int main(void)
{
    cin >> (str1 + 1) >> (str2 + 1);
    int n = (int) strlen(str1 + 1), ans = 1e9;
    
    for (int i = 1; i <= n; ++i) {
        str1[i + n] = str1[i]; str1[i] = 0;
        str2[i + n] = str2[i + n * 2] = str2[i];
    }
    
    // cazuri particulare
    int nr1 = 0, nr2 = 0;
    for (int i = 1; i <= n; ++i) {
        nr1 += str1[i + n] == '1';
        nr2 += str2[i + n] == '1';
    }
    
    if (!nr2) {
        cout << (!nr1 ? 0 : -1) << endl;
        return 0;
    }
    
    // solutia legit
    for (int i = 1; i <= n * 3; ++i)
        psm[i] = psm[i - 1] + (str2[i] == '1');
    
    for (int i = 1; i <= n * 3; ++i)
        psl[i] = (str2[i] == '1' ? 0 : psl[i - 1] + 1);
    for (int i = n * 3; i >= 1; --i)
        psr[i] = (str2[i] == '1' ? 0 : psr[i + 1] + 1);
    
    // rotesc sirul a cu p pasi in una din cele 2 directii
    for (int p = -n + 1; p <= +n - 1; ++p) {
        arr.clear();
        
        int p1 = n, p2 = n + p;
        if (p1 > p2) swap(p1, p2);
        
        for (int i = 1; i <= n; ++i) {
            if (str1[i + n] == str2[i + n + p])
                continue;
            
            if (psm[p2 + i] - psm[p1 + i - 1] > 0)
                arr.push_back(make_pair(0, 0));
            else
                arr.push_back(make_pair(psl[min(i + n, i + n + p)],
                                        psr[max(i + n, i + n + p)]));
        }
        
        sort(arr.begin(), arr.end());
        arr.push_front(make_pair(0, 1e9));
        
        p1 = p2 = 0; val[arr.size()] = 0;
        for (int i = (int) arr.size() - 1; i >= 1; --i)
            val[i] = max(val[i + 1], arr[i].second);
        
        for (int i = 0; i < arr.size(); ++i)
            if (!i or cost(p1, p2, p) > cost(arr[i].first, val[i + 1], p))
                tie(p1, p2) = tie(arr[i].first, val[i + 1]);
        
        ans = min(ans, cost(p1, p2, p) + (int) arr.size() - 1);
    }
    
    cout << ans << endl;
    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n, r; cin >> n >> r;
        int k = 1e9, sum = 0;
        for (int i = 1; i <= n; i++) {
                sum += r + i - 1;
                if (abs(k) > abs(r + i - 1)) k = r + i - 1;
        }

        sum -= k;
        cout << sum;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int k = 111;
    while(N > k) {
        k += 111;
    }
    cout << k << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int a,b,c; cin >> a>>b>>c;
    a=abs(a);

    int reach=a/c;
    int c1=a-c*reach;
    int c2=min(c1+c,abs(c1-c));
    if(b<reach){
        cout<<a-b*c<<endl;
    }else{
        if((b-reach)%2==0) cout<<c1<<endl;
        else cout<<c2<<endl;
    }
}

Measured memory_bytes: 3632
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


a, b = fetch_one_line().split(" ")
a_n, b_n = [int(i) for i in fetch_one_line().split(" ")]
remove_str = fetch_one_line()

if a == remove_str:
    a_n -= 1

else:
    b_n -= 1

print(a_n, b_n)




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

using namespace std;

const int N = 1000100;

int Dp[N][2];

int main()
{
    string s[2];    cin >> s[0];

    int n = s[0].size();

    for(int i = 0; i < n; i++)  s[0][i] -= '0';

    s[1] = s[0];

    for(int i = 0; i < n; i++)  s[1][i] = 9 - s[0][i];

    s[1][n - 1] = 10 - s[0][n - 1];

    Dp[n][0] = Dp[n][1] = 0;

    for(int i = n - 1; ~i; --i)
        for(int j = 0; j < 2; j++)
            Dp[i][j] = min(s[j][i] + Dp[i + 1][j], 1 + s[!j][i] + Dp[i + 1][!j]);

    cout << Dp[0][0] << endl;
}


Measured memory_bytes: 10116
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
 
    stack<int>S1;
    stack<pair<int, int> >S2;
    char ch;
    int sum = 0;
    for (int i = 0;cin>>ch; i++){
        if (ch == '\\')S1.push(i);
        else if (ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
 
 
    vector<int>ans;
    int t = 0;
    while (S2.size() > 0){ ans.push_back(S2.top().second); S2.pop(); }
    reverse(ans.begin(), ans.end());
    cout << sum << "\n";
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++){
        cout << " ";
        t += ans[i];
        cout << ans[i];
    }cout << "\n";
 
    return 0;
}

Measured memory_bytes: 1292
import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s=bu.readLine();
        int l=s.length()-1;
        sb.append(s);
        if(s.charAt(l)=='s') sb.append("es");
        else sb.append("s");
        System.out.print(sb);
    }
}


Measured memory_bytes: 32500
mol = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(mol[k-1])

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

string solve(string s)
{
    int S=s.size();

    if(s[0]==s[S-1])
    {
        if(S%2==1) return "Second";
    }
    else
    {
        if(S%2==0) return "Second";
    }

    return "First";
}

int main()
{
    string s;
    cin >>s;
    cout << solve(s) << endl;
    return 0;
}


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





#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
ll N;
//-----------------------------------------------------------------------------------
int main() {
	cin >> N;
	N++;

	int d = 0;
	ll n = N;
	while (0 < n) n /= 2, d++;

	deque<int> deq;
	ll cur = 1; int num = 1;
	rrep(i, d - 2, 0) {
		deq.push_back(num); num++;
		cur *= 2;

		if (((cur + 1) << i) <= N) {
			deq.push_front(num);
			num++;
			cur++;
		}
	}

	cout << 80 + deq.size() << endl;
	rep(i, 0, 80) printf("%d ", i + 1);
	for (int i : deq) printf("%d ", i);

	cout << endl;
}

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

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

using namespace std;
using lint=long long;

int main(){
	int n,x; scanf("%d%d",&n,&x);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	lint ans=0;
	rep(i,n-1) if(a[i]+a[i+1]>x) {
		ans+=a[i]+a[i+1]-x;
		a[i+1]=x-a[i];
		if(a[i+1]<0){
			a[i]+=a[i+1];
			a[i+1]=0;
		}
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 640
a, b, m = map(int,input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
saisho=min(alist)+min(blist)
for i in range(m):
    x, y, c = map(int,input().split())
    now=alist[x-1]+blist[y-1]-c
    if now<=saisho:
        saisho=now

print(saisho)

Measured memory_bytes: 72168
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  ll m;
  std::cin>>m;

  ll now=0,ans=-1,up=0;

  rep(i,0,m){
    ll d,c;
    std::cin>>d>>c;

    ans+=c;
    up+=(now+d*c)/10;
    now=(now+d*(c%10))%10;
  }

  while(up+now>=10){
    ans+=up;
    ll sum=up+now;
    up=sum/10;
    now=sum%10;
  }

  std::cout<<ans+up<<"\n";

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int d[3],i;
  while(scanf("%d %d %d",&d[0],&d[1],&d[2])!=EOF){
    int c=0,n[10]={0};
    for(i=0;i<3;i++)n[d[i]-1]++;
    for(i=0;i<10;i++){
      if(n[i]==0){
	if(d[0]+d[1]+i+1<=20)c++;
      }
    }
    if(c>3)printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdlib>

bool contains(int bottom, int left, int w, int h, int x, int y, int r)
{
    return (left <= x - r) && (left + w >= x + r) && (bottom <= y - r) && (bottom + h >= y + r);
}

int main()
{
    int w, h, x, y, r;
    std::cin >> w >> h >> x >> y >> r;
    std::cout << (contains(0, 0, w, h, x, y, r) ? "Yes" : "No") << std::endl;
    
    /*
    for (int j=2; j>=0; j--)
        for (int i=0; i<j; i++)
            if (x[i] > x[i + 1])
                swap(&x[i], &x[i + 1]);
    */
    return 0;
}



Measured memory_bytes: 3112
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,mix=2e9;
ll ans;
int main(void){
	register int i,x,y;
	n=read();
	for(i=1;i<=n;++i){
		x=read(),y=read();
		ans+=y;
		if(y<x)mix=min(mix,y);
	}
	if(mix==2e9)puts("0");
	else printf("%lld\n",ans-mix);
	return 0;
}

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

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

  ll divisor = 1000000007;
  ll power = 1;
  for (int i = 1; i <= n; i++) {
    // cout << power << " * " << i << " = ";
    power = power * i;
    if (power >= divisor) {
      power = power % divisor;
    }
    // cout << power << endl;
  }

  cout << power << endl;
  return 0;
}


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

int main(){
  int n;
  std::cin >> n;
  vector<int> a(n);
  int mini = 1e9, maxi = 0;
  for (int i = 0; i < n; i++){
    std::cin >> a[i];
    maxi = max(maxi, a[i]);
    mini = min(mini, a[i]);
  }
  if(maxi - mini > 1){
    std::cout << "No" << std::endl;
    return 0;
  }
  if(maxi == mini){
    if(n - maxi == 1 or maxi <= n/2){
      std::cout << "Yes" << std::endl;
    }else{
      std::cout << "No" << std::endl;
    }
  }else{
    int p = 0, q = 0;
    for (int i = 0; i < n; i++) {
      p += (a[i] == mini);
      q += (a[i] == maxi);
    }
    if(maxi <= p){
      std::cout << "No" << std::endl;
    }else if(maxi <= p + q/2) {
      std::cout << "Yes" << std::endl;
    }else{
      std::cout << "No" << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 768
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	char buf[3];
	int i,j,cnt,flg,n;
	scanf("%d",&n);
	cnt=0;	flg=1;
	for(i=0;i<n;i++)	{
		scanf("%s",buf);
		if(strcmp(buf,"A")==0)	cnt++;
		else cnt--;
		if(cnt<0)	{
			flg=0;	break;
		}
	}
	if(cnt!=0)	flg=0;
	if(flg==1)	printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N);
	long long sum =0;
	for(int i =0; i < N; i++) {
		cin >> A[i];
		sum +=A[i];}
	vector<long long> pE(N+1,-sum-tisic),pO(N+1,-sum-tisic);
	pE[0] =0;
	for(int i =0; i < N; i++) {
		if(A[i] == 0) {
			pE[i+1] =pE[i];
//			cout << pE[i+1] << "\n";
			continue;}
		pO[i+1] =max((A[i]-1)/2+pE[i],A[i]/2+pO[i]);
		pE[i+1] =max(A[i]/2+pE[i],(A[i]+1)/2+pO[i]);
		pE[i+1] =max(pE[i+1],pO[i+1]);
//		cout << pO[i+1] << " " << pE[i+1] << "\n";
		}
	cout << max(pE[N],pO[N]) << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
int main() {
	int n, k; std::cin >> n >> k;
	std::vector<int> values(n);
	for (auto& value : values) std::cin >> value;
	int max = 0;
	for (auto left_until = 0; left_until <= n; ++left_until) {
		int sum = 0;
		std::priority_queue<int, std::vector<int>, std::greater<int>> queue;
		for (auto i = 0; i < left_until; ++i) {
			sum += values[i];
			if (values[i] < 0) {
				queue.push(values[i]);
			}
		}
		for (auto right_from = left_until; right_from <= n; ++right_from) {
			if (left_until + n - right_from > k) {
				continue;
			}
			else {
				int left_sum = sum;
				int right_sum = 0;
				std::priority_queue<int, std::vector<int>, std::greater<int>> right_queue;
				for (auto i = right_from; i < n; ++i) {
					right_sum += values[i];
					if (values[i] < 0) {
						right_queue.push(values[i]);
					}
				}
				std::vector<int> poped_left;
				for (auto count = left_until + n - right_from; count < k; ++count) {
					if (right_queue.empty() || queue.empty()) {
						if (!right_queue.empty()) {
							right_sum -= right_queue.top(); right_queue.pop();
						}
						else if (!queue.empty()) {
							left_sum -= queue.top(); poped_left.push_back(queue.top()); queue.pop();
						}
					}
					else if (right_queue.top() < queue.top()) {
						right_sum -= right_queue.top(); right_queue.pop();
					}
					else {
						left_sum -= queue.top(); poped_left.push_back(queue.top()); queue.pop();
					}
				}
				if (max < left_sum + right_sum) {
					max = left_sum + right_sum;
				}
				for (const auto& p : poped_left) queue.push(p);
			}
		}
	}
	std::cout << max << std::endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll N;
	cin >> N;
	string ans;
	while (N > 0) {
		N--;
		ans.push_back('a' + N % 26);
		N /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
int n, a[500000]; vector<int>p;
int main() {
	cin >> n;
	int B = n; if (n % 2 == 0)B = n - 1;
	for (int i = B; i >= 1; i -= 2)p.push_back(i);
	for (int i = 2; i <= n; i += 2)p.push_back(i);
	if (n % 2 == 0)reverse(p.begin(), p.end());
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) { if (i >= 2)cout << ' '; cout << a[p[i - 1]]; }cout << endl;
	return 0;
}

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

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    int A[102][102] = {};
    int B[102][102] = {};
    //?????????????´????????´?
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cin >> A[i][j];
    }

    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++) cin >> B[i][j];
    }


    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            long long temp = 0;
            for(int k = 0; k < m; k++){
                temp += A[i][k] * B[k][j];
            }
            if(j == l-1) cout << temp;
            else cout << temp << " ";
        }
        cout << endl;
    }



return 0;
}

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

typedef long long LL;
typedef unsigned long long ULL;

template<class T>
inline bool read(T &num)  
{
       char in;bool IsN=false;
       while(in=getchar(),in!='-'&&(in<'0'||in>'9'))if(in==EOF)return false;
       in=='-'?(IsN=true,num=0):num=in-'0';
       while(in=getchar(),in>='0'&&in<='9')num=num*10+in-'0';
       return IsN?num=-num:num,true;
}


#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define __m  int mid=l+(r-l)/1

const int maxn   = 2e6 + 7;
const LL  inf_LL = 9e18   ;
const int inf    = 2e9 + 7;
const int mod    = 1e9 + 7;
int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif
    int n;
    cin>>n;
    LL ans=0;
    while(n--)
    {
        int a,b;
        cin>>a>>b;
        ans+=b-a+1;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

const int N = 3e3 + 5, mod = 1e9 + 7, MAXX = 2e5 + 5;
int h, w, n, dp[N], fact[MAXX], invFact[MAXX];

struct Cell {
    int x, y;
    Cell (int x = 0, int y = 0) : x(x), y(y) {}
    bool operator< (const Cell& rhs) const { return x == rhs.x ? y < rhs.y : x < rhs.x; }
} cell[N];

int binPow (int _a, int _m) {
    int ret = 1;
    for (; _m; _m >>= 1, _a = 1LL * _a * _a % mod) if (_m & 1) ret = 1LL * ret * _a % mod;
    return ret;
}

int C (int _k, int _n) { return 1LL * fact[_n] * invFact[_k] % mod * invFact[_n - _k] % mod; }

int main () {
    fact[0] = 1; for (int i = 1; i < MAXX; ++i) fact[i] = 1LL * fact[i - 1] * i % mod;
    invFact[MAXX - 1] = binPow(fact[MAXX - 1], mod - 2);
    for (int i = MAXX - 2; i >= 0; --i) invFact[i] = 1LL * invFact[i + 1] * (i + 1) % mod;


    scanf("%d %d %d", &h, &w, &n);
    for (int i = 1; i <= n; ++i) {
        int x, y; scanf("%d %d", &x, &y);
        cell[i] = Cell(x, y);
    }
    cell[0] = Cell(1, 1);
    cell[n + 1] = Cell(h, w);
    sort(cell, cell + n + 2);

    for (int i = 1; i <= n + 1; ++i) {
        dp[i] = C(cell[i].x - 1, cell[i].x + cell[i].y - 2);
        for (int j = 1; j < i; ++j) {
            if (cell[j].y <= cell[i].y) dp[i] = (dp[i] - 1LL * dp[j] * C(cell[i].x - cell[j].x, cell[i].x - cell[j].x + cell[i].y - cell[j].y) ) % mod;
        }
    }

    cout << (dp[n + 1] + mod) % mod;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int l;
#define fastIO              ios::sync_with_stdio(false), cin.tie(0)
#define pf                  push_front
#define pb                  push_back
#define popb                pop_back()
#define popf                pop_front()
#define loop(i,n)           for(int i=0;i<n;i++)
#define lop(i,n)           for(int i=1;i<n;i++)
#define loops(i,x,n)        for(int i=x;i<n;i++)
#define loopr(i,n)          for(int i=n-1;i>=0;i--)
#define loopt(i,n)          for(int i=0;i<=n;i++)
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define INT_BITS 32
#define  st                  l t; cin>>t;
#define  sn                  l n; cin>>n;
#define  unordered_map<l,l>  u;
#define MOD1 1000000007
char c[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
l gcd(l a,l b)
{
    return b==0?a:gcd(b,a%b);
}
int maxSubArray(vector<int>& nums) {
        int msf = INT_MIN,meh = 0;
        for(int i=0;i<nums.size();i++)
        {
            meh = meh + nums[i];
            if(meh<nums[i])
                meh = nums[i];
            if(msf<meh)
                msf = meh;
        }
        return msf;
}
l binaryToDecimal(l n)
{
    l num = n;
    l dec_value = 0;
    l base = 1;

    l temp = num;
    while (temp) {
        l last_digit = temp % 10;
        temp = temp / 10;

        dec_value += last_digit * base;

        base = base * 2;
    }

    return dec_value;
}
/*void bt(int s,int e,int *tree,int ind )
{
    if(s==e)
    {}
}*/
l sum(l a,l b)
{
    return a+b;
}
l frog(l h[],l n,l k)
{
   l dp[n];
   dp[0] = 0;
   for(l i=1;i<n;i++)
   {
       l ans = INT_MAX;
       for(l j=0;j<k;j++){
           l a;
           if((i-j)-1>=0){
        a = dp[(i-j)-1] + abs(h[i]-h[(i-j)-1]);
           }
       dp[i] = min(a,ans);
       ans = min(a,ans);
       }
   }
return dp[n-1];
}
int main()
{
    fastIO;
    l  n,k;
    cin>>n>>k;
    l a[n];
    l h[n];
    for(l i=0;i<n;i++)
    cin>>h[i];
    cout<<frog(h,n,k)<<"\n";

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
	ll k;string s;
	cin>>k>>s;
	ll n=s.size();
	COMinit();
	ll ans=0;
    // 計算例
//    cout << COM(100000, 50000) << endl;	
	for(ll i=0;i<=k;i++){
		ll n1=COM(n-1+k-i,n-1);
		ll n2=modpow(25,k-i,inf);
		ll n3=modpow(26,i,inf);
		ll cnt=n1*n2;
		cnt%=inf;
		cnt*=n3;
		cnt%=inf;
		ans+=cnt;
		ans%=inf;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 123828
def main():
    n = int(input())
    taro, hanako = 0, 0
    for _ in range(n):
        cards = input().split()
        if cards[0] == cards[1]:
            taro += 1
            hanako += 1
        elif cards[0] != sorted(cards)[0]:
            taro += 3
        else:
            hanako += 3
    print(taro, hanako)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<int>cnt(n,1);
    int x=0;
    for(int i=1;i<n;i++){
        if(a[i-1]==a[i]){
            cnt[x]++;
        }
        else x++;
    }
    sort(cnt.begin(),cnt.end());
    reverse(cnt.begin(),cnt.end());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=cnt[i];
    }
    if(n-ans<0){
        cout << 0 << endl;
        return 0;
    } 
    cout << n-ans << endl;
}

Measured memory_bytes: 4776
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << endl;
    } else {
        cout << R + 100 * (10 - N) << endl;
    }
    return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        /*
         * 値の格納
         * AとBの大小比較
         * 小さいほうにfalseを代入
         * trueの数を数える
         * */

        int numOfTenboudai = sc.nextInt();
        int numOfMichi = sc.nextInt();
        boolean[] isHighest = new boolean[numOfTenboudai];
        for (int i = 0; i < numOfTenboudai; i++) {
            isHighest[i] = true;
        }

        int[] hightOfTenboudai = new int[numOfTenboudai];
        for (int i = 0; i < numOfTenboudai; i++) {
            hightOfTenboudai[i] = sc.nextInt();
        }

        int A = 0;
        int B = 0;
        for (int i = 0; i < numOfMichi; i++) {
            A = sc.nextInt()-1;
            B = sc.nextInt()-1;
            if (hightOfTenboudai[A] > hightOfTenboudai[B]) {
                isHighest[B] = false;
            } else if (hightOfTenboudai[A] < hightOfTenboudai[B]) {
                isHighest[A] = false;
            } else {
                isHighest[A] = false;
                isHighest[B] = false;
            }
        }

        int ans = 0;

        for (int i = 0; i < numOfTenboudai; i++) {
            if (isHighest[i]) {
                ans++;
            }
        }

        System.out.println(ans);


    }
}


Measured memory_bytes: 59516