akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

ll x, y, z, k, a[1005], b[1005], c[1005];
vector<ll> ab, abc;
int main() {
	int i, j, sz;
	cin >> x >> y >> z >> k;
	for(i=0; i<x; i++) cin >> a[i];
	for(i=0; i<y; i++) cin >> b[i];
	for(i=0; i<z; i++) cin >> c[i];
	for(i=0; i<x; i++) for(j=0; j<y; j++) {
		ab.push_back(a[i] + b[j]);
	}
	sort(ab.begin(), ab.end());
	sz = min(k, (ll)ab.size());
	for(i=0; i<z; i++) for(j=0; j<min(k, (ll)ab.size()); j++) {
		abc.push_back(c[i] + ab[ab.size()-1-j]);
	}
	sort(abc.begin(), abc.end());
	for(i=0; i<k; i++) {
		cout << abc[abc.size()-1-i] << endl;
	}
	return 0;
}

Measured memory_bytes: 43236
#include<stdio.h>
int main(){
int i,j,max=0,com=0,c;
char a[15][15];
for(i=0;i<14;i++){
for(j=0;j<14;j++){
a[i][j]='0';
}
}
while(scanf("%c",&a[1][1])!=EOF){
for(i=1;i<13;i++){
for(j=1;j<13;j++){
if(i!=1 || j!=1){
scanf("%c",&a[i][j]);
}
}
scanf("\n");
}
scanf("\n");
for(i=1;i<13;i++){
for(j=1;j<13;j++){
if(a[i][j]=='1'){
if(a[i+1][j]=='2'){
max=1;
}
if(a[i][j+1]=='2'){
max=1;
}
if(a[i][j-1]=='2'){
max=1;
}
if(a[i-1][j]=='2'){
max=1;
}
if(max==0){
com++;
a[i][j]='2';
}
else{
a[i][j]='2';
}
max=0;
}
c=j;
if(a[i][j]!='0'){
while(a[i+1][c]!='0'){
a[i+1][c]='2';
c--;
}
}
}
}
printf("%d\n",com);
com=0;
for(i=0;i<14;i++){
for(j=0;j<14;j++){
a[i][j]='0';
}
}
}
return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvi dp;

int main(){
	cin>>n>>m;
	m--;
	dp=vvi(2,vi(m+1));
	for(int i=0;i<n;i++){
		int w,v;
		cin>>w>>v;
		vvi DP=dp;
		for(int j=0;j<=m;j++) DP[1][j]=max(DP[1][j],dp[0][j]+v);
		for(int j=m-w;j>=0;j--){
			DP[0][j+w]=max(DP[0][j+w],dp[0][j]+v);
			DP[1][j+w]=max(DP[1][j+w],dp[1][j]+v);
		}
		dp=DP;
	}
	int res=0;
	for(int i=0;i<=m;i++) res=max({res,dp[0][i],dp[1][i]});
	cout<<res<<endl;
}

Measured memory_bytes: 256
A, B, K = (int(i) for i in input().split())  

st = max(A, B)
cnt = 0
for i in range(st)[::-1]:
    j = i + 1
    if (A%j==0) & (B%j==0):
        cnt += 1
    if cnt == K:
        ans = j
        break

print(ans)

Measured memory_bytes: 3060
<>=~$";@a=glob`dd`;$a[$_-1]%2&&++$a[$%=$_%$'?$_:$_-1+$']*$%&&push@_,"
@{[map{$_/$'+1|0,$_%$'+1}$_-1,$%]}"for 1..$`*$'-1;print@_+0,@_

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, K;
  cin >> N >> K;
  vector<string> P(N);
  REP(i,N) cin >> P[i];

  vector<int> alpha(26, 0);
  REP(i,N) alpha[P[i][0] - 'A']++;
  int res = 0;
  while(1) {
    sort(alpha.rbegin(), alpha.rend());
    if(alpha[K - 1] == 0) break;
    REP(i,K) alpha[i]--;
    res++;
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 896
import math

n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]

if k == 0 and max(a) == 0:
    print(sum(a))
else:
    l = int(math.log2(max(k, max(a))))
    mask = int(math.pow(2, l))

    f = False
    gsum = 0

    for i in reversed(range(0, l + 1)):
        psum = 0
        for j in range(0, n):
            psum += 1 if (a[j] & mask) != 0 else 0 
        
        if f:
            if psum <= n // 2:
                gsum += mask * (n - psum)
            else:
                gsum += mask * psum
        else:
            if (k & mask) != 0:
                if psum > n // 2:
                    gsum += mask * psum
                    f = True
                else:
                    gsum += mask * (n - psum)
            else:
                gsum += mask * psum
        mask = mask >> 1
    print(gsum)

Measured memory_bytes: 14620
#include<stdio.h>
int main()
{
	int n, ma, mb;
	scanf("%d %d %d", &n, &ma, &mb);
	int i, j, k;
	int a[44], b[44], c[44];
	for (i = 0; i < n; i++)
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
	int dp[2][402][402];
	for (j = 0; j < 402; j++)
		for (k = 0; k < 402; k++)
			dp[0][j][k] = dp[1][j][k] = 1000000009;
	dp[0][0][0] = dp[1][0][0] = 0;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 402 - a[i]; j++)
			for (k = 0; k < 402 - b[i]; k++)
				if (dp[1][j + a[i]][k + b[i]] > dp[0][j][k] + c[i])
					dp[1][j + a[i]][k + b[i]] = dp[0][j][k] + c[i];
		for (j = 0; j < 402; j++)
			for (k = 0; k < 402; k++)
				dp[0][j][k] = dp[1][j][k];
	}
	int ans = 1000000009;
	for (i = 1; (ma * i < 402) && (mb * i < 402); i++)
		if (ans > dp[0][ma * i][mb * i])
			ans = dp[0][ma * i][mb * i];
	if (ans < 1000006)
		printf("%d\n", ans);
	else
		printf("-1\n");
	return 0;
}

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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

