akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>

using namespace std;
using ullong = long long;

ullong choice(int n,int m){
  ullong p = 1;
  for(int i=1;i<=m;++i){
    p = p*(n-i+1)/i;
  }
  return p;
}

int main(){
  int n,p;
  cin >> n >> p;
  int oddnum=0,evennum=0;
  for(int i=0;i<n;++i){
    int a;
    cin >> a;
    if(a%2) oddnum++;
    else evennum++;
  }

  ullong pat = 0;
  for(int i=p;i<=oddnum;i+=2){
    for(int j=0;j<=evennum;++j){
      pat += choice(oddnum,i)*choice(evennum,j);
    }
  }

  cout << pat << endl;

  return 0;
}



Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
avg = sum(X)//N
aa = []
for i in range(2):
  avg = avg + i
  a = 0
  for j in range(N):
    a += (X[j] - avg)**2
  aa.append(a)
print(min(aa))

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

int main()
{
    string a,b,c;
    char n,m,h;
    cin>>a>>b>>c;
   n=a[0] ;
   m=b[0];
   h=c[0];
   h-=32;
   n-=32;
   m-=32;
             cout<<n<<m<<h<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	static char s[4], t[4];
	int cnt;

	scanf("%s%s", s, t);
	cnt = 0;
	if (s[0] == t[0])
		cnt++;
	if (s[1] == t[1])
		cnt++;
	if (s[2] == t[2])
		cnt++;
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define MAX 2000005

int C[MAX], n, A[MAX], B[MAX];
void countingSort(int A[], int B[], int k)
{
    for(int i=0; i<=k; i++)
        C[i] = 0;
    for(int j=1; j<=n; j++)
        C[A[j]]++;
    for(int i=1; i<=k ;i++)
        C[i] += C[i-1];
    for(int i=n; i>=1; i--)
    {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
}
int main()
{
    cin >> n;
    cin >> A[1];
    int max = A[1];
    for(int i=2; i<=n; i++)
    {
        cin >> A[i];
        if(max < A[i])
            max = A[i];
    }
    countingSort(A,B,max);
    for(int i=1; i<=n-1; i++)
        cout << B[i] << " ";
    cout << B[n] << endl;
    return 0;
}

Measured memory_bytes: 18736
n = int(input())
b = list(map(int, input().split()))

a = [0 for _ in range(n)]
a[0] = b[0]
for i in range(1,n-1):
    a[i] = min(b[i-1], b[i])
a[n-1] = b[n-2]
print(sum(a))

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

using namespace std;

int n;
int square[15][15];

int solve(int x, int y, int cnt) {

    if(cnt > n * n) return 0;

    if(square[y][x]) {
        solve(n - 1 - ((n - 1 - x) + 1) % n, (y + 1) % n, cnt);
    } else {
        square[y][x] = cnt;
        solve((x + 1) % n, (y + 1) % n, cnt + 1);
    }

}

int main() {

    while(cin >> n, n) {

        memset(square, 0, sizeof(square));

        solve(n / 2, n / 2 + 1, 1);

        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                printf("%4d", square[i][j]);
            }
            cout << endl;
        }

    }

}

Measured memory_bytes: 1192
n, k = map(int, input().split(" "))
dices_e = [float((e+1)/2) for e in list(map(int, input().split(" ")))]
e = max_e = sum(dices_e[:k])
for i in range(1, n-k+1):
  e = e - dices_e[i-1] + dices_e[i+k-1]
  if e>max_e:
    max_e = e

print(max_e)

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



int N, M, X;

