akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}


ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
} 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
//O(r)
ll combination_mod(ll n, ll r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    ll b=pow_mod(fact_mod(r), mod-2);
    return (a%mod)*(b%mod)%mod;
}
ll inv_mod(ll n){
    return pow_mod(n,mod-2);
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    vector<pair<ll,ll>> v;
    ll after=0;
    rep(i,n){
        pair<ll,ll> p;
        cin>>p.first>>p.second;

        if(p.first==0 and p.second==0){
            after++;
        }
        else{
            v.push_back(p);
        }
    }
    n-=after;

    // やくぶｎ，(分子，分母)　負なら，分子を負
    auto f=[](ll si,ll bo){
        if(si==0)return make_pair(0ll,1ll);
        if(bo==0)return make_pair(1ll,0ll);
        ll g=gcd(abs(si),abs(bo));
        si/=g;bo/=g;

        if(si>0 and bo>0) return make_pair(si,bo);
        if(si<0 and bo<0) return make_pair(abs(si),abs(bo));
        else return make_pair(-abs(si),abs(bo));
    };

    map<pair<ll,ll>,ll> cnt,cnt2;
    for(int i=0;i<n;i++){
        cnt[f(v[i].second,v[i].first)]++;  
        auto p=f(v[i].first,v[i].second);
        p.first=-p.first;
        cnt2[p]++;
    }

    vector<pair<ll,ll>> yabai;
    for(auto pp:cnt){
        auto p=pp.first;
        ll lf=pp.second;

        if(lf==0) continue;

        pair<ll,ll> target;
        if(p.first<0) target=make_pair(p.second,-p.first);
        else target=make_pair(-p.second,p.first);

        if(cnt.count(target)){

            if(cnt[target]) yabai.push_back(make_pair(lf,cnt[target]));
            cnt[target]=0;
        }
    }

    ll s=0;
    for(auto p:yabai) s+=p.first+p.second;
    ll ans=pow_mod(2,n-s);
    for(auto p:yabai){
        ll res=(pow_mod(2,p.first+p.second)+mod-(pow_mod(2,p.first)-1)*(pow_mod(2,p.second)-1)%mod)%mod;
        ans=ans*res%mod;
    }
    ans+=after-1;
    if(ans<0) ans+=mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 31296
#include<bits/stdc++.h>
using namespace std;
set<string> s;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string p;
		cin>>p;
		s.insert(p);
	}
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 19108
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n; cin >> n;
    V<int> A(n), B(n), C(n);
    loop (n, i) { cin >> A[i]; A[i]--; }
    loop (n, i) cin >> B[i];
    loop (n - 1, i) cin >> C[i];

    ll ans = 0;
    int prev = -2;
    loop (n, i) {
        ans += B[A[i]];
        if (A[i] == prev + 1) ans += C[prev];
        prev = A[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
N,M = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}

#構造入力
for i in range(1,M+1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)

#幅優先探索
dq =deque()
dq.append(1)
parent ={i:-1 for i in range(1,N+1)} #1につながっている＝答え
parent[1] =0
while dq:
    now =dq.popleft()
    for next in connection[now]:
        if parent[next] !=-1:
            continue
        else:
            parent[next] =now
            dq.append(next)
if -1 not in parent.values():
    del parent[1]
    print("Yes")
    print(*parent.values(),sep="\n")

Measured memory_bytes: 82668
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int[] dp = new int[2019];
        int[] tdp = new int[2019];
        int ans=0,cur;
        for(int i=0; i<s.length(); i++){
            cur = s.charAt(i)-'0';
            tdp[cur]++;
            for(int k=0; k<2019; k++){
                tdp[(10*k+cur)%2019] += dp[k];
            }
            ans+=tdp[0];
            for(int k=0; k<2019; k++){
                dp[k]=tdp[k];
                tdp[k]=0;
            }
        }
        System.out.println(ans);     

    }
}

//10 3 10 3

