akhauriyash/Code-Regression huggingface dataset:
h, w, k = map(int, input().split())
S = [[int(s) for s in list(input())] for i in range(h)]
ans = 10**4
for b in range(2**(h-1)):
    cnt = bin(b).count('1')
    B = format(b, 'b').zfill(h-1)+'1'
    T = [[0]*w for i in range(cnt+1)]
    for j in range(w):
        t, c = 0, 0
        for i in range(h):
            t += S[i][j]
            if B[i] == '1':
                T[c][j] += t
                t = 0
                c += 1
    if max([max(T[i]) for i in range(cnt+1)]) > k:
        continue
    A = [T[i][0] for i in range(cnt+1)]
    tmp = cnt
    for j in range(1, w):
        A = [A[i]+T[i][j] for i in range(cnt+1)]
        if any([a > k for a in A]):
            A = [T[i][j] for i in range(cnt+1)]
            tmp += 1
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 55388
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,t=0,c;
    cin>>a;
    int ar[a+1];

    for(int i=0; i<a; i++)
    {
        cin>>ar[i];

    }
    c=ar[0];
    for(int i=1; i<a; i++)
    {

        if(c>ar[i])
        {
            t++;
            c=ar[i];

        }
    }
    cout<<t+1<<endl;

    return 0;
}



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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    double x, a, b;
    cin >> x >> a >> b;

    if (abs(x - a) < abs(x - b))
        cout << "A" << endl;
    else
        cout << "B" << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
count=0
countt=0
for t in range(1,n+1):
    for i in range(countt,n):
        if a[i]!=t:
            count+=1
            countt+=1
        else:break
    countt+=1
if count==n:
    print(-1)
else:
    print(count)

Measured memory_bytes: 77772
# AGC 025 A - Digits Sum
n = int(input())
cnt=0
sum_of_min = 999999999999999999
for a in range(1,n):
    b = n - a
    sum_of_a = sum([int(c) for c in str(a)])
    sum_of_b = sum([int(c) for c in str(b)])
    sum_of_n = sum_of_a + sum_of_b

    if sum_of_n < sum_of_min:
        sum_of_min = sum_of_n
        
print(sum_of_min)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,m,a[55],b[55],c[55],d[55];
  cin>>n>>m;
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];

  for(int i=0;i<m;i++)
    cin>>c[i]>>d[i];

  for(int i=0;i<n;i++){
    int ans,data=1;
    for(int j=0;j<m;j++){
      int sma = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(j == 0)
	ans=sma;
      else if(sma<ans){
	ans=sma;
	data=j+1;
      }
    }
    cout<<data<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
A, B, K = list(map(int, input().split()))

def exchange(a, b):
  if a % 2 == 1:
    a -= 1
  half = a/2
  return (half, b+half)

for i in range(K):
  if i % 2 == 0:
    A, B = exchange(A, B)
  else:
    B, A = exchange(B, A)

print(int(A), int(B))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
#define ll long long

int main(){
    ll r,d,x;
    cin >> r >> d >> x;
    ll i;
    for(i=0;i<10;i++){
        x=r*x-d;
        cout << x <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include <stack>
#include <string.h>
using namespace std;



int main() {
	string c;
int i;
cin >> c;
if (c[2]=='\0') {
	cout << c[0] << c[1] << endl;
}

else {
	cout << c[2] << c[1] << c[0] << endl;
}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
ll n,k;
ll a[210000];
bool C3(ll x,ll z){
  return a[x]>=z;
}
ll upper3(ll l,ll r,ll z){//条件を満たす中で最小のものを返す
  ll lb=l-1,ub=r+1;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(C3(mid,z)) ub=mid;
    else lb=mid;
  }
  return ub;
}
bool C4(ll x,ll z){
  return a[x]>=z;
}
ll upper4(ll l,ll r,ll z){//条件を満たす中で最小のものを返す
  ll lb=l-1,ub=r+1;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(C4(mid,z)) ub=mid;
    else lb=mid;
  }
  return ub;
}

bool C2(ll x,ll z){
  return a[x]<=z;
}
ll lower2(ll l,ll r,ll z){//条件を満たす中で最大のものを返す
  ll lb=l-1,ub=r+1;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(C2(mid,z)) lb=mid;
    else ub=mid;
  }
  return lb;
}

bool C5(ll x,ll z){
  return a[x]<=z;
}
ll lower5(ll l,ll r,ll z){//条件を満たす中で最大のものを返す
  ll lb=l-1,ub=r+1;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(C5(mid,z)) lb=mid;
    else ub=mid;
  }
  return lb;
}