int main(){
	cin >> N >> M >> X;
	int A[M];
	int l=0, r=0;
	for(int i=0;i < M;i++){
		cin >> A[i];
		if(A[i] < X)l++;
		else if(A[i] > X)r++;
	}
	cout << min(l,r) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define endl "\n"
#define sz(u) (int)(u.size())
#define L(x)(2*x)
#define R(x)(2*x+1)
#define M(x,y)((x+y)/2)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve(){
    ll n,k;
    cin>>n>>k;
    ull t[n+1];
    bool vis[n+1];
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++) cin>>t[i];
    ull pos=1;
    vis[1]=1;
    bool hh=false;
    while(k>0){
        k--;
        pos=t[pos];
        if(vis[pos]){
            hh=true;
            break;
            }
        vis[pos]=1;
    }
    if(hh){
    memset(vis,0,sizeof(vis));
    ull cnt=1,temp_pos=pos;
    while(t[temp_pos]!=pos){
            cnt++;
        temp_pos=t[temp_pos];

    }
    k%=cnt;
    while(k>0){
        k--;
        pos=t[pos];
    }
    cout<<pos;
    }
    else{
        cout<<pos<<endl;
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //int t;
    //cin>>t;
    //while(t--){
        solve();
        //cout<<endl;
    //}
}



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

count = 0
i = 1
position = 1
position_list = [1]
position_history = [0] * N
start_loop = 0
def last():
  k = (K - start_loop) % (count - start_loop)
  print(position_list[start_loop+k])

while i > 0:
  position = A[position-1]
  position_history[position-1] += 1
  count += 1
  if count == K:
    print(position)
    break
  elif position_history[position-1] > 1:
    start_loop = position_list.index(position)
    position_list.append(position)
    last()
    break
  else:
    position_list.append(position)
  	




Measured memory_bytes: 32400
#include <iostream>
#include<cstring>

using namespace std;
int a[200007];
//WWRRWRR
int main()
{
    int n; cin >> n;
    int k; cin >> k;
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    int l=1, r=1000000007;
    while(l<r) {
        int m=(l+r)>>1;
        long long ans=0;
        for(int i=0; i<n; i++) {
            ans += (1ll*a[i]+m-1)/m-1;
            if(ans>k) break;
        }
        if(ans>k) {
            l=m+1;
        } else {
            r=m;
        }
    }
    cout << r << '\n';
}


Measured memory_bytes: 4316
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;




int main()
{
	IOS;
	ll n, x, t;
	cin >> n >> x >> t;
	if (n % x == 0)cout << (n / x)*t;
	else cout << (n / x + 1)*t;












}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
int main()
{
    int h1,m1,h2,m2,s,k,l;
    cin>>h1>>m1>>h2>>m2>>s;
    k=((h2-h1)*60) - (m1-m2);
    l=k-s;
    if(l<=0) cout<<"0"<<endl;
    else cout<<l<<endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>
#include <iomanip>
#include <bitset>

#define INF 1000000000
#define Inf 1000000000000000000
#define mp make_pair
#define pb push_back
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int n, a, b, vis[200100];
vi adjList[200100];

ii dfs(int u, int l) {
  vis[u] = true;
  ii best = mp(u, l);
  for(int i = 0; i < adjList[u].size(); ++i) {
    int v = adjList[u][i];
    if (!vis[v]) {
      ii cur = dfs(v, l + 1);
      if (cur.second > best.second) {
        best = cur;
      }
    }
  }
  return best;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10);

  cin >> n;

  for(int i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    adjList[a].pb(b);
    adjList[b].pb(a);
  }
  ii x = dfs(1, 0);
  memset(vis, 0, sizeof(vis));
  int d = dfs(x.first, 0).second;
  if (d == 0) cout << "First" << endl;
  else if (d == 1) cout << "Second" << endl;
  else if ((d - 1) % 3 == 0) cout << "Second" << endl;
  else cout << "First" << endl;

  return 0;
}


