akhauriyash/Code-Regression huggingface dataset:
// package other2019.keyence2019;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    static long __startTime = System.currentTimeMillis();

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int[] a = new int[4];
        for (int i = 0; i <4 ; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);

        boolean x =  (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9);
        out.println(x ? "YES" : "NO");
        out.flush();
    }

    private static void printTime(String label) {
        debug(label, System.currentTimeMillis() - __startTime);
    }

    private static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

Measured memory_bytes: 22996
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
						 {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

char s[200010];
int h[200010],d[200010];

int main() {
	int n;
	cin >> n;
	cin >> s;
	int ht=0;
	int dt=0;
	rep(i,n){
		if(s[i]=='#'){
			ht++;
			h[i]=ht;
		}else{
			h[i]=ht;
		}
	}
	rrep(i,n){
		if(s[i]=='.'){
			dt++;
			d[i]=dt;
		}else{
			d[i]=dt;
		}
	}
	int m=1000000;
	rep(i,n+1){
		if(i==0){
			m=min(d[i],m);
			continue;
		}
		if(i==n){
			m=min(h[i-1],m);
		}
		m=min(d[i]+h[i-1],m);
	}
	printf("%d",m);
	
	
	
	
	
	/* --------------------------------- */
	printf("\n");
	return 0;
}

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

int main() {
  int N,hp;
  cin >> N;
  vector<int> takoyaki(N);
  for(int i =0;i < N;i++) {
    cin >> takoyaki.at(i);
  }
  for(int i =0;i < N;i++) {
   for(int j =i+1;j < N;j++) {
     hp = hp + takoyaki.at(i)*takoyaki.at(j);
   }
  }
  
  cout << hp << endl;
}


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

ll INF = 1e+18;
int iINF = 1e9;

int 
main()
{
  int N; cin >> N;
  map<string, ll> m;
  vector<pair<ll, ll>> arr(N + 1);
  rep(i, 1, N + 1){
    int tmp; cin >> tmp;
    arr[i].first = i;
    arr[i].second = tmp;
    tmp = i - tmp;
    m["x" + to_string(tmp)] += 1;
  }

  ll ans = 0;
  rep(i, 1, N){
    ll comp = arr[i].first + arr[i].second;
    ans += m["x" + to_string(comp)];
  }

  cout << ans << endl;

}

Measured memory_bytes: 34920
#include <algorithm>
#include <sstream>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;

#define rep(i,n) for(int i = 0;i<n;i++)
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main() {
	while(true){
		int N;
		vector<int> v;
		cin >> N;
		if(N==0)break;
		rep(i,N){
			int s = 0;
			rep(j,5){
				int k;
				cin >> k;
				s += k;
			}
			v.push_back(s);
		}
		sort(v.begin(),v.end());
		cout << v[v.size()-1] << " " << v[0] << endl;
	}
	return 0;
}

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

namespace abc168_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int nmb =int.Parse( N.Substring(N.Length - 1, 1));
            
            if (nmb==2 || nmb == 4 || nmb == 5 || nmb == 7 ||nmb == 9)
            {
                Console.Write("hon");
            }
            else if(nmb==0 || nmb == 1 || nmb == 6 || nmb == 8)
            {
                Console.Write("pon");
            }
            else if(nmb==3)
            {
                Console.Write("bon");
            }
            Console.Read();
        }
    }
}


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

