akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=998244353, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;


vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

ll M = 1000000;
vector<ll> inv(M+10);
void cominit(){
    inv[1]=1LL;
    for(int i=2;i<=M;i++) inv[i]=mod-inv[mod%i]*(mod/i)%mod;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    set<ll> P;
    sieve(M+10);
    for(ll i=0;i<=M;i++) if(IsPrime[i]) P.insert(i);
    ll n; cin >> n;
    vector<ll> a(n);
    vector<long long> f(M+1, 0), w(M+1, 0);
    for (int i=0;i<n;i++) {
        cin >> a[i];
        f[a[i]] += a[i];
    }
    for(auto& p:P) for(int i=M/p;i>0;i--) f[i] += f[i*p];
    for(int i = 1; i <= M; i++){
        w[i] = inv[i];
        f[i] %= mod;
        (f[i] *= f[i]) %= mod;
    }
    for(auto &p: P){
        for(int i=M/p;i>0;i--){
            w[i*p] -= w[i];
            if(w[i*p] < 0) w[i*p] += mod;
        }
    }
    ll ans = 0;
    for (int i=0;i<=M;i++) (ans += w[i] * f[i] % mod) %= mod;
    for (int i=0;i<n;i++) (ans -= a[i]) %= mod;
    cout << (ans * inv[2] % mod + mod) % mod << endl;
    return 0;
}




Measured memory_bytes: 29056
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    string s, res;
    for(;n--;){
      cin >> s;
      res = s.substr(0, 1);
      int now = 0;
      for(i = 2;i < s.size();i += 3){
        if(now == res.size() - 1 && s[i] == '>'){
          res = res + s.substr(i + 1, 1);
          ++now;
        }else if(now == 0 && s[i - 1] == '<'){
          res = s.substr(i + 1, 1) + res;
        }else{
          if(s[i] == '>')++now;
          else --now;
        }
      }
      pri(res);

      s.clear();
      res.clear();
    }


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,f=0;
	cin>>n>>m;
	vector<int>v[n+3];
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
	}
	for(int i=0;i<v[1].size();i++)
	{
		int x=v[1][i];
		if(find(v[x].begin(),v[x].end(),n)!=v[x].end())
		{
			f=1;
			break;
		}
	}
	if(f)
	cout<<"POSSIBLE"<<endl;
	else
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    string S;
    cin >> S;
    int c = 0;
    FOR(i, 0, S.size())
    c += S[i] == 'o';
    YES(c + 15 - S.size() >= 8);
}

Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let h: usize = sc.read();
    let w: usize = sc.read();

    if h == 1 || w == 1 {
        println!("1");
    } else {
        println!("{}", (h * w + 1) / 2);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){ 
     cout << "Yes" << endl; 
    }
    else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]){ 
     cout << "Yes" << endl; 
    }
    else if(s[0] == s[3] && s[1] == s[2] && s[0] != s[1]){ 
     cout << "Yes" << endl; 
    }
    else  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
using ull = unsigned long long;
ull A, B, score;

ull Parabola(ull from, ull to, ull sum){
    if(to < sum>>1) return to*(sum - to);
    if(from > sum+1>>1) return from*(sum - from);
    return (sum>>1)*(sum+1>>1);
}

bool Appropriate(ull X){
    if(X < B){
        return Parabola(1, A - 1, X + 1) < score && Parabola(1, X + 1 - A, X + 2) < score;
    }
    return Parabola(1, X + 1 - A, X + 2) < score && Parabola(X + 2 - A, B - 1, X + 1) < score;
}

int main(){
    unsigned Q;
    scanf("%u", &Q);
    for (unsigned i = 0; i < Q; i++)
    {
        scanf("%llu %llu", &A, &B);
        if(A == B){
            printf("%llu\n", A - 1 << 1);
            continue;
        }
        score = A*B;
        if(A*B == 2){
            printf("0\n");
            continue;
        }
        ull tmp = A;
        A = min(A, B);
        B = max(tmp, B);
        ull ok = A, ng = A + B - 2, mid;
        while(ng - ok > 1){
            mid = ok + ng >> 1;
            if(Appropriate(mid)) ok = mid;
            else ng = mid;
        }
        printf("%llu\n", ok);
    }
	return 0;
}

Measured memory_bytes: 1720
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        FastScanner sc = new FastScanner(Console.OpenStandardInput());
        int N = 3;
        int[] A = sc.intArray(N);
        Console.WriteLine(22 <= A.Sum() ? "bust" : "win");
        return;
    }
}

