akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int  A[9], B[9], n, b;

int main(){
    for (int i=1; i<=9; i++) {
        B[i]=0;
    }
    //for (int i=1; i<=9; i++) cout << B[i];
    scanf("%d %d %d\n", &A[1] , &A[2] , &A[3]);
    scanf("%d %d %d\n", &A[4] , &A[5] , &A[6]);
    scanf("%d %d %d\n", &A[7] , &A[8] , &A[9]);
    //cin >> A[4] >> A[5] >> A[6];
    //cin >> A[7] >> A[8] >> A[9];
    //for (int i=1; i<=9; i++) cout << A[i];
    scanf("%d", &n) ;
    //cout << n;
    for (int i=1; i<=n; i++){
        scanf( "%d", &b);
        //cout << b;
        for (int j=1; j<=9; j++){
            if (A[j] == b) {
                B[j]=1;
                //cout << "match";
            } 
        }
    }
    //for (int i=1; i<=9; i++) cout << B[i];

    if (B[1]==1 && B[2]==1 && B[3]==1) cout << "Yes";
    else if (B[4]==1 && B[5]==1 && B[6]==1) cout << "Yes";
    else if (B[7]==1 && B[8]==1 && B[9]==1) cout << "Yes";
    else if (B[1]==1 && B[4]==1 && B[7]==1) cout << "Yes";
    else if (B[2]==1 && B[5]==1 && B[8]==1) cout << "Yes";
    else if (B[3]==1 && B[6]==1 && B[9]==1) cout << "Yes";
    else if (B[1]==1 && B[5]==1 && B[9]==1) cout << "Yes";
    else if (B[3]==1 && B[5]==1 && B[7]==1) cout << "Yes";
    else cout << "No";
return 0;
}

Measured memory_bytes: 256
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

INF = 10**9
dp = [[INF for _ in range(H+10)] for _ in range(N+1)]

for i in range(1, N+1):
    a, b = magic[i-1]
    dp[i][0] = 0
    for j in range(1, H+1):
        dp[i][j] = min(dp[i][max(0, j-a)]+b, dp[i-1][j])

print(dp[N][H])

Measured memory_bytes: 125276
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll L[101];
int main(){
    cin>>N;
    for(ll i=0;i<N;i++)cin>>L[i];
    ll ans=0;
    for(ll i=0;i<N;i++) for(ll j=i+1;j<N;j++) for(ll k=j+1;k<N;k++){
        if(L[i]==L[j] || L[i]==L[k] || L[j]==L[k])continue;
        if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] &&L[k]+L[i]>L[j])ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <queue>