bool C(ll x){
  ll cnt = 0;
  ll cnt2=0;
  rep(i,n){
    if(x>=0){
      if(a[i]>0){
	cnt += lower2(0,n-1,x/a[i])+1;
	//	if(x==18) cout << a[i] << " " << lower2(0,n-1,x/a[i]) << "\n";
      }
      else if(a[i]<0){
	cnt += n-upper3(0,n-1,x/a[i]);
	//	if(x==18) cout << upper3(0,n-1,x/a[i]) << "\n";	
      }
      else{
	cnt += n;
      }
    }
    else{
      if(a[i]>0){
	cnt += lower5(0,n-1,(x-a[i]+1)/a[i])+1;
	//	cnt += lower5(0,n-1,x/a[i])+1;	
      }
      else if(a[i]<0){
	cnt += n-upper4(0,n-1,(x+a[i]+1)/a[i]);
	//	if(x==-4) cout << upper4(0,n-1,(x+a[i]+1)/a[i]) << "\n";
      }
    }
    if(a[i]*a[i]<=x) cnt2++;
    //    if(x==18) cout << cnt << "\n";
  }
  // cout << x << ":" << cnt2 << "\n";
  // cout << x << ":" << cnt << "\n";
  return (cnt-cnt2)/2>=k;
}
ll upper(ll l,ll r){//条件を満たす中で最小のものを返す
  ll lb=l-1,ub=r+1;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(C(mid)) ub=mid;
    else lb=mid;
  }
  return ub;
}

int main()
{
  cin >> n >> k;
  rep(i,n) cin >> a[i];

  sort(a,a+n);
  
  ll in=-1e+18;
  ll ax=1e+18;;
  cout << upper(in,ax) << "\n";
  
  return 0;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long K, X, Y;
	cin >> K >> X >> Y;
	if (K % 2 == 0 && (X + Y) % 2 != 0) {
		cout << -1 << endl;
		return 0;
	}
	vector<pair<long long, long long> > ANS;
	bool Swap = false, Xm = false, Ym = false;
	if (X < 0) Xm = true, X = -X;
	if (Y < 0) Ym = true, Y = -Y;
	if (X < Y) Swap = true, swap(X, Y);
	if (X + Y < K) {
		if ((X + Y) % 2 == 1) {
			ANS.push_back({ X, X - K });
			ANS.push_back({ (K + 3 * X - Y) / 2, (X - K + Y) / 2 });
			ANS.push_back({ X,Y });
			cout << ANS.size() << endl;
			for (int i = 0; i < ANS.size(); i++) {
				long long ANSX = ANS[i].first, ANSY = ANS[i].second;
				if (Swap) swap(ANSX, ANSY);
				if (Xm) ANSX = -ANSX;
				if (Ym) ANSY = -ANSY;
				cout << ANSX << " " << ANSY << endl;
			}
		}
		else {
			ANS.push_back({ (X + Y) / 2, (X + Y - 2 * K) / 2 });
			ANS.push_back({ X,Y });
			cout << ANS.size() << endl;
			for (int i = 0; i < ANS.size(); i++) {
				long long ANSX = ANS[i].first, ANSY = ANS[i].second;
				if (Swap) swap(ANSX, ANSY);
				if (Xm) ANSX = -ANSX;
				if (Ym) ANSY = -ANSY;
				cout << ANSX << " " << ANSY << endl;
			}
		}
		return 0;
	}
	long long P = (K - (X + Y) % K) % K;
	long long N;
	if (P % 2 == 0) N = (X + Y + K - 1) / K;
	else            N = (X + Y + K - 1) / K + 1;
	long long A = (N * K - X - Y) / 2;
	long long B = X;
	long long C = (N * K - X + Y) / 2;
	long long NOWX = 0, NOWY = 0;
	for (int i = 1; i <= N; i++) {
		if (i * K <= A) {
			ANS.push_back({ 0, -i * K });
		}
		else if (i * K <= A + B) {
			ANS.push_back({ i * K - A, -A });
		}
		else {
			ANS.push_back({ X, i * K - A * 2 - B });
		}
	}
	cout << ANS.size() << endl;
	for (int i = 0; i < ANS.size(); i++) {
		long long ANSX = ANS[i].first, ANSY = ANS[i].second;
		if (Swap) swap(ANSX, ANSY);
		if (Xm) ANSX = -ANSX;
		if (Ym) ANSY = -ANSY;
		cout << ANSX << " " << ANSY << endl;
	}
}

Measured memory_bytes: 5484
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

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

        vll a(n+1);
        REP(i,1,n){
                cin >> a[i];
                a[i]--;
        }
        a[0] = 0;
        REP(i,1,n){
                a[i] += a[i-1];
                a[i] %= k;
        }
        unordered_map<ll,ll> mp;
        ll ans = 0;
        REP(i,0,n){
                if(i - k >= 0){
                        mp[a[i-k]]--;
                }

                ans += mp[a[i]];
                mp[a[i]]++;
        }
        cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  int count = 10000;
  for (int i=1; i<N-1; i++){
    int j = N - i;
    int i1 = i%10;
    int i10 = i/10%10;
    int i100 = i/100%10;
    int i1000 = i/1000%10;
    int i10000 = i/10000%10;
    int i100000 = i/100000%10;
    int isum = i1+i10+i100+i1000+i10000+i100000;
    int j1 = j%10;
    int j10 = j/10%10;
    int j100 = j/100%10;
    int j1000 = j/1000%10;
    int j10000 = j/10000%10;
    int j100000 = j/100000%10;
    int jsum = j1+j10+j100+j1000+j10000+j100000;
    count = min(count, isum+jsum);
  }
  if (N == 2){
    cout << 2 << endl;
  }
  else cout << count << endl;
}


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


