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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, k;
	cin >> n >> k;
	cout << min(n % k, (n / k + 1) * k - n) << "\n";
}

Measured memory_bytes: 256
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 998244353


void solve()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	vector<vll> dp(c + 1, vll(d + 1, 0));
	dp[a][b] = 1;
	for (ll i = a; i <= c; i++)
	{
		for (ll j = b; j <= d; j++)
		{
			if (i != a or j != b)
				dp[i][j] = (mod + (dp[i - 1][j] * j) % mod + (dp[i][j - 1] * i) % mod - (dp[i - 1][j - 1] * (i - 1) * (j - 1)) % mod) % mod;
			//dp[i][j] %= mod;
		}
	}
	cout << dp[c][d] << "\n";
	return;
}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin >> t;
	// while (t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 73588
#include <stdio.h>
#include <math.h>
int main(void){
  int n,t[100001],x[100001],y[100001];
  t[0]=0;x[0]=0;y[0]=0;
  scanf("%d",&n);
  int i,j;
  for(i=1;i<=n;i++){
    scanf("%d %d %d",&t[i],&x[i],&y[i]);
  }
  int tm,dis;
  for(i=0;i<n;i++){
    tm=t[i+1]-t[i];
    dis=abs(x[i]-x[i+1])+abs(y[i]-y[i+1]);
    if(dis<=tm&&tm%2==dis%2) j=0;
    else {printf("No");return 0;}
  }
  printf("Yes");
  return 0;
}

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

int main(){

    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;

    int last = 1;
    int sum = 0;
    for(int i = 0; i <= c; i++){
        if(i == a * last){
            last += 1;
            sum += b;
        }
    }

    cout << sum << endl;

}



Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    vector <int> p(n);
    int c = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        if (p[i] != i + 1) c++;
    }

    if (c == 0 || c == 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 888
# coding: utf-8

while True:
	try:
		n = int(raw_input())
		cnt = 0
		for i in range(10):
			for j in range(10):
				for k in range(10):
					if n-i-j-k >= 0 and n-i-j-k <= 9:
						#print("{:}-{:}-{:}-{:}={:}".format(n,i,j,k,n-i-j-k))
						cnt += 1
		print cnt
	except EOFError:
		break

Measured memory_bytes: 4640
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif



int n,v,p,m,a[N];
ll s[N];

int main() {
	scanf("%d%d%d%d",&n,&m,&v,&p);
	REP(i,1,n) scanf("%d",a+i);
	sort(a+1,a+1+n,greater<int>());
	REP(i,1,n) s[i]=s[i-1]+a[i];
	int ans, pos = p;
	while (pos<n&&a[pos+1]==a[p]) ++pos;
	ans = pos++;
	REP(i,pos,n) {
		if (a[i]+m<a[p]) break;
		int j = i;
		while (j<n&&a[j+1]==a[i]) ++j;
		int cnt = v-(p-1)-(n-i+1);
		if (cnt>0) {
			if (s[i-1]-s[p-1]+(ll)cnt*m>(ll)(i-p)*(a[i]+m)) break;
		}
		ans += j-i+1;
		i = j;
	}
	printf("%d\n",ans);
}









Measured memory_bytes: 5120
import java.util.*;

import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int INF = (int) 1e9;
	public static char[][] s;
	public static int h;
	public static int w;
	public static void main(String[] args) {
		int i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		h = parseInt(sc.next());
		w = parseInt(sc.next());
		s = new char[h][w];
		int kabeCnt=0;
		for (i = 0; i < h; i++) {
			s[i] = sc.next().toCharArray();
			for (j = 0; j < s[i].length; j++) {
				if(s[i][j]=='#') kabeCnt++;
			}
		}
		sc.close();
		ArrayDeque<Point> que;
		int[][] ll;
		int[] dw = {-1, 1, 0, 0}; 
		int[] dh = {0, 0, -1, 1}; 
		que = new ArrayDeque<>();
		ll = new int[h][w];
		for (i = 0; i < h; i++) {
			Arrays.fill(ll[i], INF);
		}
		ll[0][0] = 0;
		que.add(new Point(0, 0));
		while (que.size() > 0) {
			Point p = que.removeFirst();
			if(p.h == h-1 && p.w == w-1) break;
			for (i=0; i<4; i++) {
				int ww = p.w+dw[i];
				int hh = p.h+dh[i];
				if(ww<0||ww>=w) continue;
				if(hh<0||hh>=h) continue;
				if (s[hh][ww] == '.'&&ll[hh][ww]==INF) {
					que.addLast(new Point(hh, ww));
					ll[hh][ww] = ll[p.h][p.w] + 1;
				}
			}
		}
//		out.println(Arrays.deepToString(ll));
		int l = ll[h-1][w-1];
		int ans=-1;
		if(l!=INF) {
			ans = h*w-kabeCnt-l-1;
		}
		out.println(ans);
	}
	public static int cntMasu(int x, int y, int m) {
		s[x][y]='#';
		if(x==w-1 && y==h-1) 
		if(x>0 && s[x-1][y]=='.')cntMasu(x-1, y, m+1);
		cntMasu(x, y, m+1);
		cntMasu(x, y, m+1);
		cntMasu(x, y, m+1);
		return m;
	}
}
class Point {
	int h;
	int w;
	Point(int h, int w) {
		this.h = h;
		this.w = w;
	}
	
}



Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>//cout << fixed からの cout << setprecision(n) << 小数　によって小数を整数部分含めてn桁表示できるようにする
#include <cctype>
#include <unordered_map>
using namespace std;
typedef long long unsigned int ll;
#define print(a) cout << a << endl;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> ok(n+1,1);
  vector<int> a(m);
  vector<ll> dp(n+1,0);
  for(int i = 0;i < m;i++) cin >> a[i];
  for(int i = 0;i < m;i++) ok[a[i]] = 0;
  dp[0] = 1;
  dp[1] = 1 * ok[1];
  for(int i = 1;i < n+1;i++){
    if(i != 1){
      dp[i] = ((dp[i-2]+dp[i-1]) * ok[i]) % 1000000007;
      }
    }
  //for(int i = 0;i < n+1; i++) cout << i << " " << dp[i] << endl;
  //cout << dp[n] << endl;
  print(dp[n])
  return 0;
}


