akhauriyash/Code-Regression huggingface dataset:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))

from collections import Counter, defaultdict
c = Counter(a)
n1, n2, n3 = c[1], c[2], c[3]
n0 = c[0]
def glist(*l, fill=None):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [glist(*ll) for _ in range(l[0])]

count = 0
S = sum(a)
sub = glist(n1+n2+n3+1,n2+n3+1,n3+1)
sub[0][0][0] = 0
#     for i1 in range(min(n+1, s+1)):
#         for i2 in range(min(n+1, (s-i1)//2+1)):
for i3 in range(n3+1):
    for i2 in range(n2+n3+1-i3):
        for i1 in range(n1+n2+n3 - (i2+i3) + 1):
            if i1==i2==i3==0 or i1+i2+i3>n:
                continue
#             print(i1,i2,i3)
            ans = n
            p = 0
            if i1>0:
                ans += i1 * sub[i1-1][i2][i3]
                p += i1
            if i2>0:
                ans += i2 * sub[i1+1][i2-1][i3]
                p += i2
            if i3>0:
                ans += i3 * sub[i1][i2+1][i3-1]
                p += i3
            ans = ans/p
            sub[i1][i2][i3] = ans
print(sub[n1][n2][n3])

Measured memory_bytes: 362252
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
long long n, res;
int main() {
    DAU
    cin >> n;
    res = n * (n - 1) / 2;
    cout << res;
    PLEC
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll N; cin >> N;
    ll ans = 1LL << 60;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i != 0) continue;
        ll j = N / i;
        ans = min(ans, (i - 1) + (j - 1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
// #include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

using i32 = int;
using i64 = long long;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
T read() {
  T a = 0;
  for(;;) {
    char c = getchar();
    if ('0' <= c && c <= '9') {
      a = a * 10 + c - 48;
    } else {
      return a;
    }
  }
}

signed main() {
//  i32 x, y, z, k;
//  scanf("%d%d%d%d", &x, &y, &z, &k);
  i32 x = read<i32>(),
      y = read<i32>(),
      z = read<i32>(),
      k = read<i32>();
  vector<i64> A(x), B(y), C(z);
//  REP(i, x) scanf("%lld", &A[i]);
//  REP(i, y) scanf("%lld", &B[i]);
//  REP(i, z) scanf("%lld", &C[i]);
  REP(i, x) A[i] = read<i64>();
  REP(i, y) B[i] = read<i64>();
  REP(i, z) C[i] = read<i64>();
  sort(ALL(A), greater<i64>());
  sort(ALL(B), greater<i64>());
  sort(ALL(C), greater<i64>());
  using P = pair<i64, i64>;
  priority_queue<P> Q;
  Q.push({A[0] + B[0] + C[0], 0});
  set<i64> S;
  S.insert(0);
  REP(_, k) {
    i64 p = Q.top().first;
    i64 q = Q.top().second;
    Q.pop();
    printf("%lld\n", p);
    i32 u = q & 1023;
    i32 v = q >> 10 & 1023;
    i32 w = q >> 20 & 1023;
    i64 u1 = q + 1;
    i64 v1 = q + (1 << 10);
    i64 w1 = q + (1 << 20);
    if (u + 1 < x && !S.count(u1)) { S.insert(u1); Q.push({A[u + 1] + B[v] + C[w], u1}); }
    if (v + 1 < y && !S.count(v1)) { S.insert(v1); Q.push({A[u] + B[v + 1] + C[w], v1}); }
    if (w + 1 < z && !S.count(w1)) { S.insert(w1); Q.push({A[u] + B[v] + C[w + 1], w1}); }
  }
}

Measured memory_bytes: 768
#include<stdio.h>
int main(void){

int x,y,n=0;

while(1){

scanf("%d %d",&x,&y);

	if( x==0 && y==0 )
	break;
	
if( x > y ){
n=x;
x=y;
y=n;
}
	printf("%d %d\n",x,y);
	
}

return 0;
}


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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	ll n; cin >> n;
	ll a[100005];
	ll sum = 0;
	ll even_sum = 0;
	rep(i, 1, n+1) {
		cin >> a[i];
		sum += a[i];
		if(i%2==0) even_sum += a[i];
	}
	ll ans[100005];
	ans[1] = sum - 2*even_sum;
	rep(i, 2, n+1){
		ans[i] = 2*a[i-1]-ans[i-1];
	}
	rep(i, 1, n){
		cout << ans[i] << ' ';
	}
	cout << ans[n] << endl;
	return 0;
}

Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll a[100005];
ll ans;

inline ll gcd(ll x,ll y){
	if(x%y==0) return y;
	else return gcd(y,x%y);
}

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]/=2;
	}
	bool f=true;
	ll  lcm=a[1];
	for(int i=2;i<=n;i++){
		lcm = lcm*a[i]/gcd(lcm,a[i]);
		if(lcm>m){
			f=false;
			break;
		}
	}
	if(f==false){
		cout<<"0"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(lcm/a[i]%2==0){
			cout<<"0"<<endl;
			return 0;
		}
	}
	ans=m/lcm;
	ans=(ans+1)/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
