akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int r,c;
char s[55][55];
int d[55][55];
int bfs(){
	int sx=0,sy=0,gx=r-1,gy=c-1;
	int dx[4]={1,0,-1,0} ,dy[4]={0,1,0,-1};
	queue<p> que;
	rep(i,0,r){
		rep(j,0,c){
			d[i][j]=inf;
		}
	}
	que.push(p(sx,sy));
	d[sx][sy]=0;
	while(que.size()){
		p pf=que.front();
		que.pop();
		
		if(pf.first==r-1&&pf.second==c-1) break;
		rep(i,0,4){
			int nx=pf.first+dx[i],ny=pf.second+dy[i];
			if(nx>=0&&nx<r&&ny>=0&&ny<c&&s[nx][ny]!='#'&&d[nx][ny]==inf){
				que.push(p(nx,ny));
				d[nx][ny]=d[pf.first][pf.second]+1;
			}
		}
	}
	return d[r-1][c-1];
}
int main(){
	int wsum=0;
	cin>>r>>c;
	rep(i,0,r){
		rep(j,0,c){
			cin>>s[i][j];
			if(s[i][j]=='.')wsum++;
		}
	}
	int reach=bfs();
	if(reach==inf){
		cout<<-1<<endl;
	}
	else{
		cout<<wsum-reach-1<<endl;
	}
}

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

int main() {
  char S1, S2, S3, T1, T2, T3;
  cin >> S1 >> S2 >> S3;
  cin >> T1 >> T2 >> T3;
  int count = 0;
  if (S1 == T1) {
    count++;
  }
  if (S2 == T2) {
    count++;
  }
  if (S3 == T3) {
    count++;
  }
  cout << count << endl;
}

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