Measured memory_bytes: 24448
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
long long dis[100005];
long long vis[100005];
long long y[100005];
long long z[100005];
int main()
{
    long long C,N,form=0;
    long long you=0,temp=0,zuo=0,ymax=0,zmax=0;
    scanf("%lld %lld",&N,&C);
    for(int i=1; i<=N; i++)
    {
        scanf("%lld %lld",&dis[i],&vis[i]);
        temp=vis[i]+temp-(dis[i]-form);
        form=dis[i];
        if(ymax<temp-dis[i])
            ymax=temp-dis[i];
        y[i+1]=ymax;
        if(you<temp)
            you=temp;
    }
    y[1]=0;
    temp=0;
    form=C;
    for(int i=N; i>0; i--)
    {
        temp=vis[i]+temp-(form-dis[i]);
         form=dis[i];
        if(zmax<temp-(C-dis[i]))
            zmax=temp-(C-dis[i]);
        z[i-1]=zmax;
        if(zuo<temp+y[i])
            zuo=temp+y[i];
    }
    z[N]=0;
    temp=0;
    form=0;
    for(int i=1; i<=N; i++)
    {
        temp=vis[i]+temp-(dis[i]-form);
        form=dis[i];
        if(you<temp+z[i])
            you=temp+z[i];
    }
    if(zuo>you)
        printf("%lld\n",zuo);
    else
        printf("%lld\n",you);
    return 0;
}


Measured memory_bytes: 3328
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    from itertools import accumulate
    Sa = list(accumulate(A))
    Sb = list(accumulate([0] + B))
    ans = 0
    for i in range(N):
        cur = Sa[i] + (Sb[N] - Sb[i])
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    anumlist = []
    for i in range(n):
        anumlist.append([a[i], i])
    anumlist.sort(reverse = True)
    dp = [[0] * (n + 1) for i in range(n+1)]
    for i in range(n):
        for j in range(n - i):
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + anumlist[i + j][0] * (anumlist[i + j][1] - i))
            dp[i][j + 1] = max(dp[i][j+1],dp[i][j] + anumlist[i + j][0] * ((n - 1 - j) - anumlist[i + j][1]))
            
    ans = 0
    for i in range(n+1):
        ans = max(ans, dp[i][n - i])
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 96192
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 101010;
bitset<N> isPrime;

void sieve() {
	isPrime.set();
	For(i, 2, N) if (isPrime[i])
		for (int j = i + i; j < N; j += i)
			isPrime[j] = false;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	sieve();
	int n;
	cin >> n;
	while (!isPrime[n]) n++;
	cout << n << '\n';
}



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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 998244353;
const ll LINF = 1e18;

ll X, Y, Z, K;
vector<ll> A, B, C;
vector<ll> AB, ABC;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    cin >> X >> Y >> Z >> K;
    A.resize(X);
    B.resize(Y);
    C.resize(Z);
    AB.resize(X * Y);
    ABC.resize(K * K);
    VECCIN(A);
    VECCIN(B);
    VECCIN(C);
    REP(i, X) REP(j, Y) { AB[i * Y + j] = A[i] + B[j]; }
    sort(All(AB), greater<ll>());
    REP(i, min(X * Y, K)) REP(j, Z) {
        ABC[i * min(X * Y, K) + j] = AB[i] + C[j];
    }
    sort(All(ABC), greater<ll>());
    REP(i, K) { cout << ABC[i] << "\n"; }
    return 0;
}


Measured memory_bytes: 78592
#include <stdio.h>

int a[99999];

int main(){
  int n,i,j,b=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  for(i=0;i<n;i++){
    if(i%2==0){
      b+=a[i];
    } else {
      b-=a[i];
    }
  }
  printf("%d ",b);
  
  for(i=1;i<n;i++){
    b-=a[i-1];
    b=0-b;
    b+=a[i-1];
    
    printf("%d ",b);
  }
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#define ll long long
#define INF 10000000

using namespace std;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(i%2==0){
            cout << s[i];
        }
    }
}

Measured memory_bytes: 592
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int k; cin >> k;
	int num = (7 % k), ans = 1;
	while (true) {
		if ((num % k) == 0) {
			cout << ans;
			break;
		}
		if (ans > 1e8) {
			cout << -1;
			break;
		}
		num *= 10;
		num += 7;
		if (num >= k) num %= k;
		ans++;
	}

	return 0;
}

Measured memory_bytes: 3196
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int h,w,d;
int main() {
	scanf("%d%d%d",&h,&w,&d);
	rep(i,0,h) {
		rep(j,0,w) {
			int p=(i+j)/d%2,q=(i+w-j)/d%2;
			putchar("RYGB"[p*2+q]);
		}
		puts("");
	}
}


