akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  map<lli,lli>mp;
  map<string,lli>mps;
  cin >> A >> B >> H >> M;
  H=H*60+M;
  long double a=5.5*H;
  const double PI=3.14159265358979323846;
  HpOut(sqrt(A*A+B*B-2*A*B*cos(PI*a/180)));
}

Measured memory_bytes: 4204
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define li long int
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define mpp(x,y) map<x,y>
#define qq(x) queue<x>
#define pqq(x) priority_queue<x> 
#define search(x,y,z) binary_search(x,y,z)
#define pi(x,y) pair<x,y>
#define forf(i,x,y) for(ll i=x;i<y;i++)
#define forl(i,x,y) for(ll i=x-1;i>=y;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define pob pop_back
#define pp push
#define po pop
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define vp(x,y) vec(pi(x,y) )
#define vv(x) vector<vector<x> >
#define all(x) x.begin(),x.end()

using namespace std;

int main()
{
	fastio;
	/*#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif*/
	
	int p,k;
	cin>>p>>k;
	li l[100005],r[100005];
	int m=0,n=0;
	forf(i,0,p)
	{	li x;cin>>x;
		if(x<0)
			l[m++]=abs(x);
		else if(x>0)
			r[n++]=x;
		else
			k--;
	}
	if(k==0)
	{	cout<<0;
		return 0;
	}
	sort(l,l+m);
	int left=0,right=0;
	if(m>=k)
		left=k;
	else
		left=m;
	ll ans=INT_MAX,x,y,c;
	while(left>=0)
	{	if(left>0 && k-left<=n)
			x=l[left-1];
		else
			x=0;
		right=k-left;
		if(right>0 && right<=n)
			y=r[right-1];
		else
			y=0;
		c=2*min(x,y)+max(x,y);
		if(c)
			ans=min(ans,c);
		left--;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
S = input()
P =2019
ans = 0
 
count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
print(ans)

Measured memory_bytes: 9276
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>H>>W;
	cout<<string(W+2,'#')<<endl;
	FOR(y,H) {
		cin>>s;
		cout<<"#"<<s<<"#"<<endl;
	}
	cout<<string(W+2,'#')<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int k, x;
   cin >> k >> x;
   cout << (k * 500 >= x ? "Yes" : "No") << endl;
   return 0;
}


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

    print(' '.join(map(str, A)))

    for i in range(1, N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(' '.join(map(str, A)))
        
main1()


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define TASK "task"

using namespace std;

void rwFile() {
    freopen(TASK ".in", "r", stdin);
    freopen(TASK ".out", "w", stdout);
}

void solveA() {
    int x, y, z; cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
   /// rwFile();
    solveA();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,m,dp[200003],ans,raod[200003];
vector<ll>v[200004],rev[200004];
set<pair<ll,ll> >st;
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    
    for(int i=1; i<=m; i++){
        ll x,y;
        cin >> x >> y;
        raod[y]++;
        rev[y].pb(x);
        v[x].pb(y);
    }
    
    for(int i=1; i<=n; i++){
        st.insert(mp(raod[i] , i));
    }
    
    while(st.size()){
        ll x = (*st.begin()).s;
        st.erase(st.begin());
        for(int i=0; i<rev[x].size(); i++)
            dp[x] = max(dp[x] , dp[rev[x][i]] + 1);
        ans = max(ans , dp[x]);
        for(int i=0; i<v[x].size(); i++){
            st.erase(st.find(mp(raod[v[x][i]] , v[x][i])));
            raod[v[x][i]]--;
            st.insert(mp(raod[v[x][i]] , v[x][i]));
        }
    }
    
    
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 25088
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxn = 100005;
const int Maxb = 30;

int n, k;
int a[Maxn], b[Maxn];
ll res;

ll Get(int mask)
{
	ll res = 0;
	for (int i = 0; i < n; i++)
		if ((mask & a[i]) == a[i]) res += b[i];
	return res;
}

int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d %d", &a[i], &b[i]);
	int cur = 0;
	for (int i = Maxb - 1; i >= 0; i--)
		if (k & 1 << i) {
			int got = cur | ((1 << i) - 1);
			res = max(res, Get(got));
			cur |= 1 << i;
		}
	res = max(res, Get(cur));
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
def main():
    n, *ab = map(int, open(0).read().split())
    a = ab[:n+1]
    b = ab[n+1:]

    init_a_sum = sum(a)
    for i, cur_b in enumerate(b):
        if a[i] > cur_b:
            a[i] -= cur_b
        else:
            a[i+1] = max(0, a[i+1] -  (cur_b - a[i]))
            a[i] = 0
    last_a_sum = sum(a)
    ans = init_a_sum - last_a_sum
    print(ans)
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 25180
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int cnt,ans=0;
    for(int i=1;i<=n;i+=2){
        cnt=0;
        for(int j=1;j<=i;j+=2){
            if(i%j==0)cnt++;
        }
        if(cnt==8)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def solve(inp):
    N = int(inp.readline().strip())
    H = list(map(int, inp.readline().strip().split(' ')))

    r = 0
    i = 0
    while i < N:
        r0 = 0
        prev = H[i]
        j = i + 1
        while j < N:
            if prev < H[j]:
                break
            r0 += 1
            prev = H[j]
            j += 1
        r = max(r, r0)
        i = j

    return str(r)


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14224
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)][::-1]
plus=0
for j in range(N):
    AB[j][0]+=plus
    if AB[j][0]%AB[j][1]!=0:
        a=AB[j][1]-(AB[j][0]%AB[j][1])
        AB[j][0]+=a
        plus+=a
print(plus)

Measured memory_bytes: 31332
retu = input()
res = list(map(str,retu))
sum = [0]*len(retu)


for i in range(len(retu)):
  if res[i] == "A" or res[i]=="C" or res[i] =="T" or res[i]=="G":
    res[i] = 1
  else:
    res[i] = 0

    
for i in range(len(retu)):
  for j in range(len(retu)-i):
    if res[i+j] == 1:
      sum[i] += 1
    else:
      break
      
print(max(sum))
    

Measured memory_bytes: 3064
#include<stdio.h> 
int main()
{
	int S, h, m, s ,x;
    scanf("%d", &S);
    h=S/3600;
    x=S%3600;
    m=x/60;
    s=x%60;
    printf("%d:%d:%d\n", h, m, s );
	return 0;	
}


Measured memory_bytes: 2092
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var a, b, c, d int

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c, d = nextInt(), nextInt(), nextInt(), nextInt()
	if b < c || d < a {
		fmt.Println(0)
		return
	}
	fmt.Println(minInt(b, d) - maxInt(a, c))
}


Measured memory_bytes: 640
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,i,flg,h[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&h[i]);
	flg=1;
	h[0]--;
	for(i=1;i<n;i++)	{
		if(h[i]<h[i-1])	{
			flg=0;
			break;
		}
		else if(h[i]>h[i-1])	{
			h[i]--;
		}
	}
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  long unsigned int n; long long k; cin >>n >>k;
  int r1=0,r2=0,r3=0,t=0; bool shit=0;
  set<int>s; vector<int>v(n); vector<int>r(n);
  for(long unsigned int i=0; i<n; i++) cin >>v[i];
  for(long unsigned int i=0; i<n; i++){
    if(i) t=v[t-1];
    else t=v[0];
    s.insert(t);
    if(s.size()==i){r1=i; r2=t; shit=1; break;}
    r[i]=t;
  }
  if(shit) for(long unsigned int i=0; i<n; i++) if(r[i]==r2) r3=i;
  if(!shit)
  {
    if(k%n) cout <<r[k%n-1];
    else cout <<r[n-1];
    return 0;
  }
  if(k<=r3) cout <<r[k-1];
  else cout <<r[(k-r3-1)%(r1-r3)+r3];
return 0;}

