akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <stack>
#define N 110
using namespace std;
stack<int> s;
int n;
int m[N][N];
int used[N];
int time = 1;
int bb_start[N];
int bb_end[N];
int getnext(int u){
    for(int i = 1; i <= n; i++){
        if(m[u][i] == 1 && used[i] == 0) return i;
    }
    return -1;
}
void dfs(int root){
    used[root] = 1;
    bb_start[root] = time++;

    while(!s.empty()) s.pop();
    s.push(root);
    while(!s.empty()){
        int u = s.top();
        int v = getnext(u);
        if(v != -1 && used[v] == 0){
            used[v] = 1;
            bb_start[v] = time++;
            s.push(v);
        } else{
            bb_end[u] = time++;
            s.pop();
        }
    }
}
int main(){
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) m[i][j] = 0;
    for(int i = 0; i < N; i++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }
    for(int i = 1; i <= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, bb_start[i], bb_end[i]);
    }
    return 0;
}


Measured memory_bytes: 2768
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;
void main()
{
    long a, b, c;
    readf("%d/%d/%d", &a, &b, &c);
    bool x = a < 2019;
    x = x || (a == 2019 && b < 4);
    x = x || (a == 2019 && b == 4 && c <= 30);
    writeln(x ? "Heisei" : "TBD");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string a,b,c;
	cin >> a>>b>>c;
	cout << a[0] << b[0] << c[0] << endl;

	return 0;
}



Measured memory_bytes: 256
s = list(input())
k = ["k", "e", "y", "e", "n", "c", "e"]
ans = []
i = 0
while s[i] == k[i]:
    ans.append(s[i])
    i += 1
    if i == 7:
        break
for j in range(len(s) - 7 + i, len(s)):
    ans.append(s[j])

jud = True
for j in range(7):
    if ans[j] != k[j]:
        jud = False
if jud:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 61868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0029
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> nums = new List<int>();

            nums.Add(int.Parse(Console.ReadLine()));
            nums.Add(int.Parse(Console.ReadLine()));
            nums.Add(int.Parse(Console.ReadLine()));
            nums.Add(int.Parse(Console.ReadLine()));
            nums.Add(int.Parse(Console.ReadLine()));

            int k = int.Parse(Console.ReadLine());

            for (int i = 0; i < nums.Count() - 1; i++)
            {
                for (int j = i + 1; j < nums.Count(); j++)
                {
                    if (nums[j] - nums[i] > k)
                    {
                        Console.WriteLine(":(");
                        return;
                    }
                }
            }

            Console.WriteLine("Yay!");
        }
    }
}


Measured memory_bytes: 28028
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int mod = 1e9 +7;