Measured memory_bytes: 384
//you never give up.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define v32 vector<int>
#define v64 vector<ll>

using namespace std;

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

    int count = 0;
    while (1)
    {
        if (b <= a)
        {
            b = b * 2;
            count++;
            continue;
        }
        if (c <= b)
        {
            c = c * 2;
            count++;
        }
        else
        {
            break;
        }
    }
    if (count <= k)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main()
{
    string s;cin >>s;
    reverse(all(s));
    ll n=(ll)s.size();
    ll m=2019;
    V memo(m,0);
    ll tmp=1,d=0;
    ll ans=0;
    rep(i,n){
        memo[d]++;
        d+=(s[i]-'0')*tmp;
        d%=m;
        tmp*=10;tmp%=m;
        ans+=memo[d];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
long long A,B,C;
int main()
{
	scanf("%lld%lld%lld",&A,&B,&C);
	if (A%2==0||B%2==0||C%2==0) cout << 0 << endl;
	else cout << min(min(A*B,A*C),B*C) << endl;
} 

Measured memory_bytes: 256
A,B,C = map(int,input().split())
K = int(input())
i = 0
while True:
    if B > A:
        break
    else:
        B = B * 2
    i += 1
q = 0
while True:
    if C > B:
        break
    else:
        C = C * 2
    q += 1
if (i + q) > K:
    print("No")
else:
    print("Yes") 


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[60];
void power()
{
    powe[0]=1;
    REP(i,1,15)
    {
        powe[i]=2*powe[i-1];
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	ll a=1,b=1,c=1,d=1;
	REP(i,1,r1+1)
	{
		a=mymod(a*i,num);
	}
	REP(i,1,c1+1)
	{
		b=mymod(b*i,num);
	}
	REP(i,1,r2+2)
	{
		c=mymod(c*i,num);
	}
	REP(i,1,c2+2)
	{
		d=mymod(d*i,num);
	}
	ll e=1,f=1,g=1,h=1;
	REP(i,1,r2+c2+3)
	{
		e=mymod(e*i,num);
	}
	REP(i,1,r1+c1+1)
	{
		f=mymod(f*i,num);
	}
	REP(i,1,r1+c2+2)
	{
		g=mymod(g*i,num);
	}
	REP(i,1,r2+c1+2)
	{
		h=mymod(h*i,num);
	}
	ll ans=0;
	ll temp=modInverse(mymod(c*d,num),num);
	ans+=mymod(e*temp,num);
	temp=modInverse(mymod(a*b,num),num);
	ans+=mymod(f*temp,num);
	temp=modInverse(mymod(a*d,num),num);
	ans-=mymod(g*temp,num);
	temp=modInverse(mymod(b*c,num),num);
	ans-=mymod(h*temp,num);
	cout<<mymod(ans,num);
	return 0;
}

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


int GetDigit(int num){
    return log10(num) + 1;
}


int main() {
  int N;
  cin >> N;
  string march = "MARCH";
  vector<ll> cnt(march.size(), 0);
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < march.size(); ++j) {
      if (s.at(0) == march.at(j)) {
        ++cnt.at(j);
        break;
      }
    }
  }
  ll result = 0;
  for (int i = 0; i < 3; ++i) {
    for (int j = i + 1; j < 4; ++j) {
      for (int k = j + 1; k < 5; ++k) {
        result += cnt.at(i) * cnt.at(j) * cnt.at(k);
      }
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 384
//
//  main.cpp
//  競技20190629

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
const int  MOD=1000000007;
const int  INF=2000000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD){;}
    return 0;
}

#define pf printf
#define sf scanf
#define in(x) {cin >> (x);}
#define inarray(array,min,max) FOR(i,min,max){in(array[i]);}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){in(arrayA[i]);in(arrayB[i]);}
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
#define br printf("\n");

//#define int long long int

/*
 1.困った時こそ冷静に問題文を見直す！制約条件を見ろ！乱択アルゴリズムとかO(N^3)とか！
 2.一度に大量のことをやろうとしない
 3.プログラミングは半分数学だが、もう半分は数学ではない
 
 */

int tekitou(){
    int a,b,c;
    in(a);in(b);in(c);
    pf("%d\n",a+b+c-max(max(a,b),c));
    return 0;
}

signed main(){
    assert(1);
    tekitou();
    //Ap();
    //Bp();
    //Cp();
    //Dp();
    //Ep();
    //Fp();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a,ans;
	while (1) {
		cin >> a;
		if (a == 0) {
			goto a;
		}
		ans = 0;
		while(a != 1) {
			ans++;
			if (a % 2 == 0) {
				a /= 2;
			}
			else {
				a = a * 3 + 1;
			}
		}
		cout << ans << endl;
	}
a:;
}


Measured memory_bytes: 3020
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e6 + 10, mod = 1e6 + 3;

ll fact[N], finv[N];

ll inverse(ll x);
ll pwr(ll x, ll e);

int main() {
	fast_cin();
	fact[0] = finv[0] = 1;
	for (int i = 1; i < N; ++i) {
		fact[i] = (i * fact[i - 1]) % mod;
		finv[i] = inverse(fact[i]);
	}
	int q; cin >> q;
	for (int i = 1; i <= q; ++i) {
		int x, d, n;
		cin >> x >> d >> n;
		if (!d) {
			cout << pwr(x, n) << '\n';
		} else if (n >= mod) {
			cout << 0 << '\n';
		} else {
			int l = (x * inverse(d)) % mod;
			int r = (l + n - 1) % mod;
			if (r < l or l == 0) {
				cout << 0 << '\n';
			} else {
				ll ans = fact[r] * finv[l - 1];
				ans %= mod;
				ans *= pwr(d, n);
				ans %= mod;
				cout << ans << '\n';
			}
		}
	}
}

ll inverse(ll x) {
	return pwr(x, mod - 2);
}

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

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


int main(){

int n;
cin >> n;
int a[n];
rep(i,n)cin >> a[i];
int count = 0;
int b=0;

rep(i,n)if(a[i]%2!=0)count++;

for(int j =0;j<30;j++){
    if(count<1){
        rep(i,n)a[i]/=2;
        rep(i,n)if(a[i]%2!=0)count++;
}
else {
    b=j;
    break;
}
}
cout << b << endl;
return 0;
}






Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
  Scanner sc = new Scanner(System.in);	
 
  public void run(){
    int n = sc.nextInt();
    long mod = 1_000_000_000 + 7;
    
    long dp[] = new long[4];
    int no09 = 0;
    int have0 = 1;
    int have9 = 2;
    int have09 = 3;
    dp[no09] = 1;
    
    for(int i = 0;i < n;i++){
      long next[] = new long[4];
      next[no09] = (dp[no09] * 8)%mod; 
      next[have0] = (dp[have0] * 9 + dp[no09])%mod;  
      next[have9] = (dp[have9] * 9 + dp[no09])%mod;  
      next[have09] = (dp[have09] * 10 + dp[have0] + dp[have9])%mod;
      dp = next; 
    }
    System.out.println(dp[have09]);
  }
  public static void main(String[] args){
    Main m = new Main();
    m.run();
  }
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a<b) puts("0");
    else puts("10");

    return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	if(c<=max(a,b) && c>=min(a,b)) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define PI 3.1415926535897932384626

int main(void){
	int a=0, b=0, c=0;
	double S=0.0, L=0.0, h=0.0;
	double a_dou=0.0, b_dou=0.0;
	double c_rad=0.0;
	
	scanf("%d %d %d", &a, &b, &c);
	a_dou = (double)a;
	b_dou = (double)b;
	c_rad = (double)c * PI / (double)180;

	S = a_dou * b_dou * sin(c_rad) / 2.0;
	L = sqrt(pow(a_dou, 2) + pow(b_dou, 2) - 2 * a_dou * b_dou * cos(c_rad)) + a_dou + b_dou;
	h = 2.0 * S / a_dou;

	printf("%lf %lf %lf\n", S, L, h);
	return 0;
}

Measured memory_bytes: 636
used = []
n = int(input())
word = input()
end = word[len(word)-1]
used.append(word)
flag = 0
for i in range(n-1):
    word = input()
    if word in used:
        flag = 1
        break
    if word[0] != end:
        flag = 1
        break
    end = word[len(word)-1]
    used.append(word)
print("Yes" if flag == 0 else "No")

Measured memory_bytes: 3064
H,W,D = map(int,input().split())

pos = [0]*(H*W)
for j in range(H):
  A = list(map(int,input().split()))
  for i in range(W):
    pos[A[i]-1] = (i,j)
#print(link)

memo = [0]*(H*W)
for x in range(H*W):
  if x<D:
    continue
  i,j = pos[x-D][0],pos[x-D][1]
  u,v = pos[x  ][0],pos[x  ][1]
  memo[x] = memo[x-D]+abs(i-u)+abs(j-v)

Q = int(input())
for _ in range(Q):
  L,R = map(int,input().split())
  print(memo[R-1]-memo[L-1])


Measured memory_bytes: 58396
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    while(true) {
      String[] strArray = br.readLine().split(" ");
      int m = Integer.parseInt(strArray[0]);
      int f = Integer.parseInt(strArray[1]);
      int r = Integer.parseInt(strArray[2]);
      int d = m + f;
      if(m == -1 && f == -1 && r == -1) {
        break;
      }
      else if(m == -1 || f == -1) {
        sb.append("F").append("\n");
      }
      else if(d >= 80) {
        sb.append("A").append("\n");
      }
      else if(d >= 65 && d < 80) {
        sb.append("B").append("\n");
      }
      else if(d >= 50 && d < 65) {
        sb.append("C").append("\n");
      }
      else if(d >= 30 && d < 50) {
        if(r >= 50) {
          sb.append("C").append("\n");
        }
        else {
          sb.append("D").append("\n");
        }
      }
      else {
        sb.append("F").append("\n");
      }
    }
    System.out.print(sb);
  }
}

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;