Measured memory_bytes: 14084
// AOJ 1169
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)

const std::string INF = "NO";

struct edge
{
	int from, to;
	std::string lab;

	edge( int from, int to, const std::string &lab )
	:	from(from), to(to), lab(lab)
	{}
};

int n, a, s, g;
std::vector<edge> es;
int maxL;

int main()
{
	while( scanf( "%d%d%d%d", &n, &a, &s, &g ), n|a|s|g )
	{
		es.clear();
		maxL = 0;

		rep( i, a )
		{
			int x, y;
			char lab[7];

			scanf( "%d%d%s", &x, &y, lab );

			es.push_back( edge( x, y, lab ) );

			maxL = std::max<int>( maxL, strlen(lab) );
		}

		std::vector<std::string> d( n, INF );
		d[g] = "";

		rep( i, n*(maxL+1) )
		{
			auto nxt = d;

			rep( j, a ) if( d[es[j].to] != INF && (nxt[es[j].from] == INF || nxt[es[j].from] > es[j].lab + d[es[j].to]) )
			{
				nxt[es[j].from] = es[j].lab + d[es[j].to];

				if( es[j].from == s && i >= n )
				{ puts("NO"); goto end; }
			}

			d.swap(nxt);
		}

		printf( "%s\n", d[s].c_str() );

end:;
	}

	return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>    //super header :標準ライブラリ,STLを全てインクルード
using namespace std;

struct Data {
    long long a;
    long long b;
};

int main(){
    long long A,B;
    cin >> A >> B;

    A--;
    long long tmpA,tmpB;
    if(A&1){
        if(A&2){
            tmpA = 0;
        }else{
            tmpA = 1;
        }
    }
    else{
        if(A%4 == 1 || A%4 == 2){
            tmpA = ((A >> 1) << 1) + 1;
        }else{
            tmpA = (A >> 1) << 1;
        }
    }

    if(B&1){
        if(B&2){
            tmpB = 0;
        }else{
            tmpB = 1;
        }
    }
    else{
        if(B%4 == 1 || B%4 == 2){
            tmpB = ((B >> 1) << 1) + 1;
        }else{
            tmpB = (B >> 1) << 1;
        }
    }

    cout << (tmpA ^ tmpB) << "\n";
}


Measured memory_bytes: 256
/// In the name of ALLAH
/// I'm THEOVE46
#include<bits/stdc++.h>
using namespace std;

#define gap             " "
#define nn              "\n"
#define pi              2*acos(0.0)
#define db              double
#define ft              float
#define ll              long long int
#define ull             unsigned long long int
#define pf              printf
#define sf              scanf
#define ff              first
#define ss              second
#define sfi(n)          sf("%d",&n)
#define sfi2(n, m)      sf("%d%d",&n,&m)
#define sfl(n)          sf("%lld",&n)
#define sfl2(n, m)      sf("%lld%lld",&n,&m)
#define sff(n)          sf("%f",&n)
#define sfd(n)          sf("%lf",&n)
#define pfi(n)          pf("%d",n)
#define pfl(n)          pf("%lld",n)
#define pff(n)          pf("%f",f)
#define pfd(n)          pf("%lf",f)
#define bfi             cin.ignore()
#define bfs             cin.get()
#define bfc             getchar()
#define gl(s)           getline(cin, s)
#define loop(a,n)       for(i=a; i<n; i++)
#define mloop(i,a,n)    for(i=a; i<n; i++)
#define rloop(i,a,n)    for(i=a; i>=n; i--)
#define tloop(test)     for(ll tl=1; tl<=test; tl++)
#define case1(z)        cout<<"Case "<<z<<": "
#define case2(z)        printf("Case %d: ",z)
#define vi              vector<int>
#define vl              vector<ll>
#define vld(vc,rw)      vector<vector<ll> >vc(rw)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define pis             pair<int,string>
#define psi             pair<string,int>
#define mls             map <ll,string>
#define msl             map <string,ll>
#define mll             map <ll,ll>
#define mp              make_pair
#define pb              push_back
#define itr             vector<int> :: iterator
#define atl(i, v)       for(auto i: v)
#define sz(s)           s.size()
#define sl(s)           s.length()
#define Sort(s)         sort(s.begin(), s.end())
#define SortR(s)        sort(s.rbegin(), s.rend())
#define all(x)          x.begin(),x.end()
#define rall(x)         x.end(), x.begin()
#define MEM(ar,val)     memset(ar, (val), sizeof(ar))
#define IN(A,B,C)       assert(B<=A && A<=C)
#define MOD             1000000007
#define EPS             1e-9
#define Max             1e9
#define Min             -1e9
#define bug1            " **1** "
#define bug2            " ****2**** "
#define artri(b,h)      0.5*b*h
#define artrap(b1,b2,h) (b1+b2)/2*h
#define arcrl(r)        pi*r*r
#define vlsyl(r,h)      pi*r*r*h
#define vlcone(r,h)     pi*r*r*(h/3)
#define vlsph(r)        (4/3)*pi*r*r*r
#define flush           fflush(stdout)
#define pcn(dg,val)     fixed << setprecision(dg) << val
#define ggl             pf("Case #%lld: ", tl)
#define FastIO          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define showsort(n, a)  for(int i=0; i<n; i++) cout << a[i] << gap; cout << endl;

///THEOVE46

int main()
{
    //FastIO;
    ll t, i;
    cin >> t;
    loop(0, t) cout << "ACL";
    cout << endl;
    return 0;
}

///   check for integer overflow, array bounds
///   check for n=1
///   - - - The Ove 46



Measured memory_bytes: 3620
package main

import (
	"fmt"
	"math"
)

var memo map[int]int
var A, B, C, D int

func solve(N int) int {
	if N == 0 {
		return 0
	}
	if N == 1 {
		return D
	}

	if v, ok := memo[N]; ok {
		return v
	}

	l2 := (N / 2) * 2
	r2 := ((N + 1) / 2) * 2
	l3 := (N / 3) * 3
	r3 := ((N + 2) / 3) * 3
	l5 := (N / 5) * 5
	r5 := ((N + 4) / 5) * 5
	res := int(1e18)

	if N < res/D {
		res = N * D
	}
	res = min(res, abs(l2-N)*D+A+solve(l2/2))
	res = min(res, abs(r2-N)*D+A+solve(r2/2))
	res = min(res, abs(l3-N)*D+B+solve(l3/3))
	res = min(res, abs(r3-N)*D+B+solve(r3/3))
	res = min(res, abs(l5-N)*D+C+solve(l5/5))
	res = min(res, abs(r5-N)*D+C+solve(r5/5))

	memo[N] = res
	return res
}

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func main() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		memo = map[int]int{}
		var N int
		fmt.Scan(&N, &A, &B, &C, &D)
		fmt.Println(solve(N))
	}

}


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

