akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int table[21][21];
char e[2];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<21;i++)
			for(int j=0;j<21;j++)
				table[i][j]=0;
		for(int i=0;i<a;i++){
			int b,c;
			scanf("%d%d",&b,&c);
			table[b][c]=1;
		}
		int d;
		int x=10;
		int y=10;
		scanf("%d",&d);
		for(int i=0;i<d;i++){
			int f;
			scanf("%s%d",e,&f);
			if(e[0]=='N')
				for(int j=0;j<f;j++)
					table[x][++y]=0;
			if(e[0]=='S')
				for(int j=0;j<f;j++)
					table[x][--y]=0;
			if(e[0]=='E')
				for(int j=0;j<f;j++)
					table[++x][y]=0;
			if(e[0]=='W')
				for(int j=0;j<f;j++)
					table[x--][y]=0;
			table[x][y]=0;
		}
		bool ok=true;
		for(int i=0;i<=20;i++)
			for(int j=0;j<21;j++)
				if(table[i][j])ok=false;
		printf(ok?"Yes\n":"No\n");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
//ask the right questions.		

int32_t main() 
{
	int N, W;
	cin >> N >>W;
	int weights[N];
	int value[N];

	int x;
	for(int i=0;i<2*N;i++)
	{
		cin >> x;
		if(i%2==0)
		{
			weights[i/2]=x;
		}
		else
		{
			value[(i-1)/2]=x;
		}
	}

	//let denote the max value when you have capacity_left of w and deciding upon nth item.
	int dp[W+1];

	for(int i=0;i<=W;i++)
		dp[i]=0;


	//TIP:
	//you are deciding on the ith item: to take or not
	//if you want to take then you look previously for a state with wight gap of at least 
	//weight[i-1] (ie weight of ith item)
	//you need not look for a greater gap as the max value obtained by a state with greater
	//weight capacity will always be equal or greater than max value obtained by a lower weight capacity state.


	// shift i-1 in weights and values
	for(int i=1; i<=N; i++)
	{
		for(int j=W; j>=weights[i-1]; j--)
		{				
			dp[j] = max(dp[ j-weights[i-1] ] + value[i-1], dp[j]);
			
		}		
	}

	cout << dp[W] <<endl;

	return 0;
	
}

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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

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

    int count = 0;

    if(n==1)
    {
        cout<<1<<endl;
        return 0;
    }

    for (int i = 1; i < n; ++i)
    {
        if(s[i]!=s[i-1])
            count++;
    }
    cout<<count+1<<endl;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

ll a, b, c;

bool read() {
    if (!(cin >> a >> b >> c))
        return false;

    return true;
}