#define R register
#define maxn 100010
struct Edge {
	Edge *next;
	int to;
}*last[maxn], e[maxn << 1], *ecnt = e;
inline void link(R int a, R int b)
{
	*++ecnt = (Edge) {last[a], b}; last[a] = ecnt;
	*++ecnt = (Edge) {last[b], a}; last[b] = ecnt;
}
std::deque<int> q;
bool vis[maxn];
int main()
{
	R int n, m; scanf("%d%d", &n, &m);
	for (R int i = 1; i <= m; ++i)
	{
		R int a, b; scanf("%d%d", &a, &b);
		link(a, b);
	}
	R bool flag = 1;
	q.push_back(1); vis[1] = 1;
	while (flag)
	{
		flag = 0;
		R int a = q.front(), b = q.back();
		for (R Edge *iter = last[a]; iter && !flag; iter = iter -> next)
			if (!vis[iter -> to])
			{
				flag = vis[iter -> to] = 1;
				q.push_front(iter -> to); 
			}
		for (R Edge *iter = last[b]; iter && !flag; iter = iter -> next)
			if (!vis[iter -> to])
			{
				flag = vis[iter -> to] = 1;
				q.push_back(iter -> to);
			}
	}
	R int _;
	printf("%d\n", _ = q.size() );
	for (R int i = 0; i < _; ++i) printf("%d ", q.front() ), q.pop_front() ;
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;

char tile[20][20];
int cnt;
int add_y[4] = {0, 0, 1,-1};
int add_x[4] = {1,-1, 0, 0};

void sarch(int y, int x, int h, int w){
	if(y<0 || y==h || x<0 || x==w) return;

	if(tile[y][x] == '.'){
		cnt++;
		tile[y][x] = '#';

		/*
		for(int i=0 ; i<h ; i++){
			for(int j=0 ; j<w ; j++){
				cout << tile[i][j];
			}
			cout << endl;
		}
		*/

	}else if(tile[y][x] == '#'){
		return;
	}

	for(int i=0 ; i<4 ; i++){
		sarch(y+add_y[i], x+add_x[i], h, w);
	}
	return;
}

int main(){

	int w, h;
	int y, x;

	while(1){
		cin >> w >> h;
		if(w==0 && h==0) break;

		cnt = 0;

		for(int i=0 ; i<20 ; i++){
			for(int j=0 ; j<20 ; j++){
				tile[i][j] = '_';
			}
		}

		string temp[h];
		getline(cin , temp[0]);
		for(int i=0 ; i<h ; i++){
			getline(cin , temp[i]);
			for(int j=0 ; j<w ; j++){
				tile[i][j] = temp[i][j];
				if(tile[i][j] == '@'){
					y = i;
					x = j;
					tile[i][j] = '.';
				}
			}
		}
		sarch(y, x, h, w);
		cout << cnt << endl;
	}
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

char c[10];
ll i, j;
int main(){
    scanf("%s", c);
    printf("%c", c[0] + 1);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N,M,i;
    scanf("%d %d",&N,&M);
    int H[N],A[M],B[M],judge[N];
    for(i=0;i<N;i++){
        scanf("%d",&H[i]);
        judge[i]=1;
    }
    for(i=0;i<M;i++){
        scanf("%d%d",&A[i],&B[i]);
        if(H[A[i]-1]>H[B[i]-1]){
            judge[B[i]-1]=0;
        }else{
            if(H[A[i]-1]<H[B[i]-1]){
                judge[A[i]-1]=0;
            }else{
                judge[A[i]-1]=0;
                judge[B[i]-1]=0;
            }
        }
    }
    int ans=0;
    for(i=0;i<N;i++){
        if(judge[i]==1){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3292
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int count = 0;
    for(int i = a; i < b + 1; i++) {
      if(c % i == 0) {
        count++;
      }
    }
    System.out.println(count);
  }
}



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

int main()
{
	int R, C;
	while (cin >> R >> C, R | C) {
		vector<int> a(C);
		for (int i = 0; i < R; i++) {
			for (int j = 0; j < C; j++) {
				int b;
				cin >> b;
				a[j] |= b << i;
			}
		}
		int res = 0;
		for (int i = 0; i < (1 << R); i++) {
			int cnt = 0;
			for (int j = 0; j < C; j++) {
				int x = __builtin_popcount(a[j] ^ i);
				cnt += max(x, R - x);
			}
			res = max(res, cnt);
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 85
#define NUM 13000

int H,W;
int A[SIZE][SIZE],B[SIZE][SIZE];
bool dp[SIZE][SIZE][NUM];

bool rangeCheck(int row,int col){

	return row >= 0 && row <= H-1 && col >= 0 && col <= W-1;
}

int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			scanf("%d",&A[row][col]);
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			scanf("%d",&B[row][col]);
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			for(int i = 0; i < NUM; i++){

				dp[row][col][i] = false;
			}
		}
	}

	dp[0][0][abs(A[0][0]-B[0][0])] = true;

	ll pre_diff,diff;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(col+1 < W){ //右

				diff = abs(A[row][col+1]-B[row][col+1]);

				for(int i = 0; i < NUM; i++){
					if(!dp[row][col][i])continue;

					pre_diff = i;

					dp[row][col+1][diff+pre_diff] = true;
					dp[row][col+1][abs(diff-pre_diff)] = true;
				}
			}
			if(row+1 < H){ //下

				diff = abs(A[row+1][col]-B[row+1][col]);

				for(int i = 0; i < NUM; i++){
					if(!dp[row][col][i])continue;

					pre_diff = i;

					dp[row+1][col][diff+pre_diff] = true;
					dp[row+1][col][abs(diff-pre_diff)] = true;
				}
			}
		}
	}

	for(int i = 0; i < NUM; i++){
		if(dp[H-1][W-1][i]){

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

	return 0;
}


Measured memory_bytes: 88320
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      while(true){
        int n = sc.nextInt();
        int r = sc.nextInt();
        if(n==0 && r==0) break;


        int[] card = new int[n];
        for(int i=0;i<n;i++){
          card[i]=n-i;
        }


        for(int i=0;i<r;i++){

          int p = sc.nextInt();
          int c = sc.nextInt();

          int[] new_card = new int[p-1];
          for(int j=0;j<p-1;j++){
            new_card[j] = card[j];
          }
          for(int j=0;j<c;j++){
            card[j] = card[p-1+j];
          }
          for(int j=0;j<p-1;j++){
            card[c+j] = new_card[j];
          }
        }
        System.out.println(card[0]);
      }
    }
  }
}


Measured memory_bytes: 37024
N = int(input())
A = [int(i) for i in input().split()]

def selectionSort(A):
    count = 0
    for i in range(len(A)):
        minj = i
        for j in range(i, len(A)):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            count += 1
    return A, count

A ,count = selectionSort(A)
print(' '.join([str(i) for i in A]))
print(count)

Measured memory_bytes: 7740
#!/usr/bin/ruby
s=gets.chomp.reverse.chars.map(&:to_i)
p (1..s.size).bsearch{|m|
	x=m*9
	g=0
	!!s.each{|c|
		y=(x+g-c)%10
		x-=y
		x<0&&break
		g=(x+g)/10
	}
}

