akhauriyash/Code-Regression huggingface dataset:
int main(void){
    int A,B,i,coin=0;
    scanf("%d",&A);
    scanf("%d",&B); 
    for(i=0;i<2;i++){  
    if(A<B){
            coin += B;
            B--;
            }
    else if(A>B){
            coin += A;
            A--;
            }
    else{coin += A;
            A--;}
    }
    printf("%d",coin);
}

Measured memory_bytes: 128
n = int(input())

l = []


for i in range(n):
    s = list(input().split())
    l.append(s)

for i in range(n):
    l[i].append(i+1)
    
l.sort()
s = [0,0,0]
l.append(s)

i = 0

while i != n:
    if l[i][0] == l[i+1][0]:
        if int(l[i][1]) < int(l[i+1][1]):
            l[i][1], l[i+1][1] = l[i+1][1], l[i][1]
            l[i][2], l[i+1][2] = l[i+1][2], l[i][2]
            i = -1
    i += 1

for i in range(n):
    print(l[i][2])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
lol u[111111];
lol ii[121111];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0,can;
  string s;
  cin >>a>>b;
  a=a%500;
  if(a>b) cout <<"No\n";
  else cout <<"Yes\n";
  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

class button_data
{
    public:
    long long int n;
    bool flag;
};

int main()
{
    int n;
    cin >> n;
    vector<button_data> v(n);
    for(int i=0;i < n;i ++)
    {
        cin >> v[i].n;
        v[i].flag = false;
    }

    int idx = 0;
    int count = 1;
    while(true)
    {

        if(v[idx].n == 2)
        {
            cout << count << endl;
            break;
        }
        else if(v[idx].flag)
        {
            cout << -1 << endl;
            break;
        }

        v[idx].flag = true;
        idx = v[idx].n-1;
        count ++;
    }
}

Measured memory_bytes: 1792
fun main(args: Array<String>) = println(run {
    val(n,m) = readLine()!!.split(" ").map { it.toInt() }
    val ab = (1..n).map { readLine()!!.split(" ").map { it.toLong() } }.sortedBy { it[0] }

    var price = 0L
    var count = 0L
    for (i in 0..n-1) {
        val (a, b) = ab[i]
        val purchase = Math.min(b, m-count)
        count += purchase
        price += a * purchase
        if(count == m.toLong()) return@run price
    }
    price
})

Measured memory_bytes: 85508
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import itertools
n=int(input())


r=0
k=len(str(n))
for j in range(3,k+1):
  l=('3', '5', '7' )
  for i in itertools.product(l, repeat=j):
    if not ( '3' in i and '5' in i and '7' in i):
      continue
    x=int(''.join(map(str,i)))
    if x > n:
      break
    r=r+1
