akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(m)]

for a, b in AB:
    place = [abs(a - c) + abs(b - d) for c, d in CD]
    print(place.index(min(place)) + 1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
template<class T>bool chmin(T &a, const T &b)
{ return (a>b ? (a=b)||1 : 0); }

int main(){
	int N,W; cin >>N>>W;
	vector<int> w(N),v(N);
	for(int i=0; i<N; i++){
		cin >>w.at(i)>>v.at(i);
	}
	vector<vector<int>> dp(N+1,vector<int>(100001,W+1));
	dp.at(0).at(0) = 0;
	for(int i=0; i<N; i++){
		for(int j=0; j<=100000; j++){
			chmin(dp.at(i+1).at(j), dp.at(i).at(j));
			if(j+v.at(i)<=100000)chmin(dp.at(i+1).at(j+v.at(i)), dp.at(i).at(j)+w.at(i));
			
		}
	}
	int mv{};
	for(int i=0; i<=100000; i++){
		if(dp.at(N).at(i)<=W) mv = max(mv,i); 
	}
	cout << mv << endl;
}

Measured memory_bytes: 40192
n,m=map(int,input().split())
l=[[0,0] for i in range(n)] #[AC,WA]
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=="AC":
        if l[p-1][0]==0:
            l[p-1][0]=1
    else:
        if l[p-1][0]==0:
            l[p-1][1]+=1
ac=0
wa=0
for i in range(len(l)):
    ac+=l[i][0]
    if l[i][0]==1:
        wa+=l[i][1]
print(ac,wa)

Measured memory_bytes: 17780
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {

    ll a,b,k;
    cin >> a >> b >> k;
    for(int i = a;i<=b;i++){
        if(i-a < k || b-i < k)cout << i << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

// a quote from http://www.igaris.com/math/c.pdf

#define MOD (1000000000+7)

long long C[1001][1001];

long long power( long long x, int n )
{
	if( n == 0 ) {
		return 1;
	}
	if( n % 2 ) {
		return x * power( x, n - 1 ) % MOD;
	}
	else {
		return power( x * x % MOD, n / 2 );
	}
}

long long ifac( long long x )
{
	long long f = 1;
	while( x > 1 ) {
		f *= power( x, MOD - 2 );
		f %= MOD;
		x--;
	}
	return f;
}

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

	// Pascal's triangle for combination
	C[0][0] = 1;
	for( int i = 1; i < 1001; i++ ) {
		for( int j = 0; j <= i; j++ ) {
			if( j == 0 || j == i ) {
				C[i][j] = C[i - 1][0];
			}
			else {
				C[i][j] = ( C[i - 1][j - 1] + C[i - 1][j] ) % MOD;
			}
		}
	}

	long long ans = 0;
	if( n >= k ) {
		for( int i = 1; i <= k; i++ ) {
			ans += power( -1, k - i ) * C[k][i] * power( i, n ) % MOD;
			ans %= MOD;
			if( ans < 0 ) {
				ans += MOD;
			}
		}
		ans *= ifac( k );
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 10032
#include<iostream>
#include<vector>

using namespace std;

int main() {

	int N, M;
	cin >> N >> M;

	vector<int> cnt(M, 0);

	for (int i = 0; i < N; i++) {
		int K;
		cin >> K;
		for (int j = 0; j < K; j++) {
			int x;
			cin >> x;
			x--;
			cnt[x]++;
		}
	}
		int check=0;

		for (int k = 0; k < M; k++) {
			if (cnt[k] == N)
				check++;
		}
		cout << check << endl;


	return 0;
}

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

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int l = s.length();
  long long sum = 0;
  for (int i = 0; i < (1<<l); ++i) {
    bitset<10> b(i);
    int c = 0;
    for (int j = 0; j < l; ++j) {
      if (b.test(j)) {
        sum += 1ll * (s[l-j-1] - '0') * pow(10, c);
        ++c;
      } else {
        sum += 1ll * (s[l-j-1] - '0') * pow(10, c);
        c = 0;
      }
    }
  }
  cout << sum/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    string s,t;
    cin>>s>>t;
    ll a=0;
    REP(i,s.size()){
    if(s[i]==t[i]){
        a++;
    }
    }
    cout<<a;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
M = N
pf = []
K = 2

while K*K <= M:
  while N%K == 0:
    pf.append(K)
    N = N//K
  K += 1
  
if N != 1:
  pf.append(N)

ans = 0

for i in set(pf):
  C = pf.count(i)
  for j in range(20):
    if j*(j+1)//2 <= C < (j+1)*(j+2)//2:
      ans += j
  
print(ans)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
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 (a>b) { a=b; return true; } return false; }

const int mod = 1e9+7;

int main(){
    int n;
    string s;
    cin >> n >> s;
    map<char, ll> mp;
    rep(i,n) mp[s[i]]++;
    ll ans = 1;
    for(auto m: mp){
        ans = (ans * (m.second+1)) % mod;
    }
    ans = ((ans - 1) + mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,count=1,sum=0;;
	scanf("%d",&n);
	vector<int>v;
	v.clear();
	for(int i=1;i<=n;i++)
	{  int a;
		scanf("%d",&a);
		v.push_back(a);
	}sum=v.size();
	sort(v.begin(),v.end());
	for(int i=1;i<v.size();i++)
	{
		if(v[i]==v[i-1]) count++;
		else 
		{if(count%2==0) sum-=count;
		else{
		 sum-=count;sum++;}count=1;
		}
	} 
	if(count%2==0) sum-=count;
	else {
		sum-=count;sum++;
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n;
    cin >> n;
    int a[n + 1], b[n + 1], c[n]; 
    fore(i, 0, n){
        cin >> a[i];
        --a[i];
    }
    fore(i, 0, n)cin >> b[i];
    fore(i, 0, n - 1)
        cin >> c[i];
    int ans = 0;
    fore(i, 0, n){
        ans += b[a[i]];
        if(i > 0 && a[i] == a[i - 1] + 1)
            ans += c[a[i - 1]];
    }cout << ans << '\n';
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

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

int main(){
    string s,t;
    cin >> s >> t;
    int len = s.length();
    bool f = false;
    rep(i,len){
        f = true;
        if(s[i] == t[0]){
            rep(j,len){
                if(s[(i+j) % len] != t[j]){
                    f = false;
                    break;
                }
            }
            if(f){
                cout << "Yes" << endl;;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[33]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
int main() {
	int k;
	cin>>k;
	cout<<c[k];

	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_c

import math

n = int(input())
num = [int(input()) for _ in range(n)]
num.sort()


def dif():
    ans = 0
    for i in range(1, n):
        ans += abs(b[i] - b[i - 1])
    return ans


b = [0]*n
# print(num)
if (n % 2 == 0):
    for i in range(n // 2):
        b[i * 2 + 1] = num[i]
        b[i * 2] = num[i + n // 2]
    # print(b)
    print(dif())
    # 大小大小…と並べていけば最適
    # 先頭・末尾以外は、大同士、小同士を入れ替えても差の絶対値に変化がない→中央値より大きい数値を小さい方から、中央値より小さい数値を小さい方から使っていけばいい
    # 偶数の時は中央値は真ん中の左側として、末尾に配置
    # 先頭の値は中央値より大きい値の内一番小さい値
else:
    # 奇数の時は中央値はもちろん真ん中の値
    # 先頭におくか末尾におくかでパターンが分かれる
    for i in range(n // 2):
        b[i * 2 + 1] = num[i]
        b[i*2] = num[i+n//2+1]
    b[n - 1] = num[n // 2]
    temp = dif()
    # print(b)
    for i in range(n // 2):
        b[i * 2 + 2] = num[i]
        b[i*2+1] = num[i+n//2+1]
    b[0] = num[n // 2]
    # print(b)
    print(max(dif(), temp))

Measured memory_bytes: 7908
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 399;
const int MOD = 1000000007;

int n;
int a[MAXN], b[MAXN];
int apos[MAXN], bpos[MAXN];
int cnt[MAXN + 1][MAXN + 1];

int fac[MAXN + 1];
int mem[MAXN + 1][MAXN + 1][MAXN / 3 + 1][3];

int go(int ai, int bi, int nc, int mode) {
	int &ret = mem[ai][bi][nc][mode];
	if (ret == -1) {
		int nhave = (cnt[ai][bi] - nc) / 2, nfree = nhave - nc;
		if (ai < n&&bpos[a[ai]] < bi) return ret = go(ai + 1, bi, nc, mode);
		if (bi < n&&apos[b[bi]] < ai) return ret = go(ai, bi + 1, nc, mode);
		if (nhave >= n / 3) { return ret = fac[n - cnt[ai][bi]]; }
		ret = 0;
		if (mode == 0) ret = (go(ai, bi, nc, 1) + (nfree > 0 ? (ll)nfree*go(ai + 1, bi, nc + 1, 0) : 0)) % MOD;
		if (mode == 1) ret = (go(ai, bi, nc, 2) + (nfree > 0 && a[ai] != b[bi] ? (ll)nfree*go(ai, bi + 1, nc + 1, 1) : 0)) % MOD;
		if (mode == 2) ret = (a[ai] != b[bi] ? (ll)(n - cnt[ai][bi] - nfree - 1)*(n - cnt[ai][bi] - nfree - 2)*go(ai + 1, bi + 1, nc, 0) : 0) % MOD;
		//printf("go(%d,%d,%d,%d)=%d (nfree=%d)\n", ai, bi, nc, mode, ret, nfree);
	}
	return ret;
}

void run() {
	fac[0] = 1; FORE(i, 1, MAXN) fac[i] = (ll)fac[i - 1] * i%MOD;
	scanf("%d", &n);
	REP(i, n) scanf("%d", &a[i]), --a[i]; REP(i, n) apos[a[i]] = i;
	REP(i, n) scanf("%d", &b[i]), --b[i]; REP(i, n) bpos[b[i]] = i;
	REPE(i, n) REPE(j, n) { cnt[i][j] = 0; REP(k, n) if (apos[k] < i || bpos[k] < j) ++cnt[i][j]; }

	memset(mem, -1, sizeof(mem));
	int ans = go(0, 0, 0, 0);
	printf("%d\n", ans);
}

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


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

int v, e;
const int MAX_N = 100100;
// 隣接リスト
vector<int> graph[MAX_N];
bool used[MAX_N];
// トポロジカルソートされた数列
vector<int> ans;

void dfs(int u) {
  if(used[u]) return;
  used[u] = true;
  for(auto& i: graph[u]) dfs(i);
  // 帰りがけ順で追加
  ans.push_back(u);
}

void tsort() {
  for(int i=0; i<v; ++i) dfs(i);
  reverse(ans.begin(), ans.end());
}

int main() {
    int N, M; cin >> N >> M;
    v = N;
    e = N + M - 1;

    vector<int> incount(N, 0);
    for (int i = 0; i < N+M-1; i++) {
        int s, t; cin >> s >> t;
        s--; t--;
        graph[s].push_back(t);
        incount[t]++;
    }

    tsort();
    
    vector<int> oya(N);
    oya[ans[0]] = 0;
    for (int i = 0; i < N; i++) {
        int t = ans[i];
        for (auto x : graph[t]) {
            if (incount[x] == 1) {
                oya[x] = t+1;
            } else {
                incount[x]--;
            }
        }
    }
    
    for (int i = 0; i < N; i++) {
        cout << oya[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10868
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
long long int modulo(long long int a,long long  int b, long long int n){
    long long int  x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n; // multiplying with base
        }
        y = (y*y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;cin >> n >> k;
    ll dp[k+1];ll ans=0;
    for(ll i=k;i>=1;i--)
    {
      ll g=k/i;
      ll dans=modulo(g,n,mod);
      for(ll j=2*i;j<=k;j+=i)_(dans,-dp[j]);
        _(ans,dans*i);
      dp[i]=dans;
    }
    cout << ans;
    }

Measured memory_bytes: 4436
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	
	int g = 0,k = 0;

	rep(i,0,n){
		long a;
		cin >> a;
		if(a % 2 == 0 )
			g++;
		else
			k++;
	}

	if(k%2 != 0 )
		NO;	
	else
		YES;

	ret 0;
}

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

int main()
{
	int a[3];
	for (int i{}; i < 3; i++) scanf("%d", a + i);
	std::sort(a, a + 3);
	printf("%d\n", a[2] * 10 + a[1] + a[0]);

	return 0;
}

Measured memory_bytes: 256
n, w = map(int, input().split())
l = [ list(map(int, input().split())) for _ in range(n) ]
dp = [ [0]*(w+1) for _ in range(n+1) ]
for i in range(1, n+1):
  for j in range(w+1):
    if j < l[i-1][0]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-l[i-1][0]] + l[i-1][1], dp[i-1][j])
print(dp[n][w])

Measured memory_bytes: 120044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
ll gcd(ll a,ll b){
  if(a==b){
    return a;
  }else if(a>b){
    return gcd(a-b,b);
  }else{
    return gcd(a,b-a);
  }
}
int main() {
 ll a,b;
  cin >> a >> b;
  cout << (a*b)/gcd(a,b) << endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    ll a[n];rep(i,n) cin>>a[i];
    vector<vector<int>> g(n);
    rep(i,n-1){
        int u,v;cin>>u>>v;u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    // 2は正だけ
    vector<vector<ll>> dp1(n+10,vector<ll>(n+10,LINF)),dp2(n+10,vector<ll>(n+10,LINF));
    int sz[n];

    function<void(int,int)> dfs=[&](int pre,int now){
        sz[now]=1;
        for(auto to:g[now])if(pre!=to){
            dfs(now,to);
            sz[now]+=sz[to];
        }
        
        ll sub1[sz[now]],sub2[sz[now]];
        rep(i,sz[now])sub1[i]=LINF,sub2[i]=LINF;
        sub1[0]=a[now];
        if(a[now]>0) sub2[0]=a[now];

        int cnt=0;
        for(auto to:g[now])if(to!=pre){
            ll memo1[cnt+1],memo2[cnt+1];
            rep(i,cnt+1)memo1[i]=sub1[i],memo2[i]=sub2[i];
            rep(i,cnt+1)sub1[i]=LINF,sub2[i]=LINF;
            rep(i,cnt+1){
                rep(j,sz[to]){
                    chmin(sub1[i+j],memo1[i]+dp1[to][j]);// 切らない
                    // dp[to][j]->すでにj本切ってる．
                    // sub1[i]->すでにi本切ってる
                    // さらにもう1本切る．

                    // 存在してないなら切れない
                    if(dp1[to][j]<0 or dp2[to][j]<LINF) chmin(sub1[i+j+1],memo1[i]);
                    if(a[now]>0){
                        chmin(sub2[i+j],memo2[i]+dp2[to][j]);
                        if(dp1[to][j]<0 or dp2[to][j]<LINF) chmin(sub2[i+j+1],memo2[i]);
                    }
                }
            }
            cnt+=sz[to];
        }
        rep(i,sz[now]){
            dp1[now][i]=sub1[i];
            dp2[now][i]=sub2[i];
        }
    };

    dfs(-1,0);

    // rep(i,n){
    //     cout<<i<<" : ";
    //     rep(j,n){
    //         cout<<"(";
    //         if(dp1[i][j]>=LINF) cout<<"X,";
    //         else cout<<dp1[i][j]<<",";

    //         if(dp2[i][j]>=LINF) cout<<"X)";
    //         else cout<<dp2[i][j]<<")";
    //     }
    //     cout<<endl;
    // }

    int ans=INF;
    rep(i,n+1){
        if(dp1[0][i]<0) chmin(ans,i);
        if(dp2[0][i]<LINF) chmin(ans,i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 393984
n = int(input())
a_list = list(map(int, input().split()))
a_list = [a_list[i] - i + 1 for i in range(len(a_list))]
a_list.sort()
sum = 0
for i in range(n//2):
    sum += a_list[n-1-i] - a_list[i]
print(sum)

Measured memory_bytes: 25196
from collections import defaultdict
import bisect

N = int(input())
S = input()
# s2i = [[] for i in range(10)]
s2i = defaultdict(list)

for i, si in enumerate(S):
    s2i[si] += [i]

ans = 0

for i in range(1000):
    pin = str(i).zfill(3)
    ii = -1
    flag = True
    for p in pin:
        s2ip = s2i[p]
        if s2ip:
            iii = bisect.bisect_right(s2ip, ii)
            if iii == len(s2ip):
                flag = False
                break
            ii = s2ip[iii]
        else:
            flag = False
            break
    if flag:
        ans += 1

print(ans)


Measured memory_bytes: 74740
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>
#include <functional>

typedef long long ll;
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i += 2){
        if(a[i - 1] % 2 != 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
    
    int H=1;
    int Y=1;
    int i,j;
    
    
    
    if(H>=300 && Y>=300){
        return 0;
    }
    
    while(H != 0 && Y != 0){
        scanf("%d %d",&H,&Y);
    for(i=0;i<H;i++){
        
        if(i==0 || i==H-1){
            
            for(j=0;j<Y;j++){
                printf("#");
            }
            
            printf("\n");
            
        }else{

            for(j=0;j<Y;j++){
            
                
            
                if(j==0){
                
                    printf("#");
            
                }else if(j==Y-1){
                
                    printf("#\n");
            
                }else{
                
                    printf(".");
            
                }
            }
        }
    }
        if(H != 0 && Y != 0)
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 588
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
i=0
N=int(input())
#N, L=input().split()
#S=input()
#T=input()
#S_list=list(S)
#T_list=  list(map(int, input().split(" ")))
#M=int(input())
#drink_list = [list(map(int, input().split(" ")))for i in range(M)]
#print(T_list[1])
#N=int(N)
#C=int(C)
#K=int(K)
T_dummy_list=[]
sentence_list=[]
total=0
mojiretu=""
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(H)
#この下の行が二次元リストの読み込
#intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
#sentence_list =  [list(input())for i in range(N)]#一文字づつばらして入れてしまう
#s = [input() for i in range(N)]
#複数行に複数の入力値を取得し、出力する
#sentence_list =  (list(input())for i in range(N))
#for i in range(H):
#  ppixel_list=list(input())
#  
#print(pixel_list)
i=0
j=0
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)
#print(pixel_list[0][1])#行　列の順番にかっこが並んでいる

#整数二次元配列を読み込む時のやり方
#gate_list =  [list(map(int, input().split(" ")))for i in range(M)]
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#print(s)
#sentence_list=sorted(s)
#print(sentence_list)
#スペースでいれつつ値を取得
can_see=0
hight_list =  list(map(int, input().split(" ")))
for i in range(len(hight_list)):
     
     for j in range(i+1):
      if hight_list[i] >= hight_list[j]:
         pass
         if j==i:
          can_see +=1
      else:
          break

print(can_see)          


Measured memory_bytes: 3060
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var map = new int[8, 8];
            var first = 0;  var fx = 0;  var fy = 0;
            for (int i = 0; i < 8; i++)
            {
               var line = Console.ReadLine().Trim();
                for (int j = 0; j < 8; j++)
                    if (line[j] == '1')
                    {
                        if (first == 0) { fx = i; fy = j; first = 1; map[i, j] = 2; }
                        else map[i, j] = 1;
                    }
            }
            Console.WriteLine(getAnser(map, fx, fy));
            if (Console.ReadLine() == null) break;
        }
    }
    public static string getAnser (int[,] map ,int x , int y)
    {
        var w = getYoko(map, x, y);
        var h = getTate(map, x, y);
        if (w == 1 && h == 4) return "B";
        if (w == 4 && h == 1) return "C";
        if (w == 2 && h == 1) return "E";
        if (w == 2 && h == 2)
            if (map[x + 1, y + 1] == 1) return "A";
            else return "G";
        if (y - 1 >= 0 && map[x + 1, y - 1] == 1) return "D";
        else return "F";
    }
    public static int getYoko (int[,] map , int x ,int y)
    {
        var count = 1;
        for (int i = 1; i < 4; i++)
        {
            if (y + i < 8 && map[x, y + i] == 1) count++;
            else break;
        }
        return count;
    }
    public static int getTate(int[,] map, int x, int y)
    {
        var count = 1;
        for (int i = 1; i < 4; i++)
        {
            if (x + i < 8 && map[x +i, y ] == 1) count++;
            else break;
        }
        return count;
    }
}

Measured memory_bytes: 8764
N = int(input())

V = []
for i in input().split():
    V.append(int(i))

C = []
for j in input().split():
    C.append(int(j))

total = 0
for k in range(N):
    p = V[k] - C[k]
    if p > 0:
        total =total + p

print(total)

Measured memory_bytes: 3060
N=int(input())
A=map(int,input().split())
a_min=10**9
ans=0
neg=0
for a in A:
    aa=abs(a)
    ans+=aa
    if a<0:
        neg+=1
    if a_min>aa:
        a_min=aa
if neg%2==1:
    ans-=a_min*2
print(ans)


Measured memory_bytes: 11212
N = int(input())
a = list(map(int, input().split()))

import heapq
que1 = []
heapq.heapify(que1)
S = [0] * (2*N + 1)
for i in range(N):
    S[i + 1] = S[i] + a[i]
    #que1.append(a[i])
    heapq.heappush(que1, a[i])
que2 = []
heapq.heapify(que2)
T = [0] * (2*N + 1)
for i in range(N):
    T[i + 1] = T[i] + a[3*N - i - 1]
    #que2.append(-a[3*N - i - 1])
    heapq.heappush(que2, -a[3*N - i - 1])

for i in range(N, 2*N):
    mi = heapq.heappop(que1)
    #print(mi)
    if a[i] > mi:
        S[i + 1] = S[i] - mi + a[i]
        #heapq.heappop(que1)
        heapq.heappush(que1, a[i])
    else:
        S[i + 1] = S[i]
        heapq.heappush(que1, mi)
for i in range(N, 2*N):
    ma = heapq.heappop(que2) * -1
    #print(ma)
    if a[3*N - i - 1] < ma:
        T[i + 1] = T[i] - ma + a[3*N - i - 1]
        #heapq.heappop(que2)
        #que2.append(-a[3*N - i - 1])
        heapq.heappush(que2, -a[3*N - i - 1])
    else:
        T[i + 1] = T[i]
        heapq.heappush(que2, -ma)

res = -float('Inf')
for i in range(N, 2*N + 1):
    res = max(res, S[i] - T[3*N - i])
print(res)


Measured memory_bytes: 37084
n = int(input())
xyd = [input().split() for _ in range(n)]


x_max_RL_ = [-2e8] * 3
x_min_RL_ = [2e8] * 3
y_max_UD_ = [-2e8] * 3
y_min_UD_ = [2e8] * 3

for x, y, d in xyd:
    x = int(x)
    y = int(y)

    if d == "R":
        ho, ve = 2, 1
    elif d == "L":
        ho, ve = 0, 1
    elif d == "U":
        ho, ve = 1, 2
    else:  # d == "D"
        ho, ve = 1, 0
    x_max_RL_[ho] = max(x_max_RL_[ho], x)
    x_min_RL_[ho] = min(x_min_RL_[ho], x)
    y_max_UD_[ve] = max(y_max_UD_[ve], y)
    y_min_UD_[ve] = min(y_min_UD_[ve], y)

kouho_time = set([0])

for _max_min in [x_max_RL_, x_min_RL_, y_max_UD_, y_min_UD_]:
    for i in range(0, 3):
        if abs(_max_min[i]) <= 1e8:
            for j in range(i + 1, 3):
                if abs(_max_min[j]) <= 1e8:
                    cross = (_max_min[i] - _max_min[j]) / (j - i)
                    if cross > 0:
                        kouho_time.add(cross)


ans = 4e16
for t in kouho_time:
    x_max = max(
        x_max_RL_[i] + t * (i - 1) for i in range(3) if abs(x_max_RL_[i]) <= 1e8
    )
    x_min = min(
        x_min_RL_[i] + t * (i - 1) for i in range(3) if abs(x_min_RL_[i]) <= 1e8
    )
    y_max = max(
        y_max_UD_[i] + t * (i - 1) for i in range(3) if abs(y_max_UD_[i]) <= 1e8
    )
    y_min = min(
        y_min_UD_[i] + t * (i - 1) for i in range(3) if abs(y_min_UD_[i]) <= 1e8
    )

    ans = min(ans, (x_max - x_min) * (y_max - y_min))

print(ans)


Measured memory_bytes: 34088
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  p=a-b;
  q=(-1)*p;
  if(k%2==1)print(q)
  else print(p)
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

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

	vector<ll> a(n);
	vector<ll> tmp(n);
	rep(i,0,n){
		cin >> a[i];
		tmp[i] = a[i] - i - 1;
	}
	
	vsort(tmp);

	ll ans = numeric_limits<ll>::max();
	rep(buf,-1,2){
		int num = tmp[min(n-1,max(n/2+buf,0))];
		rep(b,num-50,num+50){
			ll sum = 0;
			rep(i,0,n) sum += abs(a[i] - (b + i + 1 ) );
			ans = min(sum , ans );
		}
	}
	
	cout << ans << endl;
	ret 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		2505

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

//
int main(){
	ll N,M;cin>>N>>M;

	ll ans = 0;

	ans += min(N,M/2);
	M -= ans*2;
	if(M>0)ans+= M/4;

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256
from collections import deque

N, Q = list(map(int, input().split()))
edges = {n:[] for n in range(N+1)}
nodes = [0 for _ in range(N+1)]
cr = deque()

# 経路
for n in range(N-1):
    a, b = list(map(int, input().split()))
    edges[a].append(b)
    edges[b].append(a)

# 各ノードの点数
for q in range(Q):
    p, x = list(map(int, input().split()))
    nodes[p] += x

# 各ノードを通ったことを覚えておく
flags = [False]*(N+1)

# ルートから探索
cr.append(1)
flags[1] = True

# ルートから葉っぱまで点数を行き渡らせる
while cr:
    c = cr.popleft()
    flags[c] = True

    # 続く幹がないならば飛ばす
    if not edges[c]:
        continue

    # 幹に点数を与え、幹を伸ばす
    pts = nodes[c]
    for trunk in edges[c]:
        if not flags[trunk]:
            flags[trunk] = True
            nodes[trunk] += pts
            cr.append(trunk)

print(*nodes[1:])

Measured memory_bytes: 83556
#include <stdio.h>
int main(void){
   int nowTime;
   int later;
   int startTime;
   scanf("%d", &nowTime);
   scanf("%d", &later);
   if(nowTime >= 24)
      nowTime = nowTime - 24;
   if(later >= 24)
      later = later - 24;
   startTime = nowTime + later;
   if (startTime >= 24)
      startTime = startTime - 24;
   printf("%d" , startTime);
   return 0;
}


Measured memory_bytes: 128
object Main extends App {

  import scala.io.StdIn.readLine
  val arr = readLine().trim.split("")
  val stack = new scala.collection.mutable.Stack[String]
  arr.foreach { e =>
    if (e == "B") {
      if (stack.isEmpty) {
        ()
      } else {
        stack.pop
      }
    } else {
      stack.push(e)
    }
  }
  println(stack.toList.reverse.mkString)

}


Measured memory_bytes: 21452
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			int ans = 0;
			for (int i = 1; i <= n; i++) {
				if (i % 2 == 0) {
					continue;
				}

				int cnt = 0;
				for (int j = 1; j <= i; j++) {
					if (i % j == 0) {
						++cnt;
					}
				}

				if (cnt == 8) {
					++ans;
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13140
import math

n, m=map(int, input().split())
if n-m>=2 or m-n>=2:
    print(0)
elif n!=m:
    print(math.factorial(m)*math.factorial(n)%(10**9+7))
else:
    print(2*math.factorial(m)*math.factorial(n)%(10**9+7))

Measured memory_bytes: 5176
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

typedef pair<ll, ll> P;

int main() {
  ll n, m; cin >> n >> m;
  map<int, int> M;
  loop(i,0,m) {
    int a, b;
    cin >> a >> b;
    M[a]++;M[b]++;
  }
  loop(i,1,n+1) {
    cout << M[i] << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    for (unsigned long i = 0; i < s.size(); ++i) {
        if (s.substr(i, t.size()) == t)
            cout << i << endl;
    }
    return 0;
}



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

bool isPrime(int x){
	if(x<2)return false;
	else if(x==2)return true;
	else if(x%2==0)return false;
	for(int i=3;i*i<=x;i+=2){
		if(x%i==0)return 0;
	}
	return true;
}


int main(){
    int x,i;
    cin>>x;
    for(i=x;;i++){
        if(isPrime(i))break;
    }
    cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;

class P
{
    static void Main()
    {
        //ステート維持
        var xy = Console.ReadLine().Split().Select(long.Parse).ToList();
        Console.WriteLine(Abs(xy[0] - xy[1]) <= 1 ? "Brown" : "Alice");
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  cin >> S;
  int N = S.length();
  int result = 1;
  for(int a = 0;a < (N - 1)/2;a++){
   if(S[a] == S[N - 1 - a]){
   }else{
     result = 0;
   }
  }
  
  for(int a = 0;a <= ((N - 1)/2 - 1)/2;a++){
   if(S[a] == S[(N - 1)/2 - 1 - a]){
   }else{
     result = 0;
   }
  }
  if(result == 1){
    cout << "Yes" << endl;
  }else{
  cout << "No" << endl;
  }
 
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;
int K, S;

int main(){
    cin >> K >> S;
    int count;
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
           if(K>=S-x-y && S-x-y>=0) count++;
        }
    }

   cout << count << endl;
}

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

using namespace std;
using ll = long long;

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

    int n, p;
    string s;

    cin >> n >> p >> s;

    ll ans = 0;

    if(p == 2 || p == 5) {
        for(int i = 0; i < n; ++i) {
            if(static_cast<int>(s.at(n - 1 - i) - '0') % p == 0) ans += n - i;
        }
    } else {
        vector<int> mods(n + 1), mods10(n + 1);
        mods10.at(0) = 1;
        for(int i = 0; i < n; ++i) {
            mods.at(i + 1) = (mods.at(i) + static_cast<int>(s.at(n - 1 - i) - '0') * mods10.at(i)) % p;
            mods10.at(i + 1) = mods10.at(i) * 10 % p;
        }

        ll count;

        for(int i = 0; i < p; ++i) {
            count = 0;
            for(int j: mods) {
                if(j == i) ++count;
            }
            ans += count * (count - 1) / 2;
        }
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 2196
n = int(raw_input())
c = 0
flag = False
for _ in range(n):
	a,b = map(int, raw_input().split())
	if a == b:
		c+=1
	else:
		c = 0
	if c == 3:
		flag = True
		break
print 'Yes' if flag else 'No'

Measured memory_bytes: 64688
c = [[0] * 3 for _ in range(3)]
for i in range(3):
    c[i][0],c[i][1],c[i][2] = map(int,input().split())

b1=c[0][0]
b2=c[0][1]
b3=c[0][2]
a1=0
a2=c[1][0]-c[0][0]
a3=c[2][0]-c[0][0]
print('Yes') if a1+b1==c[0][0] and a1+b2==c[0][1] and a1+b3==c[0][2] and a2+b1==c[1][0] and a2+b2==c[1][1] and a2+b3==c[1][2] and a3+b1==c[2][0] and a3+b2==c[2][1] and a3+b3==c[2][2] else print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
# define M_PI 3.14159265358979323846
int main(){

    double  H,M;
    double A,B;
    cin>>A>>B>>H>>M;
    double angle = H*30-M*5.5;
    if(angle>180)
        angle= 360-angle;
    double  length;
    length=pow(A,2)+pow(B,2)-2*A*B*cos(angle*M_PI/180.0);
    length= sqrt(length);
    cout<< fixed<<setprecision(16)<< length;

}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int h,w,k;
  cin>>h>>w>>k;
  string s[h];
  int cake[h][w];
  REP(i,h){
    REP(j,w){
      cake[i][j] = -1;
    }
  }


  int count = 1;
  REP(i,h){
    cin>>s[i];
    REP(j,w){
      if(s[i][j]=='#'){
        cake[i][j] = count;
        count++;
      }
    }
  }

  REP(i,h){
    REP(j,w){
      if(cake[i][j] != -1){
        int p,q;
        int now = cake[i][j];
        p = i;
        q = j-1;
        while(q>=0&&cake[p][q] == -1){
          cake[p][q] = now;
          q--;
        }
        q = j+1;
        while(q<w&&cake[p][q] == -1){
          cake[p][q] = now;
          q++;
        }
      }
    }
  }

  REP(i,h){
    REP(j,w){
      if(cake[i][j] != -1){
        int p,q;
        int now = cake[i][j];
        p = i-1;
        q = j;
        while(p>=0&&cake[p][q] == -1){
          cake[p][q] = now;
          p--;
        }
        p = i+1;
        while(p<h&&cake[p][q] == -1){
          cake[p][q] = now;
          p++;
        }
      }
    }
  }

  REP(i,h){
    REP(j,w){
      cout<<cake[i][j]<<" ";
    }
    cout<<endl;
  }
 

  return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
 	s = 0; int f = 0; char c = getchar();
 	while (!isdigit(c)) f |= (c == '-'), c = getchar();
 	while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
 	s = f ? -s : s;
}

typedef long long LL;
const int _ = 100010;
const LL p = 1e9 + 7;

int n; LL dp[_], sum[_], A, B, a[_];

int main() {
	read(n), read(A), read(B); if (A < B) swap(A, B);
	for (rg int i = 1; i <= n; ++i) read(a[i]);
	for (rg int i = 1; i + 2 <= n; ++i)
		if (a[i + 2] - a[i] < B) return puts("0"), 0;
	dp[0] = sum[0] = 1;
	for (rg int l = 0, r = 0, i = 1; i <= n; ++i) {
		while (r < i && a[i] - a[r + 1] >= A) ++r;
		if (l <= r) dp[i] = (sum[r] - (l > 0 ? sum[l - 1] : 0ll) + p) % p;
		sum[i] = (sum[i - 1] + dp[i]) % p;
		if (i > 1 && a[i] - a[i - 1] < B) l = i - 1;
	}
	LL ans = 0;
	for (rg int i = n; ~i; --i) {
		ans = (ans + dp[i]) % p;
		if (i < n && a[i + 1] - a[i] < B) break;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2560
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n,l=get_i
s=array(n,1)
n.times do|i|
  s[i]=get
end
s.sort!
puts s.join("")

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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

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

void solve()
{
  int n; cin>>n;
  int ans=n;
  for (int i=0; i<=n; i++) {
    int cc = 0;
    int t = i;
    while (t>0) {
      cc += t%6;
      t /= 6;
    }
    t=n-i;
    while (t>0) {
      cc += t%9;
      t /= 9;
    }
    ans = min(ans, cc);
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>

char c[10010], c2[10010];
char c3[10010];

void merge(int l, int r)
{
	int ind, ind2, ind3;
	
	if (r - 1 == l){  
		return;       
	}				  
	
	merge((l + r) / 2, r);
	merge(l, (l + r) / 2);
	
	
	ind2 = 0;
	for (ind = l; ind < (l + r) / 2; ind++){ 
		c2[ind2] = c[ind];					 
		ind2++;
	}
	ind2 = 0;
	for (ind = (l + r) / 2; ind < r; ind++){ 
		c3[ind2] = c[ind];                   
		ind2++;
	}
	
	ind2 = 0;
	ind3 = 0;
	
	for (ind = l; ind < r; ind++){
		
		if (ind3 == r - (r + l) / 2 || (c2[ind2] < c3[ind3] && ind2 != (l + r) / 2 - l)){
			c[ind] = c2[ind2];
			ind2++;
		}
		else{
			c[ind] = c3[ind3];
			ind3++;
		}
	}
}

int main(void)
{
	int i, n;
	double s, s2;
	
	while (1){
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		s = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &c[i]);
		}
		
		merge(0, n);
		
		for (i = 0; i < n-1; i++){
			s += c[i];
		}
		s2 = s;
		for (i = n - 2; 0 < i; i--){
			s += s2 - c[i];
			s2 -= c[i];
		}
		printf("%.0f\n", s);
	}
	return (0);
}
	

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

int main(){
	std::string s,t;
	std::cin>>s>>t;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			std::cout <<"No"<< std::endl;
			exit(0);
		}
	}

	std::cout << "Yes" << std::endl;
	return 0;
}

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

ans = 'Yes'
if len(H) == 1:
  print(ans)
  exit(0)

for i in range(1, len(H)):
  if H[i-1] < H[i]:
    H[i] -= 1
  if H[i-1] > H[i]:
    ans = 'No'
    break

print(ans)

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

        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double C = sc.nextDouble();

        double theta = Math.PI*C/180;
        double S = 0.5 * a * b * Math.sin(theta);
        double L = a + b + Math.sqrt(a*a + b*b - 2*a*b*Math.cos(theta));
        double h = 2 * S / a;
        System.out.println(S);
        System.out.println(L);
        System.out.println(h);
    }
}


Measured memory_bytes: 27936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll m,d;
  cin >> m >> d;
  ll ans=0;
  for(ll i=1;i<=m;i++) {
    for(ll j=1;j<=d;j++) {
      ll d1=j/10;
      ll d2=j%10;
      if(d1<=1||d2<=1) continue;
      if(d1*d2==i) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int G[100][100], d[100], f[100], C[100];
int t = 1;

void Depth(int);

int main(){
  
  int i, j, n, u;

    scanf("%d", &n);

   
    for (i = 1; i <= n; i++){
        d[i] = f[i] = 0;
        for (j = 1; j <= n; j++){
            G[i][j] = 0;
        }
    }

   
    for (i = 1; i <= n; i++){
        scanf("%d", &u);
        scanf("%d", &C[u]);
	
        for (j = 1; j <= C[u]; j++){
            scanf("%d", &G[u][j]);
        }
    }

    for (i = 1; i <= n; i++){
      
        if (d[i] == 0) Depth(i);
        
    }

    for (i = 1; i <= n; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}


void Depth(int u){
    int i;

    d[u] = t++;
    
    for (i = 1; i <= C[u]; i++){
      
        if (d[G[u][i]] == 0) Depth(G[u][i]);
    }
    
    f[u] = t++;
}



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

using namespace std;

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

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

    int tot = accumulate(a.begin(), a.end(), 0);
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (abs(a[i] * n - tot) < abs(a[ans] * n - tot))
            ans = i;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256