akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] cnt = new int[N];
    for (int i = 1; i < N; i++) {
      int A = scanner.nextInt();
      cnt[A - 1]++;
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
      sb.append(cnt[i]).append('\n');
    }
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 50220
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m,c; cin >> n >> m >> c;
  vector<int>a(m);
  vector<int>b(m);
  for(int i = 0;i < m;i++){
    cin >> b[i];
  }
  int count;
  for(int j = 0;j < n;j++){
    int sum = c;
    for(int i = 0;i < m;i++){
      cin >> a[i];
      sum += (a[i] * b[i]);
    }
    if (sum > 0){
      count++;
    }
  }
  cout << count << endl;
}

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

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define ALL(a) a.begin, a.end()

using namespace std;

int main(void) {

	int N;

	cin >> N;

	vector<int> A(N);

	double sum = 0;

	REP(i, N) cin >> A[i];

	REP(i, N) {
		sum += 1.0 / A[i];
	}

	cout << std::fixed;
	cout << setprecision(10) << 1.0 / sum << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
    int K,i,N,T;
    char s[100001];

    scanf("%s",s);

    N = strlen(s);
    T = strlen(s);

    for(i=0;i<N-1;i++){
        if(s[i] != s[i+1]){
            if((i+1>=N-(i+1))&&(T>i+1)){
                T=i+1;
            }else if((i+1<=N-(i+1))&&(T>N-(i+1))){
                T=N-(i+1);
            }
        }
    }

    printf("%d",T);

    return 0;
}

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

double distance(double xi, double yi, double xj, double yj) {
    // ２点間の距離を求める関数
    return sqrt((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj));
}

int main() {
    // 入力
    int N;
    cin >> N;
    vector<double> x, y;
    for (int i = 0; i < N; i++) {
        double tmp_x, tmp_y;
        cin >> tmp_x >> tmp_y;
        x.emplace_back(tmp_x);
        y.emplace_back(tmp_y);
    }

    // 距離を計算して distance_table に格納しておく
    double distance_table[10][10]; // distance_table[i][j]: i,jの距離
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            distance_table[i][j] = distance(x[i], y[i], x[j], y[j]);
            distance_table[j][i] = distance(x[i], y[i], x[j], y[j]);
        }
    }

    // 順列の始めのケースを作成: {0,1,2,...,n-1}
    vector<int> one_permutation_case;
    for (int i = 0; i < N; i++) {
        one_permutation_case.emplace_back(i);
    }

    double sum_distance = 0; // 総移動距離の合計
    int case_number = 0;     // 何通りあったか
    do {
        // 移動距離を sum_distance に加えていく
        case_number++;
        int now = one_permutation_case[0];
        for (int i = 1; i < N; i++) {
            int next = one_permutation_case[i];
            sum_distance += distance_table[now][next];
            now = next;
        }
    } while (next_permutation(one_permutation_case.begin(), one_permutation_case.end()));

    // setprecision(10) が無いと精度が足りない
    cout << setprecision(10) << sum_distance / case_number << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<int>h(n); rep(i, n)cin >> h[i];
	vector<int>dp(n); rep(i, n)dp[i] = INF;
	dp[0] = 0;
	rep(i, n) {
		for (int j = 1; j <= k; j++) {
			if (i + j >= n)break;
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
  
  int n,x[100],min=100,max=1,mins=0,s,i,j;
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&x[i]);
    if(min > x[i])  min = x[i];
    if(max < x[i])  max = x[i];
  }
  
  for(i=0; i<n; i++)  mins += (x[i]-min)*(x[i]-min);
  for(i=min+1; i<=max; i++){
    s=0;
    for(j=0; j<n; j++){
      if     (x[j] < i)  s += (i-x[j])*(i-x[j]);
      else if(x[j] > i)  s += (x[j]-i)*(x[j]-i);
    }
    if(s < mins)  mins = s;
  }
  
  printf("%d",mins);
  
  return 0;
}

Measured memory_bytes: 128
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int c = 0;
		for(int i = 0;i<2;i++){
			c += sc.nextInt()%2;
		}if(c==2)System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	ll H, N;
	cin >> H >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	ll x = H;
	for(int i=0; i<N; i++) x -= A[i];

	if(x>0) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = Integer.parseInt(W);

		int x500 = N/500;
		N=N%500;
		int x5 = N/5;
		System.out.println(x500*1000+x5*5);

	}

}


