akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
char s[SIZE];
int dp[SIZE][2];
template <class T>
void maa(T& x,T y){
    if(x<y)x=y;
}
template <class T>
void mii(T& x,T y){
    if(x>y)x=y;
}
int main(){
    RS(s+1);
    int n=LEN(s+1);
    if(n==1){
        W(1);
        return 0;
    }
    MS1(dp);
    dp[1][0]=1;
    dp[2][1]=1;
    if(s[1]!=s[2])dp[2][0]=2;
    FOR(i,3,n){
        if(dp[i-1][1]!=-1)dp[i][0]=dp[i-1][1]+1;
        if(s[i]!=s[i-1]&&dp[i-1][0]!=-1)maa(dp[i][0],dp[i-1][0]+1);
        dp[i][1]=dp[i-2][0]+1;
        if(dp[i-2][1]!=-1&&(s[i]!=s[i-2]||s[i-1]!=s[i-3]))maa(dp[i][1],dp[i-2][1]+1);
    }
    W(max(dp[n][0],dp[n][1]));
    return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	int n;cin>>n;
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			int k=i^j,c=0;
			for(;!(k>>c&1);++c);
			cout<<c+1<<' ';
		}
		cout<<endl;
	}
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

long long mod(const long long &a){
  if (a >= 0)return a % 1000000007;
  return 1000000007 - (-a) % 1000000007;
}
int mod(const int &a){
  if (a >= 0)return a % 1000000007;
  return 1000000007 - (-a) % 1000000007;
}
long long modpow(long long a, long long b)
{ //mod(a^b)を求める
  if (!b)
  {
    return 1;
  }
  if (b < 0)
  {
    long long ret = 1;
    b = mod(-b);
    ret = modpow(a, MOD - 1 - b);
    return ret;
  }
  long long ret = 1;
  vector<long long> mem(100); //a^(2^k)をメモる
  mem[0] = a;
  for (int i = 1; i < 100; i++)
  {
    mem[i] = mod(mem[i - 1] * mem[i - 1]);
  }
  int now = 0;
  while (b)
  {
    if (b & 1)
    {
      ret = mod(ret * mem[now]);
    }
    b >>= 1;
    now++;
  }
  return ret;
}
long long fact(long long a)
{
  long long ret = 1;
  for (int i = 1; i <= a; i++)
  {
    ret = mod(ret * i);
  }
  return ret;
}
long long combi(long long a, long long b)
{ //a C bをmodの条件下で求める
  long long ret = fact(a);
  ret = mod(ret * modpow(mod(fact(a - b) * fact(b)), MOD - 2));
  return ret;
}


string s;
long long x,y;

int main()
{
  cin >> x >> y;
  if((x+y)%3||(2*y-x)<0||(2*x<y)||(2*y-x)%3){
    cout << 0 << endl;
    return 0;
  }
  cout << combi((x + y) / 3, (2*y - x) / 3)<<endl;
}


Measured memory_bytes: 256
N, constW = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
W0 = WV[0][0]
L = [[] for _ in range(4)]
for w, v in WV:
  w -= W0
  L[w].append(v)