int main() {
    int n;
    scanf("%d" , &n);
    int w = 0;
    for (int i = 0 ; i < n ; ++ i) {
        int x;
        scanf("%d" , &x);
        if (x & 1) ++ w;
    }
    puts(w & 1 ? "NO" : "YES");
}


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

struct UnionFind{
    vector<int> parent;
    vector<int> size;
    vector<int> rank;

    /* constructor (initialize) */
    UnionFind(int n){
        parent.resize(n);
        size.resize(n);
        rank.resize(n);
        for(int i=0; i<n; i++){
            parent[i] = i;// completely-disjoint
            size[i] = 1;
            rank[i] = 0;// union by rank
        }
    }

    int root(int x){
        // terminal case
        if(parent[x] == x){
            return x;// by definition
        }

        // recursion
        parent[x] = root(parent[x]);// path compression : keep tree as shallow as possible
        return parent[x];
    }

    void merge(int x, int y){
        int rx = root(x);
        int ry = root(y);

        // if (root(x) == root(y)) do nothing;
        if (rx != ry){
            if(rank[rx] < rank[ry]){
                parent[rx] = ry;// root of merged tree = ry
                size[ry] += size[rx];
            }
            else if(rank[rx] == rank[ry]){
                parent[rx] = ry;
                size[ry] += size[rx];
                rank[ry] += 1;
            }
            else if(rank[rx] > rank[ry]){
                parent[ry] = rx;// root of merged tree = rx
                size[rx] += size[ry];
            }
        }
        return;
    }

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

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

int main(){
    long long int n, m;
    cin >> n >> m;

    vector<int> x(m), y(m), z(m);
    for(int i=0; i<m; i++){
        cin >> x[i] >> y[i] >> z[i];
        x[i] -= 1;
        y[i] -= 1;
    }
    
    UnionFind uf(n);
    for(int i=0; i<m; i++){// for each edge
        if(uf.same(x[i],y[i]) == false){
            uf.merge(x[i], y[i]);
        }
    }
    
    set<int> roots;
    for(int i=0; i<n; i++){
        roots.insert(uf.root(i));
    }
    cout << roots.size() << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>

using namespace std;

string solve(string s) {
    int num = -1;
    int count = 0;
    string message = "";
    string chars[] = {
        ".,!? ", "abc", "def",
        "ghi", "jkl", "mno",
        "pqrs", "tuv", "wxyz"
    };
    for (int i = 0; i < (int)s.length(); ++i) {
        if (s[i] == '0') {
            if (num > 0) {
                int len = chars[num - 1].length();
                message += chars[num - 1][(count + len - 1) % len];
            }
            count = 0;
            num = -1;
        } else {
            ++count;
            num = s[i] - '0';
        }
    }
    return message;
}

int main() {
    int n;
    string s;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        cout << solve(s) << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
const ll INF = 100000000000ll;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;

int main(){
	ll n,m,l;
	std::cin >> n>>m>>l;
	vector<ll>a(m),b(m),c(m);
	rep(i,m)std::cin >> a[i]>>b[i]>>c[i];
	ll q;
	std::cin >> q;
	vector<ll>s(q),t(q);
	rep(i,q)std::cin >> s[i]>>t[i];
	
	std::vector<std::vector<ll>> d(n,vector<ll>(n,INF));
	std::vector<std::vector<ll>> dd(n,vector<ll>(n,INF));
	rep(i,n)d[i][i]=0ll;
	rep(i,m){
		if(c[i]<=l){
			d[a[i]-1][b[i]-1]=1ll;
			d[b[i]-1][a[i]-1]=1ll;
		}
	}
	
	rep(i,n)dd[i][i]=0ll;
	rep(i,m){
		if(c[i]<=l){
			dd[a[i]-1][b[i]-1]=c[i];
			dd[b[i]-1][a[i]-1]=c[i];
		}
	}
	for (int i = 0; i < n; i++)      // 経由す頂点
     for (int j = 0; j < n; j++)    // 開始頂点
       for (int k = 0; k < n; k++)  // 終端
         dd[j][k] = min(dd[j][k], dd[j][i] + dd[i][k]);
	rep(ii,2){
	for (int i = 0; i < n; i++)      // 経由す頂点
     for (int j = 0; j < n; j++)    // 開始頂点
       for (int k = 0; k < n; k++)  // 終端
         d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
       
       
    rep(i,n)rep(j,n){
    	if(d[i][j]<INF&&d[i][j]>=1&&dd[i][j]<=l)d[i][j]=1;
    }}

    rep(i,q){
    	if(d[s[i]-1][t[i]-1]==INF)std::cout << -1 << std::endl;
    	else std::cout << max(d[s[i]-1][t[i]-1]-1,0ll)<< std::endl;
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main()
{
	int n;
	cin >> n;
	double v[n+1];
	rep(i,n) cin >> v[i];
	sort(v,v+n);
	double ans = v[0];
	srep(i,1,n){
		ans += v[i];
			//	cout << ans << " mmans" << endl;

		ans /= 2.0;
		//cout << ans << " ans" << endl;
	}
	cout <<ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

avg1 = sum(a) // n
avg2 = (sum(a) // n) + 1
ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += abs(a[i] - avg1) ** 2
    ans2 += abs(a[i] - avg2) ** 2

print(min(ans1,ans2))

Measured memory_bytes: 3064
import sys
import fractions

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
NS = list(str(N))

q, mod = divmod(N, 10)
i = -1
while q:
    if mod < 8:
        NS[i:] = ['9' for i in range(-i)]
        NS[i-1] = str(int(NS[i-1]) - 1)
    i -= 1
    q, mod = divmod(q, 10)

print(sum(map(int, NS)))


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

using namespace std;

int main(void) {
  int h, r;
  cin >> h >> r;

  int ans = 0;
  if (h + r > 0) {
    ans = 1;
  } else if (h + r < 0) {
    ans = -1;
  }
  cout << ans << endl;

  return 0;
}


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

int N;

int main(){
	cin >> N;
	if(N <= 500){
		cout << N << endl;
		for(int i = 1 ; i <= N ; ++i)
			for(int j = 1 ; j <= N ; ++j)
				cout << i << " \n"[j == N];
	}
	else{
		cout << 500 << endl;
		for(int i = 1 ; i <= 500 ; ++i)
			for(int j = 1 ; j <= 500 ; ++j){
				int val = (i & 1) * 500 + (i + j) % 500 + 1;
				if(val > 500 && val <= 1500 - N) val -= 500;
				if(val > 500) val -= 1000 - N;
				cout << val << " \n"[j == 500];
			}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>
#include <fstream>


int main(){
	int N, a[100001];
	long int sum=0;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
		if(i != 0){
			sum += abs(a[i]-a[i-1]); 
		}
	}
	sum += abs(a[0])+abs(a[N-1]);
	cout << sum-abs(a[0])-abs(a[1]-a[0])+abs(a[1]) <<endl;

	for(int i = 1; i < N-1; i++){
		cout << sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]) << endl;
	}
	cout << sum-abs(a[N-1]-a[N-2])-abs(a[N-1])+abs(a[N-2]) << endl;
	return 0;
}

Measured memory_bytes: 1664
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut s: Vec<i64> = vec![0; n + 1];
    let mut t: Vec<i64> = vec![0; n + 1];
    for i in 0..n {
        s[i + 1] = s[i] + a[i];
    }
    for i in 0..n {
        t[i + 1] = t[i] + max(a[i], 0);
    }

    let mut ans = 0;
    for i in 0..n - k + 1 {
        ans = max(ans, t[i] + max(0, s[i + k] - s[i]) + t[n] - t[i + k]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
k = 1 
result = 0
if K < N:
    while k <= K:

        result += X
        k += 1
    while k <= N:

        result += Y
        k += 1
if K >= N:
    while k <= N:
        result += X
        k += 1
print(result)


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b,t;
  cin >> a >> b >> t;
  t /= a;
  cout << t * b << endl;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m,k=map(int,input().split())
friend=[[] for _ in range(n)]
block=[[] for _ in range(n)]
a=UnionFind(n)
for i in range(m):
    x,y=map(int,input().split())
    friend[x-1].append(y-1)
    friend[y-1].append(x-1)
    a.union(x-1,y-1)
for i in range(k):
    x,y=map(int,input().split())
    block[x-1].append(y-1)
    block[y-1].append(x-1)
ans=[]
for i in range(n):
    ans.append(a.size(i)-len(friend[i])-sum(a.same(i,j) for j in block[i])-1)
print(*ans)

Measured memory_bytes: 51696
#include<iostream>
using namespace std;
int t[100][100];
int a[100][100];
int n,flg;

void print();
int T(int y,int x){
  if(0<=y&&y<10&&0<=x&&x<10)return t[y][x];
  return 1;
}

int Tdraw(int y,int x,int z){
  if(0<=y&&y<10&&0<=x&&x<10)t[y][x]+=z;
}

void drawsmall(int y,int x,int z){
  Tdraw(y,x,z);Tdraw(y+1,x,z);Tdraw(y-1,x,z);Tdraw(y,x-1,z);Tdraw(y,x+1,z);
}
void drawmid(int y,int x,int z){
  drawsmall(y,x,z);
  Tdraw(y+1,x+1,z);Tdraw(y-1,x-1,z);Tdraw(y+1,x-1,z);Tdraw(y-1,x+1,z);
}
void drawlarge(int y,int x,int z){
  drawmid(y,x,z);
  Tdraw(y+2,x,z);Tdraw(y-2,x,z);Tdraw(y,x-2,z);Tdraw(y,x+2,z);
}


bool small(int y,int x){
  if(T(y,x)>=1&&T(y+1,x)>=1&&T(y-1,x)>=1&&T(y,x-1)>=1&&T(y,x+1)>=1)return true;
  else return false;
}
bool mid(int y,int x){
  if(small(y,x)){
    if(T(y-1,x-1)>=1&&T(y+1,x-1)>=1&&T(y-1,x+1)>=1&&T(y+1,x+1)>=1){
      return true;
    }
  }
  return false;
}
bool large(int y,int x){
  if(mid(y,x)){
    if(T(y-2,x)>=1&&T(y+2,x)>=1&&T(y,x+2)>=1&&T(y,x-2)>=1){
      return true;
    }
  }
  return false;
}

void check(int y,int x,int cnt){
  /*
  cout<<y<<' '<<x<<' '<<cnt<<endl;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cout<<t[i][j];
    }
    cout<<endl;
  }
  */
  if(y==10&&x==0&&cnt==n){
    print();
    flg=1;
  }
  if(flg)return;
  if(cnt>n)return;

  if(t[y][x]==0)check((x==9?y+1:y),(x==9?0:x+1),cnt);

  if(large(y+2,x)&&y+2<10){
    drawlarge(y+2,x,-1);a[y+2][x]+=10000;
    check(y,x,cnt+1);
    drawlarge(y+2,x,1);a[y+2][x]-=10000;
  }
  if(small(y+1,x)&&y+1<10){
    drawsmall(y+1,x,-1);a[y+1][x]++;
    check(y,x,cnt+1);
    drawsmall(y+1,x,1);a[y+1][x]--;
  }
  if(mid(y+1,x+1)&&y+1<10&&x+1<10){
    drawmid(y+1,x+1,-1);a[y+1][x+1]+=100;
    check(y,x,cnt+1);
    drawmid(y+1,x+1,1);a[y+1][x+1]-=100;
  }

  
}


void dfs(int x,int cnt){
  if(flg)return;
  if(x==10){
    check(0,0,cnt);
    return;
  }
  if(small(0,x)){
    drawsmall(0,x,-1);
    a[0][x]++;
    dfs(x,cnt+1);
    a[0][x]--;
    drawsmall(0,x,1);
  }
  if(mid(0,x)){
    drawmid(0,x,-1);
    a[0][x]+=100;
    dfs(x,cnt+1);
    a[0][x]-=100;
    drawmid(0,x,1);
  }
  if(large(0,x)){
    drawlarge(0,x,-1);
    a[0][x]+=10000;
    dfs(x,cnt+1);
    a[0][x]-=10000;
    drawlarge(0,x,1);
  }
  dfs(x+1,cnt);
}

int main(){
  flg=0;
  cin>>n;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>t[i][j];
      a[i][j]=0;
      //cout<<t[i][j]<<' ';
    }
    //cout<<endl;
  }
  dfs(0,0);
  return 0;
}

void print(){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      while(a[i][j]>=10000){
	cout<<j<<" "<<i<<" "<<'3'<<endl;
	a[i][j]-=10000;
      }
      while(a[i][j]>=100){
	cout<<j<<" "<<i<<" "<<'2'<<endl;
	a[i][j]-=100;
      }
      while(a[i][j]>=1){
	cout<<j<<" "<<i<<" "<<'1'<<endl;
	a[i][j]-=1;
      }
    }
  }
}

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

const int N=19000;
int n;
string s;

bool func(vector<int>a,int x){
    if(x<0)return 0;
    int dp1[20000],dp2[20000];
    for(int i=0;i<=x;i++){
        dp1[i]=0;
        dp2[i]=0;
    }
    dp1[0]=1;
    for(int i=0;i<a.size();i++){
        for(int j=0;j<=x;j++)if(dp1[j]){
            dp2[j+a[i]]=1;
            dp2[j]=1;
        }
        swap(dp1,dp2);
        for(int j=0;j<=x;j++)dp2[j]=0;
        //for(int j=0;j<=10;j++)printf("%d ",dp1[j]);
        //printf("\n");
    }
    if(dp1[x]!=0)return 1;
    else return 0;
}

int main(){

    int x,y;
    vector<int>a,b;

    cin>>s>>x>>y;
    n=s.length();
    int flag=0;///x
    int now=-1;
    for(int i=0;i<n;i++){
        if(s[i]=='T'){
            if(now==-1)x-=i;
            else{
                if(flag){
                    int tmp=i-now-1;
                    y+=tmp;
                    b.push_back(2*tmp);
                }
                else{
                    int tmp=i-now-1;
                    x+=tmp;
                    a.push_back(2*tmp);
                }
            }
            now=i;
            flag=1-flag;
        }
    }
    if(now==-1)x-=n;
    else{
        if(flag){
            int tmp=n-now-1;
            y+=tmp;
            b.push_back(2*tmp);
        }
        else{
            int tmp=n-now-1;
            x+=tmp;
            a.push_back(2*tmp);
        }
    }

    /*printf("%d:",x);
    for(int i=0;i<a.size();i++)printf("%d ",a[i]);
    printf("\n");
    printf("%d:",y);
    for(int i=0;i<b.size();i++)printf("%d ",b[i]);
    printf("\n");
*/

    if(func(a,x)&&func(b,y))printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,t,cnt=0,temp=0;
    cin>>A>>B;
    for(int i=A; i<=B; i++)
    {
        temp= i;
        t=0;
        while(temp!=0)
        {
            t=(t*10)+(temp%10);
            temp/=10;
        }
        if(A==t)
            cnt++;

            A++;
    }

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


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

#define int long long
signed  main(void)
{

    while(true){
        vector<int> A;
        int n, l, r;
        int con = 0;
        
        cin>>n>>l>>r;

        if(!n && !l && !r) break;

        A.resize(n);
        
        for(int i = 0; i < n; i++){
            cin>>A[i];
        }

        for(int i = l; i <= r; i++){
            bool flag = !(n%2);
            for(int j = 0; j < n; j++){
                if(i%A[j] == 0){
                    if(j%2 == 0) flag = true;
                    else flag = false;
                    break;
                }
            }
            if(flag) con++;
        }

        cout<<con<<endl;
    }
    return 0;
}



Measured memory_bytes: 3024
#include<stdio.h>

#define MAX 100000
#define SEN 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card *,int,int,int,int);
void mergeSort(struct Card *,int,int,int);
int partition(struct Card *,int,int,int);
void quickSort(struct Card *,int,int,int);

int main(){
  int n,i,a;
  struct Card A[MAX],B[MAX];
  char s[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++)
  {
    scanf("%s %d",s,&a);
    A[i].suit = B[i].suit = s[0];
    A[i].value = B[i].value = a;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++)
  {
    if(A[i].suit != B[i].suit)stable = 0;
  }

  if(stable == 1)
  {
    printf("Stable\n");
  }
  else 
  { 
    printf("Not stable\n"); 
    }

  for(i=0;i<n;i++)
  {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

void merge(struct Card A[],int n, int left,int mid,int right)
{
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i=0;i<n1;i++)
  {
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++)
  {
    R[i] = A[mid + i];
  }

  L[n1].value = R[n2].value = SEN;

  i = j = 0;
  for(k=left;k<right;k++)
  {
    if(L[i].value <= R[j].value)
    {
      A[k] = L[i++];
    }
    else {A[k] = R[j++];}
  }
}

void mergeSort(struct Card A[],int n,int left,int right)
{
  int mid;

  if(left + 1 < right)
  {
    mid = (left + right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[],int n ,int p,int r)
{
  int i,j;
  struct Card t,x;

  x = A[r];
  i = p - 1;
  for(j=p;j<r;j++)
  {
    if(A[j].value <= x.value)
    {
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;

  return i + 1;
}

void quickSort(struct Card A[],int n, int p, int r)
{
  int q;

  if(p < r)
  {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}



Measured memory_bytes: 4048
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <math.h>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  long long a,v;
  long long b,w;

  cin >> a >> v;
  cin >> b >> w;
  long long t;
  cin >> t;

  long long diff = abs(b - a);
  long long speed = (v - w);

  if (speed <= 0) {
    cout << "NO" << endl;
    return 0;
  }

  if ((diff - (speed * t)) <= 0)  {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    int N;
    int t[110000],x[110000],y[110000];
    t[0] = x[0] = y[0] = 0;
    bool can = true;

    cin >> N;
    for (int i=0; i<N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];

    for ( int i=0; i<N; ++i)
    {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]- y[i]);
        if (dt<dist) can = false;
        if (dt%2 != dist%2) can = false;
    }

    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
	char tmp;
	long long int sum=0;
	scanf("%c",&tmp);
	while(tmp!='\n'){
		sum+=(tmp-48);
		//printf("%lld\n",sum);
		scanf("%c",&tmp);
	}
	
	if(sum%9){
		printf("No");
	}else{
		printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 1644
n = int(input())
c = list(input())

i = 0
j = len(c)-1
cnt = 0

while i < j:
  if c[i] == "R":
    i += 1
    continue
  if c[j] == "W":
    j -= 1
    continue
  i += 1
  j -= 1
  cnt += 1
print(cnt)

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

int main() {
    int N,Y;
    cin>>N>>Y;

    int a,b,c,y = -1,h = -1,n = -1;

    for(a=0;a<=N;++a){
        for(b=0;b<=N;++b){
            c = N-b-a;
            if(c < 0)break;
            else if(Y == a*10000 + b*5000 + c*1000){
                y = a;
                h = b;
                n = c;
            }
        }
    }

    cout<<y<<" "<<h<<" "<<n<<endl;
}





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

int f[101][11],p[101][11],b[11];
int main()
{
	ios::sync_with_stdio(false);
	int n,ans=-1000000000;
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=10;j++)
			cin>>f[i][j];
	for(int i=1;i<=n;i++)
		for(int j=0;j<=10;j++)
			cin>>p[i][j];
	b[10]=1;
	while(1){
		int x=10;
		while(b[x]==1) b[x]=0,x--;
		b[x]=1;
		if(x==0) break;
		x=0;
		for(int i=1;i<=n;i++)
		{
			int s=0;
			for(int j=1;j<=10;j++)
				if(f[i][j]==1&&b[j]==1) s++;
			x+=p[i][s];
		}
		ans=max(ans,x);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
int partition(int *,int,int);

int main()
{

  int i,q,n,A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  q=partition(A,0,n-1);
  for(i=0;i<n;i++)
    {
      if(i)printf(" ");
      if(i==q)printf("[");
       printf("%d",A[i]);
        if(i==q)printf("]");
    }
  printf("\n");
  return 0;
}


int partition(int *A,int p,int r)
{
  int x,j,a,i;
  x = A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j]<=x)
	{
	  i=i+1;
	  a=A[i];
	  A[i]=A[j];
	  A[j]=a;
	}
    }
  a=A[i+1];
  A[i+1]=A[r];
  A[r]=a;
  return i+1;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
	//Enter your code here Tanmay:)
	int n,a,b;
	cin>>n>>a>>b;
	int x=a+b;
	int res=n/x;
	int res1=n%x;
	if(res1<=a)
		res1=res1;
	else
		res1=a;
	cout<<a*res+res1;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 ) 
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(s: String) -> bool {
    let mut v = s.chars().collect::<Vec<char>>();
    v.sort();

    v.into_iter().collect::<String>() == "abc"
}

fn main() {
    let s = parse_line!(String);
    println!("{}", if solve(s) { "Yes" } else { "No"});
}

#[test]
fn solve_test() {
    assert_eq!(solve("abc".to_string()), true);
    assert_eq!(solve("bab".to_string()), false);
    assert_eq!(solve("bac".to_string()), true);
    assert_eq!(solve("aaa".to_string()), false);
}


Measured memory_bytes: 4352
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int s = sc.nextInt();

		HashSet<Integer> set = new HashSet<Integer>();

		set.add(s);
		int i = 2;

		while(true){
			if(s % 2 == 0){
				s /= 2;
			}
			else {
				s = s*3 + 1;
			}

			if(set.contains(s)){
				System.out.println(i);
				return;
			}

			set.add(s);
			i++;
		}

	}

}


Measured memory_bytes: 21716
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, a, b = rli()
    p = n // (a+b)
    ans = p*a+min(n%(a+b), a)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import sys
from heapq import heappush, heappushpop
X, Y, Z = map(int, input().split())
xyz = sorted([list(map(int,l.split()))for l in sys.stdin],key=lambda x:x[0]-x[1])

uq = []
cy = 0
for x, y, z in xyz[:Y]:
    heappush(uq, y - z)
    cy += y
Ly = [cy]
for x, y, z in xyz[Y:Y+Z]:
    cy += y - heappushpop(uq, y - z)
    Ly += [cy]

lq = []
cx = 0
for x, y, z in xyz[-X:]:
    heappush(lq, x - z)
    cx += x
Lx = [cx]
for x, y, z in xyz[Y+Z-1:Y-1:-1]:
    cx += x - heappushpop(lq, x - z)
    Lx += [cx]

print(max(map(sum, zip(Lx, Ly[::-1]))))

Measured memory_bytes: 39108
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

long N;
int res = 0;

void dfs(string s) {
    if (stol(s) > N) {
        return;
    }
    int n = s.size();
    map<char, int> m;
    REP(i, n) {
        m[s[i]]++;
    }
    if (m['3'] > 0 && m['5'] > 0 && m['7'] > 0) {
        res++;
    }
    dfs(s + "3");
    dfs(s + "5");
    dfs(s + "7");
}

// main
int main() {
    cin >> N;
    dfs("3");
    dfs("5");
    dfs("7");
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define maxx ((ll)1e6+5)
#define pb push_back
#define ins insert
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expo(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
using namespace std;//ok i saw
signed main()
{
    int n,W,i,j,k;
    cin >> n >> W;
    int w[n+1],v[n+1];
    for(i=1 ; i<=n ; i++)
    	cin >> w[i] >> v[i];
    int d[n+1][W+1];
    for(i=0 ; i<=n ; i++)
		for(j=0 ; j<=W ; j++)
			d[i][j] = 0;
	for(i=1 ; i<=n ; i++)
		for(j=1 ; j<=W ; j++)
		{
			d[i][j] = max(d[i-1][j] , d[i][j-1]);
			if(w[i] <= j)
				d[i][j] = max(d[i][j] , v[i] + d[i-1][j-w[i]]);
		}
	cout << d[n][W] <<"\n";
    return 0;
}

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

int main(){
    string S,s,A,B,a,b;;
    cin>>S;
    s=S;
    reverse(s.begin(),s.end());
    
    A = S.substr(0,(S.size()-1)/2);
    a = A;
    reverse(a.begin(),a.end());
    B = S.substr((S.size()+1)/2,S.size());
    b = B;
    reverse(b.begin(),b.end());
    
    bool flag = true;
    if(S!=s){
        flag = false;
    }
    if(A!=a){
        flag = false;
    }
    if(B!=b){
        flag = false;
    }

    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    ll N, a, b;
    cin >> N;
    a = N / 500;
    N = N % 500;
    b = N / 5;
    cout << (a * 1000 + b * 5) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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


        a = sc.nextInt();


        b = sc.nextInt();
        int add=a+b;
        int sub=a-b;
        int mul=a*b;
        int values[] = {add,sub,mul};
        int max =values[0];
        if(-1000<=a&a<=1000&-1000<=b&b<=1000){
           for (int index = 1; index < values.length; index ++) {
            max = Math.max(max, values[index]);
        }

        }
        System.out.println(max);

    }
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int ans = (h - a) * (w - b);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

using LL = long long;


signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    string s;
    cin >> s;
    auto ss = s;
    reverse(s.begin(), s.end());
    int l = s.length();
    
    int ans = 0;
    for (int i = 0; i < l; i++) {
        if(ss[i] != s[i]) ans++;
    }
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  VV<> a; assign(a, 1001, 1001);
  for (int i = 0; i < n; ++i) {
    int xl, yl, xr, yr; cin >> xl >> yl >> xr >> yr;
    ++a[xl][yl], --a[xl][yr], --a[xr][yl], ++a[xr][yr];
  }
  for (int x = 0; x < 1001; ++x) for (int y = 0; y < 1000; ++y) a[x][y + 1] += a[x][y];
  for (int y = 0; y < 1001; ++y) for (int x = 0; x < 1000; ++x) a[x + 1][y] += a[x][y];
  int res = 0;
  for (auto&& v : a) res = max(res, *max_element(begin(v), end(v)));
  cout << res << '\n';
}


Measured memory_bytes: 6804
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;
  cin >> N >> M;
  priority_queue<ll> que;
  REP(i,N) {
      ll ai;
      cin >> ai;
      que.push(ai);
  }

  REP(i,M){
      ll c = que.top(); que.pop();
      que.push(c/2);
  }

  ll ans = 0;
  while(!que.empty()){
      ans += que.top(); que.pop();
  }

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


Measured memory_bytes: 1528
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  return N % 2 === 0 ? N : N * 2;
};

console.log(main(read()));


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

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>s(n);vector<int>v(m);
    vector<vector<int> >a(n,vector<int>(m));
    REP(i,n) REP(j,m) cin>>a.at(i).at(j);
    REP(i,m) cin>>v.at(i);
    
    REP(i,n)
    {
        int sum=0;
        REP(j,m)
        {
            sum+=a.at(i).at(j)*v.at(j);
        }
        cout<<sum<<endl;
    }
}



Measured memory_bytes: 3168
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n, m;
    string u[260], t;
    bool fnd, dor=false;
    cin>>n;
    for (int i=0; i<n; i++) cin>>u[i];
    cin>>m;
    for (int i=0; i<m; i++)
    {
        fnd=false;
        cin>>t;
        for (int j=0; j<n; j++) if (t==u[j]) fnd=true;
        if (fnd && dor) { cout<<"Closed by "; dor=false; }
        else if (fnd && !dor) { cout<<"Opened by "; dor=true; }
        else cout<<"Unknown ";
        cout<<t<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3224
h,w = (int(x) for x in input().split())
ab = []
count = 0
for _ in range(h):
    a = input()
    a = a+'#'
    ab.append(list(a))
    for i in a:
        if i == '.':
            count += 1
ab.append(list('#'*w))
dp = [[0 for i in range(w)] for j in range(h)]
 
step = [[0, 0]]
dp[0][0] = 1
 
while len(step) > 0:
    y, x = step.pop(0)
    if y == h-1 and x == w-1:
        print(count-dp[y][x])
        exit()
    if ab[y+1][x] == '.' and dp[y+1][x] == 0 :
        step.append([y+1, x])
        dp[y+1][x] = dp[y][x] + 1
    if ab[y][x+1] == '.' and dp[y][x+1] == 0 :
        step.append([y, x+1])
        dp[y][x+1] = dp[y][x] + 1
    if ab[y-1][x] == '.' and dp[y-1][x] == 0 :
        step.append([y-1, x])
        dp[y-1][x] = dp[y][x] + 1
    if ab[y][x-1] == '.' and dp[y][x-1] == 0 :
        step.append([y, x-1])
        dp[y][x-1] = dp[y][x] + 1
 
 
print(-1)   

Measured memory_bytes: 3188
r, c = map(int, input().split())

matrix = [list(map(int, input().split())) for _ in range(r)]

for i in range(r):
    matrix[i].append(sum(matrix[i]))

matrix.append(list(map(sum, zip(*matrix))))
# matrix.append([sum(i) for i in zip(*matrix)])

for row in matrix:
    print(*row)


Measured memory_bytes: 6228
#include<iostream>
#include<string>

using namespace std;

int main() {
	int A, B, C;	cin >> A >> B >> C;
	if (A == 5) {
		if (B == 5) {
			if (C == 7) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	if (A == 5) {
		if (B == 7) {
			if (C == 5) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	if (A == 7) {
		if (B == 5) {
			if (C == 5) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m;
vll G[10];

ll ans=0;
void dfs(ll v, set<ll> s){
  s.insert(v);
  
  if(s.size()==n){
    ans++;
    return;
  }
  
  for(auto nv: G[v]){
    if(s.count(nv)) continue;
    dfs(nv, s);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m;
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  set<ll> s;
  dfs(0,s);
  cout<<ans<<endl;
}

Measured memory_bytes: 256