// FastScanner start
public class FastScanner
{
    public readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public FastScanner(Stream stream)
    {
        str = stream;
    }
    private T[] enumerate<T>(int n, Func<T> f)
    {
        var a = new T[n];
        for (int i = 0; i < n; ++i) a[i] = f();
        return a;
    }
    public char nextChar()
    {
        byte b = 0;
        do
        {
            b = read();
        }
        while ((b < 33 || 126 < b) && !isEof);
        return (char)b;
    }
    public int nextInt()
    {
        return (isEof) ? int.MinValue : (int)nextLong();
    }
    public long nextLong()
    {
        if (isEof)
        {
            return long.MinValue;
        }
        long ret = 0;
        byte b = 0;
        var ng = false;
        do
        {
            b = read();
        }
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-')
        {
            ng = true;
            b = read();
        }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
            {
                return ng ? -ret : ret;
            }
            else ret = ret * 10 + b - '0';
        }
    }
    public int[] intArray(int n)
    {
        return enumerate(n, nextInt);
    }
    public long[] longArray(int n)
    {
        return enumerate(n, nextLong);
    }
    public char[] charArray(int n)
    {
        return enumerate(n, nextChar);
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = nextChar(); b >= 33 && b <= 126; b = (char)read())
        {
            sb.Append(b);
        }
        return sb.ToString();
    }
    private byte read()
    {
        if (isEof)
        {
            return 0;
        }
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
}
// FastScanner end