int main(){
    int n;
    cin>>n;
    vector<double>arr(n);
    for(int i = 0; i < n ; i++){
        cin>>arr[i];
    }
    vector<vector<double>>dp(n+1, vector<double>(n+1, 0));
    dp[1][1] = arr[0];
    dp[1][0] = 1.0 - arr[0];
    for(int i = 2 ; i <= n ; i++){
        dp[i][0] = dp[i-1][0]*(1.0-arr[i-1]);
        for(int j = 1 ; j <= n ; j++){
            dp[i][j] = dp[i-1][j]*(1.0-arr[i-1]) + dp[i-1][j-1]*arr[i-1];
        }
    }
    int t= n/2;
    double ans = 0.0;
    for(int j = t+1; j<=n; j++){
        ans = ans+dp[n][j];
        // cout<<dp[n][j]<<" ";
    }   
    cout<<setprecision(10)<<ans;
    // cout<<endl;
    // for(int i = 1; i <= n ;i++){
    //     cout<<dp[i][0]<<" ";
    // }
    // for(int i = 1 ; i <= 3; i++){
    //     for(int j = 1 ;j <= 3; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
 
const int MAX = 1000005;
const ll MOD = 1000000007;
 
ll mul(ll x, ll y) {return (x*y)%MOD;}
ll add(ll x, ll y) {return (x+y)%MOD;}
 
int main() {
 
    int N;
    cin >> N;
    vector<ll> C(N);
    REP(i,N) cin >> C[i];
    sort(all(C),greater<ll>());
    vector<ll> v(N+1);
    v[0] = 1;
    ll M = 1;
    FOR(i,1,N) {
        M = (M*2) % MOD;
        v[i] = M;
    }
    ll ans = 0;
    REP(i,N) {
        ans += mul(mul(mul(C[i],((ll)i+2)),v[N-1]),v[N-1]); ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

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

int n;
int x[110000];
int nxt[110000][40];
int L;

int query(int a, int b) {
	int ans = 0;
	for (int l = 20; l >= 0; l--) {
		if (nxt[a][l] < b) {
			a = nxt[a][l];
			ans += (1<<l);
		}
	}
	return ans+1;
}

int main() {
	scanf("%d", &n);
	REP(i,n) scanf("%d", x+i);

	scanf("%d", &L);
	REP(i,n) {
		nxt[i][0] = (upper_bound(x, x+n, x[i]+L) - x) - 1;
	}

	for (int l = 1; l < 32; l++) {
		REP(i,n) {
			nxt[i][l] = nxt[ nxt[i][l-1] ][l-1];
		}
	}

	int q;
	scanf("%d", &q);
	REP(i,q) {
		int a,b;
		scanf("%d %d", &a, &b); a--;b--;
		if (a > b) swap(a,b);
		printf("%d\n", query(a,b));
	}
}

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

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

    double p = 0.0;

    for(int i=1;i<n+1;++i)
    {
        int m = i;
        double pi = 1.0;
        while(m<k)
        {
            m *= 2;
            pi *= 0.5;
        }

        p += pi/n;
    }

    cout << fixed << setprecision(12);
    cout << p << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL P = 1000000007;
const int maxn = 100005;
int n, m, x, pos[maxn], L, R;
LL frac[maxn], frav[maxn];
LL C(int n, int m) {
    if (m > n) return 0LL;
    return frac[n] * frav[m] % P * frav[n - m] % P;
}
int main() {
    scanf("%d", &n);
    frac[0] = frav[0] = frav[1] = 1;
    for (int i = 1; i <= 100002; ++i) { frac[i] = frac[i-1] * i % P; pos[i] = -1; }
    for (int i = 2; i <= 100002; ++i) frav[i] = P - (P / i) * frav[P % i] % P;
    for (int i = 1; i <= 100002; ++i) (frav[i] *= frav[i-1]) %= P;
    for (int i = 0; i <= n; ++i) {
        scanf("%d", &x);
        if (pos[x] != -1) {
            m = pos[x] + n - i;
            break;
        }
        pos[x] = i;
    }
    for (int i = 1; i <= n + 1; ++i) {
        printf("%lld\n", (P + C(n + 1, i) - C(m, i - 1)) % P);
    }
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

// a以上の最小のbの倍数
ll Upmul(ll a, ll b) {
	if (a%b == 0) return a;
	else return b * ((a / b) + 1);
}


int A[100001];
int B[100001];

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

	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
	ll ans = 0;

	for (int i = N-1; i>=0; i--) ans += (Upmul(A[i] + ans, B[i]) - (A[i] + ans));
	cout << ans << endl;

	return 0;
}

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

using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  
  map<string,ll> sums;
  
  for(int i=0; i<N; i++){
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
    
    if(sums.count(S[i])==0){
      sums[S[i]] = 1;
    }else{
      sums[S[i]]++;
    }
  }
 
  ll ans = 0;
  
  for(auto itr=sums.begin(); itr != sums.end(); ++itr){
    if(itr->second > 1) {
             ll num = itr->second-1;
             ans += (num*(num+1)/2);
     }
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 13984
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();
            String s = in.next();

            for (int i = 0; i < a; i++) {
                char ch = s.charAt(i);
                if (!(ch >= '0' && ch <= '9')) {
                    out.println("No");
                    return;
                }
            }

            if (s.charAt(a) != '-') {
                out.println("No");
                return;
            }

            for (int i = a + 1; i < a + b + 1; i++) {
                char ch = s.charAt(i);
                if (!(ch >= '0' && ch <= '9')) {
                    out.println("No");
                    return;
                }
            }

            out.println("Yes");

        }

    }
}



Measured memory_bytes: 22996
#include <stdio.h>
#include <stdlib.h>

int mini(int x,int y){
	if(x >= y) return y;
	else return x;
}

int comp(const void *a,const void *b){
	long long int da = *(long long int*)a;
    long long int db = *(long long int*)b;
    if(da > db)
    	return -1;
    else if(da == db)
    	return 0;
    else return 1;
}

int main()
{
	int a,b,c,k;
	long long x[1001],y[1001],z[1001];
	long long sum = 0;
	long long s[300000];
	
	scanf("%d %d %d %d",&a,&b,&c,&k);
	for(int i = 0;i < a;i++)
		scanf("%lld",&x[i]);
	for(int i = 0;i < b;i++)
		scanf("%lld",&y[i]);
	for(int i = 0;i < c;i++)
		scanf("%lld",&z[i]);
	
	qsort(x,a,sizeof(x[0]),comp);
	qsort(y,b,sizeof(y[0]),comp);
	qsort(z,c,sizeof(z[0]),comp);
	
	for(int i = 0;i < mini(k,a);i++){
		for(int j = 0;j < mini(k/(i+1),b);j++){
			for(int g = 0;g < mini(k/((i+1)*(j+1)),c);g++){
				s[sum] = x[i] + y[j] + z[g];
				sum++;
			}
		}
	}
	
	qsort(s,sum,sizeof(s[0]),comp);
	for(int i = 0;i < k;i++)
		printf("%lld\n",s[i]);
	return 0;
}

Measured memory_bytes: 3324
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];

 
ll n,m,ans=0;
ll i,j;
ll a[100005];
ll x,num;