print(r)




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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto &a : v) cin>>a;
    int mi = inf;
    for(int p=1;p<=100;++p){
        int sum = 0;
        for(auto a : v){
            sum += abs(a-p)*abs(a-p);
        }
        mi = min(mi,sum);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int h,w;
int i,j;
while(1){
scanf("%d %d", &h, &w);
if(h==0&&w==0)break;
for(i=0;i<h;i++){
for(j=0;j<w;j++){ if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){ printf("#");
}
else{ printf(".");
}
}
printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2608
#include<iostream>
using namespace std;
	
int link[4][4];
int used[4];
bool dfs(int p){
	used[p]=1;
	bool flag=true;
	for(int i=0;i<4;i++) if(used[i]==0) flag=false;
	if(flag) {
		return true;
		used[p]=0;
	}
	bool res=false;
	for(int i=0;i<4;i++){
		if(used[i] || i==p) continue;
		if(link[p][i]) res=dfs(i);
	}
	used[p]=0;
	return res;
}

int main(){
	for(int i=0;i<3;i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		link[a][b]=1;
		link[b][a]=1;
	}
	bool flag=true;
	for(int i=0;i<4;i++) if(dfs(i)){cout << "YES" << endl;return 0;}
	cout << "NO" << endl;
	return 0;
}


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

// definitions
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define pb push_back
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256

using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dq;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;


// standard functions
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 


ll modexp(ll x, ll ex, ll modp) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%modp;
        ex >>= 1ll;
        x = (x * x)%modp;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

// code beigns in main
int main()
{
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll a;
        cin >> a;
        
        ll n1=a/500;
        a-=n1*500;
        
        ll n2=a/5;
        
        cout << n1*1000+n2*5 << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var H = long.Parse(Console.ReadLine());

            var monsters = (long)1;
            var answer = (long)monsters;
            while (H > 1)
            {
                H /= 2;
                monsters *= 2;
                answer += monsters;
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13140
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B
import qualified Data.Array.IArray as A
import qualified Data.IntMap.Strict as M
import Control.Monad

readIntPair :: B.ByteString -> [(Int, Int)]
readIntPair = map (pair . map readInt . B.words) . B.lines

pair :: [t] -> (t, t)
pair [x, y] = (x, y)
pair _ = undefined

main = do
  n <- readLn
  es <- readUndirectedEdge <$> replicateM (n-1) B.getLine
  [q,k] <- map read . words <$> getLine
  xys <- readIntPair <$> B.getContents
  let g = buildG (1,n) es
  let m = dijkstra g k
  putStrLn $ unwords $ map (show . transit m) xys

transit m (x,y) = fst (m M.! x) + fst (m M.! y)  

type Bound = (Vertex, Vertex)
type Vertex = Int
type Weight = Int
type Edge = ((Vertex, Vertex), Weight)
type Path = [Vertex]
type Graph = A.Array Vertex (S.Set (Vertex, Weight))

buildG :: Bound -> [Edge] -> Graph
buildG b = A.accumArray (flip S.insert) S.empty b . map (\((s, t), w) -> (s, (t, w)))

from :: Graph -> Vertex -> S.Set (Vertex, Weight)
from = (A.!)

size :: Graph -> Int
size g = let (i,j) = A.bounds g in j - i + 1

readUndirectedEdge :: [B.ByteString] -> [Edge]
readUndirectedEdge = concatMap (constructTwoWay . map readInt . B.words)

constructTwoWay :: [Int] -> [Edge]
constructTwoWay [s,t,w] = [((s, t), w), ((t, s), w)]
constructTwoWay _ = undefined

readInt :: B.ByteString -> Int
readInt = maybe undefined fst . B.readInt

type Memo = M.IntMap (Weight, Path)

-- accumrated weight and lexical order shortest path
dijkstra :: Graph -> Vertex -> Memo
dijkstra g s = _dijkstra g q0 m0
  where
   q0 = singleton (0, s)
   m0 = M.singleton s (0, [])

_dijkstra :: Graph -> PriorityQueue -> Memo -> Memo
_dijkstra g q m
  | isEmpty q = m
  | otherwise = _dijkstra g q2 m1
  where
    ((w0, s), q1) = deleteFindMin q
    p = s : snd (m M.! s)
    m1 = S.foldr (\(t, w) acc -> M.insertWith min t (w0 + w, p) acc) m vns
    q2 = S.foldr (\(t, w) acc -> insert (w0 + w, t) acc) q1 vns
    vns = S.filter (\(t, w) -> M.notMember t m || w0 + w <= fst (m M.! t)) (from g s)

type PriorityQueue = S.Set (Weight, Vertex)

isEmpty :: PriorityQueue -> Bool
isEmpty = S.null

singleton :: (Weight, Vertex) -> PriorityQueue
singleton = S.singleton

insert :: (Weight, Vertex) -> PriorityQueue -> PriorityQueue
insert = S.insert

deleteFindMin :: PriorityQueue -> ((Weight, Vertex), PriorityQueue)
deleteFindMin = S.deleteFindMin


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/02  Problem: Nagoya_univ_contest16_b  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;
LL t[102];
LL ans = 0LL;

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; }


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

	cin >> N;
	ans = 1;
	FOR(i, 0, N) {
		cin >> t[i];
	}
	ans = lcm(ans, t[0]);
	FOR(i, 1, N) {
		ans = lcm(ans, t[i]);
	}


	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
	int n;
	string s;
	cin >> n >> s;
	if (n % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < n/2; i++) {
		if (s[i] != s[i + n / 2]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}



int main(void){
    int k,a,b;
    cin >> k >> a >> b;
    bool flag = false;

    for(int i=a;i<=b;++i){
        if(i%k==0){
            flag  = true;
        }
    }
    if(flag){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
  
int main()
{
  int n;
  cin>>n;
  while(n!=0)
  {
    if(n%10==7)
    {
      cout<<"Yes";
      break;
    }
    n=n/10;
    
  }
  if(n==0)
  {
    cout<<"No";
  }
  
  return 0;

  
}


Measured memory_bytes: 3672
// seabreeeze //
 
#include<bits/stdc++.h>
 
using namespace std;
 
#define lli unsigned long long
lli MOD=1e9+7;
 
#define MAXN 2000006 
 
// Template function //
lli powermod(lli x, lli y)  
{  
    lli res = 1;  
    x = x % MOD;
    if (x == 0) return 0;  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % MOD;  
        y = y>>1;   
        x = (x*x) % MOD;  
    }  
    return res;  
}
lli modinv(lli x)
{
    return powermod(x,MOD-2);
}
// Template functions end //
 
// Custom funtions //
void preprocess()
{

}

int mex(int a[],int n)
{
    vector<int> c(n+1,0);
    for(int i=0;i<n;i++)
    {
        c[a[i]]=1;
    }
    for(int i=0;i<n+1;i++)
    {
        if(c[i]==0)
        return i;
    }
    return 0;
}
 
// Custom functions end //
 
int main()
{
    lli q=1;
    // cin>>q;
    time_t start, end;
    time(&start);
    preprocess();
    for(lli tc=1;tc<=q;tc++)
    {
        // Start solution //
        lli n;
        cin>>n;
        string s[]  = {"AC","WA","TLE","RE"};
        string t;
        int a[4]={0};
        for(int i=0;i<n;i++)
        {
            cin>>t;
            for(int j=0;j<4;j++)
            {
                if(t==s[j])
                a[j]++;
            }
        }
        for(int i=0;i<4;i++)
        {
            cout<<s[i]<<" x "<<a[i]<<endl;
        }
        // End Solution //
        end:;
    }
    
    time(&end);
    // cout<<fixed<<double(end - start)<<setprecision(10)<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <atcoder/all>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
using namespace atcoder;
typedef long long ll;

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

    int n, q;
    cin >> n >> q;
    dsu d(n);
    rep(i, q){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0){
            d.merge(u, v);
        }
        else{
            if(d.same(u, v)) puts("1");
            else puts("0");
        }
    }
    
    return 0;
}

Measured memory_bytes: 3856
#include <algorithm>
#include<string>
#include<iostream>
using namespace std;
int main() {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int u=0;
    int d=0;
    int su=0;
    if(n==1){
        cout << 0;
        return 0;
    }else{
        for(int i=0;i<n-1;++i){
            if(s[i]==s[i+1]){
                su+=1;
            }else{
                if(s[i]=='L' && s[i+1]=='R'){
                    u+=1;
                }
                if(s[i]=='R' && s[i+1]=='L'){
                    d+=1;
                }
            }
        }
    }
    int c1=0;
    if(d-u<0){
        if(s[0]=='L'){
            c1+=1;
        }
        if(s[n-1]=='R'){
            c1+=1;
        }
        if(k>min(min(u,d),k)){
            su+=min(min(c1,k-min(min(u,d),k)),u-d);
        }
    }
    int c2=0;
    if(d-u>0){
        if(s[0]=='R'){
            c2+=1;
        }
        if(s[n-1]=='L'){
            c2+=1;
        }
        if(k>min(min(u,d),k)){
            su+=min(min(c2,k-min(min(u,d),k)),d-u);
        }
    }
    cout << su+2*min(min(u,d),k);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(void)
{
	int H, W, A, B;  cin >> H >> W >> A >> B;
	string X(A, '1'), Y(A, '0');
	rep(i, 0, W - A) {
		X.push_back('0');
		Y.push_back('1');
	}

	rep(i, 0, B)cout << X << endl;
	rep(i, 0, H - B)cout << Y << endl;

	return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


#define MAX 5100000
#define MOD 1000000007

//fac: 階乗、finv: 階乗の逆元(invの積)、inv: ある数の逆元(フェルマーの小定理より)
ll fac[MAX], finv[MAX], inv[MAX];

//テーブルを作る前処理
void combModInit() {
    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 comb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll X, Y;
    cin >> X >> Y;

    combModInit();

    if(Y > 2 * X || 2 * Y < X || (X + Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll moves = (X + Y) / 3;
    ll up = X - moves;
    ll ans = comb(moves, up);

    cout << ans << endl;

    return 0;
}




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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    ll sum = 0;
    ll a = 0;
    vector<string> s(n);
    vector<ll> t(n);
    for(i = 0;i < n;++i){
        cin >> s.at(i) >> t.at(i);
        a += t.at(i);
    }
    string x;
    cin >> x;
    for(i = 0;i < n;++i){
        sum += t.at(i);
        if(s.at(i) == x) break;
    }
    cout << a - sum << endl;


    return 0;
}

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

using namespace std;

#define int long long

int n,k;
int a[200001];
int f[200001];
int b[200001];

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

	cin >> n >> k;
	for (int i=1;i<=n;i++)
		cin >> a[i];
	for (int i=1;i<=n;i++)
		cin >> f[i];
	sort(a+1,a+1+n);	
	sort(f+1,f+1+n);
	int l = 0;
	int r = 1e12;
	int res = 1e12;
	while(l <= r)
	{
		int mi = (l+r)/2;
		for (int i=1;i<=n;i++)
			b[i] = mi / f[i];
		int cur = 0;
		for (int i=1;i<=n;i++)
		{
			if (a[n+1-i] <= b[i])
				continue;
			cur += a[n+1-i] - b[i];
		}
		if (cur > k)
			l = mi + 1;
		else
		{
			res = mi;
			r = mi - 1;
		} 	
	}
	cout << res;		
}

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

int main() {
int a,b,c;
    cin >> a >> b >> c;
    int d = a*100 + b*10 + c;

    if (d%4 == 0){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    }

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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILL(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};

ll binary_search(vector<int> &v,int n){
  int left = -1,right = (int)v.size();
  while(right - left > 1){
    int mid = (left+right)/2;
    if(v[mid] >= n)right = mid;
    else left = mid;
  }
  return right;
}
ll binary_searchD(vector<int> &v,int n){
  int left = -1,right = (int)v.size();
  while(right - left > 1){
    int mid = (left+right)/2;
    if(v[mid] > n)right = mid;
    else left = mid;
  }
  return left;
}

int main(){
  
  int n;
  ll res = 0;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  REP(i,n)cin >> a[i];
  REP(i,n)cin >> b[i];
  REP(i,n)cin >> c[i];
  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));
  REP(i,n){
    ll down = binary_search(c,b[i]+1);
    if(down == n)continue;
    ll up = binary_searchD(a,b[i]-1);
    if(up == -1)continue;
    res += (n - down)*(up + 1);
  }
  cout << res;
  

  return 0;
}


Measured memory_bytes: 1536
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
#define int long long
	int n;
	cin >> n;
	int now_time = 0;
	int now_x = 0;
	int now_y = 0;
	REP(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		int req = abs(b - now_x) + abs(c - now_y);
		if (req+now_time <= a&&(a-now_time-req) % 2 == 0) {
			now_x = b;
			now_y = c;
			now_time = a;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
	
	static int n;
	static int[] a;
	
	static boolean solve(int i,int x) {
		if(x == 0) {
			return true;
		}else if(i >= n) {
			return false;
		}
		boolean res = solve(i+1,x) || solve(i+1,x-a[i]);
		return res;
	}
	
	static void judge(int x) {
		if(solve(0,x)) {
			System.out.println("yes");
		}else {
			System.out.println("no");
		}
	}
	
	void main() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int[] m = new int[q];
		for(int i=0;i<q;i++) {
			m[i] = sc.nextInt();
		}
		
		for(int i=0;i<q;i++) {
			judge(m[i]);
		}
	}

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

}



Measured memory_bytes: 27108
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++) 
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;


void solve()
{
  int n,i,x,k=0,l;
  cin>>n;
  vi a,b;
  rep(i,n){
    cin>>x>>l;
    a.pb(x);
    b.pb(l);
  }
  rep(i,n){
    if(a[i]==b[i])
      k++;
    else
      k=0;
    if(k==3){
      cout<<"Yes"<<endl;
      return;
    }
  }
  cout<<"No"<<endl;
}
int  main() 
{
  auto start=clock();
  fast_io;
    int t=1;
    //cin>>t;
    while(t--){
      solve();
    }
    auto stop =clock();
    cerr<<"time taken:"<<double(stop-start)/double(CLOCKS_PER_SEC)<<" s"<<endl;
  return 0; 
}


Measured memory_bytes: 3840
using System;

public class p1045{
	private int n;
	
	p1045 ()
	{
		string str;
		string[] st;
		
		while ((str=Console.ReadLine())!=null && str != "0") {
			n = int.Parse (str);
			st = (Console.ReadLine ()).Split (' ');
			Console.WriteLine ("{0}", solve(st, 0, 0, 0));
		}
	}
	
	int solve (string[] st, int p, int s, int t)
	{
		if (p == n)
			return Math.Abs (s-t);
		
		
		return Math.Min (solve (st, p+1, s+int.Parse(st[p]), t), solve (st, p+1, s, t+int.Parse(st[p])));
	}
	
	public static int Main(string[] args){
		new p1045();
		return 0;
	}
}

Measured memory_bytes: 5660
#include <iostream>

using namespace std;

int main()
{
string s;
cin>>s;
int a=0 , b=0 , c=0 ;
if (s[0] == 'A'){
    a=1;
}
for (int i = 2 ; i < s.size()-1 ; i++){
    if (s[i]=='C')
        b++;
}
for (int i=0 ;i <s.size(); i++){
    if(isupper(s[i])){
        c++;
    }
}
if(a==1 && b==1 && c==2)
    cout<<"AC";
else
    cout<<"WA";


}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    e = collections.defaultdict(list)
    for _ in range(n-1):
        a,b = LI()
        e[a].append(b)
        e[b].append(a)

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv in e[u]:
                ud = 1
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

    ad = search(1)
    bd = search(n)
    t = -1
    for i in range(2,n):
        if ad[i] <= bd[i]:
            t += 1
        else:
            t -= 1

    if t >= 0:
        return 'Fennec'

    return 'Snuke'


print(main())





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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e12;

void zeta(int N, vector<pair<PLL,PLL>>& dp){
  for(int i=0;i<N;++i){
	for(int b=0;b<(1<<N);++b){
	  if((b>>i&1) == 1){
		PLL p11 = dp[b^(1<<i)].FF;
		PLL p12 = dp[b^(1<<i)].SS;
		PLL p21 = dp[b].FF;
		PLL p22 = dp[b].SS;
		if(p11.FF >= p21.FF){
		  dp[b].FF = p11;
		  if(p11 != p21){
			dp[b].SS = max(p12, p21);
		  }
		  else{
			dp[b].SS = max(p12, p22);
		  }
		}
		else{
		  dp[b].FF = p21;
		  if(p21 != p11){
			dp[b].SS = max(p22, p11);
		  }
		  else{
			dp[b].SS = max(p22, p12);
		  }
		}
	  }
	}
  }
}

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

  int N;
  cin >> N;
  int N2 = 1 << N;
  VL xs(N2);
  cin >> xs;

  vector<pair<PLL,PLL>> dp(N2);
  REP(i,N2) dp[i] = MP(MP(xs[i],i), MP(-INF,-1));
  zeta(N, dp);

  LL ans = 0;
  FOR(i,1,N2){
	maxi(ans, dp[i].FF.FF + dp[i].SS.FF);
	cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 2e2;

int main() {

    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<long long> pref(n+1);
    for (int i = n - 1; i >= 0; i--) {
        pref[i] = pref[i+1] + a[i];
        pref[i] %= MOD;
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long x = (a[i] * (pref[i + 1]));
        x %= MOD;
        ans += x;
    }
    /*
    long long ans2 = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans2 += (a[i] * a[j]);
            ans2 %= MOD;
        }
    }*/
    cout << (ans % MOD) << endl;
    //cout << ans2 << endl;

    return 0;
}

Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	sort(vec.begin(), vec.end());
	int r = *max_element(vec.begin(), vec.end());
	int l = *min_element(vec.begin(), vec.end());
	cout<<abs(r - l)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;

int main()
{
  int N;
  scanf("%d",&N);
  while(N-- > 0)
    {
      int n;
      cin >> n;
      int dp[n][n];
      int vec[n];
      for(int i=0;i<n;i++)
	{
	  cin >> vec[i];
	  for(int j=0;j<n;j++)
	    dp[i][j] = 0;
	}
      
      int mex = 0;
      for(int i=0;i<n;i++)
	dp[i][(i+1)%n] = abs(vec[i]-vec[(i+1)%n]),mex = max(mex,dp[i][(i+1)%n]);
      
      for(int i=2;i<n;i++)//幅
	{
	  for(int j=0;j<n;j++)//index
	    {
	      for(int k=j;k<=j+i-1;k++)//中間地点
		{
		  if(k == j)
		    {
		      dp[j][(j+i)%n] = max(dp[j][(j+i)%n],dp[j][(j+i-1)%n]+abs(vec[j]-vec[(j+i)%n]));
		      mex = max(mex,dp[j][(j+i)%n]);
		      continue;
		    }
		  dp[j][(j+i)%n] = max(dp[j][(j+i)%n],
				       dp[k%n][(j+i)%n]+dp[j][k%n]);
		}
	      mex = max(mex,dp[j][(j+i)%n]);
	    }
	}

      cout << mex << endl;


    }
  return 0;
}

Measured memory_bytes: 1276
#include<set>  
#include<map>  
#include<stack>  
#include<cstdio>  
#include<queue>  
#include<cmath>  
#include<vector>  
#include<climits>  
#include<cstring> 
#include<iostream> 
#include<algorithm> 
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
LL read(){ 
    LL f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
#define MAXN 100000
struct node{
	int x,y;
	node(){}
	node(int X,int Y){x=X,y=Y;}
	friend bool operator < (node a,node b){return a.x==b.x?a.y<b.y:a.x<b.x;}
}dot[MAXN+5];
map<node,bool> Map,Use;
LL H,W,N,ans[10];
bool cmp(node a,node b){return a.x==b.x?a.y<b.y:a.x<b.x;}
int main(){
	H=read(),W=read(),N=read();
	for(int i=1;i<=N;i++){
		dot[i].x=read(),dot[i].y=read();
		Map[node(dot[i].x,dot[i].y)]=1;
	}
	for(int i=1;i<=N;i++)
		for(int t=0;t<=8;t++){
			int sx=dot[i].x-t%3,sy=dot[i].y-t/3;
			if(sx<1||sy<1||sx>H-2||sy>W-2||Use.count(node(sx,sy))) continue;
			int tmp=0;
			for(int j=sx;j<sx+3;j++)
				for(int k=sy;k<sy+3;k++)
					if(Map.count(node(j,k))) tmp++;
			Use[node(sx,sy)]=1;
			if(tmp) ans[tmp]++;
		}
	LL tmp=0;
	for(int i=1;i<=9;i++)
		tmp+=ans[i];
	ans[0]=(H-2)*(W-2)-tmp;
	for(int i=0;i<=9;i++)
		printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 63488
#include<stdio.h>
int main(void)
{
	int i,j,n,m,l,a[101],x[10],y,z;
	scanf("%d",&n);
	m=0;
	y=0;
	l=0;
	for(i=0;i<8;i++){
		x[i]=0;
	}
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		if(a[i]<3200){
			if(a[i]>=1 && a[i]<400){
				x[0]++;
			}
			else if(a[i]>=400 && a[i]<800){
				x[1]++;
			}
			else if(a[i]>=800 && a[i]<1200){
				x[2]++;
			}
			else if(a[i]>=1200 && a[i]<1600){
				x[3]++;
			}
			else if(a[i]>=1600 && a[i]<2000){
				x[4]++;
			}
			else if(a[i]>=2000 && a[i]<2400){
				x[5]++;
			}
			else if(a[i]>=2400 && a[i]<2800){
				x[6]++;
			}
			else if(a[i]>=2800 && a[i]<3200){
				x[7]++;
			}
		}
		else{
			m++;
		}
	}
	for(i=0;i<8;i++){
		if(x[i]==0){
			l++;
		}
		else{
			y++;
		}
	}
	z=y+m;
	if(y==0){
		y=1;
	}
		printf("%d %d\n",y,z);
	return 0;
}

Measured memory_bytes: 128
#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()
{
    int n;
    cin >> n;
    cout << (100000 - n) % 1000 << endl;
    return 0;
}

Measured memory_bytes: 3620
N, M, X, Y = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.append(X)
B.append(Y)

maxA = max(A)
minB = min(B)

if minB > maxA :
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N;
llong H[100100];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	int tmp = 0;
	int ans = 0;
	for (int i = 1; i < N; i++) {
		if (H[i - 1] >= H[i]) {
			tmp++;
		}
		else {
			tmp = 0;
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import math

n, d = map(int, input().split())
xy = list(list(map(int, input().split())) for i in range(n))

def dist(a, b):
    return math.sqrt(a**2 + b**2)

ans = 0
for x, y in xy:
    if dist(x, y) <= d:
        ans += 1

print(ans)


Measured memory_bytes: 45464
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = (arg[0].split(" ")[0]);
    const N = S.length;
    
    let answer = 0;
    let cnt = [...Array(2020)].fill(0);
    cnt[0] = 1;
    
    let total = 0;
    let p = 1;
    
    for(let i=N-1; i>=0; i--) {
        total = (total + parseInt(S[i]) * p) % 2019;
        
        // console.log("total:" + total);
        // console.log("S[i]:" + S[i]);
        
        answer += cnt[total];
        
        p = (p * 10) % 2019;
        // console.log("p:" + p);
        // console.log("------")
        cnt[total]++;
    }
    
    // console.log(cnt);
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32712
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B = IL()
s = S()

if s.count("-")==1 and s.index("-")==A:
  print("Yes")
else:
  print("No")

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

void dft(vector<vector<int>> graph, vector<vector<int>>& time, int v, int& t){
    for(int i=0; i<graph[v].size(); i++){
        int next_v = graph[v][i];
        if(time[next_v][0] == 0){
            time[next_v][0] = t;
            t++;
            dft(graph, time, next_v, t);
        }
    }
    time[v][1] = t;
    t++;
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<vector<int>> graph(n+1);

    for(int i=1; i<=n; i++){
        int u, k;
        cin >> u >> k;
        for(int j=0; j<k; j++){
            int v;
            cin >> v;
            graph[i].push_back(v);
        }
    }

    vector<vector<int>> time(n+1, vector<int>(2, 0));
    int v = 1, t = 1;

    while(v <= n){
        time[v][0] = t;
        t++;
        dft(graph, time, v, t);

        for(; v<=n; v++){
            if(time[v][0] == 0){
                break;
            }
        }
    }

    for(int i=1; i<=n; i++){
        cout << i << " " << time[i][0] << " " << time[i][1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3808
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
AB = [lr() for _ in range(M)]
AB.sort(key=lambda x: x[1])
cur = 0
answer = 0
for a, b in AB:
    if a >= cur:
        answer += 1
        cur = b

print(answer)


Measured memory_bytes: 60380
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

const ll MOD = 200003;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int conv[MOD];

const ld PI = acos(-1.0);
struct cmplx {
	ld x, y;
	ld real() {
		return x;
	}
	cmplx operator+(const cmplx &b) {
		return {x + b.x, y + b.y};
	}
	cmplx operator-(const cmplx &b) {
		return {x - b.x, y - b.y};
	}
	cmplx operator*(const cmplx &b) {
		return {x * b.x - y * b.y, x * b.y + y * b.x};
	}
	cmplx operator/(ld k) {
		return {x / k, y / k};
	}
};

void fft(cmplx *a, int k, int inv) {
	int n = (1 << k);
	for (int i = 1, j = 0; i < n; ++i) {
		int k = n;
		do j ^= (k >>= 1); while (~j & k);
		if (i < j)
			swap(a[i], a[j]);
	}
	for (int bl = 1; bl < n; bl *= 2) {
		ld ang = PI / bl;
		cmplx wadd{cos(ang), sin(ang)};
		for (int i = 0; i < n; i += 2 * bl) {
			cmplx w{1, 0};
			for (int j = i; j < i + bl; ++j, w = w * wadd) {
				cmplx u = a[j], v = a[j + bl] * w;
				a[j] = u + v, a[j + bl] = u - v;
			}
		}
	}
	if (inv) {
		reverse(a + 1, a + n);
		for (int i = 0; i < n; ++i) {
			a[i] = a[i] / n;
		}
	}
}

cmplx a[1 << 19];
ll b[1 << 19];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	ll cur = 1;
	for (int i = 0; i < MOD - 1; ++i) {
		conv[cur] = i;
		cur = (cur * 2) % MOD;
	}

	ll ans = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		ll x;
		cin >> x;
		if (x != 0) {
			ans -= (x * x) % MOD;
			a[conv[x]].x += 1;
		}
	}

	fft(a, 19, 0);
	for (int i = 0; i < (1 << 19); ++i) {
		a[i] = a[i] * a[i];
	}
	fft(a, 19, 1);

	for (int i = 0; i < (1 << 19); ++i) {
		ll x = llround(a[i].x);
		b[i % (MOD - 1)] += x;
	}

	cur = 1;
	for (int i = 0; i < MOD - 1; ++i) {
		ans += cur * b[i];
		cur = (cur * 2) % MOD;
	}
	cout << ans / 2 << "\n";

	return 0;
}




Measured memory_bytes: 22720
#include<stdio.h>

int main (){

  int n;
  int m;
  int i;
  scanf("%d",&n);
  m=n;
 	for(i=0;m>0;i++){
      m/=10;
      //printf("%d",i);
    }
 if(i<=1){
 	printf("%d",n);
 }
 else if(i>1&&i<=2){
 	printf("%d",9);
 } 
 else if(i>2&&i<=3){
 	printf("%d",9+n-100+1);
 }
   else if(i>3&&i<=4){
 	printf("%d",9+900);
 }
   else if(i>4&&i<=5){
 	printf("%d",9+900+n-10000+1);
 }
  else printf("%d",9+900+90000);
	return 0;
}

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

using namespace std;
typedef long long ll;

const ll mod=1000000007;

ll fpow(ll b,ll e)
{
    ll res=1;
    while(e)
    {
        if(e&1) res=(res*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll res=fpow(10,n);
    res=(res-2*fpow(9,n))%mod;
    res=(res+fpow(8,n))%mod;
    if(res<0) res+=mod;
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3636
N = int(input())
P = [int(i) for i in input().split()]
T = [ i for i in range(1,N+1)]

missc = 0
for i in range(N):
    if P[i]!=T[i]:
        missc+=1

print( 'YES' if missc==2 or missc==0 else 'NO')

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
#define MAX 100010

int q[MAX];
int head=0,tail=0;
void enque(int a){
  q[tail++]=a;
}
int deque(){
  return q[head++];
}
void print_que(){
  int i;
  printf("Q:[ ");
  for(i=head;i<tail;i++)
    printf("%d ",q[i]);
  printf("]\n");
}

int parent[MAX+1]={};

int* list[MAX+1];
int deg[MAX+1]={};
int odeg[MAX+1]={};
int searched[MAX+1]={};
typedef struct{
  int u;
  int v;
  int d;
}edge;
edge tree[MAX];
edge other[MAX];
int comp[MAX]={};
int height[MAX]={};
void dfs(int v);
void input();
int root(int a);
int solve();

void write_tree(int v);
int dep[MAX+1]={};
int depth=0;
void print_list();

int n,m;
int main(){
  scanf("%d%d",&n,&m);
  if(m%2){
    printf("-1\n");
    int a,b,i;
    for(i=0;i<m;i++) scanf("%d%d",&a,&b);
    return 0;
  }
  int i;
  for(i=1;i<=n;i++)list[i]=NULL;
  for(i=0;i<m;i++){
    input();
  }
  dfs(1);
  if(df){
    print_list();
    write_tree(1);
  }
  solve();
  
}


int root(int a){
  if(comp[a]==0)return a;
  int u=root(comp[a]);
  comp[a]=u;
  return u;
}

void input(){
  int a,b;
  scanf("%d%d",&a,&b);
  int u=root(a),v=root(b);
  if(u==v){
    printf("%s%d %d%s\n",df?"[":"",a,b,df?"]":"");
    odeg[a]^=1;
    return;
  }
  list[a]=realloc(list[a],sizeof(int)*(++deg[a]));
  list[b]=realloc(list[b],sizeof(int)*(++deg[b]));
  list[a][deg[a]-1]=b;
  list[b][deg[b]-1]=a;
  int w=(height[u]<height[v])?u:v;
  comp[u+v-w]=w;
  height[w]=height[u+v-w]+1;
}


void dfs(int v){
  int i;
  for(i=0;i<deg[v];i++){
    int u=list[v][i];
    if(u==parent[v])continue;
    parent[u]=v;
    dfs(u);
  }
}

int solve(){
  int i;
  for(i=1;i<=n;i++){
    if(deg[i]==1)enque(i);
  }
  if(df)print_que();
  while(head-tail){
    int v=deque(), u=parent[v];
    if(v==1)continue;
    if(odeg[v]){
      printf("%s%d %d%s\n",df?"[":"",v,u,df?"]":"");
    }else{
      printf("%s%d %d%s\n",df?"[":"",u,v,df?"]":"");
      odeg[u]^=1;
    }
    searched[u]++;
    if(deg[u]-searched[u]==1)enque(u);
  }
}
void write_tree(int v){
  printf("%2d",v);
  dep[v]=depth++;
  int i,u;
  for(i=0;i<deg[v];i++){
    u=list[v][i];
    if(u==parent[v])continue;
    
      int j;
      if(i==0 || (i==1 && list[v][0]==parent[v]))printf("-");
      else{
	for(j=0;j<dep[v]*3+2;j++)printf(" ");
	printf("L");
      }
    
    write_tree(u);
    if(deg[u]==1)printf("\n");
  }
  depth--;
}
void print_list(){
  int i,v;
  for(v=1;v<=n;v++){
    printf("%d:[ ",v);
    for(i=0;i<deg[v];i++){
      printf("%d ",list[v][i]);
    }
    printf("] deg:%d\n",deg[v]);
  }
}

/// confirm df==0 ///


Measured memory_bytes: 14208
//
//  main.cpp
//  Ubiquity
//
//  Created by Bryan on 13/09/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    long long X;
    scanf ("%lld",&X);
    long long mod = 1000000007;
    long long ans = 1;
    for (long long f = 0; f<X;f++)
    {
        ans*=10;
        ans%=mod;
    }
    long long sm = 1;
    for (long long f = 0; f<X;f++)
    {
        sm*=9;
        sm%=mod;
    }
    long long nl = 1;
    for (long long f = 0; f<X;f++)
    {
        nl*=8;
        nl%=mod;
    }
    ans+=mod;
    ans-=sm;
    ans+=mod;
    ans-=sm;
    ans+=nl;
    
    
    ans%=mod;
    printf ("%lld\n",ans);
    
}


Measured memory_bytes: 3800
#include<stdio.h>
#include<math.h>
int main(void){
	int h,w,i,i2;
	scanf("%d %d",&h,&w);
	while(h!=0&&w!=0){
		for(i=0;i<h;i++){
			for(i2=0;i2<w;i2++){
				if(i%2==1){
					if(i2%2==1){
						printf("#");
					}
					else{
						printf(".");
					}
				}
				else{
					if(i2%2==1){
						printf(".");
					}
					else{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d",&h,&w);
	}
	return 0;
}

Measured memory_bytes: 2552
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> N >> K;

	int A[60];

	rep(i, 0, N)
	{
		cin >> A[i];
	}

	int ans = 0;
	rep(i, 0, min(N, K) + 1)
	{
		rep(j, 0, min(N, K) + 1 - i)
		{
			int res = 0;
			priority_queue<int> pq;

			rep(l, 0, i)
			{
				res += A[l];
				if (A[l] < 0)
				{
					pq.push(-A[l]);
				}
			}
			rep(r, N - j, N)
			{
				res += A[r];
				if (A[r] < 0)
				{
					pq.push(-A[r]);
				}
			}
			int tk = K - i - j;
			while (0 < tk && !pq.empty())
			{
				int t = pq.top();
				pq.pop();
				res += t;
				tk--;
			}
			chmax(ans, res);
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256