Measured memory_bytes: 1792
import math
n=int(input())
a=list(map(int,input().split()))
mxa=max(a)

def get_sieve_of_eratosthenes(mxa):
    fact = [0]*(mxa+1)
    limit = int(math.sqrt(mxa))
    for i in range(2,limit+1):
        if fact[i]!=0:
            continue
        else:
            fact[i]=i
            for j in range(i, mxa+1, i):
                if fact[j]==0:
                    fact[j]=i
    for i in range(2,mxa+1):
        if fact[i]==0:
            fact[i]=i

    return fact

fact = get_sieve_of_eratosthenes(mxa)

lst=[0]*(len(fact))
for i in range(n):
    divisor = set()
    while a[i]!=1:
        divisor.add(fact[a[i]])
        a[i]//=fact[a[i]]
    for d in divisor:
        lst[d]+=1

pair=True
st=True

for i in lst:
    if i>=2:
        pair=False
    if i==n:
        st=False
if pair:
    print("pairwise coprime")
elif st:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 189448
#include <stdio.h>

int calc(int a,int c){
	if(a==4)	return c+4;
	
	c++;
	if(a%2==0)	calc(a/2,c);
	else	calc(a*3+1,c);
}

int main(){
	int s;
	
	scanf("%d",&s);
	
	if(s==1 || s==2)	printf("4");
	else	printf("%d",calc(s,0));
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a= scan.nextInt();
		int b= scan.nextInt();
		scan.close();

		if( (1<=a && a<10) && (1<=b && b<10) )
		System.out.println(a*b);
		else
		System.out.println(-1);
	}
}

Measured memory_bytes: 23764
a, b, c = gets.split(" ").map(&:to_i)
ary = []
cnt = 0
c.times do |i|
	if c % (i+1) == 0
		ary.push(i+1)
	end
end
ary.each do |num|
	if num >= a && num <= b
		cnt += 1
	end
end
puts cnt

Measured memory_bytes: 8708
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, D = inl()


def solve():
    cnt = 0
    for i in range(N):
        x, y = inl()
        if x * x + y * y <= D * D:
            cnt += 1
    return cnt


print(solve())


Measured memory_bytes: 9204
N, M = map(int, input().split())
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px < py:
        p[py] = px
    else:
        p[px] = py
*p, = range(N)

for i in range(M):
    x, y, z = map(int, input().split())
    unite(x-1, y-1)
ans = 0
for i in range(N):
    if root(i) == i:
        ans += 1
print(ans)

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

#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<int,int>

using namespace std;

int n,a[N],s[2 * N],l,r,md,cep,sag,x;
ll ans,jog,den;
ll dg,p[N],sum,m;