Measured memory_bytes: 33712
#include <iostream>
using namespace std;
int f(int x,int y){
    if(x<y)swap(x,y);
    if(y==0)return x;
    return f(y,x%y);
}
int s[100000],n,a[100000],b[100000],MAX;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<n-1;i++){
        a[i+1]=f(a[i],s[i]);
        b[i+1]=f(b[i],s[n-i-1]);
    }
    for(int i=0;i<n;i++){
        MAX=max(MAX,f(a[i],b[n-i-1]));
    }
    cout<<MAX<<endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#pragma GCC target("avx")
int N,K,C;
char*S;
int R[2<<17];
char buf[2<<17],out[3<<19];sz;outsz;
char c[6];
main()
{
	read(0,buf,2<<17);
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		K=K*10+k-'0';
	}
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		C=C*10+k-'0';
	}
	S=buf+sz;
	int now=K;
	for(int i=N;i-->0;)
	{
		if(S[i]=='o')
		{
			R[i]=now--;
			i-=C;
		}
	}
	now=0;
	for(int i=0;i<N;i++)
	{
		if(S[i]=='o')
		{
			if(R[i]==++now)
			{
				int t=i+1;
				int cs=6;
				do{
					c[--cs]=t%10+'0';
				}while(t/=10);
				for(;cs<6;)out[outsz++]=c[cs++];
				out[outsz++]='\n';
			}
			i+=C;
		}
	}
	write(1,out,outsz);
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int(a.size())

int main(){
	int k; cin>>k;
	int odd = 0, even = 0;
	for(int i = 1; i <= k; i++){
		if(i % 2 == 0){
			even++;
		}
		else odd++;
	}
	cout<<even * odd<<endl;
}


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

xs_arranged = sorted(xs)
l = int(n/2 - 1)
a1,a2 = xs_arranged[l],xs_arranged[l+1]
base = (a1+a2)/2
    
for i in xs:
    if i < base:
        print(a2)
    else:
        print(a1)

Measured memory_bytes: 25264
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mp = 0
ans = 0
l = []
for i in range(n):
    if a[i] < b[i]:
        mp -= b[i] - a[i]
    else:
        ans += 1
        l.append(a[i] - b[i])
l.sort(reverse=True)
for p in l:
    if mp == 0:
        break
    mp += min(p, -mp)
    ans -= 1
if mp < 0:
    print(-1)
else:
    print(n - ans)


Measured memory_bytes: 18292
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>

const long long MAXN=1e5+10;
using namespace std;
typedef long long ll;

 int main() {
 	int a,b;
 	cin>>a>>b;
	if(a+b>=10){
		cout<<"error"<<endl;
	}
	else cout<<a+b<<endl;
	
 	return 0;
 }

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

bool isCoffee(string word){
if(word.at(2) == word.at(3) && word.at(4) == word.at(5)){
    cout<<"Yes";
    return true;
}
else{
    cout<<"No";

    return false;
}
}