void solve() {
    cout << min(c - 1, a + b) + 1 + b << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
 string S;
 cin >> S;
 int sum = 1;
 for (int i = 0; i < S.size() - 1; i++) {
    if (S.at(i) != S.at(i + 1)) {
        sum += 1;
    }
    else if (i == S.size() - 2) {
        break;
    }
    else if (i == S.size() - 3) {
        sum += 1;
        break;
    }
    else if (i == S.size() - 4) {
        sum += 2;
        break;
    }
    else {
        sum += 2;
        i += 2;
    }
 }
 cout << sum << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9
#define common cout << "Case #" << wi+1 << ": "  


int main()
{
    int n,x,t;
    cin >> n >> x >> t;
    int ans=(n/x)*t;
    if(n%x!=0)
        ans+=t;
    cout << ans << endl;
}

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

int main() {
    ll n, t;
    cin >> n >> t;
    ll a[n];
    for(int i=0; i<n; i++) cin >> a[i];

    ll cnt=0;
    for(int i=0; i<n-1; i++) {
        if(a[i+1]-a[i]<t) cnt+=a[i+1]-a[i];
        else cnt+=t;
    }
    cout << cnt+t << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;

namespace _99
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            int ans = -1;
            if(a < 10 && b < 10) ans = a * b;
            
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll INF = 1e18L+5;
vector<ll>dp;
vector<ll>pre;// preprocessing to find the score of a particular group.
// pre[mask]- score of group 'mask';

void rec(int i, const vector<int>&not_selected, ll sum_of_money, int mask, int group){
    if(i == (int) not_selected.size()){
        dp[mask] = max(dp[mask], sum_of_money+pre[group]);
        return;
    }
    // first case when a particular rabbit is not selected.
    rec(i+1, not_selected, sum_of_money, mask, group);
    // second case when a particular rabbit is selected.
    rec(i+1, not_selected, sum_of_money, mask^(1<<not_selected[i]), group^(1<<not_selected[i]));
}

int main(){
    int n;
    cin >> n;
    vector<vector<ll>>a(n, vector<ll>(n));
    for(int i=0; i<n;i++){
        for(int j=0; j<n; j++){
            cin >> a[i][j];
        }
    }
    // now preparing the possible groups according to the mask in which the rabbits
    // can be there ans the possible group have a sum which is us in the recursive function
    // in order to calculate the sum of money so far if the rabbit is in a
    // particular group.

    pre.resize(1<<n);
    for(int mask =0; mask<(1<<n);mask++){
        for(int i=0; i<n; i++){
            if(mask & (1<<i)){
                // this means the rabbit belong to the group having mask = 'mask'
                for(int j=i+1; j<n; j++){
                    // now for the rabbit i we are itterating over the other rabbits
                    // so they can also be in the group as the ith rabbit.
                    if(mask & (1<<j)){
                        // now if the jth rabbit also belongs to the same mask the sum of the score
                        // so far is equal to the sum of the rabbits compatibility.
                        pre[mask] += a[i][j];
                    }
                }
            }
        }
    }

    // making a list of the rabbits which is not selected.
    // mask represent the rabbit selected.
    dp.resize(1<<n, -1000000000);
    dp[0] = 0;
    // dp[mask] - best total score if we grouped from 'mask' already.
    for(int mask=0; mask<(1<<n); mask++){
        // selecting the rabbits for the mask which are not selected and then.
        // iterating over teh non selected rabbits. (recursively).
        vector<int>not_selected;
        for(int i=0; i<n; i++){
            if(!(mask&(1<<i))){
                not_selected.push_back(i);
            }
        }
        // calling recursive function here so that we know for a mask of "mask"
        // which all rabbits are not selected.
        rec(0, not_selected, dp[mask],mask, 0);
    }

    cout << dp[(1<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int n,m,i,x,y,z;
        int arr[5];
        int cnt=0;
        for(i=0;i<5;i++)
        {
            cin>>arr[i];
            if(arr[i]==0)
                cnt=i+1;
        }
    cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
def DFS(v):
  if(already[v]==0):
    already[v]=1
    for i in range(n):
      if(con[v][i]==1):
        if(already[i]==0):
          DFS(i)


n,m=map(int,input().split())
INF=10**15
a=[-1for i in range(m)]
b=[-1for i in range(m)]
count=0
for i in range(m):
  a[i],b[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
for i in range(m):
  con=[[0 for n in range(n)]for j in range(n)]
  for j in range(n):con[j][j]=1
  already=[0 for i in range(n)]
  for j in range(m):
    if(i!=j):
      con[a[j]][b[j]]=1
      con[b[j]][a[j]]=1

  DFS(0)
  if(0 in already):count+=1
print(count)

Measured memory_bytes: 3064
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int) 1e5 + 5;
const int mod = (int) 1e9 + 7;

inline void add (int &a, int b) {
        a += b;
        if (a >= mod) {
                a -= mod;
        }
}

int n, dp[2][N], l[N], p = 1;
ll a[N], A, B;

inline void solve () {
        scanf ("%d%lld%lld", &n, &A, &B);
        if (A > B) {
                swap (A, B);
        }
        for (int i = 1; i <= n; i++) {
                scanf ("%lld", &a[i]);
                if (i > 1 && a[i] - a[i - 1] >= A) {
                        l[i] = l[i - 1];
                } else {
                        l[i] = i;
                }
        }
        dp[0][1] = dp[1][1] = 1;
        for (int i = 2; i <= n; i++) {
                if (a[i] - a[i - 1] >= A) {
                        add (dp[0][i], dp[0][i - 1]); add (dp[0][i], dp[1][i - 1]);
                } else if (i > 2 && a[i] - a[i - 2] < A) {
                        puts ("0"); exit (0);
                } else {
                        add (dp[0][i], dp[1][i - 1]);
                }
                while (a[i] - a[p] >= B) {
                        p++;
                }
                if (p == i) {
                        add (dp[1][i], dp[0][i - 1]); add (dp[1][i], dp[1][i - 1]);
                } else if (p >= l[i - 1]) {
                        add (dp[1][i], dp[0][p]);
                }
//                printf ("%d %d %d\n", i, dp[0][i], dp[1][i]);
        }
        int ans = 0; add (ans, dp[1][n]); add (ans, dp[0][n]);
        printf ("%d\n", ans);
}

int tests = 1;

int main () {
//        freopen (".in", "r", stdin);
//        freopen (".out", "w", stdout);
//        scanf ("%d", &tests);
        while (tests--) {
                solve ();
        }
        return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<char>s;
  string c;
  cin >> c;
  for(int i = 0;i < c.size();i++){
    if(c[i] == 'B'){
      if(!s.empty()){
	s.pop_back();
      }
    }else{
      s.push_back(c[i]);
    }
  }
  for(int i = 0;i < s.size();i++){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

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

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

int main(void){
    ll A; cin >> A;
    ll B; cin >> B;
    cout << lcm(A,B) << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}


struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

bool sortbysec(const pair <ll,ll> &a, const pair <ll,ll> &b){
    return a.first-a.second<b.first-b.second;
}


int main(){
    IOS;
    make2(string,s1,s2);
    ll ans=0;
    fr(i,s1.length()){
        if(s1[i]!=s2[i]) ans++;
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 3804
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

std::multiset<int> list;

int main(){
  int N, A, B;
  scanf("%d %d %d", &N, &A, &B);
  for(int i = 0; i < N; i++) {
    int tmp;
    scanf("%d", &tmp);
    list.insert(tmp);
  }
  int cnta = 0, cntb = 0, cntc = 0;
  auto it = list.begin();
  while(it != list.end() && *it <= A){
    cnta++;
    it++;
  }
  while(it != list.end() && *it <= B){
    cntb++;
    it++;
  }
  while(it != list.end()){
    cntc++;
    it++;
  }
  printf("%ld\n", std::min(cnta, std::min(cntb, cntc)));
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

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);
    }
}
#pragma endregion

int main()
{
    int s, w;
    cin >> s >> w;
    string ans = s > w ? "safe" : "unsafe";

    cout << ans << endl;

    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    string S; cin >> S;
    i64 N = S.length();

    vector<vector<i64>> C(26, vector<i64>(N + 1, 0));
    REP(i, N) {
        i64 ci = S[i] - 'a';
        REP(j, 26) {
            if (j == ci) C[j][i + 1] = C[j][i] + 1;
            else C[j][i + 1] = C[j][i];
        }
    }

    vector<map<i64, i64>> mps(26);
    REP(r, N) {
        REP(i, 26) {
            auto it = mps[i].upper_bound((r + 1) - 2 * C[i][r + 1]);
            if (it == mps[i].end()) {
                mps[i][r - 2 * C[i][r]] = r;
                continue;
            }
            i64 l = it->second;
            cout << (l + 1) << " " << (r + 1) << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;

    return 0;
}

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

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

  if (n % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  ll num = 10;
  while (num <= n) {
    ans += n / num;
    num *= 5;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 105
using namespace std;

typedef long long ll;
ll n, mx, a[N], v[N];

void f(ll p, ll q) {
	int i, t[N];
	if (p > n) {mx = max(mx, q); return;}
	f(p + 1, q + a[p]);
	if (a[p] < 0) {
		for (i = p; i <= n; i += p) t[i] = a[i], a[i] = 0;
		f(p + 1, q);
		for (i = p; i <= n; i += p) a[i] = t[i];
	}
}

int main()
{
	ll i;
	cin >> n;
	for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for (i = n / 2 + 1; i <= n; i++) a[i] = max(0LL, a[i]);
	f(1, 0);
    cout << mx << endl;
    return 0;
}

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

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

 
int main()
{
    int a,b;
//    long long int Y, Ytemp;
//    int i,j;
//    int N_cnt=0;
//    int en10=0;
//    int en5=0;
//    int en1=0;
  
 // 整数の入力
    scanf("%d %d", &a, &b);
 // printf("%d\n",N);

    
  
/*    for(i=0;i<N;i++){
    Y= Ytemp - (10000 * i);
    N = Ntemp -i;
    en10 = i;
      for(j=0;j<(N-i);j++){
        
      
      }
        else{
          break;
        }
    }
  

    printf("%d %d %d %d %d\n",en10, en5, en1, N, Y);
    if(0!=Y){
      en10 = -1;
      en5 = -1;
      en1 = -1;
    }
*/  
    if(0 == ((a*b) % 2))    
    printf("Even\n");
    else 
    printf("Odd\n");
    return 0;
}


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

int main(){
  int r,c;

  cin >> r >> c;

  int *a = new int[r*c + r];

  for(int i = 0; i<r*c; ++i){
    cin >> a[i];
  }

  int sum = 0;
  for(int i=0; i<r; ++i){
    for(int l=0; l<c; ++l){
      cout << a[c*i + l] << " ";
      sum += a[c*i + l];
    }
    a[c*r + i] = sum;
    cout << sum << endl;
    sum = 0;
  }

  for(int i=0; i<c; ++i){
    for(int l=0; l<r; ++l){
      sum += a[i + l*c];
    }
    
    cout << sum << " ";
    sum = 0;
  }

  for(int i=0; i<r; ++i){
    sum += a[c*r + i];
  }

  cout << sum << endl;

  delete[] a;
}



Measured memory_bytes: 3140
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

vector<int> nums;

int main() {
    int N;
    cin >> N;
    
    int total = N, four=0, two=0;
    rep(i,N){
        int v;
        cin >> v;
        if(v%4==0) four++;
        else if(v%2==0) two++;
    }
    
    string ans;
    if(total/2<=four) ans="Yes";
    else if(two>1 && (total-two+1)/2<=four) ans="Yes";
    else ans="No";
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int a[2020];
int main(){
	int n,m;
	cin>>n>>m;
	ll sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]*4*m>=sum) cnt++;
		if(cnt==m){
			cout<<"Yes"<<endl;
			break;
		}
	}
	if(cnt<m) cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
class MainClass{
  public static void Main(string[] args){
    long n = 0;
    long N = 0;
    long cnt = 0;
    string s = Console.ReadLine();
    N = long.Parse(s);
    cnt = s.Length;
    for (int i = 0; i < cnt; i++){
      n += long.Parse(s.Substring(i, 1));
    }
    if ((N % n) == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }
  }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m=sc.nextInt();
		int x=sc.nextInt();
		int sumRight=0;
		int sumLeft=0;
		int[] marr = new int[101];
		for(int i=0;i<m;i++) {
			marr[sc.nextInt()]=1;
		}
		for(int i=x;i<n;i++) {
			sumRight+=marr[i];
}
		for(int i=x;i>=0;i--) {
			sumLeft+=marr[i];
		}
		
		if(sumRight>sumLeft) System.out.println(sumLeft);
		else System.out.println(sumRight);
	}
}


Measured memory_bytes: 22996
// 

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for (int i=(a);i>(b);i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define caset int ___T; cin >> ___T; while(___T--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define get1(a) ll int a; cin>>a;
#define get2(a,b) ll int a,b; cin>>a>>b;
#define get3(a,b,c) ll int a,b,c; cin>>a>>b>>c;
#define gets(s) string s; cin >> s;

#define fast_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

int main() {
	fast_IO;

	int n;
	cin >> n;

	if (n%1000) {
		cout << 1000 - n%1000 << endl;
	} else {
		cout << 0 << endl;
	}

	cout << flush;
}



Measured memory_bytes: 3568
#include <iostream>
#include <map>
#include <algorithm>

#ifdef _MSC_VER
using LL = __int64;
using ULL = unsigned __int64;
#else
using LL = long long int;
using ULL = unsigned long long int;
#endif

using namespace std;

int N;
int A[100000 + 100];
int B[100000 + 100];

LL solve() {
	LL sum = 0;
	for (int i = 0; i < N; ++i) sum += B[i];
	LL ans1 = sum - 2LL * B[0];
	LL ans2 = sum;
	for (int i = 0; i < N - 1; ++i) {
		if (A[i] < 0) {
			A[i] = -A[i];
			A[i + 1] = -A[i + 1];
		}
	}
	if (A[N - 1] < 0) {
		return ans1;
	}
	else {
		return ans2;
	}
}

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

	sort(&B[0], &B[N]);
	cout << solve() << endl;

	return 0;
}

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

int gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}

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

  int x, y;
  cin >> x >> y;
  cout << (x + 1) + y - gcd(x, y) << endl;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	FOR(i,0,tx-sx)cout<<'R';
	FOR(i,0,ty-sy)cout<<'U';
	FOR(i,0,tx-sx)cout<<'L';
	FOR(i,0,ty-sy)cout<<'D';
	cout<<'D';
	FOR(i,0,tx-sx+1)cout<<'R';
	FOR(i,0,ty-sy+1)cout<<'U';
	cout<<"LU";
	FOR(i,0,tx-sx+1)cout<<'L';
	FOR(i,0,ty-sy+1)cout<<'D';
	cout<<'R'<<endl;
}

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

int ans[131072],h[131072],n,A,B;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void print(int x)
{
	static char s[233];
	if (!x) { putchar('0');putchar(' ');return; }
	int tot=0;
	for (;x;x/=10) s[++tot]=x%10+'0';
	for (;tot;tot--) putchar(s[tot]);
	putchar(' ');
}

inline void gao(int n,int x,int *ans)
{
	if (n==1) { ans[0]=0;ans[1]=1;return; }
	if (x&(1<<(n-1)))
	{
		gao(n-1,1,ans);
		gao(n-1,x^(1<<(n-1))^1,ans+(1<<(n-1)));
		for (int i=0;i<(1<<(n-1));i++) ans[i+(1<<(n-1))]^=(1<<(n-1))^1;
		return;
	}
	gao(n-1,x,ans);
	gao(n-1,ans[1],ans+(1<<(n-1)));
	for (int i=1;i<=(1<<(n-1));i++) h[i]=ans[i],ans[i]=ans[i+(1<<(n-1))-1]^(1<<(n-1));
	for (int i=(1<<(n-1))+1;i<(1<<n);i++) ans[i]=h[i-(1<<(n-1))];
}

int main()
{
	n=rd();A=rd();B=rd()^A;
	int hh=0;
	for (int i=0;i<n;i++) if ((1<<i)&B) hh++;
	if (!(hh&1)) { puts("NO");return 0; }
	gao(n,B,ans);
	puts("YES");
	for (int i=0;i<(1<<n);i++) print(ans[i]^A);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

int beki(long long a,long long b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}

pair<int,int> dfs(vector<int> h){
	int width = h.size();
	int m = 1000000004;
	for(int i=0;i<h.size();i++){
		m = min(m,h[i]);
	}
	int height = m;
	
	for(int i=0;i<h.size();i++){
		h[i] -= m;
	}
	
	int check = 1,notcheck = 1;
	bool f = false;
	int cnt0 = 0;
	while(h.size()!=0){
		while(h.size()!=0&&h.back()==0){
			h.pop_back();
			cnt0 ++;
		}
		if(h.size()==0)break;
		vector<int> t;
		while(h.size()!=0&&h.back()!=0){
			t.push_back(h.back());
			h.pop_back();
		}
		
		pair<int,int> p = dfs(t);
		if(!f){
			f=true;
		}
		check = mod(check * p.first);
		notcheck = mod(notcheck * mod(p.first*2 + p.second));
	}
	
	if(f){
		notcheck = mod(notcheck * beki(2,cnt0));
		check = mod(check * 2);
		notcheck = mod(notcheck - check);
		check = mod(check * beki(2,height-1));
	}
	else{
		check = beki(2,height);
		notcheck = mod(beki(2,width)-2);
	}
	//cout<<height<<','<<width<<','<<check<<','<<notcheck<<endl;
	return make_pair(check,notcheck);
}
	

int main(){
	
	int N;
	cin>>N;
	
	vector<int> h(N);
	for(int i=0;i<N;i++){
		cin>>h[i];
	}
	
	pair<int,int> p = dfs(h);
	
	cout<<mod(p.first+p.second)<<endl;
	
	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    string s[2];
    rep(0,i,2)cin>>s[i];
    ll a[2];
    rep(0,i,2)cin>>a[i];
    string u;
    cin>>u;
    rep(0,i,2)if(s[i]==u)--a[i];
    cout<<a[0]<<" "<<a[1]<<endl;
}

Measured memory_bytes: 256
/**
 *      ABC 74 C
 *      author  : kyomukyomupurin
 *      created : 2018-10-16 21:07:22
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
    double maxd = (double) E / (100 + E);
    double dd = -1;
    int sw = 0; int s = 0;
    int mA = F / (100 * A); int mB = F / (100 * B); int mC = F / C; int mD = F / D;

    for (auto i = 0; i <= 100 * A * mA ; i += 100 * A) {
        for (auto j = 0; j <= 100 * B * mB; j += 100 * B) {
            for (auto k = 0; k <= mC * C; k += C) {
                for (auto l = 0; l <= mD * D; l += D) {                    
                    double d = (double) (k + l) / (i + j + k + l);
                    if (d > dd && d <= maxd && i + j + k + l <= F){
                        dd = d; sw = i + j + k + l; s = k + l;
                    }
                }
            }
        }
    }
    cout << sw << " " << s << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if(a==b && b!=c)
		cout << "Yes\n";
	else if(b==c && a!=c)
		cout << "Yes\n";
	else if(a==c && a!=b)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, h, cnt = 0; cin>>n>>h;
	for(int i =0 ; i<n; i++)	{
		int x; cin>>x;
		if(x >=h){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
sys.setrecursionlimit(10 ** 9)


def main():
    N, M = MAP()
    AB = sorted([list(MAP()) for _ in range(M)], key=(lambda x: x[1]))

    point = cnt = 0
    for (a, b) in AB:
        if a > point:
            point = b - 1
            cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


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

int main(){
  int k, s, count=0;;
  cin >> k >> s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(s-i-j>=0 && s-i-j<=k)count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    string S = "MARCH";
    long long a[5] = {0};
    for ( int i = 0; i < N; i++ ) {
        string s;
        cin >> s;
        for ( int j = 0; j < 5; j++ ) {
            if ( s[0] == S[j] ) { a[j]++; }
        }
    }
    long long ans = 0;
    for ( int i = 0; i < 5; i++ ) {
    for ( int j = i+1; j < 5; j++ ) {
    for ( int k = j+1; k < 5; k++ ) {
        ans += a[i] * a[j] * a[k];
    }
    }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void program();
int main() { program();}
#define int long long int

#define N 16
#define BIG 65536
int dp[BIG], cost[BIG], a[N][N];

void debug_printmask(int x, int size) {
    vector<int> res;
    for(;x;x/=2) res.push_back(x&1);
    while((int)res.size() < size) res.push_back(0);
    reverse(res.begin(), res.end());
    for(auto c: res) cout << c;
}

int f(int x) {
    /*
    cout << "start";
    debug_printmask(x,N);
    cout << endl;
    */
    if (dp[x] != -1) return dp[x];

    vector<int> alive;
    for(int y=x, p=0;y;y/=2,p++) if(y&1) {
        alive.push_back(p);
    }
    int res = 0;
    int num_alive = alive.size();
    for(int m=0;m<(1<<(num_alive-1));m++) {
        int nxt_m = 0;
        for(int i=0;i<num_alive-1;i++) if(m&(1<<i)) {
           nxt_m |= (1<<alive[1+i]);
        }
        int cur_m = x^nxt_m;
        /*
        cout << "cur: ";
        debug_printmask(cur_m,N);
        cout << endl;
        */
        res = max(res, cost[cur_m] + f(nxt_m));
    }
    return dp[x] = res;
}


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

    for(int m=0;m<BIG;m++) {
        dp[m] = -1;
        for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++) if(m&(1<<i) && m&(1<<j)) {
            cost[m] += a[i][j];
        }
    }

    // debug print masks
    /*
    for(int m=0;m<(1<<n);m++) {
        debug_printmask(m, n);
        cout << " " << cost[m] << endl;
    }
    */

    dp[0] = 0;
    for(int i=0;i<N;i++) dp[(1<<i)] = 0;

    cout << f((1<<n)-1) << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

typedef long double ld;
const ld PI = 3.14159265358979323846264338327950288;

int main(){
	int n;
	ld l,t[3002];
	cin >> n >> l;
	for(int i = 0 ; i < n ; i ++)cin >> t[i];
	
	ld x = 0.0, y = 0.0;
	for(int i = 0 ; i < n ; i ++){
		for(int j = i+1 ; j < n ; j ++){
			x += (n-2-(j-i-1))*cos(PI*(t[i]+t[j])/l);
			y += (n-2-(j-i-1))*sin(PI*(t[i]+t[j])/l);
			x -= (j-i-1)*cos(PI*(t[i]+t[j])/l);
			y -= (j-i-1)*sin(PI*(t[i]+t[j])/l);
		}
	}
	
	x *= 6; x /= n; x /= n-1; x /= n-2;
	y *= 6; y /= n; y /= n-1; y /= n-2;
	cout.precision(20);
	cout << x << " " << y << endl;
}

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

char space[105][105];

int main() {
	int n, m, d;
	cin >> n >> m >> d;
	for (int i = 0;i < n;i++) {
		cin >> space[i];
	}
	int p = 0;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j <= m - d;j++) {
			int flg = 1;
			for (int k = j;k < j + d;k++) {
				if (space[i][k] == '#') {
					flg = 0;
					break;
				}
			}
			if (flg == 1) { p++; }
		}
	}

	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n - d;j++) {
			int flg = 1;
			for (int k = j;k < j + d;k++) {
				if (space[k][i] == '#') {
					flg = 0;
					break;
				}
			}
			if (flg == 1) { p++; }
		}
	}
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>
int main(){
  int i,N,j,*A,minj,for_change,times=0;

  scanf("%d",&N);
  A = (int *)malloc(N * sizeof(int));

  for(i = 0 ; i < N ; i++) scanf("%d",&A[i]);

  for(i = 0 ; i < N-1 ; i++){
    minj = i;
    for(j = i ; j <= N-1 ; j++){
      if(A[j] < A[minj]) minj = j; } 
    for_change = A[i];
    A[i] = A[minj];
    A[minj] = for_change;
    if(i != minj) times++; }
  
  for(j = 0 ; j < N-1 ; j++) printf("%d ",A[j]);
  printf("%d\n",A[N-1]);
  printf("%d\n",times);

  free(A);

  return 0;
}


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

int main() {
  int a,b,c; cin >>a >>b >>c;
  int k; cin >>k;
  vector<int> x = {a, b, c};
  sort(x.begin(), x.end());
  for (int i=0; i<k; i++){
    x.at(2) *= 2;
  }
  
  cout <<x.at(0) + x.at(1) + x.at(2) <<endl;
}


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

int main() {
  long A, B, K;
  cin >> A >> B >> K;
  
  if(A >= K){
    cout << A - K << " " << B << endl;
  }else if(A + B > K){
    cout << 0 << " " << A + B - K << endl;
  }else{
    cout << 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
 
int main(){
	long long x=0;
	long long y=0;
	scanf("%lld %lld", &x, &y);
	int ans=1;
	while(2*x<=y){
		ans++;
		x=x*2; 
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

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

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    }
}


Measured memory_bytes: 89948
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = 0;
    int ans = 0;
    cin >> n;
    REP(i,n){
	string ss;
	cin >> ss;
	ss += ss;
	REP(i,ss.size()/2){
	    if(s == ss.substr(i,s.size())) {
		ans++;
		break;
	    }
	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> h(n+1, 0), a(n+1, 0);
    vector<long long> dp(n+1, 0);
    for(int i=1;i<=n;i++) cin >> h[i];
    for(int i=1;i<=n;i++) cin >> a[i];
    long long ans = 0;
    for(int i=1;i<=n;i++){
        long long res = 0;
        int x = h[i];
        while(x > 0){
            if(res < dp[x]) res = dp[x];
            x -= (x & -x);
        }
        res += a[i];
        x = h[i];
        while(x <= n){
            if(dp[x] < res) dp[x] = res;
            x += (x & -x);
        }
        if(ans < res) ans = res;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
import Control.Monad
import Data.List
import Data.Int

main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  [x, y, z] <- transpose <$> replicateM n (map read . words <$> getLine) :: IO [[Int64]]
  print $ solve x y z m

inf :: Int64
inf = -10^18

solve :: [Int64] -> [Int64] -> [Int64] -> Int -> Int64
solve a b c m = maximum [maxsum (map (*i) a) (map (*j) b) (map (*k) c) m | i <- [-1, 1], j <- [-1, 1], k <- [-1, 1]]

maxsum :: [Int64] -> [Int64] -> [Int64] -> Int -> Int64
maxsum a b c m = sum . take m . reverse . sort . map (\(x, y, z) -> x + y + z) $ zip3 a b c




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

class Cube{
public:
    int s[6];
    Cube(){}
    void roll_z(){roll(1,2,4,3);}//横回転、時計回り
    void roll_y(){roll(0,2,5,3);}//W
    void roll_x(){roll(0,1,5,4);}//N
    void roll(int i,int j,int k,int l){
        int t=s[i];s[i]=s[j];s[j]=s[k];s[k]=s[l];s[l]=t;
    }

};
bool eq(Cube c1,Cube c2){
    for(int i=0;i<6;i++){
        if(c1.s[i]!=c2.s[i]) return false;
    }
    return true;
}
bool equal(Cube c1,Cube c2){
    for(int i=0;i<6;i++){
        for(int j=0;j<4;j++){
            if(eq(c1,c2)){
                return true;
            }
            c1.roll_z();
        }
        if(i%2==0) c1.roll_y();
        else c1.roll_x();
    }
    return false;
}

int main() {
    Cube c1,c2;

    int f1,f2;
    for(int i=0;i<6;i++){
        cin>>c1.s[i];
    }
    for(int i=0;i<6;i++){
        cin>>c2.s[i];
    }
    if(equal(c1,c2)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;

}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>

ll MOD = 1e9+7;
ll inv(ll a, ll b) {
	return 1 < a ? b - inv(b % a, a) * b / a : 1;
}

ll fac[100001];
ll C(ll n, ll m){
    return (((fac[n]*inv(fac[m],MOD))%MOD)*(inv(fac[n-m], MOD)))%MOD;
}

int main(){
    ios::sync_with_stdio(0);
    int n, k;
    ll ans = 0;
    cin >> n >> k;
    ll a[n], b[n], t = n-1;
    for (int i = 0 ; i < n ; ++i){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a, a+n);
    fac[0] = 1;
    for (int i = 1 ; i < 100001 ; ++i)
        fac[i] = (fac[i-1]*i)%MOD;

	for(int i = 0;i<n;i++){
		if(i>=k-1)ans+=a[i]*C(i,k-1),ans%=MOD;
		if(n-i-1>=k-1)ans-=a[i]*C(n-i-1,k-1),(ans+=MOD)%=MOD;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(){
   long long i,n,a[200010],suff[200010];
   cin>>n;
   for(i=1;i<=n;i++){
       cin>>a[i];
   }
   for(i=n-1,suff[n]=a[n];i>1;i--){
       suff[i]=(a[i]+suff[i+1])%1000000007;
   }
   long long ans=0;
   for(i=1;i<n;i++){
       ans+=a[i]*suff[i+1];
       ans%=1000000007;
   }
   cout<<ans;
}

Measured memory_bytes: 6748
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
    int n[5];
    int n2[5];
    for(int i=0;i<5;i++){
        scanf("%d",&n[i]);
        if(n[i]%10==0){
            n2[i]=n[i];
        }else{
            n2[i] = n[i]+(10-n[i]%10);
        }
    }
    int min=10000000;
    for(int i=0;i<5;i++){
        ans=n[i];
        for(int j=0;j<5;j++){
            if(i!=j){
                ans += n2[j];
            }
        }
        if(ans<min){
            min=ans;
        }
    }
    printf("%d",min);
    return 0;
}


Measured memory_bytes: 128
import heapq
def dijkstra_heap(s,g):
    used = [True] * n #True:未確定
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,[e[0],e[1]])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        if v==g:
            return minedge[0]
        kai=minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[kai+e[0],e[1]])                   
    return -1

################################
n,m = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
l=[]
for i in range(m):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])
    l.append([x-1,y-1])
zeroedge=[0]*n
l.sort()
l.append([10**10,10**10+1])
i=0
nl=l[i][0]
r=l[i][1]
while i<m+1:
    if l[i][0]>r:
        for j in range(nl,r):
            edge[j+1].append([0,j])
        nl=l[i][0]
        r=l[i][1]
        i+=1
    else:
        r=max(r,l[i][1])
        i+=1       
print(dijkstra_heap(0,n-1))


Measured memory_bytes: 82516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    
    int n;
    cin >> n;
    
    vector<int> d;
    for(int i=0;i<n;i++){
        int m;
        cin >> m;
        d.push_back(m);
    }
    sort(d.begin(),d.end());
    int result = 0;
    while(d.size()>0){
        if(d.back() != 101){
            result++;
            int max=d.back();
        
        vector<int> a;
        for(int i=0;i<d.size();i++){
            if(d[i] == max){
                a.push_back(i);
            }
        }
        for(int i=0;i<a.size();i++){
            d[a[i]] = 101;
        }
        }
        d.pop_back();
    }
    cout << result << endl;
}


Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

const int MAX_LIMIT = 1000006;

bool isPrime[MAX_LIMIT];
std::vector<int> prime;
void sieve()
{
	int limit = MAX_LIMIT, i, j;
	memset(isPrime, 0, sizeof(isPrime));
	for(i = 2; i < limit + 1; i++)
		isPrime[i] = 1;

	int inLimit = sqrt(limit);
	inLimit++;

	for(i = 2; i < inLimit; i++)
	{
		if(isPrime[i]==1)
		{
			for(j=i*i; j<limit; j+=i)
				isPrime[j] = 0;
		}
	}

	for(i = 2; i < MAX_LIMIT; i++)
		if(isPrime[i])
			prime.push_back(i);

	return;
}

ll numPrimes = 0;
ll uniquePrimes = 0;
ll dp[100005][55];

long long power(long long _n,long long _k, long long _mod)
{
	long long r=1;
	while(_k) {
		if(_k&1) {
			r = ((r * _n) % _mod);
		}
		_n = ((_n * _n) % _mod);
		_k>>=1;
	}
	return (r % _mod);
}

ll rec(int ind, int x) {
	if (ind == 1 || x == 0) {
		return 1;
	}

	ll &ret = dp[ind][x];
	if (ret != -1) {
		return ret;
	}

	ret = (
		rec(ind - 1, x) + rec(ind, x - 1)) % MOD;
	return ret;
}

ll N, M;
map<ll, int> mp;

long long int _fact[MAX_LIMIT];
void fillFactorial()
{
	_fact[0] = 1;
	// inv_fact[0] = power(_fact[0], MOD - 2);
	for(int i = 1; i < MAX_LIMIT; i++) {
		_fact[i] = (_fact[i - 1] * i) % MOD;
		// inv_fact[i] = power(_fact[i], MOD - 2);
	}
}

inline int mul(int _a, int _b)
{
	return (long long) _a * _b % MOD;
}

ll getNcR(int n, int r)
{
	ll ret = 0;
	ret = power(mul(_fact[r], _fact[n - r]), MOD - 2, MOD);
	ret = mul(ret, _fact[n]);
	return ret;
}

int main()
{
	memset(dp, -1, sizeof(dp));
	sieve();
	fillFactorial();
	scanf("%lld %lld", &N, &M);

	for (int i = 0; i < prime.size(); i++) {
		while(M % prime[i] == 0) {
			// cout << prime[i] << "\n";
			M /= prime[i];
			mp[prime[i]]++;
		}
	}

	if (M != 1) {
		mp[M]++;
	}

	ll ans = 1;

	for (map<ll, int>::iterator itr = mp.begin(); itr != mp.end(); itr++) {
		// cout << (rec(N, itr->second)) % MOD << "\n";
		ans = (ans * getNcR(N + itr->second - 1, itr->second)) % MOD;
	}

	printf("%lld\n", ans);


	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 52472
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

ll calc(const string&s)
{
    ll ret=0;
    auto itr=s.begin();
    while(true){
        auto pl=find(itr,s.end(),'+');
        ret+=stoll(string(itr,pl));
        if(pl==s.end())break;
        itr=pl+1;
    }
    return ret;
}
int main()
{
    ll n=in(),t=in(),a=in();
    REP(i,n-1){
        ll ti=in(),ai=in();
        t=(t+ti-1)/ti*ti;
        a=(a+ai-1)/ai*ai;
             if(t/ti<a/ai)t=a/ai*ti;
        else if(t/ti>a/ai)a=t/ti*ai;
    }
    cout<<(t+a)<<endl;
}

Measured memory_bytes: 256