double dp[3000][3000];

void resolve()
{
    int N;
    cin >> N;
    vector<double> p(N + 1);
    RPT1(i, N) cin >> p[i];

    // dp[i][j] : i枚目まで投げた時、表がj枚である確率
    dp[0][0] = 1;
    RPT1(i, N) dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    RPT1(i, N)
    RPT(j, 1, i) dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);

    double ans = 0.0;
    RPT(j, N / 2 + 1, N) ans += dp[N][j];
    printf("%.10f\n", ans);
}

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


Measured memory_bytes: 68992
#include <iostream>
#include <vector>
#include <queue>
#define INF 1e+9
using namespace std;

int main() {
	int n,m;
	int lose[5000] = {};
	vector<int> edge[5000];
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		lose[b - 1]++;
		edge[a - 1].push_back(b - 1);
	}
	int flag = 0;
	queue<int> que;
	for(int i = 0;i < n;i++) {
		if(!lose[i]) que.push(i);
	}
	while(!que.empty()){
		if(que.size() >= 2) flag = 1;
		int q = que.front();que.pop();
		cout << q + 1 << endl;
		for(int i = 0;i < edge[q].size();i++){
			lose[edge[q][i]]--;
			if(lose[edge[q][i]] == 0) que.push(edge[q][i]);
		}
	}
	cout << flag << endl;
	return 0;
}

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

const int MAX_N = 1e5+1;
vector<int> graph[MAX_N], ans;
bool visited[MAX_N];

void dfs(int x) {
    visited[x] = true;
    ans.push_back(x);
    for (int i : graph[x]) {
        if (!visited[i]) {
            dfs(i);
            break;
        }
    }
}

int main() {
    int N, M, a, b;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1);
    reverse(ans.begin(), ans.end());
    ans.pop_back();
    dfs(1);

    cout << ans.size() << endl;
    for (int i: ans) {
        cout << i << " ";
    }
    cout << endl;
}

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

void solve(long long N){
	if(N == 3) {
		cout << "2 5 63" << endl;
		return;
	}
	int sum = 0;
	vector<int> res;
	for(int i = 2; res.size() < N - 2; ++i) if(i % 2 == 0 || i % 3 == 0) {
		res.push_back(i);
		sum += i;
	}
	int b = res.back(), c = b + 1;
	if(sum % 6 == 1 || sum % 6 == 3 || sum % 6 == 5) {
		while(c % 6 != 3) {
			c++;
		}
	} else {
		while(c % 6 == 1 || c % 6 == 3 || c % 6 == 5) {
			++c;
		}
	}
	sum += c;
	res.push_back(c);

	int t = b + 1;
	while((sum + t) % 6 != 0 || t == c) {
		++t;
	}
	res.push_back(t);

	for(int i = 0; i < N; ++i) {
		cout << res[i] << (i == N - 1 ? "\n" : " ");
	}
}