Measured memory_bytes: 24404
from collections import defaultdict
n,c = map(int,input().split())
d = [0]
for i in range(c):
    d.append([0] + list(map(int,input().split())))
li0 = []
li1 = []
li2 = []
for i in range(n):
    g = list(map(int,input().split()))
    for j in range(n):
        if (i + j) % 3 == 0:
            li0.append(g[j])
        if (i + j) % 3 == 1:
            li1.append(g[j])
        if (i + j) % 3 == 2:
            li2.append(g[j])
dic0 = defaultdict(int)
dic1 = defaultdict(int)
dic2 = defaultdict(int)
for i in li0:
    dic0[i] += 1
for i in li1:
    dic1[i] += 1
for i in li2:
    dic2[i] += 1 
ans = 1000000000
for i in range(1,c+1):
    for j in range(1,c+1):
        for k in range(1,c+1):
            if i == j or j == k or i == k:
                continue
            x = 0
            for color in range(1,c+1):
                x += dic0[color] * d[color][i]
                x += dic1[color] * d[color][j]
                x += dic2[color] * d[color][k]
            ans = min(x,ans) 
print(ans) 


Measured memory_bytes: 58204
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int time = sc.nextInt();

		// 時間
		int hour = time / 60 / 60;
		// 分
		int minutes = time / 60 % 60;
		// 秒
		int sec = time % 60;

		System.out.println(hour + ":" + minutes + ":" + sec);

	}

}