const int N = 8;
int L[N];

int n, a, b, c, mini = 1e9;

void dfs(int depth, int na, int nb, int nc, int sc){
    if(na > 0 and nb > 0 and nc > 0){
        mini = min(mini, abs(na - a) + abs(nb - b) + abs(nc - c) + sc * 10);
    }
    if(depth == n) return;
    dfs(depth + 1, na + L[depth], nb, nc, (na == 0 ? sc : sc + 1));
    dfs(depth + 1, na, nb + L[depth], nc, (nb == 0 ? sc : sc + 1));
    dfs(depth + 1, na, nb, nc + L[depth], (nc == 0 ? sc : sc + 1));
    dfs(depth + 1, na, nb, nc, sc);
}

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

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

    dfs(0, 0, 0, 0, 0);

    cout << mini << endl;

    return 0;
}

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

int N;
vector<vector<int>> h, dp;

int main() {
  cin >> N;

  h.resize(N, vector<int>(3));
  rep(i, N) rep(j, 3) { cin >> h[i][j]; }

  dp.resize(N + 1, vector<int>(3, 0));

  rep(i, N) {
    rep(j, 3) {
      rep(k, 3) {
        if (j == k) continue;

        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + h[i][k]);
      }
    }
  }

  cout << *max_element(all(dp[N])) << endl;

  return 0;
}


