akhauriyash/Code-Regression huggingface dataset:
def choose(n, r, mod = 10 ** 9 + 7)
  r = n - r if r > n - r
  ((n - r + 1)..n).inject(1){|sum, item|(sum * item) % mod} \
    * modpow((1..r).inject(1){|sum, item|(sum * item) % mod}, mod - 2, mod) \
    % mod
end

def modpow(n, p, mod = 10 ** 9 + 7)
  res = 1
  while p > 0
    if p & 1 == 1
      res = (res * n) % mod
    end
    n = (n ** 2) % mod
    p >>= 1
  end
  res
end

def prm_fct(n)
  pre = n
  res = Hash.new(0)
  i = 2
  while i * i <= pre
    if n % i == 0
      cnt = 0
      while n % i == 0
        cnt += 1
        n /= i
      end
      res[i] = cnt
    end
    i += 1
  end
  if n * n > pre
    res[n] = 1
  end
  return res
end

MOD = 10 ** 9 + 7
N, M = gets.split.map(&:to_i)

lists = prm_fct(M)
# p lists
ans = 1
lists.each do |a, b|
  # N個に分ける→N-1つの柵を挟む
  ans = (ans * choose(b + N - 1, N - 1, MOD)) % MOD
end
puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 gcd(s64 x, s64 y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}

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

    s64 k;
    cin >> k;

    s64 ans = 0;
    for (s64 a = 1; a <= k; ++a)
    {
        for (s64 b = 1; b <= k; ++b)
        {
            for (s64 c = 1; c <= k; ++c)
            {
                ans += gcd(a, gcd(b, c));
            }
        }
    }

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



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    printf("%d %d %d",c,a,b);
    return 0;
}



Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i] != L[j] and L[j] != L[k] and L[i] != L[k] and max(L[i],L[j],L[k]) < sum([L[i],L[j],L[k]])/2:
                count+=1
print(count)

Measured memory_bytes: 74576
s = input()