Measured memory_bytes: 26204
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	int a,b,c; cin >>a>>b>>c;
	int now=0;
	while(1){
		if(now%60<=c&&c<=(now%60+a)){
			cout << now+(c-now%60) << endl;
			return 0;
		}
		else if(now%60+a>=60&&c<=(now%60+a)%60){
			cout << now+(60-now%60+c%60) << endl;
			return 0;
		}
		now+=(a+b);
		if(now%60==0){
			cout << -1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;


int main() {
	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<ll> cnt(64);
	for (int i = 0; i < n; i++) {
		for (ll j = 0; j <= 62; j++) {
			cnt[j] += (a[i] >> j) & 1;
		}
	}
	vector<vector<ll>> dp(64, vector<ll>(4, -1e18));
	dp[63][1] = 0;
	for (int i = 62; i >= 0; i--) {
		if ((1LL << i) <= k) dp[i][0] = dp[i + 1][0] + (max(n - cnt[i], cnt[i]) << i);
		if ((k >> i) & 1) dp[i][0] = max(dp[i][0], dp[i + 1][1] + (cnt[i] << i));
		dp[i][1] = dp[i + 1][1] + ((k >> i) & 1 ? ((n - cnt[i]) << i) : (cnt[i] << i));
	}
	cout << max(dp[0][0], dp[0][1]) << endl;
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) A = 14;
  if (B == 1) B = 14;
  cout << ((A > B) ? "Alice" : (A < B) ? "Bob" : "Draw") << "\n";
}

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

int64_t gcd(int64_t a, int64_t b){
  if(a < b) swap(a,b);

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

int main(){
  int64_t N, X;
  vector<int64_t> x(100010);

  cin >> N >> X;
  for(int i=0; i<N; i++){
    cin >> x[i];
    x[i] = abs(x[i]-X);
  }

  int64_t ans = x[0];
  for(int i=0; i<N; i++) ans = gcd(ans, x[i]);

  cout << ans << endl;
}

Measured memory_bytes: 1024
n,a,b = map(int,(input().split()))
s = str(input())

num_pass = 0
num_pass_kaigai = 0

for i in range(n):
    if s[i] == "a" :
        if num_pass < a + b:
            num_pass += 1
            print("Yes")
        else:
            print("No")
    elif s[i] == "b":
        if num_pass < a + b and num_pass_kaigai < b:
            num_pass += 1
            num_pass_kaigai += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4016
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int* a = new int[n];
	int oldtemp, newtemp;
	cin >> oldtemp >> newtemp;
	int min = oldtemp;
	int max = newtemp - oldtemp;
	for (int i = 1; i <= n - 2; i++)
	{
		oldtemp = newtemp;
		cin >> newtemp;
		if (oldtemp < min)
			min = oldtemp;
		if (newtemp - min > max)
			max = newtemp - min;
	}
	cout << max << endl;






	delete[] a;
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Segment_Tree{
	private:
	int n;
	vi date;
	int Query_func(int a,int b,int k,int l,int r){
		if(r<=a||b<=l) return 0;
		if(a<=l&&r<=b) return date[k];
		int m=(l+r)/2;
		return Query_func(a,b,k*2+1,l,m)+Query_func(a,b,k*2+2,m,r);
	}
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
		for(int i=0;i<n;i++) Update(i,1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		return Query_func(a,b,0,0,n);
	}
};

const int M=26;

int n,b[M],S[M];;
string s;
vi a[M];


int main(){
	cin>>s;
	n=s.size();
	Segment_Tree st(n);
	for(int i=0;i<n;i++) a[s[i]-'a'].push_back(i);
	for(int i=0;i<M;i++) S[i]=a[i].size();
	ll res=0;
	for(int i=0;i<n/2;i++){
		int m=inf,t;
		for(int j=0;j<M;j++) if(S[j]-2*b[j]>1){
			int c=st.Query(0,a[j][b[j]])+st.Query(a[j][S[j]-b[j]-1]+1,n);
			if(c<m){
				m=c;
				t=j;
			}
		}
		if(m==inf){
			cout<<-1<<endl;
			return 0;
		}
		res+=m;
		st.Update(a[t][b[t]++],0);
		st.Update(a[t][S[t]-b[t]],0);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3964
#include<iostream>
#include<cstdio>
using namespace std;
int main(void) {
	int x, y;
	while (cin>>y>>x && (x!=0 || y!=0))
	{
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				if (i == 0 || j == 0 || j == x - 1 || i == y - 1) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}


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

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

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//C++14 (GCC 5.4.1)
int main() {
    int N;
    cin >>N;

    int p;
    int ans=0,max=0;
    rep(i,N){
        cin >> p;
        chmax(max,p);
        ans+=p;
    }
    //-----------------------------------
    ans-=max/2;
    cout << ans <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    ll d, t, s;
    cin >> d >> t >> s;
    cout << (d <= t * s ? "Yes" : "No") << endl;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int end = s.size() % 2 == 0 ? s.size() - 2 : (s.size() - 1);
    int half = end / 2;
    int ans = 0;
    while (end > 0){
//        cout << "before : " << s.substr(0, half) << endl;
//        cout << "after : " << s.substr(half, half) << endl;
        if(s.substr(0, half) == s.substr(half, half)) break;
        end -= 2;
        half = end / 2;
    }
    ans = end;
    cout << ans << endl;
}

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

int main(){
	int n;
	scanf("%d", &n);
	int vec[n];
	for(int i = 0;  i < n; i++)
		scanf("%d", &vec[i]);
	int mini = vec[0];
	int ans = 1;
	for(int i = 1; i < n; i++)
	{
		if(mini > vec[i])
			ans++;
		mini = min(mini, vec[i]);
	}
	printf("%d\n", ans);
	
	return 0;
}

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

#define llint long long int

using namespace std;

int main()
{
    int N;

    cin >> N;

    vector<int> A(N), B(N);

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

        B[i] = A[i];
    }
    sort(B.begin(), B.end(), greater<int>());

    for (int i = 0; i < N; i++)
    {
        if (A[i] == B[0])
        {
            cout << B[1] << endl;
        }
        else
        {
            cout << B[0] << endl;
        }
    }
}

Measured memory_bytes: 4780
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Diagnostics;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(s);
            int a = s[0];
            int b = s[1];
            int c = s[2];

            WriteLine(
                Abs(a-b) + Abs(b-c)
                );
        }
    }
}


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

using namespace std;
int main(){
    long n;
    unsigned long long sum=0;
    cin>>n;
    for (long i = 1; i <= n; ++i) {
        if(i%3==0||i%5==0){

        } else
            sum=sum+i;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3620
def main():
    ABCK = list(map(int,input().split()))

    AB = ABCK[0] + ABCK[1]


    if ABCK[0] > ABCK[3]:
        print(ABCK[3])

    elif ABCK[3] > AB:
        kk = ABCK[3]-AB

        # print(kk)

        print(ABCK[0]-(kk))

    else:
        print(ABCK[0])


if __name__ == '__main__':
    main()



Measured memory_bytes: 9120
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    long long n, a, b;
    long long x[100005];
    cin >> n >> a >> b;
    rep(i,n) cin >> x[i];

    long long ans = 0;
    rep(i,n - 1){
        ans += min((x[i + 1] - x[i]) * a, b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define gc getchar()
using namespace std;
int n,m,f[21][1<<20],g[21][1<<20];
char str[1<<21];
int read()
{
	int x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
	int s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
	return s*x;
}
int main()
{
	n=read(),m=read();
	for (int i=0;i<=n;i++)
	{
		scanf("%s",&str);
		for (int j=0;j<(1<<i);j++)
			f[i][j]=(str[j]=='1');
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<(1<<i);j++)
		{
			int fir=j>>(i-1)&1,pos=0;
			while (pos<i&&(j>>(i-pos-1)&1)==fir) pos++;
			g[i][j]=pos==i?-1:pos;
		}
	}
	int ans=0,len=0;
	for (int i=0;i<=n;i++)
	{
		for (int j=1;i+j<=n;j++)
		{
			for (int k=0;k<(1<<(i+j));k++)
			{
				f[i][k>>j]+=f[i+j][k];
				int t=g[j][k&((1<<j)-1)];
				if (t!=-1) f[i+j-t][k>>j<<(j-t)|(k&((1<<(j-t))-1))]+=f[i+j][k];
			}
		}
		for (int j=(1<<i)-1;~j;j--)
			if (f[i][j]>=m) ans=j,len=i;
	}
	for (int i=len;i;i--)
		putchar((ans>>(i-1)&1)+'0');
	puts("");
	return 0;
}


Measured memory_bytes: 93568
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x;
  cin >> n >> x;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
    x -= a[i];
  }
  int cnt = n;
  sort(a.begin(),a.end());
  cnt += (x / a[0]);
  cout << cnt << endl;
}

Measured memory_bytes: 256
// 自分（自分含む）より右側にある直近のLと自分（自分含む）より左側にある直近のRの位置を表す配列を作る
// 10^100は偶数なので距離の偶奇で判別
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	runes := []rune(s)
	LindiciesOfRight, RindiciesOfLeft := make([]int, len(runes)), make([]int, len(runes))
	LindiciesOfRight[len(runes)-1] = len(runes) - 1
	for i := 1; i < len(runes); i++ {
		now := string(runes[i])
		if now == "R" {
			RindiciesOfLeft[i] = i
		} else {
			RindiciesOfLeft[i] = RindiciesOfLeft[i-1]
		}
	}
	for i := len(runes) - 2; i >= 0; i-- {
		now := string(runes[i])
		if now == "L" {
			LindiciesOfRight[i] = i
		} else {
			LindiciesOfRight[i] = LindiciesOfRight[i+1]
		}
	}
	ans := make([]int, len(runes))
	for i := 0; i < len(runes); i++ {
		now := string(runes[i])
		if now == "R" {
			dist := LindiciesOfRight[i] - i
			if dist%2 == 0 {
				ans[LindiciesOfRight[i]]++
			} else {
				ans[LindiciesOfRight[i]-1]++
			}
		} else {
			dist := i - RindiciesOfLeft[i]
			if dist%2 == 0 {
				ans[RindiciesOfLeft[i]]++
			} else {
				ans[RindiciesOfLeft[i]+1]++
			}
		}
	}
	for i, a := range ans {
		fmt.Print(a)
		if i == len(ans)-1 {
			fmt.Println()
		} else {
			fmt.Print(" ")
		}
	}
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int y[2];
    cin>>y[0]>>y[1];
    sort(y,y+2);
    int sum=y[1];
    y[1]--;
    sort(y,y+2);
    cout<<sum+y[1]<<endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<min(a,b)+min(c,d)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    int n;
    cin >> n;
    vector<double> dp(n+1, 0);
    dp[0] = 1;

    for(int j = 1; j <= n; j++){
        double x;
        cin >> x;

        vector<double> cur(n+1, 0);
        cur[0] = dp[0]*((double)1 - x);
        for(int k = 1; k <= n; k++)
            cur[k] = dp[k-1]*x + ((double)1 - x)*dp[k];

        dp = cur;
    }
    double ans = 0;
    for(int j = (n+1)/2; j <= n; j++) ans += dp[j];
    cout << fixed << setprecision(9) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,L,T;
    cin>>N>>L>>T;
    vector<ll> X(N),W(N);
    REP(i,N) cin>>X[i]>>W[i];
    vector<ll> tmp(N);
    REP(i,N){
        if(W[i]==1) tmp[i]=(X[i]+T)%L;
        else tmp[i] = ((X[i]-T)%L + L)%L;
    }
    VSORT(tmp);
    ll cnt=0;
    REP(i,N){
        if(W[i]==1) cnt -= (T - (L - X[i]) + L) / L;
        else cnt += (T - (X[i] + 1) + L) / L;
    }
    cnt = (cnt % N + N) % N;
    vector<ll> res(N);
    REP(i,N) res[(i+cnt)%N] = tmp[i];
    REP(i,N) cout<<res[i]<<endl;
}


Measured memory_bytes: 4352
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處
const int M = (int)2e5 + 5;
LL a[M];
LL counter[M];
LL eqs[M];
LL ans[M];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        counter[a[i]]++;
    }
    LL total = 0;
    for (int i = 1; i <= n; i++) {
        eqs[i] = counter[i] * (counter[i] - 1) / 2;
        total += eqs[i];
    }
    for (int i = 1; i <= n; i++) {
        ans[i] = total - eqs[i] + (counter[i] - 1) * (counter[i] - 2) / 2;
    }
    for (int i = 0; i < n; i++) {
        printf("%lld\n", ans[a[i]]);
    }
}


