akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
char s[3000][3001];
int osum[3000][3000],isum[3000][3000];
int main(void)
{
	int h,w,i,j,x;
	long long sum;
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++)	scanf("%s",s[i]);
	for(i=0;i<h;i++)	{
		x=0;
		for(j=w-1;j>=0;j--)	{
			if(s[i][j]=='O')	x++;
			osum[i][j]=x;
		}
	}
	for(j=0;j<w;j++)	{
		x=0;
		for(i=h-1;i>=0;i--)	{
			if(s[i][j]=='I')	x++;
			isum[i][j]=x;
		}
	}
	sum=0;
	for(i=0;i<h;i++)	{
		for(j=0;j<w;j++)	{
			if(s[i][j]=='J')	{
				sum+=osum[i][j]*isum[i][j];
			}
		}
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 81812
import sys
from collections import deque

input = sys.stdin.readline
digtmp = [(0,1), (1,0), (0,-1), (-1,0)]

def solve():
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        return -1
    h_cnt = 0
    wallset = set()
    for i in range(2*H-1):
        wallflag = list(map(int, input().split()))
        if i%2 == 0:
            for j, wf in enumerate(wallflag):
                if wf == 1:
                    wallset.add( frozenset( ((h_cnt, j), (h_cnt, j+1)) ) )
        else:
            for j, wf in enumerate(wallflag):
                if wf == 1:
                    wallset.add( frozenset( ((h_cnt, j), (h_cnt+1, j)) ) )
            h_cnt += 1

    #BFS
    field = [[0]*W for i in range(H)]
    field[0][0] = 1
    que = deque([(0,0)])
    while True:
        fr_x, fr_y = que.popleft()
        cnt = field[fr_x][fr_y]
        for d_x, d_y in digtmp:
            to_x = fr_x + d_x
            to_y = fr_y + d_y
            if 0 <= to_x < H and 0 <= to_y < W:
                wallcheck = set(((fr_x, fr_y), (to_x, to_y)))
                if wallcheck in wallset:
                    continue
                if field[to_x][to_y] == 0:
                    field[to_x][to_y] = cnt + 1
                    que.append((to_x, to_y))
        if len(que) == 0:
            break
    
    #ans
    ans = field[H-1][W-1]
    print(ans)
    return 0

def main():
    status = 0
    while status == 0:
        status = solve()
            
if __name__ == "__main__":
    main()



Measured memory_bytes: 6308
ks=[]
as=[]
sum=0
n,m=gets.split.map(&:to_i)
n.times do
  ka=gets.split.map(&:to_i)
  k=ka[0]
  a=ka[1..-1]
  ks << k
  as << a
end
1.upto(m) do |i|
  if as.all?{|an| an.include?(i)}
    sum+=1
  end
end
puts sum


Measured memory_bytes: 1788
# E - All-you-can-eat
n,t=map(int,input().split())
a,b=[],[]
for i in range(n):
    aa,bb=map(int,input().split())
    a.append(aa)
    b.append(bb)

dp1=[[0]*t for _ in range(n+1)] # 前から
dp2=[[0]*t for _ in range(n+1)] # 後ろから
arev=a[::-1]
brev=b[::-1]

for i in range(1,n+1):
    for j in range(t):
        if j-a[i-1]>=0:
            dp1[i][j]=max(dp1[i-1][j-a[i-1]]+b[i-1],dp1[i-1][j])
        else:
            dp1[i][j]=dp1[i-1][j]

for i in range(1,n+1):
    for j in range(t):
        if j-arev[i-1]>=0:
            dp2[i][j]=max(dp2[i-1][j-arev[i-1]]+brev[i-1],dp2[i-1][j])
        else:
            dp2[i][j]=dp2[i-1][j]

ans=-1
for i in range(1,n+1):
    for j in range(t):
        ans=max(ans,dp1[i-1][j]+dp2[n-i][t-1-j]+b[i-1])
print(ans)


Measured memory_bytes: 178308
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;




void solve(){
    int n, k, ans = 0;
    cin>>n>>k;
    int a[n];
    f(i,n)cin>>a[i];
    sort(a,a+n);
    if(k >= n){cout<<"0";return ;}
    f(i,n-k)ans += a[i];
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 1792
N, Y = map(int, input().split())

for x in range(N + 1):
  for y in range(N - x + 1):
    z = N - x - y
    
    if x * 10000 + y * 5000 + z * 1000 == Y:
      print(x, y, z)
      exit()

print("-1 -1 -1")

Measured memory_bytes: 3060
import sys
import itertools

N = int(input())

z = 0
c = 'No'
for i in range(N):
    a, b = map(int, input().split())
    if a == b:
        z += 1
    else:
        z = 0

    if z > 2:
        c = 'Yes'

print(c)


Measured memory_bytes: 62376
n = int(input())
a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]

ans = 0
for i in range(n):
  t=min(b[i],a[i])
  ans+=t
  a[i]-=t
  b[i]-=t
  t=min(b[i],a[i+1])
  ans+=t
  a[i+1]-=t
  
print(ans)

Measured memory_bytes: 82916
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var A, B, C int

func main() {
	sc.Split(bufio.ScanWords)

	a := make([]int, 3)
	a[0], a[1], a[2] = nextInt(), nextInt(), nextInt()
	sort.Ints(a)

	ans := 0
	ans += (a[1] - a[0]) / 2
	if (a[1]-a[0])%2 == 1 {
		ans++
		a[2]++
	}

	ans += (a[2] - a[1])

	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
   int N,M;
   cin>>N>>M;
   vi A(N);
   rep(i,N) cin>>A[i];
   double sum=0;
   rep(i,N) sum+=A[i];
   double b=sum/(4*M);
   bool ok=false;
   int counter=0;
   rep(i,N) {
       if(A[i]>=b) counter++;
   }
   if(counter>=M) ok=true;
   if(ok) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		cin >> ar[0] >> ar[1] >> ar[2];
		sort(ar,ar+3);
		if(ar[0]==ar[1] && ar[1]!=ar[2] || ar[1]==ar[2] && ar[0]!=ar[1] || ar[0]==ar[2] && ar[1]!=ar[0])cout<<"Yes";else
		cout<<"No";
	
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll a;
    cin >> a;
    rep(i, 1, 10){
        rep(j, 1, 10){
            if(i * j == a){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = INF;
    rep(i, max(X, Y) + 1) {
        ll tmp = A * max(X - i, 0) + B * max(Y - i, 0) + 2 * C * i;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

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

	int a = 100000;
	for (int i = 0; i < n; i++) {
		a *= 1.05;
		int n = a % 1000;

		if (n) {
			a -= n;
			a += 1000;
		}
	}

	cout << a << endl;
}


Measured memory_bytes: 3016
N, K = map(int, input().split())
S = input()

# 穴の位置memo
memo = []
cnt = 0
for i in range(len(S)):
    if S[i] == "1":
        if cnt > 0:
            memo.append([i-cnt,cnt])
        cnt = 0
    else:
        cnt += 1
if cnt > 0:
    memo.append([i+1-cnt,cnt])
# print(memo)

import sys
if K >= len(memo):
    print(len(S))
    sys.exit()

max = 0
for i in range(len(memo) - K + 1):
    if i == 0:
        max = memo[K][0]
    elif i == (len(memo) - K):
        if max < len(S) - (memo[i-1][0] + memo[i-1][1]):
            max = len(S) - (memo[i-1][0] + memo[i-1][1])
    else:
        if max < memo[i + K][0] - (memo[i-1][0] + memo[i-1][1]):
            max = memo[i + K][0] - (memo[i-1][0] + memo[i-1][1])
print(max)

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

N = int(input())

S = [input().replace('\n', '') for _ in range(N)]

AC_c = 0
WA_c = 0
TLE_c = 0
RE_c = 0

r = {'AC': 0, 'WA': 0, 'TLE':0, 'RE':0}

for s in S:
    r[s] += 1

print(f'AC x {r["AC"]}')
print(f'WA x {r["WA"]}')
print(f'TLE x {r["TLE"]}')
print(f'RE x {r["RE"]}')



Measured memory_bytes: 74384
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

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

    vector<int> a(n + 1), b(n + 1);
    rep(i, n + 1)
        cin >> a[i];
    rep(i, n)
        cin >> b[i];

    long cnt = 0;
    long mod = 0;
    rep(i, n + 1) {
        if (0 > a[i] - b[i] - mod) {
            //全員a[i]倒せる
            cnt += a[i];

            //今のが倒さないといけない量
            mod = a[i] - mod;

            if (0 > mod)
                //前のが全員倒してくれたら今のはフル
                mod = b[i];
            else
                //前のが力尽きたら今も使って残りは繰越
                mod = b[i] - mod;

        }            
        else {
            //b[i]+繰越だけ倒せる
            cnt += b[i] + mod;

            //次への繰越無し
            mod = 0;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
int v[12345];
int sum[12345];
int main(){
//    freopen("input.txt", "r", stdin);
    int a, b, c, d;
    cin >> a >> b;
    int res = 0;
    res += min(a, b);
    cin >> c >> d;
    res += min(c, d);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int n, m, c;

    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) {
        cin >> b[i];
    }
    vector<vector<int> > a(n, vector<int>(m, 0));;
    rep(i, n) {
        rep(j, m) {
            cin >> a[i][j];
        }
    }
    int res = 0;
    rep(i, n) {
        LL tmp = 0;
        rep(j, m) {
            tmp += a[i][j] * b[j];
        }
        if (tmp + c > 0) {
            res += 1;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
	int n, i, w[100];
	fscanf(stdin,"%d", &n);
	for(i=0;i<n;i++){
		fscanf(stdin,"%d", &w[i]);
	}
	int cut = 2/n, sum1=0, sum2=0, flag=1, min;
	for(i=0;i<cut;i++) sum1 += w[i];
	for(i=cut;i<n;i++) sum2 += w[i];
	min = sum2-sum1;
	if(min>0){ //sum2>sum1
		while(flag){
			if(min-2*w[cut]<=0 || cut==n-1){
				min = abs(min)<abs(min-2*w[cut])?min:min-2*w[cut];
				flag = 0;
			}else{
				min = min-2*w[cut];
			}
			cut++;
		}
	}else if(min<0){
		while(flag){
			if(min+2*w[cut]>=0 || cut==0){
				min = abs(min)<abs(min+2*w[cut])?min:min+2*w[cut];
				flag = 0;
			}else{
				min = min+2*w[cut];
			}
			cut--;
		}
	}
	printf("%d\n",abs(min));
	return 0;
}


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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int N;
map<long long, int> ma;

long long rec(int p, long long mul) {
    if (mul > 75) return 0;
    if (p > N) {
        if (mul == 75) return 1;
        else return 0;
    }

    long long res = 0;
    for (int i = 0; i < ma[p]+1; ++i) res += rec(p+1, mul * (i+1));
    return res;
}

int main() {
    cin >> N;
    for (int i = 2; i <= N; ++i) {
        auto ps = prime_factorize(i);
        for (auto it : ps) ma[it.first] += it.second;
    }
    cout << rec(2, 1) << endl;
}


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

#define all(x) begin(x), end(x)
#define log(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i,a,b) for (int i = (int)a; i >= (int)b; --i)
#define loop(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

ll p[83] = {0};

int main() {
	int n;
	cin >> n;
	vector<string> vs(n);
	rep (i, n) cin >> vs[i];

	int m=0,a=0,r=0,c=0,h=0;
	char b;
	rep (i, n) {
		b = vs[i][0];
		m += b=='M',a += b=='A',
		r += b=='R',c += b=='C',h += b=='H';
	}
	p['M']=m,p['A']=a,p['R']=r,p['C']=c,p['H']=h;

	ll cnt = 0;
	string s = "MARCH";

	loop (i, 1, s.size()) {
		rep (j, i) {
			loop (k, i+1, s.size()) {
				cnt += p[(int)s[i]] * p[(int)s[j]] * p[(int)s[k]];
			}
		}
	}

	log(cnt);

	return 0;
}



Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;

//ll m,n;
int main()
{
    int n,a,b;
    cin>>a>>b>>n;
    cout<<min(a*b,n)<<endl;
  /*cin>>m>>n;


  m%=2019;
  n%=2019;
  if(m>n)
  n+=2019;
  if(m==0||n==0)
    cout<<0<<endl;
else
  {

       ll mins=1e9;
      for(int i=m;i<=n;i++)
      {
          for(int j=i+1;j<=n;j++)
          {
             ll  sum=(ll)i*j%2019;
              mins=min(mins,sum);

          }

      }
      cout<<mins<<endl;
  }
*/

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	static long gcd(long a,long b){
		while(a!=b){
			if(a>b)
				a=a-b;
			else
				b=b-a;
		}
		return a;
	}
	static void lcm(long a,long b,long g){
		System.out.println(g+" "+(a*b/g));
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			long a=scan.nextInt();
			long b=scan.nextInt();
			long g=0;
			g = gcd(a,b);
			lcm(a,b,g);
		}
		scan.close();
	}

}

Measured memory_bytes: 17216
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

cnt = 0
lst = []
for i in range(n):
    if s[i-1:i+1] == 'AC':
        cnt += 1
    lst.append(cnt)

for i in range(q):
    print(lst[lr[i][1] - 1] - lst[lr[i][0] - 1])

Measured memory_bytes: 29744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
vector<ll>adj[100010];
vector<bool>visited(100010);
vector<ll>p(100010);
ll n,m;
vector<ll>dist(100010);
void addEdge(ll v,ll w){
    adj[v].push_back(w);
    adj[w].push_back(v);
}
void bfs(ll src){
    for(int i=1;i<=n;i++) visited[i]=false;
    queue<ll>q;
    visited[src]=true;
    q.push(src);
    p[src]=-1;
    while(!q.empty()){
        ll z=q.front();
        q.pop();
        for(int i=0;i<adj[z].size();i++)
        {
            if(!visited[adj[z][i]])
            {
                visited[adj[z][i]]=true;
                q.push(adj[z][i]);
                p[adj[z][i]]=z;
                dist[adj[z][i]]=dist[z]+1;
            }
        }
    }
}
void solve(){
    cin>>n>>m;ll a,b;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        addEdge(a,b);
    }
    vector<ll>ans;
    bfs(1);
    for(int i=2;i<=n;i++){
        if(!visited[i]) {cout<<"No";return;}
        ans.push_back(p[i]);
    }
    cout<<"Yes"<<'\n';for(auto x:ans) cout<<x<<'\n';
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 14580
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 998244353;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll n , m ; cin >> n >> m;
    vector<vector<ll>> hen(n,vector<ll>(0));
    rep(i,m){
        ll a,b; cin >> a >> b;
        a--; b--;
        hen.at(a).push_back(b);
        hen.at(b).push_back(a);
    }

    queue<ll> q;
    q.push(0);
    vector<bool> seen(n,0);
    seen.at(0) = 1;
    vector<ll> shirube(n,-1);

    while(q.size()){
        ll x = q.front();
        q.pop();
        for(auto z:hen.at(x)){
            if(seen.at(z)) continue;
            seen.at(z) = 1;
            shirube.at(z) = x;
            q.push(z);
        }
    }
    bool ng = 0;

    for(int i=1;i<n;i++){
        if(shirube.at(i)==-1) ng = 1;
    }

    if(ng){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        for(int i=1;i<n;i++){
            cout << shirube.at(i) + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 12944
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < n; (i)++)
#define SORT(a) sort((a).begin(), (a).end())
#define MOD 1000000007
typedef long long ll;

int main(void){
  int n;
  cin >> n;
  vector<vector<int>> p(n, vector<int>(15, 0));
  vector<vector<int>> f(n, vector<int>(15, 0));
  rep(i, n) rep(j, 10) cin >> f[i][j];
  rep(i, n) rep(j, 11) cin >> p[i][j];

  int sum = 0;
  int ans = -MOD;
  for(int bit = 1; bit < (1<<10); bit++){
    vector<int> count(n, 0);
    sum = 0;
    for(int i = 0; i < 10; i++){
      if(bit & (1<<i)){
        for(int j = 0; j < n; j++){
          if(f[j][i]) count[j]++;
        }
      }
    }
    for(int k = 0; k < n; k++)
      sum += p[k][count[k]];
    ans = max(sum, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include<vector>
#include <algorithm>
#include <utility>
#include<stack>
#include<queue>
#include<map>
#include <fstream>
#include<set>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long

//    set<int>s;
    map<int,int> num;
    int a[100010];

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i];
         //   s.push( a[i] );
            num[ a[i] ] ++;
        }
        vector<int>val;
      //  cout <<num.size() <<endl;
       if( n%3 == 0  ){
        if( num.size() > 3 ) cout << "No"<<endl;
        else if( num.size() == 1 ){
            auto it=num.begin();
            if( it->first != 0 ) cout << "No"<<endl;
            else cout<<"Yes"<<endl;
        }
        else if( num.size() == 2 ){
                auto it=num.begin();
                auto nxt = next(it);
                if( it->first != 0 && nxt->first!=0 ){
                    cout << "No"<<endl;
                }
                else if( num[0]==(n/3) ){
                    cout <<"Yes"<<endl;
                }
                else cout<<"No"<<endl;
        }
        else{
                int curr=-1;
            for( auto it=num.begin();it!=num.end();it++ ){
           //     if( curr=-1 ) curr=it->second;
                 if( it->second !=( n/3 ) ){
                    cout<<"No"<<endl;
                    return 0;
                }
                val.pb( it->first );
            }
            if( ( val[0]^val[1] ) == val[2] && ( val[0]^val[2] ) == val[1] && (val[1]^val[2]) == val[0] ){
                cout << "Yes"<<endl;
            }
            else cout<<"No"<<endl;
        }
       }
       else{
             if( num.size() > 1 ) cout<<"No"<<endl;
             else{
                auto it=num.begin();
                if( it->first!= 0 ) cout <<"No"<<endl;
                else cout<< "Yes"<<endl;
             }
       }


      return 0;
    }





























Measured memory_bytes: 4224
#include<stdio.h>
int main()
{
  int i,count=0;
  char s[100];
  char s1[100];
  scanf("%s",s);
  scanf("%s",s1);
  for(i=0;i<=2;i++)
  {
    if(s[i]==s1[i])
      {
        count++;
      }
  }
  printf("%d",count);

}
 

Measured memory_bytes: 128
n=int(input())
a=[0 for i in range(n)]
b=list(map(int,input().split()))

for i in range(n):
  if i==0:
    a[i]=b[0]
  elif i==n-1:
    a[i]=b[-1]
  else:
    a[i]=min(b[i],b[i-1])
    
print(sum(a))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		scan.close();
		System.out.println((a*b>=c*d)? a*b:c*d);
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		double n = sc.nextDouble();
		double a = Math.ceil(n/1.08);
		double b = Math.floor(a*1.08);
		if(n==b){
			int c = (int)a;
			System.out.println(c);
		}else{
			System.out.println(":(");
		}
	}

}


Measured memory_bytes: 24404
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <set>
#include <vector>

#define MAX_N (10000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N - 1], bs[MAX_N - 1], cs[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    scanf("%d %d", &as[i], &bs[i]);
    as[i]--;  // NOTE : modified input
    bs[i]--;  // NOTE : modified input
  }
  for (int i = 0; i < N; i++) {
    scanf("%d", &cs[i]);
  }

  // sort cs
  sort(cs, cs + N);

  // create adj_sets
  vector<set<int>> adj_sets(N, set<int>());
  for (int i = 0; i < N - 1; i++) {
    const int a = as[i], b = bs[i];
    adj_sets[a].insert(b);
    adj_sets[b].insert(a);
  }

  // solve
  int ans = 0, us[MAX_N] = {}, xs[MAX_N] = {};
  for (int i = 0; i < N; i++) {
    const int c = cs[i];
    // find node with maximum edges
    int min_j = 0, min_size = N;
    for (int j = 0; j < N; j++) {
      const int size = adj_sets[j].size();
      if (!us[j] && size <= min_size) {
        min_j = j;
        min_size = size;
      }
    }
    us[min_j] = 1;
    xs[min_j] = c;

    // remove edges connected to it
    for (int k : adj_sets[min_j]) {
      adj_sets[k].erase(min_j);
    }
    adj_sets[min_j].clear();

    // update score
    ans += min_size * c;

    // printf("min_j = %d, min_size = %d, c = %d\n", min_j, min_size, c);
  }
  printf("%d\n", ans);
  for (int i = 0; i < N; i++) {
    printf("%d ", xs[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=5e3+10;
const ll MOD=1e9+7;
int N;
vector<int>G[MAXN];
int sz[MAXN];
int maxsz[MAXN];
ll fact[MAXN];
ll C[MAXN][MAXN];
ll dp[MAXN];
ll mult(ll a,ll b)
{
    return a*b%MOD;
}
ll add(ll a,ll b)
{
    return (a+b)%MOD;
}
void init()
{
    fact[0]=1;
    for(int u=1;u<MAXN;u++){
        fact[u]=mult(u,fact[u-1]);
    }
    C[0][0]=1;
    for(int u=1;u<MAXN;u++){
        C[u][0]=C[u][u]=1;
        for(int v=1;v<u;v++){
            C[u][v]=add(C[u-1][v],C[u-1][v-1]);
        }
    }
}
void dfs(int rt,int fa)
{
    sz[rt]=1;
    for(int v:G[rt]){
        if(v==fa)continue;
        dfs(v,rt);
        sz[rt]+=sz[v];
        maxsz[rt]=max(maxsz[rt],sz[v]);
    }
    maxsz[rt]=max(maxsz[rt],N-sz[rt]);
}
void solve()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    for(int u=0;u<N-1;u++){
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    init();
    dfs(1,0);
    int f=1;
    for(int u=2;u<=N;u++){
        if(maxsz[f]>maxsz[u]){
            f=u;
        }
    }
    if(N%2==0&&sz[f]==N/2){
        cout<<mult(fact[N/2],fact[N/2]);
        return;
    }
    vector<int>vs;
    for(int v:G[f]){
        if(sz[v]<sz[f])vs.push_back(sz[v]);
    }
    if(f!=1)
        vs.push_back(N-sz[f]);
    int tmp=0;
    dp[0]=1;
    for(int v:vs){
        for(int k=tmp+v;k>=0;k--){
            for(int j=1;j<=v;j++){
                if(j>k)break;
                dp[k]=add(dp[k],mult(mult(dp[k-j],C[v][j]),mult(C[v][j],fact[j])));
            }
        }
        tmp+=v;
    }
    ll ans=0,sg=1;
    for(int u=0;u<N;u++){
        ans=add(ans,mult(mult(dp[u],fact[N-u]),sg));
        sg=mult(sg,MOD-1);
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


Measured memory_bytes: 195200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    string s;
    cin >> s;
    int center = s.size() / 2;
    int ans = 0;
    rep(i, center) {
        if (s[i] != s[s.size() - i - 1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		int q = Integer.parseInt(reader.readLine());
		st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < q; i++) {
			if (subsetSum(Integer.parseInt(st.nextToken()), a)) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
		reader.close();
	}

	private boolean subsetSum(int s, int[] a) {
		int n = a.length;
		int[][] dp = new int[n+1][s+1];
		for (int i = 0; i < n; i++) {
			int v = a[i];
			for (int j = 0; j <= s; j++) {
				if (v == j || (v < j && dp[i][j-v] > 0)) {
					dp[i+1][j] = dp[i][j] + 1;
				} else  {
					dp[i+1][j] = dp[i][j];
				}
			}
		}
		return dp[n][s] > 0;
	}
}


Measured memory_bytes: 41792
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		String S = stdIn.next();
		int sum = S.length();
		int ans[] = new int[sum];
		for(int i = 0; i < sum; i++){
			ans[i] = (S.charAt(i) - 65 + N) % 26 + 65;
			System.out.print((char)ans[i]);
		}
		System.out.println();
		stdIn.close();
	}
}


Measured memory_bytes: 39900
n=int(input())
A=list(map(int,input().split()))

lsum=A[0]+A[1] #真ん中の仕切りの左側の総和
rsum=0 #真ん中の仕切りの右側の総和
for i in range(2,n):
    rsum+=A[i]

res=lsum+rsum
le=0
ri=2
sum1=0
sum2=lsum
sum3=0
sum4=rsum

for mid in range(2,n-1): #真ん中の仕切り
    while le<mid and (abs((sum1+A[le])-(sum2-A[le]))<abs(sum1-sum2)) :
        sum1+=A[le]
        sum2-=A[le]
        le+=1
    while ri<n and (abs((sum3+A[ri])-(sum4-A[ri]))<abs(sum3-sum4)) :
        sum3+=A[ri]
        sum4-=A[ri]
        ri+=1


    #print(str(sum1)+" "+str(sum2)+" "+str(sum3)+" "+str(sum4))

    res=min(res,max(sum1,sum2,sum3,sum4)-min(sum1,sum2,sum3,sum4))

    sum2+=A[mid]
    sum3-=A[mid]


print(res)

    
    
                         


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

int main()
{
    ll a,b,x;
    cin >> a >> b >> x;
    if(a==0) cout << b/x +1 << endl;
    else cout << b/x - (a-1)/x << endl;
    return 0;
}




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

from itertools import product

if __name__ == "__main__":
    N, M, K = map(int, raw_input().split())
    success = False
    for	n, m in	product(range(N+1), range(M+1)):
        if n*M + m*N - 2*n*m == K:
            success = True
            break
    if success:
        print "Yes"
    else:
        print "No"

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define ll  long long int
#define fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
using namespace std;

int main()
    {fast;
    ll t =1;
    //cin>>t;

while(t--){
    
    ll h,w,m;
    cin>>h>>w>>m;
    vector<ll> a[h+1], b[w+1];
    map<ll,bool> che[h+1];
    ll ma=-1, mi=-1, mh=-1, mw=-1;

ll s=0;
    while(m--){
        ll u,v;
        cin>>u>>v;
        a[u].push_back(v);
        b[v].push_back(u);
       ll n = a[u].size();
        if(ma < n){
            mh = u;
            ma = a[u].size();      
        }
n = b[v].size();
        if(mi < n){
            mw = v;
            mi = b[v].size();
        }
    che[u][v] = true;
    }


    ll ans = mi + ma -1;

    for(ll j=1; j<=w;j++)
        if(b[j].size()==mi)
        s++;

    for(ll i=1; i<=h;i++){
        ll po=0;
        for(auto j: a[i]){
            if(b[j].size()==mi)
            po++;
        }
        if(po!=s && a[i].size() == ma)
            {ans++;
            break;}
    }

    cout<<ans<<endl;
    
}
        return 0;
}

Measured memory_bytes: 69284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long n,x=1;
    double long routeN;
    cin>>n;
    routeN = sqrtl((long double)n);
    for(long i = 1 ;i <= (long)routeN;i++){
        if(n%i==0){
            x=i;
        }
    }
    cout<<x+(n/x)-2<<endl;
    return 0;
}

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

using namespace std;

vector<vector<int>> e;
int N, M;
bool used[5000];

vector<int> in;

int main() {
	cin >> N >> M;
	e.resize(N);
	in.resize(N);
	for (int i = 0; i < N; i++)in[i] = 0;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		e[a].push_back(b);
		in[b]++;
	}
	bool f = false;
	int ct = 0;
	while (ct != N) {
		
		int zeroct = 0;
		for (int i = 0; i < in.size(); i++) {
			if (in[i] == 0 && used[i] == false)zeroct++;
		}
		if (zeroct > 1)f = true;

		int target = 0;
		for (int i = 0; i < in.size(); i++) {
			if (in[i] == 0 && used[i] == false) {
				target = i;
			}
		}

		cout << target + 1 << endl;

		used[target] = true;
		for (int i = 0; i < e[target].size(); i++) {
			if (used[e[target][i]] == false) {
				in[e[target][i]]--;
			}
		}
		ct++;
	}
	cout << f << endl;
	return 0;
}

Measured memory_bytes: 3740
from operator import itemgetter

def main():
	n = int(input())
	v = list(map(int, input().split()))

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")
		return

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if sort_nums[0][0][0]!=sort_nums[1][0][0]:
		print(n - sort_nums[0][0][1] - sort_nums[1][0][1])
		return

	#from here is the case where sort_nums[0][0][0] == sort_nums[1][0][0]

	b1 = -100
	b2 = -100

	if len(sort_nums[0])==1:
		print(n - sort_nums[0][0][1] - sort_nums[1][1][1])
		return
	if len(sort_nums[1])==1:
		print(n - sort_nums[1][0][1] - sort_nums[0][1][1])
		return


	if len(sort_nums[0])>1 and len(sort_nums[1])>1:
		b1 = n - sort_nums[0][0][1] - sort_nums[1][1][1]
		b2 = n - sort_nums[1][0][1] - sort_nums[0][1][1]
		print(min(b1, b2))


main()

Measured memory_bytes: 22108
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>

int main() {
  constexpr std::int64_t kModulus = 998244353;
  std::string S;
  int K;
  std::cin >> S >> K;
  const int N = S.size();
  K = std::min(K, N);
  std::vector<int> zeros;
  for (int i = 0; i < N; ++i) {
    if (S[i] == '0') {
      zeros.push_back(i);
    }
  }
  const int num_zeros = zeros.size();
  if (num_zeros == 0 || num_zeros == N) {
    std::cout << 1 << std::endl;
    return 0;
  }
  zeros.push_back(N);
  std::vector<std::vector<std::vector<std::int64_t>>> mem(num_zeros + 1, std::vector<std::vector<std::int64_t>>(N + 1, std::vector<std::int64_t>(K + 1)));
  mem[num_zeros][N][0] = 1;
  for (int i = num_zeros - 1; i >= 0; --i) {
    for (int j = zeros[i]; j < N; ++j) {
      for (int k = std::max(j + 1, zeros[i + 1]); k <= N; ++k) {
        int m = std::max(0, (j - zeros[i]) - (k - zeros[i + 1]));
        for (int l = 0; l + m <= K; ++l) {
          mem[i][j][l + m] += mem[i + 1][k][l];
          mem[i][j][l + m] %= kModulus;
        }
      }
    }
  }
  std::int64_t sum = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= K; ++j) {
      sum += mem[0][i][j];
    }
  }
  std::cout << sum % kModulus << std::endl;
  return 0;
}


Measured memory_bytes: 111796
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N, K;
    cin >> N >> K;
    stringstream ans;
    while (N != 0) {
        int c = N % K;
        N /= K;
        ans << c;
    }

    cout << ans.str().size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a[5], k;
  int i, j, tmp;
  
  for ( i = 0; i < 5; i++ ) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &k);
  
  if ( a[4] - a[0] > k ) {
    printf(":(\n");
  }
  else {
    printf("Yay!\n");
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
typedef vector<int> vi;
typedef vector<vi> vvi;

int main(){
    int n,l;
    while(~scanf("%d %d",&n,&l) && n){
        vvi v(n);
        int t=-1;
        rep(i,n){
            char d; int p;
            cin>>d>>p;
            v[i]={p,d=='R' ? 1 : -1,i+1};
            t=max(t, (d=='L' ? p : l-p));
        }
        int ans;
        while(1){
            rep(i,v.size()) v[i][0]+=v[i][1];
            v.erase(remove_if(v.begin(),v.end(),[l](const vi& a){
                        return a[0]==0 || a[0]==l;
                    }),v.end());
            if(v.size()==0) break;
            sort(v.begin(),v.end());
            ans=v.front()[2];
            rep(i,v.size()-1){
                if(v[i][0]==v[i+1][0]){
                    swap(v[i][2],v[i+1][2]);
                }
            }
        }
        printf("%d %d\n",t,ans);
    }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  double m;
  while(cin>>a>>b,a!=0&&b!=0){
    m=100;
    for(int i=0;i<=a/2;i++){
      int j=a-i;
     m=min(m,abs(sqrt(i*i+j*j)-b));
  }
  printf("%.10f\n",m);
  }
  return 0;
}

Measured memory_bytes: 1196
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        String result;
        if (a + b == 15) {
            result = "+";
        } else if (a * b == 15) {
            result = "*";
        } else {
            result = "x";
        }

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


Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int N, K, X, Y;
    io.read(N, K, X, Y);
    cout << min(K, N) * X + max(0, N - K) * Y;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll p[]={a,1,0},q[]={b,0,1};
		while(*q){
			ll t=*p/ *q;
			rep(i,3) swap(p[i]-=t*q[i],q[i]);
		}
		if(p[0]<0) rep(i,3) p[i]=-p[i];
		x=p[1],y=p[2];
		return p[0];
	}
	ModInt inv() const {
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
int main(){
	int N,A[2001];
	mint K;
	mint maes[2001]={},ikos[2001]={};
	mint ans=0;
	scan(N>>K);
	rep(i,N){
		scan(A[i]);
	}
	rep(i,N){
		rep(j,N){
			if(i==j) continue;
			if(A[i]>A[j]){
				if(j<i) maes[i]++;
				else ikos[i]++;
			}
		}
	}
	rep(i,N){
		ans+=ikos[i]*K*(K+1)/2+maes[i]*(K-1)*K/2;
	}
	prin(ans);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i=0; i<N; i++) {
    cin >> d.at(i);
  }
  int answer = 0;
  for (int i=0; i<N; i++) {
    for (int j=1; j<N-i; j++) {
      answer += d.at(i)*d.at(i+j);
    }
  }
  cout << answer << endl;
}

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

int main() {
    int H, W;
    while (cin >> H >> W, H | W) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i + j) % 2) {
                    cout << ".";
                } else {
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;
using lint = long long;

int main(void)
{
    int N;
    string S;
    cin >> N;
    cin >> S;

    int ans = 1;
    for(int i = 1; i < N; i++){
        if(S[i] != S[i-1]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
n = int(input())

alp =  ["z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
name = ""
for i in range (30):
    name = alp[n%26]+name
    if n <=26:
        break
    if n%26 == 0:
        n = int(n/26 -1)
    else:
        n //=26
   

print(name)

Measured memory_bytes: 61872