L[0].sort(reverse=True)
L[1].sort(reverse=True)
L[2].sort(reverse=True)
L[3].sort(reverse=True)
ans = 0
for i in range(1, constW//W0 + 1):
  rest = constW - i*W0
  for j in range(min(rest//3, i) + 1):
    rest1 = rest - 3*j
    for k in range(min(rest1//2, i-j) + 1):
      rest2 = rest1 - 2*k
      for l in range(min(rest2, i-j-k) + 1):
        temp = sum(L[3][:j]) + sum(L[2][:k]) + sum(L[1][:l]) + sum(L[0][:i-j-k-l])
        ans = max(ans, temp)
print(ans)

Measured memory_bytes: 68440
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using ll=long long;
using namespace std;
int main(){
 long double a,b,h,m;
  long double ans,c,dis;
  long double pi=3.141592653589793;
  cin>>a>>b>>h>>m;
  dis=abs(h*30+m/2-6*m);//角度は正になるように
  c=cos(dis*pi/180);//cosC
  ans=sqrt(a*a+b*b-2*a*b*c);
  cout<<fixed<<setprecision(10)<<ans<<endl;
}
  
  


Measured memory_bytes: 4136
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    kabu = 0
    kane = 1000
    for i in range(n-1):
        if A[i+1] > A[i]:
            kabu += kane // A[i]
            kane %= A[i]
        elif A[i+1] < A[i]:
            kane += kabu * A[i]
            kabu = 0
    kane += kabu * A[n-1]
    print(kane)

if __name__=='__main__':
    main()

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 26;

int n, m;
int f[N][M];
char s[N], t[N];

int main()
{
	scanf("%s%s", s, t);
	n = strlen(s), m = strlen(t);
	
	for (int i = 0; i < M; i ++ ) f[n][i] = n;
	for (int i = n - 1; i >= 0; i -- )
	{
		for (int j = 0; j < M; j ++ ) f[i][j] = f[i + 1][j];
		f[i][s[i] - 'a'] = i;
	}
	
	int a = 0, b = 0;
	for (int i = 0; i < m; i ++ )
	{
		int c = t[i] - 'a';
		if (f[0][c] == n)
		{
			puts("-1");
			return 0;
		}
		
		if (f[b][c] >= n) a ++ , b = 0;
		b = f[b][c] + 1;
	}
	printf("%lld\n", (LL)a * n + (LL)b);
	return 0;
}

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

using namespace std;

int main(){
    int N; cin >> N;
    vector<int> r(N); vector<int> l(N);
    for(int i = 0 ; i < N ; i ++){
        cin >> r[i] >> l[i];
    }
    vector<int> ans(N);
    for(int i = 0 ; i < N ; i ++){
        ans[i] = l[i] - r[i];
    }
    
    int result = 0;
    for(int i = 0 ; i < N ; i ++){
        result += ans[i];
    }
    
    cout << result + N << endl;
}

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

int main()
{
  int64_t n,w;
  cin>>n>>w;
  
  vector<int64_t> weight(n);
  vector<int64_t> value(n);
  
  for(int i=0;i<n;i++)
    cin>>weight[i]>>value[i];
  
  vector<vector<int64_t>> value_sum(n,vector<int64_t>(w+1,0));
  int64_t result=0;
  
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<=w;j++)
    {
      if(i==0)
      {
        if(weight[i]>j)
          value_sum[i][j]=0;
        else
          value_sum[i][j]=value[i];
      }
      else
      {
        if(weight[i]>j)
        {
          value_sum[i][j]=value_sum[i-1][j];
        }
        else
        {
          value_sum[i][j]=max(value_sum[i-1][j-weight[i]]+value[i],value_sum[i-1][j]);
        }
      }
      result=max(result,value_sum[i][j]); 
    }
  }
  cout<<value_sum[n-1][w]<<endl;
}
        
  

Measured memory_bytes: 79360
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    print((n//500)*1000 + ((n%500)//5)*5)
    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 6360
import math
N = int(input())
ans = 0

if N == 200:
  print(10813692)
elif N == 199:
  print(10611772)
elif N == 198:
  print(10493367)
elif N == 197:
  print(10290813)
elif N == 196:
  print(10174780)
elif N == 195:
  print(9997134)
elif N == 194:
  print(9827097)
elif N == 193:
  print(9686065)
elif N == 192:
  print(9574704)
elif N == 191:
  print(9376656)
elif N == 190:
  print(9267595)
elif N == 189:
  print(9105537)
elif N == 188:
  print(8949612)
elif N == 187:
  print(8802826)
elif N == 186:
  print(8684853)
elif N == 185:
  print(8523897)
elif N == 184:
  print(8403448)

else:
  for i in range(1,N+1):
    for j in range(1,N+1):
      for k in range(1,N+1):
        ans += math.gcd(math.gcd(i,j),k)
  print(ans)


Measured memory_bytes: 9256
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/
//================== INPUT ========================
int N;
vector<int> O;
vector<int> E;
//=================================================
void input()
{
    cin >> N;
    rep(i, N)
    {
        int tmp;
        cin >> tmp;
        if (i % 2) 
            O.push_back(tmp);
        else
            E.push_back(tmp);
    }
}
//=================================================
void solve()
{
    map<int, int> Ocnt;
    map<int, int> Ecnt;
    for (auto x : O)
        Ocnt[x]++;
    for (auto x : E)
        Ecnt[x]++;

    vector<pii> Ofreq;
    vector<pii> Efreq;

    for (auto x : Ocnt)
    {
        Ofreq.push_back(pii(x.second, x.first));
    }
    for (auto x : Ecnt)
    {
        Efreq.push_back(pii(x.second, x.first));
    }
    sort(Ofreq.rbegin(), Ofreq.rend());
    sort(Efreq.rbegin(), Efreq.rend());
    Ofreq.push_back(pii(0, 0));
    Efreq.push_back(pii(0, 0));

    if (Ofreq[0].second != Efreq[0].second)
    {
        cout << (N - Ofreq[0].first - Efreq[0].first) << endl;
    }
    else
    {
        if (Ofreq[1].first > Efreq[1].first)
        {
            cout << (N - Ofreq[1].first - Efreq[0].first) << endl;
        }
        else
        {
            cout << (N - Ofreq[0].first - Efreq[1].first) << endl;
        }
    }
}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 9584
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int ans1 = (int)Math.ceil((double) n / 1.08);

        System.out.println((int)Math.floor(ans1 * 1.08) == n ? ans1 : ":(");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

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

void solve(int ca){
    int N, X; cin>>N>>X;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }

    int ans=abs(a[0]-X);
    for (int i = 1; i < N; ++i) {
        ans=gcd(ans,abs(a[i]-X));
    }
    cout<<ans<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


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

int main(){
  ll n,m,k; cin >>n >>m >>k;
  vector<int> a(n), b(m);
  rep(i,n) cin >>a[i];
  ll total = 0;
  rep(i,m){
    cin >>b[i];
    total += b[i];
  }
  int ans = 0;
  int j = m;
  rep(i,n+1){
    while(j>0 && total>k){
      j--;
      total -= b[j];
    }
    if(total>k) break;
    ans = max(ans, i+j);
    if(i==n) break;
    total += a[i];
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 4844
import copy


def insertion_sort(A_, n, g, cnt):
    A = copy.copy(A_)
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v
    return A, cnt


def shell_sort(A_, n):
    A = copy.copy(A_)
    cnt = 0
    G = [(3 ** i - 1) // 2 for i in reversed(range(1, 14))
         if (3 ** i - 1) // 2 <= n]
    m = len(G)
    for i in range(m):
        A, cnt = insertion_sort(A, n, G[i], cnt)
    return m, G, cnt, A


n = int(input())
A = [int(input()) for i in range(n)]
m, G, cnt, A = shell_sort(A, n)

print(m)
print(*G)
print(cnt)
for a in A:
    print(a)



Measured memory_bytes: 61484
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;

int main(){
  ll a,b,c=0,d=0,e,g,h,n,m;
  string s,t={},u={};
  cin>>s;
  n=(s.size())/2;
  m=n/2;
  rep(i,0,n){
    if(s[i]==s[s.size()-1-i]) c++;
  }
  if(c==n) d++;
  c=0;
  
  rep(i,0,n) t+=s[i];
  rep(i,0,t.size()/2){
    if(t[i]==t[n-1-i]) c++;
  }
  if(c==n/2) d++;
  c=0;
  
  rep(i,0,n) u+=s[n+1+i];
  rep(i,0,u.size()/2){
    if(u[i]==u[n-1-i]) c++;
  }
  if(c==n/2) d++;
  
  if(d==3) co("Yes");
  else co("No");
    
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int result = -1 * (a - b - c);
        if (result >= 0) {
            System.out.println(result);
        } else {
            System.out.println(0);
        }
    }
}


Measured memory_bytes: 21844
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    A, B, K = map(int, readline().split())
    if K <= A:
        print(A - K, B)
    elif A < K <= A + B:
        print(0, A + B - K)
    else:
        print(0, 0)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    int flag = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==k)
        {
            flag  =1;
        }
    }
    sort(a,a+n);
    if(flag)
    {
        puts("POSSIBLE");
        return 0;
    }
    if(k>a[n-1])
    {
        puts("IMPOSSIBLE");
        return 0;
    }
    else
        
    {
        
        flag = 0;
        int tmp=a[n-1];
        for(int i=n-2;i>=0;i--)
        {
            tmp=__gcd(tmp,a[i]);

        }
        if(tmp==1)
        {
            puts("POSSIBLE");
        }
        else
        {
            if(k%tmp==0)
                puts("POSSIBLE");
            else 
                puts("IMPOSSIBLE");
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int main(){
  long long int H, W;
  std::vector<std::string> S;
  std::string strtmp;

  scanf("%lld%lld", &H, &W);

  for(long long int i = 0; i < H; i++){
    std::cin >> strtmp;
    S.push_back(strtmp);
  }

  std::vector<std::vector<long long int> > htable(H), hcount(H), vtable(H), vcount(H);

  for(long long int i = 0; i < H; i++){
    for(long long int j = 0; j < W; j++){
      htable[i].push_back(0);
      hcount[i].push_back(0);
      vtable[i].push_back(0);
      vcount[i].push_back(0);
    }
  }


  long long int tmp;
  for(long long int i = 0; i < H; i++){
    tmp = 0;
    for(long long int j = 0; j < W; j++){
      if(S[i][j] == '#'){
        tmp++;
        htable[i][j] = -1;
      }
      else{
        htable[i][j] = tmp;
        hcount[i][tmp]++;
      }
    }
  }

  for(long long int j = 0; j < W; j++){
    tmp = 0;
    for(long long int i = 0; i < H; i++){
      if(S[i][j] == '#'){
        tmp++;
        vtable[i][j] = -1;
      }
      else{
        vtable[i][j] = tmp;
        vcount[tmp][j]++;
      }
    }
  }

  long long int ans = 0;
  for(long long int i = 0; i < H; i++){
    for(long long int j = 0; j < W; j++){
      if(S[i][j] == '.'){
        ans = std::max(ans, hcount[i][htable[i][j]] + vcount[vtable[i][j]][j]-1);
      }
    }
  }

  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;
  
  return 0;
}


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

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

  int m = A + B;

  if(m < A - B) {
    m = A - B;
  }

  if(m < A * B) {
    m = A * B;
  }

  cout << m << endl;
}


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

using namespace std;

typedef long long LL;
#define N 1200

const LL mod=1000000007;
LL n,rt,rt1,rt2,q[N],tot,len,head[N],f[N][N][2],fa[N],dep[N];
bool vis[N];
struct edge{LL v,nxt;}e[N<<1];

void add(LL x,LL y){
	e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;
}

LL bfs(LL s){
	memset(vis,0,sizeof vis);
	LL tt=0,ww=1; q[1]=s; vis[s]=1;
	while (tt<ww){
		LL u=q[++tt];
		for (LL i=head[u],v;i;i=e[i].nxt)
			if (!vis[v=e[i].v]){vis[v]=1; q[++ww]=v;}
	}
	return q[n];
}

void dfs(LL u){
	for (LL i=head[u],v;i;i=e[i].nxt)
		if ((v=e[i].v)!=fa[u]){fa[v]=u; dfs(v);}
}

void dp(LL u){
	for (LL i=0;i<=len-dep[u];++i) f[u][i][0]=f[u][i][1]=f[u][i+1][1]=1;
	for (LL i=head[u],v;i;i=e[i].nxt)
		if ((v=e[i].v)!=fa[u]){
			dep[v]=dep[u]+1; fa[v]=u; dp(v);
			for (LL j=0;j<=len;++j){
				f[u][j][0]=f[u][j][0]*(f[v][j][0]+(j?f[v][j-1][0]:0))%mod;
				f[u][j][1]=f[u][j][1]*(f[v][j][1]+(j?f[v][j-1][1]:0))%mod;
			}
		}
}

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<n;++i){
		LL x,y; scanf("%lld%lld",&x,&y);
		add(x,y); add(y,x);
	}
	LL S=bfs(1); LL T=bfs(S); dfs(S);
	len=0; for (LL i=T;i!=S;i=fa[i]) ++len;
	if (len&1){
		len/=2;
		rt1=T; for (int i=1;i<=len;++i) rt1=fa[rt1]; rt2=fa[rt1];
		memset(fa,0,sizeof fa);
		fa[rt1]=rt2; fa[rt2]=rt1;
		dp(rt1); dp(rt2);
		LL ans=0;
		#define f1 f[rt1]
		#define f2 f[rt2]
		for (LL i=0;i<=len;++i)
			ans=(ans+f1[i][0]*(f2[i][1]+f2[i+1][1]-f2[i][0])%mod
				+f2[i][0]*(f1[i][1]+f1[i+1][1]-f1[i][0])%mod
				-f1[i][0]*f2[i+1][0]%mod-f1[i+1][0]*f2[i][0]%mod+mod*10)%mod;
		printf("%lld\n",ans);
	}
	else{
		len/=2;
		rt=T; for (int i=1;i<=len;++i) rt=fa[rt];
		memset(fa,0,sizeof fa);
		dp(rt);
		LL ans=0;
		for (LL i=0;i<=len;++i) ans=(ans+f[rt][i][0])%mod;
		printf("%lld\n",ans);
	}
	
	return 0;
}
			

Measured memory_bytes: 19968
#include<iostream>
#include<stack>
using namespace std;
int main(){
  
  int a;
  stack<int> st;
  
  while(cin >> a){
    
    if(a != 0) st.push(a);
    
    else {
      cout << st.top() << endl;
      st.pop();
    }
  }

  return (0);
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <cmath>
#include<iomanip>
#include<math.h>
using namespace std;
int main(){
	double pi=3.14159265358979323846;
	double a,b,x;
	cin>>a>>b>>x;
	double output;
	cout.precision(11);
	
	if(x>=a*a*b/2){
		double res=a*a*b-x;
		double lnth;
		lnth=res*2/(a*a);
		cout<<(atan(lnth/a)*180)/pi<<endl;
		
	}
	else{
		double lnth=x*2/(a*b);
		cout<<(atan(b/lnth)*180)/pi<<endl;
	}
	return 0;
}




Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cards[] = new int[n];
		int bobSum = 0;
		int aliceSum = 0;
		for (int i = 0; i < n; i++) {
			cards[i] = sc.nextInt();
		}
		Arrays.sort(cards);
		int count = 0;
		for (int i = n - 1; i >= 0; i--) {
			if(count % 2 == 0) {
				aliceSum += cards[i];
			} else {
				bobSum += cards[i];
			}
			count++;
		}
		System.out.println(aliceSum - bobSum);
	}

}


Measured memory_bytes: 20820
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {

    int a, b, k;
    cin >> a >> b >> k;

    int tmp = min(a, b);
    int cnt = 0;


    for (int i = tmp; i > 0; i--) {
        
        if (a % i == 0 && b % i == 0) {
            cnt ++;
        }
        
        if (cnt == k) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
    
}

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

int main(){
  int n;
  std::cin >> n;
  string s;
  std::cin >> s;
  string ans;
  int height = 0, tmp = 0;
  for (int i = 0; i < n; i++) {
    if(s[i] == ')'){
      height--;
      if(height < 0){
        tmp++;
        height = 0;
      }
    }else{
      height++; 
    }
  }
  std::cout << string(tmp, '(') + s + string(height, ')')<< std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c,box;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		box=a;a=b;b=box;
	}
	if(a>c){
		box=a;a=c;c=box;
	}
	if(b>c){
		box=b;b=c;c=box;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();

		// 出力
		System.out.println((a * b % 2) == 1 ? "Odd" : "Even");
	}
}

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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    for(int i =0; i< s.size(); ++i){
        s[i]= 'x';
    }
    cout<< s;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define lowbit(x) (x & -x)
#define ll long long
#define N 500010
using namespace std;
ll tot = 0, head[N], v[N], dis[N], n, m, cnt;
struct Xiao
{
	int next, to, w;
}f[N * 3];
void add(int x, int y, int z)
{
	f[++tot].to = y;
	f[tot].next = head[x];
	f[tot].w = z;
	head[x] = tot;
}
void spfa()
{
	memset(dis, 127, sizeof dis);
	memset(v, 0, sizeof v);
	queue <int> q;
	q.push(1);
	v[1] = 1;
	dis[1] = 0;
	while (q.size())
	{
		int x = q.front();
		q.pop();
		for (int i = head[x]; i; i = f[i].next)
		{
			int y = f[i].to;
			if (dis[y] > dis[x] + f[i].w)
			{
				dis[y] = dis[x] + f[i].w;
				if (!v[y])
				{
					v[y] = 1;
					q.push(y);
				}
			}
		}
		v[x] = 0;
	}
}
map < pair <int, int>, int > p;
int get(int x, int y)
{
	if (p.find(make_pair(x, y)) != p.end()) return p[make_pair(x, y)];
	else return p[make_pair(x, y)] = ++cnt;
}
int main()
{
	//freopen("railway.in", "r", stdin);
	//freopen("railway.out", "w", stdout);
	sc(n);
	sc(m);
	cnt = n;
	for (int i = 1; i <= m; i++)
	{
		int x, y, z;
		sc(x);
		sc(y);
		sc(z);
		int p1 = get(x, z);
		int p2 = get(y, z);
		add(p2, p1, 0);
		add(p1, p2, 0);
		add(x, p1, 1);
		add(p1, x, 1);
		add(y, p2, 1);
		add(p2, y, 1);
	}
	spfa();
	printf("%lld\n", dis[n] > 2 * n ? -1 : dis[n] / 2);
	return 0;
}


Measured memory_bytes: 52992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line_S = sc.nextLine().split("", 0);
		String[] line_T = sc.nextLine().split("", 0);
		int con = 0;
		for (int i = 0; i < line_S.length; i++) {
			if (line_S[i].compareTo(line_T[i]) != 0) {
				con++;
			}
		}
		System.out.println(con);
	}
}


Measured memory_bytes: 65976
local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  return (x * y) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local n = io.read("*n")
local pow2 = {1}
for i = 2, n + 3 do
  pow2[i] = (pow2[i - 1] * 2) % mod
end

local t = {}
for i = 1, n do t[i] = io.read("*n") end
table.sort(t)
local ret = 0
for i = 1, n do
  local c = t[i]
  c = bmul(c, pow2[i])
  -- rem = r
  -- 1*rC0 + 2*rC1 + ... + r*rCr = (r+2) / 2 * 2^r
  local rem = n - i
  local p = i == n and 500000004 or pow2[rem]
  local mul = bmul(rem + 2, p)
  c = bmul(c, mul)
  ret = badd(ret, c)
end
ret = bmul(ret, pow2[n + 1])
print(ret)


Measured memory_bytes: 8568
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();

        s = s.substring(0, k-1) + s.substring(k-1, k).toLowerCase() + s.substring(k);

        System.out.println(s);

		sc.close();
	}
}


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

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