Measured memory_bytes: 11136
n,m=map(int,raw_input().split())
x=[[0 for i in range(m)]for i in range(n)]
a=[[0 for i in range(m+1)] for i in range(n+1)]

for i in range(n):
	x[i] = map(int,raw_input().split())
	for j in range(m):
		a[i][j] = x[i][j]
		a[n][j] += x[i][j]
		a[i][m] += x[i][j]
	print " ".join(map(str,a[i]))
a[n][m]=sum(a[n])
print " ".join(map(str,a[n]))


Measured memory_bytes: 4820
N = int(input())
A = list(map(int, input().split()))

xor = 0
for a in A[2:]:
    xor ^= a

n = A[0] + A[1] - xor
if n < 0 or n%2:
    print(-1)
    quit()

n //= 2
a = b = 0
digit = 1
d = []
while n or xor:
    n0 = n & 1; xor0 = xor & 1
    if n0:
        if xor0:
            print(-1)
            quit()
        else:
            a += digit
            b += digit
    else:
        if xor0:
            b += digit
            d.append(digit)

    digit *= 2
    n >>= 1; xor >>= 1

if a > A[0]:
    print(-1)
    quit()

while d:
    dd = d.pop()
    if a + dd <= A[0]:
        a += dd; b -= dd

if a:
    print(A[0] - a)
else:
    print(-1)

Measured memory_bytes: 9196
#include <iostream>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <vector>

using namespace std;

typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int> ii;
typedef tuple<int, int, int> iii;
typedef unordered_set<ii> sii;
typedef priority_queue<iii> pq;

namespace std {
  template<> struct hash<ii> {
    size_t operator()(const ii &i) const {
      return hash<int>()(get<0>(i) * 100 + get<1>(i));
    };
  };
}

int s(const vvb &m, int h, int w, sii &v, pq &q) {
	int k, i, j;
	while (true) {
		if (q.empty()) return -1;
		tie(k, i, j) = q.top();
		k = -k;
		q.pop();
		if (v.count(make_tuple(i, j))) continue;
		v.insert(make_tuple(i, j));
		break;
	}
	if (i == h - 1 && j == w - 1) return k;
	if (i > 0 && m[i - 1][j] && !v.count(make_tuple(i - 1, j))) q.push(make_tuple(-(k + 1), i - 1, j));
	if (i < h - 1 && m[i + 1][j] && !v.count(make_tuple(i + 1, j))) q.push(make_tuple(-(k + 1), i + 1, j));
	if (j > 0 && m[i][j - 1] && !v.count(make_tuple(i, j - 1))) q.push(make_tuple(-(k + 1), i, j - 1));
	if (j < w - 1 && m[i][j + 1] && !v.count(make_tuple(i, j + 1))) q.push(make_tuple(-(k + 1), i, j + 1));
	return s(m, h, w, v, q);
}

int main() {
	int h, w;
	cin >> h >> w;
	vvb m(h);
	int b = 0;
	for (int i = 0; i < h; i++) {
		m[i] = vb(w);
		for (int j = 0; j < w; j++) {
			char c;
			cin >> c;
			m[i][j] = c == '.';
			b += c == '#';
		}
	}
	pq q;
	q.push(make_tuple(-1, 0, 0));
	sii v;
	int c = s(m, h, w, v, q);
	if (c == -1) cout << -1 << endl;
	else cout << h * w - c - b << endl;
}


Measured memory_bytes: 640
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int n;
int m;
int sz[N];
int parent[N];
long long ans[N];
pair < int , int > adj[N];

long long ss;

int getP(int u){
    if(parent[u] == u)
        return u;
    return parent[u] = getP(parent[u]);
}

void join(int u , int v){
    u = getP(u);
    v = getP(v);
    if(u == v)
        return;
    parent[v] = u;
    ss -= sz[u] * sz[v] * 1ll;
    sz[u] += sz[v];
}