int main()
{
  ll N,M;
  cin >> N >> M;
  vector<vector<ll> > A(N);
  rep(i,N){
    ll a,b;
    A[i].resize(2);
    cin >> A[i][0] >> A[i][1];
  }
  // rep(i,N) cout << A[i][0] << " " ;
  // cout << endl;
  // rep(i,N) cout << A[i][1] << " " ;
  // cout << endl;
  // cout << "-------" << endl;

  sort(A.begin(),A.end());
  // rep(i,N) cout << A[i][0] << " " ;
  // cout << endl;
  // rep(i,N) cout << A[i][1] << " " ;
  // cout << endl;

  ll zan = M;
  ll ans;
  rep(i,N){
    int t = min(zan,A[i][1]);
    ans += A[i][0] * t;
    zan -= t;
    if(zan == 0){
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 998244353;

template <int MOD = 1000000007>
struct Mint {
    int x;

    Mint() : x(0) {}
    Mint(long long t) {
        x = t % MOD;
        if (x < 0) x += MOD;
    }

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n, s;
    cin >> n >> s;
    int a[n];
    rep(i, n) {
        cin >> a[i];
    }
    Mint<MOD> dp[n + 1][s + 1];
    dp[0][0] = Mint<MOD>(2).pow(n);
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= s; j++){
            dp[i + 1][j] += dp[i][j];
            if (j - a[i] < 0) continue;
            dp[i + 1][j] += dp[i][j - a[i]] / 2;
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}

Measured memory_bytes: 38816
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
int main() {
    int n,v[20],c[20];
    int ans = 0;
	cin >> n;
	for(int i=0;i<n;i++) cin>>v[i];
	for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<n;i++) {
        if (v[i] - c[i] > 0) {
            ans += (v[i] - c[i]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# Aizu Problem 0185: Goldbach Conjecture II
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def primes2(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
        sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

primes = primes2(10**6)
pset = set(primes)

while True:
    n = int(input())
    if n == 0:
        break
    S = 0
    for p in primes:
        if p > n // 2:
            break
        if n - p in pset:
            S += 1
    print(S)

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

int main()
{
    int n, t;
    cin >> n >> t;
    int a[100002], les[100002], lar[100002];
    int mdif = 0;
    cin >> a[0];
    les[0] = a[0];
    for(int i = 1; i < n; i++){
        cin >> a[i];
        les[i] = min(les[i - 1], a[i]);
        mdif = max(mdif, a[i] - les[i]);
    }
    lar[n - 1] = a[n - 1];
    for(int i = n - 2; i >= 0; i--){
        lar[i] = max(lar[i + 1], a[i]);
    }
    vector<int> demin;
    int count = 0;
    int nmin = 0;
    for(int i = 0; i < n; i++){
        if(lar[i] - a[i] == mdif){
            if(a[i] == nmin) count++;
            else{
                demin.push_back(count);
                nmin = a[i];
                count = 1;
            }
        }
    }
    demin.push_back(count);
    demin.erase(demin.begin());
    vector<int> demax;
    count = 0;
    int nmax = 0;
    for(int i = n - 1; i >= 0; i--){
        if(a[i] - les[i] == mdif){
            if(a[i] == nmax) count++;
            else{
                demax.push_back(count);
                nmax = a[i];
                count = 1;
            }
        }
    }
    demax.push_back(count);
    demax.erase(demax.begin());
    int l = demin.size();
    reverse(demin.begin(), demin.end());
    int ans = 0;
    for(int i = 0; i < l; i++){
        ans += min(demin[i], demax[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2044
N = int(input())
A = list(map(int,input().split()))
M = 1000
S = 0
for i in range(N-1):
  if A[i]<A[i+1]:
    S += M//A[i]
    M = M%A[i]
  else:
    M += S*A[i]
    S = 0
M += S*A[N-1]
print(M)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  int cur = 0, cnt = 0;
  while (cur != 1) {
    if (mp[cur]) {
      cout << "-1" << endl;
      return 0;
    }
    mp[cur]++;
    cur = a[cur];
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int cnt[2010];

int main() {
//	freopen("in.txt", "r", stdin);
	string s;
	cin >> s;
	int num = 0, t = 1, res = 0;
	cnt[0] = 1;
	for(int i = s.size() - 1; i>=0; i--) {
		num = (num + (s[i] - '0') * t) % 2019;
		res += cnt[num]++;
		t = t * 10 % 2019;
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 3836
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
string X,Y;
int T[1010][1010];
int main()
{
    cin>>X>>Y;
    for(int i=0;i<=X.size();i++)
        for(int j=0;j<=Y.size();j++)
        {
            if(i==0)
                T[i][j]=j;
            else if(j==0)
                T[i][j]=i;
            else if(X[i-1]==Y[j-1])
                T[i][j]=T[i-1][j-1];
            else if(X[i-1]!=Y[j-1])
            {
                int a=min(T[i][j-1]+1,T[i-1][j]+1);
                int b=min(a,T[i-1][j-1]+1);
                T[i][j]=b;
            }
        }
        cout<<T[X.size()][Y.size()]<<endl;
        return 0;
}


Measured memory_bytes: 7120
while (s=gets) 
a,b = s.split.map{|item| item.to_i}
p (a+b).to_s.length    #　p (a+b).to_s.size でも可能
end

# .length .size は文字オブジェクトにおいて使うことができるメソッドなので、
# .to_s によって文字オブジェクトに変えている。



Measured memory_bytes: 6872
#!/usr/bin/env python

S = raw_input().split()

lst = []

for s in S:
    if s == '+':
        num1 = lst.pop()
        num2 = lst.pop()
        lst.append(num1 + num2)
    
    elif s == '-':
        num1 = lst.pop()
        num2 = lst.pop()
        lst.append(num2 - num1)
        
    elif s == '*':
        num1 = lst.pop()
        num2 = lst.pop()
        lst.append(num2 * num1)
        
    else:
        lst.append(int(s))

print lst[0]


Measured memory_bytes: 4656
import math
N = int(input())
x = []
y = []
for _ in range(N):
    i = list(map(int, input().split()))
    x.append(i[0])
    y.append(i[1])
length = 0
for i in range(N):
    for j in range(i+1,N):
        length += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)

kaburi = (N-1)*2*math.factorial(N-2)
fac_N = math.factorial(N)
length *= kaburi
print(length/fac_N)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

int main() {
  long long  k;
  cin >> k;

  queue<long long> Q;

  for (int i = 1; i <= 9; i++) {
    Q.push(i);
  }

  long long a;
  for (int i = 0; i < k; i++) {
    a = Q.front();
    Q.pop();
    if (a % 10 > 0) {
      Q.push(a * 10 + a % 10 - 1);
    }
    Q.push(a * 10 + a % 10);
    if (a % 10 < 9) {
      Q.push(a * 10 + a % 10 + 1);
    }
  }
  cout << a << endl;
  

  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

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

        int y = sc.nextInt();
        int x = sc.nextInt();
        System.out.println(calc(x, y));
//        test();
    }

    private static int calc(int x, int y) {
        if (x == y) {
            return 0;
        } else if (y == 0) {
            if (x >= 0) {
                return x;
            } else {
                return Math.abs(x) + 1;
            }
        } else if (x == 0) {
            if (y <= 0) {
                return Math.abs(y);
            } else {
                return y + 1;
            }
        } else if (y > 0 && y < x) {
            return x - y;
        } else if (x > 0 && y > x) {
            return y - x + 2;
        } else if (y < 0 && x < y) {
            return y - x + 2;
        } else if (x < 0 && y < x) {
            return x - y;
        } else {
            return Math.abs(Math.abs(x) - Math.abs(y)) + 1;
        }
    }

    private static void test() {
        System.out.println(calc(-1,2));
    }
}


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


Measured memory_bytes: 3996
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		int A = sc.nextInt();
		final int LEN = 55;
		
		long dp[][] = new long[LEN][LEN*LEN];
		dp[0][0] = 1;
		
		for (int i = 1; i <= N; i++) {
			int x = sc.nextInt();
			for (int j = i - 1; j >= 0; j--) {
				for (int k = 0; k <= LEN*j; k++) {
					dp[j + 1][k + x] += dp[j][k];
				}
			}
		}
		
		long ans = 0;
		for (int i = 1; i <= N; i++) {
			ans += dp[i][i*A];
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 25044
#include <iostream>
#include <string>
#include <cmath>

#include <list>
#include <queue>
#include <algorithm>

#define INF 1000000000

using namespace std;

int main(void)
{
    long long a;
    string b;
    cin >> a >> b;

    int d1 = stoi(b.substr(0, 1));
    int d2 = stoi(b.substr(2, 1));
    int d3 = stoi(b.substr(3, 1));

    long long ans = a * d1 * 100 + a * d2 * 10 + a * d3;
    cout << ans / 100;
    return 0;
}


Measured memory_bytes: 3632
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define ll rt<<1
#define rr rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define lowbit(x) (x&-x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define fi freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9;

int main()
{
#ifndef ONLINE_JUDGE

#endif

    int n, a, b;
    SCCC(n, a, b);
    if(n == 1){
        if(a != b) puts("0");
        else puts("1");
    }
    else{
        if(a > b) puts("0");
        else{
            LL xiao = 1LL * (n-1) * a + b;
            LL da = 1LL * (n-1) * b + a;
            printf("%lld\n", da - xiao + 1);
        }
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

ll H, W;
vector<pair<int, int> > V;

void solve();


int main() {

	solve();

	return 0;
}

void solve() {
	int i, j, k, l, r, x, y; string s;

	cin >> W >> H;
	for (i = 0; i < W; i++) {
		cin >> x;
		V.push_back({ x,0 });
	}
	for (i = 0; i < H; i++) {
		cin >> x;
		V.push_back({ x,1 });
	}

	sort(V.begin(),V.end());
	ll ret = 0;
	W++;
	H++;

	vector<pair<int, int> >::iterator it = V.begin();

	for (; it != V.end(); it++) {
		if ((*it).second == 1) { ret += W*(*it).first, H--; }
		else {
			ret += H*(*it).first, W--;
		}
	}
	cout << ret << endl;

}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define s second
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
using namespace std;


int main(){
    faster
    int T = 1;
    while(T--){
        int n5=0,n7=0;
        int a;
        for(int i=0; i<3; i++){
            cin>>a;
            if(a == 5) n5++;
            if(a == 7) n7++;
        }
        if(n5 == 2 && n7 == 1) cout<<"YES";
        else cout<<"NO";
    }
    return 0;
}

Measured memory_bytes: 896
import math
A,B,H,M = map(int, input().split())
# 360/12, 360/60, 1h=30
h_angle = (360/12 * H) + (M * 0.5)
m_angle = 360/60 * M

tri_angle = abs(h_angle - m_angle)

C = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(math.radians(tri_angle)))
print(C)


Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
int main() {
string s;
cin>>s;
ll f=0;
ll counter=0;
ll n=s.size();
if(s.at(0)=='W'){
f++;}
for(ll i=1; i<n; i++){
if((f==1&&s.at(i)=='W')||(f==0&&s.at(i)=='B')) continue;
else{
counter++;
if(s.at(i)=='W'){
f=1;}
else
f=0;}}
cout<<counter<<endl;}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    string fr = s.substr(0, n / 2);
    string ba = s.substr(n / 2 + (n % 2), n / 2);
    reverse(ALL(ba));
    int ans = 0;
    // cout << fr << endl;
    // cout << ba << endl;
    for(int i = 0; i < n / 2; i++) {
        if(fr[i] != ba[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    std::string s;
    std::cin >> s;

    
    int num[4];
    num[0] = s[0] - '0';
    num[1] = s[1] - '0';
    num[2] = s[2] - '0';
    num[3] = s[3] - '0';
    std::vector<int> ans(8);

    ans[0] = num[0] + num[1] + num[2] + num[3];
    ans[1] = num[0] - num[1] + num[2] + num[3];
    ans[2] = num[0] + num[1] - num[2] + num[3];
    ans[3] = num[0] + num[1] + num[2] - num[3];
    ans[4] = num[0] - num[1] - num[2] + num[3];
    ans[5] = num[0] + num[1] - num[2] - num[3];
    ans[6] = num[0] - num[1] + num[2] - num[3];
    ans[7] = num[0] - num[1] - num[2] - num[3];

    int index;
    for (int i = 0; i < 8; i++)
    {
        if(ans[i] == 7) {
            index = i;
        }
    }

    std::string anss = "";
    std::string a = std::to_string(num[0]);
    std::string b = std::to_string(num[1]);
    std::string c = std::to_string(num[2]);
    std::string d = std::to_string(num[3]);
    if (index == 0)
    {
        anss += a;
        anss += "+";
        anss += b;
        anss += "+";
        anss += c;
        anss += "+";
        anss += d;
    }
    else if (index == 1)
    {
        anss += a;
        anss += "-";
        anss += b;
        anss += "+";
        anss += c;
        anss += "+";
        anss += d;
    }
    else if (index == 2)
    {
        anss += a;
        anss += "+";
        anss += b;
        anss += "-";
        anss += c;
        anss += "+";
        anss += d;
    }
    else if (index == 3)
    {
        anss += a;
        anss += "+";
        anss += b;
        anss += "+";
        anss += c;
        anss += "-";
        anss += d;
    }
    else if (index == 4)
    {
        anss += a;
        anss += "-";
        anss += b;
        anss += "-";
        anss += c;
        anss += "+";
        anss += d;
    }
    else if (index == 5)
    {
        anss += a;
        anss += "+";
        anss += b;
        anss += "-";
        anss += c;
        anss += "-";
        anss += d;
    }
    else if (index == 6)
    {
        anss += a;
        anss += "-";
        anss += b;
        anss += "+";
        anss += c;
        anss += "-";
        anss += d;
    }
    else if(index == 7)
    {
        anss += a;
        anss += "-";
        anss += b;
        anss += "-";
        anss += c;
        anss += "-";
        anss += d;
    }

    anss += "=7";

    std::cout << anss << "\n";
}

Measured memory_bytes: 3636
import copy
s=list(input())

def is_kaibun(ls):
    tmp = ls[:]
    tmp.reverse()
    return "".join(ls) == "".join(tmp)

flag = True
if not is_kaibun(s):
    flag = False
aaa=s[0:(len(s)-1)//2]
if not is_kaibun(aaa):
    flag=False
bbb=s[(len(s)+3)//2-1:len(s)]
if not is_kaibun(bbb):
    flag=False

if flag:
    print("Yes")
else:
    print("No")

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  string s, t; cin >> s >> t;
  t.pop_back();

  if (s == t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
N,M = gets.split.map &:to_i
H = gets.split.map &:to_i
H.unshift 0

T = [true] * (N+1)
T[0] = nil

M.times do 
    a,b = gets.split.map &:to_i
    next if !T[a] && !T[b]
    diff = H[a] - H[b]
    if diff == 0 then
        T[a] = T[b] = nil
    else
        T[diff>0?b:a] = nil
    end
end

p T.compact.size


Measured memory_bytes: 22636
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  x = 1
  for i in range(1, N+1):
    x = (x * B) % M
    if i in g:
      sum_g[g[i]] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret += (sx*sy*sz) % M
  return ret%M


edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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

int main()
{
	int n,d,x;
	cin >> n >> d >> x;
	rep(i,n)
	{
		int a;
		cin >> a;
		x += (d-1) / a + 1;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!
int skill[12];

ll check(ll b, int m, int n, vvi &a, vi &c, int x){
  rep(j,m) skill[j] = 0;
  int price = 0;
  rep(i,n){
    if((b>>i) & 1){
      rep(j,m){
        skill[j] += a[i][j];
      }
      price += c[i];
    }
  }
  rep(j,m){ if(skill[j]<x) return numeric_limits<ll>::max(); }
  return price;
}
// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  ll n, m, x;
  cin >> n >> m >> x;
  vi c(n,0);
  vvi a(n, vi(m,0));
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }
  ll ret = numeric_limits<ll>::max();
  ll B = pow(2,n);
  rep(b,B){
    chmin(ret, check(b,m,n,a,c,x));
  }
  if(ret==numeric_limits<ll>::max()) cout << -1 << endl;
  else cout << ret << endl;
  return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000001
vector<int> lis(vector<int> a){
	int n = a.size();
	vector<int> tmp(n,inf);
	vector<int> it(n);
	for(int i=0;i<n;i++){
	auto k = lower_bound(tmp.begin(),tmp.end(),a[i])-tmp.begin();
	it[i]= k;		
	tmp[k]= a[i];

	}
	int m = *max_element(it.begin(),it.end());
	vector<int> res(m+1);
	for(int i=n-1;i>=0;i--){
	if(it[i]==m){
		res[m] = a[i];
		m--;
		}
	}
	return res;
}

int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){ cin>>a[i];}
vector<int > ans = lis(a);
cout<< ans.size()<<endl;
	return 0;
}



Measured memory_bytes: 4660
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	bool flag = true;
	int count = 1;
	int N, i, j;
	cin >> N;
	vector<int> height(N);
	for (i = 0; i < N; i++)
	{
		cin >> height[i];
	}
	for (i = 1; i < N; i++)
	{
		for (j = 0; j < i; j++)
		{
			if (height[j] > height[i])
				flag = false;
		}
		if (flag == true)
			count += 1;
		flag = true;
	}
	cout << count;

	return 0;
}

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

int main() {
    int a,b;
    char op = 'a';
    
    while (op != '?') {
        cin >> a >> op >> b;
        if (op == '+') {
            cout << a + b << endl;
        } else if (op == '-') {
            cout << a - b << endl;
        } else if (op == '*') {
            cout << a * b << endl;
        } else if (op == '/') {
            cout << a / b << endl;
        } else {
            break;
        }
    }
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define int long long
signed main(){
	int n;
	cin>>n;
	string a[n];
	map<string,int>ma;
	for(int i=0;i<n;++i){
		cin>>a[i];
		sort(a[i].begin(),a[i].end());
	}
	int tot=0;
	for(int i=0;i<n;++i){
		tot+=ma[a[i]];
		++ma[a[i]];
	}
	cout<<tot<<endl;
	return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    float v[52], total;

    cin >> n;

    for (int i = 0; i < n; i++) cin >> v[i];

    sort(v, v+n);

    for (int i = 0; i < n; i++)
    {
        if (i == 0) total = v[i];
        else total = (v[i] + total) / 2;
    }

    cout << total;

    return (0);
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;
    yukari<int> g(n);
    for (int i = 0; i < n - 1; i++)
    {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);
    map<int, int> ans;
    for (int i = 0; i < n; i++)
    {
        akari<int> ds(n, -1);
        ds[i] = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty())
        {
            int v = q.front();
            q.pop();
            for (int nv : g[v])
            {
                if (ds[nv] == -1)
                {
                    ds[nv] = ds[v] + 1;
                    q.push(nv);
                }
            }
        }
        for (int j = 0; j < n; j++)
        {
            ans[ds[j]]++;
        }
    }
    for (int k = 1; k < n; k++)
    {
        cout << ans[k] / 2 << endl;
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int sz=1e3+5;
int arr[sz][sz];
int main()
{
    //int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int x=float(i)*1.08f;
        //cout<<int(x)<<endl;
        if(x==n)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
    return 0;

} 

Measured memory_bytes: 256
import Data.Vector((!),fromList)
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
getIntList = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine
binarySearch :: Integral a => (a -> Bool) -> a -> a -> a
binarySearch pred ok ng
  | abs (ok-ng) <= 1 = ok
  | pred mid = binarySearch pred mid ng
  | otherwise = binarySearch pred ok mid
    where mid = (ok+ng) `div` 2

main = do
    n <- readLn :: IO Int
    l <- fromList . sort <$> getIntList
    let list = [max 0 (right-left+1) |
           i <- [0 .. n - 3],
           let a = l ! i,
           j <- [i + 1 .. n - 2],
           let b = l ! j,
           -- condition :: l!k < a+b,abs (a-b) < l!k , j < k
           let left = binarySearch (\k -> abs (a-b) < l ! k) (n-1) j,
           let right = binarySearch (\k -> l ! k < a+b) 0 n
           ]
    print $ sum list

Measured memory_bytes: 5412
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size()
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define For(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
#define repd(i,j) for(int (i)=(j);(i)>=0;(i)--)
#define Ford(i,j,k) for(int (i)=(j);i>=(k);i--)
#define vfor(c,v) for(auto (c): v)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using pii = std::pair<int,int>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 10241024;
const ll INFL = (1ll << 62) - 1;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//_____________________________________Templates_________________________________________//

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
//_____________________　following sorce code_________________________//
int n,m,k;
//vvll dp(400, vll(400));
string S;
vll cost(1 << 16);
int h,w;
vi v;
vll u;
ll x[1000000];
ll a[1000000];


bool check(){
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  IN(n);
  x[0] = a[0] = 0;
  rep(i,n){
    int A;IN(A);
    x[i+1] = x[i] ^ A;
    a[i+1] = a[i] + A;
  }
  int idx = 0;
  ll ans = 0;
  rep(i,n){
    while(idx < n && (a[idx+1] - a[i]) == (x[idx+1] ^ x[i]))idx++;
    ans += idx - i;
    if(idx == i)idx++;
    //OUT(ans);
  }
  OUT(ans);
  //cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


LL a[5001];
LL dp1[5001][5001][2];
LL d[5001];
vector<int> G[5001];

void rec(int u,int v){
    d[u] = 1;
    for(auto g:G[u]){
        if(g==v) continue;
        rec(g,u);
        d[u] += d[g];
    }
    int num = 0;
    vector<vector<LL>> dp(d[u]+1,vector<LL> (2,LINF));
    dp[0][0] = a[u];
    if(a[u] > 0) dp[0][1] = a[u];
    for(auto g:G[u]){
        if(g==v) continue;
        for (int j = num; j >= 0; j--) {
            LL t0 = dp[j][0], t1 = dp[j][1];
            dp[j][0] = LINF;dp[j][1] = LINF;
            for (int k = 0; k <= d[g]; k++) {
                chmin(dp[j+k][0],dp1[g][k][0]+t0);
                if(dp1[g][k][0] < 0 || dp1[g][k][1] != LINF) chmin(dp[j+k+1][0],t0);
                if(a[u]>0){
                    chmin(dp[j+k][1],dp1[g][k][1]+t1);
                    if(dp1[g][k][0] < 0 || dp1[g][k][1] != LINF) chmin(dp[j+k+1][1],t1);
                }
            }
        }
        num += d[g];
    }
    for (int i = 0; i <= d[u]; i++) {
        dp1[u][i][0] = dp[i][0];
        dp1[u][i][1] = dp[i][1];
    }
}

int main(){
    int n;cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n-1; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        G[x].pb(y);
        G[y].pb(x);
    }
    for (int i = 0; i < 5001; i++) {
        for (int j = 0; j < 5001; j++) {
            for (int k = 0; k < 2; k++) {
                dp1[i][j][k] = LINF;
            }
        }
    }
    rec(0,0);
    for (int i = 0; i <= n; i++) {
        if(dp1[0][i][0] < 0){
            cout << i << endl;
            return 0;
        }
        if(dp1[0][i][1] != LINF){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 392220
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * ceil_(a, b)); }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class ARegistration {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    string S, T;
    cin >> S >> T;
    if (T.substr(0, T.size()-1) == S) {
      cout << "Yes" << Endl;
    } else {
      cout << "No" << Endl;
    }
  }
};


signed main() {
  ARegistration solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

using namespace std;

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

  int n, a;
  cin >> n;
  int two = 0, four = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a%4 == 0) four++;
    else if (a%2 == 0) two++;
  }
  cout << (2*four + two >= n || 2*four+1 == n ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 256
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
x=int(input())
for i in range(x,5*x):
    if is_prime(i):
        print(i)
        break

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

int main(void) {
    long long N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    vector<vector<long long> > dp(N + 1,
                                  vector<long long>(3, 0LL));  //グーチョキパー
    for (int i = 1; i <= K; i++) {
        dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) +
                   (T[i - 1] == 's' ? R : 0);
        dp[i][1] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) +
                   (T[i - 1] == 'p' ? S : 0);
        dp[i][2] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) +
                   (T[i - 1] == 'r' ? P : 0);
    }

    for (int i = K + 1; i <= N; i++) {
        long long ma =
            max({dp[i - K - 1][0], dp[i - K - 1][1], dp[i - K - 1][2]});
        if (ma + R != dp[i - K][0]) {  // K回前にグーを出していない
            dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) +
                       (T[i - 1] == 's' ? R : 0);
        } else {
            dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
        }
        if (ma + S != dp[i - K][1]) {  // K回前にチョキを出していない
            dp[i][1] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) +
                       (T[i - 1] == 'p' ? S : 0);
        } else {
            dp[i][1] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
        }
        if (ma + P != dp[i - K][2]) {  // K回前にパーを出していない
            dp[i][2] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) +
                       (T[i - 1] == 'r' ? P : 0);
        } else {
            dp[i][2] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
        }
    }

    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

    return 0;
}

Measured memory_bytes: 5760
h = [0] * 2019
h[0] = 1

cur = 0
p10 = 1

ans = 0
gets.to_s.chomp.bytes.reverse_each do |c|
  cur = ( cur + ( c - 48 ) * p10 ) % 2019 # p '0'.ord 48
  ans += h[cur]
  h[cur] += 1
  p10 = p10 * 10 % 2019
end

puts ans

Measured memory_bytes: 16200
#include<bits/stdc++.h>
#define N 1005
#define M1 131
#define M2 1999
using namespace std;
typedef unsigned long long ull;
int h1,w1,h2,w2;
string a[N],b[N];
ull x=1,y=1,X[N][N],Y[N][N],C[N],D=0;

int main(){
  cin>>h1>>w1;
  for(int i=0;i<h1;i++)cin>>a[i];
  cin>>h2>>w2;
  for(int i=0;i<h2;i++)cin>>b[i];
  
  for(int i=0;i<w2;i++)x*=M1;
  for(int i=0;i<h2;i++)y*=M2;
  
  for(int i=0;i<h2;i++)
    for(int j=0;j<w2;j++)
      C[i]=C[i]*M1+b[i][j];
  
  for(int i=0;i<h2;i++)D=D*M2+C[i];
  
  for(int i=0;i<h1;i++){
    X[i][0]=a[i][0];
    for(int j=1;j<w2;j++)X[i][j]=X[i][j-1]*M1+a[i][j];
    for(int j=w2;j<w1;j++)
      X[i][j]=X[i][j-1]*M1-x*a[i][j-w2]+a[i][j];
  }
  
  for(int j=w2-1;j<w1;j++){
    Y[0][j]=X[0][j];
    for(int i=1;i<h2;i++)Y[i][j]=Y[i-1][j]*M2+X[i][j];
    for(int i=h2;i<h1;i++){
      Y[i][j]=Y[i-1][j]*M2-y*X[i-h2][j]+X[i][j];
    }
  }
  for(int i=0;i<h1;i++){
    for(int j=0;j<w1;j++){
      if(Y[i][j]==D){
	printf("%d %d\n",i-h2+1  , j-w2+1);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 18352
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K ;
    int a;
    int l=0;

    for(int i=0; i<N; i++){
        cin >> a ;
        if(a>=K){
           l++;


        }

    }

    cout << l <<endl; 
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;
template <typename... Args>
void dbg(Args&&... args) {
  using expander = int[];
  (void)expander {0,(static_cast<void>(void(cout << std::forward<Args>(args) << " ")), 0)...};
  cout << endl;
}
void gen() {exit(0);}

int n;

void input() {
  scanf("%d", &n);
}

void solve() {
  if (n == 0) {
    printf("0\n");
    return;
  }
  string ans = "";
  while (n) {
    int cur = (n % -2);
    n /= -2;
    if (cur < 0) {
      cur += 2;
      n++;
    }
    ans = to_string(cur) + ans;
  }
  printf("%s\n", ans.c_str());
}

int main() {
#ifdef DEBUG
  freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);
  //  gen();
#endif
  input();
  solve();
  return 0;
}


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

const int INF = 24;
const int MAX_N = 50;
const int MAX_BIT = (1 << 24);
int dp[2][MAX_BIT];

int calcDiff(int t, int bit){
  int ret = INF;
  for(int i = 0 ; i < 24 ; i++){
    if((bit >> i)&1){
      int time = i;
      ret = min(ret, min((time - t + 24)%24, abs(time - t)));
    }
  }
  if(ret == INF)return 0;
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector<int>vec;
  for(int i = 0 ; i < N ; i++){
    int tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }
  for(int i = 0 ; i < 2 ; i++){
    for(int j = 0 ; j < MAX_BIT ; j++){
      dp[i][j] = -1;
    }
  }
  int now = 0;
  int next = 1;

  dp[now][1] = INF;
  int res = -1;
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < MAX_BIT ; j++){
      if(dp[now][j] == -1)continue;
      vector<int>cand;
      cand.push_back(vec[i]);
      cand.push_back((24 - vec[i])%24);
      for(int k = 0 ; k < cand.size() ; k++){
        //cout << "i = " << i << endl;
        //cout << "cand[k] = " << cand[k] << endl;
        int min_time = min(calcDiff(cand[k], j), dp[now][j]);
        int next_bit = (j | (1 << cand[k]));
        //cout << "min_time = " << min_time << " next_bit = " << next_bit << endl;
        dp[next][next_bit] = max(dp[next][next_bit], min_time);
        if(i+1 == N){
          res = max(res, dp[next][next_bit]);
        }
      }
    }
    swap(now,next);
    for(int j = 0 ; j < MAX_BIT ; j++){
      dp[next][j] = -1;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 131328
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 六  4/ 7 19:57:28 2018

*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

int a, b, c;


int main()
{
	scanf("%d %d %d", &a, &b, &c);
	int Min = min(a, min(b, c));
	int ans = 1 << 30; 
	for(int i = -10000000; i <= 10000000; i++){
		int now = 0;
		int tmp = (i - a);
		if(tmp < 0) now += abs(tmp);
		else {
			now += (tmp + 1) / 2;
			if(tmp & 1) now++;
		}
		tmp = (i - b);
		if(tmp < 0) now += abs(tmp);
		else {
			now += (tmp + 1) / 2;
			if(tmp & 1) now++;
		}
		tmp = (i-c);
		if(tmp < 0) now += abs(tmp);
		else {
			now += (tmp + 1) / 2;
			if(tmp & 1) now++;
		}
		ans = min(ans, now);
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef complex<int> ci;
typedef complex<double> cd;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define ins insert
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define FORI(a, b) for (auto(a) = (b).begin(); (a) != (b).end(); ++(a))
#define ROFI(a, b) for (auto(a) = (b).rbegin(); (a) != (b).rend(); ++(a))
#define CEIL(a, b) ((a) + (b)-1) / (b)
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b << endl;

    return 0;
}


Measured memory_bytes: 256