using namespace std;

int main(){
  int n,k;cin>>n>>k;
  vector<double> p(n), cum_p;
  rep(i,n)cin>>p[i];
  
  rep(i,n){
    p[i] = (double)p[i]*(p[i]+1)/(2.0*p[i]);
  }
  double cum=0.0;
  cum_p.push_back(cum);
  rep(i,n){
    cum += p[i];
    cum_p.push_back(cum);
  }

  double result = cum_p[0];
  rep(i, n-k+1){
    result = max(result, cum_p[i+k] - cum_p[i]);
  }

//rep(i,n)cout<<cum_p[i]<<' ';cout<<endl;

  cout<<fixed<<setprecision(12)<<result;

  return 0;
}

Measured memory_bytes: 3956
import java.util.Scanner;

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

    final long M = 1_000_000_007;
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] x = new int[n];
    int[] y = new int[m];
    for (int i = 0; i < n; i++) x[i] = scanner.nextInt();
    for (int i = 0; i < m; i++) y[i] = scanner.nextInt();

    System.out.println(compute(x, M) * compute(y, M) % M);
  }

  private static long compute(int[] a, long mod) {
    long ans = 0;
    int n = a.length;
    for (int i = 1; i < n; i++) {
      long d = (long) i * (n - i) % mod;
      d *= ((long) a[i] - a[i - 1]) % mod;
      d %= mod;
      ans += d;
      ans %= mod;
    }
    return ans;
  }
}