int main(){
    int n, m, i;
    int h[100000];
    int a;
    int b;
    int ma[10000];
    cin >> n >> m;
    for(i=0; i<n; i++){
        cin >> h[i];
    }
    bool check[n];
    for(i=0; i<n; i++){
        check[i] = true;
    }
    for(i=0; i<m; i++){
        cin >> a >> b;
        a -= 1;
        b -= 1;
        if(h[a] <= h[b]){
            check[a] = false;
        }
        if(h[a] >= h[b]){
            check[b] = false;
        }
    }
    int ans = 0;
    for(i=0; i<n; i++){
        if(check[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
}

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

const int MAX= 31700; //sqrt(1e9)
int sosu[MAX+1];
void Prime_Factor(){
  for(int i=2;i<=MAX;i++){
    if(!sosu[i]){
      for(int j=i*2;j<=MAX;j+=i){
        sosu[j]=1;
      }
    }
  }
}
void Prime_Factorization(int k){//kを素因数分解
    int pri_num=0;
    for(int i=2;i<=MAX;i++){
      while(!sosu[i] && k%i==0){
        cout<<" "<<i;
        k/=i;
        pri_num++;
      }
    }
    if(pri_num==0) cout<<" "<<k;
}
int main(){
  int n; cin>>n;
  cout<<n<<':';
  Prime_Factor();
  Prime_Factorization(n);
  cout<<"\n";
}



Measured memory_bytes: 3212
#!/usr/bin/env python3
import sys, math, fractions, itertools

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, t: "List[int]", x: "List[int]", y: "List[int]"):
    flag = True
    p = (0, 0)
    ct = 0
    for i in range(N):
        d = abs(x[i] + y[i])
        dt = t[i] - ct
        if dt - d < 0 or (dt - d) % 2 != 0:
            flag = False
    if flag:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]" 
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        t[i] = int(next(tokens))
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, t, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13684
/*                    ___          |\    /|           ____   ____   ____  ____
   |     |    /\    /    \ |     | | \  / |    /\    |    \ |    \ |     |    \
   |_____|   /__\   \____  |_____| |  \/  |   /__\   |____/ |____/ |__   |____/
   |     |  /    \       \ |     | |      |  /    \  |      |      |     |   \
   |     | /      \ \____/ |     | |      | /      \ |      |      |____ |    \
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define pld pair<long double,long double>
#define endl '\n'
#define loop(i,n) for(ll i=0;i<n;i++)
#define mod ((ll)(1e9+7))
#define in(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define in3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define inv(v) for(auto&i:v) in(i)
#define vl vector<ll>
#define ml unordered_map<ll,ll> 
#define vpl vector<pair<ll,ll>>
#define INF 0x3f3f3f3f

int main() {
    ll a,b,c,d;
    in2(a,b);
    in2(c,d);
    if(d==1) cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
}

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

int main(){

  int n, out, runner, pt;
  string str, s;

  cin >> n;

  for(int i=0; i<n; i++){
    out = 0;
    runner = 0;
    pt = 0;
    while(out != 3){
      cin >> s;
      if(s == "OUT"){
        out++;
      }
      else if(s == "HOMERUN"){
        pt += runner + 1;
        runner = 0;
      }
      else{
        if(runner < 3) runner++;
        else pt++;
      }
    }

    cout << pt << endl;

  }  

  return 0;

}

Measured memory_bytes: 1208
n, m = map(int, input().split())
p = {int(input()) for _ in range(m)}
s = 10 ** 9 + 7

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
if 1 in p:
    dp[1] = 0

for i in range(2, n+1):
    if i in p:
        continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % s

print(dp[-1])


Measured memory_bytes: 11884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vll c(n);
  vector<vll> a(n,vll(m));
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
  ll ans = 10000000000LL;
  for(int i = 0; i<(1<<n); i++) {
    ll tmp = 0LL;
    vi v(m);
    rep(j,n) {
      if(i>>j&1) {
        tmp += c[j];
        rep(k,m) v[k] += a[j][k];
      }
    }
    bool ok = true;
    rep(j,m) if(v[j]<x) ok = false;
    if(ok) ans = min(ans,tmp);
  }
  if(ans==10000000000LL) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

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

const int MAX_N = 1e5 + 5;
int n, ans;
int Arr[MAX_N];
string s;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> s;
    if (s == "SAT")
        cout << 1;
    if (s == "FRI")
        cout << 2;
    if (s == "THU")
        cout << 3;
    if (s == "WED")
        cout << 4;
    if (s == "TUE")
        cout << 5;
    if (s == "MON")
        cout << 6;
    if (s == "SUN")
        cout << 7;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;

void input() {
  cin >> n;
}

void solve() {
  ll ans = 0;

  for (int i = 0; i < n; ++i) {
    int x = i + 1;

    if (x % 3 != 0 && x % 5 != 0)
      ans += x;
  }

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3612
#!/usr/bin/env python3


def main():
    N = int(input().strip())
    print(lcm(N, 2))


def lcm(a, b):
    return a * b // gcd(a, b)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> table(m,0);
  int k;
  rep(i,n){
    cin>>k;
    rep(j,k){
      int buf;
      cin>>buf;
      table[buf-1]++;
    }
  }
  int ans = 0;
  rep(i,m) if(table[i] == n) ans++;
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#define REP(i,n) for (long long i=0;i<(n);i++)
using namespace std;
template<typename V,typename Weight>
class Dijekstra {
private:
	struct edge {
		Weight dist;V node;V prev;
		bool operator<(edge const& a) const {
			return dist < a.dist;
		}
		bool operator>(edge const& a) const {
			return dist > a.dist;
		}
	};
	//vector<V> trace;
	vector<vector<pair<V,Weight>>> E;
	V const sz;
public:
	Weight const inf = numeric_limits<Weight>::max();
	vector<Weight> D;
	Dijekstra(V v) :
		E(v),sz(v),D(v,inf) {}

	void inline addEdgeDirected(V from,V to,Weight dis){
		E[from].emplace_back(make_pair(to,dis));
	}
	void inline addEdgeUndirected(V from,V to,Weight dis){
		E[from].emplace_back(make_pair(to,dis));
		E[to].emplace_back(make_pair(from,dis));
	}

	V size() {return sz;}
	Weight & operator[] (V n) { if (0 <= n && n < sz) return D[n];} 

	void dijekstra(V start){
		priority_queue<pair<Weight,V>,vector<pair<Weight,V>>,greater<pair<Weight,V>>> que;
		D[start] = 0;
		que.push(make_pair(0,start));
		while(!que.empty()){
			pair<Weight,V> cur = que.top();que.pop();
			Weight d = cur.first;
			V v = cur.second;
			if (D[v] < d) continue; //既により最適が見つかっている
			for(V i = 0;i < E[v].size();i++){
				V next = E[v][i].first;
				Weight newCost = d + E[v][i].second;
				if (D[next] > newCost) {
					D[next] = newCost;
					que.push(make_pair(newCost,next));
				}
			}
		}
	}
/*
	vector<V> show_trace(V start,V goal){ // startからgoalの最短距離上のノード
		vector<V> ret;
		for (V node = goal;node != start;node = trace[node]) ret.push_back(node);
		ret.push_back(start);
		return ret; // 配列の先頭がgoal,末尾がstart
	}
*/
};

