akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    for(int i=0;i<s.length();i++){
      if(s.charAt(i)!=t.charAt(i)){
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}
    

Measured memory_bytes: 35680
N = int(input())
A = [0]*N

for i in range(N):
    A[i] = int(input())

mx = max(A)
mxi = A.index(max(A))

for i in range(N):
    if i != mxi:
        print(mx)
    elif i == 0:
        print(max(A[1:N]))
    elif i == N-1:
        print(max(A[0:N-1]))
    else:
        print(max(max(A[0:i]),max(A[i+1:N])))


Measured memory_bytes: 14012
n = int(input())
a = list(map(float,input().split()))
b = [0]
table = [[0 for _ in range(n+1)]for  _ in range(n+1)]
table[0][0] = 1
for v in a:
    b.append(1-v)
s1 =1
s2 =1
ans = 0
a = [0]+a
for i in range(1,n+1):
    s1*=a[i]
    s2*=b[i]
    table[i][0]=s1
    table[0][i]=s2
for i in range(1,n):
    for j in range(1,n):
        if i+j<=n:
            table[i][j] = table[i-1][j]*a[i+j]+ table[i][j-1]*b[i+j]
for i in range(n+1):
    for j in range(n+1):
        if i>j and i+j ==n:
            ans+= table[i][j]
print(ans)


Measured memory_bytes: 324616
#include <stdio.h>
int x_go_max[17][100000];//2^17日>10^5日あれば，端の町から端の町まで移動できる
int a[100000], b[100000];
int main(void){
    int n, i, j;
    scanf("%d", &n);
    int x[100000];
    for(i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    int l;
    scanf("%d", &l);
    int q;
    scanf("%d", &q);
    
    for(i = 0; i < q; i++){
        scanf("%d%d", &a[i], &b[i]);
        a[i]--;
        b[i]--;
    }
    
    for(i = 0; i < n; i++){
        //2分探索で，最大どこからどこまで移動できるかを計算
        if(x[n-1] - x[i] <= l){
            x_go_max[0][i] = n-1;
            continue;
        }
        int left = i+1;
        int right = n;
        while(right - left > 1){
            int mid = (right - left)/2 + left;
            if(x[mid] - x[i] <= l){
                left = mid;
            }else{
                right = mid;
            }
        }
        x_go_max[0][i] = left;
    }

    for(i = 1; i < 17; i++){
        for(j = 0; j < n; j++){
            x_go_max[i][j] = x_go_max[i-1][x_go_max[i-1][j]];
        } 
    }

    for(i = 0; i < q; i++){
        int ans = 0;
        int c = a[i] > b[i] ? b[i] : a[i];
        int d = a[i] > b[i] ? a[i] : b[i];
        //cからd(c < d)に移動することを考える
        for(j = 16; j >= 0; j--){
            if(x_go_max[j][c] < d){//(1 << j)日で移動できない場合
                c = x_go_max[j][c];
                ans += 1 << j;
            }
        }
        printf("%d\n", ans+1);
    }
    return 0;
}

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

int main(){
  int n, tmp;
  int ans=0, min=999999;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> tmp;
    if(tmp<min){
      min = tmp;
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
  
  int i,j;
  
  int main(void){
           for(i=1;i<=9;i++){
                   for(j=1;j<=9;j++){
                  printf("%dx%d=%d\n",i,j,i*j);
                   }
                  }
  
            return 0;
  }

Measured memory_bytes: 524
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]


def sol(list):
    res = 0
    for i in range(q):
        if list[abcd[i][1]-1] - list[abcd[i][0]-1] == abcd[i][2]:
            res += abcd[i][3]
    return res


def dfs(i, la):
    if i == n-1:
        return sol(la)
    else:
        last = 1
        if i >= 0:
            last = la[-1]
        res = 0
        for j in range(last, m+1):
            res = max(res, dfs(i+1, la+[j]))
        return res

print(dfs(-1,[]))

Measured memory_bytes: 73504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
int main(){
	string s;
	int len,i,sum=0;
	cin>>s;
	len=s.size();
	for(i=0;i<len;i++){
		if(s[i]=='1'){
			sum++;
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

N = intinput()
K = intinput()
x = listintinput()
ans = 0
for i in range(N):
    ans += 2 * min(x[i], abs(K - x[i]))

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int N, K;
  cin>>N>>K;
  vector<int> H(N);
  for(int i=0; i<N; i++)cin>>H[i];

  if(N<=K){
    cout<<0<<endl;
    return 0;
  }

  sort(H.begin(), H.end());
  for(int i=0; i<K; i++)H.pop_back();

  long long ans = 0;

  for(int x: H)ans += x;

  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> d(K);
	vector<int> A(N,0);
	for (int i = 0; i < K; i++) {
		cin >> d[i];
		for (int j = 0; j < d[i]; j++) {
			int a = 0;
			cin >> a;
			A[a - 1]++;
		}
	}
	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3624
import sys
from collections import deque

q = int(input())
L = deque()
L2 = deque()
cur = 0
for i in range(q):
    query = sys.stdin.readline()
    if query[0] == '0':
        L2.appendleft(query[2:].strip())
    elif query[0] == '1':
        n = int(query[2:].strip())
        if n > 0:
            for _ in range(n):
                L.append(L2[0])
                L2.popleft()
        else:
            for _ in range(-n):
                L2.appendleft(L[-1])
                L.pop()
    else:
        L2.popleft()

for i in L:
    print(i)
for i in L2:
    print(i)


Measured memory_bytes: 35596
// 2020/07/30 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

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

	int DP[101][10001];

	for(int j=0; j<=10000; j++){
		DP[0][j] = 1000000001;
	}
	DP[0][0] = 0;

	for(int i=1; i<=N; i++){
		for(int j=0; j<=10000; j++){
			if(j<v[i-1]){
				DP[i][j] = DP[i-1][j];
			}
			else{
				DP[i][j] = min(DP[i-1][j], DP[i-1][j-v[i-1]]+w[i-1]);
			}
		}
	}

	for(int j=10000; j>=0; j--){
		if(DP[N][j]<=W){
			cout << j << endl;
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 7072
import sys
INFTY=sys.maxsize

def readinput():
    a,b,c,x,y=list(map(int,input().split()))
    return a,b,c,x,y

def main(a,b,c,x,y):
    minPrice=INFTY
    for nab in range(0,max(x,y)*2+1,2):
        na=max(0,x-nab//2)
        nb=max(0,y-nab//2)
        price=nab*c+na*a+nb*b
        #print(price, na, nb, nab)
        minPrice=min(minPrice,price)  
    return minPrice  

if __name__=='__main__':
    a,b,c,x,y=readinput()
    ans=main(a,b,c,x,y)
    print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << endl;
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef pair<float, float> ff;
const int Nmax = 100001;
int arr[Nmax], n, f[Nmax];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	scanf("%d", &n);
	REP1(i, n) scanf("%d", &arr[i]);
	f[2] = abs(arr[1] - arr[2]);
	FOR(i, 3, n) f[i] = min(f[i - 1] + abs(arr[i] - arr[i - 1]), f[i - 2] + abs(arr[i] - arr[i - 2]));
	cout << f[n];
	return 0;
}

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

using namespace std;

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

    long long ans_1 = 0, ans_2 = 0;
    vector<long long> sum(N);
    for(int i = 0;i < N; i++){
        if(i == 0){
            sum[i] = a[i];
        }else{
            sum[i] = sum[i-1] + a[i];
        }

        if(i % 2 == 1){ // 奇数番目をマイナス
            if(sum[i] >= 0){
                ans_1 += sum[i] + 1;
                sum[i] -= sum[i] + 1;
            }
        }else{ // 偶数番目をプラス
            if(sum[i] <= 0){
                ans_1 += 1-sum[i];
                sum[i] += 1-sum[i];
            }
        }
    }

    for(int i = 0; i < N; i++){
        if(i == 0){
            sum[i] = a[i];
        }else{
            sum[i] = sum[i-1] + a[i];
        }

        if(i % 2 == 1){ // 奇数番目をプラス
            if(sum[i] <= 0){
                ans_2 += 1-sum[i];
                sum[i] += 1-sum[i];
            }
        }else{ // 偶数番目をマイナス
            if(sum[i] >= 0){
                ans_2 += sum[i]+1;
                sum[i] -= sum[i]+1;
            }
        }
    }

    cout << min(ans_1, ans_2) << endl;


    return 0;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#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 rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  string a;
  cin>>a;
  a.insert(4," ");
  cout<<a<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        //1行目
        Integer intN = scan.nextInt();
        Integer intM = scan.nextInt();
        int[] highArr = new int[intN + 1];

        //2行目
        for (int i = 1; i <= intN; i++) {
            highArr[i] = scan.nextInt();
        }

        //3行目以降
        List<Integer> ngList = new ArrayList<Integer>();

        while (scan.hasNext()) {
            Integer intLeft = scan.nextInt();
            Integer intRight = scan.nextInt();
            if(highArr[intLeft] < highArr[intRight]) {
                ngList.add(intLeft);
            } else if (highArr[intLeft] > highArr[intRight]) {
                ngList.add(intRight);
            } else {
                ngList.add(intLeft);
                ngList.add(intRight);
            }
        }

        scan.close();
        // 結果
        ArrayList<Integer> retList = new ArrayList<Integer>(new HashSet<>(ngList));
        System.out.println(intN - retList.size());
    }
}


Measured memory_bytes: 61992
N=int(input())
s=["" for i in range(N)]
t=["" for i in range(N)]
for i in range(N):
    s[i],t[i]=input().split()
    t[i]=int(t[i])
X=input()
flag=0
ans=0
for i in range(N):
    if flag==1:
        ans+=t[i]
    else:
        if s[i]==X:
            flag=1
print(ans)


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

int main() {
  long n, ans = 0, flag = 0;

  cin >> n;

  while (n) {
    if (n / 10 < 1) {
      if (flag) {
        ans += n % 10 - 1;
      } else {
        ans += n;
      }
    } else {
      ans += 9;
      if (n % 10 != 9) flag = 1;
    }
    n /= 10;
  }

  cout << ans;

  return 0;
}

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

int N;
set<string>st;
int main(){
	cin>>N;
	while(N--){
		string S;
		cin>>S;
		st.insert(S);
	}
	cout<<st.size()<<endl;
}


Measured memory_bytes: 19228
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

    vec v1,v2;
    for(int i=0;i<N;i++){
        if(S[i]=='(')v1.push_back(i);
        else v2.push_back(i);
    }
    int L1=v1.size(),L2=v2.size();
    int front=L2,back=L1;
    
    if(!v1.empty() && !v2.empty()){
    int i=0,j=0;
    while(i<L1){
        while(v1[i]>v2[j] && j<L2)j++;
        if(j==L2)break;
        front--;back--;
        i++;j++;
    }}
    
    for(int i=0;i<front;i++)cout<<"(";
    cout<<S;
    for(int i=0;i<back;i++)cout<<")";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX 40

int n, pos;
vector<int> pre, in, post;
int order_in[MAX+1];

void detectTree(int left, int right){
    if(left >= right) return;
    int root = pre[pos++];
    int m = order_in[root];
    detectTree(left, m);
    detectTree(m+1, right);
    post.push_back(root);
}


int main(void){
    int id;
    pos = 0;
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> id;
        pre.push_back(id);
    }
    for(int i = 0; i < n; i++){
        cin >> id;
        in.push_back(id);
        order_in[id] = i;
    }
    
    detectTree(0, n);
    for(int i = 0; i < n; i++){
        if(i) cout << " ";
        cout << post[i];
    }
    cout << endl;
}



Measured memory_bytes: 3160
//package Atcoder_dp;

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++){
            h[i] = scanner.nextInt();
        }
        if(n==0){
            System.out.println(0);
            return;
        }
        int pp = 0;
        int p = Math.abs(h[0]-h[1]);
        for(int i = 2; i < n; i++){
            int aux = Math.min(pp+Math.abs(h[i]-h[i-2]), p+Math.abs(h[i]-h[i-1]));
            pp = p;
            p = aux;
        }
        System.out.println(p);
    }
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1000000000 //
#define LINF (ll)4000000000000000000 //
#define MOD (ll)1000000007
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    map<string, int> mp;
    set<string> st;
    int n;
    cin >> n;

    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
        st.insert(s);
    }

    int m;
    cin >> m;

    rep(i, m) {
        string s;
        cin >> s;
        mp[s]--;
        st.insert(s);
    }

    int money = 0;
    auto itr = st.begin();

    rep(i, st.size()) {
        money = max(money, mp[*itr]);
        itr++;
    }

    cout << money << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define MOD 1e9+7

int main()
{
    string s;cin>>s;
    int n=s.length()+1;
    vector<int> a(n,0);
    vector<int> b(n,0);
    int i;
    for(i=1;i<n;i++)
    {
        if(s.at(i-1)=='<')a.at(i)=a.at(i-1)+1;
        else a.at(i)=0;
    }
    for(i=n-2;i>=0;i--)
    {
        if(s.at(i)=='>')b.at(i)=b.at(i+1)+1;
        else b.at(i)=0;
    }
    long long ans=0;
    for(i=0;i<n;i++)
    {
        ans+=max(a.at(i),b.at(i));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4868
import sys,math,collections,itertools
input = sys.stdin.readline
m=10**9+7
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    i=2
    if temp%i==0:
        cnt=0
        while temp%i==0:
            cnt+=1
            temp //= i
        arr.append([i, cnt])
            
    for i in range(3, int(-(-n**0.5//1))+1,2):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])    

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=int(input())
A=list(map(int,input().split()))
d = collections.defaultdict(int)
for a in A:
    arr = factorization(a)
    for ar in arr:
        if d[ar[0]]<ar[1]:
            d[ar[0]]=ar[1]

lcm = 1
for key,val in d.items():
    lcm = lcm*pow(key,val)

ans = 0
for a in A:
    ans = ans+lcm//a
print(ans%m)


Measured memory_bytes: 10672
import numpy as np
S = np.array(list(input().rstrip()))
T = np.array(list(input().rstrip()))

s = len(S)
t = len(T)

max_count = 0

for i in range(s-t+1):
  max_count = max(max_count, (S[i:i+t]==T).sum())
      
print(len(T) - max_count)

#print(S[5:5+1])
#print(T[-(10-5):5+1])
#print(S[5:5+1] in T[-(10-5):5+1])

Measured memory_bytes: 27304
N, M = map(int, input().split())
H = list(map(int, input().split()))
l = [1] * N
for i in range(M):
    A, B = map(int, input().split())
    if H[A - 1] > H[B - 1]:
        l[B - 1] = 0
    elif H[A - 1] < H[B - 1]:
        l[A - 1] = 0
    elif H[A - 1] == H[B - 1]:
        l[A - 1], l[B - 1] = 0, 0
print(l.count(1))

Measured memory_bytes: 20032
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
//#pragma comment(linker, "/stack:200000000")

using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
//#define ipq priority_queue<ll, vector<ll>, greater<ll> >
//#define dpq priority_queue<ll>
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
//#define PQ(type) priority_queue<type>
//#define PQD(type) priority_queue<type,vector<type>,greater<type> >
//#define umap unordered_map<ll,ll> 
//#define vpair vector<pair<ll,ll>>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
ll mod=1e9+7;

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

    ll a,b;
    cin>>a>>b;
    a=a+b;
    if(a%2)
        cout<<"IMPOSSIBLE";
    else
        cout<<a/2;
    
    
}

Measured memory_bytes: 256
var input = require( 'fs' ).readFileSync( '/dev/stdin' ).toString();
  var data = input.split( " " ).map( Number );
  var a = data[0];
  var b = data[1];
  var C = data[2]*(Math.PI/180);
   
  var h = Math.sin( C )*b;
  var ta = Math.cos( C )*b;
  var c = Math.sqrt( Math.pow( (a-ta), 2 )+Math.pow( h, 2 ) );
   
  var S = (a*h)/2;
  var L = a+b+c;
  console.log( S+'\n'+L+'\n'+h );

Measured memory_bytes: 15668
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>  
#include <cstdlib>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int main() {
    int x, t;
    cin >> x >> t;
    int ans = x-t;
    if (ans<0) ans = 0;
    cout << ans << endl;
    return 0;
}

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

struct UnionFind {
    vector<int> data;
    UnionFind(int v) : data(v, -1) { }

    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            data[x] += data[y]; data[y] = x;
        }
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    UnionFind uf(N);
    for(int i = 0; i < Q; i++) {
        int comm, x, y;
        cin >> comm >> x >> y;
        if(comm == 0) {
            uf.merge(x, y);
        }
        else {
            cout << (uf.same(x, y) ? 1 : 0) << endl;
        }
    }
}

Measured memory_bytes: 1236
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

int dp[50][500][500];

int main()
{
  REP(i, 50)REP(j, 500)REP(k, 500)dp[i][j][k] = INF;

  int N, Ma, Mb;
  cin >> N >>  Ma >> Mb;
  vector<int> a(N), b(N), c(N);
  REP(i, N) cin >> a[i] >> b[i] >> c[i];

  dp[0][0][0] = 0;
  REP(i, N) {
    REP(j, 410) {
      REP(k, 410) {
        dp[i + 1][j + a[i]][k + b[i]] = min(dp[i][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
        dp[i + 1][j][k] = min(dp[i][j][k], dp[i + 1][j][k]);
      }
    }
  }

  int ans = INF;
  for (int i = 1; i <= 40; i++) {
    ans = min(ans, dp[N][i * Ma][i * Mb]);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;

	return 0;
}



Measured memory_bytes: 49024
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int n, X[200005], S[200005], a[200005], ans;

signed main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        X[i + 1] = X[i] ^ a[i];
        S[i + 1] = S[i] + a[i];
    }
    for(int l = 0; l < n; l++){
        int lb = l + 1, ub = n + 1;
        while(ub - lb > 1){
            int mid = (lb + ub) / 2;
            if((X[mid] ^ X[l]) == (S[mid] - S[l])) lb = mid;
            else ub = mid;
        }
        ans += lb - l;
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int d[20][20];
int dp[1<<17];


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	while (cin >> N) {
		if(N==0) break;
        
        
        for(int i=0; i<20; ++i){
            for(int j=0; j<20; ++j){
                d[i][j] = d[j][i] = 1e9;
            }
        }
        for(int i=0; i<N; ++i){
            for(int j=0; j<N+1; ++j){
                cin >> d[i][j];
            }
        }
        
        fill(dp, dp + (1 << 17), 1e9);
        
        dp[0]=0;
        for(int bit=0; bit<(1<<N); ++bit){
            for(int i=0; i<N; ++i){
                if( (bit & (1<<i))!=0) continue; //すでにクリアしている場合
                int cost = d[i][0];
                for(int j=0; j<N; ++j){
                    if( (bit & (1<<j)) == 0) continue;
                    
                    cost = min(d[i][j+1], cost);
                }
                
                int now = (bit | (1<<i));
                dp[now] = min(dp[now], dp[bit]+cost);
            }
        }
        cout << dp[(1<<N)-1] << endl;
	}
	int c; cin >> c;
	return 0;

}


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

using namespace std;

const int MAX_N = 260;
int n;
string grid[MAX_N];

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

int rec(int y, int x, int d)
{
    int nx = x + dx[d];
    int ny = y + dy[d];

    if (nx < 0 || nx >= n || ny < 0 || ny >= n)
        return 1;
    if (grid[ny][nx] == '0')
        return 1;

    return rec(ny, nx, d) + 1;
}

int main()
{
    while (cin >> n, n) {
        for (int i = 0; i < n; i++) 
            cin >> grid[i];

        int max_len = 0;
        for (int y = 0; y < n; y++) 
            for (int x = 0; x < n; x++) 
                if (grid[y][x] == '1') {
                    for (int k = 0; k < 4; k++) 
                        max_len = max(max_len, rec(y, x, k));
                }

        cout << max_len << endl;
    }

    return 0;
}

Measured memory_bytes: 1292
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		//FileReader f = new FileReader("src/test.txt");
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		StringBuilder a = new StringBuilder(in.next());
		if (a.length() == 2) {
			out.println(a);
		} else {
			out.println(a.reverse());
		}
		out.flush();
		out.close();

	}
	// 70376445703718

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

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

using namespace std;

typedef long long ll;

int main(){
        ll N, W;
        vector <ll> wv[4];
        cin>>N>>W;
        ll w1;
        for(ll i=0;i<N;i++){
                ll ww, vv;
                cin>>ww>>vv;
                if(i==0){
                        w1=ww;
                }
                wv[ww-w1].push_back(vv);
        }
        for(ll i=0;i<4;i++){
                sort(wv[i].begin(), wv[i].end());
                wv[i].push_back(0);
                reverse(wv[i].begin(), wv[i].end());
                for(ll j=1;j<(ll)wv[i].size();j++){
                        wv[i][j]+=wv[i][j-1];
                }
        }
        ll res=0;
        for(ll i=0;i<(ll)wv[0].size();i++){
                for(ll j=0;j<(ll)wv[1].size();j++){
                        for(ll k=0;k<(ll)wv[2].size();k++){
                                for(ll h=0;h<(ll)wv[3].size();h++){
                                        ll fact=w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*h;
                                        if(fact<=W){
                                                res=max(res, wv[0][i]+wv[1][j]+wv[2][k]+wv[3][h]);
                                        }
                                }
                        }
                }
        }
        cout<<res<<endl;
        return 0;
}


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

using namespace std;

#define price first
#define weight second

int main(){
	int W;
	int cnt = 1;
	while (cin >> W, W) {
		int N; cin >> N;
		vector<pair<int, int> > tres(N);
		for (int i = 0; i < N; i++) {
			scanf("%d,%d", &tres[i].price, &tres[i].weight);
		}
		vector<int> dp(W+1);
		for (int i = 0; i < W+1; i++) { dp[i] = -1; }
		dp[0] = 0;
		for (int i = 0; i < N; i++) {
			for (int j = W; j >= 0; j--) {
				if (dp[j] == -1) { continue; }
				if (j+tres[i].weight <= W) {
					dp[j+tres[i].weight] = max(dp[j]+tres[i].price, dp[j+tres[i].weight]);
				}
			}
		}
		int PRICE = 0;
		int WEIGHT = 0;
		for (int i = W; i >= 0; i--) {
			if (PRICE <= dp[i]) {
				PRICE = dp[i];
				WEIGHT = i;
			}
		}

		cout << "Case " << cnt << ":" << endl;
		cout << PRICE << endl;
		cout << WEIGHT << endl;
		cnt++;
	}
}

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

const int INF = 1e9;

struct Node {
    bool done;
    int dist;
    vector<int> to;
};

void diameter(int pos, int& res, vector<Node>& node) {
    node[pos].done = true;
    res = max(res, node[pos].dist);
    for (int i = 0; i < node[pos].to.size(); i++) {
        int npos = node[pos].to[i];
        if (node[npos].done == false) {
            node[npos].dist = node[pos].dist + 1;
            diameter(npos, res, node);
        }
    }
    return;
}

int main() {
    int n;
    cin >> n;
    vector<Node> node(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        node[a].to.push_back(b);
        node[b].to.push_back(a);
    }

    for (int i = 0; i < n; i++) {
        node[i].done = false;
        node[i].dist = INF;
    }
    node[0].dist = 0;
    int res = 0;
    diameter(0, res, node);
    int pos;
    for (int i = 0; i < n; i++) {
        if (node[i].dist == res) {
            pos = i;
        }
    }
    for (int i = 0; i < n; i++) {
        node[i].done = false;
        node[i].dist = INF;
    }
    node[pos].dist = 0;
    diameter(pos, res, node);
    if (res % 3 == 1) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
    return 0;
}

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

int main() {
  char a;
  cin >> a;

  if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

int main() {
int h,w,n;
  cin>>h>>w>>n;
  int ans=min((h+n-1)/h, (w+n-1)/w);
  cout<<ans<<endl;
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int mod=1e9+7;  ///A simpler way to write 1,000,000,007
 
int main()
{
    int n,k;
    cin >> n >> k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    int dp[n+1][k+1];
    dp[0][0]=1;
    for(int i=1;i<=k;i++)  /// Set the initial values
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        int sums[k+1];
        sums[0]=dp[i-1][0];
        for(int j=1;j<=k;j++)
        {
            sums[j]=(sums[j-1]+dp[i-1][j])%mod;  ///Calculate the prefix sums for i-1
        }
        for(int j=0;j<=k;j++)
        {
            int tr=sums[j];  ///Sum of dp[i-1][0...j]
            int unreachable=j-a[i]-1;  ///We need to subtract the sum of the first "unreachable" elements (dp[i-1][0...unreachable])
            if(unreachable>=0)
            {
                tr=(tr-sums[unreachable]+mod)%mod;  ///Add mod to make sure that "tr-sums[unreachable]" is not negative.
            }
            dp[i][j]=tr;
        }
    }
  	cout << dp[n][k];
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A,B,S[101010];
ll mo=1000000007;

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	V add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	V set(int e,V v) { add(e,v-val[e]);}
};

BIT<ll,20> BTA,BTB;
vector<int> VA,VB;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B;
	S[0]=-1LL<<60;
	cin>>S[1];
	
	int LA=0,LB=0;
	
	BTA.add(0,1);
	BTB.add(0,1);
	VA.push_back(0);
	VB.push_back(0);
	for(i=2;i<=N;i++) {
		cin>>S[i];
		
		while(LA<i-2&&S[i]-S[LA+1]>=A) LA++;
		while(LB<i-2&&S[i]-S[LB+1]>=B) LB++;
		
		BTB.add(i-1,BTA.total(LA)%mo);
		BTA.add(i-1,BTB.total(LB)%mo);
		
		if(S[i]<S[i-1]+A) {
			FORR(r,VB) BTB.set(r,0);
			VB.clear();
		}
		if(S[i]<S[i-1]+B) {
			FORR(r,VA) BTA.set(r,0);
			VA.clear();
		}
		VA.push_back(i-1);
		VB.push_back(i-1);
	}
	
	cout<<(BTA.total(N+1)+BTB.total(N+1))%mo<<endl;

}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size());
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e18;
// 左右から累積和
int main() {
  int n;
  cin >> n;
  vector<int> a(3*n);
  rep(i,3*n) cin >> a[i];

  vector<ll> l_max(2*n+1,0);
  priority_queue<ll, vector<ll>, greater<ll>> quel;
  //左から最大n~2n
  rep(i,n) {
    l_max[i+1] = l_max[i] + a[i];
    quel.push(a[i]);
  }

  for (int i = n; i < 2*n; i++) {
    ll mi = quel.top();
    if (a[i] > mi) {
      l_max[i+1] = l_max[i] - mi + a[i];
      quel.pop();
      quel.push(a[i]);
    }
    else l_max[i+1] = l_max[i];
  }

  vector<ll> r_min(2*n+1,0);
  priority_queue<ll> quer;
  //右から最小
  rep(i,n) {
    r_min[i+1] = r_min[i] + a[3*n-1-i];
    quer.push(a[3*n-1-i]);
  }

  for (int i = n; i < n*2; i++) {
    ll ma = quer.top();
    if (a[3*n-1-i] < ma) {
      r_min[i+1] = r_min[i] - ma + a[3*n-1-i];
      quer.pop();
      quer.push(a[3*n-1-i]);
    }
    else r_min[i+1] = r_min[i];
  }

  ll res = -INF;
  for (int i = n ; i <= 2*n; i++) {
    res = max(res, l_max[i] - r_min[n*3-i]);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 6900
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct query{int a,b,c,d;};
int main(){
    int h,w;
    cin>>h>>w;
    int a[h][w];
    rep(i,h)rep(j,w)cin>>a[i][j];
    vector<query> ans;
    rep(i,h){
        rep(j,w-1){
            if(a[i][j]%2){
                ans.push_back({i+1,j+1,i+1,j+2});
                a[i][j+1]++;
            }
        }
        if(i!=h-1&&a[i][w-1]%2){
            ans.push_back({i+1,w,i+2,w});
            a[i+1][w-1]++;
        }
    }
    cout<<ans.size()<<endl;
    for(auto q : ans){
        cout<<q.a<<" "<<q.b<<" "<<q.c<<" "<<q.d<<endl;
    }
    return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n;i++){
        cin >> A.at(i);
    }
    int max=0;
    int index=0;    
    for (int i = 0; i < n;i++){
        if(max<A.at(i)){
            max = A.at(i);
            index = i;
        }
    } 

    std::sort(A.begin(), A.end(), std::greater<int>());

    for (int i = 0; i < n;i++){
        if(i==index){
            cout << A.at(1) << endl;
        } else {
            cout << A.at(0) << endl;
        }
    }
}


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

int main(){
  string s;
  cin >> s;
  
  int counter = 0;
  
  if(s[0] == '1') counter++;
  if(s[1] == '1') counter++;  
  if(s[2] == '1') counter++;
  
  cout << counter << endl;
  
}

Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
 
int main() {
  
 int K, A,B;
 
 cin>>K>>A>>B;
 
 int rem= A%K;
 
 if(rem==0 || B>= (A+K-rem))
    cout<<"OK";
else
    cout<<"NG";
}

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

int main(){
	int h,w,K;

	cin>>h>>w>>K;

	int s[h][w];

	string s1;
	for(int i =0;i <h;i++){
		cin>>s1;
		for(int j = 0;j<w;j++)
			s[i][j] = s1[j] - '0';
	}

	int ans = h + w - 2;
	int mask = 1 << (h - 1);

	for(int i = 0; i < mask ; i++){
		int no_of_ones = __builtin_popcount(i);
		//cout<<"i: "<<i<<" ones: "<<no_of_ones<<endl;

		vector<int> cuts;
		for(int j =0; j < h -1; j++){
			if(i & (1 << j)){
				cuts.push_back(j);
			}
		}

		cuts.push_back(h-1);

		int count[cuts.size()][w];

		for(int k =0;k<cuts.size();k++)
			for(int l =0;l<w;l++)
				count[k][l] = 0;

		for(int k = 0; k < cuts.size(); k++){
			//cout<<"k : "<<k<<endl;
			int l;
			l = (k == 0) ?  0: cuts[k-1] + 1;
			for(;l <= cuts[k];l++){
				for(int m =0;m < w;m++){
					if(s[l][m])
						count[k][m]++;
				}
			}
		}

		// for(int k = 0;k<cuts.size();k++){
		// 	for(int l =0;l<w;l++)
		// 		cout<<count[k][l]<<" ";
		// 	cout<<endl;
		// }

		int sum_col[cuts.size()];
		for(int k =0;k<cuts.size();k++)
			sum_col[k] = 0;

		int vertical_cuts = 0;
		for(int k = 0;k < w;k++){
			for(int l = 0; l < cuts.size();l++){
				int x = sum_col[l] + count[l][k];

				if(x > K){
					//cout<<"Vertical cut at: "<<k<<endl;
					vertical_cuts++;
					for(int m =0;m < cuts.size();m++){
						if(count[m][k] > K)
						{
							vertical_cuts = -1;
							break;
						}
						else{
							sum_col[m] = count[m][k];
						}
					}
					break;
				}
				else{
					sum_col[l] = x;
				}

			}
		}
		//cout<<vertical_cuts<<endl;
		if(vertical_cuts != -1){
			ans = min(ans, no_of_ones + vertical_cuts);
		}
		//cout<<"========="<<endl;

	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
mtx_cnt, vec_cnt = gets.split.map(&:to_i)

  mtx, vec = [], []

  mtx_cnt.times do
    mtx << gets.split.map(&:to_i)
  end

  vec_cnt.times do
    vec << gets(chomp:true).to_i
  end

  mtx.each do | mtx_row |
    output = 0

    mtx_row.each_with_index do | mtx_num, idx |
      output += mtx_num * vec[idx]
    end

    puts output
  end


Measured memory_bytes: 8988
N, K = map(int, input().split())
x = list(map(int, input().split()))

# xiにいってからxi+(K-1)に行く
a = []
b = []
for i in range(N - K + 1):
    a.append(abs(x[i] - 0) + abs(x[i + K - 1] - x[i]))
    b.append(abs(x[i + K - 1] - 0) + abs(x[i] - x[i + K - 1]))

print(min(min(a), min(b)))

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

#define sqr(x) (x*x)

using namespace std;

const int MAXN=101;

int n,sum=0,ans=0,pos,val;

int main() {
	scanf("%d",&n);
	for(int i=1,x; i<=n; ++i) {
		scanf("%d",&x);
		sum+=x,ans+=x*x;
	}
	pos=sum/n;
	val=n*sqr(pos)-2*pos*sum;
	if(pos+1<=100) {
		++pos;
		val=min(val,n*sqr(pos)-2*pos*sum);
	}
	printf("%d\n",ans+val);
	return 0;
}

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

using namespace std;

#define endl '\n'

int main()
{
#ifdef jcg
	assert(freopen("input.in", "r", stdin));
	// assert(freopen("output.out", "w", stdout));
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<vector<int>> adj(n);

	for (int i = 1; i < n; ++i)
	{
		int u, v;
		cin >> u >> v;
		adj[--u].push_back(--v);
		adj[v].push_back(u);
	}

	function<int(int, int)> dfs = [&](int u, int p)
	{
		int used = 0, more = 0;

		for (int v : adj[u]) if (v != p)
		{
			int mask = dfs(v, u);
			more |= mask & used;
			used |= mask;
		}

		for (int k : {1, 2, 4, 8, 16}) more |= more >> k; ++more;

		int possible = (~used) & (-more);
		used |= possible & -possible;
		used &= -(possible & -possible);

		return used;
	};

	cout << __lg(dfs(0, 0)) << endl;

	return 0;
}

Measured memory_bytes: 12544
sc = list(map(int, input().split()))
w = sc[0]
h = sc[1]
x = sc[2]
y = sc[3]
r = sc[4]
if (0 <= x - r) and (x + r <= w) and (0 <= y - r) and (y + r <= h):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
struct Data{
	int hp, x, y, cost;
	Data(int _hp, int _x, int _y, int _cost){
		hp = _hp;
		x = _x;
		y = _y;
		cost = _cost;
	}
	Data(){}
};
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int w, h, n, sx, sy;
int gx[11], gy[11];
int memo[11][1001][1001];
string maze[1001];

int main(void){
	fill_n(**memo, 11*1001*1001, INF);
	cin >> h >> w >> n;
	rep(i, h){
		cin >> maze[i];
		rep(j, w){
			if(maze[i][j] == 'S'){
				sx = j;
				sy = i;
				break;
			}else if(maze[i][j] != 'X' && maze[i][j] !='.'){
				gx[maze[i][j]-'0'] = j;
				gy[maze[i][j]-'0'] = i;
			}
		}
	}
	queue<Data> que;
	que.push(Data(1, sx, sy, 0));
	while(!que.empty()){
		Data data = que.front();que.pop();
		int x = data.x;
		int y = data.y;
		int hp = data.hp;
		int cost = data.cost;
		if(maze[y][x]-'0' == hp)hp++;
		if(hp == n+1){
			FIN(cost);
			break;
		}
		if(memo[hp][y][x] <= cost)continue;
		memo[hp][y][x] = cost;
		rep(i, 4){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx < 0 || ny < 0 || nx >= w || ny >= h || maze[ny][nx] == 'X')continue;
			que.push(Data(hp, nx, ny, cost+1));
		}
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 45332
#include<stdio.h>
long long div[2000];
int inde;

void getDiv(long long n){
  inde = 0;
  long long i;
  for(i=1;i*i<=n;i++)
    if(n%i == 0)
	{
	  div[inde++] = i;
	  if(i*i != n)
	    div[inde++] = n/i;
	}
}

long long gcd(long long x,long long y)
{
  long long r;
  if(x < y)
    {
      long long tmp = x;
      x = y;
      y = tmp;
    }
  while(y > 0)
    {
      r = x%y;
      x = y;
      y = r;
    }
  return x;
}

int main()
{
  long long n;
  
  while(1)
    {
      scanf("%lld",&n);
      if(n == 0)
	break;
      long long cnt = 0;
      long long i,j;
      getDiv(n);
      for(i=0;i<inde;i++)
	{
	  for(j=i;j<inde;j++)
	    {
	      long long a,b;
	      a = div[i];
	      b = div[j];
	      if(a/gcd(a,b)*b == n)
		cnt++;
	    }
	}
      printf("%lld\n",cnt);
    }
  
  return 0;
}

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

int main(){
 	int H,A,N;
  	cin >> H >> N;
  	for(int i = 0 ; i < N ; i ++){
     	cin >> A;
      	H -= A;
    }
  	if(H <= 0) cout << "Yes" << endl; else cout << "No" << endl;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
total = 0

for i in range(1,n+1):
    l = []
    l = list(str(i))
    l_in = [int(j) for j in l]
#    print(l_in)
    if a <= sum(l_in) <= b:
        total += i

print(total)


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

using namespace std;

int main(){
    int min, mini, resp = 0;

    vector<int> v(5);

    for(int i = 0; i < 5; i++){
        cin >> v[i];
        if(i == 0){
            min = v[i]%10;
            mini = 0;
        }else if((v[i]%10 < min && v[i]%10 != 0 && min) || min == 0){
            //cout << i << " " << min << " " << v[i]%10 << endl;
            
            min = v[i]%10;
            mini = i;
        }
    }

    for(int i = 0; i < 5; i++){
        if(i != mini){
            if(v[i]%10 != 0)
                resp += v[i] + 10 - (v[i]%10);
            else resp += v[i];
        } 
        //cout << resp << endl;
    }

    resp += v[mini];

    cout << resp << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a;
  cin >> a;
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      if(i * j == a){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

list = {n,0,0,0,0,0}
i = a
for j in {b,c,d,e} :
  if i>j :
    i = j
print(5+-(-n//i)-1)

Measured memory_bytes: 3064