int main(){
    string input;
    cin >> input;
    isCoffee(input);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,ans=0,suffixSum=0, m=1000000007;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    for(int i=0;i<n;i++)
    {
        ans = ans+(suffixSum*a[i]);
        suffixSum = suffixSum + a[i];
        ans = ans%m;
        suffixSum = suffixSum%m;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4380
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function bsearch(a,x);l,r=0,length(a)+1;while r-l>1;m=(r+l)>>1;if a[m]<x;l=m;else;r=m;end;end;r;end
are(a::Array{Int,1},x::Int)=Int[i%x for i in a]

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	r = 29
	ans = 0
	for i in 1:r
		t = 2^(i-1)
		c = are(b,2t)
		c = sort(c)
		s = 0
		for j in 1:n
			x = a[j]%(2*t)
			s += bsearch(c,2t-x)-bsearch(c,t-x)+bsearch(c,4t-x)-bsearch(c,3t-x)
		end
		ans += (s%2)*t
	end
	println(ans)
end

main()

Measured memory_bytes: 170936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N; cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  rep(i, N) cin >> S[i] >> T[i];
  string X; cin >> X;
  int k = 0;
  while (S[k] != X) k++;
  k++;
  int ans = 0;
  for (int i = k; i < N; i++) ans += T[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <assert.h>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;
typedef long long ll;
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

static const ll max_n = 200010;
combination comb(max_n);


void Main(){
    ll n, k;
    cin >> n >> k;
    ll K = min(n, k+1);
    mint ans = 0;
    // 移動した人数がm人なので、各部屋1人ずつ確保した後、互いに取り合うのは移動したm人になる。
    // だから n-m H m になる
    rep(i, K){
        ans += comb(n, i) * comb(n-1, n-1-i);
    }

    cout << ans << endl;

}

int main(){
    Main();
    // string S = "ksdfjl";
    // char v = S[3];
    // S[3] = 'a';
    // cout << S <<endl;
}

Measured memory_bytes: 5784
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (c <= max(a, b) && c >= min(b, a))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

class UnionFind(n: Int) {
    private val rank = IntArray(n) { 0 }
    private val parent = IntArray(n) { -1 }

    fun find(x: Int): Int {
        if (parent[x] < 0) {
            return x
        }
        parent[x] = find(parent[x])
        return parent[x]
    }

    fun unite(x: Int, y: Int) {
        val x1 = find(x)
        val y1 = find(y)
        if (x1 == y1) {
            return
        }
        if (rank[x1] < rank[y1]) {
            parent[y1] += parent[x1]
            parent[x1] = y1
        } else {
            parent[x1] += parent[y1]
            parent[y1] = x1
            if (rank[x1] == rank[y1]) {
                rank[x1]++
            }
        }
    }

    fun same(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }

    fun size(x: Int): Int {
        return -parent[find(x)]
    }
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val uf = UnionFind(n)
    for (i in 0 until m) {
        val a = sc.nextInt() - 1
        val b = sc.nextInt() - 1
        uf.unite(a, b)
    }
    println((0 until n).map { uf.size(it) }.max()!!)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 60728
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(cin >> s){
        if(s == "#")
            return 0;
        int y,m,d;cin >> y >> m >> d;
        bool r = false;
        if(y >= 32){
            r = true;
        }
        if(y == 31 && m >= 5){
            r = true;
        }
        if(r){
            cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
        }else{
            cout<<"HEISEI"<<" "<<y<<" "<<m<<" "<<d<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int k;
  string s;
  cin >> k >> s;

  if (s.size() <= k) {
    cout << s << '\n';
  } else {
    for (int i = 0; i < k; ++i) {
      cout << s[i];
    }
    cout << "..." << '\n';
  }

  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n, k;
    cin >> n >> k;
    long long res = 0;
    for (int i = 0; i < n - 1; i++) {
        res += res / (k - 1) + 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3116
#include<stdio.h>

int main(void){

  int i,n;

  long int a,min = 1000000,max = -1000000,sum = 0;

  scanf("%d",&n);

  for(i = 1;i <= n;i++)

  {

    scanf("%ld",&a);

    if(a < min)

      min = a;

    if(a > max)

      max = a;

    sum += a;

  }

  printf("%ld %ld %ld\n",min,max,sum);

  return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC061C - Big Array
  ll N, K; cin >> N >> K;
  vector<ll> num(1e6+1, 0);
  REP(i, N){
    ll a, b; cin >> a >> b;
    num[a] += b;
  }

  ll cnt = 0;
  REP(i, 1e6+1){
    cnt += num[i];
    if(cnt >= K){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // input A B
        // A+B,A-B,AxB max
        Scanner sc = new Scanner(System.in);
        int numA = sc.nextInt();
        int numB = sc.nextInt();
        int retNum = 0;
        if(numA + numB < numA - numB){
            if(numA - numB < numA * numB){
                retNum = numA * numB;
            } else {
                retNum = numA - numB;
            }
        } else {
            if(numA + numB < numA * numB){
                retNum = numA * numB;
            } else {
                retNum = numA + numB;
            }
        }
        System.out.println(retNum);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;

int main(void)
{
	int a;
	cin >> a;

	int b = sqrt(a);

	int tmp = a;

	if (a != 2) {
		vector<int> v;
		v.push_back(2);


		for (int i = 3; i <= b; i++) {
			if (i % 2 != 0)
				v.push_back(i);
		}

		while(1) {
			int cnt = 0;
			for (int i = 0; i < v.size(); i++) {
				if (tmp % v[i] != 0) {
					cnt++;
				}
			}

			if (cnt == v.size())
				break;

			tmp++;
		}
	}
		

	cout << tmp << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	ll s;
	cin >> s;

	const int v = 1000000000;

	int x = (v-s%v)%v;
	int y = (s+x)/v;
	
	cout <<"0 0 1000000000 1 " << x << " " << y << '\n';
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
def main():
    import math
    h,n = map(int, input().split())
    aa = [0]*(n+1)
    bb = [0]*(n+1)
    mp = [[None for _ in range(n+1)] for _ in range(h+1)]
    # 体力i 技の種類j
    for j in range(1, n+1):
      mp[0][j] = 0
      aa[j], bb[j] = map(int, input().split())
    for i in range(1, h+1):
        mp[i][0] = float("inf")
    for j in range(1, n+1):
        for i in range(1, h+1):
        	mp[i][j] = min(mp[i][j-1], mp[max(0, i - aa[j])][j] + bb[j])
    print(mp[h][n])

if __name__ == '__main__':
    main()

Measured memory_bytes: 260232
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    ll res = 0;
    vector<int> v(n);
    rep(i, 0, n)
        cin >> v[i];
    rep(i, 1, n)
    {
        int a = max(0, v[i] + v[i-1] - x);
        res += a;
        v[i] = max(0, v[i] - a);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 640
import math

a, b = map(int, input().split())

list_a = []
list_b = []
sqrt_a = math.sqrt(a)
sqrt_b = math.sqrt(b)


for i in range(2, int(sqrt_a)):
    if (a % (i) == 0):
        list_a.append(i)
        while(a % (i) == 0):
            a = a//(i)
if a != 1:
    list_a.append(a)

for i in range(2, int(sqrt_b)):
    if (b % (i) == 0):
        list_b.append(i)
        while(b % (i) == 0):
            b = b//(i)
if b != 1:
    list_b.append(b)

# print(list_a)
# print(list_b)

set_a = set(list_a)
set_b = set(list_b)

set_ab = set_a & set_b

print(len(set_ab) + 1)


Measured memory_bytes: 40172
n, m = map(int, input().split())
a = list(map(int, input().split()))
num = sum(a)
cnt = 0
for i in range(n):
    if a[i] < num/(4*m):
        continue
    else:
        cnt += 1
if cnt >= m:
    print("Yes")
else:
    print("No")   

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

int main(){
    int n,f=1;
    cin>>n;
    int a[n+1];
    
    for(int i=1;i<=n;i++)
      cin>>a[i];
      
    for(int i=1;i<=n;i++){
        if(a[i]%2==0)
          if(!(a[i]%3==0 || a[i]%5==0))
            f=0;
    }
    
    if(f==1)
      cout<<"APPROVED"<<endl;
    else if(f==0)
      cout<<"DENIED"<<endl;
      
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long int a,b,c;
    cin>>a>>b>>c;
   if(a==0)
    cout<<((b/c)+1)<<endl;
   else
   {a=a-1;
   cout<<(b/c)-(a/c)<<endl;

   }
   return 0;

}


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

int main() {
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto p : mp) mx = max(mx, p.second);
    for (auto p : mp) {
        if (p.second != mx) continue;
        cout << p.first << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a)
    cin >> x;
  vector<int> freq(n + 1);
  for (int i = 0; i < n; ++i)
    ++freq[a[i]];
  ll ans = 0;
  for (int i = 0; i <= n; ++i)
    ans += (ll)freq[i] * (freq[i] - 1) / 2;
  for (int i = 0; i < n; ++i) {
    cout << ans - (freq[a[i]] - 1) << '\n';
  }
  return 0;
}

Measured memory_bytes: 4224
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb emplace_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) sort(all(v)),v.erase(unique(all(v)), v.end());
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
#define deb(x) cout<<"\n["<<#x<<" = "<<x<<"]\n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int d,ans,x,y;
void solve(){
  cin>>x>>y;
  if(x*x+y*y<=d)ans++;
}
int32_t main()
{
  ibs;cti;
  // solve();return 0;
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  int t;cin>>t>>d;d=d*d;
  while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();}
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3648
H,W = map(int, input().split())
S = []
S.append('.' *(W+2))
for i in range(H):
    S.append('.' + input() + '.')

S.append('.' *(W+2))

#print(S)
for h in range(1,H+1):
    ans = ''
    for w in range(1,W+1):
        c = 0
        if S[h][w] == '#':
            ans += '#'
        else:
            c += S[h-1][w-1:w+2].count('#')
            c += S[h][w-1:w+2].count('#')
            c += S[h+1][w-1:w+2].count('#')
            ans += str(c)
    print(ans)

Measured memory_bytes: 3064
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    s_len=len(s)
    g=[0]*s_len
    g[0]=1
    if s[1]==s[0]:g[1]=1
    else: g[1]=2
    for i in range(2,s_len):
        if s[i]==s[i-1]:
            g[i]=g[i-3]+2
        else:
            g[i]=g[i-1]+1
    print(g[-1])

if __name__=='__main__':
    main()

Measured memory_bytes: 41712
#include <stdio.h>
#include <algorithm>
int n;
long long x;
long long a[200000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
	}
	std::sort(a, a + n);
	for (int i = 0; i < n; i++) {
		x += a[n - 1 - i / 2];
	}
	printf("%lld\n", x - a[n - 1]);
}

Measured memory_bytes: 3296
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=[I() for i in range(n)]
c=Counter(lis)
count=0
for i in c.keys():
    if c[i]%2==1:
        count+=1
print(count)

Measured memory_bytes: 54492
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    int st = 0;
    while(st != -1){
        st = s.find("ABC");
        st++;
        if(st == 0) break;
        cnt++;
        s.erase(s.begin(), s.begin() + st);
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 3596
#!/use/bin/env python3

import re

n = input("")
n = re.split(" ",n)

if(int(n[0]) <= int(n[2])):
    if(int(n[1]) <= int(n[2])):
        print(0)
    else:
        if(int(n[1]) <= int(n[3])):
            print(int(n[1]) - int(n[2]))
        else:
            print(int(n[3]) - int(n[2]))

else:
    if(int(n[3]) <= int(n[0])):
        print(0)
    else:
        if(int(n[3]) <= int(n[1])):
            print(int(n[3]) - int(n[0]))
        else:
            print(int(n[1]) - int(n[0]))


Measured memory_bytes: 3188
N=int(input())
dx,dy,dt=0,0,0
count=0
for i in range(N):
    t,x,y=map(int,input().split())
    if (x+y+t)%2 == 0 and abs(x-dx) + abs(y-dy) <= abs(t-dt):
        count+=1
    dx,dy,dt=x,y,t

if count==N:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 9108
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

vector<int> v[N];
vector<int> period;
vector<int> vis(N, 0); int st;

void dfs(int node)
{
	period.pb(node);

	vis[node] = 1;

	for(int i : v[node])
	{
		if(vis[i])
		{
			st = i;
			return;
		}

		dfs(i);
	}
}

int main()
{
 	int n; ll k;
 	scn(n); lscn(k);

 	rep(i, 1, n+1)
 	{
 		int a;
 		scn(a);

 		v[i].pb(a);
 	}

 	dfs(1);

 	// rep(i, 0, period.size())
 	// pri(period[i]); prin(st);

 	int before = 0;

 	rep(i, 0, period.size())
 	if(period[i] == st)
 	{
 		before = i;
 		break;
 	}

 	vector<int> cycle;

 	rep(i, before, period.size())
 	cycle.pb(period[i]);

 	// deb(before);

 	if(k <= before)
 	{
 		prin(period[k]);
 	}
 	else
 	{
 		if(before == 0)
 		{
 			int node = k % (int)period.size(); 
 			prin(period[node]);
 		}
 		else
 		{
	 		k -= before;

	 		int len = (int)cycle.size();
	 		// deb(len); deb(k);
	 		int node = k % len; 

	 		// deb(node);

	 		node = cycle[node];

	 		prin(node);
 		}
 	}

    return 0;
}

Measured memory_bytes: 25596
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<double,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll D;
    cin >> D;
    vector<double> c(27,0);
    for(ll i=0;i<26;++i)cin>>c[i+1];
    vector<vector<double>> S(D+1, vector<double>(27, 0));
    for(ll i=0;i<D;++i)
        for(ll j=0;j<26;++j)cin>>S[i+1][j+1];
    ll Maxscore=-INF;
    vl ans;
    for(double k=-1.0;k<=47;k+=0.02){
        vector<ll> last(27,0);
        ll score=0;
        vector<ll> t(D+1,0);
        for(ll i=1;i<=D;++i){
            ll mark;
            double Max=-2000000000;
            for(ll j=1;j<=26;++j){
                if(chmax(Max,S[i][j]+c[j]*(min(k,(double)D-i))))mark=j;
            }
            t[i]=mark;
            last[t[i]]=i;
            score+=S[i][t[i]];
            for(ll j=1;j<=26;++j)score-=c[j]*(i-last[j]);
        }
        if(chmax(Maxscore,score))ans=t;
    }
    for(double k=-1.0;k<=47;k+=0.02){
        vector<ll> last(27,0);
        ll score=0;
        vector<ll> t(D+1,0);
        for(ll i=1;i<=D;++i){
            ll mark;
            double Max=-2000000000;
            for(ll j=1;j<=26;++j){
                if(chmax(Max,S[i][j]+c[j]*k))mark=j;
            }
            t[i]=mark;
            last[t[i]]=i;
            score+=S[i][t[i]];
            for(ll j=1;j<=26;++j)score-=c[j]*(i-last[j]);
        }
        if(chmax(Maxscore,score))ans=t;
    }
    for(ll i=1;i<=D;++i)prt(ans[i]);

    return 0;
}



Measured memory_bytes: 3916
import numpy as np

N, M, X = map(int, input().split())
book = [list(map(int, input().split())) for _ in range(N)]

ans = 10**9

for i in range(1<<N):
    cost = 0
    tisiki = np.array([0]*M)
    cond = [0]*N
    for j in range(N):
        if 1&(i>>j):  # 右シフトして論理積（bit全探索）
            cond[j] = 1
    
    for k in range(N):
        if cond[k]==1:
            b = book[k]
            cost += b[0]
            tisiki += np.array(b[1:])
    
    if np.all(tisiki>=X):
        ans = min(ans, cost)

if ans < 10**9:
    print(ans)
else:
    print(-1)

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n;
const int m=256;
int l[257];
int r[257];

int num[257];

long double entropy(int s,int a,int c){
	r[0]=s;
	range(i,1,n+1) r[i]=(a*r[i-1]+c)%m;
	rep(i,m) num[i]=0;
	range(i,1,n+1) num[(l[i]+r[i])%m]++;
	long double sum=0.0;
	rep(i,m){
		long double cur=1.0*num[i]/n;
		if(cur==0.0)
			continue;
		sum-=(cur*log(cur));
	}
	return sum;
}

int main(void){
	while(cin >>n){
		if(n==0)
			break;
		range(i,1,n+1) cin >> l[i];
		long double cmin=entropy(0,0,0);

		int ss=0,aa=0,cc=0;
		rep(s,16)rep(a,16)rep(c,16){
			double cur=entropy(s,a,c);
			if(cur<cmin){
				cmin=cur;
				ss=s,aa=a,cc=c;
			}
		}
		cout << ss << " " << aa << " " << cc << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <algorithm>

int main() {
  std::string str;
  std::cin >> str;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++)
  {
    std::string cmd, p;
    int a, b;
    std::cin >> cmd >> a >> b;
    if (cmd == "print") {
      std::cout << str.substr(a, b - a + 1) << "\n";
    }
    if (cmd == "reverse") {
      std::string tmp = str.substr(a, b - a + 1);
      std::reverse(tmp.begin(), tmp.end());
      str.replace(a, b - a + 1, tmp);
    }
    if (cmd == "replace") {
      std::string tmp;
      std::cin >> tmp;
      str.replace(a, b - a + 1, tmp);
    }
  }
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
int d[200][200];
bool used[8];
int r[8];
int R,res=INF;
void dfs(int c,int las,int di){
    if(c==R+1){
        chmin(res,di);
        return;
    }
    REP(i,R)if(!used[i]){
        used[i]=true;
        if(las==-1)dfs(c+1,i,0);
        else dfs(c+1,i,di+d[r[las]][r[i]]);
        used[i]=false;
    }
}

signed main(){
    int n,m;cin>>n>>m>>R;
    REP(i,R){
      	int x;cin>>x;x--;
      	r[i]=x;
    }
    REP(i,n)REP(j,n)d[i][j]=INF;
    REP(i,n)d[i][i]=0;
    REP(i,m){
        int a,b,c;cin>>a>>b>>c;a--;b--;
        d[a][b]=d[b][a]=c;
    }
    REP(k,n)REP(i,n)REP(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	dfs(1,-1,0);
  	cout<<res<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
   int main(void){
   int sk,ik,h[10],r[3]={0,0,0};
      for(sk=0;sk<10;sk++)
         scanf("%d",&h[sk]);
      for(ik=0;ik<10;ik++){
         if(h[ik]>r[0])
            r[2]=r[1],r[1]=r[0],r[0]=h[ik];
         else if(h[ik]>r[1])
            r[2]=r[1],r[1]=h[ik];
         else if(h[ik]>r[2])
            r[2]=h[ik];
      }
      printf("%d\n%d\n%d\n",r[0],r[1],r[2]);
   return 0;
   }

Measured memory_bytes: 600
h, w = map(int, input().split())
lst = []
for i in range(h):
    si = list(input())
    lst.append(si)

for i in range(h):
    for j in range(w):
        if lst[i][j] == '#':
            continue
        cnt = 0
        if i-1>=0:
            if lst[i-1][j] == '#':
                cnt += 1
            if j-1>=0:
                if lst[i-1][j-1] == '#':
                    cnt += 1
            if j+1 < w:
                if lst[i-1][j+1] == '#':
                    cnt += 1
        if j-1 >= 0:
            if lst[i][j-1] == '#':
                cnt += 1
            if i+1 < h:
                if lst[i+1][j-1] == '#':
                    cnt += 1
        if i+1 < h:
            if lst[i+1][j] == '#':
                cnt += 1
            if j+1 < w:
                if lst[i+1][j+1] == '#':
                    cnt += 1
        if j+1 < w:
            if lst[i][j+1] == '#':
                cnt += 1
        lst[i][j] = str(cnt)

for i in range(h):
    print(''.join(lst[i]))

Measured memory_bytes: 40300
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>

#define SIZE 100005
#define MOD 1000000007

using namespace std;

class CTsundoku {
public:
    static void solve(std::istream &cin, std::ostream &cout) {
        int64_t n, m, k;
        cin >> n >> m >> k;
        vector<int64_t> a_vec(n);
        vector<int64_t> b_vec(m);
        for (int64_t i = 0; i < n; ++i) cin >> a_vec[i];
        for (int64_t i = 0; i < m; ++i) cin >> b_vec[i];

        vector<int64_t> accumulate_a(n + 1);
        for (int64_t i = 1; i < n + 1; ++i)
            accumulate_a[i] = accumulate_a[i - 1] + a_vec[i-1];
        vector<int64_t> accumulate_b(m + 1);
        for (int64_t i = 1; i < m + 1; ++i)
            accumulate_b[i] = accumulate_b[i - 1] + b_vec[i-1];
        int64_t ans = 0;
        for (int64_t i = 0; i < n + 1; ++i) {
            if (k - accumulate_a[i] < 0) break;
            int64_t tmp = i + distance(accumulate_b.begin(),
                                       upper_bound(accumulate_b.begin(),
                                                   accumulate_b.end(),
                                                   k - accumulate_a[i]));
            ans = max(ans, tmp);
        }
        for (int64_t i = 0; i < m + 1; ++i) {
            if (k - accumulate_b[i] < 0) break;
            int64_t tmp = i + distance(accumulate_a.begin(),
                                       upper_bound(accumulate_a.begin(),
                                                   accumulate_a.end(),
                                                   k - accumulate_b[i]));
            ans = max(ans, tmp);
        }

        cout << max(int64_t(0), ans-1) << endl;

    }
};


int main() {
    CTsundoku solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

typedef long long ll;

int main() {

	ll n, k, ans = 0;
	cin>>n>>k;
	ans = (n / k) * (n / k) * (n / k);
	if (k % 2 == 0) {
		ll a = n / (k / 2) - (n / k);
		ans += a * a * a;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3628
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		
		// 計算
		int result = 0;
		result = a[n-1] - a[0];
		

		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int count2[1000001] = {};

void prepare() {
  for(int i =1; i<=1000000; ++i) {
    if(i%2==0) {
      count2[i] = count2[i/2] + 1;
    }
  }
  for(int i =1; i<=1000000; ++i) {
      count2[i] += count2[i-1];
  }
}

int is_comb_odd(int a, int b) {
  return count2[a] == count2[b] + count2[a-b];
}

int A[1000000];

int main() {
  prepare();
  int N;
  cin >> N;
  int all02 = true;
  REP(i, N) {
    char _A;
    cin >> _A;
    A[i] = _A - '1';
    if(A[i] == 1) {
      all02 = false;
    }
  }
  if(all02) {
    REP(i, N) {
      A[i] = A[i] / 2;
    }
  } else {
    REP(i, N) {
      A[i] = A[i] % 2;
    }
  }
  int ret = 0;
  REP(i, N) {
    if(A[i] == 1 && is_comb_odd(N-1, i)) {
      ret = 1 - ret;
    }
  }
  if(all02) {
    ret *= 2;
  }
  cout << ret << endl;
}

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

char ary[100010];
int main(){
	cin>>ary;
	int cnt=0;
	char las=ary[0];
	for(int i=0;i<strlen(ary);i++){
		if(las!=ary[i]){
			las=ary[i];
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  if(n == m){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
from copy import deepcopy
n = int(input())
v = list(map(int, input().split()))

d1 = [0]*(10**5+1)
d2 = [0]*(10**5+1)
for i in range(n):
    if i%2: d2[v[i]] += 1
    else: d1[v[i]] += 1
        
max_d1 = [0, 0]
max_d2 = [0, 0]
submax_d1 = [0, 0]
submax_d2 = [0, 0]
for i in range(10**5+1):
    if max_d1[1] < d1[i]:
        submax_d1 = deepcopy(max_d1)
        max_d1[0] = i
        max_d1[1] = d1[i]
    elif submax_d1[1] < d1[i]:
        submax_d1[0] = i
        submax_d1[1] = d1[i]
    if max_d2[1] < d2[i]:
        submax_d2 = deepcopy(max_d2)
        max_d2[0] = i
        max_d2[1] = d2[i]
    elif submax_d2[1] < d2[i]:
        submax_d2[0] = i
        submax_d2[1] = d2[i]
if max_d1[0] == max_d2[0]:
    if max_d1[1] + submax_d2[1] > max_d2[1]+submax_d1[1]:
        print(n-max_d1[1]-submax_d2[1])
    else:
        print(n-max_d2[1]-submax_d1[1])
else:
    print(n-max_d1[1]-max_d2[1])

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

int main()
{
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a;
    cin >> a;
    if(a % 2 == 0)
        cout << pow((a/2), 2);
    else
        cout << ((a/2)*((a/2)+1));
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
n = int(input())
jobs = []
for _ in range(n):
  a,b  = map(int,input().split())
  jobs.append((a,b))
  
jobs.sort(key = lambda x: x[1])
time = 0
for i in range(n):
  a,b = jobs[i]
  time += a
  if time <= b:
    continue
  else:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 73176
import sys
input = sys.stdin.readline
 
N = int(input())
words = {}
while N > 0:
    word = ''.join(sorted(input().rstrip()))
    if word in words:
        words[word] += 1
    else:
        words[word] = 1
    N -= 1

count = 0
for n in words.values():
    if n > 1:
        count += n*(n-1) // 2

print(count)

Measured memory_bytes: 17852
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
 
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    
    bool ans[n];
    fill(ans, ans+n, false);
    
    for(int i=0; i<k; i++){
        int d;
        cin >> d;
        for(int j=0; j<d; j++){
            int a;
            cin >> a;
            ans[a-1]=true;
        }
    }
    int flag=0;
    for(int i=0;i<n;i++){
        if(!ans[i]) flag++;
    }
    cout << flag << endl;
    return 0;
}


Measured memory_bytes: 3624
from collections import Counter
n = int(input())
list_A = list(map(int, input().split()))
l = Counter(list_A)

list_B = l.values()

value_1 = 0
value_2 = 0
value_0 = 0

for num in list_B:
    a = num
    while True:
        a = a % 3 + a // 3
        if a < 3:
            break
    if a == 2:
        value_2 += 1
    elif a == 1:
        value_1 += 1
    else:
        value_0 += 1

ans = value_1 + 2*(value_2//2) + value_0

print(ans)

Measured memory_bytes: 18656