akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def max_heapify(a, i):
    heap_size = a[0]

    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest)


def main():
    heap = [-1] * 2000001
    heap[0] = 1
    for cmd in stdin:
        if cmd[0] == 'i':
            heap[0] += 1
            i = heap[0]
            heap[i] = int(cmd[7:])

            half = i // 2
            while i > 1 and heap[half] < heap[i]:
                heap[i], heap[half] = heap[half], heap[i]
                i //= 2
                half = i // 2
        elif cmd[1] == 'x':
            print(heap[1])
            heap[1] = heap[heap[0]]
            heap[0] -= 1
            max_heapify(heap, 1)
        elif cmd[1] == 'n':
            exit(0)


main()

Measured memory_bytes: 43372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5005,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,A,B,dp[N][2],f[N],s[N],g[N],gg[N];
void check(int &x,int y){if ((x+=y)>=p) x-=p;}
int main(){
	n=read();A=read();B=read();
	if (A>B) swap(A,B);
	
	f[0]=1;
	for (int i=1;i<B;i++){
		memcpy(s,f,sizeof(s));
		for (int j=0;i+j<B;j++){
			check(g[i+j],f[j]);
			check(s[j+1],s[j]);
			if (j>=A) check(f[j],s[j-A]);
		}
	}
	memcpy(s,g,sizeof(s));
	for (int i=1;i<B;i++){
		gg[i]=g[i];
		check(s[i],s[i-1]);
		if (i>=A) check(gg[i],s[i-A]);
	}
	for (int i=1;i<A;i++) dp[i][0]=1;
	for (int i=1;i<B;i++) dp[i][1]=gg[i];
	for (int i=1;i<=n;i++){
		for (int j=1;(j<A)&&(i+j<=n);j++) check(dp[i+j][0],dp[i][1]);
		for (int j=1;(j<B)&&(i+j<=n);j++) check(dp[i+j][1],(ll)dp[i][0]*((i+j==n) ? gg[j] : g[j])%p);
	}
	int ans=qpow(2,n);
	check(ans,p-dp[n][0]);
	check(ans,p-dp[n][1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3860
#include<stdio.h>
int main(){
  int x,y,r,number;

  scanf("%d%d",&x,&y);

  if(x<y){
    number = x;
    x = y;
    y = number;
  }

  r = x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }

  printf("%d\n",y);

  return 0;
}
  



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	double k=1,c=1;
	double town[n][2]={};
	for(int i=0; i<n; i++){
		cin>>town[i][0]>>town[i][1];
	}
	for(int i=1; i<=n; i++){
		c*=i;
	}
	for(int i=1; i<n; i++){
		k*=i;
	}
	k*=2;
	double ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			ans+=(sqrt( ((town[i][0]-town[j][0]) *(town[i][0]-town[j][0]))+((town[i][1]-town[j][1]) *(town[i][1]-town[j][1])) ) );
			//cout<<ans<<endl;
		}
	}
	
	//cout<<k<<" "<<c<<endl;
	cout<<fixed<<setprecision(15)<<(ans*k)/c<<endl;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
 
using namespace std;
 
struct UnionFind
{
  vector< int > data;
 
  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }
 
  bool operator()(int a, int b)
  {
    a = (*this)[a], b = (*this)[b];
    if(a == b) return (false);
    if(data[a] > data[b]) swap(a, b);
    data[a] += data[b];
    data[b] = a;
    return (true);
  }
 
  int operator[](int a)
  {
    if(data[a] < 0) return (a);
    return (data[a] = (*this)[data[a]]);
  }
 
};
 
int H, W;
string P[102];
 
bool used[102 * 102];
vector< vector< int > > g;
 
string hashed(int idx)
{
  vector< string > ff;
  for(int to : g[idx]) ff.push_back(hashed(to));
  sort(begin(ff), end(ff));
  return (">" + accumulate(begin(ff), end(ff), string()) + "<");
}
 
string get()
{
  cin >> H >> W;
  if(H == 0) exit(0);
 
  P[0] = P[H + 1] = string(W + 2, '.');
  for(int i = 1; i <= H; i++) {
    cin >> P[i];
    P[i] = "." + P[i] + ".";
  }
  H += 2, W += 2;
 
  auto ei1333 = [&](int y, int x)
  {
    return (x * H + y);
  };
 
  UnionFind tree(H * W);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(i > 0 && P[i - 1][j] == P[i][j]) tree(ei1333(i - 1, j), ei1333(i, j));
      if(j > 0 && P[i][j - 1] == P[i][j]) tree(ei1333(i, j - 1), ei1333(i, j));
      if(P[i][j] == '#') {
        if(P[i - 1][j - 1] == '#') tree(ei1333(i - 1, j - 1), ei1333(i, j));
        if(P[i - 1][j + 1] == '#') tree(ei1333(i - 1, j + 1), ei1333(i, j));
      }
    }
  }
 
  memset(used, false, sizeof(used));
  used[tree[ei1333(0, 0)]] = true;
  g.clear();
  g.resize(W * H);
  for(int i = 0; i < H; i++) {
    for(int j = 1; j < W; j++) {
      int p = tree[ei1333(i, j - 1)], q = tree[ei1333(i, j)];
      if(used[q]) swap(p, q);
      if(p == q || used[q]) continue;
      g[p].push_back(q);
      used[q] = true;
    }
  }
  return (hashed(ei1333(0, 0)));
}
 