int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        sz[i] = 1;
        parent[i] = i;
    }
    for(int i = 1; i <= m; i++){
        int u , v;
        scanf("%d%d" , &u , &v);
        adj[i] = {u , v};
    }
    ss = 1ll * n * (n - 1ll) / 2;
    for(int i = m; i >= 1; i--){
        ans[i] = ss;
        join(adj[i].first , adj[i].second);
    }
    for(int i = 1; i <= m; i++){
        printf("%lld\n" , ans[i]);
    }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  int n=S.size(),a=0,b=0,c=0,d=0;
  for(int i=0;i<n;i++){
    if(S.at(i)=='N')a++;
    if(S.at(i)=='S')b++;
    if(S.at(i)=='E')c++;
    if(S.at(i)=='W')d++;
  }
  
  int check1=0,check2=0;
  if((a==0 && b==0) or (a>0 && b>0))check1=1;
  if((c==0 && d==0) or (c>0 && d>0))check2=1;
  
  if(check1*check2==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define oset tree<long long, null_type,less_equal<long long>, rb_tree_tag,tree_order_statistics_node_update>
using ll = long long;
ll mod=1e9+7;




int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        ll n,k,i;
        cin>>n>>k;
        oset s,s2;
        ll a[n+2];
        for(i=0;i<n;i++){
            cin>>a[i];
            s2.insert(a[i]);
        }
        
        ll bigonR[n+2],bigger[n+2];
        for(i=0;i<n;i++){
            bigger[i] = s2.order_of_key(a[i]);
        }
        
        
        for(i=n-1;i>=0;i--){
            bigonR[i]=s.order_of_key(a[i]);
            s.insert(a[i]);
            
        }
        ll sum=0;
        for(i=0;i<n;i++){
            // cout << bigger[i] << ' ' << bigonR[i] << "\n";
            ll kk = (k * (k - 1)) / 2;
            kk %= mod;
            sum += ((bigger[i] * kk) % mod);
            sum %= mod;
            sum += ((bigonR[i] * k) % mod);
            sum %= mod;
        }
        cout << sum;
        cout<<"\n";
    }
}




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

struct Node{
  int key;
  struct Node *pre,*nex;
};

struct Node *nil;

void Insert(int key){
  struct Node *x;

  x=(struct Node*)malloc(sizeof(struct Node));
  x->key=key;
  x->nex=nil->nex;
  nil->nex->pre=x;
  nil->nex=x;
  x->pre=nil;
}

struct Node *listserch(int key){
  struct Node* gol=nil->nex;
  while(gol!=nil&&gol->key!=key){
    gol=gol->nex;
  }
  return gol;
}

void Delete(struct Node *y){
if(y==nil)return;
y->pre->nex=y->nex;
y->nex->pre=y->pre;
}

int main(){
  struct Node *ans;
  int n,value,i;
  char order[10];

  nil=(struct Node*)malloc(sizeof(struct Node));
  nil->nex=nil;
  nil->pre=nil;

    scanf("%d",&n);

    for(i=0;i<n;i++){
      scanf("%s",order);

      if(strcmp(order,"insert")==0){
      scanf("%d",&value);
      Insert(value);
    }

      else if(strcmp(order,"delete")==0){
        scanf("%d",&value);
      Delete(listserch(value));
    }

      else if(strcmp(order,"deleteFirst")==0)
      Delete(nil->nex);

      else if(strcmp(order,"deleteLast")==0)
      Delete(nil->pre);

      else
      printf("miss order!!\n");

    }

    ans=nil->nex;
  while(ans->nex!=nil){
    printf("%d ",ans->key);
    ans=ans->nex;
  }

    printf("%d\n",ans->key);

    return 0;
}



Measured memory_bytes: 36104
#include <iostream>

using namespace std;

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

  int d[4] = {0};
  int a, b;
  for (int i = 0; i < 3; i++) {
    cin >> a >> b;
    d[a - 1]++;
    d[b - 1]++;
  }
  int c = 0;
  for (auto e : d) {
    if (e % 2 == 1) c++;
  }
  if (c == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;

/* 判定式を指定できるめぐる式二分探索 */
/* input: arr:行列、callback:判定方法の関数ポインタ、 userQuery:判定に使用するための引数(省略可)*/
/* output: 条件を満たす要素の最小値(全て満たさなければ要素サイズを返す) */
/* 制約事項: 行列のある要素に対して判定方法callbackを満たすとき、それより大きな要素も判定方法を満たす必要がある。 */
template<class X> int binarySearch_latest(vector<X> arr, bool (*callback)(X, int), X userQuery = 0) {
    int ng = -1;
    int ok = (int)arr.size();
    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if (callback(arr[mid], userQuery)){ ok = mid; } else { ng = mid; }
    }
    return ok;
}

template<class X> bool judge1(X arrValue, int user){
    return (arrValue >= (X)user);
}