Measured memory_bytes: 35916
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],b[N],c[N],d[N],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(int k=0;k<29;k++)
	{
		int m=(1<<k),s=0;
		for(int i=1;i<=n;i++)
			c[i]=a[i]%(m*2);
		for(int i=1;i<=n;i++)
			d[i]=b[i]%(m*2);
		sort(d+1,d+n+1);
		for(int i=1;i<=n;i++)
		{
			int l1=lower_bound(d+1,d+n+1,m-c[i])-d,r1=lower_bound(d+1,d+n+1,m*2-c[i])-d;
			int l2=lower_bound(d+1,d+n+1,m*3-c[i])-d,r2=lower_bound(d+1,d+n+1,m*4-c[i])-d;
			if((r1-l1+r2-l2)&1)
				s^=1;
		}
		if(s)
			ans+=m;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6888
h, w = map(int, input().split())
s = [input() for i in range(h)]

if h == 1:
    if w == 1:
        if s[0][0] == "#":
            print("No")
            exit()
    else:
        for j in range(w):
            if s[0][j] == ".":
                continue
            else:
                if j == 0:
                    if s[0][1] == ".":
                        print("No")
                        exit()
                if j == w-1:
                    if s[0][w-2] == ".":
                        print("No")
                        exit()
                else:
                    if s[0][j-1] == "." and s[0][j+1] == ".":
                        print("No")
                        exit()

elif w == 1:
    for i in range(h):
        if s[i][0] == ".":
            continue
        else:
            if i == 0:
                if s[1][0] == ".":
                    print("No")
                    exit()
            elif i == h-1:
                if s[h-2][0] == ".":
                    print("No")
                    exit()
            else:
                if s[i- 1][0] == "." and s[i+1][0] == ".":
                    print("No")
                    exit()

else:
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                continue
            else:
                if i == 0:
                    if j == 0:
                        if s[0][1] == "." and s[1][0] == ".":
                            print("No")
                            exit()
                    elif j == w-1:
                        if s[0][w-2] == "." and s[1][w-1] == ".":
                            print("No")
                            exit()
                    else:
                        if s[i][j-1] == "." and s[i][j+1] == "." and s[i+1][j] == ".":
                            print("No")
                            exit()

                elif i == h-1:
                    if j == 0:
                        if s[h-1][1] == "." and s[h-2][0] == ".":
                            print("No")
                            exit()
                    elif j == w-1:
                        if s[h-1][w-2] == "." and s[h-2][w-1] == ".":
                            print("No")
                            exit()
                    else:
                        if s[h-1][j-1] == "." and s[h-1][j+1] == "." and s[h-2][j] == ".":
                            print("No")
                            exit()

                elif j == 0:
                    if s[i-1][0] == "." and s[i][1] == "." and s[i+1][0] == ".":
                            print("No")
                            exit()

                elif j == w-1:
                    if s[i-1][w-1] == "." and s[i][w-2] == "." and s[i+1][w-1] == ".":
                            print(".")
                            exit()

                else:
                    if s[i][j-1] == "." and s[i-1][j] == "." and s[i+1][j] == "." and s[i][j+1] == ".":
                            print("No")
                            exit()

print("Yes")



Measured memory_bytes: 3192
def resolve():
    '''
    code here
    '''
    import collections
    K = int(input())

    que = collections.deque(list(range(1,10)))

    cnt = 0
    
    while cnt < K:
        cnt += 1
        temp = que.popleft()

        push1 = temp*10 + temp%10 - 1
        push2 = temp*10 + temp%10
        push3 = temp*10 + temp%10 + 1

        if temp%10 != 0:
            que.append(push1)
        
        que.append(push2)

        if temp%10 != 9:
            que.append(push3)
        
    print(temp)



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 18992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ms(x, t) memset(x, t, sizeof(x))
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define mp make_pair
#define pb push_back
#define pf push_front
#define endl "\n"
typedef pair<int, int> pll;
typedef pair<int, pll> plll;
typedef vector<int> vl;
typedef vector<vector<int>> vvl;
typedef vector<pll> vpll;
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;

const int limit = 1e5 + 1;
const int inf = 1e7;
const int mod = 1e9 + 7;

int modExpItr(int a, int b)
{
  int ans = 1;
  while (b > 0)
  {
    if (b & 1)
    {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b = b >> 1;
  }
  return ans;
}

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vl a(n);
  vvl v(n, vl(62, 0));
  vvl postv(n, vl(62, 0));
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    int x = a[i];
    int j = 0;
    while (x)
    {
      v[i][j] = x & 1;
      x /= 2;
      j++;
    }
  }
  vl postSum(n, 0);
  for (int i = n - 2; i >= 0; i--)
  {
    postSum[i] = (postSum[i + 1] + (a[i + 1] % mod)) % mod;
    for (int j = 0; j < 62; j++)
    {
      postv[i][j] = postv[i + 1][j] + v[i + 1][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < n; i++)
  {
    ans = (ans % mod + postSum[i] % mod) % mod;
    for (int j = 0; j < 62; j++)
    {
      if (a[i] & 1LL << j)
      {
        ans = (ans % mod + (((n - 1 - i - 2 * postv[i][j]) % mod) * (modExpItr(2, j) % mod)) % mod) % mod;
      }
    }
    // trace1(ans);
  }
  cout << (ans + mod) % mod << endl;

  return 0;
}

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

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	int ans = 0;
	for(int i = 1; i < s.size(); i++)
		if(s[i] != s[i - 1]) ans++;
	cout << ans << '\n';
}


Measured memory_bytes: 512
n, m = map(int, input().split())
if n%2 == 1:
	for i in range(m):
		print(i+1, n-i)
else:
	ans = []
	M = n//2-1
	for i in range((M+1)//2):
		ans.append((i+1, n-i))
	for i in range((M+1)//2, M+1):
		ans.append((i+1, n-i-1))
	for i in range(m):
		print(*ans[i])

Measured memory_bytes: 72376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE 100100
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int a, b;
string s;

int main() {
	cin >> a >> b >> s;
	bool f = 1;
	rep(i, a) {
		if (!(s[i] >= '0'&&s[i] <= '9'))f = 0;
	}
	if (s[a] != '-')f = 0;
	FOR(i, a + 1, a + b + 1) {
		if (!(s[i] >= '0'&&s[i] <= '9'))f = 0;
	}
	if (f)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define repi(i,a) for(auto i = a.begin(); i!= a.end() ;++i) 
#define repdi(i,a) for(auto i = a.rbegin(); i!=a.rend();++i) 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) (int)a.size() 
#define all(a) a.begin(),a.end()
#define mod 998244353
#define limit 1000
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  

typedef vector<ll> vll;
typedef pair<ll,ll> pii;
typedef vector<pii> vpi;
typedef vector<vector<ll> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
ll dp[100005],a[100005],n,k;

ll ans(int i) {
	if(i==n-1) return 0;
	if(i>=n) return INF; 
	if(dp[i]!=-1) return dp[i];
	ll cnt = INF;
	rep(j,1,k+1) {
		cnt = min(cnt , abs(a[i]-a[i+j]) + ans(i+j));
	}
	return dp[i] = cnt ;
}

void solve() {
	cin >> n >> k;
	rep(i,0,n) cin >> a[i] ;
	fl(dp,-1);
	cout << ans(0) ;
}

int32_t main() {

    fast; 
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve() ;
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstring>
using namespace std;
string a, b = "CF";
int al, bl;
int main()
{
    cin >> a;
    al = a.length();
    for(int i = 0;i < al;i++)
        if(a[i] == b[bl]){
			bl++;
            if(bl == 2) break;
        }
    if(bl == 2) cout << "Yes"; 
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
mini=100001
maxi=0
for i in range(M):
    l,r=map(int,input().split())
    if l>maxi:
        maxi=l
    if r<mini:
        mini=r
res=mini-maxi+1
if res>0:
    print(mini-maxi+1)
else:
    print(0)

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

int main() {
  
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string color;
    cin >> color;
    if (color == "Y") {
      cout << "Four" << endl;
      break;
    }
    if (i == N-1) {
      cout << "Three" << endl;
      }
  }
  
}


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

int main(){
  string S;
  cin >> S;
  
  if(S == "Sunny")
    cout << "Cloudy" << endl;
  else if(S == "Cloudy")
    cout << "Rainy"<<endl;
  else 
    cout <<"Sunny" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define pb push_back
#define mp make_pair
#define NMAX 100005

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n;
ll cost;
int a[NMAX];
int main(){
   // freopen("C.inp","r",stdin);
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    int now=0;
    for(int i=1;i<=n;i++){
       cost+=abs(a[i]-now);
       now=a[i];
    }
    cost+=abs(now-0);
    now=0;
    for(int i=1;i<=n;i++){
     //   cout<<now<<" "<<a[i]<<'\n';
        if((a[i]>=now&&a[i+1]>=a[i])||(a[i]<=now&&a[i+1]<=a[i])){
            writeln(cost);
        }
        else{
            if((a[i]>=now&&a[i+1]>=now&&a[i+1]<=a[i])||(a[i]<=now&&a[i+1]>=a[i]&&a[i+1]<=now)) writeln(cost-2*abs(a[i+1]-a[i]));
            else  writeln(cost-2*abs(now-a[i]));
       //     else cout<<"B: ",writeln(cost-2*abs(a[i+1]-a[i]));
        }
        now=a[i];
    }
}



Measured memory_bytes: 1664
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        char[] chars = s.toCharArray();
        int numOfZero = 0;
        int numOfOne = 0;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '0') {
                numOfZero++;
            }
            if (chars[i] == '1') {
                numOfOne++;
            }
        }
        System.out.println(2 * Math.min(numOfOne, numOfZero));
    }

}

Measured memory_bytes: 27892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    set<ll> s;
    rep(i, n) {
        ll a; cin >> a;
        if(s.count(a)) s.erase(a);
        else s.insert(a);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 8092
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#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 ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


ll dp[110][110][500];
int main()
{
  REP(i, 110) REP(j, 110) REP(k, 500) dp[i][j][k] = -1;
  ll N, W;
  cin >> N >> W;
  vector<vector<ll>> v(4);
  ll w0, v0; cin >> w0 >> v0;
  v[0].PB(v0);
  REP(i, N - 1) {
    ll wi, vi;
    cin >> wi >> vi;
    v[wi - w0].PB(vi);
  }
  REP(i, 4) {
    if (! v[i].empty()) {
      sort(ALL(v[i]), greater<ll>());
      REP(j, v[i].size() - 1) v[i][j + 1] += v[i][j];
    }
  }

  ll ans = -1;
  auto ps = [&](ll x, ll y) { return y >= 1 ? v[x][y - 1] : 0; };
  REP(i, v[0].size() + 1) {
    REP(j, v[1].size() + 1) {
      REP(k, v[2].size() + 1) {
        REP(l, v[3].size() + 1) {
          if (w0 * (i + j + k + l) + j + 2*k + 3*l <= W)
            ans = max(ans, ps(0, i) + ps(1, j) + ps(2, k) + ps(3, l));
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 47488
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] nums = new int[n];
        int sum = 0;
        int costs = 0;
        for (int i = 0; i < n; i++) {
            int temp = scan.nextInt();
            nums[i] = temp;
            sum += nums[i];
        }
        double avg = Math.round((double)sum / n);
        for (int num : nums) {
            costs += Math.pow(num - avg, 2);
        }
        System.out.println(costs);
    }
}


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

using namespace std;

int main(void){
    int n, x;
    cin >> n >> x;
    
    vector<long long> a(n);
    
    for (int i = 0; i < n; i++) cin >> a[i];
    
    long long count = 0;
    
    if (a[0] > x) count += (a[0]- x), a[0] = x;
    
    for (int i = 0; i +1 < n; i++){
        
        if (a[i] + a[i+1] > x){
            count += (a[i] + a[i+1] - x);
            a[i+1] = x - a[i];
        }
    }
    cout << count << endl;
    
}


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

using namespace std;


int main()
{
    set<int> s;
    int n;
    cin >> n;
    int x;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if (s.find(x) != s.end())
        {
            cout << "NO\n";
            return 0;
        }
        s.insert(x);
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int m,int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(m,n / 2);
	x *= x;
	if (n % 2 == 1)x *= m;
	return x;
}
ll max(ll a, ll b) {
	if (a < b)return b;
	else return a;
}
struct edge { int to, cost; };


int main() {
	int n, m;
	int ans = 0;
	cin >> n >> m;
	hei(Pint) a(n);
	rep(i, 0, n)cin >> a[i].first >> a[i].second;
	sort(a.begin(), a.end());
	priority_queue<int, hei(int)> s;
	int i = 0;
	for (int j = 1;j<=m;j++) {
		for (; i< a.size();i++) {
			if (a[i].first == j) {
				s.push(a[i].second);
			}
			if(a[i].first>j) break;
		}
		if (!s.empty()) {
			ans += s.top();
			s.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1660
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        BigInteger now = new BigInteger("1");
        BigInteger lim = new BigInteger("1000000000000000000");
        BigInteger zz = new BigInteger("0");
        boolean f = true;
        for(int i=0;i<n;i++){
            BigInteger x = sc.nextBigInteger();
            if(x.compareTo(zz)==0) {
                f = true;
                now = zz;
              	break;
            }
          	if(f){
                now = now.multiply(x);
            }
            if(now.compareTo(lim)==1){
                f = false;
            }
            
        }
        if(f) System.out.println(now);
        else System.out.println(-1);
    }
}


Measured memory_bytes: 60172
#include <cstdio>
#include <cstdint>
#include <numeric>
#include <vector>
#include <algorithm>
#include <utility>

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

  intmax_t res = 0;
  for (intmax_t a = 1; a <= k; ++a)
    for (intmax_t b = 1; b <= k; ++b)
      for (intmax_t c = 1; c <= k; ++c)
        res += std::gcd(std::gcd(a, b), c);

  printf("%jd\n", res);
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
unsigned int randInt() {
    static unsigned int tx = 123456789, ty=362436069, tz=521288629, tw=88675123;
    unsigned int tt = (tx^(tx<<11));
    tx = ty; ty = tz; tz = tw;
    return ( tw=(tw^(tw>>19))^(tt^(tt>>8)) );
}

int main(){
    int N, K;
    cin >> N >> K;
    int Max_pair = (N - 1) * (N - 2) / 2;
    int max_E = N * (N - 1) / 2;
    
    if(Max_pair < K){
        cout << -1 << endl;
    }else{
        vector<pair<int, int>> ans;
        for(int i = 1; i <= N - 1; i++){
            for(int j = i + 1; j <= N; j++){
                ans.push_back(make_pair(i, j));
            }
        }
        int Na = ans.size();
        int Edge = max_E - K;
        cout << Edge << endl;
        for(int i = 0; i < Edge; i++){
            cout << ans[i].first << " " << ans[i].second << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 384
from collections import deque

n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  graph[a-1].append(b)
  graph[b-1].append(a)
  
seen = [False]*n
finished = [False]*n
count = 0

def dfs(v):
  global graph
  global seen
  global count
  
  seen[v] = True
  if seen == [True]*n:
    count += 1

  for next_v in graph[v]:
    if seen[next_v-1]: 
      continue
    dfs(next_v-1)
    
  seen[v] = False
  	
dfs(0)
print(count)

Measured memory_bytes: 44636
# https://atcoder.jp/contests/dp/tasks/dp_a
# A - Frog 1

N=int(input())
H=list(map(int,input().strip().split(" ")))


def find(H):
    if len(H) == 1:
        return 0

    dp = [0] * len(H)
    dp[1] = abs(H[1] - H[0])
    for i in range(2, len(H)):
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
    return dp[-1]


#H = [10, 30, 40, 20]
print(find(H))


Measured memory_bytes: 13980
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	points := make(Points, n)
	edges := make([][]Edge, n)
	for i := 0; i < n; i++ {
		points[i].x = getNextInt64(scanner)
		points[i].y = getNextInt64(scanner)
		points[i].s = points[i].x
		points[i].i = i
	}

	sort.Sort(points)

	for i := 0; i < n-1; i++ {
		cost := points[i+1].x - points[i].x
		edges[points[i].i] = append(edges[points[i].i], Edge{
			i:    points[i+1].i,
			cost: cost,
		})
		edges[points[i+1].i] = append(edges[points[i+1].i], Edge{
			i:    points[i].i,
			cost: cost,
		})
		points[i].s = points[i].y
		points[i+1].s = points[i+1].y
	}
	sort.Sort(points)

	for i := 0; i < n-1; i++ {
		cost := points[i+1].y - points[i].y
		edges[points[i].i] = append(edges[points[i].i], Edge{
			i:    points[i+1].i,
			cost: cost,
		})
		edges[points[i+1].i] = append(edges[points[i+1].i], Edge{
			i:    points[i].i,
			cost: cost,
		})
	}

	var ans int64
	color := make([]int, n)
	var h EdgeHeap
	heap.Init(&h)
	heap.Push(&h, Edge{
		i:    0,
		cost: 0,
	})

	for h.Len() > 0 {
		p := heap.Pop(&h).(Edge)
		if color[p.i] == 2 {
			continue
		}
		color[p.i] = 2
		if p.i != 0 {
			ans += p.cost
		}
		for i := 0; i < len(edges[p.i]); i++ {
			if color[edges[p.i][i].i] == 2 {
				continue
			}
			heap.Push(&h, Edge{
				i:    edges[p.i][i].i,
				cost: edges[p.i][i].cost,
			})
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// Point ...
type Point struct {
	i       int
	x, y, s int64
}

// Edge ...
type Edge struct {
	i    int
	cost int64
}

type EdgeHeap []Edge

func (h EdgeHeap) Len() int           { return len(h) }
func (h EdgeHeap) Less(i, j int) bool { return h[i].cost < h[j].cost }
func (h EdgeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *EdgeHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(Edge))
}

func (h *EdgeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

// Points ...
type Points []Point

func (a Points) Len() int           { return len(a) }
func (a Points) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Points) Less(i, j int) bool { return a[i].s < a[j].s }

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

func minint(a int, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 27776
#include <iostream>
#include <math.h>
#include <cmath>
using namespace std;

int main() {
	
int N, D;
  	int count = 0;
  	cin >> N >> D;

  	for (int i = 0; i < N; i++) {
    	long X, Y;
      	cin >> X >> Y;
      
      	double A = abs(sqrt((X*X) + (Y*Y)));
      	
      	if (A <= D) {count++;}
    }
  
  	cout << count << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string::iterator it;
int P,Q,R;

int formula(){
  ++it;
  switch(*it){
  case '-':
    return 2-formula();
  case 'P':
    return P;
  case 'Q':
    return Q;
  case 'R':
    return R;
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;

  case '(':
    int form1 = formula();
    int form2;

    ++it;
    switch(*it){
    case '*':
      form2 = formula();
      ++it;
      return min(form1,form2);
    case '+':
      form2 = formula();
      ++it;
      return max(form1,form2);
    }
  }

  return 0;
}

int main(){
  string str;

  while(cin >> str,str != "."){
    int cnt = 0;

    for(int i = 0 ; i < 3 ; i++){
      for(int j = 0 ; j < 3 ; j++){
	for(int k = 0 ; k < 3 ; k++){
	  it = str.begin()-1;
	  P = i, Q = j , R = k;
	  if(formula() == 2) cnt++;
	}
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1188
from collections import Counter


def main():
    N, K, Q = [int(i) for i in input().split()]
    A = [int(input()) for _ in range(Q)]
    counter = Counter(A)
    scores = [K - Q] * N
    for guest, win in counter.items():
        guest -= 1
        scores[guest] += win
    ans = ["Yes" if i > 0 else "No" for i in scores]
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 70104
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n,x,i,j;
  cin>>n;int a[n+1][3],dp[n+1][3];
  for(i=0;i<n;i++)
  {
    for(j=0;j<3;j++)
    {  
    	cin>>a[i][j];
    }
  }dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];x=max(max(dp[0][0],dp[0][1]),max(dp[0][1],dp[0][2]));
  for(i=1;i<n;i++)
  {
      dp[i][0]=max(dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0]);
      dp[i][1]=max(dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1]);
      dp[i][2]=max(dp[i-1][0]+a[i][2],dp[i-1][1]+a[i][2]);
      x=max(max(dp[i][0],dp[i][1]),max(dp[i][1],dp[i][2]));
  }
  cout<<x;
  return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

#define N_MAX 200
#define C_MAX 29

int main(void)
{
	int n;
	long b = (1L << C_MAX) - 1L;
	int c = C_MAX;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		long a;
		scanf("%ld", &a);
		while (a & b) {
			b >>= 1;
			if (!(--c)) goto zero;
		}
	}
zero:
	printf("%d\n", c);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string str;
		int base[5]={0};
		while(1){
			cin>>str;
			if(str=="HIT"){
				for(int j=3;j>=1;j--){
					if(base[j]==1){
						base[j+1]++;
						base[j]--;
					}
				}
				base[1]++;
			}else if(str=="HOMERUN"){
				for(int j=1;j<=3;j++){
					if(base[j]==1){
						base[4]++;
						base[j]--;
					}
				}
				base[4]++;
			}else if(str=="OUT"){
				base[0]++;
			}
			if(base[0]==3) break;
		}
		cout<<base[4]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#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() {
  string s, t;
  cin >> s;
  char pre = s[0];
  t.push_back(pre);
  for (int i = 1; i < s.size(); i++) {
    if (pre != s[i]) {
      pre = s[i];
      t.push_back(pre);
    }
  }
  cout << t.size() - 1 << endl;
  return 0;
}


Measured memory_bytes: 3760
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

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

using namespace std;

int main()
{
	int h,w;
	cin>>h>>w;
	
	rep(i,h)
	{
		rep(j,w)
		{
			string s;
			cin>>s;
			
			if(s=="snuke")
			{
				printf("%c%d\n",'A'+j, i+1);
			}
		}
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

int A[100000];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X; cin >> X;
	int t = sqrt(2 * X);
	rep(i, 0, 100000) {
		A[i] = i*(i + 1) / 2;
	}
	auto a = lower_bound(all(A), X);
	cout << a - A << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
	int h,n,x,i,j,k,m=0;
	
	for(h=1;h>0;h++)
	{
	
		scanf("%d %d",&n,&x);
		
	
	

	for(i=1;i<=n-2;i++)
		{
			
			for(j=i+1;j<=n-1;j++)
			{
			
				for(k=j+1;k<=n;k++)
				{
					if(i+j+k==x)
					{
						m++;
					}
				}
			
			}
			
	    }

	if(n==0&&x==0)
	{
		h = h*(-1);
	}
	else
	{
		printf("%d\n",m);
		m=0;
	}
	
  }


	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
//#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  int a, b;
  double t;
  cin >> a >> b >> t;
  
  cout << b * int(t/a) << endl;
}

Measured memory_bytes: 256
N = int(input())
nums=[int(input()) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX+1)
dp[0] = 1
for num in nums:
  for i in range(MAX+1)[::-1]:
    if dp[i] == 1 and (i + num) <= MAX+1:
      dp[i+num] = 1
ans = 0
for i in range(MAX+1):
  if dp[i] == 1 and i%10 != 0:
    ans = i
print(ans)


Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll a[n];
    rp(i,n)
    cin >>a[i];
    set<ll> setik;
    ll free = 0;
    rp(i,n){
        if(a[i]> 3199) free++;
        else if(a[i] > 2799) setik.insert(1);
        else if(a[i] > 2399) setik.insert(2);
        else if(a[i] > 1999) setik.insert(3);
        else if(a[i] > 1599) setik.insert(4);
        else if(a[i] > 1199) setik.insert(5);
        else if(a[i] > 799)  setik.insert(6);
        else if(a[i] > 399)  setik.insert(7);
        else  setik.insert(8);
    }
    ll mn,mx;
    if(free ==0){
            mn = setik.size();
            mx = setik.size();
    }
    if(free > 0) {
        mn = setik.size();
        if(mn < 1) mn = 1;
        mx = setik.size()+free;
    }
    cout << mn << " " << mx <<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main()
{
	int n;
	while(cin >> n,n != -1)
	{
		double q = n/2.0;

		while(fabs((q*q*q) - n) >= 0.00001*n)
		{
			q = q - ((q*q*q - n) / (3*q*q));
		}

		cout << fixed;
		cout.precision(6);
		cout << q << endl;
			
	}
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

struct edge{
    ll from ,to,cost;
};

edge es[MAX];
ll d[MAX];
ll N,E,ans;
bool negative[MAX];


void bellmanford(ll s){
    rep(i,N){
        d[i]=LLINF;
        negative[i]=false;
    }
    d[s]=0;
    rep(loop,N){
        rep(i,E){
            edge e=es[i];
            if(d[e.from]!=-LLINF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }

    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>E;
    rep(i,E){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;c=-c;
        es[i]={a,b,c};
    }
    bellmanford(0);
    ans=d[N-1];
    rep(loop,N){
        rep(i,E){
            edge e=es[i];
            if(d[e.from]!=-LLINF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                negative[e.to]=true;
            }
            if(negative[e.from]==true){
                negative[e.to]=true;
            }
        }
    }
    if(negative[N-1]) cout<<"inf"<<endl;
    else cout<<-ans<<endl;
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int a, b; cin >> a >> b;
    int c = 0;
    rep3(i, a, b + 1) {
        string s = to_string(i);
        string t = s;
        reverse(all(t));
        if (s == t) c++;
    }
    out(c);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, s;
  cin >> n >> s;

  long long ans = 0;
  vector<int> dp(s + 5, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;

    for (int j = s-x; j >= 1; --j) {
      dp[j + x] = (dp[j + x] + dp[j]) % M;
    }
    if (x <= s) dp[x] += i;
    ans = (ans + dp[s]) % M;
  }

  cout << ans << '\n';

}






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

int main(){	
	long long K;
	long long M;
	scanf("%lld",&M);
	scanf("%lld",&K);
	if (1<<M <= K || (M == 1 && K == 1)) {
		cout << "-1" << endl;
		return 0;
	}
	if (M == 1 && K == 0) {
		{
			cout << "1 1 0 0" << endl;
			return 0;
		}
	}
	rep(i, 1<<M) {
		if (i == K) continue;
		cout << i << " ";
	}
	cout << K << " ";
	rep(i, 1<<M) {
		if ((1<<M)-1-i == K) continue;
		cout << (1<<M)-1-i << " ";
	}
	cout << K << endl;

	return 0;
}



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

using namespace std;

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	/*
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	*/
	int n,t;
	cin >> n >> t;
	int smallest = 1000000;
	int sol = -1;
	for(int i = 0; i < n; i++){
		int a,b;
		cin >> a >> b;
		if(b <= t && a < smallest){
			sol = a;
			smallest = a;
		}
	}
	if(sol == -1) cout << "TLE";
	else cout << sol;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	int A[50];
	rep(i, N) cin >> A[i];

	int kotae = 0;
	rep(i, N) rep(j, i) {
		kotae += A[i] * A[j];
	}
	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define N 1000005

using namespace std;

void solve()
{
	string s, t;
	cin >> s >> t;
	ll ans = INF;
	for (int i = 0; i < s.length(); ++i)
	{
		ll temp = 0;
		for (int j = i; j < i + t.length() && j < s.length(); ++j)
		{
			temp += (s[j] != t[j - i]);
			if (j - i + 1 == t.length())ans = min(temp, ans);
		}

	}
	cout << ans << endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3620
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll point = 0;
    v memo(n, 0);
    rep(i, k)
    {
        if(t[i] == 'r') point += p;
        if(t[i] == 's') point += r;
        if(t[i] == 'p') point += s;
        memo[i] = 1;
    }
    auto add = [&](int i){
        if(t[i] == 'r')
            { 
                point += p;
            }else if(t[i] == 's')
            {
                point += r;
            }else{
                point += s;
            }
            memo[i] = 1;
    };
    rep(i, n)
    {
        if(i < k) continue;
        if(memo[i - k] == 0 && t[i] == t[i - k])
        {
            add(i);
        }else if(t[i] != t[i - k]){
            add(i);
        }
    }
    cout << point << endl;
}

Measured memory_bytes: 896
s = input()
for i in range(len(s)-1):
    s1 = s[i]
    s2 = s[i+1]
    if s1 == s2:
        print(i+1, i+2)
        exit()
    if i < len(s) - 2:
        s3 = s[i+2]
        if s1 == s3:
            print(i+1, i+3)
            exit()
print('-1 -1')

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

string s,t;
long long ans;
int idx,id;
vector<int> abc[30];

int main(){
	cin>>s>>t;
	int ss = s.length();
	for(int i =0;i<ss;i++){
		abc[s[i]-'a'].push_back(i);
	}
	int id = -1;
	int pan = t.length();
	ans = 0;
	for(int i =0;i<pan;i++){
		int now = t[i]-'a';
		if(abc[now].size()==0){
			printf("-1\n");
			return 0;
		}
		
		idx = lower_bound(abc[now].begin(),abc[now].end(),id+1)-abc[now].begin();
		
		if(idx==abc[now].size()){
			idx = lower_bound(abc[now].begin(),abc[now].end(),0)-abc[now].begin();
			ans+= ss-id + abc[now][idx];
		} else {
			ans+= abc[now][idx]-id;
		}
		id = abc[now][idx];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>

using namespace std;

int main(){
    cin.tie();
    ios::sync_with_stdio(false);
    
    int N,a[10001]={},ans=0;

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

    for(int i=0;i<N;i++){
        while(a[i]%2==0){
            a[i] /= 2;
            ans++;
        }
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define _for(it, a) \
  for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)

using namespace std;

vector<int> a;
map<int, int> initial;
map<int, int> final;

int main() {
  int N, x;
  cin >> N;
  for (int n = 0; n < N; ++n) {
    scanf("%d", &x);
    initial[x] = n;
    a.pb(x);
  }
  sort(all(a));
  int e = 0;
  int o = 0;
  int k = 0;
  for (int n = 0; n < N; ++n) {
    final[a[n]] = n;
    if (initial[a[n]] % 2 == 0 && final[a[n]] % 2 == 1)
      ++k;
    else if (initial[a[n]] % 2 == 1 && final[a[n]] % 2 == 0)
      ++k;
  }
  cout << k / 2 << endl;
  return 0;
}

// Built using Sublime-CHelper plug-in (beta)


Measured memory_bytes: 9976
import numpy as np

N = int(input())
A = [0]*N
X = np.zeros([N,N],dtype=int)
Y = np.zeros([N,N],dtype=int)

for n in range(N):
    A[n] = int(input())
    for a in range(A[n]):
        X[n][a], Y[n][a] = list(map(int,input().split()))

ans = 0

for bits in range( 1, 1<<N ):
    ok = True
    for i in range( 0, N ):
        if not ok:
            break
        if not ( bits & (1 << i) ):
            continue
        for j in range( 0, A[i] ):
            if (( bits >> (X[i][j]-1) ) & 1) ^ Y[i][j]:
                ok = False
                break
    if ok:
        ans = max( ans, (str(bin(bits))[2:]).count('1'))
        
print(ans)       

Measured memory_bytes: 12516
/**
 *    author:  tourist
 *    created: 08.01.2020 23:04:05       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> cnt(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    ++cnt[x];
    ++cnt[y];
  }
  for (int i = 0; i < n; i++) {
    if (cnt[i] % 2 == 1) {
      cout << "NO" << '\n';
      return 0;
    }
  }  
  cout << "YES" << '\n';
  return 0;
}


Measured memory_bytes: 640