int main(void){
	long V,E,R;
	long s,t,d;
	cin >> V >> E >> R;
	Dijekstra<long,long> dij(V);

	REP(i,E){
		cin >> s >> t >> d;
		dij.addEdgeDirected(s,t,d);
	}
	dij.dijekstra(R);
	REP(i,V) {
		if (dij[i] == dij.inf) cout << "INF" << endl;
		else cout << dij[i] << endl;
	}

	return 0;
}





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

int main(void){
    int x;
    int i = 1;
    
    while(true){
    cin >> x;
    if(x == 0) return 0;
    cout << "Case " << i << ": " << x << endl;
    i++;
    }
    
    return 0;
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N;
int a[16][16];
int memo[1<<16];
int dp[1<<16];
signed main() {
	cin>>N;
	rep(i,N)rep(j,N)cin>>a[i][j];
	rep(i,1<<N)rep(j,N)if(i>>j&1)rep(k,N)if(i>>k&1)memo[i]+=a[j][k];
	rep(i,1<<N){
		for(int j=i;j>0;j=(j-1)&i){
			chmax(dp[i],dp[i-j]+memo[j]);
		}
	}
	cout<<dp[(1<<N)-1]/2<<endl;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e6+10;
    int n;
    char num[MAXN];
    int dp[MAXN][2];
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>num;
        n=strlen(num);
        for(int u=n-1;u>=0;u--){
            dp[u][0]=min(dp[u+1][0]+num[u]-'0'
            ,dp[u+1][1]+num[u]-'0'+1);
            if(u==n-1)dp[u][1]=dp[u+1][0]+10-(num[u]-'0');
            else dp[u][1]=min(dp[u+1][0]+10-(num[u]-'0'),dp[u+1][1]+9-(num[u]-'0'));
        }
        //借位和不借位,齐头并进
        cout<<min(dp[0][0],dp[0][1]+1);
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();  
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    [&](){
      vector<int> a(n),b(n);
      for(int i=0;i<n;i++)cin>>a[i];
      for(int i=0;i<n;i++)cin>>b[i];
      sort(a.begin(),a.end());
      sort(b.begin(),b.end());
      int cnt=0,j=0;
      for(int i=n-1;i>=0;i--){
	while(j<n&&b[j]-cnt<=0)j++;
	if(n-j==a[i]){
	  cnt++;
	  continue;
	}
	cout<<"No"<<endl;
	return;
      }
      cout<<"Yes"<<endl;
    }();
  }
  return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int MAXN=100005;
long long n,a[MAXN];
map<long long,long long> cnt;
vector<long long> v;
int main()
{
	cnt.clear();
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	for (int i=0;i<n;++i)
	{
		while (cnt[a[i]]>=2)
		{
			v.push_back(a[i]);
			cnt[a[i]]-=2;
		}
	}
	if ((int)v.size()<2)
	{
		cout<<0<<endl;
		return 0;
	}
	sort(v.rbegin(),v.rend());
	cout<<(long long)(v[0]*v[1])<<endl;
	return 0;
}

Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){
    
    ll N;
    cin >> N;
    V v(N);
    rep(i, N)cin >> v[i];
    ll ans = 0, tmp = 0;
    rep(i, N){
        tmp += v[i];
        if(i % 2 == 0 && tmp <= 0){
            ans += 1 - tmp;
            tmp = 1;
        }
        else if(i % 2 == 1 && tmp >= 0){
            ans += 1 + tmp;
            tmp = -1;
        }
    }
    ll ans2 = 0, tmp2 = 0;
    rep(i, N){
        tmp2 += v[i];
        if(i % 2 == 1 && tmp2 <= 0){
            ans2 += 1 - tmp2;
            tmp2 = 1;
        }
        else if(i % 2 == 0 && tmp2 >= 0){
            ans2 += 1 + tmp2;
            tmp2 = -1;
        }
    }    
    chmin(ans, ans2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n,m = map(int,input().split())
l = []
for i in range(m):
    a,b = map(int,input().split())
    l.append((a,b))

l = sorted(l, reverse=False, key=lambda x: x[1])
ans = 1
tmp = l[0][1]
for i in range(1,len(l)):
    if tmp <= l[i][0]:
        
        tmp = l[i][1]
        ans += 1

print(ans)
    
    

Measured memory_bytes: 24716
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void) {
    char list[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    while(true) {
        int n,k[200];
        char s[150]={};

        scanf("%d", &n);
        if(!n) break;

        for(int i=0; i<n; i++)
            scanf("%d", &k[i]);

        scanf("%s",s);

        for(int i=0; s[i]; i++) {
            printf("%c", list[((lower_bound(list, list+52, s[i])-list)-k[i%n]+52)%52]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1004
#include<cstdio>

const int MAX_N = 1e5, A = 1e9 + 7;
int n;
int a[MAX_N], cnt[MAX_N];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int ans = 1;
    int nl = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            if (++nl > 3) {
                printf("0\n");
                return 0;
            }
            cnt[0]++;
        }
        else {
            if (cnt[a[i] - 1] == 0) {
                printf("0\n");
                return 0;
            }
            ans = static_cast<long>(ans) * cnt[a[i] - 1]-- % A;
            cnt[a[i]]++;
        }
    }
    
    ans = (nl == 1) ? (static_cast<long>(ans) * 3 % A) : (static_cast<long>(ans) * 6 % A);
    printf("%d\n", ans); 
    return 0;
}


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

using namespace std;

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

  for (int i = 0; i < 2; i++) {
    if (N[i] == N[i+1] && N[i+1] == N[i+2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int s0 = count(S.cbegin(), S.cend(), '0');
  int s1 = count(S.cbegin(), S.cend(), '1');
  cout << min(s0, s1) * 2 << "\n";
}

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

using ll = long long int;
using P = pair<ll,ll>;
constexpr int INF = 1<<30;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    int hmin = INF;
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i] >> h[i];
        hmin = min(hmin, h[i]);
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(int H=0;H<=200;H++){
                bool ok = true;
                for(int k=0;k<n;k++){
                    if(max(H+hmin-abs(i-x[k])-abs(j-y[k]),0) != h[k]){
                        ok = false;
                        break;
                    }
                }
                if(ok){
                    cout << i << " " << j << " " << H+hmin << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


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

int main() {
	int n,a,b,c;
	bool r = true;
	cin >> n;
	vector<int> t, x, y;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		t.push_back(a);
		x.push_back(b);
		y.push_back(c);
	}
	a = 0; b = 0;
	int j = 0;
	for (int i = 0; i < n; i++) {
		for (; j < t[i]; j++) {
			if (x[i] > a) {a++;}
			else if (x[i] < a) { a--; }
			else if (y[i] > b) { b++; }
			else if (y[i] < b) { b--; }
			else { a--; }
		}
		if (a != x[i] || b != y[i]) { r = false; break; }
	}
	if (r == true) { cout << "Yes"; }
	else { cout << "No"; }
	return 0;
}

Measured memory_bytes: 1644
#include<cstdio>
using namespace std;
int n,l,r;
long long ai[200005],sum[200005],xsum[200005],ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&ai[i]);
		sum[i]=sum[i-1]+ai[i];
		xsum[i]=xsum[i-1]^ai[i];
	}
	r=1;
	for(l=1;l<=n;l++){
		while(r<=n&&(sum[r]-sum[l-1])==(xsum[r]^xsum[l-1])){
			r++;
		}
		r--;
		ans += (r-l+1);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
n, m = map(int, input().split())
A = [list(map(int, input().split())) for j in range(n)]
b = [int(input()) for i in range(m)]

c = [0 for i in range(n)]
for i in range(n):
    for j in range(m):
        c[i] += A[i][j] * b[j]
    print(c[i])



Measured memory_bytes: 6024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;

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

  vector<vector<char>> vec(h*2,vector<char>(w));
  for (int i = 0; i < 2*h; i+=2)
  {
    for (int j = 0; j < w; j++)
    {
      cin >> vec.at(i).at(j);
      vec.at(i+1).at(j) = vec.at(i).at(j);
    }
  }

  for (int i = 0; i < 2*h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      cout << vec.at(i).at(j);
    }
    cout << endl;
  }
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 1e9 + 1
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

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

    vector<int> kuro(s.size(), 0);
    vector<int> shiro(s.size(), 0);
    int tmp_kuro = 0, tmp_shiro = 0;
    REP(i, s.size()) {
        if(s[i] == '.') {
            tmp_shiro++;
        } else {
            tmp_kuro++;
        }
        kuro[i] = tmp_kuro;
        shiro[i] = tmp_shiro;
    }

    int ans = INF, tmp = 0;

    REP(i, s.size()+1) {
        if(i == 0){
            tmp = shiro[s.size()-1];
        } else if (i == s.size()) {
            tmp = kuro[s.size()-1];
        } else {
            tmp = kuro[i-1];
            tmp += shiro[s.size()-1] - shiro[i-1];
        }

        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2180
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#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;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

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

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 ncnt[200005];

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

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

    }
    vector< int > cnt;
    for( int i = 0; i < 200005; ++i ) {
        if( ncnt[i] != 0 ) {
            cnt.pb(ncnt[i]);

        }
    }

    sort(all(cnt), greater<int>());
    LL res = 0;
    for( int i = k; i < cnt.size(); ++i ) {
        res += cnt[i];

    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 2168
/* ex9_1
   UMAboogie */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10

typedef struct { //スタックを定義
  int size;
  int count;
  char data[SIZE];
  char *top;
} stack;

void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk, char x);
double pop(stack *stk);

stack stk;

int main(void){

  int i = 0;
  char key[SIZE+1]; //一時的に格納する配列を宣言
  initialize_stack(&stk); //スタックを初期化
  scanf("%s", key); //入力されたデータをkeyに追加

  while(key[i] != '\0'){
    if(key[i] == 'B'){
      if(stk.count > 0){
        pop(&stk); //入力がBでかつcountが正であればpop
      }
    }else{
      push(&stk,key[i]); //入力が0or1のときそれをスタックに追加
    }
    i++;
  }
  print_stack(&stk); //結果を出力
  return 0;
}


void initialize_stack(stack *stk){ //スタックの初期化
  stk->count = 0; //要素数を0にする
  stk->size = SIZE; //スタックの大きさをSIZEにする
  stk->top = &(stk->data[SIZE]); //topを配列の末尾にする
}

void push(stack *stk, char x){ //データの追加
  if(stk->count >= stk->size){//オーバーフローする時
    exit(1);
  }else{
    stk->top--; //topを1つ手前にする
    *(stk->top) = x; //そこにデータを格納する
    stk->count++; //countを1加算する
  }
}

double pop(stack *stk){ //データの取り出し
  char x;
  if(stk->count <= 0){//アンダーフローする時
    exit(1);
  }else{
    x = *(stk->top); //topの位置からデータを取り出す
    stk->top++; //topを1つ下げる
    stk->count--; //countを1下げる
    return x;
  }
}

void print_stack(stack *stk){ //スタックの中身を古い順に出力
  for(int i=0;i<stk->count;i++){
    printf("%c",stk->data[SIZE-i-1]);
  }
}


Measured memory_bytes: 1632
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  
  int sum = 700;
  if(s[0] == 'o')
    sum += 100;
  if(s[1] == 'o')
    sum += 100;
  if(s[2] == 'o')
    sum += 100;
  cout << sum << endl; 
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 5e5 + 5;
int p[N], q[N];

void pref_func(const string &s, int a[N]) {
    for (int i = 1; i < s.size(); i++) {
        a[i] = a[i - 1];
        while (a[i] != 0 && s[a[i]] != s[i]) {
            a[i] = a[a[i] - 1];
        }
        if (s[a[i]] == s[i])
            a[i]++;
    }
}

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

    string s;
    cin >> s;

    int n = s.size();

    pref_func(s, p);
    reverse(all(s));
    pref_func(s, q);
    reverse(q, q + n);

    int per = n - p[n - 1];

    if (n == per || n % per) {
        cout << "1\n1";
    }
    else if (per == 1) {
        cout << n << "\n1";
    }
    else {
        int ct = 0;
        for (int i = 0; i + 1 < n; i++) {
            if ((p[i] == 0 || (i + 1) % (i + 1 - p[i])) &&
                (q[i + 1] == 0 || (n - i - 1) % (n - i - 1 - q[i + 1])))
                ct++;
        }
        cout << "2\n" << ct;
    }

    return 0;
}

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

long long a, b, c, d;

int main() {
  cin >> a >> b >> c >> d;
  if ((c + b - 1) / b <= (a + d - 1) / d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
using namespace std;

#define INT_max 2147483647


typedef long long ll;
typedef long double ld;


char change(char x){
	if(x == '9') return '1';
	return x+1;
}


int main(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue<int,vector<int>,greater<int> > pq1,pq2;
	for(int i = 0;i < a;i++){
		int t;
		cin>>t;
		if(pq1.size() < x) pq1.push(t);
		else if(pq1.top() < t){
			pq1.pop();
			pq1.push(t);
		}
	}
	for(int i = 0;i < b;i++){
		int t;
		cin>>t;
		if(pq2.size() < y) pq2.push(t);
		else{
			if(pq2.top() < t){
				pq2.pop();
				pq2.push(t);
			}
		}
	}
	for(int i = 0;i < c;i++){
		int t;
		int m = pq1.top() , n = pq2.top();
		//cout<<m<<" "<<n<<endl;
		cin>>t;
		if(m > n){
			if(t > n){
				pq2.pop();
				pq2.push(t);
			}
		}
		else{
			if(t > m){
				pq1.pop();
				pq1.push(t);
			}
		}
	}
	ll ans = 0;
	while(pq1.size()){
		ans += pq1.top();
		pq1.pop();
	}
	while(pq2.size()){
		ans += pq2.top();
		pq2.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    string str;
    cin >> str;

    int n=0, w=0, s=0, e=0;
    rep(i, str.size()){
        if(str[i] == 'N') n++;
        if(str[i] == 'W') w++;
        if(str[i] == 'S') s++;
        if(str[i] == 'E') e++;
    }

    if(n > s) swap(n, s);
    if(w > e) swap(w, e);

    if(n == 0 && s != 0 || w == 0 && e != 0) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    h, w = read_int(2)
    a = []
    for y in range(h):
        a.append(read_line(n=w))
    return a


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    mode = 10 ** 9 + 7
    wall_symbol = '#'

    h = len(a)
    w = len(a[0])

    ways_count_to_get = [[0 for x in range(w)] for y in range(h)]
    ways_count_to_get[0][0] = 1

    for y in range(h):
        for x in range(w):
            if x == 0 and y == 0:
                continue
            if x == 0:
                if a[y][x] == wall_symbol:
                    continue
                else:
                    ways_count_to_get[y][x] = ways_count_to_get[y - 1][x]
                    continue
            if y == 0:
                if a[y][x] == wall_symbol:
                    continue
                else:
                    ways_count_to_get[y][x] = ways_count_to_get[y][x - 1]
                    continue
            if a[y][x] == wall_symbol:
                ways_count_to_get[y][x] = 0
            else:
                ways_count_to_get[y][x] = (ways_count_to_get[y - 1][x] + ways_count_to_get[y][x - 1]) % mode

    return ways_count_to_get[h - 1][w - 1]


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 53980
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int comp(string a,string b){
	if(a.size()>b.size())return 1;
	else if(b.size()>a.size())return -1;
	else{
		rep(i,a.size()){
			if(a[i]>b[i])return 1;
			else if(a[i]<b[i])return -1;
		}
		return 0;
	}
}

int main(){
	string a,b;
	cin>>a>>b;
	if(comp(a,b)>0)cout<<"GREATER"<<endl;
	else if(comp(a,b)<0)cout<<"LESS"<<endl;
	else cout<<"EQUAL"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] Hs = new int[N];

        for (int i=0; i<N; i++) {
            Hs[i] = sc.nextInt();
        }

        int max = Hs[0];
        int result = 1;

        for (int i=1; i<N; i++) {
            if (Hs[i] >= max) {
                result++;
            }
            max = Hs[i] > max ? Hs[i] : max;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > Pi;
const int INF = (1 << 30) - 1;
const ll LLINF = 1LL << 60;

int main()
{
    ll K;
    ll A[100005];
    ll low = 2, high = 2;
    bool flag = true;
    cin >> K;
    for(int i = 0; i < K; i++) {
        cin >> A[i];
    }
     
    for(int i = K - 1; i >= 0; i--) {
        if((high / A[i]) - ((low - 1) / A[i]) <= 0) {
            flag = false;
        } else {
            low = (low + A[i] - 1) / A[i] * A[i];  
            high = high / A[i] * A[i] + A[i] - 1;
            if(low > high) flag = false;
        }
    }
    if(flag) cout << low << " " << high << endl;
    else cout << -1 << endl;
    return (0);
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
	int num[100]={0};
	int a[100]={0};
	int temp,i,max;

	while( scanf("%d", &temp) != EOF)
		num[temp-1]++;
	
	for(i=0; i<100;i++) a[i]=num[i];
	
	max=num[0];
	for(i=1; i<100;i++) 
		if(num[i]>max) max=num[i];

	for(i=0; i<100;i++)
		if(a[i]==max) printf("%d\n", i+1);

	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    ll x, y;
    cin >> x >> y;
    if((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll timer = (x + y) / 3;
    x -= timer;
    y -= timer;
    if(x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << combination(x + y, x) << endl;
    return 0;
}


Measured memory_bytes: 234624
// Author : Nachiket Kanore
// Institute : PICT, Pune

/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */

#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <memory>
#include <random>
#include <cmath>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
 
 
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
const int mod = 1e9+7;
const int inf = 1e18;
const int N = 2e5+20;


int32_t main(){
    FAST;

    precise(10);
    double ans = 0;
    test{
        double val; cin >> val;
        string s;   cin >> s;
        if(s == "JPY") ans += val;
        else {
            double v = (double)(380000) * (double)val;
            ans += v;
        }
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

class UnionFind {
    public:
        vector<int> rank, p, size;

        UnionFind() {}
        UnionFind(int s) {
            rank.resize(s, 0);
            p.resize(s, 0);
            size.resize(s, 0);
            rep (i, s) init(i);
        }

        void init(int x) {
            p[x] = x;
            rank[x] = 0;
            size[x] = 1;
        }

        bool isSame(int x, int y) {
            return root(x) == root(y);
        }

        void unite(int x, int y) {
            if (isSame(x, y)) return;
            link(root(x), root(y));
        }

        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
                size[x] += size[y];
            } else {
                p[x] = y;
                size[y] += size[x];
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }

        int root(int x) {
            if (x != p[x]) {
                p[x] = root(p[x]);
            }
            return p[x];
        }

        int getSize(int x) {
            return size[root(x)];
        }
};

struct edge {
    int source, target, cost;
    edge(int source = 0, int target = 0, int cost = 0): source(source), target(target), cost(cost) {}
    bool operator < (const edge &e) const {
        return cost < e.cost;
    } 
};

int kruskal(int N, vector<edge> edges) {
    int totalCost = 0;
    sort(edges.begin(), edges.end());

    UnionFind uf = UnionFind(N + 1);
    rep (i, N) uf.init(i);

    int source, target;
    rep (i, edges.size()) {
        edge e = edges[i];
        if (!uf.isSame(e.source, e.target)) {
            totalCost += e.cost;
            uf.unite(e.source, e.target);
        }
    }

    return totalCost;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<tuple<int, int, int> > s, t;
    rep (i, n) {
        int x, y;
        cin >> x >> y;
        s.emplace_back(x, y, i);
        t.emplace_back(y, x, i);
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    vector<edge> v;
    FOR (i, 1, n) {
        int x1, x2, y1, y2;
        x1 = get<0>(s[i - 1]), y1 = get<1>(s[i - 1]);
        x2 = get<0>(s[i]), y2 = get<1>(s[i]);
        edge e;
        e.source = get<2>(s[i - 1]), e.target = get<2>(s[i]);
        e.cost = min(abs(x1 - x2), abs(y1 - y2));
        v.push_back(e);
    }
    FOR (i, 1, n) {
        int x1, x2, y1, y2;
        x1 = get<0>(t[i - 1]), y1 = get<1>(t[i - 1]);
        x2 = get<0>(t[i]), y2 = get<1>(t[i]);
        edge e;
        e.source = get<2>(t[i - 1]), e.target = get<2>(t[i]);
        e.cost = min(abs(x1 - x2), abs(y1 - y2));
        v.push_back(e);
    }
    cout << kruskal(n, v) << endl;

    return 0;
}



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

int main() {
  int A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
  int min = 100, ans = 0;
  ans += A; if (A < min) min = A;
  ans += B; if (B < min) min = B;
  ans += C; if (C < min) min = C;
  ans += D; if (D < min) min = D;
  ans -= min; min = 100;
  ans += E; if (E < min) min = E;
  ans += F; if (F < min) min = F;
  ans -= min;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3080
import time
t0 =time.time()
D=int(input())
c = list(map(int,input().split()))

s=[None]*D
for i in range(D):
    s[i] = list(map(int,input().split()))

def maxarg(l):
    nl=len(l)
    ma=-10**20
    idx=-1
    for i in range(nl):
        if l[i]>ma:
            ma=l[i]
            idx=i
    return (idx,ma)

last=[0]*26
t_greed = []
for j,ss in enumerate(s):
    
    cand = [ss[i]+c[i]*(j+1-last[i]) for i in range(26)]
    idx,val = maxarg(cand)
    last[idx]=j+1
    t_greed.append(idx+1)

sumc=sum(c)
def calc_score(t):
    last=[0]*26
    satis=0
    pena=0
    delta_pena=0
    for j in range(D):
        ss=s[j]
        tt=t[j]
        satis += ss[tt-1]
        delta_pena += sumc - c[tt-1]*(j+1-last[tt-1])
        last[tt-1]=j+1   
        pena += delta_pena
    return satis-pena

import random
t_old=t_greed[:]
while True:
    if time.time()-t0>=1.8:
        break
    d = random.randrange(D+1)
    q = random.randrange(26)
    
    t_new = t_old[:]
    t_new[d-1] = q+1
    if calc_score(t_new)>calc_score(t_old):
        t_old=t_new[:]
        
for tt in t_old:
    print(tt)
    

Measured memory_bytes: 81392