int main()
{
    int n;
    cin >> n;
    vector<int> l;
    rep(i, n){ int tmp; cin >> tmp; l.push_back(tmp);}
    sort(l.begin(), l.end());
    //show(l);

    int ans = 0;
    for (int i = 0; i < l.size(); i++)
    {
        for (int j = i + 1; j < l.size(); j++)
        {
            int two_sum = l[i] + l[j];
            int youso =  binarySearch_latest(l, judge1, two_sum);
            ans += ((youso - j - 1) < 0) ? 0: (youso - j - 1); 
        }
        
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> graph;
vector<int> dist, ans, cnt;
void recur(int x)
{
    cnt[x]--;
    if (cnt[x] > 0) return;
    
    for (int i : graph[x]) {
        if (dist[i] < dist[x] + 1) dist[i] = dist[x]+1;
        recur(i);
    }
}
void recur2(int x, int prev)
{
    ans[x] = prev;
    for (int i : graph[x]) {
        if (dist[i] == dist[x] + 1) {
            recur2(i, x);
        }
    }
}
int main()
{
    int N, M; cin >> N >> M;
    vector<int> A(N-1+M), B(N-1+M);
    graph.resize(N);
    dist = ans = cnt = vector<int>(N);
    for (int i = 0; i < N-1+M; i++) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
        graph[A[i]].push_back(B[i]);
    }
    for (int i = 0; i < N-1+M; i++) {
        cnt[B[i]]++;
    }
    int root = min_element(begin(cnt), end(cnt)) - begin(cnt);
    cnt[root]++;
    dist[root] = 0;
    recur(root);
    recur2(root, -1);
    for (int i : ans) cout << i+1 << '\n';
    return 0;
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int64_t sum = 0;
    for (int i = 1; i <= n; i++){
        if(i % 3 == 0)
            continue;
        if(i % 5 == 0)
            continue;
        sum += i;
        }
    cout << sum << endl;
}


Measured memory_bytes: 3632
//### In The Name Of GOD ###

// %% Remember; (((He))) is The (((Accepter))) %%

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) / b

const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2 * 1000 * 1000 + 200;
const int MAXN = 2 * 1000 * 100 + 20;
const int MLOG = 18;
const int NMAX = 1 * 1000;

int ps[MAXN][2], fath[MAXN][2], num[MAXN][2];

int fad(int x, int b){
  if(fath[x][b] == x) return x;
  else return fad(fath[x][b], b);
}

void mrg(int x, int y, int b){
  if(x == y) return ;
  if(ps[x][b] > ps[y][b]){
    fath[y][b] = x;
    num[x][b] += num[y][b];
  }else if(ps[x][b] == ps[y][b]){
    fath[y][b] = x;
    ps[x][b]++;
    num[x][b] += num[y][b];
  }else{
    fath[x][b] = y;
    num[y][b] += num[x][b];
  }
}

signed main(){
  IO;
  int n, rah, gat, a, b;
  cin >> n >> rah >> gat;
  // cout << "a";
  for(int i = 0; i < n + 20; i++){
    // cout << "b";
    fath[i][0] = i;
    num[i][0] = 1;
    fath[i][1] = i;
    num[i][1] = 1;
  }
  for(int i = 0; i < rah; i++){
    cin >> a >> b;a--;b--;
    // cout << "x" << endl;
    mrg(fad(a, 0), fad(b, 0), 0);
  }
  for(int i = 0; i < gat; i++){
    cin >> a >> b;a--;b--;
    // if(fad(a, 0) == fad(b, 0)){
      mrg(fad(a, 1), fad(b, 1), 1);
    // }
    // cout << "y";
  }
  map<pair<int, int>, int> h;
  for(int i = 0; i < n; i++){
    h[{fad(i, 1),fad(i, 0)}]++;
  }
  for(int i = 0; i < n; i++){
    cout << h[{fad(i, 1),fad(i, 0)}] << ' ';
  }
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	int n;cin >> n;
	
	REP(i,n){
		ll a,b,c,d;cin >> a >> b >> c >> d;
		a -= b;
		if(a < 0 || d < b){
			DBG(cout << 1 << endl;)
			cout << "No" << endl;
			continue;
		}
		if(b <= c){
			DBG(cout << 2 << endl;)
			cout << "Yes" << endl;
			continue;
		}
		ll tmp1 = ((a - c) / b);
		a -= tmp1 * b;
		if(a > c)a -= b;
		if(a < 0){
			DBG(cout << 3 << endl;)
			cout << "No" << endl;
			continue;
		}
		
		if(d % b == 0){
			DBG(cout << 4 << endl;)
			cout << "Yes" << endl;
			continue;
		}
		
		set<ll> ans;
		ans.insert(a);
		
		while(1){
			ll seica = max((c - a) / (d % b) - 1,1LL);
			a += seica *(d % b);
			if(a > c && a < b){
				cout << "No" << endl;
				break;
			}
			if(a >= b)a-=b;
			if(ans.count(a)){
				cout << "Yes" << endl;
				break;
			}
			ans.insert(a);
		}
		
	}

	return 0;
}


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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

const ll MAX_N = 1e5 + 1;
ll C[MAX_N];

