akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, K, X, Y; cin >> N >> K >> X >> Y;
    int sum=0;
    for (int i=1; i<=N; i++){
        if (i<=K){
            sum+=X;
        } else {
            sum+=Y;
        }
    }
    cout << sum;
    return 0;
}

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

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

using namespace std;

const int INF=1<<29;

int main(){
	int n,q;
	string s; cin>>n>>q>>s;
	vector<char> c(q),dir(q);
	rep(i,q) cin>>c[i]>>dir[i];

	auto simulate=[&](int x){
		rep(i,q+1){
			if(x==-1) return -1;
			if(x== n) return  1;
			if(i<q && s[x]==c[i]) x+=(dir[i]=='L'?-1:1);
		}
		return 0;
	};

	int ans=n,lo=-1,hi=n;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		if(simulate(mi)==-1) lo=mi;
		else                 hi=mi;
	}
	ans-=lo+1;

	lo=-1; hi=n;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		if(simulate(mi)==1) hi=mi;
		else                lo=mi;
	}
	ans-=n-hi;

	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 3928
N, A, B = map(int, input().split())
S = input()
cnt = 0
cntb = 1
for i in S:
    if i == 'a':
       if cnt < A + B:
           cnt += 1
           print('Yes')
       else:
           print('No')
    elif i == 'b':
        if cnt < A + B and cntb <= B:
            cnt += 1
            cntb += 1
            print('Yes')
        else:
            print('No')
    else:
        print('No')


Measured memory_bytes: 4024
x = 0

def format_input(filename = None):
	global x
	if filename == None:
		x = int(input())

	elif filename == '__random__':
		from random import randint as rng
		x = rng(0, 10**9)
		print(x)

def get_answer():
	num_of_500s = x // 500
	residue = x % 500
	num_of_5s = residue // 5

	answer = num_of_500s * 1000 + num_of_5s * 5

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 3060
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((u, v, w % 2))
    E[v].append((v, u, w % 2))
dfs = deque(E[1])
while dfs:
    p = (dfs.popleft())
    f, t, w = p
    if ans[t] != -1:
        continue
    if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
    for i in E[t]:
        dfs.append(i)
for i in ans[1:]:
    print(i)

Measured memory_bytes: 38328
#include <iostream> 

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>b)
	{
		cout<< "a > b" <<endl;
	}
	else if (a<b)
	{
		cout<<"a < b"<<endl;
	}
	else
	{
		cout<<"a == b"<<endl;
	}
}


Measured memory_bytes: 3068
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in input().split()]
def II(): return int(input())
INTMIN = -9223372036854775808

N=II()
RA=LI()
RB=LI()
GAIN1=[]
GAIN2=[]
for i in range(3):
    if RA[i] < RB[i]:
        GAIN1.append((RA[i], RB[i]-RA[i]))
    if RA[i] > RB[i]:
        GAIN2.append((RB[i], RA[i]-RB[i]))

dp1 = [0]*(N+1)
for i in range(N+1):
    for cost, gain in GAIN1:
        if (i+cost) <= N:
            dp1[i+cost] = max(dp1[i+cost],dp1[i]+gain)

M = dp1[N]+N
dp2 = [0]*(M+1)
for i in range(M+1):
    for cost, gain in GAIN2:
        if (i+cost) <= M:
            dp2[i+cost] = max(dp2[i+cost],dp2[i]+gain)

print(M+dp2[M])