int main(){	
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(void){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int out=0,base=0,point=0;
		while(out<3){
			string event;
			cin >> event;
			if(event == "OUT"){
				out++;
			}else if(event == "HIT"){
				if(base == 3){
					point++;
				}else{
					base++;
				}
			}else{
				point += base + 1;
				base = 0;
			}
		}
		cout << point << endl;
	}
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<ll>>;

struct UnionFind {
  vector<ll> par;

  UnionFind(ll n) : par(n,-1){}
  void init(ll n) { par.assign(n, -1); }

  ll root(ll x){//xを根とする連結成分
    if(par[x]<0) return x;
    else return par[x] = root(par[x]);
  }

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

  bool merge(ll x, ll y){
    x = root(x);
    y = root(y);
    if(x==y) return false;
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  ll size(ll x){
    return -par[root(x)];
  }
};

int main(){
    ll N,M; cin>>N>>M;
    vector<pair<ll,ll>> B;
    rep(i,M){
        ll a,b; cin>>a>>b;
        B.push_back({a-1,b-1});
    }
    reverse(B.begin(),B.end());
    vector<ll> res;
    ll now = N*(N-1)/2;
    UnionFind T(N);
    rep(i,M){
        res.push_back(now);
        ll a = B.at(i).first,b = B.at(i).second;
        if(T.same(a,b)) continue;
        ll n1 = T.size(a);
        ll n2 = T.size(b);
        now -= n1*n2;
        T.merge(a,b);
        
    }
    reverse(res.begin(),res.end());
    rep(i,res.size())cout<<res.at(i)<<endl;
}


Measured memory_bytes: 5488
n = int(input())
list = []
for i in range(n):
    list += [int(input())]

max_ = max(list)
for i in range(n):
    a = list[i]
    if a == max_:
        del list[i]
        ans = max(list)
        print(ans)
        list.insert(i,a)
        if ans == max_:
            for j in range(n-i-1):
                print(max_)
            break
    else:
        print(max_)

Measured memory_bytes: 12520
#include <stdio.h>
using namespace std;
using ll = long long;

int main(void) {
	ll A;
	int b1, b2;
	scanf("%lld %d.%d", &A, &b1, &b2);
	printf("%lld\n", A * (b1 * 100 + b2) /  100);
	return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int dp[3000][3000];
string getLCS(string s,string t,int len){
	string ans;
	int i = 0,j = 0;
	while(len>0){
		if(s[i]==t[j]){
			ans.push_back(s[i]);
			i++;
			j++;
			len--;

		}
		else{
			if(dp[i+1][j] > dp[i][j+1])
				i++;
			else
				j++;
		}
	}
	return ans;
	
}
int lenLCS(string&s,string&t,int i,int j){
	if(i>=s.length() || j>=t.length()){
		return 0;
	}
	if(dp[i][j]!=-1){
		return dp[i][j];
	}

	if(s[i]==t[j]){
		return dp[i][j] = 1 + lenLCS(s,t,i+1,j+1);
	}
	return dp[i][j] = max(lenLCS(s,t,i,j+1),lenLCS(s,t,i+1,j));
}
string solve(string s,string t){
	memset(dp,-1,sizeof(dp));
	int len = lenLCS(s,t,0,0);
	return getLCS(s,t,len);
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	string s,t;
	cin>>s>>t;
	cout<<solve(s,t)<<endl;
	return 0;
}

Measured memory_bytes: 39224
def in_data(ts):
    while True:
        t = tuple(map(int, input().split(' ')))
        if t[0] == 0 and t[1] == 0:
            break
        ts.append(t)


def out_data(ts):
    for t in ts:
        cnt = 0
        for i in range(1, t[0] + 1):
            for j in range(i + 1, t[0] + 1):
                for k in range(j + 1, t[0] + 1):
                    if k == i or k == j:
                        continue
                    if i + j + k == t[1]:
                        cnt += 1
        print(cnt)


ts = []
in_data(ts)
out_data(ts)



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, A; cin >> N >> A;
  vector<ll> x(N), y(N + 1);
  for(ll i = 0; i < N; i++) cin >> x.at(i);
  for(ll i = 1; i <= N; i++) y.at(i) = x.at(i - 1) - A;
  vector<vector<ll>> dp(N + 1, vector<ll> (2 * N * N + 1, 0));
  dp.at(0).at(N * N) = 1;
  for(ll i = 1; i <= N; i++) {
    for(ll j = 0; j <= 2 * N * N; j++) {
      dp.at(i).at(j) = dp.at(i - 1).at(j);
      if(j - y.at(i) >= 0 && j - y.at(i) <= 2 * N * N) {
        dp.at(i).at(j) += dp.at(i - 1).at(j - y.at(i));
      }
    }
  }
  cout << dp.at(N).at(N * N) - 1 << endl;
}

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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] str = br.readLine().split(" ");
		Set<Integer> S = new TreeSet<Integer>();
		for(int i = 0; i < n; i++){
			S.add(Integer.parseInt(str[i]));
		}
		int m = Integer.parseInt(br.readLine());
		str = br.readLine().split(" ");
		for(int i = 0; i < m; i++){
			int b = Integer.parseInt(str[i]);
			if(S.contains(b)) S.remove(b);
			else S.add(b);
		}
		for(Integer num : S) System.out.println(num);
	}
}



Measured memory_bytes: 144068
local function gcd(a,b)
    if b == 0 then
        return a
    else
        return gcd(b, a % b)
    end
end
-----
local A,B,C = io.read("n","n","n")
local m = A % B
local function solve()
    if m == 0 then
        return C == 0
    else
        local g = gcd(B, m)
        if g == 1 then
            return true
        else
            return C % g == 0
        end
    end
end
print(solve() and 'YES' or 'NO')

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

using namespace std;

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

    vector<int> h(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }

    // 足場iに辿り着くまでに支払うコストの総和の最小値dp[i]
    vector<int> dp(N+1, 1500000000);

    // 初期条件
    dp[1] = 0;
    

    // dp開始
    for (int i = 2; i <= N; i++) {
        for (int k = 1; k <= K; k++) {
            if (i - k < 1) {
                break;
            }
            
            dp[i] = min(dp[i], dp[i-k] + abs(h[i-k] - h[i]));
        }
    }

    cout << dp[N] << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    double t,x;cin>>t>>x;
    cout<<fixed<<setprecision(15)<<t/x<<endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;