int main() {
    ll i, j, k;
    ll N;
    cin >> N;
    vll A(N);
    for(i = 0; i < MAX_N + 1; i++) {
        C[i] = 0;
    }
    for(auto &e : A) {
        cin >> e;
        C[e]++;
    }
    ll s = 0;
    for(i = 0; i < N; i++) {
        s += A[i];
    }
    ll Q;
    cin >> Q;
    for(i = 0; i < Q; i++) {
        ll b, c;
        cin >> b >> c;
        ll bcount = C[b];
        C[b] = 0;
        C[c] += bcount;
        s += bcount * (c - b);
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 4836
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };


int main(void) {
	long long int k, s;
	long long int total = 0;

	cin >> k >> s;

	LFOR(x, 0, k) {
		LFOR(y, 0, k) {
			if (s - x - y <= k&&s-x-y>=0) {
				total++;
			}
		}
	}

	cout << total << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

int main(void){
    int N,K;
    cin >>N>>K;
    vector<int> A(N);
    for(int a=0;a<N;a++){
        cin >>A[a];
    }
    for(int i=K;i<N ;i++){
        //cout <<A[i-(K)]<<endl;
        //cout <<A[i]<<endl;
        if(A[i-(K)]<A[i]){
            cout <<"Yes"<<endl;
        }else{
            cout <<"No"<<endl;
        }
    }
}

Measured memory_bytes: 3992
#include<iostream>
#include<cmath>
#include<cstdlib>

#define MOD 1000000007

using namespace std;

int main(void)
{
    long long n,m;
    
    cin>>n;
    cin>>m;

    if(abs(n-m) >= 2) {
	cout<<0<<endl;
    } else {
	long long sum;
	if(n != m)
	{
	    sum = 1;
	}
	else
	{
	    sum = 2;
	}
	for(long long i = m;i >= 1;i--)
	    sum = sum * i % MOD;
	for(long long i = n;i >= 1;i--)
	    sum = sum * i % MOD;

	cout<<sum<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
     
    using namespace std;
     int vec[3],vec2[3];
     
    int main(){
        bool flag = true;
        int n,m ,s ,c;

        cin >> n >> m;

        if(n == 1 && m == 0){
            cout<<0 << "\n";
            return 0;
        }
        for (int i = 0; i < m; i++)
        {
            cin >> s >> c;

            if(n > 1 && s == 1 && c == 0){
                flag = false;
                continue;
            }
            else if(c != vec[n-s] && vec[n-s]> 0){
                flag = false;
                continue;
            }
            vec[n-s] = c;
            vec2[n-s]++;
            

        }
        
        if(flag){
        
        if(vec[2] == 0 && vec[1] == 0 && n == 3)
            cout<< 100+vec[0]<< "\n";
        
        else if(vec[2] == 0 && n == 3)
            cout<< 100 + vec[1]*10 + vec[0]<< "\n";
        else if(vec[1] == 0 && n == 2)
            cout<< 10+vec[0]<< "\n";
        else if( n == 1)
            cout<< vec[0]<< "\n";
        
        else{
            cout<< 100*vec[2] + 10*vec[1] +vec[0] << "\n";
        }
            }
        else{
            cout<< "-1"<< "\n";
        }

       return 0;
    }

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

int main(){
	int n;
	cin >> n;
	vector<double> x(n);
	vector<double> y(n);
	rep(i, n) cin >> x.at(i) >> y.at(i);

	vector<int> a(n);
	rep(i, n) a.at(i) = i;

	double dist = 0;
	double num = 0;
	do{
		rep(i, n-1){
			int dx = x.at(a.at(i)) - x.at(a.at(i+1));
			int dy = y.at(a.at(i)) - y.at(a.at(i+1));
			dist += sqrt(dx*dx + dy*dy);
		}
		num++;
	}while(next_permutation(a.begin(), a.end()));

	cout << fixed << setprecision(10) << dist/num << endl;
	
}

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

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 
 		long n =fr.nextLong() ,ct[] ,sm ,dm ,md =1000000007l ;	int k =fr.nextInt() ,i ,j ;	ct =new long[k+1] ;	ct[k] =1l ;	sm =k ;
 		for (i =k-1 ; i>0 ; --i) {
 			ct[i] =pow(k/i , n , md) ;	for (j =i+i ; j<=k ; j+=i)	ct[i] =(ct[i] - ct[j] + md)%md ;
 			dm =(ct[i] * (1l * i))%md ;	sm =(sm + dm)%md ;
 		}
		op.println(sm) ;	op.flush();	op.close();
	}
	static long pow (long b , long e , long md) {
		if (e==0l)	return 1l;
		if (e==1l)	return b;
		long dm =pow(b,e/2l,md) ;	dm =(dm * dm)%md ;
		if ((e&1l)==1l)	dm =(b * dm)%md ;
		return dm ;
	}		
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements())) 
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}
				
			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}

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