int main(){
	cin>>n>>x;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n-1;i++){
		num = a[i]+a[i+1];
		if(num>x && a[i+1] >= num-x){
			a[i+1] -= num-x;
			ans += num-x;
		}else if(num > x){
			a[i] -= (num-x-a[i+1]);
			a[i+1] = 0;
			ans += num-x;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#n = int(input())
a, b, c, x, y = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
mn = a*x+b*y
for i in range(0, max(x, y)+1):
    mn = min(mn, max(x-i, 0)*a+max(y-i, 0)*b+2*i*c)
print(mn)


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

int main(){
    int A, B, ans = 0;
    cin >> A >> B;
    if(A >= B){
        ans += A;
        A -= 1;
    }else{
        ans +=B;
        B -= 1;
    }
    ans += max(A, B);
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
long long q,h,s,d,n,res;
int main()
{
	scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
	res=(!(n%2))? (min(min(min(q*8,h*4),s*2),d)*n>>1):(min(min(min(q*8,h*4),s*2),d)*(n-1)>>1)+(min(min(q*4,h*2),s));
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


class UnionFind:
    def __init__(self, n: int):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x: int):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x: int, y: int):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        if self.parents[y] < self.parents[x]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x: int):
        return -self.parents[self.find(x)]
    
    def same(self, x: int, y: int):
        return self.find(x) == self.find(y)
    
    def members(self, x: int):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N, M = map(int, rl().split())
    uf = UnionFind(N)
    for _ in range(M):
        a, b = map(lambda n: int(n) - 1, rl().split())
        uf.union(a, b)
    
    ans = 0
    for i in range(N):
        ans = max(ans, uf.size(i))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 78500
#include <stdio.h>
 
int main(){
    int countTable[256] = {0};
    char ch;
 
    while((ch = getchar()) != EOF){
                countTable[ch]++;
    }
    for(int i = 97; i <=122;i++)printf("%c : %d\n",i,countTable[i]+countTable[i-32]);
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
char s[1000001];
int f[100011][14];
main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	f[0][0]=1;
	for(int i=1; i<=n; i++) {
		for(int k=0; k<=9; k++)
			for(int j=0; j<=12; j++) {
				if(s[i]=='?')
					f[i][(k+j*10%13)%13]=(f[i][(k+j*10%13)%13]+f[i-1][j])%mod;
				else if(s[i]-'0'==k)
					f[i][(k+j*10%13)%13]=(f[i][(k+j*10%13)%13]+f[i-1][j])%mod;
			}
	}
//	cout<<f[2][0]<<"";
	cout<<f[n][5]<<endl;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; string S; 
	cin >> N >> S; 
	long long r = 0, g = 0, b = 0; 
	for(int i = 0; i < N; i++){
		if(S.at(i) == 'R') r++; 
		if(S.at(i) == 'G') g++;
		if(S.at(i) == 'B') b++;
	}
	long long ans = r * g * b; 
	for(int i = 0; i < N; i++){
		for(int j = 1; (i-j >= 0 && i+j < N); j++){
			if(S.at(i) != S.at(i-j) && S.at(i) != S.at(i+j) && S.at(i-j) != S.at(i+j)) ans --; 
		}
	}
	cout << ans << endl; 
}

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

int main() {
  ll a1,a2,a4,a8,n,ans=0;
  cin >> a1>>a2>>a4>>a8>>n;
  n*=4;
  if(a1*8>=a8&&a2*4>=a8&&a4*2>=a8){
    ans+=(n/8)*a8;
    n=n%8;
  }
  if(a1*4>=a4&&a2*2>=a4){
    ans+=(n/4)*a4;
    n=n%4;
  }
  if(a1*2>=a2){
    ans+=(n/2)*a2;
    n=n%2;
  }
  ans+=n*a1;
  cout << ans<<endl;
}


Measured memory_bytes: 256
n=int(input())
lst=list(map(int,input().split()))
num=0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if (i<j<k and i!=j and j!=k and k!=i) and (lst[i]!=lst[j] and lst[j]!=lst[k] and lst[k]!=lst[i]) and (lst[i]+lst[j]>lst[k] and lst[j]+lst[k]>lst[i] and lst[k]+lst[i]>lst[j] ):
                num+=1
print(num)


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

int gcd(int x, int y){
	if(y == 0) return x;
	return gcd(y, x%y);
}

int main(){
	int w, h, c;
	cin >> w >> h >> c;
	int area = pow(gcd(w, h), 2);
	cout << w*h / area * c << endl;
	return 0;
}


Measured memory_bytes: 3104
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    int A,B,C,D;
    cin>>A>>B>>C>>D;

    if(A==C){
        cout<<0<<endl;
    }
    else{
        cout<<1<<endl;
    }


}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[100010];
int X[100010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int sum=0;
	int sum2=0;
	REP(i,N){
		sum+=A[i];
	}
	for(int i=1;i<N;i+=2){
		sum2+=A[i];
	}
	X[0]=sum-sum2*2;
	for(int i=1;i<N;i++){
		X[i]=A[i-1]*2-X[i-1];
	}
	REP(i,N){
		cout<<X[i];
		if(i<N-1){
			cout<<" ";
		}
	}
	cout<<endl;
	return 0;
}


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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

