akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1LL<<62;
const int MAX = 1e5;

//mod(1e9+7)
const int mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x = 0) : x(x % mod){}
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

int main() {
    int n; cin >> n;
    vector<string> field(2);
    rep(i,2) cin >> field[i];
    int id = 0;
    vint x;
    while (id < n) {
        if (field[0][id] == field[1][id]) {
            x.push_back(1);
            id++;
        }
        else {
            x.push_back(0);
            id += 2;
        }
    }
    mint sum = 0;
    if (x[0] == 1) sum += 3;
    else sum += 6;
    REP(i,x.size()) {
        if (x[i] == 1 && x[i-1] == 1) sum *= 2;
        if (x[i] == 0 && x[i-1] == 1) sum *= 2;
        if (x[i] == 0 && x[i-1] == 0) sum *= 3;
    }
    cout << sum.x << endl;
}

Measured memory_bytes: 256
# include<iostream>
using namespace std;
static const int MAX = 1000;

void output(int A[],int N){
    for(int i=0;i<N;i++){
        cout << A[i];
        if(i == N-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
}

void insertionSort(int A[],int N){
    int v,j;
    for(int i=1;i<N;i++){
        output(A,N);
        v = A[i];
        j = i - 1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
    }
}
int main(){
    int N;
    int A[MAX];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    insertionSort(A,N);
    output(A,N);
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
const int INF=100000000;
const int MAX_V = 301;
// d[u][v]Íu©çvÖÌRXgBßÉ×Ú·éGbWÌRXgðüêÄ¨¢½è·êÎæ¢Í¸B
int d[MAX_V][MAX_V];
// ¸_
int V;
// S_ÎÅZoHâèðÆ­O(V^3)AÓª ÁÄà®ì
void warshall_floyd(){
    for(int i = 0; i < V; i++){
        for(int j = 0; j < V; j++){
            for(int k = 0; k < V; k++){
                int prv=d[j][k];
                d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }
}
int main(){
    int n;
    while(cin>>n&&n!=0){
        int idx=0;
        map<string,int> dict;
        string s,a,b,t;
        for(int j = 0; j < MAX_V; j++){
            for(int k = 0; k < MAX_V; k++){
                if(j==k)
                    d[j][k]=0;
                else
                    d[j][k]=INF;
            }
        }
        for(int i = 0; i < n; i++){
            cin>>s;
            cin>>a;
            if(dict.find(a)==dict.end())
	      dict[a]=idx++;
            cin>>s;
            cin>>t;
            int cost;
            for(int j = 0; j < t.size(); j++){
                if(t[j]=='^')
                    cost=atoi(t.substr(j+1).c_str());
            }
            cin>>b;
            if(dict.find(b)==dict.end())
                dict[b]=idx++;
            if(cost<0){
                d[dict[a]][dict[b]]=-cost;
                d[dict[b]][dict[a]]=cost;
	    }
            else{
                d[dict[b]][dict[a]]=cost;
                d[dict[a]][dict[b]]=-cost;
	    }
        }
        V=idx;
        bool no=false;
        warshall_floyd();
	// ÌÂHª êÎno
	for(int i = 0; i < idx; i++)
	  if(d[i][i]<0)no=true;
	if(no)
	  cout<<"No"<<endl;
	else
	  cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1304
/*
  AtCoder Beginner Contest 085
  D - Katana Thrower
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int N, H;
vector<int> a, b;

int main() {
  scanf("%d %d", &N, &H);

  for (int i = 0; i < N; ++i) {
    int a_, b_;
    scanf("%d %d", &a_, &b_);
    a.push_back(a_);
    b.push_back(b_);
  }

  // bを昇順にソート
  sort(b.begin(), b.end(), greater<int>());
  // aの最強の刀
  int strongest_a = *max_element(a.begin(), a.end());

  int cnt = 0;
  for (int i = 0; i < b.size(); ++i) {
    if (b[i] < strongest_a) break;

    H -= b[i];
    cnt += 1;
    if (H <= 0) break;
  }

  if (H > 0) cnt += (H + strongest_a - 1) / strongest_a;

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C,count=0;
  cin>>A>>B>>C;
  if(B==C)count++;
  if(C==A)count++;
  if(A==B)count++;
  count==1?cout<<"Yes"<<endl:cout<<"No"<<endl;
}

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

bool isMatch(vector<string>A,vector<string>B,int i,int j){
    //Aを左上(i,j)から始めて、完全にBと一致してればtrueを返す。
    bool res=false;
    int x=0,y=0;
    rep2(a,i,i+B.size()){
        x=0;
        rep2(b,j,j+B.size()){
            if(A[a].at(b)!=B[y].at(x)){
                return false;
            }
            x++;
        }
        y++;
    }
    //最後まで来れればtrue;
    return true;
}

int main(){
    int N,M;
    cin>>N>>M;
    vector<string> A(N),B(M);
    rep(i,N){
        cin>>A[i];
    }
    rep(i,M){
        cin>>B[i];
    }
    bool match=false;
    //左上の基準は、(0,0)～(N-M,N-M)まで
    rep(i,N-M+1){
        rep(j,N-M+1){
            if(isMatch(A,B,i,j)){
                match=true;
            }
        }
    }
    string ans;
    ans=(match)?"Yes":"No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod  = 1e9+7;
string grid[1001];
int dp[1001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int h,w;
  cin >> h >> w;
  h--; w--;
  for(int i=0;i<=h;i++)
    cin >> grid[i];
  for(int i=0;i<=1000;i++)
  //   for(int j=0;j<=1000;j++)
      dp[i] = 0;
  dp[w] = 1;

  for(int row = h;row>=0;row--) {
    for(int col = w;col>=0;col--) {
      if (grid[row][col] == '.' and !(row==h and col==w)) {
        dp[col] = (dp[col] + dp[col+1])%mod;
        // cerr << row << ' ' << col << '\n';
      } 
      else if (grid[row][col] == '#')
        dp[col] = 0;  
    }
    // cerr << "Row: " << row << '\n';
    // for(int i=0;i<=w;i++) cerr << dp[i] << ' ';
    // cerr << '\n';
  }
  // for(int i=0;i<=h;i++) {
  //   for(int j=0;j<=w;j++) {
  //     cerr << dp[i][j] << ' ';
  //   }
  //   cerr << '\n';
  // }
  cout << dp[0];
  return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

long long       X;
long long       Y;

int             main(void)
{
        long long       num;
        int                     count = 1;

        scanf("%lld%lld", &X, &Y);
        num = 2 * X;
        while (num <= Y)
        {
                count++;
                num *= 2;
        }
        printf("%d\n", count);
        return (0);
}

Measured memory_bytes: 1708
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  if (A + B >= 10)cout << "error" << endl;
  else cout << (A + B) << endl;
}


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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int N;cin >> N;
    vector<long long> A(N);
    int r=0;
    REP(i, N)
    {
        int a;
        cin >> a;
        if (a<0){
            r++;
            a*=-1;
        }
        A.at(i) = a;
    }
    SORT(A);
    if (r % 2 == 1)
    {
        A.at(0) *= -1;
    }
    
    cout << accumulate(ALL(A),0LL) << endl;

  
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
void call(int n){
  for(int i=1;i<=n;i++){
    int x=i;
    if(x % 3 == 0){
      printf(" %d",i);
    }else if(x % 10 == 3){
      printf(" %d",i);
    }else{
      x /= 10 ;
      while(x){
        if(x % 10 == 3){
          printf(" %d",i);
          x=0;
        }else{
          x /= 10;
        }
      }
    }
  }
}
int main(){
  int n;
  scanf("%d",&n);

  call(n);
  printf("\n");
}



Measured memory_bytes: 2088
from collections import Counter
n,k,q = map(int,input().split())
a = list (int(input()) for hogehoge in range(q))
acount = Counter(a)
for i in range(1,n+1):
         if acount[i] >= (q-k+1):
                  print("Yes")
         else:
                  print("No")


Measured memory_bytes: 11888
#include<bits/stdc++.h>
using namespace std;
int main(){

  int a,c[4]={0};
  char b[3];

  while(scanf("%d,%s",&a,b) != EOF){

    if(strcmp("A",b)==0) c[0]++;
    else if(strcmp("B",b)==0) c[1]++;
    else if(strcmp("AB",b)==0) c[2]++;
    else if(strcmp("O",b)==0) c[3]++;
  }

  for(int i=0;i<4;i++) cout << c[i] << endl;
  return (0);
}

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

struct Classroom {
    char name[16];
    int visitor;
    int income;
};

int main() {
    Classroom classroom[9];
    for (int i = 0; i < 9; i++) {
        int am, pm;
        cin >> classroom[i].name >> am >> pm;
        classroom[i].visitor = am + pm;
        classroom[i].income = am * 200 + pm * 300;
    }
    for (int i = 0; i < 9; i++) {
        cout << classroom[i].name << " " << classroom[i].visitor << " " << classroom[i].income << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

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

typedef long long ll;

int main() {
	int K, S;
	cin >> K >> S;
	
	ll ans = 0;
	REP(i, K + 1) REP(j, K + 1) {
		int k = S - i - j;
		if (k >= 0 && k <= K) ans++;
	}
	cout << ans << endl;	
	return 0;
}

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

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  int pos = 0;
  for (int i = k; i < n; ++i) {
    if (a[i] > a[i - k]) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
  }
  return 0;
}

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

count = 0
for i in range(n):
  count += min(a[i],b[i])
  if a[i] > b[i]:
    continue
  
  tmp = b[i] - a[i]
  count += min(a[i+1], tmp)
  a[i+1] = max(0, a[i+1]-tmp)
  
  
print(count)
  

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

int main(){
    string S;
  cin>>S;
  int cnt=0;
  for(int i=0;i<(S.size())/2;i++){
    if(S.at(i)!=S.at(S.size()-1-i))cnt++;
  }
  
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int ans[1<<15+1];
const ll MAX_N =(1<<15);
int main(){
	for(int i = 0;i*i<=MAX_N;i++){
		for(int j = i;i*i+j*j <=MAX_N;j++){
			for(int k= j;i*i+j*j+k*k<=MAX_N;k++){
				for(int l = k;i*i+j*j+k*k+l*l<=MAX_N;l++){
					ans[i*i+j*j+k*k+l*l]++;
				}
			}
		}
	}
	int n;
	while(cin>>n,n){
		cout <<ans[n]<<endl;
	}
	return 0;
}

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

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;

    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        if(t % 2 == 1){
            cout << 0 << endl;
            return 0;
        }
        vec.push_back(t);
    }

    while(true){
        for(ll i = 0; i < N; i++){
            if(vec[i] % 2 == 1){
                cout << ans << endl;
                return 0;
            }
            vec[i] /= 2;
        }
        ans++;
    }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF=999999;
const int maxx=11;
int ma[maxx][maxx];
 int n,m;

void init()
{
   for(int i=0;i<maxx;i++)
        for(int j=0;j<maxx;j++)
            if(i!=j)
            ma[i][j]=INF;

}

int main()
{




    while(~scanf("%d",&n)&&n)
    {
        init();
        m=0;
        for(int i=0;i<n;i++)
        {
            int a,b,c;
            scanf("%d %d %d",&a,&b,&c);
            ma[a][b]=ma[b][a]=c;
            m=max(m,max(a,b)+1);
        }



        for(int i=0;i<m;i++)
            for(int j=0;j<m;j++)
                for(int k=0;k<m;k++)
                    ma[j][k]=min(ma[j][k],ma[j][i]+ma[i][k]);



        int ans=INF;int k;
        for(int i=0;i<m;i++)
        {
            int sum=0;
            for(int j=0;j<m;j++)
                if(ma[i][j]!=INF)
                    sum+=ma[i][j];
            if(sum<ans)
            {
                k=i;
                ans=sum;
            }

        }


        printf("%d %d\n",k,ans);
    }
}

Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <deque>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
vector<vector<ll>> dp;
void warshall_floyd() {
  REP(k, n) {
    REP(i, n) {
      REP(j, n) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
}

struct Edge {
  int x, y, cost;
};

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

  cin >> n >> m;
  vector<Edge> ve;
  dp.assign(n, vector<ll>(n, INF));
  REP(i, n) dp[i][i] = 0;

  REP(i, n) REP(j, n) dp[i][j] == INF;
  REP(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    dp[a][b] = c;
    dp[b][a] = c;
    ve.push_back(Edge{a, b, c});
  }

  warshall_floyd();
  int count = 0;
  REP(i, m) {
    Edge e = ve[i];
    if(dp[e.x][e.y] != e.cost) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 384
n = gets.split[0].to_i
c = gets.split.map &:to_i
m = (0..n+1).to_a

for i in 2..n
  for j in c
    if j <= i && m[i-j]+1 < m[i]
      m[i] = m[i-j]+1
    end
  end
end

puts m[n]

Measured memory_bytes: 9192
package main
 
import(
  "fmt"
	"bufio"
	"os"
	"strings"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}
 
func abc141a(s string){
	if s == "Sunny"{
		fmt.Println("Cloudy")
	}else if s == "Cloudy"{
		fmt.Println("Rainy")
	}else if s == "Rainy"{
		fmt.Println("Sunny")
	}
}
 
func main(){
	x := ""
	fmt.Scan(&x)
	abc141a(x)
}

Measured memory_bytes: 640
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    s = input()
    t = input()

    slen = len(s)
    tlen = len(t)
    dp = [[0 for _ in range(tlen + 1)] for _ in range(slen + 1)]

    for i in range(slen):
        for j in range(tlen):
            if s[i] == t[j]:
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])

    ans = ''
    while slen > 0 and tlen > 0:
        if dp[slen][tlen] == dp[slen - 1][tlen]:
            slen -= 1
        elif dp[slen][tlen] == dp[slen][tlen - 1]:
            tlen -= 1
        else:
            slen -= 1
            tlen -= 1
            ans += s[slen]
    print(ans[::-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 120668
/*
  AUTHOR:SOURABH
  CREATED:06:05:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,m,x,i,j,k,sum,ans,f;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n>>m>>x;
        vll a(n),val(m);
        ll b[n][m];
        fn(i,n)
        {
            cin>>a[i];
            fn(j,m)
            cin>>b[i][j];
        }
        ans=1e9;
        fn(i,1LL<<n)
        {
            sum=0;
            f=1;
            fn(j,n)
            {
                if(i & (1LL<<j))
                {
                    sum+=a[j];
                    fn(k,m)
                    val[k]+=b[j][k];
                }
            }
            fn(j,m)
            {
                if(val[j]<x)
                    f=0;
                val[j]=0;
            }
            if(f)
                ans=min(ans,sum);
        }
        if(ans==1e9)
            cout<<-1;
        else
            cout<<ans;
    }
    return 0;
}

















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


long long a[502];
int k;
int n;

long long low[502], high[502];

set<long long> pc;



bool solve(long long x) {
	vector<long long> b(a +1, a+n + 1);
	for(long long &bb: b)
		bb%=x;
	sort(b.begin(), b.end());
	high[n] = 0;
	low[0] = b[0];
	for(int i=1;i<n;i++)
		low[i] = low[i-1] + b[i];
	for(int i= n-1;i>=0;i--)
		high[i] = high[i+1] + x - b[i];
	int cnt = high[0];
	for(int i=0;i<n;i++)
		if(low[i]>=high[i+1])
			return low[i]<=k;
	return false;
}
int main() {
	cin >> n >> k;
	long long sum  =0;
	int i;
	for(i=1;i<=n;i++){
		cin >> a[i];
		sum +=a[i];
	}
	for(i=1;i*i<=sum;i++) {
		if(sum%i==0)
			pc.insert(i), pc.insert(sum/i) ;
	}
	int ans = 1;
	for(int x: pc){
		if(solve(x))
			ans = max(ans, x);
	}
	cout << ans<<"\n";
	return 0;
}


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

mod = 10**9 + 7
ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    # 桁が違うのでk(== 2**0, 2**1, 2**2,...)をかける必要がある
    ans += ((k % mod) * cnt_1 * cnt_0) % mod

print(ans % mod)


Measured memory_bytes: 124368
fun main(args: Array<String>) = yorukatsu14b()

fun yorukatsu14b() {
    val n = readLine()!!.toLong()

    val answer = (1..n).fold(1L) { acc, l -> (acc * l) % MOD }

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()


Measured memory_bytes: 33636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<list>
using namespace std;
int main() { 
	long long  n;
	cin >> n;
	vector<long long >a(n);
	vector<long long >a2(n);
	for (long long i = 0; i < n; i++) {
		cin >> a[i];
	}
	a2 = a;
	sort(a2.begin(), a2.end());
	for (long long i = 0; i < n; i++) {
		if (a[i] == a2[n-1]) {
			cout << a2[n-2] << endl;
		}
		else {
			cout << a2[n-1] << endl;
		}
		
	}
}

Measured memory_bytes: 4736
import itertools
N, M, Q = map(int, input().split())
vec = [list(map(int, input().split())) for i in range(Q)]
A = itertools.combinations_with_replacement(range(1,M+1), N)
ans = 0

for a in A:
    tmp = 0
    for v in vec:
        if (a[v[1]-1] - a[v[0]-1]) == v[2]:
            tmp += v[3]
    if ans < tmp:
        ans = tmp
        
print(ans)

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

int a, b, c, x, y;
int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(a), read(b), read(c), read(x), read(y);
    int mn = std::min(x, y);

    if(2 * c <= a + b) {
        printf("%d\n", std::min(mn * 2 * c + x * a + y * b - mn * (a + b), 2 * std::max(x, y) * c));
    } else {
        printf("%d\n", x * a + y * b);
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    set<int> s;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(s.count(a)) s.erase(a);
        else s.insert(a);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 8216
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    int N;
    cin >> N;
    
    cout << pow(N, 3) << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
long long int cnt=0;
vector<long long int> hoge;
void insertSort(int n, int g){
  for(int i=g; i<n; i++){
    int v=hoge.at(i);
    int j=i-g;
    while(j>=0&&hoge.at(j)>v){
      hoge.at(j+g)=hoge.at(j);
      j=j-g;
      cnt++;
    }
    hoge.at(j+g)=v;
  }
}
int main(void){
  long int n;
  cin>>n;
  for(int i=0; i<n; i++){
    int a;
    cin>>a;
    hoge.push_back(a);
  }

  long long int m=n;
  vector<long long int> g(m,0);
  g.at(0)=1;
  for(int i=1; i<m; i++){
    g.at(i)=g.at(i-1)*3+1;
    if(g.at(i)>n){
      m=i;
      g.at(i)=0;
      break;
    }
  }
  sort(g.begin(),g.end());
  reverse(g.begin(),g.end());
  for(int i=0; i<m; i++){
    insertSort(n,g.at(i));
  }
  cout<<m<<endl;
  for(int i=0; i<m; i++){
    cout<<g.at(i);
    if(i!=m-1){
      cout<<" ";
    }else{
      cout<<endl;
    }
  }
  cout<<cnt<<endl;
  for(int i=0; i<n; i++){
    cout<<hoge.at(i)<<endl;
  }
}


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

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

int main(){
  int x,y;
  cin >> x >> y;

  string ans = "No";
  rep(i,x+1){
    int kame=i;
    int turu=x-i;
    if(kame*4+turu*2==y) ans="Yes";
  }

  cout << ans;
}

Measured memory_bytes: 3624
import std.stdio;
import std.string;
import std.array;
import std.range;
import std.algorithm;
import std.conv;

void main(string[] args) {
  readln();
  string input = readln().chomp;
  int[2][char] range;

  foreach(int i, char c; input) {

    if(c in range){
      range[c][1] = i;
    }else{
      range[c] = [i,0];
    }
  }

  int[100] res;

  foreach(char c, int[2] a; range){
    for(int i = a[0]; i < a[1]; i++){
      res[i]++;
    }
  }

  res.reduce!max.writeln;
}

Measured memory_bytes: 256
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [0 for i in range(8)]
for i in range(N):
    b = int(input())
    if b == A[0][0] or b == A[1][0] or b == A[2][0]:
        B[0] += 1
    if b == A[0][1] or b == A[1][1] or b == A[2][1]:
        B[1] += 1
    if b == A[0][2] or b == A[1][2] or b == A[2][2]:
        B[2] += 1
    if b == A[0][0] or b == A[0][1] or b == A[0][2]:
        B[3] += 1
    if b == A[1][0] or b == A[1][1] or b == A[1][2]:
        B[4] += 1
    if b == A[2][0] or b == A[2][1] or b == A[2][2]:
        B[5] += 1
    if b == A[0][0] or b == A[1][1] or b == A[2][2]:
        B[6] += 1
    if b == A[0][2] or b == A[1][1] or b == A[2][0]:
        B[7] += 1
if 3 in B:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Measured memory_bytes: 9300
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)


int main() {

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (A % 2 == 0) {
			if (A % 3 == 0 || A % 5 == 0) {
				continue;
			}
			else {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;

	return 0;
}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n; cin >> n;
    if(n==2){ cout << 1 << endl; return 0; }
    ll ans=2;//n-1はn-1の倍数なのでそれも含める.n自身はnの倍数であり,n/n=1のため
    //n-1の倍数のとき
    for(ll i=2;i*i<n;i++){ //n-1まで
        if((n-1)%i==0) ans += 2;
        if(i*i==n-1) ans--;
    } 
    //nの倍数のとき
    vector<ll> ya;
    for(ll i=2;i*i<n+1;i++){
        if(n%i!=0) continue;
        ya.push_back(i);
        if(i*i!=n) ya.push_back(n/i);
    }
    rep(i,0,ya.size()){
        //cout << ya[i] << endl;
        ll na = n;
        while(na%ya[i]==0) na/=ya[i];
        if(na%ya[i]==1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

int main(){
	string a;
	cin >> a;
	
	long long samepair = 0;
	long long total = ((long long)a.size())*(a.size()-1)/2;
	vector<long long> chars(26);
	
	for(int i = 0;i < a.size();i++){
		chars[a[i]-'a']++;
	}
	
	for(int i = 0;i < 26;i++){
		samepair += chars[i]*((long long)chars[i]-1)/2;
	}
	
	cout << 1+total - samepair << endl;
	
	return 0;
}

Measured memory_bytes: 768
from math import pi, sin, cos, sqrt
import sys

A, B, H, M = map(int, input().split())

h = (H + M/60)/ 12 * 2 * pi
m = M / 60 * 2 * pi
print(sqrt((A * sin(h) - B * sin(m)) ** 2 + (A * cos(h) - B * cos(m)) ** 2))




Measured memory_bytes: 9500
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void push(double);
int pop(void);
int y=0;
double b[100];

int main(){
  char a[100];
  double c;
  char x=0;
  while((scanf("%s",a)) != EOF) {
    if(a[0]=='+')push(pop() + pop());
    else if(a[0]=='-'){
      c = pop();
      push(pop() - c);
    }
    else if(a[0]=='*')push(pop() * pop());
    else push(atoi(a));
  }
  printf("%d\n",pop());
  return 0;
}

void push(double f)
{
  if (y < 100)b[y++] = f;
}

int pop(void){
  if (y > 0)
    return b[--y];
  else {
    return 0;
  }
}







Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
    map<int,int> f;
    LL ok = 1;
    for(int z = 0; z < 2; z++){
        int n;
        cin >> n;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            if(z == 0){
                f[a]++;
            } else {
                f[a]--;
            }
            if(f[a] < 0) ok = 0;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, n;
    cin >> x >> n;
    int ele;
    int value;
    set<int> s;
    for(int i = 0; i < n; i++)
    {
        cin >> value;
        s.insert(value);
    }
    int mindiff = INT32_MAX;
    for(int i = x; i >= x - 100; i--)
    {
        if(s.find(i) == s.end())
        {
            // outline(i);
            int diff = x - i;
            // outline(mindiff);
            if(diff < mindiff)
            {
                mindiff = diff;
                ele = i;
            }
            break;
        }
    }
    for(int i = x; i <= x + 100; i++)
    {
        if(s.find(i) == s.end())
        {
            int diff = i - x;
            // outline(diff);
            // outline(mindiff);
            if(diff < mindiff)
            {
                diff = mindiff;
                ele = i;
            }
            break;
        }
    }
    outline(ele);
    return 0;
}

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

int main()
{
    char a, b; cin >> a >> b;

    if (a == 'H' && b == 'H') cout << 'H' << endl;
    if (a == 'H' && b == 'D') cout << 'D' << endl;
    if (a == 'D' && b == 'H') cout << 'D' << endl;
    if (a == 'D' && b == 'D') cout << 'H' << endl;
   
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    int n,w;cin>>n>>w;
    ll arrw[n];ll arrv[n]; 
    fr(i,0,n-1)cin>>arrw[i]>>arrv[i];
    ll dp[n+1][w+1];
    fr(i,0,n){
        fr(j,0,w){
            if(i==0||j==0)dp[i][j]=0;
            else if(arrw[i-1]<=j){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-arrw[i-1]]+arrv[i-1]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<endl;
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}


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

string s;
string::iterator p;
ll fact();
ll term();
ll exp();
ll M=1LL<<10,l;
bool f,ff[111];

ll fact() {
  if(!f) return 1;
  ll x;string num;
  while(isdigit(*p)){num+=*p;++p;}
  if(num.size()) {
    int k=1;
    x=0;
    if(num.size()>20) f=0;
    for(int i=num.size()-1; i>=0; i--) {
      x+=(num[i]-'0')*k;
      k*=2;
    }
    if(*p=='('||x<0||x>=M) f=0;
  } else if(*p=='(') {
    ++l;
    ff[l]=0;
    ++p;x=exp();
    if(!ff[l])f=0;
    ++p;--l;
  } else f=0;
  if(x<0||x>=M) f=0;
  return x;
}
 
ll term() {
  if(!f) return 1;
  ll x=fact();
  if(*p=='+'&&*p=='-') f=0;
  while(*p=='*'||*p=='/') {
    ff[l]=1;
    if(*p=='*') {
      ++p;
      x*=fact();
      if(x<0||x>=M) f=0;
    } else {
      ++p;
      x/=fact();
      if(x<0||x>=M) f=0;
    }
  }
  return x;
}

ll exp() {
  if(!f) return 1;
  int x=term();
  if(*p=='*'||*p=='/') f=0;
  while(*p=='+'||*p=='-') {
    ff[l]=1;
    if(*p=='+') {
      ++p;
      x+=term();
      if(x<0||x>=M) f=0;
    } else {
      ++p;
      x-=term();
      if(x<0||x>=M) f=0;
    }
  }
  return x;
}

bool ck() {
  int x=0;
  for(int i=0; i<s.size(); i++) {
    if(s[i]=='(') x++;
    if(s[i]==')') x--;
    if(x<0) return 0;
  }
  return !x;
}

ll ans;
string t;
void dfs(int k) {
  if(k==t.size()) {
    memset(ff,0,sizeof(ff));
    l=0;
    f=ck();
    p=s.begin();
    ll x=exp();
    if(p==s.end()&&f) ans=max(ans,x);
    return;
  }
  if(t[k]=='.') {
    string r="01+-*()";
    for(int i=0;i<r.size();i++) {
      s[k]=r[i];
      dfs(k+1);
    }
  } else dfs(k+1);
}

int main() {
  cin >> t;
  s=t;
  ans=-1;
  dfs(0);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int n;
int k;
long long res;

int main() {
	scanf("%d%d", &n, &k); n++;
	for(int i = k + 1; i < n; i++) {
		int s = i - k;
		res += n / i * s + max(0, n - n / i * i - k);
	}
	printf("%lld\n", res - (!k) * (n - 1));
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    X = str(input())
    stack = 0
    pop = 0
    for i in range(len(X)):
        if X[i] == 'S':
            stack += 1
        elif X[i] == 'T' and stack > 0:
            pop += 1
            stack -= 1
    print(len(X)-pop*2)

resolve()

Measured memory_bytes: 40048
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int main(){
	string ev[] = {"HIT", "OUT", "HOMERUN"};
	int n;
	cin >> n;
	while(n--){
		string s;
		int out = 0;
		int state = 0;
		int runner = 0;
		int point = 0;
		while(out < 3){
			cin >> s;
			if(s == ev[0]){
				state = state << 1;
				state++;
				if(state&(1<<3)){
					point++;
				}else{
					runner++;
				}
			}else if(s == ev[1]){
				out++;
			}else if(s == ev[2]){
				point += ++runner;
				state = 0;
				runner = 0;
			}
		}
		cout << point << endl;
	}

	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
char s[N];
int n;
int main() {
    scanf("%d", &n);
    scanf("%s", s);
    int ans = 0;
    for(int i = 2; i < n; ++i) {
        if(s[i - 2] == 'A' and s[i - 1] == 'B' and s[i] == 'C') {
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>
#include <functional>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	ll a, b, c, k, ans=0;
	cin >> a >> b >> c >> k;
	
	if (a >= k)
		ans = k;
	else {
		if ((a + b) >= k)
			ans = a;
		else
			ans = a - (k - a - b);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {
	string s;
	int k, l;

	cin >> s;

	for ( k = 0; k < s.size(); k++)
	{
		if (s[k] == 'A')break;
	}

	for (l = s.size() - 1; l >= 0; l--)
	{
		if (s[l] == 'Z')break;
	}

	cout << max(0, l - k + 1) << "\n";

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#define f first
#define s second
#define mp make_pair
using namespace std;

int main()
{
  int n,m;
  vector<pair<int,int> > a;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m;
    a.push_back(mp(m,i));
  }
  sort(a.begin(),a.end());
  int count=0;
  for(int i=0;i<a.size();i++){
    if(abs(a[i].s-i)%2==1)count++;
  }
  cout<<count/2<<endl;
  return 0;
}

Measured memory_bytes: 1400
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <unistd.h>
#include <fcntl.h>
#include <ext/stdio_filebuf.h>
#include <string.h>

using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;

static const char stdout_pre[]  = "\033[1m";
static const char stderr_pre[]  = "\033[31;1m";
static const char stdxxx_post[] = "\033[m";

class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count)
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};

int main()
{
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else {
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int a;
	std::string s;

	std::cin >> a >> s;

	std::cerr << "hogehoge\n";

	if (a >= 3200)
		std::cout << s << "\n";
	else
		std::cout << "red\n";
}


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

int ans;
int _size;

bool check(const string a, const string str)
{
  int cnt_3=0;
  int cnt_5=0;
  int cnt_7=0;
  
  for(int i=0;i < a.size();i++){
    if(a[i] == '3') cnt_3++;
    else if(a[i] == '5') cnt_5++;
    else if(a[i] == '7') cnt_7++;
  }
  if(cnt_3 >= 1 && cnt_5 >= 1 && cnt_7 >= 1){
    if( atoi(a.c_str()) <= atoi(str.c_str()) ){
      return true;
    }
    else return false;
  }
  return false;
}

void dfs(string base, const string str)
{
  if(base.size() > _size) return;

  if(check(base,str)){
    ans++;
  }
  
  dfs(base+"3",str);
  dfs(base+"5",str);
  dfs(base+"7",str);
}

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

  _size = str.size();
  
  string base = "";
  
  dfs(base+"3",str);
  dfs(base+"5",str);
  dfs(base+"7",str);

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

Measured memory_bytes: 256
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 8010
#define M 210
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
const int mod=998244353;
int f[M][N],a[N<<2],b[N<<2],c[N<<2],r[N<<2],limit=1,l=0;
int n,m,t;
int fac[N],inv[N];
inline int C(int n,int m){if(n<m)return 0;return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int ksm(int a,int b)
{
	int ans=1;
	while(b){if(b&1)ans=1LL*ans*a%mod;b>>=1;a=1LL*a*a%mod;}
	return ans;
}
inline int Z(int x){return x>=mod?x-mod:x;}
inline void NTT(int a[],int flag)
{
	for(register int i=0;i<limit;i++)if(i<r[i])swap(a[i],a[r[i]]);
	for(register int mid=1;mid<limit;mid<<=1)
	{
		int Wn=ksm(3,(mod-1)/(mid<<1));if(flag<0)Wn=ksm(Wn,mod-2);
		for(register int R=(mid<<1),j=0;j<limit;j+=R)
		{
			int w=1;
			for(register int k=0;k<mid;k++,w=1LL*w*Wn%mod)
			{
				int x=a[j+k],y=1LL*a[j+k+mid]*w%mod;
				a[j+k]=Z(x+y);a[j+k+mid]=Z(x+mod-y);
			}
		}
	}
	int inv=ksm(limit,mod-2);
	if(flag<0)for(register int i=0;i<limit;i++)a[i]=1LL*a[i]*inv%mod;
}
inline void mul(int a[],int b[],int c[],int len1,int len2)
{
	limit=1,l=0;
	while(limit<=len1+len2)limit<<=1,l++;
	for(register int i=len1+1;i<limit;i++)a[i]=0;
	for(register int i=len2+1;i<limit;i++)b[i]=0;
	for(register int i=0;i<limit;i++)r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
	NTT(a,1);NTT(b,1);
	for(register int i=0;i<limit;i++)c[i]=1LL*a[i]*b[i]%mod;
	NTT(c,-1);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read();t=max(n,m);
	fac[0]=1;
	for(register int i=1;i<N;i++)fac[i]=1LL*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;
	for(register int i=2;i<N;i++)inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	for(register int i=2;i<N;i++)inv[i]=1LL*inv[i]*inv[i-1]%mod;
	for(register int i=0;i<=n;i++)f[m][i]=C(n,i);
	for(register int i=m-1;i>=0;i--)
	{
		for(register int j=0;j<=n;j++)f[i][j]=1LL*f[i+1][j]*(C(j+1,2)+1)%mod;
		for(register int j=1;j<=n;j++)a[n-j+1]=1LL*f[i+1][j]*fac[j+2]%mod;
		for(register int j=1;j<=n;j++)b[j]=inv[j+2];
//		for(register int j=0;j<=n;j++)cout<<a[j]<<" ";cout<<endl;
//		for(register int j=0;j<=n;j++)cout<<b[j]<<" ";cout<<endl;
		mul(a,b,c,n,n);
		memset(a,0,sizeof(a));memset(b,0,sizeof(b));
//		for(register int j=0;j<limit;j++)cout<<c[j]<<" ";cout<<endl;
		for(register int j=0;j<=n;j++)f[i][j]=Z(f[i][j]+1LL*inv[j]*c[n-j+1]%mod);
		memset(c,0,sizeof(c));
//		for(register int j=0;j<=n;j++)cout<<f[i][j]<<" ";cout<<endl;cout<<endl;
	}
	printf("%d\n",f[0][0]);
	return 0;
}
/*
3 2
*/

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a < b && a < c) {
			System.out.print(a + " ");
			if (b < c) {
				System.out.println(b + " " + c);
			} else {
				System.out.println(c + " " + b);
			}
		} else if (b < a && b < c) {
			System.out.print(b + " ");
			if (a < c) {
				System.out.println(a + " " + c);
			} else {
				System.out.println(c + " " + a);
			}
		} else {
			System.out.print(c + " ");
			if (a < b) {
				System.out.println(a + " " + b);
			} else {
				System.out.println(b + " " + a);
			}
		}
	}

}

Measured memory_bytes: 26276
#include <iostream>
#include <iomanip>//stw(数字)で空白による桁揃え
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;

int main(void){
    int X,A;cin>>X>>A;
    if(X<A){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
    return 0;
}      

Measured memory_bytes: 256
import numpy as np
h, w = map(int, input().split())
table = np.array([list(input())for _ in range(h)]) == '.'
 
d = np.zeros((h, w), dtype = int)
u = np.zeros((h, w), dtype = int)
r = np.zeros((h, w), dtype = int)
l = np.zeros((h, w), dtype = int)

for i in range(h):
    d[i] = (d[i-1]+1) * table[i]
    u[-i-1] = (u[-i]+1) * table[-i-1]

for i in range(w):
    r[:, i] = (r[:, i-1]+1) * table[:, i]
    l[:, -i-1] = (l[:, -i]+1) * table[:, -i-1]
print(np.max(d+u+r+l)-3)

Measured memory_bytes: 219856
#include <iostream>
#include <string>

int main(){
  int ans = 0;
  std::string str;
  std::getline(std::cin, str);
  for(int i=0;i<4;i++){
    if(str[i] == '+'){
      ans++;
    }else{
      ans--;
    }
  }
std::cout << ans;
}


Measured memory_bytes: 256