Measured memory_bytes: 230808
def main():
    from math import ceil

    N, K = map(int, input().split())
    *a, = map(int, input().split())

    ans = ceil((N - K) / (K - 1)) + 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 13812
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> v(n);
    vector<string> M;
    vector<string> A;
    vector<string> R;
    vector<string> C;
    vector<string> H;
    for (auto& value : v)
    {
        cin >> value;
    }
    // グルーピング
    for (auto& value : v)
    {
        if (value.front() == 'M')
        {
            M.emplace_back(value);
        }
        if (value.front() == 'A')
        {
            A.emplace_back(value);
        }
        if (value.front() == 'R')
        {
            R.emplace_back(value);
        }
        if (value.front() == 'C')
        {
            C.emplace_back(value);
        }
        if (value.front() == 'H')
        {
            H.emplace_back(value);
        }
    }
    // コンビネーション場合分け
    int count = 0;
    if (!M.empty())
    {
        count++;
    }
    if (!A.empty())
    {
        count++;
    }
    if (!R.empty())
    {
        count++;

    }
    if (!C.empty())
    {
        count++;
    }
    if (!H.empty())
    {
        count++;
    }

    // 5C2以下
    if (count <= 2)
    {
        cout << 0 << endl;
        return 0;
    }

    // それ以外
    ULL result = static_cast<ULL>(M.size())*static_cast<ULL>(A.size())*static_cast<ULL>(R.size());

    result += static_cast<ULL>(M.size())*static_cast<ULL>(A.size())*static_cast<ULL>(C.size());

    result += static_cast<ULL>(M.size())*static_cast<ULL>(A.size())*static_cast<ULL>(H.size());

    result += static_cast<ULL>(M.size())*static_cast<ULL>(R.size())*static_cast<ULL>(C.size());

    result += static_cast<ULL>(M.size())*static_cast<ULL>(R.size())*static_cast<ULL>(H.size());

    result += static_cast<ULL>(M.size())*static_cast<ULL>(C.size())*static_cast<ULL>(H.size());

    result += static_cast<ULL>(A.size())*static_cast<ULL>(R.size())*static_cast<ULL>(C.size());

    result += static_cast<ULL>(A.size())*static_cast<ULL>(R.size())*static_cast<ULL>(H.size());

    result += static_cast<ULL>(A.size())*static_cast<ULL>(C.size())*static_cast<ULL>(H.size());

    result += static_cast<ULL>(R.size())*static_cast<ULL>(C.size())*static_cast<ULL>(H.size());

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 11636
#include<iostream>
#include<iostream>
#include<math.h>
#include<string>
#include<bits/stdc++.h>
#include<cstdio>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define bll __builtin_popcountll
#define bufclr while((getchar())!='\n')
#define bufcl int ws=cin.get()
#define bl "\n"
#define mp make_pair
#define pb push_back
#define ll long long int
#define UI unsigned int
#define mod  1000000007 /*998244353*/ 
//#define fs first
//#define sc second
#define fora(i,a,x) for(int i=a; i<x; ++i)
#define fors(i,x,a) for(int i=x; i>a; --i)
using namespace std;
void op(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
	#endif
}
int C(pair<int,int> &a ,pair<int,int> &b){
	return a.first<b.first;
}
int main() { 
    //	op();
		float  d,t,s;
		cin>>d>>t>>s;
		if(d/s>t)
			cout<<"No";
		else
			cout<<"Yes";
}




            

Measured memory_bytes: 3716
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
//#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll


const int N = 5e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
bool prime(int n) {
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
    ios;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i += 2) {
        if(s.substr(i , 2) != "hi") {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
		public static void main (String[] args){
			
			Scanner in = new Scanner(System.in);
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();

			
			if(a<b && b<c){
				System.out.println("Yes");
			}else{
				System.out.println("No");
		}
	}
}

Measured memory_bytes: 17304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    rep(i, (int)s.size()) if(i % 2 == 0) cout << s[i];
    cout << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

const int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int H, W; cin >> H >> W;
    vector<string> A(H); readv(A);
    vector<bools> b(H, bools(W, false));
    int n = 0;
    queue<Pii> que;
    REP(i, H) REP(j, W){
        if(A[i][j] == '#'){
            n++;
            b[i][j] = true;
            que.push(Pii(i, j));
        }
    }
    int ans = 0;
    while(n < H * W){
        int m = que.size();
        REP(t, m){
            Pii p = que.front(); que.pop();
            REP(k, 4){
                int i = p.f + dx[k], j = p.s + dy[k];
                if(i >= 0 && i < H && j >= 0 && j < W && !b[i][j]){
                    n++;
                    b[i][j] = true;
                    que.push(Pii(i, j));
                } 
            }
        }
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 17844
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const ll MOD = 998244353;
const int MAXN = 200'000 + 5;
ll pow10[MAXN];

set<int> IE;
map<int, int> EtS;
map<pii, int> V;
set<pii> Intervals;

ll ans = 0;
int N, Q;

void printPii(pii A) {
	cout << "(" << A.first << ", " << A.second << ")" << endl;
}

pii get_interval(int x) {
	int e = *IE.lower_bound(x);
	int s = EtS[e];
	return {s, e};
}

ll getIV(pii I) {
	int v = V[I];
	ll a = 0;
	a += pow10[N - I.first - 1] * v;
	a %= MOD;
	if (N - 1 != I.second) {
		a -= pow10[N - I.second - 2] * v;
		a %= MOD;
	}
	if (a < 0) a += MOD;
	return a;
}

void insert_interval(pii I, int v) {
	IE.insert(I.second);
	EtS[I.second] = I.first;
	Intervals.insert(I);
	V[I] = v;
	ans += getIV(I);
	ans %= MOD;
}

void remove_interval(pii I) {
	IE.erase(I.second);
	EtS.erase(I.second);
	ans -= getIV(I);
	ans %= MOD;
	if (ans < 0) ans += MOD;
	V.erase(I);
	Intervals.erase(I);
}

void update(int l, int r, int d) {
	//db(ans);
	//cout << "UPDATING " << l << " " << r << " " << d << endl;
	pii newI = {l, r};
	pii II = get_interval(l);
	vector<pii> delme;
	auto it = Intervals.find(II);
	while (it != Intervals.end()) {
		II = *it;
		if (newI.second < II.first) {
			break;
		} else {
			delme.push_back(II);
		}
		it++;
	}
	for (pii I: delme) {
		if (newI.first <= I.first && I.second <= newI.second) {
			remove_interval(I);
		} else if (I.first < newI.first && I.second <= newI.second) {
			pii addI = {I.first, newI.first - 1};
			int v = V[I];
			remove_interval(I);
			insert_interval(addI, v);
		} else if (newI.first <= I.first && newI.second < I.second) {
			pii addI = {newI.second + 1, I.second};
			int v = V[I];
			remove_interval(I);
			insert_interval(addI, v);
		} else {
			pii addI1 = {I.first, newI.first - 1};
			pii addI2 = {newI.second + 1, I.second};
			//printPii(addI1);
			//printPii(addI2);
			int v = V[I];
			remove_interval(I);
			insert_interval(addI1, v);
			insert_interval(addI2, v);
		}
	}
	insert_interval({l, r}, d);
}

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	pow10[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		pow10[i] = pow10[i - 1] * 10LL + 1;
		pow10[i] %= MOD;
	}
	
	cin >> N >> Q;
	insert_interval({0, N - 1}, 1);
	for (int q = 0; q < Q; q++) {
		int l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		update(l, r, d);
		//cout << ans << "\n";
		cout << ans << endl;
	}
}



Measured memory_bytes: 45712
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  ll a[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int tmp = 1;
  int ans = 0;
  for(int i = 1; i < n; i++){
    if(a[i-1]==a[i]){
      tmp++;
    }
    else{
      if(tmp%2!=0){
        ans++;
      }
      tmp=1;
    }
    
  }
  if(tmp%2!=0) ans++;
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    int N, M;
    scanf("%d %d", &N, &M);
    int a[M], b[M];
    for(int i=0; i<M; i++){
        scanf("%d %d", &a[i], &b[i]);
    }
    //FR
    int C[N+1];
    for(int i=1; i<=N; i++){
        C[i] = 0;
    }
    for(int i=0; i<M; i++){
        C[a[i]]++;
        C[b[i]]++;
    }
    for(int i=1; i<=N; i++){
        if(C[i]%2 == 1){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

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

int main() {
	vector<int> packs(3, 0);
	for (int i = 0; i < 3; i++){
		cin >> packs[i];
	}
	sort(packs.begin(), packs.end());
	if (packs[0] == (packs[1] + packs[2])) cout << "Yes" << endl;
	else if ((packs[0] + packs[1]) == packs[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    int n,m;
    int a,b;
    int i,j,k,l;
    scanf("%d %d",&n,&m);
    int num[n];
    for(k=0;k<=n-1;k++)
    {
        num[k]=0;
    }
    for(i=1;i<=m;i++)
    {
        scanf("%d %d",&a,&b);
        for(j=1;j<=n;j++)
        {
            if(a==j||b==j)
            {
                num[j-1]+=1;
            }
            
        }
    }
    for(l=1;l<=n;l++)
    {
        printf("%d\n",num[l-1]);
    }
 
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int dp[100005][3], v[100005][3], n;
int f(int ind, int p)
{
    if (p > n)
    {
        return 0;
    }
    int &r = dp[p][ind];
    if (r != -1)
    {
        return r;
    }

    for (int i = 0; i < 3; i++)
    {
        if (i != ind)
        {
            r = max(r, f(i, p + 1) + v[p][i]);
        }
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> v[i][j];
        }
    }
    int max1 = 0, ind = 0;
    for (int i = 0; i < 3; i++)
    {
        max1 = max(max1, f(i, 1) + v[0][i]);
    }
    cout << max1 << "\n";
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

#define x first
#define y second
#define pb push_back
#define MX 100007

int fx[4]={1,-1,0,0};
int fy[4]={0,0,1,-1};
int n,m;

int a[1000007];
int main()
{
	int a,b,c;
	cin >>a>>b>>c;
	if(c>=a&&c<=b)puts("Yes");
	else if(c>=b&&c<=a)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	long long x;
	cin>>x;
	for(int i=0;i<=1000;i++){
		for(int j=-1000;j<=1000;j++){
			if(i*i*i*i*i-j*j*j*j*j==x){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

vector<int> d[510];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, Q;
    cin >> n >> m >> Q;
    vector<int> l(m), r(m), p(Q), q(Q);
    rep(i, 0, m){
        cin >> l[i] >> r[i];
        l[i]--; r[i]--;
        d[l[i]].push_back(r[i]);
    }
    rep(i, 0, n){
        sort(d[i].begin(), d[i].end());
    }
    rep(i, 0, Q){
        cin >> p[i] >> q[i];
        p[i]--; q[i]--;
        int ans = 0;
        rep(j, p[i], q[i] + 1){
            int idx = upper_bound(d[j].begin(), d[j].end(), q[i]) - d[j].begin();
            ans += idx;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 8192
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a-1)/2 - (a-i)*(a-i-1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a+1,i+b)
print(int(count % mod))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
  string S;
  cin >> S;
  vector<vector<mint>> dp(100010,vector<mint> (13,0));
  dp[0][0]=1;
  REP(i,sz(S)){
    if(S[i]=='?'){
      REP(j,13){
        REP(k,10){
          dp[i+1][(j*10+k)%13]+=dp[i][j];
        }
      }
    }else{
      REP(j,13){
        dp[i+1][(j*10+(S[i]-'0'))%13]+=dp[i][j];
      }
    }
  }

  cout << dp[sz(S)][5] << endl;
}

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

int main() {
    int n, m, k; cin >> n >> m >> k;

    for(int lines = 0; lines <= n; ++lines) {
        for(int columns = 0; columns <= m; ++columns) {
            if(columns * lines + (m - columns) * (n - lines) == k) {
                cout << "Yes\n";
                return 0;
            }
        }   
    }

    cout << "No\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <map>

using namespace std;

long long n, x, d;
long long smin[500000];
long long smax[500000];
map<int, vector<pair<long long, long long> > > st;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> x >> d;
	if (d == 0)
    {
        if (x == 0)
        {
            cout << 1;
            return 0;
        }
        cout << n + 1;
        return 0;
    }
	for (int i = 1; i <= n; i++) smin[i] = smin[i - 1] + i - 1;
	for (int i = 1; i <= n; i++) smax[i] = smax[i - 1] + n - i;
	for (int k = 0; k <= n; k++)
    {
        long long mn = k * x + smin[k] * d;
        long long mx = k * x + smax[k] * d;
        long long md = ((k * x) % d + d) % d;
        mn = (mn - md) / d;
        mx = (mx - md) / d;
        st[md].push_back({mn, mx});
    }
    long long ans = 0;
    for (auto vv : st)
    {
        vector<pair<long long, long long> > v = vv.second;
        sort(v.begin(), v.end());
        long long sm = -1e18;
        for (int i = 0; i < v.size(); i++)
        {
            v[i].first = max(v[i].first, sm);
            if (v[i].first > v[i].second) continue;
            else ans += v[i].second - v[i].first + 1, sm = v[i].second + 1;
        }
    }
    cout << ans;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

class UnionFindTree {
private:
  int nodeSize;
  vector<int> parent;
  vector<int> rank;
  vector<int> treeSize;

public:
  UnionFindTree(int ns) {
    nodeSize = ns;
    parent = vector<int>(nodeSize);
    rank = vector<int>(nodeSize, 0);
    treeSize = vector<int>(nodeSize, 1);

    for(int i = 0; i < nodeSize; i++) {
      parent[i] = i;
    }
  }

  int find(int x) {
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = find(parent[x]);
    }
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) {
      return false;
    }

    if (rank[x] < rank[y]) {
      parent[x] = y;
      treeSize[y] += treeSize[x];
    } else {
      parent[y] = x;
      treeSize[x] += treeSize[y];
      if (rank[x] == rank[y]) {
        rank[x]++;
      }
    }

    return true;
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int getSize(int x) {
    return treeSize[find(x)];
  }
};

int main() {
  int N, M;
  cin >> N >> M;

  UnionFindTree uf(N);

  rep (i, M) {
    int x, y, z;
    cin >> x >> y >> z;
    uf.unite(x - 1, y - 1);
  }

  set<int> ans;
  rep (i, N) ans.insert(uf.find(i));

  cout << ans.size() << endl;
}


Measured memory_bytes: 6144
D, G = map(int,input().split())
problems = []
for _ in range(D):
    problems.append(list(map(int,input().split())))

def solve(n):
    N = n
    score = 0
    ans = 0
    for i in range(D):
        if N & 1:
            score += (i + 1) * 100 * problems[i][0] + problems[i][1]
            ans += problems[i][0]
        N >>= 1
    if score >= G:
        return ans
    i = D - 1
    while n & 2 ** i and i != -1:
        i -= 1
    if i == -1:
        return 10 ** 8
    cnt = 0
    while score + (i + 1) * 100 * cnt < G:
        cnt += 1
    if cnt >= problems[i][0]:
        return 10 ** 8
    return ans + cnt

MIN = 10 ** 8
for i in range(2 ** D):
    MIN = min(MIN, solve(i))
print(MIN)

Measured memory_bytes: 3064
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

long long gcd(long long a,long long b)
{
	if(a%b == 0) return b;
	else return gcd(b,a%b);
}

long long lcm(long long m,long long n)
{
	if((m == 0) || (n == 0)) return 0;
	return ((m / gcd(m,n)) * n);
}


int main()
{
	long long a1,m1,a2,m2,a3,m3;
	while(cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3 && a1)
	{
		long long x = 1,y = 1,z = 1;
		
		
		long long count_x = 1;
		while(true)
		{
			if((a1*x)%m1 == 1)
			{
				break;
			}
			else
			{
				count_x++;
				x = (a1*x)%m1;
			}
		}

		long long count_y = 1;
		while(true)
		{
			if((a2*y)%m2 == 1)
			{
				break;
			}
			else
			{
				count_y++;
				y = (a2*y)%m2;
			}
		}

		long long count_z = 1;
		while(true)
		{
			if((a3*z)%m3 == 1)
			{
				break;
			}
			else
			{
				count_z++;
				z = (a3*z)%m3;
			}
		}

		long long ans = lcm(count_x,count_y);
		ans = lcm(ans,count_z);

		cout << ans << endl;
	}
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int i =0;
  bool flag = true;
  while(i<=(N-3)/2){
    if(S[i]!=S[(N-3)/2-i]) flag = false;
    ++i;
  }
  i = (N+1)/2;
  while(i<=N-1){
    if(S[i]!=S[(3*N-1)/2-i]) flag = false;
    ++i;
  }
  i = 0; 
  while(i<=N-1){
    if(S[i]!=S[(N-1)-i]) flag = false;
    ++i;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int X, Y;
  	cin >> X >> Y;
  	cout << 6-X-Y << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

int dp[MAX+1][MAX+1];

string getLCS(string &s, string &t, int len){
	string lcs = "";
	int i = 0;
	int j = 0;

	while(len){
		if(s[i] == t[j]){
			lcs.push_back(s[i]);
			i++;
			j++;
			len--;
		}
		else{
			if(dp[i][j+1]>dp[i+1][j]){
				j++;
			}
			else{
				i++;
			}
		}
	}
	return lcs;
}

int lenLCS(string &s, string &t, int i, int j){

	// Base Case
	if(i>=s.size() || j>=t.size()){
		return 0;
	}

	// Check if dp is calculated or not
	if(dp[i][j] == -1){
		if(s[i]==t[j]){
			dp[i][j] = 1 + lenLCS(s,t,i+1,j+1);
		}
		else{
			dp[i][j] = max(lenLCS(s,t,i+1,j),lenLCS(s,t,i,j+1));
		}
	}

	return dp[i][j];
}

string solve(string s, string t){
	
	// Making it to -1
	memset(dp, -1, sizeof dp);

	// Find the len of the lcs
	int len = lenLCS(s,t,0,0);
	return getLCS(s,t,len);

}

int main(){

	string s,t;
	cin>>s>>t;

	cout<<solve(s,t)<<"\n";
}

Measured memory_bytes: 35968
n = int(input())
tree = [[-1, -1, True] for i in range(n)]
for i in range(n):
    id, left, right = map(int, input().split())
    if left != -1:
        tree[id][0] = left
        tree[left][2] = False
    if right != -1:
        tree[id][1] = right
        tree[right][2] = False

def preoder(id):
    if id == -1:
        return
    print(' ' + str(id), end='')
    preoder(tree[id][0])
    preoder(tree[id][1])

def inorder(id):
    if id == -1:
        return
    inorder(tree[id][0])
    print(' ' + str(id), end='')
    inorder(tree[id][1])

def postorder(id):
    if id == -1:
        return
    postorder(tree[id][0])
    postorder(tree[id][1])
    print(' ' + str(id), end='')

root = 0
for i, node in enumerate(tree):
    if node[2] == True:
        root = i

print('Preorder')
preoder(root)
print('')
print('Inorder')
inorder(root)
print('')
print('Postorder')
postorder(root)
print('')



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
string s,s1;
ll ar[250007],cr[200098],a,b, test, sum,t,x=0,p,q,y,i,j,k=0,l,cnteven=0,w=0,cnt,br[200008];
int main()
{
    ll test;
ll m=9999999999;
cin>>a>>b;
for(i=1;i<=a;i++)
cin>>ar[i];
sort(ar+1,ar+a+1);
for(i=1;i<=a-b+1;i++)
 m=min(ar[i+b-1]-ar[i],m);
cout<<m<<endl;

}





Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <stack>
#define rep(i, n) for (int i = 0; i < n; i++)

int main(int argc, char *argv[]) {
  int x, i = 1;
  while (true) {
    std::cin >> x;
    if (x == 0) {
      break;
    }
    std::cout << "Case " << i << ": " << x << std::endl;
    i++;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int pass = 0;
		int b_pass = 0;
		String S = sc.next();
		for(int i = 0; i < S.length(); i ++){
			switch(S.charAt(i)){
			case 'a':
				if(pass < A + B){
					System.out.println("Yes");
					pass++;
				}else{
					System.out.println("No");
				}
				break;
			case 'b':
				if(pass < A + B && b_pass < B){
					System.out.println("Yes");
					pass++;
					b_pass++;
				}else{
					System.out.println("No");
				}
				break;
			default:
				System.out.println("No");
				break;
			}
		}
	}
}

Measured memory_bytes: 50396
n=int(input())
h=list(map(int, input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])

for i in range(2, n):
    a=abs(h[i]-h[i-1])
    b=abs(h[i]-h[i-2])
    dp[i]=min((dp[i-1]+a), (dp[i-2]+b))

print(dp[n-1])

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

int a[100001];
int N, i, cnt;
main(){
    cin >> N;
    for(; i<N; i++) cin >> a[i];
    for(int i = 0; i < N; i++){
        if(a[a[i] - 1] - 1 == i){
            cnt++;
        }
    }
    cout << cnt / 2 << endl;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  string ans = "Good";
  for(int i = 0; i < s.size()-1; i++){
    if(s[i] == s[i+1])ans = "Bad";
  }
  cout<<ans<<endl;
}

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

int main()
{
    int N;
    cin >> N;

    vector<int> H(N);
    rep(i,N) cin >> H[i];

    int ans = 0;
    int count = 0;
    rep(i,N-1) {
        if (H[i] >= H[i+1]) count++;
        else count = 0;
        if (ans < count) ans = count;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long v = in.nextLong();
			long[] a = in.nextLongArray(n);
			long[] b = in.nextLongArray(n);
			long[] c = in.nextLongArray(n);
			long[] d = in.nextLongArray(n);

			Map<Long, Long> map = new HashMap<>();

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					long key = a[i]+b[j];
					map.merge(key, 1L, Long::sum);
				}
			}
			long ans = 0;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (map.containsKey(v - (c[i]+d[j]))) {
						ans += map.get(v - (c[i]+d[j]));
					}
				}
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}



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

int main()
{
	
    vector<vector<int>> c(3, vector<int>(3));

	int a0;    // 0 <= c_ij <= 100
	int a1;
	int a2;
	int b0;
	int b1;
	int b2;

	string answer = "No";

	// 入力
	for (int i = 0; i < 3; i++) {
		cin >> c.at(i).at(0) >> c.at(i).at(1) >> c.at(i).at(2);
	}

	// a0
	a0 = 0;

	// b0,b1,b2
	b0 = c.at(0).at(0) - a0;
	b1 = c.at(0).at(1) - a0;
	b2 = c.at(0).at(2) - a0;

	// a1,a2
	a1 = c.at(1).at(0) - b0;
	a2 = c.at(2).at(0) - b0;


	if (a0 + b0 == c.at(0).at(0) &&
		a0 + b1 == c.at(0).at(1) &&
		a0 + b2 == c.at(0).at(2) &&

		a1 + b0 == c.at(1).at(0) &&
		a1 + b1 == c.at(1).at(1) &&
		a1 + b2 == c.at(1).at(2) &&

		a2 + b0 == c.at(2).at(0) &&
		a2 + b1 == c.at(2).at(1) &&
		a2 + b2 == c.at(2).at(2))
	{
		answer = "Yes";
	}
	
	cout << answer <<  endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long x;
  cin >> x;
  
  long ans = 0;
  
  ans = x/500;
  ans *= 1000;
  x = x%500;
  x = x/5;
  ans += x*5;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import Debug.Trace

main :: IO ()
main = do
    k <- readLn
    [x, y] <- map read.words <$> getLine
    case solve k x y of
        Nothing -> print (-1)
        Just ans | validate k ans -> do
            print $ length ans
            putStr $ concat[shows x$' ':shows y"\n"|(x,y)<-ans]

prop :: Int -> Int -> Int -> Bool
prop k x y = maybe True (validate k) $ solve k x y

solve :: Int -> Int -> Int -> Maybe [(Int, Int)]
solve k x y
    | even k && odd (x + y) = Nothing
    | even k    = Just . map f' $ solveEven k (f (x', y'))
    | otherwise = Just . map f' $ solveOdd  k (f (x', y'))
  where
    (!x', !y') = rot45 (x, y)
    !sx' | x' == 0 = 1
         | otherwise = signum x'
    !sy' | y' == 0 = 1
         | otherwise = signum y'
    f (xx, yy) = (abs xx, abs yy)
    f' (xx', yy') = rot45' (sx' * xx', sy' * yy')

rot45 :: (Int, Int) -> (Int, Int)
rot45 (x, y) = (x - y, x + y)

rot45' :: (Int, Int) -> (Int, Int)
rot45' (x, y) = (div (x + y) 2, div (y - x) 2)

solveEven :: Int -> (Int, Int) -> [(Int, Int)]
solveEven k (gx, gy)
    | max gx gy == k = [(gx, gy)]
    | 0 < gx, gx < k, 0 < gy, gy < k = [(k, gy - k), (gx, gy)]
    | otherwise = go (0, 0)
  where
    go (!x, !y)
        | dx > 2 * k, dy > 2 * k = (x + k, y + k):go (x + k, y + k)
        | dx > 2 * k = (x + k, y):go (x + k, y)
        | dy > 2 * k = (x, y + k):go (x, y + k)
        | max dx dy == k = [(gx, gy)]
        | gx - x <= k = [(x + k, gy - k), (gx, gy)]
        | gy - y <= k = [(gx - k, y + k), (gx, gy)]
        | otherwise = [(gx - k, y + k), (gx, gy)]
      where
        !dx = gx - x
        !dy = gy - y

solveOdd :: Int -> (Int, Int) -> [(Int, Int)]
solveOdd k (gx, gy)
    | max gx gy == k = [(gx, gy)]
    | 0 < gx, gx < k, 0 < gy, gy < k, odd gx = [(k, -1), (gx + k, k - 1), (gx, gy)]
    | 0 < gx, gx < k, 0 < gy, gy < k = [(k, gy - k), (gx, gy)]
    | otherwise = go (0, 0)
  where
    go (!x, !y)
        | dx > 2 * k, dy > 2 * k = (x + k, y + k):go (x + k, y + k)
        | dx > 2 * k, y + 1 <= gy = (x + k, y + 1):go (x + k, y + 1)
        | dx > 2 * k = (x + k, y - 1):go (x + k, y - 1)
        | dy > 2 * k, x + 1 <= gx = (x + 1, y + k):go (x + 1, y + k)
        | dy > 2 * k = (x - 1, y + k):go (x - 1, y + k)
        | max dx dy == k = [(gx, gy)]
        | gx - x <= k, even dy = [(x + k, gy - k), (gx, gy)]
        | {- gy - y <= k, -} even dx = [(gx - k, y + k), (gx, gy)]
        | dx > k, odd dx = (x + k, y - 1) : go (x + k, y - 1)
        | dy > k, odd dy = (x - 1, y + k) : go (x - 1, y + k)
      where
        !dx = gx - x
        !dy = gy - y


dist :: (Int, Int) -> (Int, Int) -> Int
dist (x0, y0) (x1, y1) = abs (x1 - x0) + abs (y1 - y0)

validate :: Int -> [(Int, Int)] -> Bool
validate k xys = all (==k) $ zipWith dist ((0,0):xys) xys


Measured memory_bytes: 33452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
string s;
ll ans = 0;
string half1, half2;
int dp[20][20];
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    srand(time(0));
    cin >> n;
    cin >> s;
    for (int i = 0; i < n; i++) half1 += s[i];
    for (int i = n; i < 2 * n; i++) half2 += s[i];
    reverse(half2.begin(), half2.end());
    for (int mask = 0; mask < (1 << n); mask++) {
        string cur1 = "";
        string cur2 = "";
        for (int j = 0; j < n; j++) {
            if (mask & (1 << j)) cur1 += half1[j];
            else cur2 += half1[j];
        }
        memset(dp, 0, sizeof dp);
        dp[0][0] = 1;
        for (int j = 0; j <= cur1.size(); j++) {
            for (int k = 0; k <= cur2.size(); k++) {
                if ((j < cur1.size()) && half2[j + k] == cur1[j]) dp[j + 1][k] += dp[j][k];
                if ((k < cur2.size()) && half2[j + k] == cur2[k]) dp[j][k + 1] += dp[j][k];
            }
        }
        ans += dp[cur1.size()][cur2.size()];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int bnd = in.nextInt();
        int lim = in.nextInt();
        int pos = 0;
        int ans = 0;

        for (int i = 0; i < bnd; i++) {
            pos += in.nextInt();
            if (lim < pos) {
                ans = i + 1;
                break;
            } else if (lim == pos) {
                ans = i + 2;
                break;
            } else if (i == bnd - 1) {
                ans = bnd + 1;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
using namespace std;
int n,len;
int t[26];
int u[26];
vector<int> G[26];
bool visited[26];
string str;

void dfs(int pos){
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    int w=G[pos][i];
    if(visited[w])continue;
    dfs(w);
  }
}

int main(){
  while(cin>>n&&n){
    for(int i=0;i<26;i++){
      t[i]=u[i]=0;
      visited[i]=false;
      G[i].clear();
    }
    int c;
    for(int i=0;i<n;i++){
      cin>>str;
      len=str.size();
      t[ str[0]-'a' ]++;
      u[ str[len-1]-'a' ]++;
      G[ str[0]-'a' ].push_back( str[len-1]-'a' );
      if(i==0)c=str[0]-'a';
    }
    dfs(c);
    bool flg=true;
    for(int i=0;i<26;i++){
      if(t[i]!=u[i])flg=false;
      if(t[i]>0&&visited[i]==false)flg=false;
    }
    if(flg)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int x = sc.NextInt();

        int answer = 0;
        for (int b = 1; b <= 1000; b++)
        {
            for (int p = 2; p <= 1000; p++)
            {
                int tmpAnswer = (int)Math.Pow(b, p);
                if (tmpAnswer > x)
                {
                    break;
                }
                answer = Math.Max(tmpAnswer, answer);
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

using namespace std;
typedef long long ll;

int N;
int m[15][15];

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            m[i][j] = -1;
        }
    }
    for(int i=0;i<N;i++){
        int A;
        cin >> A;
        for(int j=0;j<A;j++){
            int x,y;
            cin >> x >> y;
            m[i][x-1] = y;
        }
    }
    int max_s = 0;
    for(int i=0;i<(1<<N);i++){
        bitset<15> bt(i);
        bool f = true;
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                if(m[j][k] == -1) continue;
                if(m[j][k] == 1){
                    if(bt[j] == 1 && bt[k] == 0) f = false;
                }else{
                    if(bt[j] == 1 && bt[k] == 1) f = false;
                }
            }
        }
        if(f) max_s = max(max_s, (int)bt.count());
    }
    cout << max_s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<math.h>
using namespace std;

int main(){
    int n,m;;
    cin>>m;
    int count=m;
    for(int s=0; s<m; s++){
        cin>>n;
        if(n==2) continue;
        else if(n%2==0)count--;
        else{
        for(int i=3; i<=sqrt(n); i+=2){
            if(n%i==0){count--;
            break;
            }
        }
        }
    }
    cout<<count<<endl;

    return 0;
}

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

C = {}
for a in A:
    if not(a in C):
        C[a] = 0

    C[a] += 1

s = sum(c*(c-1)//2 for c in C.values())

for a in A:
    c = C[a]
    print(s - c*(c-1)//2 + (c-1)*(c-2)//2)





Measured memory_bytes: 24996
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N;
  cin>>N;
  VL A(N);
  rep(i,N) cin>>A[i];
  set<ll> S;
  S.insert(-1);
  S.insert(N);
  VL X(N);
  rep(i,N) X[A[i]-1]=i;
  ll ans=0;
  rep(i,N){
    auto itr=S.lb(X[i]);
    ll R=*itr;
    itr--;
    ll L=*itr;
    ans+=(R-X[i])*(X[i]-L)*(i+1);
    S.insert(X[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);

int main(){
    int n;
    cin >> n;
    
    vector<pair<long double, pair<int, int>>> point;
    for(int i=0; i<n; i++){
        int x, y;
        cin >> x >> y;

        if(x == 0 && y == 0) continue;

        point.push_back({atan2(y,x)       , {x,y}});
        point.push_back({atan2(y,x) + 2*PI, {x,y}});
    }
    sort(point.begin(), point.end());

    n = point.size() / 2;

    // cumulative sum
    vector<int> x(2*n+1), y(2*n+1);
    vector<long double> angle(2*n);
    for(int i=0; i<2*n; i++){
        x[i+1] = point[i].second.first;
        x[i+1] += x[i];
        y[i+1] = point[i].second.second;
        y[i+1] += y[i];
        angle[i] = point[i].first;
        //cout << fixed << setprecision(5) << angle[i] << endl;
    }    

    long long int ans = 0;
    for(int i=0; i<n; i++){
        int m = upper_bound(angle.begin(), angle.end(), angle[i] + PI) - angle.begin();
        //cout << j << " : ";
        for(int j=i+1; j<=m; j++){
            long long int xsum = x[j] - x[i];
            long long int ysum = y[j] - y[i];
            ans = max(ans, xsum * xsum + ysum * ysum);
        }
    }
    cout << fixed << setprecision(12) << sqrt(ans) << endl;
    return 0;
}

Measured memory_bytes: 4160