int main()
{
  while(true) {
    if(get() == get()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

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

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

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

  int cnt = 0;
  REP(i, s.size()) {
    if (cnt == 0 && s[i] == 'C') {
      cnt++;
      continue;
    }
    if (cnt == 1 && s[i] == 'F') {
      cnt++;
      break;
    }
  }

  cout << ((cnt == 2) ? "Yes" : "No") << endl;


  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int a,b,c,sum=0;
	scanf("%d %d %d",&a,&b,&c);
	if(sum<a*10+b+c)
		sum=a*10+b+c;
	if(sum<a+b*10+c)
		sum=a+b*10+c;
	if(sum<a+b+c*10)
		sum=a+b+c*10;
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;
const int _max = 110;

char s[_max], t[_max];

bool cmp(const char&a, const char &b)
{
    return a > b;
}

int main()
{
    scanf("%s%s", s, t);
    int slen = strlen(s), tlen = strlen(t);
    sort(s, s + strlen(s)), sort(t, t + strlen(t), cmp);
    bool ok = 0;
    if(slen < tlen)
        for(int i = 0, j = 0; t[j]; i++, j++)
        {
            if(s[i] == t[j]) continue;
            if(s[i] < t[j]) ok = 1;
            break;

        }
    else if(strcmp(s, t) < 0) ok = 1;
    printf("%s\n",  ok ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int M;
	cin >> M;
	ll nagasa = 0;
	ll ketawa = 0;
	rep(i, M) {
		ll d, c;
		cin >> d >> c;
		ketawa += d * c;
		nagasa += c;
	}

	ll kotae = nagasa - 1;
	kotae += (ketawa - 1) / 9;

	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<numeric>
#include<list>
#include<cmath>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0])
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;



int main(void) {
	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  cout << (a.size() == n ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1024
#include <iostream>                                             
using namespace std;                                            
typedef long long ll;                                           
                                                                
int GCD(ll a,ll b) {                                            
  if (b==0) {                                                   
    return a;                                                   
  }                                                             
  return GCD(b,a%b);                                            
}                                                               
                                                                
int LCM(ll a,ll b) {                                            
  return a*b/GCD(a,b);                                          
}                                                               
                                                                
int main() {                                                    
  ll a, b;                                                      
  while (cin >> a >> b) {                                       
    cout << GCD(a,b) << " " << LCM(a,b) << endl;                
  }                                                             
  return 0;                                                     
}                                                               
                      

Measured memory_bytes: 3060
n = int(input())
sn = sorted([''.join(sorted(input())) for _ in range(n)])

ans = 0
cnt = 1
for i in range(n-1):
    # print(sn[i], cnt, ans)
    if sn[i] == sn[i+1]:
        cnt += 1
    else:
        ans += cnt * (cnt -1) //2
        cnt = 1
ans += cnt * (cnt -1) //2
print(ans)


Measured memory_bytes: 60120
import itertools



s1 = input()
n, m, q = map(int, s1.split(' '))

abcd = []

for i in range(q):
    s = input()
    aa, bb, cc, dd = map(int, s.split(' '))
    abcd.append((aa, bb, cc, dd))


# print(abcd)

max_point = 0

for A in itertools.combinations_with_replacement(range(1, m+1), n):
    # print(str(A))
    point = 0
    for t in abcd:
        # print(A[t[1]-1], A[t[0]-1], t[2])
        if A[t[1]-1] - A[t[0]-1] == t[2]:
            point += t[3]

    # print(point)
    if max_point < point:
        max_point = point

print(max_point)

Measured memory_bytes: 9216
li = []
while True:
    h, w = map(int, input().split(' '))
    if h == w == 0:
        break
    li.append((h, w))

for t in li:
    h, w = t
    for i in range(0, h):
        for j in range(0, w):
            print('#', end='')
        print()
    print()



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

int main() {

    int N;
    string S;
    cin >> N;
    rep(i,N){
        cin >>S;
        if(S == "Y"){
            cout << "Four" << endl;
            return 0;
        } 
    }
    cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace algorithm
{
	class Program
	{
		
		static void Main(string[] args)
		{
			double n = long.Parse(Console.ReadLine());
			long a = long.Parse(Console.ReadLine());
			long b = long.Parse(Console.ReadLine());
			long c = long.Parse(Console.ReadLine());
			long d = long.Parse(Console.ReadLine());
			long e = long.Parse(Console.ReadLine());
			//最小を取得
			double min = Math.Min(a, Math.Min(b, Math.Min(c, Math.Min(d,e))));
			Console.WriteLine(Convert.ToInt64(Math.Ceiling((double)n / min))+4);


		}

	}
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define PI 3.141592653589793238

typedef long long ll;

using namespace std;



int main() {
    
    ll n;
    cin>>n;
    
    ll a[n+1]={0};
    ll fr[n+1]={0};
    
    for(ll i=2;i<=n;i++)
    {
        cin>>a[i];
        fr[a[i]]++;
    }
    for(ll i=1;i<=n;i++)
    {
        cout<<fr[i]<<"\n";
    }
}

Measured memory_bytes: 6744
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

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

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int r;
	cin >> r;

	cout << 3 * r * r << endl;
	return 0;
}


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

int main(void)
{
  int i=0;
  long double v,floar;

  while(scanf("%Lf", &v) != EOF && i<50){
    floar = (v*v/98)+1;  
    if(floar - (int)floar > LDBL_EPSILON){
      floar++;
    }
    printf("%d\n", (int)floar);
    i++;  
  }
  return 0;
}

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

int main()
{
ll n , k ;
cin >> n ;
bool ok=0;
rep(i,n+1){
  if(n==((i+1)*i)/2){
    k=i+1;
    ok=1;
    cout << "Yes" << endl;
    break;
  }
}
if(!ok){cout << "No" << endl;return 0;}
cout << k << endl;
vector<vector<ll>> v(k);
vector<ll> itr(k);
ll num=1;
rep(i,k){
  rep(j,i){
    v[i].push_back(v[j][itr[j]]);
    itr[j]++;
    itr[i]++;
  }
  rep(j,k-1-i){
    v[i].push_back(num);
    num++;
  }
}
rep(i,k){
  cout << k-1 << " ";
  for(auto an:v[i]){
    cout << an << " ";
  }
  cout << endl;
}

return 0;
}

Measured memory_bytes: 3200
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- fetch input ---
inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---
s_1 = inputs[0]
s_2 = inputs[1]

flag = False
if len(s_2) == len(s_1) + 1:
    if s_1 == s_2[:-1]:
        flag = True

print('Yes' if flag else 'No')

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    int N; cin >> N;
    vi A(N); rep(i,N) cin >> A[i];
    sort(A.begin(), A.end());
    A.emplace_back(-1);
    int ans = 0, tmp = 0, cnt = 0;
    rep(i,N+1){
        if(A[i] != tmp){
            ans += (cnt >= tmp?cnt - tmp:cnt);
            tmp = A[i];
            cnt = 1;
        }else{
            cnt++;
        }
    }

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


Measured memory_bytes: 4000
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, K; cin >> N >> K;
    int c = 1, d = K-1;
    while(d < N)
    {
       c++;
       d = pow(K, c)-1; 
    }
    cout << c << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
x = sorted([list(map(int, input().split())) for i in range(N)])
i = 0
price = 0
minprice = x[i][0]
minnumber = x[i][1]
while True:
    if minnumber >= M:
        price += minprice*M
        break
    else:
        price += minprice * minnumber
        M -= minnumber
        i += 1
        minprice = x[i][0]
        minnumber = x[i][1]
print(price)

Measured memory_bytes: 28648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

void solve(){
	int a,b,c; cin>>a>>b>>c;
	int k; cin>>k;
	int f=0;
	while(b<=a && k>0){
		b*=2;
		k--;
	}
	if(b<=a){
		cout<<"No";LOL
		return;
	}
	while(c<=b && k>0){
		c*=2;
		k--;
	}
	if(c<=b || b<=a){
		cout<<"No";LOL
		return;
	}
	cout<<"Yes";LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int _=1;// cin>>_;
  for(int i=1 ; i<=_ ; i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
  return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int x,y; cin>>x>>y;
  for(int i=0; i<=x; i++){
    if(2*i+4*(x-i)==y){
      cout << "Yes"<<endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
using namespace std;
long long n,a,b,sum;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	sum+=a*(n/(a+b));
	n%=a+b;
	if(n<a)sum+=n;
	else sum+=a;
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input().split() for _ in range(N)]

a = []
b = []
for i in range(N):
	if S[i][0] not in a:
		a.append(S[i][0])
		b.append([[i + 1, int(S[i][1])]])
	else:
		for j in range(len(a)):
			if S[i][0] == a[j]:
				b[j].append([i + 1, int(S[i][1])])

index = sorted(range(len(a)), key=lambda x: a[x])


for i in range(len(index)):
	li = sorted(b[index[i]], key = lambda x: (x[1], x[0]), reverse = True)
	for j in range(len(li)):
		print(li[j][0])


Measured memory_bytes: 59756
def dfs(x, i)
  if i >= @s.size-1
    tmp = @s[0]
    a = []
    @s[1..-1].each_with_index do |t, id|
      if x[id]
        tmp += t
      else
        a << tmp.to_i
        tmp = t
      end
    end
    a << tmp.to_i
    @ans += a.sum
    return true
  end

  dfs(x.dup, i + 1)
  x[i] = true
  dfs(x.dup, i + 1)
end

@s = gets.chomp.split('')
x = Array.new(@s.size-1, false)
@ans = 0
dfs(x, 0)
puts @ans

Measured memory_bytes: 14388
#include<stdio.h>

int cnt_sum(int n,int s,int x){
  if( n==0 && s == 0){
    return 1;
  }
  if( x > 9 ){
    return 0;
  }

  return ( cnt_sum(n-1,s-x,x+1) + cnt_sum(n,s,x+1));
}

int main(void){
  int n,s;
  while(1){
    scanf("%d %d",&n,&s);
    if( n == 0 && s == 0){
      break;
    }
    printf("%d\n",cnt_sum(n,s,0));
  }
  return 0;
}

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

int main()
{
	int M, K;
	cin >> M >> K;
	if (K >= (1 << M)) {
		puts("-1");
		return 0;
	}
	if (M == 1) {
		if (K == 0) {
			puts("0 0 1 1");
		}
		else {
			puts("-1");
		}
		return 0;
	}
	for (int i = 0; i < (1 << M); i++) {
		if (i != K) {
			printf("%d ", i);
		}
	}
	printf("%d ", K);
	for (int i = (1 << M) - 1; i >= 0; i--) {
		if (i != K) {
			printf("%d ", i);
		}
	}
	printf("%d\n", K);
	return 0;
}


Measured memory_bytes: 1792
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

  ll a,b,h,m;
  cin >> a >> b >> h >> m;

  double m_ang = m * 6.0;
  double h_ang = h * 30.0 + m / 2.0;
  if(h_ang >= 360.0) h_ang -= 360.0;

  double aida = abs(h_ang - m_ang);

  double PI = 3.141592653589793;

  if(aida > 180.0)
  {
    aida = 360.0 - aida;
  }

  double ans = a * a + b * b - 2 * a * b * cos(PI /180.0 * aida);


  cout << fixed << setprecision(15) << sqrt(ans) << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}


Measured memory_bytes: 4228
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

inline int MaxDay(int y, int m) {
  if (y % 3 == 0) { return 20; }
  return m % 2 == 1 ? 20 : 19;
}
int main() {
  int n;
  int y, m, d;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d %d %d", &y, &m, &d);
    int ans = 0;
    while (y != 1000 || m != 1 || d != 1) {
      ans++;
      d++;
      if (d > MaxDay(y, m)) {
        d = 1;
        m++;
        if (m > 10) {
          m = 1;
          y++;
        }
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 872
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  ll n,m;
  cin>>n>>m;
  if((n-m)%2==0){cout<<min(n,m)+abs(n-m)/2;}
  else cout<<"IMPOSSIBLE";
  cout<<endl;
}


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int xdiff = x2 - x1;
  int ydiff = y2 - y1;
  int x3 = x2 - ydiff;
  int y3 = y2 + xdiff;
  int x4 = x1 - ydiff;
  int y4 = y1 + xdiff;

  // 解答
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


Measured memory_bytes: 256
import sys 

readline = sys.stdin.readline

LRd = readline().split()
L = int(LRd[0])
R = int(LRd[1])
d = int(LRd[2])

counter = 0
for i in range(L, R+1):
    if i % d == 0:
        counter += 1

print(counter)

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

long f[52], p[52];

long func(int n, long x)
{
    long res=0;
    if (x<=0) return 0;
    x--;
    if (x>=f[n-1]) {
        res+=p[n-1];
        x-=f[n-1];
        if (x<=1) return res+x;
        x--;
        ++res;
        if (x>=f[n-1]) return res+p[n-1];
        return res+func(n-1, x);
    }
    return func(n-1, x);
}

int main()
{
    int n; cin>>n;
    long x; cin>>x;
    f[0]=p[0]=1;
    for(int i=1; i<=n; ++i) {
        f[i]=1+f[i-1]+1+f[i-1]+1;
        p[i]=p[i-1]+1+p[i-1];
    }
    cout<<func(n, x)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#define dst first
#define id second
using namespace std;
typedef pair<int, int> Edge;
const int NODE = 51;
const int START_GOAL = 20;
const int BUF = 1 << START_GOAL;


int nNode;
vector<Edge> adj[NODE];
int nSG, startGoal[START_GOAL][2];

void read() {
    for (int i = 0; i < NODE; ++i) adj[i].clear();

    cin >> nNode;
    for (int i = 0; i < nNode - 1; ++i) {
        int s, t;
        cin >> s >> t;
        --s, --t;
        adj[s].push_back(Edge(t, i));
        adj[t].push_back(Edge(s, i));
    }
    cin >> nSG;
    for (int i = 0; i < nSG; ++i) {
        int s, g;
        cin >> s >> g;
        --s, --g;
        startGoal[i][0] = s;
        startGoal[i][1] = g;
    }
}


bool dfs(int pre, int cur, int goal, int edge2mask[NODE], int id) {
    if (cur == goal) return true;
    for (int i = 0; i < adj[cur].size(); ++i) {
        Edge &e = adj[cur][i];
        if (e.dst == pre) continue;
        if (dfs(cur, e.dst, goal, edge2mask, id)) {
            edge2mask[e.id] |= 1 << id;
            return true;
        }
    }
    return false;
}


long long rec(int cur, int mask, long long dp[NODE][BUF], int edge2mask[NODE]) {
    long long &ret = dp[cur][mask];
    if (ret != -1) return ret;
    
    ret = 0;
    
    if (mask == (1 << nSG) - 1) {
        ret = (1LL << (nNode - 1 - cur));
        return ret;
    }

    if (cur == nNode - 1) {
        return ret;
    }
    
    // color edge
    ret += rec(cur + 1, mask | edge2mask[cur], dp, edge2mask);
    
    // do not color edge
    ret += rec(cur + 1, mask, dp, edge2mask);

    return ret;
}


void work() {
    int edge2mask[NODE] = {};
    for (int i = 0; i < nSG; ++i) {
        dfs(-1, startGoal[i][0], startGoal[i][1], edge2mask, i);
    }

    static long long dp[NODE][BUF];
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 0, dp, edge2mask) << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 418048
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc1 = new Scanner(System.in);
        String s1 = sc1.next();
        int count = 0;
        
        char words[] = new char[s1.length()];
        for(int i = 0; i < s1.length(); i++){
            words[i] = s1.charAt(i);
        }
        
        // check first A
        if(words[0] == 'A'){
            count++;
            words[0] = 'a';
        }
        
        // check C
        int cCount = 0;
        for(int i = 2; i < s1.length() - 1; i++){
            if(words[i] == 'C'){
                cCount++;
                words[i] = 'c';
            }
        }
        
        if(cCount == 1){
            count++;
        }
        
        // check small chalacter
        for(int i = 1; i < s1.length(); i++){
            if(Character.isUpperCase(words[i])){
                count--;
            }
        }
        
        if(count == 2){
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
        
    }
}


Measured memory_bytes: 21844
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long

int digsum(int n){
    int res = 0;
    while(n > 0){
        res ++;
        n /= 10;
    }
    return res;
}


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s; cin >> s;
    int sum;
    int ans = 100000;

    for(int i = 0;i < s.size()-2;i ++){
        sum = (s.at(i) - '0') * 100 + (s.at(i+1) - '0') * 10 + s.at(i+2) - '0';
        ans = min(ans, abs(sum - 753));
    }

    cout << ans << endl;
}







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


int main(){
    ll n,k;cin>>n>>k;
    ll a[1010];
    a[0]=0;
    rep(i,0,n)cin>>a[i+1];
    vector<ll> b;
    rep(i,1,n+1)a[i]+=a[i-1];
    rep(i,0,n){
        rep(j,i+1,n+1){
            b.push_back(a[j]-a[i]);
        }
    }
    ll x=0;
    for(ll i=40;i>=0;i--){
        ll cn=0,pw=1LL<<i;
        x+=pw;
        rep(j,0,b.size()){
            if((b[j]&x)==x)cn++;
        }
        if(cn<k)x-=pw;
    }
    cout<<x<<endl;
}

    









Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p(ll a,ll n){ll s=(1LL<<n)-1,t=s/2;return t<a?a-t-1:t-a;}
char f(ll a,ll b,ll n){ll s = (1LL<<n)-1;return ((a*2>s)^(p(a, n)&1)^(b&1)?'L':'R');}
int main(){
	ll n, a, b;
	while(cin>>n>>a>>b,n+a+b) {
		a--;b--;
		string s;
		while(n>1){s+=f(a, b, n);a = p(a, n);n--;b /= 2;}
		s+=(a^b?'R':'L');
		reverse(s.begin(),s.end());
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cmath>

int main(){
    long long n;
    std::cin >> n;

    long long ans = 1;
    for(long long i = 1; i <= n; ++i){
        ans *= i%(long long)(std::pow(10, 9) + 7);
        ans = ans%(long long)(std::pow(10, 9) + 7);
    }

    std::cout << ans << std::endl;;

    return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int64 x, y;
  cin >> x >> y;
  if (abs(x - y) <= 1) {
    cout << "Brown" << endl;
  } else {
    cout << "Alice" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l, N, i=0;
  cin >> N;
  int vec[N];
  int g_max = 0;
  int max = 0;
  int sec_index = 0;
  int sec_max = 0;
  while(cin >> l){
    vec[i] = l;
    if (max < l){
      max = l;
      g_max = i;
    } else {
      if (sec_max < l){
        sec_max = l;
      }
    }
    
    i++;
  }

  for(i = 0; i < N; i++){
    max = 0;
    if(i == g_max){
      max = sec_max;
    } else {
      max = vec[g_max];
    }
    cout << max << "\n";
  }
}

Measured memory_bytes: 2432
#include<iostream>
using namespace std;
int n, a;
int main() {
	while (cin >> n) {
		a = (n - 1) % 39 + 1;
		if (a >= 10) { cout << "3C" << a << endl; }
		else { cout << "3C0" << a << endl; }
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  vector<int> c(a);
  vector<int> d(a-1);
  rep(i,a)
    cin>>b.at(i);
  rep(i,a)
    cin>>c.at(i);
  rep(i,a-1)
    cin>>d.at(i);
  int e=0;
  rep(i,a)
    e+=c.at(i);
  rep(i,a-1){
  if(b.at(i)+1==b.at(i+1))
    e+=d.at(b.at(i)-1);
  }
    cout<<e;
    
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewMe)
{
  StNode*  poParnt = nullptr;
  StNode** ppoNode = &rpoRoot;

  while (*ppoNode)
  {
    poParnt = *ppoNode;
    if (poNewMe->m_nKey < poParnt->m_nKey)
      ppoNode = &poParnt->m_poLeft;
    else
      ppoNode = &poParnt->m_poRigt;
  }

  poNewMe->m_poParnt = poParnt;
  *ppoNode = poNewMe;
}

StNode* fnFind(StNode* poRoot, int nNo)
{
  StNode* poNode = poRoot;
  while (poNode)
    if (nNo == poNode->m_nKey)
      return poNode;
    else if (nNo < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;

  return nullptr;
}

void fnDelete(StNode*& rpoRoot, StNode* poDelMe)
{
  StNode** ppoPrToMe;
  if (poDelMe == rpoRoot)
    ppoPrToMe = &rpoRoot;
  else
    if (poDelMe->m_nKey < poDelMe->m_poParnt->m_nKey)
      ppoPrToMe = &poDelMe->m_poParnt->m_poLeft;
    else
      ppoPrToMe = &poDelMe->m_poParnt->m_poRigt;

  int nDegr = 0;
  StNode* poMeToCd;
  if (poDelMe->m_poLeft)
  {
    ++nDegr;
    poMeToCd = poDelMe->m_poLeft;
  }
  if (poDelMe->m_poRigt)
  {
    ++nDegr;
    poMeToCd = poDelMe->m_poRigt;
  }

  if (!nDegr)
  {
    *ppoPrToMe = nullptr;
    delete poDelMe;
  }
  else if (nDegr == 1)
  {
    *ppoPrToMe = poMeToCd;
    poMeToCd->m_poParnt = poDelMe->m_poParnt; 
    delete poDelMe;
  }
  else if (nDegr == 2)
  {
    StNode* poNext = poDelMe->m_poRigt;
    while (poNext->m_poLeft)
      poNext = poNext->m_poLeft;

    poDelMe->m_nKey = poNext->m_nKey;
    fnDelete(rpoRoot, poNext);
  }
}

void fnInOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (!poNode)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewMe = new StNode(nNo);
      fnInsert(rpoRoot, poNewMe);
    }
    else if (sCmd[0] == 'f')
    {
      int nNo;
      cin >> nNo;
      if (fnFind(rpoRoot, nNo))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    else if (sCmd[0] == 'd')
    {
      int nNo;
      cin >> nNo;
      StNode* poDelMe;
      if (poDelMe = fnFind(rpoRoot, nNo))
        fnDelete(rpoRoot, poDelMe);
      else;
    }
    else if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
    else;
  }
}

void fnPstOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
  fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 21912
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{

	public static Node root = null;
	private static class Node {
		Node() {
			this.value = -1;
			this.leftNode = null;
			this.rightNode = null;
		}
		public int value;
		public Node leftNode;
		public Node rightNode;
	}

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		Scanner s = new Scanner(System.in);
		int cnt = new Integer(br.readLine()).intValue();
		for(int i=0 ; i<cnt ; i++) {
			String[] tmp = br.readLine().split(" ");
			if("insert".equals(tmp[0])) {
				Node n = new Node();
				n.value = new Integer(tmp[1]).intValue();
				insert(n);
			}else {
				inorder(root);
				System.out.println();
				preorder(root);
				System.out.println();
			}
		}
		if(br!=null) {
			br.close();
			br = null;
		}
	}

	public static void insert(Node node) {
		if(root==null){
			root = node;
			return;
		}
		Node targetNode = root;
		Node parent = null;
		while(targetNode != null) {
			parent = targetNode;
			if(targetNode.value > node.value)
				targetNode = targetNode.leftNode;
			else
				targetNode = targetNode.rightNode;
		}
		if(parent.value > node.value)
			parent.leftNode = node;
		else
			parent.rightNode = node;
	}

	public static void preorder(Node root) {
		System.out.print(" " + root.value);
		if(root.leftNode != null)
			preorder(root.leftNode);
		if(root.rightNode != null)
			preorder(root.rightNode);
	}

	public static void inorder(Node root) {
		if(root.leftNode != null)
			inorder(root.leftNode);
		System.out.print(" " + root.value);
		if(root.rightNode != null)
			inorder(root.rightNode);
	}
}

Measured memory_bytes: 247812
package main

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

var (
	dp   []int
	dmg  []int
	cost []int
)

const inf = 100000000000

func main() {
	H := nextInt()
	N := nextInt()
	dmg = make([]int, N)
	cost = make([]int, N)
	for i := 0; i < N; i++ {
		dmg[i] = nextInt()
		cost[i] = nextInt()
	}
	dp = make([]int, H+1)
	for i := 1; i < H+1; i++ {
		dp[i] = inf
	}
	for h := 1; h < H+1; h++ {
		for j := 0; j < N; j++ {
			if dmg[j] >= h {
				dp[h] = minInt(dp[h], cost[j])
			} else {
				dp[h] = minInt(dp[h], dp[h-dmg[j]]+cost[j])
			}
		}
	}
	fmt.Println(dp[H])
}

func minInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
using vp = vector<pair<int,int>>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main(){
    string s;cin >> s;
    int n;cin >> n;
    deque<char> ans;
    rep(i,s.size()) ans.push_back(s[i]);
    bool TF = true;
    rep(i,n){
        int a;cin >> a;
        if(a == 1){
            if(TF) TF = false;
            else if(!TF) TF = true;
        }
        if(a == 2){
            int b;cin >> b;
            char c;cin >> c;
            if(b == 1){
                if(TF) ans.push_front(c);
                if(!TF) ans.push_back(c);
            }
            if(b == 2){
                if(TF) ans.push_back(c);
                if(!TF) ans.push_front(c);
            }
        }
    }
    string Ans = "";
    if(!TF) reverse(ans.begin(),ans.end());
    rep(i,ans.size()) Ans += ans[i];
    cout << Ans << endl;
}


Measured memory_bytes: 4256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static int INF = (int) 1e9;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if (n == 0 && m == 0) {
				break;
			}
			int[] c = new int[m];
			for(int i=0;i<m;i++) {
				c[i] = sc.nextInt();
			}
			int[] x = new int[n];
			for(int i=0;i<n;i++) {
				x[i] = sc.nextInt();
			}
			int[][] dp = new int[n+1][256];
			for(int i=0;i<=n;i++) {
				Arrays.fill(dp[i], INF);
			}
			dp[0][128] = 0;
			for(int i=0;i<n;i++) {
				for(int j=0;j<256;j++) {
					if (dp[i][j] >= INF) {
						continue;
					}
					for(int k=0;k<m;k++) {
						int to = j + c[k];
						if (to < 0) {
							to = 0;
						}else if(to >= 256) {
							to = 255;
						}
						int diff = (x[i] - to) * (x[i] - to);
						dp[i+1][to] = Math.min(dp[i+1][to],dp[i][j] + diff);
					}
				}
			}
			int min = INF;
			for(int i=0;i<256;i++) {
				min = Math.min(min,dp[n][i]);
			}
			System.out.println(min);
		}
	}

}

Measured memory_bytes: 130936
import sys

input = sys.stdin.readline


def main():
    N, T = map(int, input().split())
    c = [0] * N
    t = [0] * N
    for i in range(N):
        c[i], t[i] = map(int, input().split())

    ans = float("inf")
    for i in range(N):
        if t[i] <= T and c[i] < ans:
            ans = c[i]

    if ans == float("inf"):
        ans = "TLE"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
T = list(input())
N = len(T)
if T[-1] == "?":
    T[-1] = "D"

if N == 1 and T[0] == "?":
    T[0] = D
elif N == 2:
    if T[0] == "?" and T[1] == "?":
        T[0] = "P"
        T[1] = "D"
                
    elif T[0] == "?" and T[1] == "D":
        T[0] = "P"
                
    elif T[0] == "?" and T[1] == "P":
        T[0] = "D"
        
    elif T[0] == "P" and T[1] == "?":
        T[1] = "D"
        
elif N > 2:        
    if T[0] == "?" and T[1] == "?":
        T[0] = "P"
        T[1] = "D"
          
    elif T[0] == "?" and T[1] == "D":
        T[0] = "P"
            
    elif T[0] == "?" and T[1] == "P":
        T[0] = "D"
            
    elif T[0] == "D" and T[1] == "?" and T[2] == "D":
        T[1] = "P"
            
    elif T[0] == "D" and T[1] == "?" and T[2] == "P":
        T[1] = "D"
    
    elif T[0] == "P" and T[1] == "?":
        T[1] = "D"
        
    for i in range(2,N-1):
        if T[i-2] == "P" and T[i-1] == "D" and T[i+1] == "D" and T[i] == "?":
            T[i] = "P"
            continue
        
        elif T[i] == "?":
            T[i] = "D"
        

ans = "".join(T)         
print(ans)


Measured memory_bytes: 73884
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Numerics;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split().Select(int.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		var S = ReadLine();
		for (var c = 'a'; c <= 'z'; c++) if (!S.Contains(c)) { WriteLine(c); return; }
		WriteLine("None");
	}
}


Measured memory_bytes: 13536
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn gcd(a: u64, b: u64) -> u64{
    if b == 0{
        return a;
    }

    return gcd(b, a%b);
}

fn lcm(a:u64, b:u64) -> u64{
    return a / gcd(a, b) * b;
}

fn main(){
    let n: usize = read_as_vec()[0];

    let mut t: Vec<u64> = vec![];

    for _ in 0..n{
        t.push(read_as_vec()[0]);
    }

    let mut ans = t[0];

    for &elem in &t{
        ans = lcm(ans, elem);
    }

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


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1001

static int dp[MAX][MAX];

int main() {
	int q; cin >> q;
	while (q--) {
		memset(dp, 0, sizeof(dp));
		string X, Y; cin >> X >> Y;
		for (int i = 1; i <= X.size(); i++) {
			for (int j = 1; j <= Y.size(); j++) {
				if (X[i - 1] == Y[j - 1]) {
					//cout << i << j << X[i - 1] << endl;
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
				else {
					dp[i][j] = max(
						dp[i - 1][j],
						dp[i][j - 1]
					);
				}
			}
		}
		//for (int i = 0; i <= Y.size(); i++) {
		//	for (int j = 0; j <= X.size(); j++) {
		//		cout << dp[j][i] << " ";
		//	}
		//	cout << endl;
		//}
		cout << dp[X.size()][Y.size()] << endl;

	}

	return 0;
}

Measured memory_bytes: 5128
#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 && W - r >= x&&H - r >= y) {


		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
	




	return 0;
}

Measured memory_bytes: 3084
def main():
    A = int(input())
    B = int(input())

    if A == 1 and B == 2:
        print(3)
    elif A == 1 and B == 3:
        print(2)
    elif A == 2 and B == 1:
        print(3)
    elif A == 2 and B == 3:
        print(1)
    elif A == 3 and B == 1:
        print(2)
    elif A == 3 and B == 2:
        print(1)


if __name__ == "__main__":
    main()


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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

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

    vector<int> A(N);
    int g = -1;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (g < 0) g = A[i];
        else g = gcd(g, A[i]);
    }

    for (int a : A) {
        if (a >= K && (a - K) % g == 0) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = "";
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='0' || s.charAt(i)=='1') {
				ans += s.charAt(i);
			}else {
				if(ans.length()!=0) {
					ans = ans.substring(0,ans.length()-1);
				}
			}
		}
		System.out.println(ans);
	}

}

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

int main(){
    ll n, m;
    cin >> n >> m;
    vector<bool> v(n+1, false);
    rep(i, 0, m) {
        ll a;
        cin >> a;
        v[a] = true;
    }
    vector<ll> dp(n+1, 0);
    dp[0] = 1;
    const ll mod = 1000000000 + 7;
    rep(i, 0, n) {
        if(v[i]) continue;
        if(!v[i+1]){
            dp[i+1] += dp[i];
            dp[i+1] %= mod;
        }
        if(!v[i+2] && i+2 <= n) {
            dp[i+2] += dp[i];
            dp[i+2] %= mod;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4044
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}

int main(){
    vector<char> c={'a','e','i','o','u'};
    char d;
    cin>>d;
    REP(e,c)if(e==d){
        cout<<"vowel"<<endl;
        return 0;
    }
    cout<<"consonant"<<endl;
}

Measured memory_bytes: 256