Measured memory_bytes: 8704
def solve(a):
	s = 0
	loss = 0
	for k in a:
		if k == 0:
			if s % 2 == 1:
				loss += 1
			s = 0
		else:
			s += k

	return (sum(a) - loss) // 2

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(a))


Measured memory_bytes: 7072
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
#L1～LNはL[0]~L[N-1]で取り出す。よってこれから竹1~Nのことを竹0~N-1と呼ぶ。

#作られるべきA,B,Cが自らの材料として選んだ竹を、集合memA, memB, memCに格納？

#メンバーの選び方[0]~[255]の「[合計初期サイズ, 本数]」を格納するリスト
initialSum = []
for i in range(2**N): #全てのフラグパターンについて計算する
    nowsum = 0
    nowbamboocnt = 0
    for j in range(N): #2^(j+1)乗で割った余りが2^j以上なら、フラグjがTrue
        if i % (2**(j+1)) >= 2**j:
            nowbamboocnt += 1
            nowsum += L[j] #j(0-N-1)本目の竹について見ているので、L[j]が今見ている竹の長さ
    initialSum.append([nowsum, nowbamboocnt])

#テスト用→ print(initialSum)

#A,B,Cが竹を選んだ場合の所要MPを出し、最低値とその時の組み合わせをminに格納する
bambooset = {i for i in range(N)} #存在する竹の組み合わせ
min = 3000 #最低値の初期化