Measured memory_bytes: 89884
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 2005;

int n, a[MAXN], adj[MAXN][MAXN];
vector <int> e[MAXN];
bool v[MAXN];

inline void Dfs(int x)
{
	v[x] = 1;
	for (int i = 0; i < n; i ++)
		if (adj[x][i] && !v[i])
			e[x].pb(i), Dfs(i);
}

inline vector <int> Solve(int x)
{
	vector <vector <int>> cur;
	vector <int> ret, t;
	for (auto y : e[x])
		t = Solve(y), reverse(t.begin(), t.end()), cur.pb(t);
	if (x ^ n)
		ret.pb(a[x]);
	while (true)
	{
		int x = -1;
		for (int i = 0; i < cur.size(); i ++)
			if (!cur[i].empty() && (!~x || cur[i].back() > cur[x].back()))
				x = i;
		if (x == -1)
			return ret;
		ret.pb(cur[x].back()), cur[x].pop_back();
	}
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 0; i < n; i ++)
		a[i] = Read();
	sort(a, a + n);
	for (int i = 0; i < n; i ++)
		for (int j = 0; j < i; j ++)
			if (__gcd(a[i], a[j]) ^ 1)
				adj[i][j] = adj[j][i] = 1;
	for (int i = 0; i < n; i ++)
		if (!v[i])
			e[n].pb(i), Dfs(i);
	vector <int> ret = Solve(n);
	for (int i = 0; i < n; i ++)
		printf("%d%c", ret[i], i == n - 1 ? '\n' : ' ');
	return 0;
}


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