Measured memory_bytes: 26092
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int cf(int a){
	int t;
	while(a!=0){ t+=a%10;
		a/=10;
	}
	return t;
}
int main(){
	long long n;
	cin >>n;
	int t=cf(n);
	if (n%t==0)	cout <<"Yes";
		else cout <<"No";
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] sArray = sc.next().toCharArray();
		int answer = 1;

		for(int i = 1; i < n; i++) {
			if(sArray[i] == sArray[i-1]) {
				continue;
			}else {
				answer++;
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 26964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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 (b<a) { a=b; return 1; } return 0; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    int sr, sc;
    cin >> sr >> sc;
    sr--, sc--;
    string s, t;
    cin >> s >> t;
    bool ok = false;
    {
        int now = sc;
        rep(i, n) {
            if(s[i] == 'R') now++;
            if(now >= w) ok = true;
            if(t[i] == 'L') now = max(0, now-1);
        }
    }
    {
        int now = sc;
        rep(i, n) {
            if(s[i] == 'L') now--;
            if(now < 0) ok = true;
            if(t[i] == 'R') now = min(w-1, now+1);  
        }
    }
    {
        int now = sr;
        rep(i, n) {
            if(s[i] == 'U') now--;
            if(now < 0) ok = true;
            if(t[i] == 'D') now = min(h-1, now+1);  
        }
    }
    {
        int now = sr;
        rep(i, n) {
            if(s[i] == 'D') now++;
            if(now >= h) ok = true;
            if(t[i] == 'U') now = max(now-1, 0);  
        }
    }
    if(ok) NO();
    else YES();
}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------
int main(void) {
  int x;
  cin >> x;
  prt(x*x*x);
}



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

using namespace std;

template <typename T>
struct Edge {
    int rev, from, to;
    T cap, icap;
    Edge(int rev, int from, int to, T cap)
        : rev(rev), from(from), to(to), cap(cap), icap(cap) {}
};

template <typename T>
struct Graph {
    vector<vector<Edge<T>>> list;
    Graph(int n = 0) : list(n) {}
    void init(int n = 0) {
        list.clear();
        list.resize(n);
    }
    inline vector<Edge<T>> &operator[](int i) { return list[i]; }
    inline const size_t size() const { return list.size(); }
    inline Edge<T> &redge(Edge<T> e) {
        if (e.from != e.to) return list[e.to][e.rev];
        else return list[e.to][e.rev + 1];
    }

    void addEdge(int from, int to, T cap) {
        list[from].push_back(Edge<T>((int)list[to].size(), from, to, cap));
        list[to].push_back(Edge<T>((int)list[from].size() - 1, to, from, 0));
    }
};

template <typename T>
struct Dinic {
    const T INF = 1 << 30;
    vector<int> level, iter;

    Dinic() {}
    void bfs(Graph<T> &graph, int s) {
        level.assign((int)graph.size(), -1);
        level[s] = 0;
        queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int i = 0; i < graph[v].size(); i++) {
                Edge<T> &e = graph[v][i];
                if (level[e.to] < 0 && e.cap > 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    T dfs(Graph<T> &graph, int v, int t, T f) {
        if (v == t) return f;
        for (int &i = iter[v]; i < graph[v].size(); i++) {
            Edge<T> &e = graph[v][i], &re = graph.redge(e);
            if (level[v] < level[e.to] && e.cap > 0) {
                T d = dfs(graph, e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    re.cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    T solve(Graph<T> &graph, int s, int t) {
        level.assign((int)graph.size(), -1);
        iter.assign((int)graph.size(), 0);
        T res = 0;
        for (;;) {
            bfs(graph, s);
            if (level[t] < 0) return res;
            for (int i = 0; i < (int)iter.size(); i++) iter[i] = 0;
            T flow = 0;
            while ((flow = dfs(graph, s, t, INF)) > 0) {
                res += flow;
            }
        }
    }
};

int main() {
    int V, E;
    cin >> V >> E;
    Graph<int> graph(V);
    for (int i = 0; i < E; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        graph.addEdge(u, v, c);
    }
    Dinic<int> dinic;
    int s = 0, t = V - 1;
    cout << dinic.solve(graph, s, t) << endl;
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N, K;
  cin >> N >> K;
  vector<vector<int>> data(N,vector<int>(2));
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;    
    data.at(i)={a, b};
  }
  stable_sort(data.begin(), data.end(), [](auto& x,auto& y){return x[0]<y[0];});
  int ans=0;
  for(int i=0; i<N; i++){
    K-=data.at(i).at(1);
    if(K<=0){
      ans= data.at(i).at(0);
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int B[N];
  for (int i = 0; i < N; i++)
    B[i] = A[i] - (i + 1);
  sort(B, B + N);
  int b = B[N / 2];
  long ans = 0;
  for (int i = 0; i < N; i++)
    ans += abs(B[i] - b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

int N, W;
int64_t w[101];
int64_t v[101];
int64_t dp[101][100001];

int64_t f(int i, int r) {
  if (i == N) return 0;
  if (dp[i][r] != -1) return dp[i][r];
  return dp[i][r] = (w[i] <= r
    ? std::max(v[i] + f(i+1, r - w[i]), f(i + 1, r))
    : f(i+1, r));
}

int main() {
  std::memset(dp, -1, sizeof(dp));
  std::cin >> N >> W;
  for (int i = 0; i < N; ++i) {
    std::cin >> w[i] >> v[i];
  }
  std::cout << f(0, W) << '\n';
}


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

using namespace std;

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

template<class T> T sqr(T x) {
  return x * x;
}

// int dp[(1<<15) + 10];

// map<pair<int, vector<int>> mp;

// int dfs(int now, vector<int> used) {
  // if (used.size() == 5) return 0;
  // if (now == 0) return 1;
  // if (mp.count(make_pair(now, used))) return dp[now];

  // int res = 0;
  // for (int x = 1; sqr(x) <= (1<<15); x++) {
    // REP(i,used.size()) if (used[i] == sqr(x)) continue;
    // vector<int> nused = used;
    // nused.push_back(sqr(x));
    // int next = now - sqr(x);
    // if (next >= 0) res += dfs(next, nused);
  // }

  // return (mp.insert(make_pair(make_pair(now, used), res)));
// }

int main() {
  int a;

  while (1) {
    scanf("%d", &a);
    if (a == 0) break;

    int mx = (1<<15);
    int res = 0;
    for (int i = 0; sqr(i) <= mx; i++) {
      if (a - sqr(i) < 0) continue;
      for (int j = i; sqr(j) <= mx; j++) {
        if (a - sqr(i) - sqr(j) < 0) continue;
        for (int k = j; sqr(k) <= mx; k++) {
          if (a - sqr(i) - sqr(j) - sqr(k) < 0) continue;
          for (int l = k; sqr(l) <= mx; l++) {
            if (a - sqr(i) - sqr(j) - sqr(k) - sqr(l) == 0) res++;
          }
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1204
import java.util.ArrayList;
import java.util.*;
public class Main {
  static Scanner sc = new Scanner(System.in);  
  static String i = sc.next();
  static long iga1 = sc.nextLong();
  
  
 public static void main(String[] args) {
  if(i.length() > iga1 ){
   String iti = i.substring(0,(int)iga1);
   String[] itibara = iti.split("");
   itiiti1(iga1,itibara);
   }else{
     String[] itibara = i.split("");
     itiiti1(iga1,itibara);
   }
 }
 static void itiiti1(long iga11,String[] itibara){
  if(iga11 > 1000000000){
    long count = 0L;
    for(long ii = 0;ii < iga11; ii++){
      if (itibara[(int)ii].equals("1")){
        count+=1;
      }else{
        System.out.println(itibara[(int)ii]);
        break;
      }
      if(count == iga11){
        System.out.println("1");
      }
    }  
      
  }else{
   long count = 0L;
   for(long ii = 0;ii < iga11; ii++){
     if (itibara[(int)ii].equals("1")){
       count+=1;
     }else{
       System.out.println(itibara[(int)ii]);
       break;
     }
   }
   if(count == iga11){
     System.out.println("1");
   }
  }
 }
}
 


Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;

        if((A+B)>=(A-B) &&(A+B)>=(A*B))
            cout<<(A+B);
        else if((A-B)>=(A+B) &&(A-B)>=(A*B))
            cout<<(A-B);
        else
            cout<<(A*B);

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> h(n);
	for( auto &k : h ) cin >> k;
	// reverse( h.begin(), h.end() );
	int m = h[0];
	int ans = 1;
	for( int i = 1; i < n; ++i ){
		if( m <= h[i] ){
			++ans;
			m = h[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000LL //2e18
#define SIZE 200010

/* Starry Sky Tree */
//0-index

struct StarrySkyTree{
  typedef ll Type;
  int segn2;
  vector<Type> data,s_data;
  
  StarrySkyTree(int n){
    for(segn2=1;segn2<n;segn2*=2);
    data.assign(segn2*2,0);
    s_data.assign(segn2*2,0);
  }
  
  //get minimum value of [a,b]
  Type query(int a,int b,int l=0,int r=-1,int k=0){
    if(r==-1) r+=segn2;
    if(r<a || b<l) return 2000000000000000LL;
    if(a<=l && r<=b) return data[k] + s_data[k];
    return min(query(a,b,l,(l+r)/2,k*2+1),query(a,b,(l+r)/2+1,r,k*2+2))+s_data[k];
  }
  
  //add x to [a,b]
  Type add(int a,int b,Type x,int l=0,int r=-1,int k=0){
    if(r==-1) r+=segn2;
    if(a<=l && r<=b){
      s_data[k]+=x;
    }else if(a<=r && l<=b){
      data[k] = min(add(a,b,x,l,(l+r)/2,k*2+1),add(a,b,x,(l+r)/2+1,r,k*2+2));
    }
    return data[k] + s_data[k];
  }
  
};

int main(){
  int n,q,a,b;
  int x;
  
  scanf("%d%d%d%d",&n,&q,&a,&b);
  a--; b--;

  StarrySkyTree seg1(n), seg2(n);
  
  seg1.add(0,n-1,LLINF);
  seg1.add(a,a,-LLINF-a);
  seg2.add(0,n-1,LLINF);
  seg2.add(a,a,-LLINF-(n-1-a));

  int lastx = b;
  
  for(int i=0;i<q;i++){
    scanf("%d",&x);
    x--;

    ll res = LLINF;

    res = min(res, seg1.query(0,x) + x);
    res = min(res, seg2.query(x,n-1) + (n-1 - x));
    
    seg1.add(0,n-1,abs(lastx-x));
    seg2.add(0,n-1,abs(lastx-x));

    ll q1 = seg1.query(lastx,lastx);
    ll q2 = seg2.query(lastx,lastx);

    if(q1 > res-lastx) seg1.add(lastx, lastx, (res-lastx) - q1);
    if(q2 > res-(n-1-lastx)) seg2.add(lastx, lastx, (res-(n-1-lastx)) - q2);
    
    lastx = x;
  }

  ll ans = LLINF;

  for(int i=0;i<n;i++){
    ans = min(ans, seg1.query(i,i) + i);
    ans = min(ans, seg2.query(i,i) + (n-1-i));
  }

  printf("%lld\n",ans);
  
  return 0;
}



Measured memory_bytes: 18688
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
v = nl()
c = nl()
ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]
print(ans)


Measured memory_bytes: 3444
from collections import defaultdict
N, A = map(int, input().split())

X = map(lambda s: int(s) - A, input().split())

counter = defaultdict(int)
counter[0] = 1

for x in X:
  for d,c in list(counter.items()):
    counter[d+x] += c

print(counter[0]-1)

Measured memory_bytes: 3572
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;

int main()
{
	int a, b, k,t;
	cin >> k >> a >> b;
	if (a % k == 0) cout << "OK";
	else {
		if (k * (a / k + 1) <= b) cout << "OK";
		else cout << "NG";
	}
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int dfsdp[100010];

bool judge(int const&X){
  int vec[22] = {100,101,102,103,104,105,201,203,205,207,209,301,302,304,305,307,311,516,517,518,519,615};
  bool Z=false;
  for(int i = 0;i<22;i++){
    Z |= X%vec[i]==0;
  }
  return Z;
}

bool dfs(int const& X){
  if(dfsdp[X]!=0) return dfsdp[X];
  else if(X==0){
    return dfsdp[X] = true;
  }
  else if (X <= 0)
  {
    return dfsdp[X] = false;
  }
  else if (judge(X))
  {
    return dfsdp[X] = true;
  }
  else
  {
    return dfsdp[X] = dfs(X-100) || dfs(X-101) || dfs(X-102) || dfs(X-103) || dfs(X-104) || dfs(X-105);
  }
}

int main(){
  int X;
  cin >> X;
  int m = X%100;
  int n = (X-m)/100;
  m = max(m-5*n,0);
  if(m==0){
    cout << 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int a, b, n, min;
	string s = "";
	
	cin >> a >> b;
	
	min = (a > b) ? b : a;
	n = a + b - min;
	
	while (n > 0) {
		s += to_string(min);
		n--;
	}
	
	cout << s << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int N_MAX=100001;
long long INF = 123456789123456789;
typedef pair<long long,int> P;
void dijkstra(int s, int V, vector<P>* g, long long* d){
  if(d[s]==0)
    return;
  int i,v;
  P p,e;
  priority_queue<P, vector<P>, greater<P>> que; // 最短距離，頂点番号
  fill(d,d+V,INF);
  d[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    p=que.top(); que.pop();
    v=p.second;
    if(d[v]<p.first) continue;
    for(i=0;i<g[v].size();i++){
      e=g[v][i];
      if(d[e.second]>d[v]+e.first){
        d[e.second]=d[v]+e.first;
        que.push(P(d[e.second],e.second));
      }
    }
  }
  return;
}
int main()
{
  int n,q,k,x,y,a,b,i;
  long long c;
  long long d[N_MAX];
  vector<P> g[N_MAX];
  cin >> n;
  fill(d+1,d+n+1,INF);
  for(i=0;i<n-1;i++){
    cin >> a >> b >> c;
    g[a].emplace_back(c,b);
    g[b].emplace_back(c,a);
  }
  cin >> q >> k;
  dijkstra(k,n,g,d);
  for(i=0;i<q;i++){
    cin >> x >> y;
    cout << d[x]+d[y] << endl;
  }
  return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
    
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'
#define N 10000002
#define MOD 1000000007

signed main() {
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '0' && i % 2 == 0) {
            cnt++;
        }
        if(s[i] == '1' && i % 2 == 1) {
            cnt++;
        }
    }
    cout << min(cnt, (int)s.size() - cnt) << endl;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define NIL -1

struct Node {
  int p, l, r;
};

Node T[26];

int getDepth(int u){
  int c = 0;
  while(T[u].p != NIL){
    u = T[u].p;
    c ++;
  }
  return c;
}

void printChildren(int u){
  int c = T[u].l;
  int cnt = 0;
  while(c != NIL){
    if ( cnt ){ cout << ", "; }
    cout << c;
    c = T[c].r;
    cnt ++;
  }
}

string getType(int u){
  if ( T[u].p == NIL){ return "root";}
  else if ( T[u].l == NIL && T[u].r == NIL){ return "leaf";}
  else {return "internal node";}
}

int getSlibling(int u){
  if ( T[u].p == NIL){return NIL;}
  if ( u == T[T[u].p].l){
    return T[T[u].p].r;
  } else {
    return T[T[u].p].l;
  }
}

int getDegree(int u){
  if ( T[u].l != NIL && T[u].r != NIL){return 2;}
  else if (T[u].l == NIL && T[u].r ==NIL){return 0;}
  else {return 1;}
}

int getHeight(int u){
  if ( u == NIL){return 0;}
  if ( T[u].l == NIL && T[u].r == NIL){return 0;}
  return max(getHeight(T[u].l), getHeight(T[u].r)) + 1;
}

int main(){
  int n, id, l, r;
  cin >> n;

  for ( int i = 0; i < n; i++){T[i].p = T[i].l = T[i].r = NIL;}

  for ( int i = 0; i < n; i++){
    cin >> id >> l >> r;
    T[id].l = l;
    T[id].r = r;
    if (l != NIL){T[l].p = id;}
    if (r != NIL){T[r].p = id;}
  }


  for ( int i = 0; i < n; i++){
    cout << "node " << i << ": parent = " << T[i].p << ", " << "sibling = " << getSlibling(i) << ", " << "degree = " << getDegree(i)  << ", depth = " << getDepth(i) << ", ";
    cout << "height = " << getHeight(i)  << ", "<< getType(i) << endl;
  }

  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int dp[3001][3001];
int lcs(string a,string b,int m,int n){
    if(m == 0 || n == 0) return 0;
    if(dp[m][n] != -1) return dp[m][n];
    if(a[m-1] == b[n-1]) return dp[m][n] = 1 + lcs(a,b,m-1,n-1);
    return dp[m][n] = max(lcs(a,b,m,n-1), lcs(a,b,m-1,n));
} 


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int m,n; 
    string a,b; 
    getline(cin,a); 
    getline(cin,b);
    m = a.length();
    n = b.length();
    for(int i = 0; i<=m; i++){
        for(int j = 0; j<=n; j++){
            dp[i][j] = -1;
        }
    }

    for (int i=0; i<=m; i++) { 
        for (int j=0; j<=n; j++) { 
            if (i == 0 || j == 0) 
                dp[i][j] = 0; 
            else if (a[i-1] == b[j-1]) 
                dp[i][j] = dp[i-1][j-1] + 1; 
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 
        } 
    } 

    int i = m,j=n;
    string ans ="";
    while(i > 0 && j > 0){
        if(a[i-1] == b[j-1]){
            ans += a[i-1];
            i--; j--;
        }
        else if(dp[i-1][j] > dp[i][j-1]) i--;
        else j--;

    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    
    return 0;

}

Measured memory_bytes: 38732
import sys
input = sys.stdin.readline

mod=1000000007
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
al=len(a)


f=0
for i in range(al-1):
    if a[i+1]==a[i]+1:
        f=1
        break
if f==1:
    print(0)
else:
    dp=[0]*(n+1)
    dp[0]=1
    if 1 in a:
        dp[1]=0
        a.pop(0)
        al-=1
    else:
        dp[1]=1
    
    for i in range(2,n+1):
        if al>0 and i==a[0]:
            dp[i]=0
            a.pop(0)
            al-=1
        else:
            dp[i]=(dp[i-1]+dp[i-2])%mod
    print(dp[n]%mod)
  

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

typedef long long ll;

int main()
{
	int n;
	ll a1 = 1, a2;
	bool zero = false;

	cin >> n;

	while (n--)
	{
		cin >> a2;

		if (a2 == 0)
			zero = true;

		if (a1 != -1)
		{
			if ((ll)1e18 / a2 < a1)
				a1 = -1;
			else
				a1 *= a2;
		}
	}

	if (zero)
		cout << 0;
	else if (a1 == -1)
		cout << -1;
	else
		cout << a1;
}

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

int n;
int a[100001];
int main(){
cin>>n;
int ans=0;
for(int i=0; i<n;i++){
cin>>a[i];
ans=(ans+a[i])%2;
}
if(ans) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return 0;
}

Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<queue>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;

string N;
ll K;
ll dp[110][5][2];

ll charNumberToLL(char c) {
    ll ret = c - '0';
    return ret;
}

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

    dp[0][0][0] = 1;

    for(int i=0; i<N.size(); i++){
        ll digit = charNumberToLL(N[i]);
        for(int j=0; j<=K; j++){
            for(int k=0; k<2; k++){
                for(int l=0; l<10; l++){
                    if(k == 0 && l > digit){
                        // Nを超えている。
                        continue;
                    }
                    if(l != 0){
                        // 0以外の数字を使用した。
                        if(l < digit || k == 1){
                            // Nを下回ることが確定。
                            dp[i+1][j+1][1] += dp[i][j][k];
                        } else {
                            // Nをこの時点で下回らない。
                            dp[i+1][j+1][0] += dp[i][j][k];
                        }
                    } else {
                        // 0を使用した。
                        if(l < digit || k == 1){
                            // Nを下回ることが確定。
                            dp[i+1][j][1] += dp[i][j][k];
                        } else {
                            // Nをこの時点で下回らない。
                            dp[i+1][j][0] += dp[i][j][k];
                        }
                    }

                }
            }
        }
    }

    cout << dp[N.size()][K][0] + dp[N.size()][K][1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    if(A+B<=2*C){
        cout << A*X+B*Y << endl;
        return 0;
    }
    ll a1=C*2*max(X,Y);
    int N=min(X,Y);
    ll a2=C*2*N+A*(X-N)+B*(Y-N);
    cout << min(a1,a2) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

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

    for (int i = 0; i < S.length()-8; i++) {
        cout << S[i];
    }
    cout << endl;

    return 0;
}

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

int main() {
	int n;
	cin >> n;
	ll x = 1;
	for (int i = 0; i < n; i++) {
		int y;
		cin >> y;
		if (y % 2 == 0)x *= 2;
	}
	cout << pow(3,n)-x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

struct UnionFind{
    vector<int> par;
    vector<ll> S;

    UnionFind(int N):par(N),S(N){
        rep(i,N){
          par[i] = i;
          S[i] = 1;
        }
    }

    int root(int x){
       while(x != par[x]){
        x =  par[x] = par[par[x]];
       }
       return x;
    }
    
    bool same(int x,int y){
      return root(x) == root(y);
    }

    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(!same(x,y)){
            S[root(x)] += S[root(y)];
            S[root(y)] = S[root(x)];
        }
        if(rx == ry)return;
        if(S[x] >= S[y]){
          par[ry] = rx;
        }else{
          par[rx] = ry;
        }
    }

    ll SIZE(int x){
        return S[root(x)];
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> L(100010);
    UnionFind UF(100010);
    rep(i,N){
        ll K;cin >> K;
        rep(j,K){
            ll l;cin >> l;
            L[l].push_back(i);
        }
    }
    rep(i,100010){
        rep(j,L[i].size()){
            UF.unite(L[i][0],L[i][j]);
        }
    }
    if(UF.SIZE(0) == N) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 5888
#include <iostream>

int main()
{
	char c;
	std::cin >> c;

	char out;
	if (c == 'A')
	{
		out = 'T';
	}
	else if (c == 'T')
	{
		out = 'A';
	}
	else if (c == 'C')
	{
		out = 'G';
	}
	else if (c == 'G')
	{
		out = 'C';
	}

	std::cout << out;

	return 0;
}

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

int main(void){
   int N,M;
   cin>>N>>M;
   vector<int> x(M),y(M);
   for(int i=0;i<M;i++){
      cin>>x[i]>>y[i];
      x[i]--;
      y[i]--;
   }
   vector<int> red(N,0);
   red[0]=1;
   vector<int> cnt(N,1);
   for(int i=0;i<M;i++){
      if(red[x[i]]==1){
         red[y[i]]=1;
      }
      cnt[x[i]]-=1;
      cnt[y[i]]+=1;
      if(cnt[x[i]]==0){
         red[x[i]]=0;
      }
   }
   int result=0;
   for(int i=0;i<N;i++){
      if(red[i]==1){
         result++;
      }
   }
   cout<<result<<endl;
   return 0;
}


Measured memory_bytes: 4768
import sys
N, x = map(int, sys.stdin.readline().rstrip().split())
aa = sorted(list(map(int, sys.stdin.readline().rstrip().split())))
cnt = 0
for a in aa:
    x -= a
    if x < 0: break
    cnt += 1
if x > 0:
    cnt -= 1
print(cnt)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
from collections import Counter
import itertools

mask = (1 << 10) - 1

def encode(a,b,c,d):
    t = 1 << 40
    for x,y,z,w in [(a,b,c,d), (b,c,d,a), (c,d,a,b), (d,a,b,c)]:
        u = x + (y << 10) + (z << 20) + (w << 30)
        if t > u:
            t = u
    return t

def decode(x):
    for _ in range(4):
        yield x & mask
        x >>= 10

def P(n,k):
    x = 1
    for i in range(k):
        x *= (n-i)
    return x

def symmetry(tile):
    a,b,c,d = decode(tile)
    if a == b == c == d:
        return 4
    if a == c and b == d:
        return 2
    return 1

N = int(input())
tiles = []
for _ in range(N):
    a,b,c,d = map(int,input().split())
    tiles.append(encode(a,b,c,d))
counter = Counter(tiles)

counter

answer = 0
for bottom, top in itertools.combinations(tiles,2):
    counter[bottom] -= 1
    counter[top] -= 1
    a,b,c,d = decode(bottom)
    e,f,g,h = decode(top)
    for x,y,z,w in [(e,f,g,h), (f,g,h,e), (g,h,e,f), (h,e,f,g)]:
        # a,b,c,d
        # x,w,z,y 
        tiles = [encode(p,q,r,s) for p,q,r,s in [(b,a,x,w), (c,b,w,z), (d,c,z,y), (a,d,y,x)]]
        need = Counter(tiles)
        x = 1
        for tile, cnt in need.items():
            x *= P(counter[tile],cnt) # 残っている個数、必要枚数
            x *= pow(symmetry(tile), cnt)
        answer += x
    counter[bottom] += 1
    counter[top] += 1

# 上下を固定した分
answer //= 3
print(answer)


Measured memory_bytes: 82776
#include<cstdio>
#include<algorithm>
#include<cstring>

#define val first
#define pos second
typedef std::pair<long long, int> Point;

const int maxn = 2005;

int n;
long long ans, f[maxn][maxn];
Point p[maxn];

int main() {
	memset(f, -0x3f, sizeof f);
	
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%lld", &p[i].val);
		p[i].pos = i;
	}
	
	sort(p + 1, p + n + 1);
	
	f[0][n + 1] = 0;
	for(int i = n; i >= 1; --i) {
		for(int l = 0; l <= n - i + 1; ++l) {
			int r = l + i;
			if(l >= 1) f[l][r] = std::max(f[l][r], f[l - 1][r] + std::abs(p[i].pos - l) * p[i].val);
			if(r <= n) f[l][r] = std::max(f[l][r], f[l][r + 1] + std::abs(p[i].pos - r) * p[i].val);
		}
	}
	
	for(int i = 0; i <= n; ++i)
		ans = std::max(ans, f[i][i + 1]);
	
	printf("%lld", ans);
}

Measured memory_bytes: 33172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define REP(i,a,b) \
for(int i=int(a);i<=int(b);i++)
#define DEP(i,a,b) \
for(int i=int(a);i>=int(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int T,i;
	cin>>T>>i;
  if(i>=T)
    cout<<"unsafe";
  else
    cout<<"safe";
	
	return 0;
}


Measured memory_bytes: 3688
function main(input) {
  var temp = input.split('\n');

  for (var i =0; i < temp.length; i++) {
    if(parseInt(temp[i]) == 0){
      break;
    }
    console.log("Case"+' '+(i+1)+": "+temp[i]);
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};


//-----------------------------------------------------------------------------


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

	int h,w;cin>>h>>w;
	string s[h];
	REP(i,h) cin>>s[i];
	REP(i,h) {
		REP(j,w) {
			if(s[i][j]=='#') {
				cout<<s[i][j];
				continue;
			}
			int cnt=0;
			REP(k,8) {
				int x=j+ddx[k],y=i+ddy[k];
				if(x<0||x>=w||y<0||y>=h||s[y][x]=='.') continue;
				cnt++;
			}
			cout<<cnt;
		}
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7


def main():
    N = int(input())
    D = defaultdict(int)
    for _ in range(N):
        S = input()
        D[S] += 1
    K = list(D.keys())
    V = list(D.values())
    M = max(V)
    L = []
    for k in K:
        if D[k] == M:
            L.append(k)
    L.sort()
    print(*L, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 37460
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A.at(i);
    }
    int count=0;
    while(true){
        bool a=false;
        rep(i,N){
            if(A.at(i)%2==1)a=true;
        }
        if(a){
            break;
        }
        else{
            rep(i,N){
                A.at(i)/=2;
            }
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vl a,x,y,p;

int main(){
	cin>>n;
	a=vl(n+1,INF);
	x=y=p=vl(n);
	for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>p[i];
	int N=1;
	for(int i=0;i<n;i++) N*=3;
	for(int i=0;i<N;i++){
		vi b(n);
		int t=i;
		for(int j=0;j<n;j++){
			b[j]=t%3;
			t/=3;
		}
		t=0;
		for(int j=0;j<n;j++) if(b[j]) t++;
		ll sum=0;
		for(int j=0;j<n;j++) if(!b[j]){
			ll tmp=min(abs(x[j]),abs(y[j]));
			for(int k=0;k<n;k++){
				if(b[k]==1) tmp=min(tmp,abs(x[j]-x[k]));
				if(b[k]==2) tmp=min(tmp,abs(y[j]-y[k]));
			}
			sum+=tmp*p[j];
			if(sum>=a[t]) break;
		}
		a[t]=min(a[t],sum);
	}
	for(auto i:a) cout<<i<<endl;
}

Measured memory_bytes: 3608