lestbamboo = bambooset.copy() #残っている竹

for i, initSumA in enumerate(initialSum): #i:0~255。initsumA[0]は初期合計サイズ, initsumA[1]は本数
#Aはこのfor文で既に選ばれていると考えればいい。
    if initSumA[1] ==0 or N - initSumA[1] < 2: continue #竹が0とか、残り竹が0,1なら飛ばす
    lestbamboo = bambooset.copy() #再初期化
    for j in range(N): #使った竹はlestbambooからremove
        if i % (2**(j+1)) >= 2**j: #j(0-N-1)本目の竹について考えている
            lestbamboo.remove(j)
    necesMPforA = abs(A - initSumA[0]) + (initSumA[1]-1)*10 #abs(目標-合計)-合成必要MP

    #次はBを計算する。Bが取らなかったものの中からCが取る
    for b in range(2**len(lestbamboo)): #残った竹それぞれにつき取るか取らないか選ぶ
    #2*残り本数通りある。ex.3本残っているとして、b(000とか101とか)で、Bの選び方を示す
        lestbambooList = list(lestbamboo) #リスト化する [0]~[本数-1]。値は竹番号[0-N]
        #lestbambooListは自動的に昇順になっている
        bamboocntB = 0 #Bの本数
        nowsumB = 0
        lestbambooforC = lestbamboo.copy() #Cのための残り竹を入れる
        for k in range(len(lestbambooList)): #2^(k+1)乗で割った余りが2^k以上なら、フラグkがTrue
            if b % (2**(k+1)) >= 2**k: #Bがとる場合
                bamboocntB += 1
                nowsumB += L[lestbambooList[k]] #竹番号はlestbambooList[k]に入っている
                lestbambooforC.remove(lestbambooList[k])
        if bamboocntB == 0: continue #0本だと駄目なので飛ばす

        for m in range(2**len(lestbambooforC)): #残った竹それぞれにつき取るか取らないか
        #このfor文終了1回につき、ABCそれぞれの組み合わせが1つ終了！
        # →このループの終了時にminの判定を行う
            lestbambooforCList = list(lestbambooforC) #やっぱりリスト化
            bamboocntC = 0
            nowsumC = 0
            for n in range(len(lestbambooforCList)):
                if m % (2**(n+1)) >= 2**n: #Cがとる場合
                    bamboocntC += 1
                    nowsumC += L[lestbambooforCList[n]] #竹番号はlestbambooListforC[n]に入っている
            if bamboocntC == 0: continue #0本だと駄目なので飛ばす

            nowTotalSum = necesMPforA + abs(B - nowsumB) + (bamboocntB-1)*10 + abs(C - nowsumC) + (bamboocntC-1)*10
            #minの判定！
            if nowTotalSum < min: min = nowTotalSum