int main() {
    ll a,b;
    cin >> a >> b;
    map<ll,ll> fa,ck;
    ll n=a,m=b;
    for(ll i=2;i<=sqrt(a);i++){
        while(n%i==0){
            n /= i;
            fa[i]++;
        }
    }
    fa[1]++;
    fa[n]++;
    for(ll i=2;i<=sqrt(b);i++){
        while(m%i==0){
            m /= i;
            ck[i]++;
        }
    }
    ck[1]++;
    ck[m]++;
    ll ans=0;
    for(auto i:fa){
        if(ck[i.first]!=0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3704
import java.util.Scanner;

public class Main {

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

        int D = sc.nextInt();
        int G = sc.nextInt();
        int[] p = new int[D];
        int[] c = new int[D];

        for (int i = 0; i<D; i++) {
            p[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        System.out.println(solve(D, G, p, c));
    }

    /**
     * 参考実装のJava移植版
     */
    private static int solve(int D, int G, int[] p, int[] c) {
        int ans = Integer.MAX_VALUE;

        // i桁の値が1なら問題iを完全に解く
        for (int mask=0; mask<(1<<D); mask++) {
            int score = 0, num = 0, rest_max = -1;

            // maskに対応したスコアを算出する
            for (int i=0; i<D; i++) {
                if ((mask>>i & 1) == 1) {
                    score += 100 * (i+1) * p[i] + c[i];
                    num += p[i];
                } else {
                    // 中途半端に解く問題 (完全に解く問題以外で最大の配点となる問題)
                    rest_max = i;
                }
            }

            if (score < G) {
                int s1 = 100 * (rest_max + 1);
                int need = (G - score + s1 - 1) / s1;
                if (need >= p[rest_max]) {
                    // このmaskと中途半端に解く問題の組合せでは総合スコアをG以上にできない
                    continue;
                }

                num += need;
            }
            ans = Math.min(ans, num);
        }

        return ans;
    }
}

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

int main(){
 int a,b,c;
 cin >> a >> b >> c;
 int i,j,k;
 i=max(max(a,b),c);
 j=min(min(a,b),c);
 k=a+b+c-i-j;
 cout << j << " " <<  k << " " <<  i << endl;
}
 



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

#define FOR(i,x) for(int i=0; i<x; i++)
#define FORic(i,y,x) for(int i=y; i<=x; i++)
#define FORdc(i,y,x) for(int i=y; i>=x; i--)

vector<string> all;
int w, h;
int masu[12];
int l, r;
bool check[62][12];

void tadoru(int i, int j){
	if(i<1) return;
	if(j<1) return;
	if(i>h) return;
	if(j>w) return;
	if(all[i][j] == '.') return;
	if(check[i][j]) return;
	else check[i][j] = true;
	masu[j]++;
	tadoru(i-1, j);
	if(all[i][j]==all[i][j-1]){
		tadoru(i, j-1);
	}
	if(all[i][j]==all[i][j+1]){
		tadoru(i, j+1);
	}
	if(all[i][j]==all[i+1][j]){
		tadoru(i+1, j);
	}
}

void siraberu(int i, int j){
	if(i<1) return;
	if(j<1) return;
	if(i>h) return;
	if(j>w) return;
	if(all[i][j] == '.') return;
	if(check[i][j]) return;
	else check[i][j] = true;
	if(all[i+1][j] != all[i][j]){
		if(all[i+1][j] != '.'){
			l = min(l, j);
			r = max(r, j);
		}
	}
	if(all[i][j]==all[i-1][j]){
		siraberu(i-1, j);
	}
	if(all[i][j]==all[i][j-1]){
		siraberu(i, j-1);
	}
	if(all[i][j]==all[i][j+1]){
		siraberu(i, j+1);
	}
	if(all[i][j]==all[i+1][j]){
		siraberu(i+1, j);
	}
}

void init_check(){
	FOR(i2, h+2){
		FOR(j2, w+2){
			check[i2][j2] = false;
		}
	}
}

int main(){
	while(cin>>w>>h){
		if(!w&&!h) break;
		all.clear();
		string buf;
		string tmpue;
		string tmpsita;
		FOR(i, w+2){
			tmpue += '.';
		}
		all.push_back(tmpue);
		FOR(i,h){
			cin>>buf;
			string tmp;
			tmp += '.';
			tmp += buf;
			tmp += '.';
			all.push_back(tmp);
		}
		FOR(i, w+2){
			tmpsita += '#';
		}
		all.push_back(tmpsita);
		bool dame = false;
		FORdc(i, h, 1){
			FORic(j, 1, w){
				if(all[i][j]!='.'){
					FOR(n,12) masu[n] = 0;
					l = 15;
					r = -1;
					init_check();
					tadoru(i, j);
					init_check();
					siraberu(i, j);
					int g=0;
					int sum=0;
					FORic(n,1,w){
						g += (2*n-1)*masu[n];
						sum += masu[n];
					}
					if(g<=(l-1)*2*sum || r*2*sum<=g){
						dame = true;
						break;
					}
				}
			}
			if(dame) break;
		}
		if(dame){
			cout<<"UNSTABLE"<<endl;
		} else {
			cout<<"STABLE"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int f(int n,int d){
  return n/d;
}
int main(){
  int l,r,d;
  cin>>l>>r>>d;
  int ans=f(r,d)-f(l-1,d);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3548
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int pass = 0;
        int abroad = 0;
        for (int i = 0 ; i < n ; i++) {
            if (s[i] == 'a' && pass < a + b) {
                System.out.println("Yes");
                pass++;
            } else if (s[i] == 'b' && pass < a + b && abroad < b) {
                System.out.println("Yes");
                pass++;
                abroad++;
            } else {
                System.out.println("No");
            }
        }
    }

}


Measured memory_bytes: 35092
A, B, C, X, Y = map(int, input().split())

x1 = min(X, Y)
price = min((A+B) * x1, 2 * C * x1)
x2 = max(X, Y) - x1
a = A if X > Y else B
price += min(a * x2, 2 * C * x2)
print(price)


Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = " " + sc.next();
        String t = " " + sc.next();
        int lens = s.length(), lent = t.length();
        int[][] dp = new int[lens][lent];
        int[][] path = new int[lens][lent];

        dp[0][0] = 0;

        int[] dx = {1, 0, 1}, dy = {0, 1, 1};
        for (int i = 1; i < lens; i++) {
            for (int j = 1; j < lent; j++) {
                if (s.charAt(i) == t.charAt(j) && dp[i - 1][j - 1] + 1 > dp[i][j]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    path[i][j] = 2;
                }
                if (dp[i][j] < dp[i - 1][j]) {
                    dp[i][j] = dp[i - 1][j];
                    path[i][j] = 0;
                }
                if (dp[i][j] < dp[i][j - 1]) {
                    dp[i][j] = dp[i][j - 1];
                    path[i][j] = 1;
                }
            }
        }

        int ps = lens - 1, pt = lent - 1;
        LinkedList<Character> sb = new LinkedList<>();

        while (ps != 0 && pt != 0) {
            if (path[ps][pt] == 2) {
                sb.addFirst(s.charAt(ps));
            }
            int ns = ps - dx[path[ps][pt]];
            int nt = pt - dy[path[ps][pt]];
            ps = ns; pt = nt;
        }
        String ans = sb.stream().map(c -> "" + c).collect(Collectors.joining("", "", ""));
        System.out.println(ans);
    }
}


Measured memory_bytes: 130632
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 4e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	cout << (a * 3 + b) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import product as pro

n = int(input())
a = []
xy = []
for i in range(n):
    a_i = int(input())
    a.append(a_i)
    xy.append([tuple(map(int, input().split())) for _ in range(a_i)])

ans = 0
for l in pro([0, 1], repeat=n):
    for i, t in enumerate(l):
        if t == 1:
            if not all(l[x-1] == y for x, y in xy[i]):
                break
    else:
        ans = max(ans, sum(l))

print(ans)


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

typedef struct{
	string name;
	int score;
}Team;

int main(void){
	int n;
	bool firstFlg = true;
	
	while(cin>>n && n){
		if(!firstFlg) cout<<endl;
		else firstFlg = false;
	
		Team t[n];
		for(int i=0;i<n;i++){
			int win,lose,draw;
			
			cin>>t[i].name>>win>>lose>>draw;
			t[i].score = win*3 + draw;
		}
		
		for(int i=0;i<n-1;i++){
			for(int j=0;j<n-1;j++){
				if(t[j].score < t[j+1].score){
					Team tmp = t[j];
					t[j] = t[j+1];
					t[j+1] = tmp;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			cout<<t[i].name<<","<<t[i].score<<endl;
		}
	}

	return 0;
}

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

int main() {
	int N, H, tmp, ans = 1;
	cin >> N >> tmp;
	for (int i = 1; i < N; ++i) {
		cin >> H;
		if (tmp <= H) ++ans;
		tmp = max(tmp, H);
	}
	cout << ans << endl;
}

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

typedef bitset<10000> bs;
int R, C;
int check(const vector<bs>& s) {
    int res = 0;
    rep(j, C) {
        int cnt = 0;
        rep(i, R) if(s[i][j]) cnt++;
        res += max(cnt, R - cnt);
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> R >> C && R) {
        vector<bs> senbei(R, bs(0));
        bool in_;
        rep(i, R) rep(j, C) {
            cin >> in_;
            if(in_) senbei[i][j] = 1;
        }
        bs to_rev(0); rep(i, C) to_rev[i] = 1;
        vector<bs> temp;
        int ans = 0;
        rep(S, 1 << R) {
            temp = senbei;
            rep(i, R) if((S >> i) & 1)
              temp[i] ^= to_rev;
            ans = max(ans, check(temp));
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
  int n,s,w,q,a[100100];
  while(cin >> n >> s >> w >> q, n){
    int g = s;
    rep(i,n){
      a[i] = (g/7) % 10;
      g = (g/2) ^ ((g%2)*w);
    }

    int ans = 0, non_zeros = 0;
    if(q==2 || q==5){
      rep(i,n){
	if(a[i])non_zeros++;
	if(a[i]%q == 0)ans += non_zeros;
      }
    }else{
      unordered_map<int,int> memo;
      memo.reserve(400400);
      memo[0] = 1;
      int rem = 0, k = 1;
      for(int i=n-1;i>=0;i--){
	rem = (rem + a[i] * k) % q;
	(k *= 10) %= q;
	if(a[i])ans += memo[rem];
	memo[rem]++;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 7616
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long int
void findAns()
{
    int a, b;
    cin >> a >> b;

    if (a == b or (a + b) % 2 == 0)
    {
        cout << (a + b) / 2;
    }
    else
    {
        cout << "IMPOSSIBLE";
    }
}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
//     cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s" << "\n";
// #endif

    FAST;
    ll  t = 1;
    //cin >> t;

    while (t--) findAns();
}


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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> xs(n), ys(n);
	for (int64_t i = 0; i < n; i++)
	{
		cin >> xs[i] >> ys[i];
	}

	vector<pair<int64_t, int64_t>> ps(n);
	for (int64_t i = 0; i < n; i++)
	{
		ps[i] = {xs[i], ys[i]};
	}
	sort(ps.begin(), ps.end());

	int64_t ans = n;

	for (int64_t i = 0; i < n; i++)
	{
		for (int64_t j = 0; j < n; j++)
		{
			if (i == j)
			{
				continue;
			}
			int64_t p = ps[j].first - ps[i].first, q = ps[j].second - ps[i].second;
			int64_t tmp = 0;
			for (int64_t k = 0; k < n; k++)
			{
				auto itr = lower_bound(ps.begin(), ps.end(), make_pair(ps[k].first - p, ps[k].second - q));
				if (itr != ps.end() && (*itr) == make_pair(ps[k].first - p, ps[k].second - q))
				{
					tmp++;
				}
			}
			ans = min(ans, n - tmp);
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    int H, W;
while(1){
    cin>>H>>W;
if(H==0 && W==0)break;
else
    for(int i=1;i<=H;i+=1){
        for(int j=1;j<=W;j+=1){
            cout<<"#";
           }
        cout<<endl;
       }
    cout<<endl;
}
    return 0;
}


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

int main() {
  int num[13] = {0,0,2,0,1,0,1,0,0,1,0,1,0};
  int x, y;
  cin >> x >> y;
  printf("%s\n", (num[x] == num[y])?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		if ( k%2==0 || k%5==0 ) {
			System.out.println("-1");
			System.exit(0);
		}

		int[] r = new int[1000000];
		Arrays.fill(r, -1);

		int s = 7;
		int t = 1;

		while ( r[s]==-1 ) {
			if ( s%k==0 ) {
				System.out.println(t);
				System.exit(0);
			}
			r[s] = s%k;
			s = ( s*10 + 7 ) % k ;
			t++;
		}
		System.out.println("-1");
	}
}

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

using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m,d; cin >> m >> d;
    int res=0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            int d1=j/10;
            int d2=j%10;
            //cout<<s[0]<<endl;
            if(d1 < 2 || d2 < 2)continue;
            if(i == d1*d2){
                res++;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(_i,_m,_n) for(ll _i = (_m); _i <= (_n); _i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll h, w, a[100][100], b;
bool g[100][100][13000];

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> h >> w;
	rep(i, 1, h){rep(j, 1, w){cin >> a[i][j];}}
	rep(i, 1, h){rep(j, 1, w){cin >> b; a[i][j] = abs(a[i][j]-b);}}
	
	memset(g, 0, sizeof(g));
	g[1][1][a[1][1]] = true;
	rep(i, 1, h){
		rep(j, 1, w){
			rep(k, 0, 12800){
				if(g[i][j][k]){
					g[i+1][j][abs(k+a[i+1][j])] = true;
					g[i+1][j][abs(k-a[i+1][j])] = true;
					g[i][j+1][abs(k+a[i][j+1])] = true;
					g[i][j+1][abs(k-a[i][j+1])] = true;
				}
			}	
		}	
	}

	rep(k, 0, 12800){
		if(g[h][w][k]){
			print(k)
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 127232
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <numeric>
#include <array>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b))?(b):(a))
#define chmin(a, b) a = (((a)<(b))?(a):(b))

const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};

#define lengthof(x) (sizeof(x) / sizeof(*(x)))


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

bool contain(int mask, int position){
  if((mask&(1<<position))) return true;
  else return false;
}


class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};


signed main(){
	int n; cin>>n;
	VI p(n), q(n), r(n);
  rep(i,n) cin>>p[i];
  rep(i,n) cin>>q[i];
  VVI v;
  iota(ALL(r), 1);
  do{
    v.PB(r);
  }while(next_permutation(ALL(r)));
  int a = lower_bound(ALL(v), p)-v.begin();
  int b = lower_bound(ALL(v), q)-v.begin();
  cout << abs(a-b) << endl;


  return 0;
}


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


def main():
    H, W, K = map(int, input().split())
    cake = [[0]*W for _ in range(H)]
    sb = []
    for y in range(H):
        s = input().strip()
        for x, c in enumerate(s):
            if c == "#":
                sb.append((y, x))
    for i, (y, x) in enumerate(sb):
        cake[y][x] = i+1

    import collections
    for i, s in enumerate(sb):
        Q = collections.deque()
        Q.appendleft(s[1])
        y = s[0]
        while Q:
            x = Q.pop()
            if x-1 >= 0 and cake[y][x-1] == 0:
                cake[y][x-1] = i+1
                Q.appendleft(x-1)
            if x+1 <= W-1 and cake[y][x+1] == 0:
                cake[y][x+1] = i+1
                Q.appendleft(x+1)

    for y in range(1, H):
        for x in range(W):
            if cake[y][x] == 0:
                cake[y][x] = cake[y-1][x]
    for y in range(H-2, -1, -1):
        for x in range(W):
            if cake[y][x] == 0:
                cake[y][x] = cake[y+1][x]

    for c in cake:
        print(*c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50844
import java.util.Scanner;

public class Main{
 public static void main(String[] args){
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 }
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    vector<int> left(n + 1), right(n + 1);
    for (int i = 0; i < n; i++) left[i + 1] = max(left[i], a[i]);
    for (int i = n - 1; i >= 0; i--) right[i] = max(right[i + 1], a[i]);
    for (int i = 0; i < n; i++) {
        cout << max(left[i], right[i + 1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>

using namespace std;

int main(){
    long long H;
    while(cin >> H){
        long long res = 0;
        long long num = 1;
        while(H > 0){
            res += num;
            H = H/2;
            num *= 2;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{

	static Scanner sc = new Scanner(System.in);
	
	static String str;
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		str = sc.nextLine();
		
		return true;
	}
	
	public static void solve(){
		
		System.out.println(str.toUpperCase());
		
	}

}

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

int bucket[30];

int main(){
	string s;
	cin >> s;
	for(int i = 0; i < (int)s.size(); i++)
		bucket[s[i]-'a']++;
	for(int i = 0; i < 26; i++) {
		if(bucket[i] >= 2) {
			printf("no\n");
			return 0;
		}
	}
	printf("yes\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <map>
#include <functional>
#include <queue> 

using namespace std;

typedef long long ll;

int t[100005];
ll d[100005];
vector<pair<ll,int> >vec;
int mp[100005];

struct sushi {
int ti;
ll di;
bool operator > (const sushi &n)const {
return di > n.di;}
}eat;

int main() {
	
	priority_queue<sushi, vector<sushi>, greater<sushi> >pque;
	
	int N,K;
	
	scanf("%d %d",&N,&K);
	
	int i;
	
	for(i=0;i<N;i++){
		scanf("%d %lld",&t[i],&d[i]);
		vec.push_back(make_pair(d[i],t[i]));
	}
	
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	
	ll sum=0ll;
	ll x=0ll;
	int pos=K;
	
	for(i=0;i<K;i++){
	sum+=vec[i].first;
	mp[vec[i].second]++;
	eat.di=vec[i].first;
	eat.ti=vec[i].second;
	pque.push(eat);
	}
	
	for(i=1;i<=N;i++){
		if(mp[i]>0){x+=1ll;}
	}
	
	ll ans=sum+(x*x);
	
	sushi tmp,tmp2;
	
	while(1){
		
		if(pos>=N || pque.empty()){break;}
		
		tmp=pque.top();pque.pop();
		
		if(mp[tmp.ti]==1){continue;}
		
		for(i=pos;i<N;i++){
			if(mp[vec[i].second]==0){break;}
		}
		
		if(i<N){
		
		ll score=(sum-tmp.di)+(vec[i].first)+((x+1ll)*(x+1ll));
		
		tmp2.di=vec[i].first;
		tmp2.ti=vec[i].second;
		
		pque.push(tmp2);
		x+=1ll;
		sum=sum-tmp.di+vec[i].first;
		mp[tmp.ti]--;
		mp[vec[i].second]++;
		ans=max(ans,score);
		pos=i;
		}
		else{
			break;
		}
	}
	
	printf("%lld\n",ans);
	
	return 0;
}

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

#define forn(i,m,n) for(int i=m;i<n;i++)
#define vv vector
#define vi vv<int>
#define ii pair<int,int>
#define vii vv<ii>
#define mp make_pair
#define pb push_back
#define PI 3.141592653589
#define ll long long
#define pll pair<ll,ll>
#define vl vv<ll>
#define ff first
#define ss second
#define MOD 1000000007

bool is_prime[1000001];
vi prime;
void sieve(int n)
{
    memset(is_prime,true,sizeof(is_prime));
    for(int i=2;i*i<=n;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {
                is_prime[j]=false;
            }
        }
    }
    forn(i,2,n+1)
    {
        if(is_prime[i])
            prime.pb(i);
    }
}


ll ex(ll a,ll b)
{
    ll res=1;
    a=a%MOD;
    while(b)
    {
        if(b%2){res=(res*a)%MOD;b--;}
        b/=2;
        a=(a*a)%MOD;
    }
    return res;
}

ll fermat_inv(ll a){ return ex(a,MOD-2); }
ll max(ll a,ll b){ return a>b?a:b; }
ll min(ll a,ll b){ return a<b?a:b; }


int main()
{
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
    //sieve(1000000);
    int te=1;
    //cin>>te;
    while(te--)
    {
        int n,w;
        cin>>n>>w;
        ll v[n+1];
        ll wt[n+1];
        forn(i,1,n+1)
        {
            cin>>wt[i];
            cin>>v[i];
        }
        ll dp[n+1][w+1];
        forn(i,0,n+1)
            dp[i][0]=0;
        forn(i,0,w+1)
            dp[0][i]=0;
        forn(i,1,n+1)
        {
            forn(j,1,w+1)
            {
                if(j>=wt[i])
                    dp[i][j]=max(dp[i-1][j-wt[i]]+v[i],dp[i-1][j]);
                else
                    dp[i][j]=dp[i-1][j];
            }
        }
        cout<<dp[n][w];
    }
}


Measured memory_bytes: 82536
n = int(input())
ans=0

if n == 1:
  print(0)
  quit()

for i in range(1, n):
  #余り、商がiになるmを求める。mが整数で、余りより大きければ答えに加える。
  #iは単調増加、mは単調減少だから、mが余りより小さくなったら打ち切る。
  temp=n-i
  syou=temp/i
  if syou>i:
    if syou.is_integer():
      ans+=int(syou)
  else:
    break
print(ans)

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

int main(){
int n,m,k,tmp;
  cin >>n >>m;
  int cnt[m];
  fill(cnt,cnt+m,0);
  for(int i=0;i<n;i++){
  cin >>k;
    while(k--){
    cin >>tmp;tmp--;cnt[tmp]++;
    }     
  }
  int ans=0;
  for(int i=0;i<m;i++){
    if(cnt[i]==n)ans++;
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
numbers = input()
numArr = str.split(numbers)
numList = []
for str in numArr:
    numList.append(int(str))
numList.sort()
if len(numList) >= 2:
    sum = numList[0]
    for i in range(1, n):
        sum = (sum + numList[i])/2
    print(sum)
else:
    print('error')

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

 using namespace std;
 int main() {
   string S;
   cin >> S;
   if (S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(0)) cout << "Yes"<< endl;
   else cout << "No" << endl;
 }


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

int main(){
    int n, tmp, mi=1000000, ma=-1000000;
    long sum=0;
    
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> tmp;
        mi = min(mi,tmp);
        ma = max(ma,tmp);
        sum += tmp;
    }
    cout << mi << " " << ma << " " << sum << endl;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        boolean enable=false;
        Scanner sc=new Scanner(System.in);
        long l=sc.nextLong();
        long sum=0;
        for(long i=1;i<=l;i++){
            if(i%3 ==0 || i%5==0){
                continue;
            }
            sum +=i;
        }
        System.out.println(sum);
    }

}

Measured memory_bytes: 35840
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;

int main()
{
    int n,x,cnt=0;
    vector<int>v;
    scanf("%d",&n);
    for(int i=0;i<n; i++)
    {
        scanf("%d",&x);
        v.push_back(x);

        if(v.size()>0 && v[i-1]==x)
        {
            cnt++;
            v[i]=0;
        }
    }

    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
program tenka1_2019_c
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,cl,cr,ans
    character(:),allocatable:: s

    read*, n
    allocate(character(n):: s)
    read*, s(:)
    cl = 0
    cr = 0
    do i=1,n
        if (s(i:i) == '.') cr=cr+1
    end do

    ans = cl+cr

    do i=1,n
        if (s(i:i) == '.') then
            cr=cr-1
        else
            cl=cl+1
        end if
        ans = min(ans,cl+cr)
    end do

    print'(i0)', ans
end program tenka1_2019_c

Measured memory_bytes: 1468
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    ll k,a,b;
    cin >> k >> a >>b;
    ll ans = 0;
    if(b-a<=2||k<(a+1)){
        ans = k+1;
        cout << ans << endl;
        return 0;
    }
    k-=a-1;
    ans = a;
    ll num = k/2;
    ans += num*(b-a);
    if(k%2==1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] DP = new int[1000001];
		int[] ODD_DP = new int[1000001];
		
		for(int j = 0; j <= 1000000; j++){
			DP[j] = ODD_DP[j] = -1;
		}
		
		DP[0] = 0;
		ODD_DP[0] = 0;
		
		for(int i = 0; ; i++){
			int number = ((i + 1) * (i + 2) * (i + 3)) / 6;
			
			if(number > 1000000){
				break;
			}
			
			for(int j = 0; j <= (1000000 - number); j++){
				if(DP[j] != -1){
					if(DP[j + number] == -1){
						DP[j + number] = (DP[j] + 1);
					}else if(DP[j + number] > DP[j] + 1){
						DP[j + number] = (DP[j] + 1);
					}
				}
			}
			
			if(number % 2 == 1){
				for(int j = 0; j <= (1000000 - number); j++){
					if(ODD_DP[j] != -1){
						if(ODD_DP[j + number] == -1){
							ODD_DP[j + number] = (ODD_DP[j] + 1);
						}else if(ODD_DP[j + number] > ODD_DP[j] + 1){
							ODD_DP[j + number] = (ODD_DP[j] + 1);
						}
					}
				}
			}
		}
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			System.out.println(DP[n] + " " + ODD_DP[n]);
			
		}
		
		sc.close();
	}
}

Measured memory_bytes: 20000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A, B;

void solve(int s, int t, int mask, vector<int> &ret)
{
	if (__builtin_popcount(mask) == 1) {
		ret.push_back(s);
		ret.push_back(t);
		return;
	}
	int d = (s ^ t) & mask;
	vector<int> ones, zeros;
	for (int i = 0; i < N; ++i) if ((mask >> i) & 1) {
		if ((d >> i) & 1) {
			ones.push_back(i);
		} else {
			zeros.push_back(i);
		}
	}
	//printf("%d %d %d %d %d\n", s, t, mask, ones.size(), zeros.size());
	if (ones.size() >= 2) {
		solve(s, t ^ (1 << ones[0]) ^ (1 << ones[1]), mask ^ (1 << ones[0]), ret);
		solve(t ^ (1 << ones[1]), t, mask ^ (1 << ones[0]), ret);
	} else {
		solve(s, s ^ (1 << zeros[0]), mask ^ (1 << ones[0]), ret);
		solve(s ^ (1 << zeros[0]) ^ (1 << ones[0]), t, mask ^ (1 << ones[0]), ret);
	}
}

int main()
{
	scanf("%d%d%d", &N, &A, &B);

	if ((__builtin_popcount(A) % 2) == (__builtin_popcount(B) % 2)) {
		puts("NO");
		return 0;
	}

	vector<int> ans;
	solve(A, B, (1 << N) - 1, ans);
	puts("YES");
	for (int i = 0; i < ans.size(); ++i) {
		printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');
	}
	if (ans[0] != A || ans[(1 << N) - 1] != B) {
		puts("><");
	}
	for (int i = 1; i < ans.size(); ++i) {
		if (__builtin_popcount(ans[i - 1] ^ ans[i]) != 1) puts("><");
	}
	return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int ans1=0, ans2=0;
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  a*=100; b*=100;

  int water,maxsugar,sugar;
  for (int i=0; i<=30&&i*a<=f; i++) {
    for (int j=0; j<=30&&i*a+j*b<=f; j++) {
      if (i+j > 0) {
        water=a*i+b*j;
        maxsugar=min(water*e/100, f-water);
        sugar=0;
        for (int k=0; k<=100&&c*k<=maxsugar; k++) {
          for (int l=0; l<=100&&c*k+d*l<=maxsugar; l++) {
            sugar = max(sugar, c*k+d*l);
          }
        }
        if (ans1==0 || sugar*(ans1+ans2)>ans2*(water+sugar)) {
          ans1 = water;
          ans2 = sugar;
        }
      }
    }
  }

  cout << ans1+ans2 << " " << ans2 << endl;
}

int main()
{
  solve();
  return 0;
}


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

for i in range(K):
    if i % 2 == 0:
        if A%2 != 0:
            A -=1
        B += A/2
        A -= A/2
    else:
        if B % 2 != 0:
            B -=1
        A += B/2
        B -= B/2

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



Measured memory_bytes: 2940