n = len(s)
flag = True
for i in range((n-1)//2):
    if flag == False:
        break
    if s[i] != s[-(i+1)]:
        print('No')
        #print(i,'1')
        flag = False
    elif s[i] != s[-(i+2+(n-1)//2)]:
        print('No')
        #print(i,'2')
        flag = False
    elif s[(i-1+(n+3)//2)] != s[-(i+1)]:
        print('No')
        #print(i,'3')
        flag = False
    
if flag == True:
    print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

bool is_yymm(ll a, ll b) {
    return ((b >= 1) && (b <= 12));
}

bool is_mmyy(ll a, ll b) {
    return ((a >= 1) && (a <= 12));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    string ls = s.substr(0, 2);
    string rs = s.substr(2);
    ll lsv = atoi(ls.c_str());
    ll rsv = atoi(rs.c_str());
    if (is_yymm(lsv, rsv) && is_mmyy(lsv, rsv)) {
        cout << "AMBIGUOUS" << endl;
    }
    else if (is_yymm(lsv, rsv)) {
        cout << "YYMM" << endl;
    }
    else if (is_mmyy(lsv, rsv)) {
        cout << "MMYY" << endl;
    }
    else {
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
x,y = map(int, input().split())
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
g3 = [2]
if x in g1 and y in g1:
    print('Yes')
elif x in g2 and y in g2:
    print('Yes')
elif x in g3 and y in g3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
N=input()
b=input()
g=list(b)
d=list(b.encode("ascii"))
if(len(d) % 2 == 1):
  print('No')
else:
  c=0
  a=len(d)//2
  for i in range(0,a):
    if(d[i]!=d[i+a]):
        c=c+1
  if(c==0):    
   print('Yes')
  else:
    print('No')

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	a := make([]int, 0)
	for {
		var v int
		fmt.Scan(&v)
		if v == 0 {
			break
		}
		a = append(a, v)
	}
	for i := 0; i < len(a); i++ {
		fmt.Printf("Case %d: %d\n", i+1, a[i])
	}
}



Measured memory_bytes: 2316
#include <iostream>

using namespace std;

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if(x-r<0 || y-r<0 || x+r>W || y+r>H)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	if( n % 111 == 0 ) cout << n << endl;
	else cout << 111 * (n / 111 + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::*;

fn main() {
    println!("{}", min::<u32>(read(), read()) + min::<u32>(read(), read()));
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class UnionFindCnt {
    private :
        std::vector<int> par;
        std::vector<int> cnt;
    public :
        UnionFindCnt(int n) {
            par.resize(n);
            for (int i=0; i<n; i++) par[i] = i;
            cnt.assign(n, 1);
        }
        void unite(int x, int y) {
            const int x_par = find(x);
            const int y_par = find(y);
            if (x_par == y_par) return;

            par[x_par] = y_par;
            cnt[y_par] += cnt[x_par];
            cnt[x_par] = 0;
        }
        int find(int x) {
            if (par[x] == x) return x;
            else return par[x] = find(par[x]);
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int size(int x) { return cnt[find(x)]; }
};

void solve() {
    int N, M;
    cin >> N >> M;

    UnionFindCnt uf(N);
    for (int i=0; i<M; ++i) {
        int a, b;
        cin >> a >> b;
        uf.unite(a-1, b-1);
    }
    int ans = 0;
    for (int i=0; i<N; ++i) chmax(ans, uf.size(i));
    cout << ans << '\n';
}

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

    solve();

    return 0;
}


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

using namespace std;
using ll = long long;
const int nax = 2 * 1e5 + 5;
ll f[nax];
ll mil(ll a, ll b){
	if(a&1) b/=2;
	else a/=2;
	return a*b;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	int n ;
	//cout << nax;
	cin >> n;
	vector<int>a(n);
	for(int i = 0; i < n;++i){
		cin >> a[i];
		f[a[i]]++;
	}
	ll total = 0;
	for(int i = 0; i <= n; ++i){
		if(f[i] >= 2){
			total += mil(f[i], f[i] - 1ll);
		}
	}
	//cout << f[1] <<" " << f[2] <<"cc";
	for(int i = 0 ;i < n; i++){
		if(f[a[i]] >= 2){
		cout << total - mil(f[a[i]], f[a[i]] - 1ll) +
		mil(f[a[i]] - 1ll, f[a[i]] - 2ll) << "\n";
		}
		else{
			// if(f[a[i]] == 2)
			// 	cout << max(total - 1, 0ll) <<"\n";
			// else 
				cout << total <<"\n";
		}
	}
}




Measured memory_bytes: 3968
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

void Main() {
  //自動整形防止用コメント
  int x, a;
  std::cin >> x >> a;
  std::cout << (x < a ? 0 : 10) << '\n';
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
while True:
    try:
        a, b, c, d, e, f = map(float, input().split())
        x = round((c * e - b * f) / (a * e - b * d), 3)
        y = round((a * f - c * d) / (a * e - b * d), 3)
        print('{0:.3f} {1:.3f}'.format(x + 0, y + 0))
    except:
        break

Measured memory_bytes: 7344
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		List<Point> red = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			Point p = new Point(a, b);
			red.add(p);
		}

		List<Point> blue = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			Point p = new Point(a, b);
			blue.add(p);
		}

		red.sort((a, b) -> a.a - b.a);
		blue.sort((a, b) -> a.a - b.a);

		for (Point bp : blue) {
			List<Point> possible = new ArrayList<>();
			for (Point rp : red) {
				if (bp.a < rp.a)
					break;

				if (bp.b > rp.b) {
					possible.add(rp);
				}
			}
			possible.sort((a, b) -> b.b - a.b);

			// System.out.println(possible);
			for (Point point : possible) {
				if (point.paired) {
					continue;
				} else {
					point.paired = true;
					break;
				}
			}
		}

		long count = red.stream().filter(p -> p.paired).count();
		System.out.println(count);
//
//		red.forEach(System.out::println);
//		blue.forEach(System.out::println);

		sc.close();
	}

}

class Point {
	@Override
	public String toString() {
		return "Point [a=" + a + ", b=" + b + ", paired=" + paired + "]";
	}

	int a;
	int b;
	Boolean paired = false;

	public Point(int a, int b) {
		this.a = a;
		this.b = b;
	}

}

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

string s;

bool dfs(Int sum,string ans,Int d){
    if(d>=s.size()) return sum==7;
    if(dfs(sum+s[d]-'0',ans,d+1)){
        ans[d-1]='+'; return true;
    }
    if(dfs(sum-(s[d]-'0'),ans,d+1)){
        ans[d-1]='-'; return true;
    }
    return false;
}

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

    cin>>s; string ans;
    cout<<s[0];
    if(dfs(s[0]-'0',ans,1)){
        for (int i = 0; i < 3; i++){
            cout<<ans[i]<<s[i+1];
        }
    }
    cout<<"=7"<<'\n';
}

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

int INF = 1000;
vector<vector<char>> maze(100, vector<char>(100));
vector<vector<int>> d(100, vector<int>(100));
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int h, w, sx, sy, gx, gy;

int bfs(){
  queue<P> que;
  rep(i, h){
    rep(j, w){
      d[i][j] = INF;
    }
  }    
  que.push(P(sx, sy));
  d[sx][sy] = 0;

  while (que.size()){
    P p = que.front(); que.pop();
    if (p.first == gx && p.second == gy) break;
    rep(i, 4){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' && d[nx][ny] == INF){
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}

int main(){
  cin >> h >> w;
  rep(i, h){
    rep(j, w){
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  rep(s1,h) rep(s2, w){
    if (maze[s1][s2] == '.') {
      sx = s1;
      sy = s2;
      rep(g1, h) rep(g2, w){
        if (maze[g1][g2] == '.'){
          gx = g1;
          gy = g2;
          int now = bfs();
          ans = max(ans, now);
        }
      }
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;

int arr[30][30];
int main(void)
{
    int H, W;
    cin >> H >> W;

    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            cin >> arr[i][j];
        }
    }

    int ans = 1000000;

    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            // 縦からi番目
            // 横からj番目に引く
            int sum = 0;
            for (int k = 0; k < H; ++k)
            {
                for (int l = 0; l < W; ++l)
                {
                    int minV = min(abs(k - i), abs(l - j));
                    sum += minV * arr[k][l];
                }
            }
            ans = min(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3096
// https://atcoder.jp/contests/tenka1-2017-beginner/tasks/tenka1_2017_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    FOR(i, 1, 3501) {
        FOR(j, i, 3501) {
            double t = 4.0 / n - 1.0 / i - 1.0 / j;
            if (t <= FLT_EPSILON)
                continue;
            ll k = round(1.0 / t);
            if ((i * j + j * k + k * i) * n == 4 * i * j * k) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,l,r;
  cin >> a >> b >> c >>d;
  l = a+b;
  r = c+d;
  if(l>r) cout << "Left" << endl;
  if (l<r) cout << "Right" << endl;
  if(l==r) cout << "Balanced" << endl;
}


Measured memory_bytes: 256
// 118_D_Match_Matching.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#include <fstream>

using namespace std;

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


int takeMatches(int i, int n, int baseWeight, vector<int> counts, vector<int> nums, vector<int> &dp)
{
	if (i >= nums.size()) return -1;

	int x = nums[i];
	int c = counts[x] - baseWeight;
	int d = n / c;
	int r = 0;

	if (x >= nums[0])
	{
		for (int j = d; j >= 0; j--)
		{
			dp[x] = j;
			//数字iをj個作った場合のマッチのあまり。
			r = n - c * j;

			//マッチを取りつくせた場合は終了。
			//その時の各数字の個数が答え。
			if (r == 0) return 0;

			//再帰
			r = takeMatches(i + 1, r, counts[nums[0]], counts, nums, dp);
			if (r == 0) return 0;;
		}
	}
	else
	{
		for (int j = 0; j <= d; j++)
		{
			dp[x] = j;
			//数字iをj個作った場合のマッチのあまり。
			r = n - c * j;

			//マッチを取りつくせた場合は終了。
			//その時の各数字の個数が答え。
			if (r == 0) return 0;

			//再帰
			r = takeMatches(i + 1, r, counts[nums[0]], counts, nums, dp);
			if (r == 0) return 0;;
		}
	}
	

	return r;
}


int main()
{
	//std::ifstream in("C:\\Users\\Owner\\Desktop\\D\\in\\0_random_3");
	//std::cin.rdbuf(in.rdbuf());

	vector<int> counts = {6,2,5,5,4,5,6,3,7,6};

	int n, m;
	cin >> n >> m;

	priority_queue<int> pq[10];
	rep(i, m)
	{
		int tmp;
		cin >> tmp;

		pq[counts[tmp]].push(tmp);
	}

	//使うマッチの数が同じで数値が最も大きいもののみ使用
	vector<int> num;
	rep(i, 10)
	{
		if (!pq[i].empty())
		{
			num.push_back(pq[i].top());
		}
	}

	sort(num.begin(), num.end(), greater<int>());
	
	vector<int> dp(10);
	rep(i, 10)
	{
		if (pq[i].empty()) continue; 

		vector<int> num2;
		int x = pq[i].top();
		num2.push_back(x);
		for (int y : num)
		{
			if (y == x) continue;

			num2.push_back(y);
		}

		fill(dp.begin(), dp.end(), 0);
		if (takeMatches(0, n, 0, counts, num2, dp) == 0)
		{
			rep(j, 10)
			{
				if (j == x) continue;
				dp[x] -= dp[j];
			}
			break;
		}
	}


	for (int i = 9; i >= 0; i--)
	{
		for (int j = 0; j < dp[i]; j++)
		{
			cout << i;
		}
	}


	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int a, b, C;
   cin >> a >> b >> C;
   double rad = C * M_PI / 180;
   double s = a * sin(rad) * b / 2;
   double c = sqrt(a * a + b * b - 2 * a * b * cos(rad));
   double l = a + b + c;
   double h = 2 * s / a;
   printf("%0.5f\n", s);
   printf("%0.5f\n", l);
   printf("%0.5f\n", h);

   return 0;
}


Measured memory_bytes: 3560
#include<stdio.h>
#include<string.h>
int main() {
    int x,y;
    scanf("%d%d",&x,&y);
    if(x-2>=y) {
        printf("%d\n",x+x-1);
    }else if(y-2>=x) {
        printf("%d\n",y+y-1);
    }else {
        printf("%d\n",y+x);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define EMPTY -100000

using namespace std;

void Sleep(vector<int>&);
void WakeUp(vector<int>&);

int main(){
  int i, w, q;
  string s;

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

    vector<int> data(w, EMPTY);
    for(i=0; i<q; ++i){
      cin >> s;
      if(s == "s") Sleep(data);
      else if(s == "w") WakeUp(data);
    }
    cout << "END" << endl;
  }

  return 0;
}

void Sleep(vector<int>& data){
  int i, id, w;
  vector<int>::iterator iter1, iter2;

  cin >> id >> w;
  vector<int> _data(w, EMPTY);
  iter1 = search(data.begin(), data.end(), _data.begin(), _data.end());

  if(iter1 == data.end()){
    cout << "impossible" << endl;
  }else{
    vector<int> weight(w, id);
    iter2 = data.erase(iter1, iter1+w);
    data.insert(iter2, weight.begin(), weight.end());

    for(i=0; i<data.size(); ++i){
      if(data[i] == id){
	cout << i << endl;
	break;
      }
    }
  }
}

void WakeUp(vector<int>& data){
  int i, id;
  vector<int>::iterator iter;

  cin >> id;
  iter = find(data.begin(), data.end(), id);

  while(iter != data.end() && *iter == id){
    *iter = EMPTY;
    ++iter;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;
int F[50][50];
int x[8]={1,1,1,0,0,-1,-1,-1};
int y[8]={1,0,-1,1,-1,1,0,-1};
int h,w;

void dfs(int j, int i){
  stack<P> S;
  S.push(P{j,i});
  F[i][j]=0;
  while(!S.empty())
  {
    P p=S.top(); S.pop();
    for(int i=0;i<8;i++)
    {
      int nx=p.first+x[i], ny=p.second+y[i];
      if(nx>=0 && nx<w && ny>=0 && ny<h && F[ny][nx]==1)
      {
        F[ny][nx]=0;
        S.push(P{nx,ny});
      }
    }
  }
}
int island(int w,int h){
  int ans=0;
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      if(F[i][j]==1)
      {
        ans++;
        dfs(j,i);
      }
    }
  }
  return ans;
}

int main(){
    cin>>w>>h;
    while(true){
      if(w==0 && h==0) break;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          cin>>F[i][j];
        }
      }
      cout<<island(w,h)<<"\n";
      cin>>w>>h;
    }

}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main(){
    fast;
	string s1,s2;
	cin>>s1>>s2;
	if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0])
		cout<<"YES";
	else
		cout<<"NO";
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int H,W; cin>>H>>W;
    vector<vector<int>> C(10,vector<int>(10));
    rep(i,0,10)rep(j,0,10) cin>>C.at(i).at(j);
    vector<int> Cnt(10,0);
    rep(h,0,H)rep(w,0,W){
        int n; cin>>n;
        if(n>=0 && n<10 && n!=1) Cnt.at(n)++;
    }

    queue<int> q;
    q.push(1);
    vector<int> Cost(10,INT_MAX);
    Cost.at(1)=0;

    while(!q.empty()){
        int node=q.front();
        q.pop();

        rep(i,0,10){
            int c=C.at(i).at(node),_cost=Cost.at(node)+c;
            if(_cost<Cost.at(i)){
                Cost.at(i)=_cost;
                q.push(i);
            }
        }
    }

    int ans=0;
    rep(i,0,10){
        ans+=Cnt.at(i)*Cost.at(i);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
%:pragma GCC optimize(3)
%:pragma GCC optimize("Ofast")
%:pragma GCC optimize("inline")
%:pragma GCC optimize("-fgcse")
%:pragma GCC optimize("-fgcse-lm")
%:pragma GCC optimize("-fipa-sra")
%:pragma GCC optimize("-ftree-pre")
%:pragma GCC optimize("-ftree-vrp")
%:pragma GCC optimize("-fpeephole2")
%:pragma GCC optimize("-ffast-math")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>

typedef int itn;
using namespace std;
typedef long long ll;
const int maxn = 2e5+7;
const int mod = 1e9+7;

inline ll read() {
	ll c = getchar(), Nig = 1, x = 0;
	while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-'){
        Nig = -1;
        c = getchar();
	}
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
#define read read()
int maxx = -1;
int minn = 0x3f3f3f3f;

struct node{
    string s;
    int val;
    int id;
    friend bool operator < (node a,node b){
        if(a.val != b.val) return a.val < b.val;
        else return a.id > b.id;
    }
};
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(b*c>=a) puts("Yes");
    else puts("No");


    return 0;
}
/**
1
5 2 3
Sorey 3
Rose 3
Maltran  3
Lailah 5
Mikleo  6
1 1
4 2
1 2 3
**/


Measured memory_bytes: 3028
#include<iostream>
#include <algorithm>

using namespace std;
int main(){
    string main, str, sidestr;
    int n, i, j;
    cin >> main >> n;
    for (int p = 0; p < n; p++)  {
        cin >> str;
        if (str == "replace") {
            cin >> i >> j >> sidestr;
            main.replace(i, j + 1 - i, sidestr);
        } else if (str == "reverse") {
            cin >> i >> j;
            string pickles = main.substr(i, j + 1  - i);
            reverse(pickles.begin(), pickles.end());
            main.replace(i, j + 1 - i, pickles);
        } else {
            cin >> i >> j;
            cout << main.substr(i, (j + 1 - i)) << endl;
        }
        }
    }


Measured memory_bytes: 3224
#include<stdio.h>

int func(int);

int main(void){
    int N,ans;

    scanf("%d",&N);
    ans=func(N);
    printf("%d\n",ans);
}


int func(int num){
    if(num == 1){
        return 1;
    }else{
        return  num + func(num - 1);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
string s;
int main(){
    cin >> s;
    if(s[0]==s[1] && s[1]==s[2]){
        printf("Yes");
        return 0;
    }
    if(s[1]==s[2] && s[2]==s[3]){
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 256
/// IN THE NAME OF GUITAR
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<ll, ll> pll;

#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define lc                          id << 1
#define rc                          lc | 1

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}
 
const ll MAXN = 2e5 + 20;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
ll mn[2][MAXN << 2], A[MAXN], pos[MAXN], n;
priority_queue<pair<pll, pll>, vector<pair<pll, pll>>, greater<pair<pll, pll>>> pq;

void build(ll id = 1, ll l = 0, ll r = MAXN) {
	if (r - l == 1) {
		mn[l & 1][id] = A[l];
		mn[(l & 1) ^ 1][id] = INF;
		return;
	}
	ll mid = (l + r) >> 1;
	build(lc, l, mid);
	build(rc, mid, r);
	for (ll i = 0; i < 2; i++) {
		mn[i][id] = min(mn[i][rc], mn[i][lc]);
	}
}

ll get(ll t, ll ql, ll qr, ll id = 1, ll l = 0, ll r = MAXN) {
	if (qr <= l || r <= ql) return INF;
	if (ql <= l && r <= qr) {
		return mn[t][id];
	}
	ll mid = (l + r) >> 1;
	return min(get(t, ql, qr, lc, l, mid), get(t, ql, qr, rc, mid, r));
}

pll get(ll ql, ll qr) {
	ll x = get(ql & 1, ql, qr);
	return {x, get(1 - (ql & 1), pos[x], qr)};
}

void update(ll l, ll r) {
	if (r <= l + 1) return;
	pq.push({get(l, r), {l, r}});
}

int main() {
	scanf("%lld", &n);
	for (ll i = 1; i <= n; i++) {
		scanf("%lld", &A[i]);
		pos[A[i]] = i;
	}
	build();
	pq.push({get(1, n + 1), {1, n + 1}});
	while (sz(pq)) {
		ll l = pq.top().S.F, r = pq.top().S.S; 
		pll x = pq.top().F; pq.pop();
		printf("%lld %lld ", x.F, x.S);
		update(l, pos[x.F]);
		update(pos[x.F] + 1, pos[x.S]);
		update(pos[x.S] + 1, r);
	}
	printf("\n");
    return 0;
}
 

Measured memory_bytes: 16724
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll a;long double b;
  cin>>a>>b;
  ll c=round(b*100);
  c=c*a;
  c=c/100;
  cout<<c<<endl;
  
  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,a[101][101];
  while(cin>>n,n){
    set<int>s1,s2;
    r(i,n)r(j,n)cin>>a[i][j];
    r(i,n){
      int m=1e9;
      r(j,n)m=min(m,a[i][j]);
      s1.insert(m);
    }
    r(i,n){
      int m=0;
      r(j,n)m=max(m,a[j][i]);
      s2.insert(m);
    }
    int F=0;
    set<int>::iterator it1,it2;
    for(it1=s1.begin();it1!=s1.end();it1++){
      for(it2=s2.begin();it2!=s2.end();it2++){
        if(*it1==*it2){
          F++;
          cout<<(*it1)<<endl;
          goto L;
        }
      }
    }L:;
    if(!F)cout<<0<<endl;
  }
}


Measured memory_bytes: 3068
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, K = MAP()
print(N-K+1)

Measured memory_bytes: 5400
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int M,D; cin >>M >>D;
  int res = 0;
  for (int i=1; i<=M; i++){
    for (int j=1; j<=D; j++){
      if (j < 10) continue;
      int d1 = j%10;
      int d10 = j/10;
      if (d1 > 1 && d10 > 1 && d1*d10==i) res++;
    }
  }
  cout <<res <<endl;
}

Measured memory_bytes: 256
N = int(input())
arr = list(map(int, input().split()))
cnt = 0
flg = False
for i in range(N):
    if arr[i] == 0:
        flg = True
    if arr[i] < 0:
        cnt += 1
    arr[i] = abs(arr[i])
if cnt % 2 == 0 or flg:
    print(sum(arr))
else:
    print(sum(arr) - min(arr)*2)

Measured memory_bytes: 85316
# coding: utf-8
# Your code here!

N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

for i in range(X+1,Y+1):
    if max(x)<i and min(y)>=i:
        print('No War')
        #print(i)
        break
    elif i==Y:
        print('War')

        


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll A,B,N;
    cin >> A >> B >> N;
    ll l = min(N,B-1);
    cout << int(floor(A*l/B)-A*floor(l/B)) << "\n";
}

Measured memory_bytes: 3592
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=1e6+7;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	int a;cin>>a;
	if(a==1)a=0;
	else a=1;
	cout<<a; 
	
   return 0;
} 

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



ll n, p, res = 1;

// 素因数分解 O(√N)
map<ll, int> pf(ll n) {
	map<ll, int> res;
	for (ll i = 2; i*i <= n; i++)
		while (n%i==0) ++res[i], n /= i;
	if (n!=1) res[n]++;
	return res;
}

signed main() {
	cin >> n >> p;
	map<ll, int> a = pf(p);
	each(i,a) rep(j,i.second/n) res *= i.first;
	cout << res << endl;
}

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

for i in range(1,10**4):
    if (i*(i-1))//2 < n <= ((i+1)*i)//2:
        maxn = i
        break
ans_list = []
for i in range(maxn,0,-1):
    if n >= i:
        ans_list.append(i)
        n -= i
for i in sorted(ans_list):
	print(i)
    
  
    

Measured memory_bytes: 41584
/**
 *    author:  FromDihPout
 *    created: 2020-06-19
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    long long a = 0, b = 0;
    for (int i = 0; i < n; i++) {
        long long x, y;
        cin >> x >> y;
        long long mult = max({(a + x - 1) / x, (b + y - 1) / y, (long long) 1});
        a = mult * x;
        b = mult * y;
    }
    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>

char m[310][310];

int main() {
    int n;

    std::cin >> n;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            std::cin >> m[i][j];
        }
    }

    int cnt = 0;

    for(int k = 0; k < n; ++k) {

        bool res = true;
        for(int i = 0; i < n && res; ++i) {
            for(int j = 0; j < n && res; ++j) {
                if(m[(i + k) % n][j] != m[(j + k) % n][i]) {
                    res = false;
                }
            }
        }

        if(res) {
            //std::cout << k << ":a: " << n - k << std::endl;

            cnt += n - k;
        }
    }


    for(int k = 1; k < n; ++k) {

        bool res = true;
        for(int i = 0; i < n && res; ++i) {
            for(int j = 0; j < n && res; ++j) {
                if(m[j][(i + k) % n] != m[i][(j + k) % n]) {
                    res = false;
                }
            }
        }

        if(res) {

            //std::cout << k << ": " << n - k << std::endl;
            cnt += n - k;
        }
    }
    
    std::cout << cnt << std::endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin>>s;
  int closest = INT_MAX;
  for(int i=0;i<s.length()-2;i++){
    string aux="";
    aux+=s[i];aux+=s[i+1];aux+=s[i+2];
    int t = stoi(aux);
    if(abs(t-753)<closest){
        closest=abs(t-753);
    }
  }
  cout<<closest<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

char s[1010][1010];
int c[1010][1010];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);

    int h,w;cin>>h>>w;

    int ch,cw;cin>>ch>>cw;
    ch--;cw--;
    int dh,dw;cin>>dh>>dw;
    dh--;dw--;

    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>s[i][j];
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)c[i][j]=-1;

    c[ch][cw]=0;

    deque<pair<int,int>> dq;
    dq.push_front(make_pair(ch,cw));

    while(!dq.empty())
    {
        pair<int,int> f=dq.front();
        dq.pop_front();

        for(int y=-2;y<=2;y++)for(int x=-2;x<=2;x++)
        {
            if(y==0&&x==0)continue;
            int iy=y+f.fi;
            int ix=x+f.se;
            if(iy<0||h<=iy||ix<0||w<=ix)continue;

            if(y*x==0&&abs(y)+abs(x)==1)
            {
                if(s[iy][ix]=='.')
                {
                    if(c[iy][ix]==-1||c[iy][ix]>c[f.fi][f.se])
                    {
                        dq.push_front(make_pair(iy,ix));
                        c[iy][ix]=c[f.fi][f.se];
                    }                    
                }
            }
            else
            {
                if(s[iy][ix]=='.')
                {
                    if(c[iy][ix]==-1)
                    {
                        dq.push_back(make_pair(iy,ix));
                        c[iy][ix]=c[f.fi][f.se]+1;
                    }          
                }
            }
        }
    }

    cout<<c[dh][dw]<<"\n";

    return 0;
}


Measured memory_bytes: 8604
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,X=map(int,input().split())
    m=[int(input()) for i in range(N)]
    m.sort()
    print(N+(X-sum(m))//m[0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38556
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	if(a[0] + a[1] == a[2]) cout << "Yes" << endl;
	else 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 reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1e9;

#define MAX_V 3000

struct edge {
  int to, cap, rev;
  edge(){}
  edge(int to, int cap, int rev):to(to), cap(cap), rev(rev){}
};
vector<edge> graph[MAX_V];
int level[MAX_V], iter[MAX_V];
void add_edge(int from, int to, int cap) {
  graph[from].emplace_back(to, cap, (int)graph[to].size());
  graph[to].emplace_back(from, 0, (int)graph[from].size()-1);
}
void bfs(int s) {
  memset(level, -1, sizeof(level));
  level[s] = 0;
  queue<int> que;
  que.push(s);
  while(que.size()) {
    int v = que.front(); que.pop();
    for(edge& e : graph[v]) {
      if(e.cap > 0 && level[e.to] < 0) {
	level[e.to] = level[v] + 1;
	que.push(e.to);
      }
    }
  }
}
int dfs(int v, int t, int f) {
  if(v == t) return f;
  for(int& i = iter[v]; i < (int)graph[v].size(); i++) {
    edge& e = graph[v][i];
    if(e.cap > 0 && level[v] < level[e.to]) {
      int d = dfs(e.to, t, min(e.cap, f));
      if(d > 0) {
	e.cap -= d;
	graph[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  while(1) {
    bfs(s);
    if(level[t] < 0) return flow;
    memset(iter, 0, sizeof(iter));
    int f; while((f = dfs(s, t, inf)) > 0) flow += f;
  }
}


int N, M;
map<int, int> mp;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N, N) {
    int s = 0, t = 1, V = 2;
    rep(i, MAX_V) graph[i].clear();
    mp.clear();
    cin >> M;
    rep(i, M) {
      int d; cin >> d;
      mp[d] = V++;
    }
    for(auto p : mp) add_edge(s, p.second, 1);
    rep(i, N) {
      cin >> M;
      rep(j, M) {
	int d; cin >> d;
	if(mp.count(d)) add_edge(mp[d], V+i, 1);
      }
      add_edge(V+i, t, 1);
    }
    cout << max_flow(s, t) << endl;
  }

  return 0;
}

Measured memory_bytes: 3268
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Card Game for Two
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int as[MAX_N], sums[2];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", &as[i]);
  sort(as, as + n);

  for (int i = 0; i < n; i++) sums[i & 1] += as[i];

  printf("%d\n", abs(sums[0] - sums[1]));
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public void solve() {
        Scanner scan = new Scanner(System.in);
       int N = scan.nextInt();
       int X = scan.nextInt();
       int T = scan.nextInt();
       int a;
       if(N%X == 0) a=N/X;
       else a=N/X+1;
       System.out.println(a*T);
        }
        public static void main(String[]args){
            new Main().solve();
        }
    }

Measured memory_bytes: 35704
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
long long a,b;
cin>>a>>b;
if(b==100)
b=101;
if(a==0){
cout<<b*1<<endl;
}else if(a==1){
cout<<b*100<<endl;
}else{
cout<<b*10000<<endl;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        cout<<'x';
    }
}

Measured memory_bytes: 256
use proconio::input;


fn main() {
    input! {
        a: usize,
        b: usize,
        m: usize,
        va: [i32; a],
        vb: [i32; b],
        x:  [[i32; 3]; m]
    }

    let mut ans = va.iter().min().unwrap()
                  + vb.iter().min().unwrap();

    for xi in x {
        let ai = xi[0] as usize;
        let bi = xi[1] as usize;
        let c  = xi[2];
        ans = std::cmp::min(ans, va[ai-1] + vb[bi-1] - c);
    }

    println!("{}", ans);
}


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


void solve() {
  map<char, string> mp;
  cin >> mp['A'] >> mp['B'] >> mp['C'];
  char turn = 'A';
  while(1) {
    if(mp[turn].empty()) {
      cout << turn;
      return;
    }
    char temp = mp[turn][0];
    mp[turn].erase(0,1);
    turn = toupper(temp);
  }
}

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long fun(long long wt[],long long v[],long long W,long long n)
{
	if(n<=0 || W<=0)
		return 0;
	if(wt[n-1]<=W)
		return max(v[n-1]+fun(wt,v,W-wt[n-1],n-1),fun(wt,v,W,n-1));
	else
		return fun(wt,v,W,n-1);
}
int main()
{
	long long n,W,i,j;
	scanf("%lld%lld",&n,&W);
	long long w[n+1],v[n+1];
	for(i=0;i<n;i++)
		scanf("%lld%lld",&w[i],&v[i]);
	//long long ans=fun(w,v,W,n);
	//printf("%lld\n",ans);
	long long dp[n+1][W+1];
	memset(dp,-1,sizeof(dp[n+1]));
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=W;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=W;j++)
		{
			if(w[i-1]<=j)
				dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	// for(i=0;i<=n;i++)
	// {
	// 	for(j=0;j<=W;j++)
	// 		prlong longf("%d ",dp[i][j]);
	// 	prlong longf("\n");
	// }
	printf("%lld\n",dp[n][W]);
}


Measured memory_bytes: 79104
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

/*********** Constants ***********/
const auto INF = static_cast<ll>(1e15);
const auto MOD = static_cast<ll>(1e9 + 7);

/*********** Variables ***********/
ll N;
vector<ll> A;
vector<vector<ll>> ANS;

/*********** Functions ***********/
bool init() {
    cin >> N;
    A.resize(N, 0);
    for (auto& a : A) cin >> a;
    return true;
}

void solve() {
    ANS.push_back(A);
    for (ll i = 1; i < N; i++) {
        ll v = A[i];
        ll j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        ANS.push_back(A);
    }
}

void output() {
    for (const auto& item : ANS) {
        for(ll i = 0; i < N; i++) {
            cout << (i ? " " : "") << item[i];
        }
        cout << endl;
    }
}

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


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

using namespace std;
using llint = long long;

int n, k , ans = -1000000000;
deque<int> v;

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

    v.resize(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v.at(i);
    }

    for (int i = 0; i <= min(k, n); ++i)
    {
        for (int j = 0; j <= min(k-i, n-i); ++j)
        {
            priority_queue<int, vector<int>, greater<int> > q;

            int sum = 0;
            for (int l = 0; l < i; ++l)
            {
                int cv = v.at(l);
                q.push(cv);
                sum += cv;
            }

            for (int r = 0; r < j; ++r)
            {
                int cv = v.at(n-r-1);

                q.push(cv);
                sum += cv;
            }

            for (int s = 0; s < k-i-j; ++s)
            {
                if (q.empty() || q.top() >= 0) break;

                sum -= q.top();     
                q.pop();
            }

            ans = max(ans, sum);
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256