print(min)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define str string
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
#define popcount __builtin_popcountll
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve(){
	int N, M; cin >> N >> M;
	vs A(N), B(M);
	rep(i, N) cin >> A[i];
	rep(i, M) cin >> B[i];
	int af = 0;
	rep(y, N - M + 1){
		rep(x, N - M + 1) {
			int f = 1;
			rep(i, M) {
				rep(j, M) {
					if (A[j + y][i + x] != B[j][i]) {
						f = 0;
					}
				}
			}
			if (f) af = 1;
		}
	}
	if (af) cout << "Yes" << endl;
	else cout << "No" << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if(a < b)
        cout << b * 2 - 1<<endl;
    else if(a > b)
        cout << a * 2 - 1<<endl;
    else
        cout << a + b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int main()
{
	fastIO
	//inp_out();
	ll r,c,k;
	cin>>r>>c>>k;
	vector<string> s(r);
	for(ll i=0;i<r;++i)
	{
		cin>>s[i];
	}

	ll range=pow(2,r-1)-1;
	ll fa=inf;

	for(ll mask=0;mask<=range;++mask)
	{
		ll ans=0;
		ll tem=mask;
		vll v;
		v.pb(0);
		for(ll i=1;i<r;++i)
		{
			if(tem&1)
			{
				v.pb(i);
				++ans;
			}
			tem/=2;
		}

		v.pb(r);
		ll div=ans+1;
	//	db(ans,mask);
		vll temp(div,0),cnt(div,0);
		for(ll j=0;j<c;++j)
		{
		//	db(j,mask);
			for(ll idx=1;idx<v.size();++idx)
			{
				temp[idx-1]=0;
				for(ll i=v[idx-1];i<v[idx];++i)
				{
					if(s[i][j]=='1')
					{
						++temp[idx-1];
						++cnt[idx-1];
					}
				}
			}

			ll flag=0;
			for(ll i=0;i<div;++i)
			{
				if(temp[i]>k)
				{
					goto x;
				}
				if(cnt[i]>k)
				{
					flag=1;
				}
			}

			if(flag==1)
			{
				++ans;
				for(ll i=0;i<div;++i)
				{
					cnt[i]=temp[i];
				}
			}
		}

	//	db(mask);
		fa=min(fa,ans);
		x:;
	}

	cout<<fa;

	return 0;
}



Measured memory_bytes: 256
n=int(input())
sp=[[0 for i in range(3)]for i in range(n)]
for i in range(n):
  sp[i][0],sp[i][1]=input().split()
  sp[i][1]=int(sp[i][1])
  sp[i][2]=i+1
sp=sorted(sp,key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(sp[i][2])

Measured memory_bytes: 3064
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

MAX = 10**(N)-1
MIN = 10**(N-1)
if N == 1:
    MIN = 0

for num in range(MIN, MAX+1):
    strnum = str(num)
    for sci in sc:
        s, c = sci[0], sci[1]
        if strnum[s-1] != str(c):
            break
    else:
        print(num)
        exit()
else:
    print(-1)


Measured memory_bytes: 3316
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<complex<double>>  DFT(vector<complex<double>> a) {
	int n = a.size();
	if (n == 1) return a;
	vector<complex<double>> a0(n / 2), a1(n / 2);
	REP(i, n) {
		if (i % 2 == 0) {
			a0[i / 2] = a[i];
		}
		else {
			a1[i / 2] = a[i];
		}
	}
	vector<complex<double>> inversed_a0 = DFT(a0), inversed_a1 = DFT(a1);
	vector<complex<double>> inversed_a(n);
	for (int i = 0; i < n; ++i) {
		complex<double> zeta = complex<double>(cos(2 * Ma_PI * i / n), sin(2 * Ma_PI * i / n));
		inversed_a[i] = inversed_a0[i % (n / 2)] + zeta * inversed_a1[i % (n / 2)];
	}
	return inversed_a;
}
vector<complex<double>> IDFT(vector<complex<double>> inversed_a) {
	int n = inversed_a.size();
	vector<complex<double>> now = DFT(inversed_a);
	reverse(now.begin(), now.end());
	for (int q = now.size() - 1; q >= 1; --q) {
		swap(now[q], now[q - 1]);
	}
	REP(i, n) {
		now[i] /= complex<double>(n, 0);
	}
	return now;
}
vector<complex<double>> conv(vector<complex<double>> a, vector<complex<double>> b) {
	int deg = a.size() + b.size() - 1;
	int n = 1;
	while (n < deg) n <<= 1;
	a.resize(n);
	b.resize(n);
	vector<complex<double>> inversed_a = DFT(a),inversed_b = DFT(b);
	vector<complex<double>> inversed_c(n);
	REP(i, n) {
		inversed_c[i] = inversed_a[i] * inversed_b[i];
	}
	return IDFT(inversed_c);
}

int main() {
	int a;
	cin >> a;
	cout << 3 * a * a << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int X[N];
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        sum += X[i];
    }
    ll ans1 = 0;
    ll ans2 = 0;
    for (int i = 0; i < N; i++) {
        ll t1 = (sum + N - 1) / N - X[i];
        ll t2 = sum / N - X[i];
        ans1 += t1 * t1;
        ans2 += t2 * t2;
    }
    cout << min(ans1, ans2) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  int main()
  {
    int N,K;
    cin >> N >> K;
    double sum=0.0;
    double ka=1.0/N;
    for(int i=1; i<=N; i++){
      int in=i;
      while(1){
        if(in<K){
          in*=2;
          ka*=0.5;
        }
        if(in>=K){
          sum+=ka;
          ka=1.0/N;
          break;
        }
      }
    }
    printf("%.9f\n",sum);
  }


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>

using namespace std;

int main(){

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

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

  long long int dp[n+1][s+1];
  memset(dp,0,sizeof(dp));
  long long int m=998244353;
  dp[0][0]=1;


  for(int i=0;i<n;i++){
    for(int j=0;j<s+1;j++){
      dp[i+1][j] = (dp[i+1][j] + 2*dp[i][j])%m;
      if(j-a[i]>=0)dp[i+1][j]=(dp[i+1][j]+dp[i][j-a[i]])%m;
    }
  }

  cout << dp[n][s] << endl;

}

Measured memory_bytes: 74004
#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++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    int N;
    cin >> N;
    ll ans = 0;
    int C[10][10];
    rep(i, 10)
    {
        rep(j, 10)
        {
            C[i][j] = 0;
        }
    }
    rep2(i, 1, N + 1)
    {
        int a0 = i % 10;
        int ak = to_string(i)[0] - '0';
        C[ak][a0]++;
    }
    rep(i, 10)
    {
        rep(j, 10)
        {
            ans += C[i][j] * C[j][i];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=1005;
const int MOD=1e9+7;

int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b;
  cin>>a>>b;
  int arr[b];
  int sum=0;
  for(int i=0;i<b;i++)
  {
  	cin>>arr[i];
  	sum+=arr[i];
  }
  if(sum>=a)
  {
  	cout<<"Yes";
  }
  else
  {
  	cout<<"No";
  }
}



Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: i64,
        op: String,
        b: i64,
    }
    println!("{}", if op == '+'.to_string() { a + b } else { a - b });
}


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

int main() {
  int i, b;
  vector<int> a(6), n(4);
  n = {0, 0, 0, 0};
  for (int i = 0; i < 6; i++) cin >> a.at(i);
  for (int i = 0; i < 6; i++){
    if(a.at(i) == 1) n.at(0)++;
    else if (a.at(i) == 2) n.at(1)++;
    else if (a.at(i) == 3) n.at(2)++;
    else if (a.at(i) == 4) n.at(3)++;
  }
  b = 0;
  for(int i = 0; i < 4; i++){
    if(b < n.at(i)) b = n.at(i);
  }
  if(b == 3) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
def solve(string):
    c11, c12, c13, c21, c22, c23, c31, c32, c33 = map(int, string.split())
    check = c11 - c12 == c21 - c22 == c31 - c32 and c12 - c13 == c22 - c23 == c32 - c33 and c13 - c11 == c23 - c21 == c33 - c31 and c11 - c21 == c12 - c22 == c13 - c23 and c21 - c31 == c22 - c32 == c23 - c33 and c31 - c11 == c32 - c12 == c33 - c13
    return "Yes" if check else "No"


if __name__ == '__main__':
    n = 3
    print(solve('\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 3064
N,A,B,C = map(int,input().split())
list = [int(input()) for _ in range(N)]

def dfs(cnt,a,b,c):
    if cnt == N:
        return abs(A-a)+abs(B-b)+abs(C-c) if min(a,b,c) > 0 else 10**9

    l  = dfs(cnt+1,a,b,c)
    la = dfs(cnt+1,a+list[cnt],b,c) + (10 if a != 0 else 0)
    lb = dfs(cnt+1,a,b+list[cnt],c) + (10 if b != 0 else 0)
    lc = dfs(cnt+1,a,b,c+list[cnt]) + (10 if c != 0 else 0)
    return min(l,la,lb,lc)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
(m, n, l)=map(int,input().split())

matrix1=[]*m
matrix2=[]*n
matrix3=[[0]*l for i in range(m)]

for row1 in range(m):
    line = list(map(int, input().split()))
    matrix1.append(line)
for row2 in range(n):
    line = list(map(int,input().split()))
    matrix2.append(line)

a = matrix1
b = list(map(list, zip(*matrix2)))

for row3 in range(m):
    for col in range(l):
        matrix3[row3][col]=sum([x*y for x,y in zip(a[row3],b[col])])
    print(*matrix3[row3], sep=" ")


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

int main() {
	int n; cin >> n;
	vector<int> a(n); rep(i, 0, n) cin >> a[i];

	int ans = 0;
	rep(i, 0, n) {
		if (a[i] % 2 != 0) {
			cout << ans << endl;
			return 0;
		}
	}
	bool f = true;
	while (f) {
		for (auto& x : a) x /= 2;
		ans++;
		for (auto& x : a) if (x % 2 != 0) f = false;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import 'dart:io';

main(List<String> args) {
  List NY = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  int N = NY[0];
  int Y = NY[1];
  int k = 0;
  bool flag = false;
  for (var i = 0; i <= N; i++) {
    for (var j = 0; j <= N - i; j++) {
      k = N - i - j;
      if (i * 10000 + j * 5000 + k * 1000 == Y) {
        print([i, j, k].join(" "));
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
  if (!flag) print("-1 -1 -1");
}

Measured memory_bytes: 13136
#include "bits/stdc++.h"

using namespace std;

int main() {
	string s;
	cin >> s;
	int paper = 0, rock = 0, win = 0, lose = 0;
	for(int i = 0; i < s.length(); ++i){
        if(s[i] == 'p'){
            if(paper < rock){
                paper++;
            }else{
                rock++;
                lose++;
            }
        }else{
            if(paper < rock){
                paper++;
                win++;
            }else{
                rock++;
            }
        }
	}
	cout << win - lose;
	return 0;

}


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


int main() {
    int a, b; cin >> a >> b;
    int k=(a+b)/2;
    if(abs(a-k) == abs(b-k)) cout << k; else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 256
S = str(input())
N = len(S)
D = [0,0] #B,W
ans = 0; prev = S[0]
for i in range(N):
  if S[i] == "B":
    D[0] += 1
  else:
    D[1] += 1
  if i >= 1:
    if S[i] == prev:
      continue
    else:
      ans += 1
      prev = S[i]
if D[0] == 0: #すべてW
  print(0); exit()
elif D[1] == 0:
  print(0); exit()
print(ans)


Measured memory_bytes: 9200
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))


Measured memory_bytes: 20140
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int ans=0;
    while(K>0){
        if(A>0){
            ans++;
            A--;
        }else if(B>0){
            B--;
        }else{
            ans --;
            C--;
        }
        K--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+ 1];
  int n, i;

  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for(i = 0; i <= VMAX; i++) C[i] = 0;

  for(i = 0; i < n; i++){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for(i = 1; i <= VMAX; i++) C[i] = C[i] + C[i - 1];

  for(i = 1; i <= n; i++){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

  for( i = 1; i <= n; i++){
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

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

using namespace std;

int main()
{
        int h, w, a, b;
        cin >> h >> w >> a >> b;

        for (int i = 0; i < h; i++, cout << '\n')
                for (int j = 0; j < w; j++)
                        cout << ((i < b && j < a) || (i >= b && j >= a));

        return 0;
}

Measured memory_bytes: 1280