//सत्यान्न प्रमदितव्यम्  ||
//Still, Taking my time to perfect the beats
//And I still got love for the streets, it's the A-D-D-U

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define LINF  0x3f3f3f3f3f3f3f3fll
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end() 

const ll mod = 999983;
#define mx 1000005
const ll mxi = 10005;

int main()
{
    fast_as_levi;
    ll n,k;
    cin>>n>>k;
    ll ar[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    
    ll l = ar[1];
    ll r = ar[ar[1]];
    
    while(l!=r)
    {
        l = ar[l];
        r = ar[ar[r]];
    }
    
    l = 1;
    while(l!=r)
    {
        l = ar[l];
        r = ar[r];
    }
    
    
    ll st = l;
    ll cnt = 0;
    l = 1;
    while(l!=st)
    {
        cnt++;
        l = ar[l];
    }
    
    l=st;
    ll cnt1 = 1;
    while(ar[l]!=st)
    {
        cnt1++;
        l = ar[l];
    }
    
    l = 1;
    while(cnt>0 && k>0)
    {
        l = ar[l];
        cnt--;
        k--;
    }
    
    if(k==0)
    {
        cout<<l<<"\n";
        return 0;
    }
    
    k = k%cnt1;
    
    while(k)
    {
        l = ar[l];
        k--;
    }
    cout<<l<<"\n";
}

Measured memory_bytes: 5184
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    VI x(3), y(3);
    REP(i, 0, n) {
      int h, m, t;
      cin >> h;
      cin.ignore();
      cin >> m >> t;
      int a = (t + 60 - m) % 60;
      int kind = -1;
      if (11 <= h && h <= 14) kind = 0;
      if (18 <= h && h <= 20) kind = 1;
      if (21 <= h || h <= 1) kind = 2;
      if (kind >= 0) {
        x[kind] += a <= 8;
        y[kind] += 1;
      }
    }
    string kind[3] = {"lunch", "dinner", "midnight"};
    REP(i, 0, 3) {
      cout << kind[i] << " ";
      if (y[i]) {
        cout << 100 * x[i] / y[i] << endl;
      } else {
        cout << "no guest\n";
      }
    }
  }
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
	
using namespace std;
 
#define int long long
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define LOCAL
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)
 
typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;
 