int main() {
  string x;
  cin >>x;
  if(x[0]-'0'==9||x[1]-'0'==9) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3596
#!/usr/bin/env ruby

gohyaku = gets.to_i
hyaku = gets.to_i
goju = gets.to_i

x = gets.to_i

def sum(a, b, c)
  a * 500 + b * 100 + c * 50
end

res = 0
(0..gohyaku).to_a.each { |a_num|
  next if x < sum(a_num, 0, 0)
  (0..hyaku).to_a.each { |b_num|
    next if x < sum(a_num, b_num, 0)
    (0..goju).to_a.each { |c_num|
      next if x < sum(a_num, b_num, c_num)
      res += 1 if x == sum(a_num, b_num, c_num)
    }
  }
}

puts res


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

public class Main {

	void solve() {
		int n = in.nextInt();
		int lastX = 0, lastY = 0, lastT = 0;
		for (int i = 0; i < n; i++) {
			int t = in.nextInt(), x = in.nextInt(), y = in.nextInt();
			int dist = Math.abs(x - lastX) + Math.abs(y - lastY);
			if (dist > t - lastT || dist % 2 != (t - lastT) % 2) {
				out.println("No");
				return;
			}
			lastT = t;
			lastX = x;
			lastY = y;
		}
		out.println("Yes");
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

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

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 41376
k, n = map(int, input().split())
a = list(map(int, input().split()))

a.append(a[0] + k)

distance = []

for i in range(len(a) - 1):
    distance.append(a[i+1] - a[i])

mindistance = 0
for j in distance:
    mindistance += j

print(mindistance - max(distance))

Measured memory_bytes: 26436
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
    int n, k;
    char* s;
    cin >> n >> k;
    s = new char[n];
    for(int i = 0; i < n; i++){
        cin >> s[i];
        if(i == k-1){
            s[i] += ('a'-'A');
        }
    }

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

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

int main(){
	string s;
	cin>>s;
	vector<int> num(30,0);

	for(int i=0;i<s.size();i++){
		num.at(s.at(i)-'a')++;
	}
  char ans = 'a';
	for(int i=0;i<26;i++){
		if(!num.at(i)){
			ans += i;
          	cout << ans << endl;
          	return 0;
		}
	}

  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct object{
  string name;
  int size;
  object *desc[50010];
  string attr;
  object(){}
  object(string s){
    name = s;
  }
  object(string s, string t){
    name = s;
    attr = t;
  }
};

object* get(object* base, string query){
  query += ".";
  int bf = 1;
  for(int i = 1; i < query.size(); i++)if(query[i] == '.'){
    string pro = query.substr(bf, i - bf);
    //cout<<"search: "<<pro<<"("<<pro.size()<<")"<<endl;
    bf = i + 1;
    bool f = false;
    for(int j = 0; j < base->size; j++){
      //cout<<"compare: "<<base->desc[j]->name<<endl;
      if(base->desc[j]->name == pro){
        //cout<<"equal!!"<<endl;
        base = base->desc[j];
        f = true;
        break;
      }
    }
    if(!f) return NULL;
  }
  return base;
}

int main(){
  string query;
  while(getline(cin, query)){
    object base("yaml");
    string input;
    object* lev_obj[50010];
    lev_obj[0] = &base;
    while(getline(cin, input)){
      int lev = 0;
      while(lev < input.size() && input[lev] == ' ') lev++;
      lev ++;
      input = input.substr(lev - 1);
      //cout<<"input: "<<input<<endl;
      //cout<<"lev: "<<lev<<endl;
      object* current;
      //
      if(input[input.size() - 1] == ':'){
        string name = input.substr(0, input.size() - 1);
        //cout<<"name: "<<name<<endl;
        current = new object(name);
      }else{
        REP(i, input.size()) if(input[i] == ':'){
          string name = input.substr(0, i);
          string attr = input.substr(i + 2);
          //cout<<"name: "<<name<<endl;
          //cout<<"attr: "<<attr<<endl;
          current = new object(name, attr);
          break;
        }
      }
      //cout<<"lev_obj["<<lev<<"]"<<" is replaced"<<endl;
      lev_obj[lev] = current;
      for(int l = lev + 1; l < 10000; l++) lev_obj[l] = NULL;
      for(int l = lev - 1; l >= 0; l--){
        if(lev_obj[l]){
          lev_obj[l]->desc[lev_obj[l]->size++] = current;
          //cout<<"insert to "<<lev_obj[l]->name<<"(lev:"<<l<<")"<<endl;
          break;
        }
      }
      //cout<<endl;
    }
    object* ans = get(lev_obj[0], query);
    if(ans){
      if(ans->attr == ""){
        cout<<"object"<<endl;
      }else{
        cout<<"string \""<<ans->attr<<"\""<<endl;
      }
    }else{
      cout<<"no such property"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 6544
N, M = map(int, input().split())

count = [0 for i in range(N+1)]

for i in range(M):
    l, r = map(int, input().split())
    count[l-1] += 1
    count[r] -= 1

ans = 0
tmp = 0

for i in range(N):
    tmp += count[i]
    if tmp == M:
        ans += 1

print(ans)


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

using namespace std;

const int MOD = 1e9 + 7;

int i;
long long n,m;

int main(){
	scanf("%lld%lld", &n, &m);
	
	long long res = 0;
	long long fact1 = 1;
	long long fact2 = 1;
	
	for(i = 1; i <= n; i++)
	fact1 = (fact1 * i) % MOD;
	for(i = 1; i <= m; i++)
	fact2 = (fact2 * i) % MOD;
	
	if(n == m - 1 || m == n - 1)
	res = (fact1 * fact2) % MOD;
	else if(n == m)
	res = (2 * fact1 * fact2) % MOD;
	
	printf("%lld\n", res);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
using Graph = vector<VE>;

int cnt[65][2];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n) {
		rep(j, 60) {
			cnt[j][(bool)(a[i] & (1LL << j))]++;
		}
	}
	int ans = 0;
	for (int i = 59; i >= 0; i--) {
		ans *= 2;
		ans += cnt[i][0] * cnt[i][1]; ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

// utils
func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func main() {
	sc.Split(bufio.ScanWords)
	A := nextInt() // pizza A price
	B := nextInt() // pizza B price
	C := nextInt() // pizza AB price
	X := nextInt() // A required
	Y := nextInt() // B required

	ans := 0

	if (A + B) >= C*2 {
		ans += C * 2 * min(X, Y)
	} else {
		ans += (A + B) * min(X, Y)
	}

	switch {
	case X > Y:
		if A >= C*2 {
			ans += C * 2 * abs(X-Y)
			break
		}
		ans += A * abs(X-Y)
	case X < Y:
		if B >= C*2 {
			ans += C * 2 * abs(X-Y)
			break
		}
		ans += B * abs(X-Y)
	}

	fmt.Print(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll a, b;
	cin >> a >> b;
	
	if( a == b ) { 
		cout << a << endl;
		return 0;
	}
	
	if( a == b - 1 ) { 
		cout << (a ^ b) << endl;
		return 0;
	}
	
	ll ans = 0;
	
	if( a % 2 == 1 ) {
		ans ^= a;
		a++;
	}
	
	if( b % 2 == 0 ) {
		ans ^= b;
		b--;
	}
	
	ll n = b - a + 1LL;
	if( (n / 2) % 2 == 1 ) ans ^= 1;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#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>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

set<int> si;

int main(){
	REP(i, 3){
		int num;
		cin >> num;
		si.insert(num);
	}
	cout << si.size() << endl;
}

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

int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		string S, T;
		cin >> S >> T;
		int s = S.size(), t = T.size();
		int dp[1010][1010] = { 0 };
		for (int i = 0; i < s; i++) {
			for (int j = 0; j < t; j++) {
				if (S[i] == T[j]) {
					dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
				}
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
			}
		}
		cout << dp[s][t] << endl;
	}
}


Measured memory_bytes: 7176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		if(n==0) {
			System.out.println("0");
		}else {
			String ans = "";
			while(n!=1) {
				if(n>0) {
					ans = n%(-2) + ans;
					n /= -2;
				}else {
					ans = -n%2 + ans;
					n = -(n-1)/2;
	 			}
				
			}
			ans = "1" + ans;
			System.out.println(ans);
		}
		in.close();
	}

}


Measured memory_bytes: 22100
import math
n=int(input())
a=input()
a.split()
#a=list(map(int,input().split()))
if n%2==1:
    print('No')
else:
    k=n//2
    current=1
    i=0
    while(i!=k):
        if a[i]!=a[i+k]:
            current=current*0
        i+=1
    if current==1:
        print('Yes')
    else:
        print('No')
        

Measured memory_bytes: 3060
//Typical Stairs

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()

int main (){
    ll N,M,a=0,b=1,c=-1;cin >> N >> M;
    vector<bool> ANA(N,false);

    int C[M];C[0]=-1;
    rep(i,1,M+1){
        cin >> C[i];
        ANA[C[i]]=true;
    }

    vector<int> Ans(N+1,0);
    Ans[0]=1;if(!ANA[1])Ans[1]=1;
    rep(j,2,N+1){
        if(!ANA[j-2])Ans[j] += Ans[j-2];
        if(!ANA[j-1])Ans[j] += Ans[j-1];
        Ans[j]%=1000000007;
    }
    cout << Ans[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int N;
	string S;

	cin >> N >> S;

	vector<vector<Int>> dp(N+1, vector<Int>(N+1));//dp[i][j]: i文字目以降およびj文字目以降の共通部分文字列長さ（この段階では被りOK）
	for (Int i = N - 1; i >= 0; i--) {
		for (Int j = N - 1; j >= 0; j--) {
			if (S[i]!=S[j]) {
				dp[i][j] = 0;
			}
			else {
				dp[i][j] = dp[i + 1][j + 1] + 1;
			}
		}
	}

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < N; j++) {
			/*if (i >= j) {
				continue;
			}
			else {*/
			ans = max(ans, min(dp[i][j], abs(j - i)));
				//}
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 195968