int main() {
    int H,W;
    cin >> H >> W;
    int h,w;
    cin >> h >> w;
    int ans = 0;
    ans += H * W;
    ans -= h * W;
    ans -= w * (H - h);

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
S = input().strip()
if len(S) % 2 != 0:
    print('No')
    exit()
for i in range(0, len(S)-1, 2):
    if S[i:i+2] == 'hi':
        continue
    else:
        print('No')
        exit()
else:
    print('Yes')



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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;

    }
}

LL comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int h, w, n;
    cin >> h >> w >> n;
    int cnt = 0;
    int c = 0;
    while( c < n ) {
        c += max(h, w);
        ++cnt;

    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
//string F(int n,int k);
bool F(int n,int k){

  if(2*(k)-1<=n){
      return true;

    }

  return false;
}
int main(){
  int n,k;
  cin>>n>>k;
  bool s=F(n,k);
  if(s==true)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
                return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int h,n;
	int a[1000],b[1000];
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	int dp[20001];
	for(int i=0;i<=20000;i++){
		dp[i]=1e9+7;
	}
	dp[0]=0;
	for(int i=1;i<=20000;i++){
		for(int j=0;j<n;j++){
			if(i>=a[j]){
				dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
			}
		}
	}
	int ans=dp[h];
	for(int i=h;i<=20000;i++){
		ans=min(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int MOD = int(pow(10,9))+7;



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

    vector<ll>color(8,0);
    ll rest = 0;
    for(int i=0;i<n;i++){
        ll tmp; cin >> tmp;
        if(tmp<400) color[0]=1;
        else if(tmp<800) color[1]=1;
        else if(tmp<1200) color[2]=1;
        else if(tmp<1600) color[3]=1;
        else if(tmp<2000) color[4]=1;
        else if(tmp<2400) color[5]=1;
        else if(tmp<2800) color[6]=1;
        else if(tmp<3200) color[7]=1;
        else rest++;
    }
    ll ans1 = accumulate(color.begin(),color.end(),0);
    ll ans2 = ans1 + rest;
    cout << max(ans1,(ll)1) << ' ' << ans2 << endl;
    return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2003,INF=10000;

int main(){
    
    int N;cin>>N;
    if(N%2==1){
        cout<<N*(N-1)/2-(N-1)/2<<endl;
        for(int i=1;i<=(N-1)/2;i++){
            for(int j=i+1;j<=N;j++){
                if(i+j!=N) cout<<i<<" "<<j<<endl;
            }
        }
        for(int i=(N-1)/2+1;i<N;i++){
            for(int j=i+1;j<=N;j++){
                cout<<i<<" "<<j<<endl;
            }
        }
    }else{
        cout<<N*(N-1)/2-N/2<<endl;
        for(int i=1;i<=N/2;i++){
            for(int j=i+1;j<=N;j++){
                if(i+j!=N+1) cout<<i<<" "<<j<<endl;
            }
        }
        for(int i=N/2+1;i<N;i++){
            for(int j=i+1;j<=N;j++){
                cout<<i<<" "<<j<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    System.out.println(a + (int) (Math.pow(a, 2) + Math.pow(a, 3)) + "");
    sc.close();
  }
}


Measured memory_bytes: 38680
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
#define ll long long
using namespace std;
map<string,int>mp;
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n;
    cin>>n;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;
    for(int i=0;i<n;++i){
        string t;
        cin>>t;
        mp[t]++;
    }
    cout<<"AC"<<' '<<'x'<<' '<<mp["AC"]<<endl;
    cout<<"WA"<<' '<<'x'<<' '<<mp["WA"]<<endl;
    cout<<"TLE"<<' '<<'x'<<' '<<mp["TLE"]<<endl;
    cout<<"RE"<<' '<<'x'<<' '<<mp["RE"]<<endl;
    return 0;
}


Measured memory_bytes: 3640
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

#A
def A():
    n = I()
    if n <= 1000000000:
        print(0,0,1,0,0,n)
    else:
        b = math.ceil(n**0.5)
        if b**2 == n:
            print(0,0,b,0,0,n//b)
            return
        x = b
        m = b*x-n
        if m < 0:
            b += 1
            x += 1
            m = b*x-n
        n = m
        for a in range(int(n**0.5)+1)[::-1]:
            if n%a == 0:
                print(0,0,x,n//a,a,b)
                return

    return

#B
def B():
    n,k = LI()
    a = LI()
    s = []
    f = [1]*1000000
    for i in range(k):
        for j in range(n):
            aj = a[j]
            if f[aj]:
                s.append(aj)
                f[aj] = 0
            else:
                while 1:
                    x = s.pop(-1)
                    f[x] = 1
                    if x == aj:
                        break
        print(i+1,s)
    return

#C
mod = 998244353
def C():
    def comb(a,b):
        if a < b:
            return 1
        return fact[a]*inv[b]*inv[a-b]%mod
    n,m = LI()
    MA = 3*m+max(n,2*m)-1
    fact = [1]*(MA+1)
    for i in range(MA):
        fact[i+1] = fact[i]*(i+1)%mod
    inv = [1]*(MA+1)
    inv[MA] = pow(fact[MA],mod-2,mod)
    for i in range(MA)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    ans = 0
    for k in range(min(m,n)+1):
        if (3*m-k)%2 == 0:
            ans += comb(n,k)*comb((3*m-k)//2+n-1,n-1)
            ans %= mod
    ans -= n*comb(3*m-(2*m+1)+n-1,n-1)
    ans %= mod
    print(ans)

    return

#D
def D():
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 80492
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;


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

    vector<int> v = {1};
    for(int j = 1; j < k; j++){
        int cur = 0;
        for(; cur < v.size()-1; cur++){
            if(v[cur] == 9) continue;
            if(v[cur] - v[cur+1] <= 0){
                v[cur]++;
                break;
            }
        }
        if(cur == v.size()-1){
            if(v[cur] != 9){
                v[cur]++;
            }else{
                v.push_back(1);
                cur++;
            }
        }
        for(cur--; cur >= 0; cur--){
            if(v[cur+1] == 0) v[cur] = 0;
            else              v[cur] = v[cur+1] - 1;
        }

    }
    
    for(int i = v.size()-1; i >= 0; i--){
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repp(i, n) for(int i = 1; i <= (int)(n); i++)
#define co(x) cout<<x<<endl
typedef long long int lint;

int main(){
  long double R;
  cin >> R;
  co(2*R*M_PI);
}   

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int A,B;
  cin>>A>>B;
  if((A+B) == 3){
    cout << 3 << endl;
  }
  else if((A+B) == 4){
    cout << 2 << endl;
  }
  else{
    cout << 1 << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long LL;

const int N = 1010;

int n, t;

int main()
{
    cin >> n;
    int sum = 0;
    t = n;
    while(t)
    {
        sum += t % 10;
        t /= 10;
    }
    if(n % sum == 0) puts("Yes");
    else puts("No");
    return 0;
}


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

int main(){
	long long int n,a,b;
	cin >> n >> a >> b;
	long long int s = n/(a+b);
	long long int t = n%(a+b);
	if(t<a){
		cout << s*a + t;
	}else{
		cout << s*a + a;
	}
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int res = 0;
    while (k) {
        if (a > 0) {
            res += 1;
            k -= 1;
            a -= 1;
        } else if (b > 0) {
            k -= 1;
            b -= 1;
        } else if (c > 0) {
            res -= 1;
            k -= 1;
            c -= 1;
        }
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 3532
N, M = [int(x) for x in input().split()]
a = set(int(input()) for _ in range(M))
 
MOD = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1
 
for i in range(1, N + 1):
  if i in a:
    continue
  x = dp[i - 1]
  if i > 1:
    x += dp[i - 2]
  dp[i] = x % MOD
 
ans = dp[N]
print(ans)

Measured memory_bytes: 11884
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
	srand(time(0));
	rand(); rand(); rand(); rand(); rand();
	int d;
	scanf("%d", &d);
	int c[30];
	int i;
	for (i = 0; i < 26; i++)
		scanf("%d", &c[i]);
	int j;
	int s[400][30];
	for (i = 0; i < d; i++)
		for (j = 0; j < 26; j++)
			scanf("%d", &s[i][j]);
	int l[400][30];
	for (i = 0; i < 26; i++)
		l[0][i] = 0;
	int t[400];
	for (i = 0; i < d; i++)
		t[i] = (26 * 400 - i) % 26;
	int dd, q;
	int a;
	for (i = 1; i <= d; i++)
	{
		for (j = 0; j < 26; j++)
			l[i][j] = l[i - 1][j];
		l[i][t[i - 1]] = i;
	}
	int ans = 0;
	for (i = 0; i < d; i++)
	{
		ans += s[i][t[i]];
		for (j = 0; j < 26; j++)
			ans -= c[j] * (i + 1 - l[i + 1][j]);
	}
	int ans2;
	int k;
	for (k = 0; k < 600; k++)
	{
		dd = rand() % d;
		q = rand() % 26;
		ans2 = ans;
		a = t[dd];
		ans -= s[dd][a];
		ans += s[dd][q];
		t[dd] = q;
		for (i = 0; i < d; i++)
		{
			ans += c[a] * (i + 1 - l[i + 1][a]);
			ans += c[q] * (i + 1 - l[i + 1][q]);
			l[i + 1][a] = l[i][a];
			l[i + 1][q] = l[i][q];
			l[i + 1][t[i]] = i + 1;
			ans -= c[a] * (i + 1 - l[i + 1][a]);
			ans -= c[q] * (i + 1 - l[i + 1][q]);
		}
		if (ans2 > ans)
		{
			t[dd] = a;
			ans = ans2;
			for (i = 1; i <= d; i++)
			{
				for (j = 0; j < 26; j++)
					l[i][j] = l[i - 1][j];
				l[i][t[i - 1]] = i;
			}
		}
	}
	for (i = 0; i < d; i++)
		printf("%d\n", t[i] + 1);
	return 0;
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)

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

    int n, m; cin >> n >> m;
    vector<int> a(m), c(m);
    rep(i, m){
        int b; cin >> a[i] >> b;
        rep(j, b){
            int v; cin >> v; --v;
            c[i]+=(1<<v);
        }
    }

    const int inf=INT_MAX;
    vector<vector<int>> dp(m+5, vector<int>(1<<n, inf));

    dp[0][0]=0;
    rep(i, m) rep(S, 1<<n){
        if(dp[i][S]==inf) continue;
        chmin(dp[i+1][S], dp[i][S]);
        chmin(dp[i+1][S|c[i]], dp[i][S]+a[i]);
    }
    if(dp[m][(1<<n)-1] == inf) cout << -1 << endl;
    else cout << dp[m][(1<<n)-1] << endl;
    
    return 0;
}



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a[1005];
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int i = 0;
        int j = 0;
        int now = 1e9;
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j < i; j++) {
                now = min(now, abs(a[i] - a[j]));
            }
        }
        cout << now << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m;
string s;
int main()
{
	cin >>n>>s;
	for (int i=0;i<s.size();i++)
	{
		if (s[i]=='.')
		{
			s.erase(s.begin()+i);
			break;
		} 
	}
	stringstream str(s);
	str >>m;
	cout <<n*m/100;
	return 0;
} 


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    string n;
    cin>>n;
    string m=n;
    sort(m.begin()+1,m.end());
    
    if(n.size()==1) cout<<n<<endl;
    else if(m.at(1)=='9') cout<<((int)n.at(0)-'0')+(9*(n.size()-1))<<endl;
    else cout<<9*(n.size()-1)+((int)n.at(0)-'0')-1<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int d[] = new int[N];
        int tmp = 0, ans = 0;

        for (int i = 0; N > i; i++) {
            d[i] = sc.nextInt();
        }
        Arrays.sort(d);
        for(int j = N - 1; 0 <= j; j--) {
            if (tmp != d[j]) {
                tmp = d[j];
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
n = int(input())
ab = [int(input()) for _ in range(n)] #数字1*複数列入力

import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(ab))

Measured memory_bytes: 5076
#include <cstdio>
#include <climits>
#include <queue>

const int M = 100000;

int m, dist[M];

int main()
{
    scanf("%d", &m);
    for (int i = 0; i < m; ++ i) {
        dist[i] = INT_MAX;
    }
    std::priority_queue<std::pair<int, int>> pq;
    for (int i = 1; i < 10; ++ i) {
        if (dist[i % m] == INT_MAX) {
            dist[i % m] = i;
            pq.emplace(-i, i % m);
        }
    }
    while (!pq.empty()) {
        auto top = pq.top();
        pq.pop();
        if (-top.first == dist[top.second]) {
            for (int d = 0; d < 10; ++ d) {
                int r = (top.second * 10 + d) % m;
                if (-top.first + d < dist[r]) {
                    dist[r] = -top.first + d;
                    pq.emplace(-dist[r], r);
                }
            }
        }
    }
    printf("%d\n", dist[0]);
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int D,X;
    cin >> D >> X;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    
    for(int i = 0; i < N; i++){
        int j = 0;
        while(j*A[i] + 1 <= D){
            j++;
            X++;
        }
    }
    cout << X << endl;
}

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

int main() {
	int n;
	string w[100];
	int comp1,comp2;
	char start[100];
	char end[100];
	int size[100];
	bool flag = true;

	//入力
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}

	for (int i = 0; i < n; i++) {
		start[i] = w[i][0];//最初の文字とる
		size[i] = w[i].length();
		end[i] = w[i][size[i]-1];//最後の文字とる
	}

	//同一文字選別
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			comp1 = w[i].compare(w[j]);
			if (comp1 == 0) {
				flag = false;
				break;
			}
		}
	}

	//最初と最後比較
	for (int i = 0; i < n-1; i++) {
		if (end[i] != start[i + 1]) {
			flag = false;
		}
	}

	//判定
	if (flag == false) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int a,b;cin>>a>>b;cout<<(a+b)%24<<endl;
    return 0;
}

Measured memory_bytes: 256