const int INF = LONG_LONG_MAX/2;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	--n;
	string s = "abcdefghijklmnopqrstuvwxyz";
	string ans = "";
	
	while (true) {
		ans += s[n%26];
		n -= n%26+1;
		if (n <= 0) {
			break;
		}
		n /= 26;
	}
	
	reverse(ALL(ans));
	cout << ans << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main()	{
  int w, a, b;
  cin >> w >> a >> b;
  if (a < b)	{
    int temp = b - a - w;
    if (temp > 0) cout << temp << endl;
    else cout << 0 << endl;
  }
  else if (b < a)	{
    int temp = a - b - w;
    if (temp > 0) cout << temp << endl;
    else cout << 0 << endl;
  }
  else	{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>

int main(){
	int i,N;
	double xa,ya,ra,xb,yb,rb;
	double distance;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
		distance=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
		if(distance>ra+rb) printf("0\n");
		else{
			if(distance<fabs(ra-rb) && ra<rb) printf("-2\n");
			else if(distance<fabs(ra-rb) && rb<ra) printf("2\n");
			else printf("1\n");
		}
	}
	return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int D, G; cin >> D >> G;
    vel p(D), c(D); rep(i, D) cin >> p[i] >> c[i];

    ll res = INF;
    for (int bit = 0; bit < (1<<D); bit++) {
        ll sum = 0, num = 0;
        rep(i,D) if (bit & (1<<i)) sum += c[i] + p[i] * 100 * (i+1), num += p[i];
        if (sum >= G) res = min(res, num);
        else {
        for (int i = D-1; i >= 0; --i) {
            if (bit & (1<<i)) continue;
            for (int j = 0; j < p[i]; ++j) {
            if (sum >= G) break;
            sum += 100 * (i+1);
            num++;
            }
        }
        res = min(res, num);
        }
    }
    cout << res << endl;
}

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

namespace CSharp_AtCoder
{

    class Program
    {
        static int N;
        static int[] x;
        static int[] y;
        static int[] h;

        static int Checker(int cx, int cy)
        {
            int H = -1;

            for(int i = 0; i < N; i++)
            {
                if(h[i] != 0)
                {
                    H = h[i] + Math.Abs(x[i] - cx) + Math.Abs(y[i] - cy);
                    break;
                }
            }

            if (H == -1) return -1;

            for(int i = 0; i < N; i++)
            {
                int h_i = Math.Max(H - Math.Abs(x[i] - cx) - Math.Abs(y[i] - cy), 0);
                if (h_i != h[i]) return -1;
            }

            return H;
        }

        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());

            x = new int[N];
            y = new int[N];
            h = new int[N];
            for(int i = 0; i < N; i++)
            {
                int[] xyh = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                x[i] = xyh[0];
                y[i] = xyh[1];
                h[i] = xyh[2];
            }

            for(int cx = 0; cx <= 100; cx++)
            {
                for(int cy = 0; cy <= 100; cy++)
                {
                    int H = Checker(cx, cy);
                    if(H != -1)
                    {
                        Console.WriteLine($"{cx} {cy} {H}");
                        return;
                    }
                }
            }


        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using  namespace std;
#define    ll  long long int
int main( )
{
    ll n,m,mx=-100000;
    map<string,ll> mp;
    map<string,ll> ::iterator it;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        string s;
        cin>>s;
        mp[s]++;

    }
    cin>>m;
    for(ll i=0; i<m; i++)
    {
        string s;
        cin>>s;
        if(mp[s]>0)
        mp[s]--;

    }
    for(it=mp.begin(); it!=mp.end(); it++)
    {
        mx=max(mx,it->second);
    }

    cout<<mx<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  string w;
  int c[30]={};
  cin >> w;

  REP(i, w.size()){
    c[w[i]-'a'] += 1;
  }

  REP(i, 30){
    if(c[i]%2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
/*input

*/

//sometimes it's the people who no one imagines anything of 
//who do the things that no one can imagine.

//code author: iamxlr8

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

#define ll long long
#define endl "\n"
#define all(c) c.begin(),c.end()
#define mod 1000000007
#define inf 1000000000000000001
#define F first
#define S second
#define dbg(x) cout << #x << " = " << x << ' '
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll add(ll a,ll b)
{
    return (a%mod+b%mod)%mod;
}

void solve()
{
    ll n;
    cin>>n;
    vector<vector<int>> v(n,vector<int>(n));
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
            cin>>v[i][j];
    }
    vector<ll> dp(1<<n);
    dp[0]=1;
    // no. of bits set in mask = no. of men paired
    // if ith mask is set then, it means ith women is paired
    for(ll mask=0;mask<(1<<n)-1;mask++)
    {
        ll men=__builtin_popcount(mask);
        for(ll women=0;women<n;women++)
        {
            if(v[men][women]&&!(mask&(1<<women)))
                dp[mask|(1<<women)]=add(dp[mask|(1<<women)],dp[mask]);
        }
    }
    cout<<dp[(1<<n)-1];
}

int main() 
{
    off;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 16640
#include<iostream>

using namespace std;

int main(){
  int i,n,x,d=0,buf;
  cin>>n>>x;
  for(i=0;i<n;i++){
    cin>>buf;
    d+=buf;
    if(d>x){
      break;
    }
  }
  cout<<i+1<<endl;
  return 0;
}

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

int main() {
int A,B;
cin>>A>>B;
  
if(A==B){  
	cout<<"Draw"<<endl;}
else if (A==1&&B!=1){
	cout<<"Alice"<<endl;}
else if (B==1&&A!=1){
	cout<<"Bob"<<endl;}
else if(A<B&&A!=1){ 
	cout<<"Bob"<<endl;}
else if(A>B&&B!=1){
    cout<<"Alice"<<endl;}

	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string a,b;
  cin >> a >> b;
  string s;
  for(int i = 0;i < (int)(a.size() + b.size());i++){
    if(i % 2 == 0)s += a[i / 2];
    else s += b[i / 2];
  }
  cout << s << endl;
}

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

using namespace std;

class UnionFind {
 public:
  std::vector<int> parent;

  UnionFind(int n) : parent(n, -1) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    return parent[x] = root(parent[x]);
  }

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

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

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) std::swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  UnionFind uf(2 * N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (S[i][j] == '1') uf.unite(i, j + N), uf.unite(i + N, j);
    }
  }
  for (int i = 0; i < N; i++) {
    if (uf.is_same(i, i + N)) {
      cout << -1 << '\n';
      return 0;
    }
  }
  auto f = [&](int s) {
    vector<int> dist(N, -1);
    dist[s] = 0;
    queue<int> que;
    que.push(s);
    int res = 0;
    while (!que.empty()) {
      auto u = que.front();
      que.pop();
      for (int v = 0; v < N; v++) {
        if (S[u][v] == '1') {
          if (dist[v] != -1) continue;
          dist[v] = dist[u] + 1;
          que.push(v);
          res = max(res, dist[v]);
        }
      }
    }
    return res + 1;
  };
  int res = 0;
  for (int i = 0; i < N; i++) {
    res = max(res, f(i));
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
var
  n, i, answer, old: Integer;
  d: array [1 .. 100 + 1] of Integer;

procedure BubbleSort();
var
  i, j, temp: Integer;
begin
  for i := 1 to n - 1 do
  begin
    for j := i + 1 to n do
    begin
      if (d[j] < d[i]) then
      begin
        temp := d[i];
        d[i] := d[j];
        d[j] := temp;
      end;
    end;
  end;
end;

begin
  // Nを教えてもらう
  readln(n);

  // N枚読み込む
  for i := 1 to n do
  begin
    readln(d[i]);
  end;

  // ソート
  BubbleSort();

  answer := 0;
  old := -1; // 最初のd[i]が新発見になるように、d[i]に出てこない値を覚えておく

  // 数値の種類数を調べる
  for i := 1 to n do
  begin
    if (d[i] <> old) then
    begin
      // 知らない数値だったのでカウントアップ
      Inc(answer);
      // 次の比較のために今の値を覚えておく
      old := d[i];
    end;
  end;

  // 回答する
  writeln(answer);

end.

Measured memory_bytes: 128
#include <stdio.h>
void Rect(unsigned int h, unsigned int w){
	int i, j;
	for (i = 1; i <= h; i++){
			for (j = 1; j <= w; j++){
				if (i==1||i==h||j==1||j==w)
					printf("#");
				else
					printf(".");
			}
		printf("\n");
	}
	printf("\n");
}

int main(void){
	unsigned int h, w;
	while (1){
		scanf("%d %d", &h, &w);
		if (!(h * w))break;
		Rect(h, w);
	}
	return 0;
}

Measured memory_bytes: 572
import math

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

for i in range(10000):
  target_a = i * 0.08
  target_b = i * 0.1
  if math.floor(target_a) == A and math.floor(target_b) == B:
    print(i)
    exit()
  else:
    pass

print(-1)

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

int main(){
    int n;
    cin >> n;
    int l[n];
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    int sum = 0;
    for(int j = 0; j < n; j++){
        sum += l[j];
    }
    int max = 0;
    for(int k = 0; k < n; k++){
        if(max < l[k]){
            max = l[k];
        }
    }
    if(2*max < sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> X(M);
  vector<int> Y(M-1);
  for(int i=0;i<M;i++){
    cin>>X.at(i);
  }
  sort(X.begin(),X.end());
  for(int i=0;i<M-1;i++){
    Y.at(i)=X.at(i)-X.at(i+1);
  }
  sort(Y.begin(),Y.end());
  reverse(Y.begin(),Y.end());
  int sum=0;
  if(N>=M){
    cout<<0<<endl;
  }else{
    for(int i=0;i<M-N;i++){
      sum+=Y.at(i);
    }
    cout<<0-sum<<endl;
  }
  
    
  
}

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

int main() {
  int N,A;
  cin >> N;
  string S="";
  A=0;

  for (int i=0; i<N; i++){
    cin >> S;
    if (S=="Y")
      A=1;
  }
  
  if (A==1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int n;
    while(cin >> n && n)
    {
        int ans = 0, sum =0;
        for(int i = 1; i < n; i++)
        {
            sum = i;
            for(int j = i + 1; j <= n; j++)
            {
                sum += j;
                if(sum == n){ ans++; break;}
                if(sum > n ) break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC X(100).
       01  a1 PIC 9(08).
       01  a2 PIC 9(08).
       01  a3 PIC 9(08).
       01  r pic 9(08).
       01  r2 pic 9(08).
       01 disp pic Z(20)9.
       PROCEDURE DIVISION.
        ACCEPT indata.
        
        UNSTRING indata DELIMITED BY SPACE INTO a1 a2 a3.
        divide a2 by a1 giving r
         IF r >= a3 THEN
          MOVE FUNCTION TRIM(a3) to disp
          DISPLAY disp
         ELSE
          MOVE FUNCTION TRIM(r) to disp
          DISPLAY disp
         END-IF


       STOP RUN.


Measured memory_bytes: 636
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main() {
	int H,A;
	cin >> H >> A;
	if (H % A == 0)cout << H / A;
	else cout << H / A + 1;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b)*c/2;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        int A;
        int[] Xi;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            A = sc.nextInt();
            Xi = new int[N];
            for (int i = 0; i < Xi.length; i++) {
                Xi[i] = sc.nextInt();

            }
        }

        //i番目のXを加えていきながら、選んだカード枚数 pで総数がjになる個数
        //dp[p][j] = dp[p-1][j-x](i番目のXを選んだ) + dp[p][j](i番目のXを選ばなかった)
        long[][][] dp;
        //B枚選んだ
        int B = 0;

        dp = new long[N + 1][N + 1][50 * 50 + 1];
        dp[0][0][0] = 1;

        while (B < N) {
            int x = Xi[B];
            //p=0だけはコピー
            for (int j = 0; j < dp[B + 1][0].length; j++) {
                dp[B + 1][0][j] += dp[B][0][j];
            }
            for (int p = 1; p < dp[B + 1].length; p++) {
                for (int j = 0; j < dp[B + 1][p].length; j++) {
                    dp[B + 1][p][j] += dp[B][p][j];
                    if (j - x >= 0) {
                        dp[B + 1][p][j] += dp[B][p - 1][j - x];
                    }
                }
            }
            B++;
        }
        long result = 0;
        for (int i = 1; i <= N; i++) {
            result += dp[N][i][(i * A)];

        }
        System.out.println(result);
    }

}


Measured memory_bytes: 87888
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[][] ab = new int[n][2];
        for(int i=0;i<n;i++){
            ab[i][0] = fs.nextInt();
            ab[i][1] = fs.nextInt();
        }
        Arrays.sort(ab,new Comparator<int[]>(){
			@Override
			public int compare(int[] o1, int[] o2) {
				return o1[1]-o2[1];
			}
        });
        int now = 0;
        for(int i=0;i<n;i++){
            now+=ab[i][0];
            if(now > ab[i][1]){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
    static class FastScanner{
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte(){
            if(ptr < buflen){
                return true;
            }else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen <= 0){
                    return false;
                }
            }
            return true;
        }

        private int readByte(){
            if(hasNextByte())return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c){
            return 33<=c && c<=126;
        }

        public boolean hasNext(){
            while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
            return hasNextByte();
        }

        public String next(){
            if(!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)){
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong(){
            if(!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if(b == '-'){
                minus = true;
                b = readByte();
            }
            if(b < '0' || '9' < b){
                throw new NumberFormatException();
            }
            while(true){
                if('0' <= b && b<='9'){
                    n*=10;
                    n+=b-'0';
                }else if(b==-1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt(){
            long nl = nextLong();
            if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
            return (int)nl;
        }
        public double nextDouble(){return Double.parseDouble(next());}
    }
}


Measured memory_bytes: 39632
import java.util.*;
 
public class Main {
  public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
    int ans;
    if (K%2 == 0)
      ans = (K/2)*(K/2);
    else
      ans = (K/2)*(K/2+1);
    System.out.println(ans);
  }
}  

Measured memory_bytes: 35744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	vector<pair<ll,ll>>a;
	for(ll i=0;i<n;i++){
		ll x,l;
		cin>>x>>l;
		ll s=x-l;
		ll e=x+l;
		a.push_back(make_pair(s,e));
	}
	sort(a.begin(),a.end());
	ll cnt=0;
	ll L=a[0].first,R=a[0].second;
	for(ll i=1;i<n;i++){
		if(R<=a[i].first){
			L=a[i].first;
			R=a[i].second;
		}
		else{
			if(R>=a[i].second){
				cnt++;
				L=a[i].first;
				R=a[i].second;
			}
			else{
				cnt++;
			}
		}
	}
	cout <<n-cnt;
	// your code goes here
	return 0;
}

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

using namespace std;
int main(void){
    int N;
    cin >> N;
    
    vector<int> EatingIndex(N + 1);
    vector<int> FoodPoint(N + 1);
    vector<int> AdditionalPoint(N);
    
    for (int idx = 1; idx <= N; idx++) {
        cin >> EatingIndex[idx];
    }
    for (int idx = 1; idx <= N; idx++) {
        cin >> FoodPoint[idx];
    }
    for (int idx = 1; idx <= N - 1; idx++) {
        cin >> AdditionalPoint[idx];
    }
    
    long result = 0;
    for (int idx = 1; idx <= N; idx++) {
        int eatingIndex = EatingIndex[idx];
        result += FoodPoint[eatingIndex];
        if (idx != N && EatingIndex[idx + 1] == eatingIndex + 1) {
            result += AdditionalPoint[eatingIndex];
        }
    }
    
    cout << result << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> ans(10050);
    for(int i=0;i<N;i++) ans[i] = 0;
    int tmp;

    rep(x, 105)rep(y, 105)rep(z, 105){
        tmp = x*x + y*y + z*z + x*y + y*z + z*x;
        if(tmp < 10050) ans[tmp]++;
    }

    rep(i,N+1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
	int s[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
	int x,y;
	cin>>x>>y;
	if(s[x]==s[y])cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! {
        mut a: [i8; 3],
    }
    a.sort();
    let max = a[2];
    let sum = a[0] + a[1] + a[2];
    let mut ans = 0;
    if sum % 2 == max % 2 {
        ans = (2 * max - (a[0] + a[1])) / 2;
    } else {
        ans = ((2 * (max + 1)) - (a[0] + a[1])) / 2 + 1;
    }
    println!("{}", ans);

}


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

int main(){
  int N; cin >> N;
  vector<int64_t> l(87);
  l.at(0)=2;
  l.at(1)=1;
  for(int i=2;i<=86;i++){
    l.at(i)=l.at(i-1)+l.at(i-2);
  }
  cout << l.at(N) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);

int N;
const int MX = 10000;
int sieve[MX + 1];
vint primes;

void eratos(){

	for(int i = 0; i <= MX; i++){
		sieve[i] = 1;
	}
	for(int i = 2; i <= MX; i++){
		if(sieve[i] == 0) continue;
		primes.push_back(i);
		for(int j = i * 2; j <= MX; j += i){
			sieve[j] = 0;
		}
	}
	// for(int i: primes) cerr << i << ", ";
	// cerr << primes.size() << endl;
}

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

	int ret = 0;
	rep(i, N){
		int x; cin >> x;
		int good = 1;
		for(int p:primes) {
			if(p < x && x % p == 0) {
				good = 0;
				break;
			}
		}
		ret += good;
	}

	cout << ret << endl;
}

Measured memory_bytes: 3180
#include<stdio.h>

class dice{
    private:
        int curface;
        int faces[6] = {};
    
    public: int GetCurface(){return curface;}
    public: int GetFace(int n){return faces[n-1];}
    public: int GetRight(){return GetFace(3);}
    public: int GetLeft(){return GetFace(4);}
    public: int GetFront(){return GetFace(2);}
    public: int GetBack(){return GetFace(5);}
    
    dice(){
        for(int i = 0;i < 6;i++) scanf("%d",&faces[i]);
        curface = faces[0];
    }
    
    public: bool Move(char toward){
        switch(toward){
            case 'N':
                faces[0] = faces[1];
                faces[1] = faces[5];
                faces[5] = faces[4];
                faces[4] = curface;
                break;
            case 'E':
                faces[0] = faces[3];
                faces[3] = faces[5];
                faces[5] = faces[2];
                faces[2] = curface;
                break;
            case 'S':
                faces[0] = faces[4];
                faces[4] = faces[5];
                faces[5] = faces[1];
                faces[1] = curface;
                break;
            case 'W':
                faces[0] = faces[2];
                faces[2] = faces[5];
                faces[5] = faces[3];
                faces[3] = curface;
                break;
        }
        curface = faces[0];
        return 1;
    }
    public: bool Rotate(){
        this -> Move('W');this -> Move('S');this ->Move('E');
        return 1;
    }
    
    
};



int main(){
    int n,x,y;
    dice d;
    scanf("%d",&n);
   
    for(int i = 1;i <= n;i++){
        scanf("%d %d",&x,&y);
        if(d.GetRight() == x) d.Move('W');
        if(d.GetLeft() == x) d.Move('E');
        while(d.Move('N') && (d.GetCurface() != x));
        while(d.Rotate() && (d.GetFront() != y));
          printf("%d\n",d.GetRight());
    }
  
}





Measured memory_bytes: 2608
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    int n;
    int r=0,l=0,f=0;
    int ans=0;
    cin >> n;
    rep(i,n){
        string s;
        char pre;
        cin >> s;
        
        if(s[0]=='B'&&s[(int)s.size()-1]=='A'){
            f++;
        }else if(s[0]=='B'){
            l++;
        }else if(s[(int)s.size()-1]=='A'){
            r++;
        }
        
        
        rep(j,s.size()){
            
            if(j>0&&s[j]=='B'&&pre=='A'){
                ans++;
            }
            pre=s[j];
        }
    }
    
    //cout << r<<l<<f<<ans<<endl;
    
    if(f>0){
        ans+=f-1;
        if(r>0&&l>0){
            ans+=2;
            r=max(r-1,0);
            l=max(l-1,0);
            ans+=min(r,l);
        }else if(r>0||l>0){
            ans++;
        }
    }else{
        ans+=min(l,r);
    }
    
    cout << ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    int a[100];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }

    for(i=0;i<n;i++)
    {
        if(a[i] % 2 ==0 && a[i]%3!=0 && a[i]%5!=0)
           {
               printf("DENIED");
               return 0;
           }
    }
    printf("APPROVED");



   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
ll const M = 1000000007;
dd const pi = acos(-1);
ll const inf = 9e18;
ll const N = 100001;
ll dp[101][N];
int main()
{
    fast;
  	ll i,j,t,W,n;
  	cin >> n >> W;
  	vector<ll> w(n + 1),v(n + 1),temp(n + 1);
  	for(i = 1; i <= n; i++)
  		cin >> w[i] >> v[i];
  	for(i = 0; i < N; i++)
  		dp[0][i] = inf;
  	dp[0][0] = 0;
  	for(i = 1; i <= n; i++)
  	{
  		for(j = 1; j < N; j++)
  		{
  			dp[i][j] = dp[i - 1][j];
  			if(j >= v[i])
  				dp[i][j] = min(dp[i][j],w[i] + dp[i - 1][j - v[i]]);
  		}
  	}
  	ll ans = 0;
  	for(i = 1; i < N; i++)
  	{
  		if(dp[n][i] <= W)
  			ans = i;
  	}
  	cout<<ans<<endl;
    return 0;
}    

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

using namespace std;

int main()
{
    int a,b;
    char c;
    cin>>a>>c>>b;
    if (c=='+')
    {
        cout<< a+b<<"\n";
    }
    else {
         cout<< a-b<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;



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

    int d[k];
    int m[k];
    for ( int i =0; i<k; i++) {cin>>d[i]; }
    for(int i=0; i<k; i++) {m[i]=-1; }
    //if(k>1){
    m[k-1]=0;
    m[k-2] = abs(d[k-2]-d[k-1]);
    for(int i=k-2; i>=0; i--)
    {
        m[i] = min(abs(d[i]-d[i+1])+m[i+1],abs(d[i]-d[i+2])+m[i+2]);
    }


    cout << m[0]<< endl;



    return 0;
}


Measured memory_bytes: 1024
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#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 > >

//std::ios::sync_with_stdio(false);
int main(){
	std::ios::sync_with_stdio(false);
	int n,k,j,i,k1=0,l[51],ans=0;
	cin>>n>>k;
	rep(i,n)
	{
		cin>>l[i];
	}
	sort(l,l+n);
	j=n-1;
	while(1)
	{
		ans+=l[j];
		k1++;
		j--;
		if(k1==k){
			cout<<ans<<endl;
			break;
		}
	}

} 


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

using P = pair<int, int>;

int h, w, s;

P solve(int x1, int y1, int x2, int y2, vector<vector<vector<vector<P>>>>& dp, vector<vector<int>> const& acc, int const sum) {
    P& r = dp[x1][y1][x2][y2];
    if(r != P{0, 0}) {
        return r;
    }
    int t = acc[y2][x2] - acc[y1][x2] - acc[y2][x1] + acc[y1][x1];
    if(sum - t > s) {
        r = make_pair(-1, -1);
    } else {
        r = make_pair(1, s - (sum - t));
    }
    for(int i=x1+1; i<x2; ++i) {
        auto c1 = solve(x1, y1, i, y2, dp, acc, sum);
        auto c2 = solve(i, y1, x2, y2, dp, acc, sum);
        if(c1.first == 0 || c2.first == 0) {
            continue;
        }
        if(c1.first + c2.first > r.first) {
            r.first = c1.first + c2.first;
            r.second = min(c1.second, c2.second);
        } else if(c1.first + c2.first == r.first) {
            r.second = max(r.second, min(c1.second, c2.second));
        }
    }
    for(int i=y1+1; i<y2; ++i) {
        auto c1 = solve(x1, y1, x2, i, dp, acc, sum);
        auto c2 = solve(x1, i, x2, y2, dp, acc, sum);
        if(c1.first == 0 || c2.first == 0) {
            continue;
        }
        if(c1.first + c2.first > r.first) {
            r.first = c1.first + c2.first;
            r.second = min(c1.second, c2.second);
        } else if(c1.first + c2.first == r.first) {
            r.second = max(r.second, min(c1.second, c2.second));
        }
    }
    return r;
}



int main() {
    while(cin >> h >> w >> s, h) {
        vector<vector<int>> v(h, vector<int>(w));
        vector<vector<int>> acc(h+1, vector<int>(w+1));
        vector<vector<vector<vector<P>>>> dp(w+1, vector<vector<vector<P>>>(h+1, vector<vector<P>>(w+1, vector<P>(h+1))));
        int sum = 0;
        for(int i=0; i<h; ++i) {
            for(int j=0; j<w; ++j) {
                int u; cin >> u;
                //cin >> v[i][j];
                sum += u;
                acc[i+1][j+1] = u;
            }
        }
        for(int i=1; i<=h; ++i) {
            for(int j=0; j<w; ++j) {
                acc[i][j+1] += acc[i][j];
            }
        }
        for(int i=0; i<h; ++i) {
            for(int j=0; j<=w; ++j) {
                acc[i+1][j] += acc[i][j];
            }
        }
        
        auto res = solve(0, 0, w, h, dp, acc, sum);
        cout << res.first << " " << res.second << endl;
    }
}


Measured memory_bytes: 13708
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
int arr[100];

int dp[2][100][100][100];

int ans,nd;
int parity(int prev,int pos,int od,int ev)
{
     if(pos==nd) return 0;
     if(dp[prev][pos][od][ev]!=-1) return dp[prev][pos][od][ev];
     int x=INT_MAX,y=INT_MAX,p=INT_MAX,q=INT_MAX,m=INT_MAX,n=INT_MAX,k=INT_MAX,l=INT_MAX;


    if(arr[pos]==0)
    {
        if(prev==1)
        {
          if(od!=0) x=parity(1,pos+1,od-1,ev)+0;
          if(ev!=0) y=parity(0,pos+1,od,ev-1)+1;
        }
        else
        {

           if(ev!=0) q=parity(0,pos+1,od,ev-1)+0;
           if(od!=0) p=parity(1,pos+1,od-1,ev)+1;

        }

    }
    else
    {
        if(arr[pos]%2 && prev==1) m=parity(1,pos+1,od,ev)+0;
        if(arr[pos]%2 && prev==0) n=parity(1,pos+1,od,ev)+1;
        if(arr[pos]%2==0 && prev==0) k=parity(0,pos+1,od,ev)+0;
        if(arr[pos]%2==0 && prev==1) l=parity(0,pos+1,od,ev)+1;


    }
   dp[prev][pos][od][ev]=min({p,q,m,n,x,y,k,l});
   return dp[prev][pos][od][ev];
}


int main()
{
ll n,k;
cin>>n>>k;
ll sum=0;
for(int i=0;i<k;i++)
{
    ll x;
    cin>>x;
    sum+=x;
}
if(sum>=n) cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}















Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define Pause system("pause")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	IOS;
    ll x,y,cnt0=0,cnt1=0;
    cin>>x>>y;
    if(abs(x-y)>1)
        cout<<"Alice";
    else
        cout<<"Brown";
    return 0;
}

Measured memory_bytes: 3104
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
int main()
{
	int n,m,a,b,c,max;
	while(~scanf("%d%d",&n,&m))
	{
		a=m+n;
		b=n-m;
		c=n*m;
		max=a>b?a:b;
		max=max>c?max:c;
		printf("%d\n",max);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a<=b)
  	  for(register int i=1;i<=b;i++)
  		  cout<<a;
  else
  	  for(register int i=1;i<=a;i++)
  		  cout<<b;
  return cout<<endl,0;
}

Measured memory_bytes: 256