akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
n = int(input())
a = []
MX = 60
li = [[0]*MX for _ in range(MX)]
for _ in range(n):
    s = input().rstrip()
    tmp = s.find('.')
    if tmp==-1:
        r = 0
        k = int(s)
    else:
        r = -(len(s)-tmp-1)
        k = int(s[:tmp]+s[tmp+1:])
    r2 = r
    while k%2==0:
        k //= 2
        r2 += 1
    r5 = r
    while k%5==0:
        k //= 5
        r5 += 1
    li[r2+10][r5+10] += 1
ans = 0
for i in range(MX):
    for j in range(MX):
        for k in range(MX):
            for l in range(MX):
                if i+k-20<0 or j+l-20<0:
                    continue
                if i==k and j==l:
                    ans += li[i][j]*(li[i][j]-1)
                else:
                    ans += li[i][j]*li[k][l]
print(ans//2)

Measured memory_bytes: 74668
const main = (input) => {
  const n = parseInt(input.trim(), 10)
  let ans = 0
  for (let i=1; i<=n; i++) {
    const c = Math.floor(n / i)
    ans += (i + c*i) * c / 2
  }

  return console.log(ans)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 33240
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;


int main()
{
 //O_O ;
   ll t,b=0;
   cin>>t;
   map<string,ll>  mp;
   map<string,ll> ::iterator it;

for(ll i=0;i<t;i++)
{
    string s;
    cin>>s;
    mp[s]++;

    b=max(b,mp[s]);

}
for(it=mp.begin();it!=mp.end();it++)
{
    if((it->second)==b)
    cout<<it->first<<nn;
}

    return 0;
}


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

int main(){
	int a, b, k; cin >> a >> b >> k;
	int ans[100];
	int cnt = 1;
	int minv = min(a, b);
	for(int i = minv; i >= 1; --i){
		if(a % i == 0&& b % i == 0){
			ans[cnt] = i;
			cnt++;
		}
	}
	cout << ans[k] << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    int x = sc.nextInt();
    Main abc117A = new Main();
    System.out.println(abc117A.solve(t, x));
  }

  public double solve(int t, int x) {
    return (double) t / x;
  }
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int w = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int answer = 0;

		if(a<b){
			if(a+w<b){
				answer = b - a - w;
			}
		}else if(b<a){
			if(b+w<a){
				answer = a - b - w;
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 21972
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}


int main(){
  ll n; cin >> n; bool flag = false;
  
  rep(i,26){
    rep(j,16){
      if(4*i + 7*j == n){
        flag = true;
        break;
      }
    }
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

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;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    for(int i=1; i<n; i++){
        ll left = a[i-1];
        ll right = a[i];
        if(left > right){
            ans += (left - right);
            a[i] += (left - right);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  if(c-a-b<=0){
    cout << "No" << endl;
    return 0;
  }
  
  if(4*a*b < (c-a-b)*(c-a-b)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}



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

int kaijou(int x){
    int y = 1;
    for (int i = x; i > 0; i--){
        y *= i;
    }
    return y;
}

double dist(int x1, int x2, int y1, int y2){
    double d = (double)sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
    return d;
}

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    int z = kaijou(n);
    vector<vector<int>> d(z,vector<int>(n));
    iota(v.begin(), v.end(), 1);       
    int i = 0;
    do {
        int j = 0;
        for(auto x : v){
            d[i][j] = x;
            j++;
        }  
        i++;
    } while( next_permutation(v.begin(), v.end()) );    


    vector<P> zahyou(n);
    rep(i, n){
        cin >> zahyou[i].first >> zahyou[i].second;
    }

    double wa = 0.0;
    rep(i, z){
        rep(j, n - 1){
            int x1 = zahyou[d[i][j]-1].first;
            int x2 = zahyou[d[i][j+1]-1].first;
            int y1 = zahyou[d[i][j]-1].second;
            int y2 = zahyou[d[i][j+1]-1].second;
            wa += dist(x1, x2, y1, y2);
        }
    }

    
    cout << fixed << setprecision(7) << (double)wa / z << "\n";

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    mint ans = 0;
    for(ll i=K;i<=N+1;i++){
        ll mi = i*(i-1)/2;
        ll ma = N*(N+1)/2-(N-i)*(N-i+1)/2;
        ans += ma-mi+1;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
vector<int> A, B;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  
  cin >> N;
  A.resize(N);
  rep(i, N) {
    cin >> A[i];
  }
  sort(all(A));

  B.resize(N);
  rep(i, N) {
    cin >> B[i];
  }
  sort(all(B));
  if (A[0] > B[0]) A.swap(B);

  vector<pii> es;
  for (int a : A) {
    es.eb(pii(a, -1));
  }

  for (int b : B) {
    es.eb(pii(b, 1));
  }
  sort(all(es));

  int cnt = 0;
  LL ans = 1;
  int sgn = 1;
  for (pii &p : es) {
    int x = p.X;
    int d = p.Y;
    if (d == -1) {
      cnt++;
      if (cnt == 1) sgn = 1;
      if (sgn == 1) {
        ans *= abs(cnt);
        ans %= MOD;
      }
    } else if (d == 1) {
      cnt--;
      if (cnt == -1) sgn = -1;
      if (sgn == -1) {
        ans *= abs(cnt);
        ans %= MOD;
      }
    } else assert(0);
    //cout << x << ", " << d << ", " << cnt << " = " << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3188
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(Number))

  const n = input[0]
  const cards = input[1]
  const total = cards.reduce((a, b) => a + b)
  let min = Number.MAX_SAFE_INTEGER
  let xx = 0
  for (let i = 0; i < n - 1; i++) {
    xx += cards[i] * 2
    const tmp = Math.abs(total - xx)
    min = Math.min(min, tmp)
  }
  console.log(min)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 35652
#include<bits/stdc++.h>
using namespace std;
 
#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define pb push_back
#define fi first
#define se second
 
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int maxm = 3e5 + 10;
const double PI = acos(-1.0);
const int inf = 1e9;
const double eps = 1e-6;

int n;
ll k,a[maxn],b[maxn],c[maxn];

bool check (ll x) {
    ll sum = 0;
    rep(i,1,n) {
        if(c[i] - x >= 0) {
            sum += (c[i] - x + b[i] - 1ll) / b[i];
        }
    }
    if(sum <= k) return true;
    else return false;
}
int main()
{
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    rep(i,1,n) cin >> a[i];
    rep(i,1,n) cin >> b[i];
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    reverse(b + 1, b + 1 + n);
    rep(i,1,n) c[i] = a[i] * b[i];
    ll l = -1, r = 1e12 + 1;
    //cout << l << " " << r << endl;
    while(r - l > 1) {
        ll mid = (l + r) / 2;
        if (check(mid))
        {
            r = mid;
        }
        else l = mid;
         //cout << l << " " << r << endl;
    }
    cout << r << endl;
    return 0;
}


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

int main() {
    int A , B , C;
    cin >> A >> B;
    C = A * B % 2;
    if (C == 0) {
        cout << "No" << endl;
    } 
    else {
        cout << "Yes" << endl;
    }   
}

Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! { n, k, c, s: chars };
    let mut a = vec![0; n];
    let mut i = 0;
    let mut cnt = 0;
    while i < n {
        if s[i] == 'o' {
            cnt += 1;
            a[i] = cnt;
            i += c;
        }
        i += 1;
    }
    if k == cnt {
        let mut i = n;
        let mut b = vec![0; n];
        while i > 0 && cnt > 0 {
            if s[i - 1] == 'o' {
                b[i - 1] = cnt;
                cnt -= 1;
                i = i.saturating_sub(c);
            }
            i = i.saturating_sub(1);
        }
        for i in 0..n {
            if a[i] == b[i] && a[i] > 0 {
                println!("{}", i + 1);
            }
        }
    }
}


Measured memory_bytes: 9724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  string a, b;
  cin >> a >> b;
  if(a.length() > b.length()){
    cout << "GREATER"<< endl;
    return 0;
  } else if(a.length() < b.length()){
    cout << "LESS" << endl;
    return 0;
  }
  rep(i, a.length()){
    if(a[i] > b[i]) {
      cout << "GREATER"<< endl;
      return 0;
    } else if (a[i] < b[i]) {
      cout << "LESS"<< endl;
      return 0;
    }
  }
  cout << "EQUAL" << endl;
}

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

ball = [0 for _ in range(N)]

for i in range(N):
    ball[A[i] - 1] += 1

all = 0
for i in range(N):
    all += ball[i]*(ball[i] - 1)//2


#print("ball", ball)
for k in range(N):
    ans = all
    ball_new = ball[A[k] - 1] - 1
    #ball_new[A[k] - 1] -= 1

    ans -= ball[A[k] - 1]*(ball[A[k] - 1] - 1)//2
    ans += ball_new*(ball_new - 1)//2

    print(ans)

Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,r;
    int ans=0;
    while(cin>>n>>r)
    {
        if(n%(r*2+1))
        {
            ans=n/(r*2+1);
            ans++;
        }
        else ans=n/(r*2+1);
        cout<<ans<<endl;
    }

}


Measured memory_bytes: 256
n,m = map(int,input().split())

s = []
for _ in range(m):
    s.append(list(map(int,input().split())))

p = list(map(int,input().split()))

l = []
ans = 0
for i in range(2**n):
    l = []
    for j in range(n):
            if i & (1<<j):
                l.append(j+1)

    flag = True
    for j in range(m):
        kosu = 0
        for k in l:
            if k in s[j][1:]:
                kosu += 1
        if kosu % 2 != p[j]:
            flag = False
            break

    if flag:
        ans += 1


print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	static public void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0;
		for (int i = 0; i < n; i++) {
			int a = scan.nextInt();
			while (a % 2 == 0) {
				count++;
				a = a / 2;
			}
		}
		scan.close();
		System.out.println(count);
	}
}


Measured memory_bytes: 36100
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int now = 0;
    int ans = 1;
  for(int i = 0; i < N-1; i++) {
    if(now == 0) {
      if(a[i] > a[i+1]) now = 1;
      else if(a[i] < a[i+1]) now = 2;
    }
    else if(now == 1 && a[i] < a[i+1]) {now = 0; ans++;}
    else if(now == 2 && a[i] > a[i+1]) {now = 0; ans++;}
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 640
# 2020/01/12

n,m=map(int,input().split())
ps=[0]*(n+1)
ac=0
wa=0

for i in range(m):
    p,s=input().split()
    p=int(p)
    if ps[p]>0:continue
    if s=='WA':
        ps[p]-=1
    else:
        wa+=-ps[p]
        ps[p]=1
        ac+=1
print(*[ac,wa])

Measured memory_bytes: 3828
a = gets.chomp!.to_i

class Fibonacci
  def exec(n)
    f = { 0 => 1, 1 => 1 }

    2.upto(n) do |i|
      f[i] = f[i-1] + f[i-2]
    end

    return f[n]
  end
end

puts Fibonacci.new.exec(a)



Measured memory_bytes: 6860
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	ll k = abs(a-b);
	if(k%2 == 0){
		cout << k/2 << endl;
	}else{
//		ll ans0 = min(b-1, n-a); 
		ll ans0 = (n-b+1+n-a)/2;
		ll ans1 = (a-1+1+b-1)/2;
		cout << min(ans0, ans1) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fd(i,b,a) for(int i=b;i>=a;--i)
#define efo(i,v,u) for(int i=BB[v],u=B[BB[v]][1];i;i=B[i][0],u=B[i][1])
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || ch>'9';ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=17,M=32770,mo=1e9+7;
int n,m,_2[N],B0,BB[N],in[N],B[N*N][2],map[N][N];
void link(int u,int v){++in[v],map[u][v]=1,B[++B0][1]=v,B[B0][0]=BB[u],BB[u]=B0;}
ll f[M],h[N][M];
void upd(ll &x,ll y){x=(x+y)%mo;}
ll qmi(ll x,ll n)
{
	ll t=1;
	for(;n;n>>=1,x=x*x%mo) if(n&1) t=t*x%mo;
	return t;
}
int main()
{
	int x,y;
	n=read(),m=read();
	_2[0]=1;fo(i,1,n) _2[i]=_2[i-1]<<1;
	fo(i,1,m) x=read(),y=read(),link(x,y);
	fo(i,1,n)
		fo(s,0,_2[n]-1)
		{
			fo(j,1,n) if(s&_2[j-1]) upd(h[i][s],map[i][j]);
			h[i][s]=qmi(2,h[i][s]);
		}
	f[0]=1;
	fo(s,1,_2[n]-1) if(!(((s&1)>0)^((s&2)>0)))
	{
		for(int W=(s-1)&s;W>=0;W=(W-1)&s) if(!(((W&1)>0)^((W&2)>0)))
		{
			int L=s^W;
			ll t=1;
			fo(i,1,n) if(L&_2[i-1]) t=t*h[i][W]%mo;
			fo(i,1,n) if(W&_2[i-1]) t=t*(h[i][L]-1+mo)%mo;
			t=t*f[W]%mo;
			upd(f[s],t);
			if(!W) break;
		}
	}
	printf("%lld",(qmi(2,m)-f[_2[n]-1]+mo)%mo);
	return 0;
}

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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  int a[50]={};
  int waya,wayb;
  for(int i=0;i<m;i++){
    cin >> waya >> wayb;
    a[waya]++;
    a[wayb]++;
  }
  for(int i=1;i<=n;i++){
    cout << a[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const ll INF = 1e16;

void solver(int N, int M, vector<int> &X, int &ans){

    sort(X.begin(), X.end());

    vector<int> dif_vec;
    for(int i = 0; i != M-1; ++i){
        int dif = X.at(i+1) - X.at(i);
        dif_vec.push_back(dif);
    }

    sort(dif_vec.begin(), dif_vec.end());

    for(int i = 0; i != N-1; ++i){
        if(dif_vec.size()) dif_vec.pop_back();
    }

    int ans_buf{};
    for(size_t i = 0; i != dif_vec.size(); ++i){
        ans_buf += dif_vec.at(i);
    }

    ans = ans_buf;

    return;
}

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for(int i = 0; i != M; ++i) cin >> X.at(i);

    int ans;
    solver(N, M, X, ans);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4268
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int n; cin >> n;
  vector<int> vec(n);
  for(auto& v : vec) {
    cin >> v;
  }

  int cnt = 0;
  while(1) {
    for(auto& v : vec) {
      if(v % 2 != 0) {
        cout << cnt << endl;
        exit(0);
      }
      v /= 2;
    }
    cnt++;
  }
}


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

#define ll long long int
#define ff(i,a,b) for(ll i = a; i < b; i++)
#define bf(i,b,a) for(ll i = b-1; i >= a; i--)
#define itf(i,a) for(auto i = a.begin(); i != a.end(); i++)
#define itfr(i,a) for(auto i = a.rbegin(); i != a.rend(); i++)
#define MII map<ll,ll> 
#define MCI map<char,ll>
#define MSI map<string,ll>
#define VI vector<ll> 
#define VC vector<char> 
#define VS vector<string> 
#define MP make_pair
#define tc ll t; cin>>t; while(t--)
#define DISPV(v) itf(i,v) cout << *i << ' ';
#define DISPM(m) itf(i,m) cout << i->first << ' ' << i->second << endl;

const int MOD = int(1e9) + 7;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin >> n;
    MSI m;
    while(n--){
        string s;
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << '\n';
    cout << "WA x " << m["WA"] << '\n';
    cout << "TLE x " << m["TLE"] << '\n';
    cout << "RE x " << m["RE"] << '\n';
}

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

const int DIM = 1e5 + 5;

int prm[DIM];

int main(void) {
    ios::sync_with_stdio(false);
    
    int n, ans = 0;
    cin >> n;
    
    for (int i = 1; i <= n; ++i)
        cin >> prm[i];
    
    for (int i = 1, j = 1; i <= n; i = ++j) {
        if (prm[i] != i)
            continue;
        
        while (j < n and prm[j + 1] == j + 1)
            ++j;
        
        ans = ans + (j - i + 2) / 2;
    }
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define LL               long long int
#define PB               push_back
using namespace std;

bool sortbysec(const pair<LL,LL> &a, const pair<LL,LL> &b) 
{ 
    return (a.second < b.second); 
} 





int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    LL x,y,n; cin>>n;
    vector <pair<LL,LL>> v,w;
    for (LL i=0;i<n;i++){
        cin>>x>>y;
        v.PB(make_pair(x,y));
        // v.PB(x); w.PB(y);
    }
    LL mn=LONG_LONG_MAX,mx=LONG_LONG_MIN;
    for (int i=0;i<n;i++){
        if (v[i].first+v[i].second<mn)mn=v[i].first+v[i].second;
        if(v[i].first+v[i].second>mx) mx=v[i].first+v[i].second;
    }
    LL f=abs(mn-mx);
    mn=LONG_LONG_MAX,mx=LONG_LONG_MIN;
    for (int i=0;i<n;i++){
        if (v[i].first-v[i].second<mn)mn=v[i].first-v[i].second;
        if(v[i].first-v[i].second>mx) mx=v[i].first-v[i].second;
    }
    LL s=abs(mn-mx);
    
    // cout<<abs(mn-mx);
//     LL f,s;
//     sort(v.begin(),v.end());
//     f=abs(v[n-1].first-v[0].first) + abs(v[0].second-v[n-1].second);
//    /// for(auto i:v) cout<<i.first<<" "<<i.second<<"\n";

//     sort(v.begin(),v.end(),sortbysec);
//     s=abs(v[n-1].first-v[0].first) + abs(v[0].second-v[n-1].second);
//     LL ans= max(f,s);
//     ans=max(ans,abs(mn-mx));
    LL ans=max(f,s);
    cout<<ans;

//    for(auto i:v) cout<<i.first<<" "<<i.second<<"\n";
}

Measured memory_bytes: 7416
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		for (;;) {

			int m = sc.nextInt();

			int c = sc.nextInt();

			if((m|c)==0)break;

			int j = 0;

			boolean[] visited = new boolean[m];

			int count = 0;

			int e=0;

			for (int i = 0;count < m; i++, i=i<m?i:0) {

				if (visited[i])

					continue;

				j++;

				if (j == c) {

					visited[i] = true;

					count++;

					j = 0;

					e=i;

				}

			}

			System.out.println(e+1);

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

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


n = int(input())
from collections import defaultdict
ns = defaultdict(set)
for i in range(n-1):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add((c,v))
    ns[v].add((c,u))
# print(ns)
k = len(bin(n-1))-2
# 深さ
def cdepth(root=0):
    # rootを根としたときの深さ
    ps = [None] * n
    ps[0] = -1
    q = [0]
    while q:
        u = q.pop()
        for c,v in ns[u]:
            if ps[v] is None:
                ps[v] = u
                q.append(v)
    # psを元から持っている場合、引数のnsをpsにしてこの下だけで良い
    depth = [None] * n
    depth[root] = 0
    q = [root]
    while q:
        u = q.pop()
        for c,v in ns[u]:
            if depth[v] is None:
                depth[v] = depth[u] + 1
                q.append(v)
    return depth, ps
def dijkstra(start):
    import heapq
    vals = [None] * n
    h = [(0, start)] # (距離, ノード番号)
    vals[start] = 0
    while h:
        val, u = heapq.heappop(h)
        for d, v in ns[u]:
            if vals[v] is None or vals[v]>val+d:
                vals[v] = val+d
                heapq.heappush(h, (vals[v], v))
    return vals

# ダブリング
def double(ps):
    # global: n=psのサイズ
    k = 0
    while pow(2,k)<n:
        k += 1
    prev = [[None]*n for _ in range(k)] # ノードjから2^i個上の上司
    for j in range(n):
        prev[0][j] = ps[j]
    for i in range(1,k):
        for j in range(n):
            p = prev[i-1][j]
            if p>=0:
                prev[i][j] = prev[i-1][p]
            else:
                prev[i][j] = p
    return prev
            

# k: 必要桁数を定める必要アリ
def cprev(u,i):
    """uからi個上の頂点を返す
    """
    for j in range(k):
        if i>>j&1:
            u = prev[j][u]
    return u

# k: 必要桁数を定める必要アリ
def lca(u,v):
    if depth[u]<depth[v]:
        v = cprev(v, depth[v]-depth[u])
    else:
        u = cprev(u, depth[u]-depth[v])
    if u==v:
        return u
    for i in range(k-1, -1, -1):
        if prev[i][u]!=prev[i][v]:
            u = prev[i][u]
            v = prev[i][v]
    return prev[0][u]

dist = dijkstra(0)
depth, ps = cdepth(0)
prev = double(ps)
q,K = map(int, input().split())
K -= 1
ans = [None]*q
for i in range(q):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    l1 = lca(x,K)
    l2 = lca(y,K)
#     print(x,y,l1,l2)
    ans[i] = (dist[x]+dist[K]-2*dist[l1]) + (dist[y]+dist[K]-2*dist[l2])
write("\n".join(map(str, ans)))

Measured memory_bytes: 164968
#include <iostream>
#include <cstdio>

//#define PI 3.141592653589

using namespace std;



int main()
{
	int H, W;
	
	while (1)
	{
		cin >> H >> W;
		if (H==0 && W==0) return 0;
		
		for (int i=0; i<H; i++)
		{
			for (int j=0; j<W; j++)
			{
				if (i%2 == 1)
				{
					if (j%2 == 1)
						cout << "#";
					else
						cout << ".";
				} else {
					if (j%2 == 1)
						cout << ".";
					else
						cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]


c = Counter(A)

ans = 0
for i in c:
    ans += c[i] * (c[i] - 1) // 2

for i in range(len(A)):
    if c[A[i]] == 1:
        print(ans)
    else:
        tmp = c[A[i]]
        print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)


Measured memory_bytes: 34016
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ve apples;
    for (ll i = 0; i < a; ++i)
    {
        ll yo;
        cin>>yo;
        apples.pb(yo);
    }
    ve nowhere;
    ve gr;
    for (ll i = 0; i < b; ++i)
    {
        ll ko;
        cin>>ko;
        gr.pb(ko);
    }

    sort(all(gr));
    reverse(all(gr));

    for (ll i = 0; i < y; ++i)
    {
        nowhere.pb(gr[i]);
    }
    for (ll i = 0; i < c; ++i)
    {
        ll co;
        cin>>co;
        nowhere.pb(co);
    }
    
    sort(all(apples));
    reverse(all(apples));
    sort(all(nowhere));
    reverse(all(nowhere));
    ve ki = nowhere;
    nowhere.clear();
    for (int i = 0; i < min((ll)(ki.size()),x+y); ++i)
    {
       nowhere.pb(ki[i]);
    }
    ll cum=0;
    ve cumi;
    for (ll i = 0; i < x; ++i)
    {
        cum+=apples[i];
        cumi.pb(cum);
    }

    cum=0;
    ve cumi1;
    for (ll i = 0; i < nowhere.size(); ++i)
    {
        cum+=nowhere[i];
        cumi1.pb(cum);
    }

    ll ans=0;
    for (ll i = 0; i < x; ++i)
    {
        ll beki=(x-i);
        beki+=y;
        if(beki>nowhere.size())continue;
        ans=max(ans,cumi[i]+cumi1[beki-2]);
    }
    if((x+y)<=cumi1.size())ans=max(ans,cumi1[x+y-1]);
    cout<<ans;
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 8944
/***/





#include<bits/stdc++.h>

using namespace std;

#define fstinpt     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll          long long
#define bn          1000090
#define sn          1010
#define mod         100000007
#define iii(i)      cin>>i
#define ooo(i)      cout<<i
#define sss         cout<<" "
#define nnn         cout<<"\n"/**
#define iii(i)      iii>>i
#define ooo(i)      ooo<<i
#define sss         ooo<<" "
#define nnn         ooo<<"\n"*/
#define ff          first
#define ss          second
#define psb         push_back

/**
        ifstream iii;iii.open("D:\\prgrms\\codechef cntst 1\\input.txt");
        ofstream ooo;ooo.open("D:\\prgrms\\codechef cntst 1\\my output.txt");
         nnn; ooo("sp = "<<sp); nnn;
*/

ll a[2000];

int main()
{
	ll n,k;
	iii(n>>k);
	for(ll i = 1; i <= n; i++) iii(a[i]);
	sort(a+1,a+n+1); a[0] = 0;
	for(ll i = 1; i <= k; i++) a[i] += a[i-1];
	ooo(a[k]);nnn;
        return 0;
}




/**




*/















/***/


Measured memory_bytes: 3588
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
using vi = vector<int>;

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

    int W, a, b;
    cin >> W >> a >> b;

    int c = a+W;
    int d = b+W;

    if (c < b || d < a) {
        outl( max(0, min({abs(a-b), abs(a-d), abs(c-b), abs(c-d)}) ));
    } else {
        outl(0);
    }
}



Measured memory_bytes: 256
#!/usr/bin/env python3

import itertools


def count_trailing_zeros(n):
    if n % 2 == 1:
        return 0
    else:
        res = 0
        for i in itertools.count(1):
            p = 5 ** i
            if p > n:
                break
            res += n // (2 * p)
        return res


def main():
    n = int(input())
    res = count_trailing_zeros(n)
    print(res)


if __name__ == "__main__":
    main()


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 a, b, c;
    cin >> a >> b >> c;

    i64 ans = 0;
    i64 d = min(b, c);
    ans += d + b, c -= d;
    i64 e = min(a, c);
    ans += e + (c > e);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

void itoa(int x, int radix, char* dst) {
  char buf[16] = {};
  char *p = buf + 14;
  int sign = 0;
  
  if (x < 0) {
    x = -x;
    sign = 1;
  }
  
  do {
    *p = "01235789abcdefghijklmnopqrstuvwxyz"[x % radix];
    --p;
    x /= radix;
  } while (x > 0);
  
  if (sign) {
    *p = '-';
    --p;
  }
  strcpy(dst, p + 1);
}

int main(void)
{
  char str[64];
  int n;
  while (scanf("%d", &n), n) {
    itoa(n, 8, str);
    printf("%s\n", str);
  }

  return (0);
}

Measured memory_bytes: 592
main=do
 getLine
 aa<-map read.words<$>getLine
 let a=0:(aa++[0])
 let b=zipWith f a$tail a
 let s=sum b
 let c=zipWith(+)b$tail b
 let d=zipWith f a$tail$tail a
 putStr$unlines$map show[s+x-y|(x,y)<-zip d c]
f x y=abs$x-y

Measured memory_bytes: 36220
n, m = map(int, input().split())
shop = [0 for i in range(n)]
for i in range(n):
    shop[i] = list(map(int, input().split()))
shop = sorted(shop)
can = 0
cost = 0
while 1:
    for i in range(n):
        if shop[i][1] < m:
            can += shop[i][1]
            cost += shop[i][0]*shop[i][1]
            m -= shop[i][1]
        else:
            cost += shop[i][0]*m
            break
    break
print(cost)

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

typedef signed long long ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()

#define DEBUG

int main()
{
	int n, s;
	int ans = 0;
	vector<int> p;

	cin >> n;
	rep(i,n)
	{
		cin >> s;
		p.push_back(s);
	}

	for(int i = 1; i < n - 1; i++)
	{
		if(p[i-1] < p[i] && p[i] < p[i+1])
		{
			ans++;
		}
		if(p[i-1] > p[i] && p[i] > p[i+1])
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200009
#define ll long long
using namespace std;
long double x[10],y[10];
int vis[10],n;
vector<long double>v;
void bt(long double cur,int pas)
{
    bool o=0;
    for(int i=0;i<n;i++)
    {
        if(vis[i])continue;
        o=1;
        vis[i]=1;
        long double form=sqrt((x[pas]-x[i])*(x[pas]-x[i])+(y[pas]-y[i])*(y[pas]-y[i]));
        bt(cur+form,i);
        vis[i]=0;
    }
    if(o==0)v.push_back(cur);
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i];
    for(int i=0;i<n;i++)
    {
        vis[i]=1;
        bt(0,i);
        vis[i]=0;
    }
    long double sum=0;
    for(int i=0;i<v.size();i++)sum+=v[i];
    long double div=1;
    for(int i=2;i<=n;i++)div*=i;
    cout<<setprecision(10)<<fixed<<sum/div;
}


Measured memory_bytes: 1400
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define YES "Yes"
#define NO "No"

int n;
int a[100000];

int main(int argc, char **argv) {
	cin >> n;
	int ma = 0, mi = n - 1;
	REP(i, n) {
		cin >> a[i];
		ma = max(ma, a[i]);
		mi = min(mi, a[i]);
	}
	if (ma != mi && ma != mi + 1) {
		cout << NO << endl;
		return 0;
	}
	if (ma != mi) {
		int mac = 0, mic = 0;
		REP(i, n) if (a[i] == ma) ++mac; else ++mic;
		cout << (mic <= mi && mac >= (ma - mic) * 2 ? YES : NO) << endl;
		return 0;
	}
	cout << (n >= mi * 2 || n == mi + 1 ? YES : NO) << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){ return a/gcd(a, b)*b; };
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end());
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, n);
    Cins(ll, n, a);
    
    ll ans = 1e16;
    for(bool f : {true, false}){
        Cusum(ll, n, a, sa);
        ll an = 0, d = 0;
        For(i, n){
            if(f){
                if(sa[i+1]+d < 1){
                    ll k = 1 - (sa[i+1]+d);
                    an += k, d += k;
                }
            }
            else{
                if(sa[i+1]+d > -1){
                    ll k = 1 + (sa[i+1]+d);
                    an += k, d -= k;
                }
            }
            f ^= true;
        }
        ans = min(ans, an);
    }
    Cout(ans);
}


Measured memory_bytes: 1804
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u32,
        b: u32,
        t: u32,
    }
    println!("{}", t / a * b);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

int main(void) {
    string S;
    cin >> S;
    int L = S.size();
    string ans = "AC";
    if (S[0] != 'A') {
        ans = "WA";
    }
    int cnt = 0;
    for (int i = 1; i < L; ++i) {
        if (isupper(S[i])) {
             if (i == 1 || i == L - 1 || S[i] != 'C') {
                 ans = "WA";
            }
            ++cnt;
        }
    }
    if (cnt != 1) {
        ans = "WA";
    }cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, a, b;
int main(void) {
    std::ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    while(cin >> n >> a >> b) {
        ll sum = 0;
        for(int i = 1; i <= n; ++i) {
            int ans = 0, t = i;
            while(t) {
                ans += t % 10;
                t /= 10;
            }
            if(ans >= a && ans <= b) sum += i;
        }
        cout << sum << endl;
    }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

//#define int long long

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int a, b;
    scanf("%d%d", &a, &b);

    if (a == b) {
        printf("%d", a * 2);
    } else if (a > b) {
        printf("%d", a * 2 - 1);
    } else if (b > a) {
        printf("%d", b * 2 - 1);
    }

    /* --------------------------------- */
    printf("\n");
    return 0;
}

Measured memory_bytes: 256