n = input()
if n == 0:
    print '0'
    exit()
num = 1
sig = 1
ans = ''
while n != 0:
    if n % (num * 2) != 0:
        n -= num * sig
        ans += "1"
    else:
        ans += "0"
    num *= 2
    sig *= -1
print ans[::-1]

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

int main() {
  int N,M,s,c;
  int ans;
  ans=0;
  cin >>N>>M;
  if(M==0){
    if(N==1){
      cout<<0<<endl;
    }
    if(N==2){
      cout<<10<<endl;
    }
    if(N==3){
      cout<<100<<endl;
    }
    return 0;
  }
  int a[N+1];
  for(int i=0;i<N+1;i++){
    a[i]=10;
  }
  for(int i=0;i<M;i++){
    cin>>s>>c;
    if(a[s]==10||a[s]==c){
      a[s]=c;
    }
    else{
      cout<<-1<<endl;
      return 0;
    }
  }
  if(N==1){
    if(a[1]==10){
    cout<<0<<endl;
    return 0;
    }
    else{
      cout<<a[1]<<endl;
      return 0;
    }
  }
    if(a[1]==0){
      cout<<-1<<endl;
      return 0;
    }
    if(a[1]==10){
      ans=1;
    }
    else{
      ans=a[1];
    }
    for(int i=2;i<N+1;i++){
      ans*=10;
      if(a[i]==10){
       continue;
      }
      else{
        ans+=a[i];
      }
    }
  cout <<ans<< endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[110][110];
ll dp[110][110];
int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	rep(i,0,h)scanf("%s",s[i]);
	//白→黒だけコストがかかる
	dp[0][0]=s[0][0]=='#';
	rep(i,0,h)rep(j,!i,w){
		dp[i][j]=1000;
		if(i)dp[i][j]=min(dp[i][j],dp[i-1][j]+(s[i-1][j]=='.'&&s[i][j]=='#'));
		if(j)dp[i][j]=min(dp[i][j],dp[i][j-1]+(s[i][j-1]=='.'&&s[i][j]=='#'));
	}
	printf("%d",dp[h-1][w-1]);
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(b==1){cout<<0<<endl; return 0;}
    cout<<RUP(b-1,a-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

string ch;
int main(){
    //cout<<endl;
    cin>>ch;
    int ans=0;
    int i=0;
    int minl;;
    while(i<ch.length()){
        //cout<<"i == "<<i<<"max == "<<ans<<endl;
        int j=i;
        int cnt_j=0,cnt_o=0,cnt_i=0;
        while(ch[j]=='J') {cnt_j++; j++;}
        if(cnt_j==0) {i++; continue;}
        
        while(ch[j]=='O') {cnt_o++; j++;}
        if(cnt_o>cnt_j) {i+=cnt_j+cnt_o; continue;}
        while(ch[j]=='I'){cnt_i++; j++;}
        if(cnt_i<cnt_o) {i+=cnt_o+cnt_j+cnt_i; continue;}
        minl=min(cnt_i,cnt_o);
        ans=max(minl,ans);
        i+=cnt_j+cnt_o+cnt_i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int res = 0;
  rep(i,0,n-2){
    if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C')res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define N 200010
#define ll long long
#define mod 1000000007
using namespace std;
int n, m, A, B, ans, jc[N], inv[N];
inline int C(int n, int m){return (ll)jc[n]*inv[m]%mod*inv[n-m]%mod;}
int main(){
	scanf("%d%d%d%d", &n, &m, &A, &B);
	jc[0]=1; for(int i=1; i<=n+m; i++)jc[i]=(ll)jc[i-1]*i%mod;
	inv[0]=inv[1]=1; for(int i=2; i<=n+m; i++)inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1; i<=n+m; i++)inv[i]=(ll)inv[i-1]*inv[i]%mod;
	ans=0;
	for(int i=A+1; i<=n; i++)ans=(ans+(ll)C(n-i+B-1, B-1)*C(i+m-B-2, m-B-1)%mod)%mod;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1664
import sys

S = input()
N = len(S)

d = {}
for i in S:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1


def trans(t, a):
    s = ''
    for i in range(len(t)-1):
        if t[i] == a or t[i+1] == a:
            s += a
        else:
            s += t[i+1]
    return s


min_val = 1000
for k in d.keys():
    s = S
    n = 0
    while s.count(k) != len(s):
        s = trans(s, k)
        n += 1
    if n < min_val:
        min_val = n

print(min_val)



Measured memory_bytes: 3064
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void solve()
{
    int H,W, m;
    scanf("%d%d%d", &H, &W, &m);
    vector<int> h(m), w(m), cnt0(H), cnt1(W);
    int i;
    for (i = 0; i < m; i++) {
        scanf("%d%d", &h[i], &w[i]); h[i]--; w[i]--;
        cnt0[h[i]]++;
        cnt1[w[i]]++;
    }
    int ans = 0;
    int cnt0max = 0, cnt1max = 0, cnt0maxcnt = 0, cnt1maxcnt = 0;
    for (i = 0; i < H; i++) {
        cnt0max = MAX(cnt0max, cnt0[i]);
    }
    for (i = 0; i < H; i++) {
        if (cnt0[i] == cnt0max) cnt0maxcnt++;
    }

    for (i = 0; i < W; i++) {
        cnt1max = MAX(cnt1max, cnt1[i]);
    }
    for (i = 0; i < W; i++) {
        if (cnt1[i] == cnt1max) cnt1maxcnt++;
    }

    int cnt = 0;
    for (i = 0; i < m; i++) {
        if (cnt0[h[i]] == cnt0max && cnt1[w[i]] == cnt1max) cnt++;
    }
    if ((ll)cnt0maxcnt*cnt1maxcnt > cnt) {
        printf("%d\n", cnt0max + cnt1max);
    }
    else {
        printf("%d\n", cnt0max + cnt1max-1);
    }

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 7528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n+5] = {};
    map<long long, int>mp;
    long long sum = 0;
    for(int i = 1; i <= n; i++)
    {
        long long tem; cin >> tem;
        sum += tem;
        mp[tem]++;
    }
    int p; cin >> p;
    for(int i = 1; i <= p; i++)
    {
        long long a, b; cin >> a >> b;
        long long tem = mp[a]*a;
        sum -= tem;
        int mm = mp[a];
        mp[a] = 0;
        sum += (mm*b);
        mp[b] += mm;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 9768
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << a[2] - a[0] << endl;

  return 0;
}

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

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

ans = 0
for a1, a2 in zip(A, A[1:]):
    if a1 >= a2:
        ans += a2
    else:
        ans += a1
ans += A[-1]
ans += A[0]
print(ans)


Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ull a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

int main(void) {
    cin >> n >> r;
    if (n < 10) {
        cout << r + 100 * (10 - n) << endl;
    } else {
        cout << r << endl;
    }
    

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n,a,b,r=0;
 	cin >> n>>a>>b;
 	for (int i = 0; i <= n; i++){
 		int c=0,t=i;
		 for(int j=0;j<5;j++)c+=t%10,t/=10;
		 if(a<=c&&c<=b)r+=i;
 	}
 	cout << r << endl;
 }

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"os"
)

func main() {
	var n float64
	fmt.Scan(&n)
	N := int(n)
	i := math.Floor(math.Sqrt(n))
	for a := int(i); a > 0; a-- {
		if N%a == 0 {
			b := N / a
			ans := b + a - 2
			fmt.Println(ans)
			os.Exit(0)
		}
	}
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  
  int ord[n];
  rep(i,n)ord[a[i]-1]=i+1;
  rep(i,n)cout << ord[i] << " ";
  cout << endl;
}

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

int main() {
  int h, n;
  cin >> h >> n;
  for (int i = 0; i < n; i++) {
    int e;
    cin >> e;
    h -= e;
  }
  cout << (h <= 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n = int(input())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if not moji[0]+moji[-1] in f_dict:
    f_dict[moji[0]+moji[-1]] = 1
  else:
    f_dict[moji[0]+moji[-1]] += 1 
  if not moji[-1]+moji[0] in s_dict:
    s_dict[moji[-1]+moji[0]] = 1
  else:
    s_dict[moji[-1]+moji[0]] += 1
for mykey in f_dict.keys():
  if mykey in s_dict:
      cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    string s,t;
    cin>>s>>t;
    set<int> st[26];
    rep(i,0,s.size()){
        int c=s[i]-'a';
        st[c].insert(i);
    }
    ll a=0,b=0;
    rep(i,0,t.size()){
        int c=t[i]-'a';
        if(st[c].empty()){
            cout<<-1<<endl;
            return 0;
        }
        auto pos=st[c].lower_bound(b);
        if(pos==st[c].end()){
            b=0;
            a++;
            pos=st[c].lower_bound(b);
        }
        b=*pos+1;
    }
    cout<<s.size()*a+b<<endl;
    return 0;
}




Measured memory_bytes: 8520
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(N) : 
    for j in range(S + 1) : 
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod 
        if j + A[i] <= S : 
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= mod
print(dp[N][S])

Measured memory_bytes: 147680
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int x = sc.nextInt();

		int[] a = new int[N];

		for(int i=0;i<N;i++) {

			a[i] = sc.nextInt();
		}

		int temp = 0;

		for(int i=0;i<N-1;i++) {

			for(int j=i+1;j<N;j++) {

				if(a[i]>a[j]) {

					temp = a[i];

					a[i] = a[j];

					a[j] = temp;
				}
			}
		}

		int sum = 0;

		int k = 0;

		int ans = 0;

		while(sum <= x) {

			if(k>=a.length)break;

			sum += a[k];

			k++;

			ans ++;

		}
		if(sum == x) {
			System.out.println(ans);
		}else {
			System.out.println(ans-1);
		}
	}

}


Measured memory_bytes: 23636
/*input
ABCACCBABCBCAABCB
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
	string S;
	cin>>S;
	int count =0;
	int match =0;
	long long ans =0;
	for(int i=0;i<S.length();i++){
		if(S[i]=='A'){
			count ++;
		}
		else if(i+1 < S.length() && S[i] == 'B' && S[i+1] == 'C') {
			ans+=count; i++;
		}
		else count =0;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 640
#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>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
	int prev = std::numeric_limits<int>::max();
	int count = -1;
	int max = 0;
	for (auto v : vec | adaptor::reversed)
	{
		if (v < prev)
		{
			count = -1;
		}
		++count;
		prev = v;
		max = std::max(max, count);
	}
	std::cout << max << std::endl;
}

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

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll A, B, C, D; cin >> A >> B >> C >> D;
	auto dp = makeVector(C+1, D+1, 0ll);

	dp[A][B] = 1;
	for (int a = A; a <= C; a++) {
		for (int b = B; b <= D; b++) {
			if (a > A) (dp[a][b] += dp[a-1][b] * b) %= mod2;
			if (b > B) (dp[a][b] += dp[a][b-1] * a) %= mod2;
			if (a > A && b > B) (dp[a][b] += mod2 - (dp[a-1][b-1] * (a-1) % mod2 * (b-1) % mod2) % mod2) %= mod2;
		}
	}
	cout << dp[C][D] << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 73588
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    string S;
    cin >> S;

    vector<int> cnt(2, 0);

    for(int i=0; i<S.size(); i++){
        // '1'-'0'=1, '0'-'0'=1
        cnt[S[i]- '0']++;
    }

    cout << min(cnt[0], cnt[1])*2 << endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 100000+5;
const LL mod = 1000000007;
int main()
{
    int a,b;
    char op;
    scanf("%d %c %d",&a,&op,&b);

    printf("%d\n",op=='+'?a+b:a-b);
    return 0;
}

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

int main() {
    int x,n,p[1000],m,ans1;
    int temp[1000]={0};
    cin>>x>>n;
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        temp[abs(x-p[i])]++;
    }

    for(int i=0;i<=100;i++)
    {
        if(i!=0 && temp[i]<=1)
        {
            m = i;
            break;
        }
        if(temp[0]==0)
        {
            m=i;
            break;
        }
    }
    ans1 = x-m;
    int ans2 = x+m;
    int c=0,d=0;
    for(int i=0;i<n;i++)
    {
        if(ans1== p[i])
        {
            c=1;
            break;
        }
        if(ans2==p[i])
        {
            d=1;
            break;
        }
    }
    if(c==0 && d==0)
    {
        cout<<min(ans1,ans2)<<endl;
    }
    else if(c==0)
    {
        cout<<ans1<<endl;
    }
    else if(d==0)
    {
        cout<<ans2<<endl;
    }
}


Measured memory_bytes: 3632
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * n for _ in range(n)]
for L in range(n - 1, -1, -1):
    for R in range(L, n):
        if L == R:
            dp[L][R] = a[L]
        else:
            dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1])
print(dp[0][n - 1])

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

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

    int sum;
    int dig;
    int d = n;

    while (d)
    {
        dig = d % 10;
        sum = sum + dig;
        d = d / 10;
    }
    (n % sum == 0) ? cout << "Yes" : cout << "No";
}

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

struct drink{
	long long a, b;
}emm[100005];

bool cmp(drink a, drink b)
{
	return a.a<b.a;
}

int main()
{
	int n, m;
	cin>>n >>m;
	int amax=0;
	for(int i=0; i<n; i++)
	{
		int a, b;
		cin>>a >>b;
		emm[i].a=a, emm[i].b=b;
	}
	sort(emm, emm+n, cmp);
	long long sum=0;
	for(int i=0; i<n; i++)
	{
			if(emm[i].b<m) m-=emm[i].b, sum+=emm[i].a*emm[i].b;
			else
			{
				sum+=m*emm[i].a;
				break;
			}
		
	}
	cout<<sum;
} 


Measured memory_bytes: 1792