int main()
{
	scanf("%d%lld",&n,&m);
	for(int i = 1;i <= n;i++){
		scanf("%d",a + i);
		s[a[i]]++;
	}
	sort(a + 1,a + n + 1);
	for(int i = 1;i <= n;i++)
		p[i] = p[i - 1] + a[i];
	l = 1,r = 2 * 1e5;
	while(l <= r){
		md = mid(l,r);
		ans = den = sum = 0;
		for(int i = 1;i <= n;i++){
			cep = 1,sag = n;
			jog = n + 1;
			while(cep <= sag){
				x = mid(cep,sag);
				if(a[x] + a[i] >= md){
					jog = x;
					sag = x - 1;
				}
				else cep = x + 1;
			}
			if(jog == n + 1) continue;
			ans += n - jog + 1;
			sum += p[n] - p[jog - 1] + (n - jog + 1) * a[i];
			if(a[i] + a[i] == md) den += s[a[i]] - 1;
			else if(a[i] < md) den += s[md - a[i]];
			
		}
		
		if(ans >= m){
			ans -= den;
			sum -= den * md;
			if(ans <= m) dg = sum + (m - ans) * md;
			l = md + 1;
		}	
		else r = md - 1;
	}
	printf("%lld",dg);
}
/*
9 14
1 3 5 110 24 21 34 5 3
*/

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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int> > V(M+1);
    rep(i, N){
        int a, b; cin >> a >> b;
        if(a > M)continue;
        V[a].push_back(b);
    }
    priority_queue<int> q;
    int ans = 0;
    for (int i = 1; i <= M; i++){
        rep(j, V[i].size()){
            q.push(V[i][j]);
        }
        if(!q.empty()){
            int x = q.top(); q.pop();
            ans += x;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int mod = 1e9 + 7;

void add_self(int&a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
int mul(int a, int b) {
    return (ll) a * b % mod;
}

int n;

struct M {
    vector<vector<int>> t;
    M() {
        t.resize(n, vector<int>(n));
    }
    M operator* (const M& b) const {
        M c = M();
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                for(int k = 0; k < n; ++k) {
                    add_self(c.t[i][k], mul(t[i][j], b.t[j][k]));
                }
            }
        }
        return c;
    }
};

int main() { // O(K * N^2)
    ll k;
    scanf("%d%lld", &n, &k);
    vector<vector<int>> can(n, vector<int>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            scanf("%d", &can[i][j]);
        }
    }
    M answer = M();
    for(int i = 0; i < n; ++i) {
        answer.t[i][i] = 1;
    }
    M m = M();
    m.t = can;
    while(k) {
        if(k % 2) {
            answer = answer * m;
        }
        m = m * m;
        k /= 2;
    }
    int total = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            add_self(total, answer.t[i][j]);
        }
    }
    printf("%d\n", total);
    return 0;
    
    vector<int> dp(n, 1);
    // dp[i] - the number of ways we got to vertex 'i' so far
    for(ll step = 0; step < k; ++step) {
        vector<int> new_dp(n);
        for(int a = 0; a < n; ++a) {
            for(int b = 0; b < n; ++b) {
                if(can[a][b]) {
                    add_self(new_dp[b], dp[a]);
                }
            }
        }
        dp = new_dp;
    }
    //~ int answer = 0;
    //~ for(int i = 0; i < n; ++i) {
        //~ add_self(answer, dp[i]);
    //~ }
    //~ printf("%d\n", answer);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
  string s1, s2;
  int nl;
  cin>>nl>>s1>>s2;
  for(int i = 0; i < s1.size(); i ++)
  {
    cout<<s1[i]<<s2[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	String r,g,b;
	public void solve() {
		r = next();
		g = next();
		b = next();

		if(Integer.parseInt(r + g + b) % 4 == 0){
			out.println("YES");
		}else{
			out.println("NO");
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

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

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

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

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

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
ll t[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    ll n, c, k;
    cin >> n >> c >> k;
    for (int i = 0; i < n; i++)
        cin >> t[i];
    sort(t, t + n);
    ll res = 1;
    ll cur_time = t[0] + k;
    ll cur_num = 1;
    for (int i = 1; i < n; i++) {
        if (t[i] > cur_time || cur_num >= c) {
            cur_time = t[i] + k;
            cur_num = 1;
            res++;
        } else {
            cur_num++;
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length() - 1; i++) {
            char c = s.charAt(i);
            if (c == 'a' || 'z' - c + 1 > k) {
                sb.append(c);
                continue;
            }
            sb.append('a');
            k -= 'z' - c + 1;
        }
        char c = s.charAt(s.length() - 1);
        if (k == 0) {
            sb.append(c);
        } else {
            k %= 26;
            sb.append((char) (((c - 'a' + k) % 26) + 'a'));
        }
        System.out.println(sb);
    }

}

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

using namespace std;

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    set<string> s;
    string a;
    for(int i=0;i<n;i++){
        cin>>a;
        s.insert(a);
    }
    cout<<s.size();
    return 0;
}

Measured memory_bytes: 19244
#include<iostream>

using namespace std;


int main()
{
	int N;
	int T;
	int t[200000];

	int X = 0;

	cin >> N >> T;

	for (int i = 0; i < N; i++) {
		cin >> t[i];
	}

	for (int i = 0; i < N-1; i++) {
		X += T;
		if (t[i + 1] - t[i] < T) {
			X -= T - (t[i + 1] - t[i]);
		}
	}
	X += T;

	cout << X << endl;

	return 0;
}

Measured memory_bytes: 1024
S = input()
l = S[:2]
r = S[2:]

lcnt = 0
rcnt = 0
if 0 < int(l) <= 12:
    lcnt = 1
if  0 < int(r) <= 12:
    rcnt = 1
if lcnt and rcnt:
    print('AMBIGUOUS')
    exit()
elif lcnt:
    print('MMYY')
    exit()
elif rcnt:
    print('YYMM')
    exit()
else:
    print('NA')


Measured memory_bytes: 3060
a, b, c, x, y = map(int, input().split())
ans = []
if x > y:
    ans.append((x - y) * a + (c * y) * 2)
else:
    ans.append((y - x) * b + (c * x) * 2)
ans.append(x * a + y * b)
ans.append(max(x, y) * (c * 2))
print(min(ans))

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

using namespace std;

int d[11][11];
static const int INF = 99999999;

void solve() {
  int n;
  while (cin >> n && n) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        d[i][j] = INF;
      }
      d[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int from, to, dist;
      cin >> from >> to >> dist;
      d[from][to] = dist;
      d[to][from] = dist;
    }
    for (int k = 0; k < 10; k++) {
      for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
    int min_sum_dist = INF;
    int pos = 0;
    for (int i = 0; i < 10; i++) {
      int sum = 0;
      for (int j = 0; j < 10; j++) {
        if (d[i][j] != INF) sum += d[i][j];
      }
      if (sum == 0) continue;
      if (min_sum_dist > sum) {
        min_sum_dist = sum;
        pos = i;
      }
    }
    cout << pos << ' ' << min_sum_dist << endl;
  }
}

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

Measured memory_bytes: 3148
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){

  int n = 1, x = 1;
  int a, b, c;
  int count = 0;

  while(n > 0 || x > 0){
    count = 0;
    scanf("%d %d", &n, &x);
    if(n == 0 && x == 0){
      break;
    }else{
      for(a = 1; a <= n; a++){
	for(b = a + 1; b <= n; b++){
	  for(c = b + 1; c <= n; c++){
	    if(a + b + c == x){
	      count++;
	    }
	  }
	}
      }
      printf("%d\n", count);
    }
  }
  
  return 0;
}


Measured memory_bytes: 2052
#include<stdio.h>
int main(void)
{
	long long x,i,m,cnt,a;
	scanf("%lld",&x);
	m=100;
	cnt=0;
	while(m<x){
		a=m*1/100;
		m=a+m;
		cnt++;
	}
		printf("%lld\n",cnt);
	return 0;
}

Measured memory_bytes: 1736
#include"bits/stdc++.h"
using namespace std;
int a[2001][2001];
int h,w;

int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif


	cin>>h>>w;
	vector<string> s(h);

	for(int i=0;i<h;i++)cin>>s[i]; //O(h*w)
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)if(s[i][j]=='.')a[i][j]=1;
	int ans=0;
	for(int i=0;i<h;i++)
	{
		int cur=0;
		for(int j=0;j<w;j++)
		{
			if(s[i][j]=='#')cur=0;
			else {a[i][j]+=cur;cur++;}
		}
		cur=0;
		for(int j=w-1;j>=0;j--)
		{
			if(s[i][j]=='#')cur=0;
			else {a[i][j]+=cur;cur++;}
		}
	}

	for(int j=0;j<w;j++)
	{
		int cur=0;
		for(int i=0;i<h;i++)
		{
			if(s[i][j]=='#')cur=0;
			else {a[i][j]+=cur;cur++;}
		}
		cur=0;
		for(int i=h-1;i>=0;i--)
		{
			if(s[i][j]=='#')cur=0;
			else {a[i][j]+=cur;cur++;}
		}
	}
	for(int i=0;i<h;i++)
		{for(int j=0;j<w;j++)
		{
			//cout<<a[i][j]<<" ";
			ans=max(ans,a[i][j]);
		}
		}
	cout<<ans;

}