int main() {
    string s, t;
    getline(cin, s);
    getline(cin, t);
    bool c = true;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            c = false;
            break;
        }
    }
    cout << (c ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <algorithm>

int main()
{
    int a, b, k;
    int p;
    scanf("%d %d %d", &a, &b, &k);
    for (p = std::min(a, b); k > 0; p--) {
	if ((a % p == 0) && (b % p == 0)) k--;
    }
    printf("%d\n", p+1);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for (int i = a ; i <= b ; i++) {
            String s = String.valueOf(i);
            if (s.substring(0, 1).equals(s.substring(4, 5)) && s.substring(1, 2).equals(s.substring(3, 4))) {
                count++;
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 39892
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int mod=1000000007;
    char s[51];
    while(scanf("%s",&s)!=EOF) {
        int len=strlen(s);
        int f=0;
        for (int i=0;i<len;++i) {
            if (f==0 and s[i]!='@') {
                printf("%c",s[i]);
            } else if (s[i]=='@') {
                f=1;
            } else if (f==1) {
                f=2;
            } else if (f==2) {
                for (int j=0;j<s[i-1]-'0';++j) {
                    printf("%c",s[i]);
                }
                f=0;
            }
        }
        printf("\n");
                
    }
    return 0;
}

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

int main() {
    int N, W;
    scanf("%d%d", &N, &W);
    int w[N + 1];
    int v[N + 1];
    for (int i = 1; i <= N; i++) {
        scanf("%d%d", &w[i], &v[i]);
    }

    int used[W + 1][N + 1];
    for (int i = 0; i <= W; i++) {
        for (int j = 1; j <= N; j++) used[i][j] = 0;
    }
    ll dp[W + 1];
    for (int i = 0; i <= W; i++) dp[i] = 0;
    for (int i = 1; i <= W; i++) {
        for (int j = 1; j <= N; j++) {
            if (i - w[j] >= 0) {
                if (dp[i - w[j]] + v[j] > dp[i] && used[i - w[j]][j] == 0) {
                    dp[i] = dp[i - w[j]] + v[j];
                    for (int k = 1; k <= N; k++) {
                        used[i][k] = used[i - w[j]][k];
                    }
                    used[i][j] = 1;
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i <= W; i++) {
        ans = max(ans, dp[i]);
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 40448
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    rep(i, S.size()){
        if(i%2 != 0) continue;
        cout << S[i];
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 592
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

ll H, W, n;
int a[100010], b[100010];
ll cnt[100010];

map<P, int> mp;

int main(void){
	cin>>H>>W>>n;
	for (int i = 0; i < n; i++) {
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
	}

	for (int i = 0; i < n; i++) {
		for (int dx = -2; dx <= 0; dx++) {
			for (int dy = -2; dy <= 0; dy++) {
				int ny = a[i] + dy, nx = b[i] + dx;
				if (ny < 0 || ny + 2 >= H || nx < 0 || nx + 2 >= W) continue;
				
				mp[{ny, nx}]++;
			}
		}
	}

	ll sum = (H - 2) * (W - 2);

	for (auto ite = mp.begin(); ite != mp.end(); ++ite) {
		for (int i = 1; i <= 9; i++) {
			if ((ite->second) == i) cnt[i]++;
		}
	}

	for (int i = 1; i <= 9; i++) sum -= cnt[i];

	cnt[0] = sum;
	for (int i = 0; i <= 9; i++) printf("%lld\n", cnt[i]);

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

#define int long long

using intpair = pair<int,int>;
signed main(){
    int N, M;
    cin >> N >> M;
    priority_queue<intpair, vector<intpair>, greater<intpair>> q;
    rep(i,N){
        int a, b; cin >> a >> b;
        q.push(intpair(a,b));
    }
    int req = M, res = 0;
    while(req > 0){
        int price = q.top().first, amount = q.top().second;
        res += price * min(amount,req);
        req -= amount;
        q.pop();
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int sum=0;
int main()
{
	int h,n;
	cin>>h>>n;
	for (int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		sum+=a;
	}
	if (sum>=h)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	int[] ary = new int[n];
    	boolean isPossible = true;
    	for(int i = 0; i < n; i++){
			ary[i] = -1;
		}
    	for(int i = 0; i < m; i++){
    		int s = sc.nextInt();
    		int c = sc.nextInt();
    		if(ary[s-1] == -1 || ary[s-1] == c){
    			ary[s-1] = c;
    		}else{
    			isPossible = false;
    		}
    	}
    	sc.close();
    	for(int i = 0; i < n; i++){
    		if(ary[i] == -1 && (i == 0 && n != 1)){
    			ary[i] = 1;
    		}else if(ary[i] == -1){
    			ary[i] = 0;
    		}
    	}
		if(n == 3 && ary[0] == 0){
			isPossible = false;
		}else if(n == 2 && ary[0] == 0){
			isPossible = false;
		}
    	String ans = "";
    	for(int i = 0; i < n; i++){
    		ans += ary[i];
    	}
    	System.out.println(isPossible ? ans : "-1");
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
int n, m;
ll a1[200005], a2[200005];
int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	cin>>n>>m;
	int from;
	ll tot=0ll;
	cin>>from;from--;
	for (int i=1; i<n; i++) {
		from%=m;
		int to;
		cin>>to;to--;
		if (from>to)
			to+=m;
		tot+=to-from;
		a1[from+1]++;
		a1[to+1]--;
		a2[from+1]+=from;
		a2[to+1]-=from;
		from=to;
	}
	for (int i=1; i<2*m; i++) {
		a1[i]+=a1[i-1];
		a2[i]+=a2[i-1];
	}
	ll ans=tot;
	for (int i=0; i<m; i++) {
		ll now=tot;
		ll x=a1[i], y=a2[i];
		now-=(x*i-x-y);
		x=a1[i+m], y=a2[i+m];
		now-=(x*(i+m)-x-y);
		ans=min(ans, now);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328