Measured memory_bytes: 26824
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N; N+=2;
  string C; cin>>C; C =	"R" + C	+ "W";
  int cnt = 0;
  int w = 0, r = N-1;
  int ww = -1, rr = N;
  while(true) {
    while(C[w] != 'W') w++;
    while(C[r] != 'R') r--;
    if(w > r) break;
    ww = w;
    rr = r;
    w++; r--;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3424
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

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

	vector<int32_t> h(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end());

	int32_t res = numeric_limits<int32_t>::max();
	for (int32_t i = 0; i + K - 1 < N; i++) {
		res = min(res, h[i + K - 1] - h[i]);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
string w;

vector <int> a;




int main()
{

	cin >> w;
	int num = 'z' - 'a';
	int c;
	a.resize(num+1);

	REP(i,w.size()){
		c = w[i] - 'a';
		a[c]++;
	}
	REP(i,a.size()){
		if(a[i]%2 != 0){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;


}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,d[50],i,j,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&d[i]);
	sum=0;
	for(i=n-1;i>=0;i--){
		for(j=i-1;j>=0;j--){
			sum+=d[i]*d[j];
		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int r, g, b;
  
  scanf("%d %d %d", &r, &g, &b);
  
  if((10*g+b)%4 == 0) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
	char S[1010], T[1010];
	scanf("%s", S);
	scanf("%s", T);
	int s = 0, t = 0;
	while(T[t] != '\0'){
		t++;
	}
	while(S[s] != '\0'){
		s++;
	}
	int p = 0, ans = t;
	while(s - p >= t){
		int count  = 0;
		for(int i = p; i < p + t; i++){
			if(S[i] != T[i-p]){
				count++;
			}
		}
		if(ans > count){
			ans = count;
		}
		p++;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1728
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 1
if N == K:
    for a in A:
        ans = ans * a % MOD
    print(ans)
    exit(0)

minus = []
plus = []
for a in A:
    if a < 0:
        minus.append(a)
    else:
        plus.append(a)

if len(minus) == N:
    if K % 2 == 0:
        A.sort()
    else:
        A.sort(reverse=True)
    for i in range(K):
        ans = ans * A[i] % MOD
    print(ans)
    exit(0)

minus.sort(reverse=True)
plus.sort()

if  K % 2:
    ans *= plus.pop()

B = []

while len(minus) > 1:
    a = minus.pop()
    b = minus.pop()
    B.append(a * b)

while len(plus) > 1:
    a = plus.pop()
    b = plus.pop()
    B.append(a * b)

B.sort()

for i in range(K // 2):
    ans = ans * B.pop() % MOD

print(ans)


Measured memory_bytes: 31724
fun main(args: Array<String>) {
    val (m, d) = readLine()!!.split(' ').map(String::toLong)

    var count = 0
    for (mt in 1..m) {
        for (dt in 1..d) {
            if ((dt % 10) < 2) continue
            if ((dt / 10) < 2) continue
            if ((dt / 10) * (dt % 10) == mt) count++
        }
    }
    println(count)
}

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

int mod = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	int z[n][n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> z[i][j];
		}
	}
	
	vector<long long> dp(1 << n);
	dp[0] = 1;
	for (int i = 0; i < (1 << n) - 1; i++) {
		int m = __builtin_popcount(i);
		for (int w = 0; w < n; w++) {
			if (z[m][w] && !(i&(1 << w))) {
				dp[i|(1 << w)] += dp[i];
				dp[i|(1 << w)] %= mod;
			}
		}
	}
	cout << dp[(1 << n) - 1];
}

Measured memory_bytes: 19560
import itertools
def memo_rec(N):
    if N == 3:
        return 61
    if N == 4:
        return 230
    L = "ATGC"
    MOD = 10 ** 9 + 7
    dic = {}
    def rec(s, k):
        if s.count("AGC"):
            return 0
        for i in range(3):
            t1, t2 = s[i], s[i + 1]
            if (s[:i] + t2 + t1 + s[i+2:]).count("AGC"):
                return 0
        if k == 0:
            return 1
        if s + str(k) in dic:
            return dic[s + str(k)]
        else:
            ret = 0
            for x in L:
                ret = (ret + rec(str(x + s[:3]), k - 1)) % MOD
            dic[s + str(k)] = ret
            return ret
    ret = 0
    for s in itertools.product(L, repeat = 4):
        t = ''
        for x in s:
            t += x
        ret = (ret + rec(t, N - 4)) % MOD
    return ret

N = int(input())
print(memo_rec(N))


Measured memory_bytes: 48860
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int sign(double x){
  return (x>0)-(x<0);
}

int deg(char *xy, int d){
  if(xy[0] == 'B') return 120 - d; //BC 
  if(xy[0] == 'C') return 60  - d; //CD
  if(xy[0] == 'D') return 180 - d; //DB 
}

int getID(int deg, int l){
  double eps = 1e-7;
  double s = sqrt(3)/2;
  
  double a = cos((deg-30) / 180.0 * M_PI) * l;
  double b = cos((deg-90) / 180.0 * M_PI) * l;
  double c = cos((deg-150)/ 180.0 * M_PI) * l;

  int A = floor(a / s + eps * sign(a));
  int B = floor(b / s + eps * sign(b));
  int C = floor(c / s + eps * sign(c));
  
  if((A + B) % 2 == 0)
    return (A + C) % 2 ? 3 : 1;
  else
    return (A + C) % 2 ? 2 : 4;
}

int main(){
  char xy[2][3];
  int d[2], l[2];

  for(int i=0;i<2;i++){
    scanf("%s%d%d",xy[i], d+i, l+i);
    d[i] = deg(xy[i], d[i]);
  }
  
  puts(getID(d[0],l[0]) == getID(d[1],l[1]) ? "YES" : "NO");
  
  return 0;
}



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

int main(){
  int N,K;
  int ai[1000],bi[1000];
  int ans[1000];

  cin >> N >> K;

  for(int i=0; i< K; ++i){
    cin >> ai[i] >> bi[i];
  }

  int worka, workb;
  for(int i=0; i<K; ++i){
    worka = ai[i] % 3;
    workb = bi[i] % 3;

    if(bi[i] >= ai[i]){
      if(bi[i] <= N - ai[i] + 1){
	if(worka == 0){
	  cout << 3 << endl;
	}else {
	  cout << worka << endl;
	}
      }else{
      int w = N - bi[i] + 1;//bi[i] - (N - ai[i] + 1);
	w = w % 3;
	if(w == 0){
	  cout << 3 << endl;
	}else{
	  cout << w << endl;
	}
      }
    }else {
      if(ai[i] <= N - bi[i] + 1){
	if(workb == 0){
	  cout << 3 << endl;
	}else{
	  cout << workb << endl;
	}
      }else{
	int w = N - ai[i] + 1;//ai[i] - (N - b[i] + 1);
	w = w % 3;
	if(w == 0){
	  cout << 3 << endl;
	}else{
	  cout << w << endl;
	}
      }
    }

  }
  
  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int smallest = INT32_MAX;
    rep(i, n)
    {
        int a;
        cin >> a;
        if (a < smallest)
        {
            ans++;
            smallest = a;
        }
    }

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

Measured memory_bytes: 384
# -*- coding: utf-8 -*-

n = int(input())
a_u = list(map(int, input().split()))
a_d = list(map(int, input().split()))

num_list = []

for i in range(n):
    num_list.append(sum(a_u[:i+1]) + sum(a_d[i:]))

print(max(num_list))

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << (s.at(2) == s.at(3) && s.at(4) == s.at(5) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    ll a, b, k, cnt = 0; cin >> a >> b >> k;
    set<ll> s;
    Rep(i, a, b+1){
        if(cnt == k) break;
        s.insert(i);
        cnt++;
    }
    cnt = 0;
    for(ll i=b; i>=a; i--){
        if(cnt == k) break;
        s.insert(i);
        cnt++;
    }
    for(auto p: s){
        cout << p << endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w)),b(h,vector<int>(w));
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> a[i][j];
    int cnt = 0;
    b = a;
    for(int i = 0; i < h; i++){
        if(i%2 == 0){
            for(int j = 0; j < w-1; j++){
                if(b[i][j]%2){
                    cnt++;
                    b[i][j]--,b[i][j+1]++;
                }
            }
            if(i == h-1) break;
            if(b[i][w-1]%2){
                cnt++;
                b[i][w-1]--,b[i+1][w-1]++;
            }
        }else{
            for(int j = w-1; j >= 1; j--){
                if(b[i][j]%2){
                    cnt++;
                    b[i][j]--,b[i][j-1]++;
                }
            }
            if(i == h-1) break;
            if(b[i][0]%2){
                cnt++;
                b[i][0]--,b[i+1][0]++;
            }
        }
    }
    cout << cnt << endl;
    for(int i = 0; i < h; i++){
        if(i%2 == 0){
            for(int j = 0; j < w-1; j++){
                if(a[i][j]%2){
                    cout << i+1 << ' ' << j+1 << ' ' << i+1 << ' ' << j+2 << endl;
                    a[i][j]--,a[i][j+1]++;
                }
            }
            if(i == h-1) break;
            if(a[i][w-1]%2){
                cout << i+1 << ' ' << w << ' ' << i+2 << ' ' << w << endl;
                a[i][w-1]--,a[i+1][w-1]++;
            }
        }else{
            for(int j = w-1; j >= 1; j--){
                if(a[i][j]%2){
                    cout << i+1 << ' ' << j+1 << ' ' << i+1 << ' ' << j << endl;
                    a[i][j]--,a[i][j-1]++;
                }
            }
            if(i == h-1) break;
            if(a[i][0]%2){
                cout << i+1 << ' ' << 1 << ' ' << i+2 << ' ' << 1 << endl;
                a[i][0]--,a[i+1][0]++;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4096
n = int(input())
A = list(map(int,input().split()))
val1 = sum(A)//n
val2 = val1+1
ans1 = 0
ans2 = 0
for a in A:
    ans1 += (a-val1)**2
    ans2 += (a-val2)**2
print(min(ans1,ans2))


Measured memory_bytes: 9060
#include <iostream>
using namespace std;
int main() {
    int n, m, i, j, k, t, mx = 0;
    int C[51][4] = {0};
    char wbr[] = {'W','B','R'};
    char cc;
    cin >> n >> m;
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            cin >> cc;
            for (k = 0; k < 3; k++) {
                if (wbr[k] == cc) {
                    C[i][k]++;
                }
            }
        }
    }
    for (i = 1; i < n-1; i++) {
        for (j = i+1; j < n; j++) {
            t = 0;
            int rw, rb, rr;
            for (rw = 0;rw < i; rw++) {
                t += C[rw][0];
            }
            for (rb = i;rb < j; rb++) {
                t += C[rb][1];
            }
            for (rr = j;rr < n; rr++) {
                t += C[rr][2];
            }
            mx = max(mx, t);
        }
    }
    cout << (n * m) - mx << endl;
    return 0;
}



Measured memory_bytes: 3076
N = int(input())
H = [int(x) for x in input().split()]
dp = [0]*N
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
    
print(dp[N-1])

Measured memory_bytes: 13980
n=STDIN.gets.to_i
vs = STDIN.gets.split(' ').map(&:to_i)
cs = STDIN.gets.split(' ').map(&:to_i)
cost = 0
vs.each_with_index do |v, i|
    rv = vs[i] - cs[i]
    if rv > 0
      cost += rv
    end
end
puts cost

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

typedef long long ll;

int main() {
    string A;
    cin >> A;
    rep(i, 8) {
        int s = A[0] - '0';
        if (i & 1) s += A[1] - '0';
        else s -= A[1] - '0';
        if ((i >> 1) & 1) s += A[2] - '0';
        else s -= A[2] - '0';
        if ((i >> 2) & 1) s += A[3] - '0';
        else s -= A[3] - '0';
        if (s != 7) continue;
        cout << A[0];
        if (i & 1) cout << "+";
        else cout << "-";
        cout << A[1];
        if ((i >> 1) & 1) cout << "+";
        else cout << "-";
        cout << A[2];
        if ((i >> 2) & 1) cout << "+";
        else cout << "-";
        cout << A[3] << "=7\n";
        return 0;
    }
}

Measured memory_bytes: 256
import           Control.Applicative
import           Data.Maybe

calc :: String -> Maybe Int
calc xs
    | op == "+" = Just $ read a + read b
    | op == "-" = Just $ read a - read b
    | op == "*" = Just $ read a * read b
    | op == "/" = Just $ read a `div` read b
    | otherwise = Nothing
  where
    [a, op, b] = words xs

main :: IO ()
main = do
    xs <- catMaybes . takeWhile isJust . fmap calc . lines <$> getContents
    mapM_ print (xs :: [Int])



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

int fact(int n){
    if(n==0) return 1;
    else return n*fact(n-1);
}

int main(void){
    int n;
    cin >> n;
    vector<pair<int,int>> town(n);
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        town[i] = make_pair(x,y);
    }
    sort(town.begin(),town.end());

    double dist = 0;
    do{
        for(int i=0;i<n-1;i++){
            int dx = town[i].first-town[i+1].first;
            int dy = town[i].second-town[i+1].second;
            dist += sqrt(dx*dx+dy*dy);
        }
    }while(next_permutation(town.begin(),town.end()));

    double ans = dist/fact(n);
    printf("%.10f\n", ans);
    return 0;

}

Measured memory_bytes: 256
<?php

$N = trim(fgets(STDIN));
$v = explode(' ', trim(fgets(STDIN)));
$v = array_map('intval', $v);
sort($v);

while (count($v) != 1) {
    $sliced = array_slice($v, 0, 2);
    $v = array_slice($v, 2);
    $sum = array_sum($sliced);
    $ans = $sum / 2;
    array_unshift($v, $ans);
}

echo $v[0], "\n";


Measured memory_bytes: 4984
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int n, a[99999],i,ans=0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i] * (-2 * (i % 2) + 1);
	}
	cout << ans << " ";
	for (i = 0; i < n-1; i++) {
		ans = (a[i] - ans / 2) * 2;
		cout << ans << " ";
	}
    return 0;
}

Measured memory_bytes: 2048
// Problem : D - Water Bottle
// Contest : AtCoder - AtCoder Beginner Contest 144
// URL : https://atcoder.jp/contests/abc144/tasks/abc144_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	ld A,B,X;
	cin>>A>>B>>X;
	// bug(A);
	// bug(B);
	// bug(X);
	ld val=1e-14;
	cout<<setprecision(18)<<fixed;
	if(X<A*A*B/2)
	{
		// val=90-atan(2*X/A/A/B);
		cout<<90-atan(2*X/(A*B*B))*180/pii;
		return 0;
	}
	else
		val=atan(2*((A*A*B-X)/(A*A*A)));
	cout<<val*180.0/pii<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

using namespace std;


int main()
{
    int N, M;
    vector<int> A, B, Ans;
    
    cin >> N; 
    A.resize(N);
    for(int i = 0; i < N; ++i)
      cin >> A[i];
      
    cin >> M;
    B.resize(M);
    for(int i = 0; i < M; ++i)
      cin >> B[i];
      
      
    set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(Ans, Ans.end()));
    
    for(auto x : Ans)
      cout << x << endl;
    
    return 0;
}


Measured memory_bytes: 4660
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> A(n);
    vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for (int j = 0; j < n; ++j) {
        cin >> B[j];
    }

    int MX = *max_element(A.begin(), A.end());
    MX = max(MX, *max_element(B.begin(), B.end()));

    int res = 0;
    int h = 0;
    while (1 << (h + 1) <= MX) {
        ++h;
    }
    ++h;

    auto calc = [&](int M) {
        vector<int> SA;
        SA.reserve(n);
        vector<int> SB;
        SB.reserve(n);
        for (int i = 0; i < n; ++i) {
            SA.push_back(A[i] & ((M << 1) - 1));
            SB.push_back(B[i] & ((M << 1) - 1));
        }
        sort(SA.begin(), SA.end());
        sort(SB.begin(), SB.end());

        // for (auto x : SA) {
        //     cout << x << " ";
        // }
        // cout << endl;
        // for (auto x : SB) {
        //     cout << x << " ";
        // }
        // cout << endl;

        long long res = 0;
        for (auto& p : vector<pair<int,int>> {{M, (M << 1) - 1}, {3 * M, (M << 2) - 1}}) {
            int L = p.first;
            int R = p.second;

            for (int i = 0, l = n - 1, r = n - 1; i < n; ++i) {
                while (l >= 0 && SA[i] + SB[l] >= L) {
                    --l;
                }
                while (r >= 0 && SA[i] + SB[r] > R) {
                    --r;
                }
                res += max(0, r - l);
                // cout << M << " " << L << " " << R << " :: " << SA[i] <<  " " << l << " " << r << endl;
            }
        }
        // cout << "res " << res << endl;
        return res;
    };

    for (int i = 0; i <= h; ++i) {
        long long cnt = calc(1 << i);
        if (cnt & 1) {
            res |= 1 << i;
        }
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleTest
{
    class Program
    {
        
        static void Main(string[] args)
        {
            var v = MyIo.Int();
            int num500 = v / 500;
            int num5 = (v % 500) / 5;
            int u = num500 * 1000 + num5 * 5;
            Console.WriteLine(u.ToString());

           
        }

    }
    static class MyIo
    {
        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }
        public static int[] Ints()
        {
            return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }
        public static int[][] MultiInts(int num)
        {
            var result = new int[num][];
            for(int i = 0; i < num; ++i)
            {
                result[i] = Ints();
            }
            return result;
        }
        public static T[] MultiItems<T>(int num, Func<string,T> parser)
        {
            var result = new T[num];
            for(int i =0; i < num; ++i)
            {
                result[i] = parser(Console.ReadLine());
            }
            return result;
        }
    }
}


Measured memory_bytes: 13140
def pat(n, x):
    if x == 0:
        return 0
    if n == 0:
        return 1
    a = 2 ** (n + 2) - 3
    if a // 2 + 1 <= x:
        return 2 ** n + pat(n - 1, x - a // 2 - 1)
    elif a // 2 == x:
        return 2 ** n - 1
    else:
        return pat(n - 1, x - 1)


n, x = map(int, input().split())
print(pat(n, x))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c=0,d;
  cin>>a>>b;
  b=b+b+1;
  while(true){

    if(a<=0){
      break;
    }
    a=a-b;
    c++;
  }
  cout<<c<<"\n";
  return(0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        sc.close();

        String ans = "";
        for (int i = 0; i < n; i++) {
            if (i == k - 1) {
                ans += String.valueOf(s.charAt(i)).toLowerCase();
            } else {
                ans += s.charAt(i);
            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 23764