akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
 
 
 
int main(){
    string s;
    cin >> s;
 
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}  

Measured memory_bytes: 3588
from collections import defaultdict

N,W = map(int, input().split())
WV = []
for i in range(N):
    WV.append(list(map(int, input().split())))

dp = defaultdict(int)

dp[0] = 0

for w,v in WV:
    for nw, nv in list(dp.items()):
        if nw+w <= W:
            dp[nw+w] = max(dp[nw+w], nv+v)
            
print(max(dp.values()))

Measured memory_bytes: 3828
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 9
char K_N[MAXN+5];
long long N,S_N;
int main(){
	scanf("%s",&K_N);
	for(int i=0;i<strlen(K_N);i++){
		S_N+=K_N[i]-'0';
		N=N*10+K_N[i]-'0';
	}
	if(N%S_N==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s1[500],s2[500];
string reverse(string str)
{
	if(str.length()==0)
	  return "";
	long long i;
	string ans;
	for(i=str.length()-1;i>=0;--i)
	  ans+=str[i];
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	int ans=0;
	cin>>s1>>s2;
	int len1=strlen(s1);
	int len2=strlen(s2);
	if(len1!=len2)
	{
		cout<<"NO\n";
		return 0;
	}
	else
	if(reverse(s2)!=s1)
	{
		cout<<"NO\n";
		return 0;
	}
	else {cout<<"YES\n";return 0;}
	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: u32 = read(&mut stdin_lock, &mut buf, b' ');
    let m: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut mv = vec![(0u16, 0u32); m];
    for i in 0..m {
        let mut s = 0u16;
        let k: usize = read(&mut stdin_lock, &mut buf, b' ');
        for _ in 0..k - 1 {
            s |= 1u16 << (read::<u16>(&mut stdin_lock, &mut buf, b' ') - 1);
        }
        s |= 1u16 << (read::<u16>(&mut stdin_lock, &mut buf, b'\n') - 1);
        mv[i].0 = s;
    }
    for i in 0..m - 1 {
        mv[i].1 = read(&mut stdin_lock, &mut buf, b' ');
    }
    mv[m - 1].1 = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = 0;
    for i in 0..2u16.pow(n) {
        if mv.iter().all(|m| ((i & m.0).count_ones() % 2) == m.1) {
            ans += 1
        }
    }
    println!("{}", ans);
}


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

int N;
string S;
int main() {
  cin >> N >> S;
  int firstRight = N, lastLeft = -1;
  for (int i = 0; i < N; ++i) {
	if (S[i] == '>') firstRight = min(firstRight, i);
	else lastLeft = max(lastLeft, i);
  }
  int res = 0;
  if (firstRight < N) res = max(res, N - firstRight);
  if (lastLeft > -1) res = max(res, lastLeft + 1);
  cout << res << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<char> a = {'M','A','R','C','H'};
    vector<long long> b(5,0);
    for(int i = 0; i<n;i++){
        string s;
        cin >> s;
        char c = s.at(0);
        for(int j = 0; j <5; j++){
            if(c == a.at(j)){
                b.at(j) += 1;
            }
        }
    }
    long long sum = 0;
    for(int i = 0; i<5; i++){
        for(int j = i+1;j<5;j++){
            for(int k = j+1;k<5; k++){
                sum += b.at(i)*b.at(j)*b.at(k);
              
            }
        }
    }
    cout << sum <<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <utility>
#include <set>
#include <vector>

using namespace std;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

class Prime {
// n以下の素数を列挙する
public:
  const int n;
  vector<bool> is_prime;
  vector<int> primes;
  Prime(int size) : n(size), is_prime(n, true) {
    for (int i = 2; i <= n; ++i) {
      if (!is_prime[i]) continue;
      primes.push_back(i);
      int tmp = 2*i;
      while (tmp <= n) {
        is_prime[tmp] = false;
        tmp += i;
      }
    }
  }
};

int main() {
  Prime prime(55555);
  int n;
  cin >> n;
  int count = 0;
  for (int p : prime.primes) {
    if (count >= n) break;
    if (p%5 != 1) continue;
    cout << p << " ";
    count++;
  }
  cout << endl;
}


Measured memory_bytes: 256
def main():
    S = input()
    if S[0] == "B":
        K = "WB"
    else:
        K = "BW"
    cnt = S.count(K)

    if S[0] == S[-1]:
        print(2 * cnt)
    else:
        print(1 + 2 * cnt)


main()


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

int main() {
  int x;
  cin >> x;
  int day = x % 7;
  // 2の時金曜
  if (day == 0) {
    cout << "thu" << endl;
  } else if (day == 1) {
    cout << "fri" << endl;
  } else if (day == 2) {
    cout << "sat" << endl;
  } else if (day == 3) {
    cout << "sun" << endl;
  } else if (day == 4) {
    cout << "mon" << endl;
  } else if (day == 5) {
    cout << "tue" << endl;
  } else if (day == 6) {
    cout << "wed" << endl;
  }
  return 0;
}



Measured memory_bytes: 3124
n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
    dum1 = s[n-i-1:n]
    dum2 = t[0:i+1]
    if dum1 == dum2:
        ans = n*2-((i+1))
if ans == 0:
    ans = n*2
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
int main()
{
    constexpr int V = 100000;
    int N, W;
    std::cin >> N >> W;
    std::vector<ll> dp(V + 1, W + 1);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        int w, v;
        std::cin >> w >> v;
        for (int j = V - v; j >= 0; j--) { dp[j + v] = std::min(dp[j + v], dp[j] + w); }
    }
    for (int v = V; v >= 0; v--) {
        if (dp[v] <= W) { return std::cout << v << std::endl, 0; }
    }
    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<string.h>

int main()
{


int i;
char moji[10];

scanf("%s",moji);


 moji[0]='2';
  
 moji[1]='0';

 moji[2]='1';
 
 moji[3]='8';
 
printf("%s",moji);

}

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

int main(){
  int N ; cin >> N ; 
  vector<P> p(N) ; 
  
  rep(i,N) cin >> p[i].second >> p[i].first ; 
  sort(p.begin(),p.end()) ; 
  
  int T = 0 ; 
  rep(i,N){
    T += p.at(i).second ; 
    if( T > p.at(i).first) {
     cout << "No" << endl ;
     return 0 ; 
    }
  }
  
  cout << "Yes" << endl ; 
  
  
  return 0 ;  
}

Measured memory_bytes: 4844
#include <cstdio>
#include <algorithm>

int main()
{
  int n;
  scanf("%d", &n);
  int v[50];
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", v + i);
  }
  std::sort(v, v + n);
  double ans = (*v + *(v + 1)) / (double)2;
  for (int i = 2; i < n; ++i)
  {
    ans = (ans + (double)v[i]) / 2;
  }
  printf("%f\n", ans);
  return 0;
}

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



int main(){
  vector<int>vec(3);
  for (int i = 0; i < 3 ; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  cout << vec.at(2) - vec.at(0);
}
      
        
    
    

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}

import Data.Array.IO
import Data.Array
import Control.Monad
import Control.Applicative

bfs :: IOUArray (Int, Int) Char -> IOUArray (Int, Int) Int -> (Int, Int) -> [(Int, Int)] -> IO Int
bfs grid distance goal [] = return (-1)
bfs grid distance goal (p@(y,x):queue) = do
  ((miny,minx),(maxy,maxx)) <- getBounds grid
  d <- readArray distance p
  if p == goal then
    return d
  else do
    next <- filterM (\(ny,nx) ->
              if (ny < miny || nx < minx || ny > maxy || nx > maxx) then
                return False
              else do
                ng <- readArray grid (ny,nx)
                nd <- readArray distance (ny,nx)
                return (nd == -1 && ng /= '#')
            ) [(y+1,x),(y-1,x),(y,x+1),(y,x-1)]
    forM_ next $ \n -> writeArray distance n (d+1)
    bfs grid distance goal (queue ++ next)

main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  strs <- replicateM h getLine :: IO [String]
  (grid :: IOUArray (Int, Int) Char) <- thaw $ listArray ((1,1),(h,w)) $ concat strs
  (distance :: IOUArray (Int, Int) Int) <- newArray ((1,1),(h,w)) (-1)
  (grid' :: Array (Int, Int) Char) <- freeze grid
  let white = (h*w) - 2 - (length [() | (_,e) <- assocs grid', e == '#'])
  writeArray distance (1,1) 0
  b <- bfs grid distance (h,w) [(1,1)]
  print $ if b == -1 then b else white - (b-1)

Measured memory_bytes: 1148
# -*- coding: utf-8 -*-
from collections import defaultdict
n, m = map(int, input().split())
a = list(map(int, input().split()))

cards = defaultdict(int)
for num in a:
    cards[num] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cards[c] += b

count = n
ans = 0
for key, val in sorted(cards.items(), key=lambda x: -x[0]):
    if count - val < 0:
        ans += key * count
        break
    else:
        ans += key * val
        count -= val
print(ans)

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N, X, T;

    cin >> N >> X >> T;

    cout << ((N + X - 1)/X)*T << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll r,g,b,n; cin>>r>>g>>b>>n;
  ll ans = 0;
  for (int i=0; i*r<=n; i++) {
    for (int j=0; i*r+j*g<=n; j++) {
      if ((n - i*r - j*g) % b == 0) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3540
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for i in range(N):
	tmp = V[i] - C[i]
	if tmp > 0:
		ans += tmp

print(ans)

Measured memory_bytes: 38256
#include <stdio.h>

int max(int a,int b){
	if(a>b) return a;
	else return b;
}

int main(void) {
	int N; scanf("%d",&N);
	int a[N+1]; for(int i=1;i<=N;i++) scanf("%d",&a[i]);
	int m[N+1]; for(int i=0;i<=N;i++) m[i] = 0;
	
	for(int i=1;i<=N;i++) m[i] = max(a[i],m[i-1]);
	
	int count = 0;
	
	for(int i=1;i<=N;i++) if(m[i]>=a[i]+2) count++;
	
	if(count>0) printf("No\n");
	else printf("Yes\n");
	
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
  int main(){
      int N;
      int A;
      int B;
     cin >> N >> A >> B;
     if( N == 1){
         cout << "Hello World" << endl;
     }
     else if(N == 2){
        cout <<  A + B << endl;
    }
  }

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final int[] days = {0,31,28,31,30,31,30,31,31,30,31,30,31};

    public static boolean isUruu(int y) {
	return (y%4 == 0 && y%100 != 0) || y%400 == 0;
    }

    public static int getDays(int y,int m,int d) {
	int res = 0;
	for(int i = 1; i <= y-1; ++i) {
	    if(isUruu(i)) res += 366;
	    else     res += 365;
	}
	for(int i = 1; i <= m-1; ++i) {
	    res += days[i];
	    if(i == 2 && isUruu(y)) ++res;
	}
	res += d;
	return res;
    }

    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	while(true) {
	    int d[][] = new int[2][3];
	    boolean flag = false;
	    for(int i = 0; i < 2; ++i) {
		for(int j = 0; j < 3; ++j) {
		    d[i][j] = s.nextInt();
		    if(d[i][j] < 0) flag = true;
		}
	    }
	    if(flag) break;
	    System.out.println(Math.abs(getDays(d[1][0],d[1][1],d[1][2])-getDays(d[0][0],d[0][1],d[0][2])));
	}
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); //number 
#define ll long long                      //of element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after 
using namespace std;                      // sort use as s.f();
using namespace __gnu_pbds;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll t=1;
//	cin>>t;
	while(t--)
	{
	string s;
	cin>>s;
	bool ans=false;
	if(s[2]==s[3] && s[4]==s[5])
	{
		ans=true;
		}
	
	if(ans)
		{cout<<"Yes"<<endl;
			}
			else
			{
				cout<<"No"<<endl;
				}
	}
	
return 0;
}


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

int main() {
	// your code goes here
	ll n;
	cin >> n;
	vector<ll> v;
	for(int i=0;i<n+1;i++)
	    v.push_back(1);
	for(int i=2;i<n+1;i++){
	    for(int j=1;j*i<n+1;j++){
	        v[j*i]++;
	    }
	}
	ll ans=0;
	for(int i=1;i<n+1;i++){
	    ans+= i*v[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 134448
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 1000005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db double
#define noop
#define flu fflush(stdout)
#define imp {cout<<"NO\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}

ll power(ll x, ll n, ll d) {
    ll val = (x%d), res = 1;
    while(n>0) {
        if(n&1)
            res = (res*val)%d;
        val = (val*val)%d;
        n = n>>1;
    }
    return (res+d)%d;
}

vector<ll> prs(Nmax,0);

void prime_factors(ll num) {
    ll c = 0;
    while((num%2)==0) {
        c++;
        num/=2;
    }
    prs[2] = max(prs[2], c);

    for(ll i=3;i<=sqrt(num);i+=2) {
        ll c = 0;
        while((num%i)==0) {
            c++;
            num/=i;
        }
        prs[i] = max(prs[i], c);
    }

    if(num>1) {
        prs[num] = max(prs[num],(ll)1);
    }
}


int main() {

    get(n);
    fill_nums(A,n);

    ll sum = 0;
    rep(i,n) {
        // sum += A[i];
        prime_factors(A[i]);
    }
    // sum %= N;
    // ll save = power(sum, N-2, N);
    // debug_vec(prs, 10);
    ll pro = 1;

    rep2(i,1,Nmax) {
        if(prs[i])
            pro = pro*power(i,prs[i],N)%N;
    }

    rep(i,n) {
        ll a = power(A[i], N-2, N);
        sum = (sum + pro*a%N)%N;
    }
    printf("%lld\n", sum);

    return 0;  
}

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

int main (){
int n;
  cin >> n;
  
 int i;
  int c=0;
  int p[n];
  for(i=0;i<n;i++){
    cin>>p[i];
  }
  for(i=1;i<n-1;i++){
    if(p[i]<p[i+1]&&p[i]>p[i-1]||p[i]<p[i-1]&&p[i]>p[i+1])
      c++;
  }
  cout<<c;
  return 0;
}
    


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long A, long long B, long long C, long long D, long long E, long long F){
    double deg = 0;
    lli ansW=100*A,ansS=0;
    for(lli a=0;100*a*A <= F;a++){
    for(lli b=0;100*(a*A+b*B)<=F;b++){
    for(lli c=0; (100*(a*A+b*B)+c*C <= F && c*C <= E*(a*A+b*B));c++){
    for(lli d=0; (100*(a*A+b*B)+c*C+d*D<=F && (c*C+d*D)<=E*(a*A+b*B)) ;d++){
        lli suger = c*C+d*D;
        lli water = 100*(a*A+b*B) + suger;
        if(suger==0)continue;
        if(water==0)continue;
        if(deg<(100*suger)/(double)(water)){
            deg = (100*suger)/(double)(water);
            ansW = water;
            ansS = suger;
        }
    }
    }
    }
    }
    cout<<ansW<<" "<<ansS<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    long long E;
    scanf("%lld",&E);
    long long F;
    scanf("%lld",&F);
    func(A, B, C, D, E, F);
    return 0;
}


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

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]) {

	bool all_visited = true;

	for (int i = 0; i < N; i++) {
		if (visited[i] == false) all_visited = false;
	}

	if (all_visited) {
		return 1;
	}

	int ret = 0;

	for (int i = 0; i < N; i++) {
		if (graph[v][i] == false)continue;
		if (visited[i])continue;

		visited[i] = true;
		ret += dfs(i, N, visited);
		visited[i] = false;
	}
	return ret;
}


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

	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
	}

	bool visited[nmax];
	for (int i = 0; i < N; i++) {
		visited[i] = false;
	}

	visited[0] = true;
	cout << dfs(0, N, visited) << endl;
	return 0;
}

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

int main() {
  int m = 0, f = 0, r = 0;
  while (true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;
    string result = "F";
    int mf = m + f;
    if (m == -1 || f == -1) result = "F";
    else if (mf >= 80) result = "A";
    else if (mf >= 65) result = "B"; 
    else if (mf >= 50) result = "C"; 
    else if (mf >= 30) {
      if (r >= 50) result = "C"; 
      else result = "D";
    }
    cout << result << endl;
  }

  return 0;
}


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

int main(){
    string s ,t ;
    cin >> s >> t ;
    ll max = s.size()-t.size() + 1 ;
    ll ans = s.size()+ 1000  ;
    rep(i,max) {
        string u = s.substr(i,t.size()) ;
        ll count = 0 ;
        rep(j,t.size()){
            if(u[j] != t[j])count++; 
        }
        ans = min(count,ans) ;
    }
    cout << ans << endl ;

}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  string s;cin>>s;
  int yyyy=(s[0]-48)*1000+(s[1]-48)*100+(s[2]-48)*10+(s[3]-48);
  int mm=(s[5]-48)*10+(s[6]-48);
  int dd=(s[8]-48)*10+(s[9]-48);
  if (yyyy>=2019){
	  if (mm>=5){
		cout<<"TBD"<<endl;
		return 0;
	  }
  }
	cout<<"Heisei"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n, ans = 0;
void solve(long num, bool s, bool t, bool r) {
    if (num > n) return;
    if (s && t && r) ans++;
    solve(num * 10 + 7, true, t, r);
    solve(num * 10 + 5, s, true, r);
    solve(num * 10 + 3, s, t, true);
}
int main() {
    cin >> n;
    solve(0, false, false, false);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  cout << 180 * (n - 2) << '\n';
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
const int N=16,M=N*N;
const int Mod=1000000007;
int G[N],Pow[M],f[1<<N],cnt[1<<N];
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
int main() {
    int n=read(),m=read(),lim=1<<n; Pow[0]=f[0]=1;
    for (int i=1;i<=m;i++) Pow[i]=(Pow[i-1]<<1)%Mod;
    for (int i=0;i<lim;i++) cnt[i]=cnt[i>>1]+(i&1);
    for (int i=1;i<=m;i++) {int x=read(),y=read();G[x-1]|=1<<(y-1);}
    for (int sta=0;sta<lim;sta++) if ((sta&1)==(sta>>1&1))
        for (int T=sta;T;T=sta&(T-1)) if ((T&1)==(T>>1&1)) {
            int res=1,U=sta^T;
            for (int i=0;i<n;i++) if (sta>>i&1) {
                res=1LL*res*(T>>i&1?1<<cnt[G[i]&U]:(1<<cnt[G[i]&T])-1)%Mod;
            }
            (f[sta]+=1LL*f[U]*res%Mod)%=Mod;
        }
    printf("%d\n",(Pow[m]-f[lim-1]+Mod)%Mod);
    return 0;
}

Measured memory_bytes: 3928
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
#include<list>

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define MAX_V 1000

using namespace std;

typedef complex<double> P;

const int dim = 2;
double dot(P x,P y){return real(conj(x)*y);}

struct min_ball {
  P center;
  double radius2;
  void add(const P& p) {
    ps.push_back(p);
  }
  void compile() {
    m = 0;
    center = P(0,0);
    radius2 = -1;
    make_ball(ps.end());
  }

  list<P> ps;
  list<P>::iterator supp_end;
  int m;
  P v[dim+1], c[dim+1];
  double z[dim+1], r[dim+1];
  void pop() { --m; }
  void push(const P& p) {
    if (m == 0) {
      c[0] = p; r[0] = 0;
    } else {
      double e = dot(p-c[m-1],p-c[m-1]) - r[m-1];
      P delta = p - c[0];
      v[m] = p - c[0];
      for (int i = 1; i < m; ++i)
        v[m] -= v[i] * dot(v[i], delta) / z[i];
      z[m] = dot(v[m], v[m]);
      c[m] = c[m-1] + e*v[m]*(1.0/z[m]/2.0);
      r[m] = r[m-1] + e*e/z[m]/4.0;
    }
    center  = c[m];
    radius2 = r[m]; ++m;
  }
  void make_ball(list<P>::iterator i) {
    supp_end = ps.begin();
    if (m == dim + 1) return;
    for (list<P>::iterator k = ps.begin(); k != i; ) {
      list<P>::iterator j = k++;
      if (dot(*j-center,*j-center) > radius2) {
        push(*j); make_ball(j); pop();
        move_to_front(j);
      }
    }
  }
  void move_to_front(list<P>::iterator j) {
    if (supp_end == j) ++supp_end;
    ps.splice (ps.begin(), ps, j);
  }
};

int n,m,p;
int r[110];
double d[110];
int use1[110],use2[110];
P ver;

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> r[i];
    r[i] = r[i]*r[i];
  }

  for(int i=0;i<m;i++){
    cin >> p;
    min_ball ball;
    for(int j=0;j<p;j++){
      cin >> ver.real() >> ver.imag();    
      ball.add(ver);
    }
    ball.compile();
    d[i] = ball.radius2;
  }

  for(int i=0;i<n;i++)use1[i] = false;

  for(int i=0;i<m;i++){
    int j;
    for(j=0;j<n;j++){
      if(!use1[j] && d[i] < r[j]+EPS){
	use1[j] = true;
	bool f = true;
	for(int k=0;k<n;k++)use2[k] = use1[k];
	for(int k=i+1;k<m;k++){
	  int id = -1;
	  for(int l=0;l<n;l++){
	    if(!use2[l] && d[k] < r[l]+EPS)
	      if( id<0 || r[l] < r[id] )id = l;
	  }
	  if(id<0){
	    f = false;
	    break;
	  }else use2[id] = true;
	}
	if(f){
	  cout << j+1 << endl;
	  break;
	}else use1[j] = false;
      }
    }
    if(j==n){
      cout << "NG\n";
      return 0;
    }
  }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int x;
int main(){
    scanf("%d",&x);
    int l=0,r=100000;
    int mid,ans;
    while(l<=r){
        mid=l+r>>1;
        if(1ll*mid*(mid+1)/2>=x)ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d\n",ans);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x.at(i);
  }
  int  ans = 0;
  for (int p = 1; p < 101; p++) {
    int total= 0;
    for (int i = 0; i < N; i++) {
        total += (p-x.at(i)) * (p-x.at(i));
    }
    if (p == 1) {
      ans = total;
    }
    else if (total < ans) {
      ans = total;
    }
  }
  cout << ans <<endl;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*{
}*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
//constexpr int inf = 1LL<<60;

signed main() {
  int n;
  string S;
  cin >> n >> S;

  vi s;
  for(char c : S){
    s.emplace_back(c == 'x');
  }

  rep(i, 0, 2) rep(j, 0, 2){
    // 1 = W, 0 = S
    /*
    o S same 0 0
    x S diff 1 0
    o W diff 0 1
    x W same 1 1
    */
    vi t;
    t.emplace_back(i);
    t.emplace_back(j);

    rep(k, 1, n-1){
      t.emplace_back((t[k-1]+s[k]+t[k])%2);
    }

    if((t[n-2]+s[n-1]+t[n-1])%2 != t[0]) continue;
    if((t[n-1]+s[0]+t[0])%2 != t[1]) continue;

    for(int k : t){
      cout << (k ? 'W' : 'S');
    }
    cout << endl;
    return 0;
  }

  cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 3152
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	ll sol = INT_MIN;
	for(int ii=0;ii<=1;ii++){
		if(ii)
			sort(arr.begin(),arr.end());
		else
			sort(arr.rbegin(),arr.rend());
		int l=0,r=n-1, li = (n-1)/2,ri=(n-1)/2;
		vi ans(n);
		ans[li] = arr[l++];
		li--;ri++;
		while(ri!=n) {
			ans[ri++]=arr[r--];
			if(li!=-1)ans[li--]=arr[r--];
			if(ri!=n) ans[ri++]=arr[l++];
			if(li!=-1)ans[li--]=arr[l++];
		}
		ll sum = 0;
		for(int i=1;i<n;i++)sum+=abs(ans[i]-ans[i-1]);
		sol=max(sum,sol);
	}
	cout<<sol;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 4032
'use strict';

function Main(input) {
    const tmp = input.split("\n");
    const A = tmp[0];
    const B = tmp[1];
    const C = tmp[2];
    const X = tmp[3];
    let cnt = 0;

    for (let a = 0; a <= A; a++) {
        for (let b = 0; b <= B; b++) {
            for (let c = 0; c <= C; c++) {
                let total = a * 500 + b * 100 + c * 50;
                if (total == X) {
                    cnt++;
                }
            }
        }
    }
    console.log(cnt);
}
//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++){
    if(i % 3 == 0){
      cout << " " << i;
      continue;
    }
    if(i % 10 == 3){
      cout << " " << i;
      continue;
    }
    int x = i;
    while(x > 3){
      x = x / 10;
      if(x % 10 == 3){
        cout << " " << i;
        break;
      }
    }  
  }
  cout << endl;
}



Measured memory_bytes: 3084
l = [int(x) for x in input().split()]
A, B, C, D = l[0], l[1], l[2], l[3]

takahashi = C//B
if C%B > 0:
    takahashi+=1
    
aoki = A//D
if A%D>0:
    aoki+=1


if aoki >= takahashi:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9188
/*
 * ID: ALDS1_1_C 
 * Problem: prime number
 */

#include <stdio.h>
#include <math.h>

int isprime(int x)
{
        if (x == 2)
            return 1; // ture

        if (x % 2 == 0)
            return 0; // false

        int i;
        for (i = 3; i <= sqrt(x); i += 2)
            if (x % i == 0)
                return 0;
        return 1;
}

int main(void)
{
    int i, n, count = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if (isprime(x)) {
            count++;
        }
    }
    printf("%d\n", count);

    return 0;
}




Measured memory_bytes: 2104
#include <stdio.h>

int main(void) {
    int w, h;
    int x, y, r;

    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

    if(x - r >= 0 && x + r <= w &&
       y - r >= 0 && y + r <= h)
       printf("Yes\n");
    else
       printf("No\n");
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

	ll n, sum=0;
	unordered_map<ll, ll> m;
	cin >> n;
	vector<ll> v(n);
	for(ll i=0; i<n; i++){
        cin >> v[i];
        sum+=v[i];
        m[v[i]]++;
	}

	ll q;
	cin >> q;
	while(q--){
        ll b, c;
        cin >> b >> c;
        sum-=(m[b]*b);
        sum+=(m[b]*c);
        m[c]+=m[b];
        m.erase(b);
        cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 7428
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define print(v); for(auto x:v) cout<<x<<" "; cout<<endl;
typedef long long int ll;
int main()
{
    fast;
    ll s, w;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

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

	bool jdg = true;
	for (int i = 1; i < S.size(); i++) {
		if (S[i - 1] == S[i]) {
			jdg = false;
			break;
		}
	}

	if (jdg == true) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from sys import stdin
from math import gcd
input = stdin.readline

N = int(input())

ans = 0

for i in range(1, N + 1):
    for j in range(1, N + 1):
        tmp = gcd(i, j)
        for k in range(1, N + 1):
            ans += gcd(tmp, k)

print(ans)


Measured memory_bytes: 68404
import heapq

N = int(input())
A = list(map(int, input().split()))

left = A[:N]
lefty = sum(left)
right = [-A[i] for i in range(3*N-1, 2*N-1, -1)]
righty = sum(right)
left_list = [lefty]
right_list = [righty]

heapq.heapify(left)
heapq.heapify(right)


for i in range(N, 2*N):
    heapq.heappush(left, A[i])
    x = heapq.heappop(left)
    lefty += A[i] - x
    left_list.append(lefty)

for i in range(2*N-1, N-1, -1):
    heapq.heappush(right, -A[i])
    y = heapq.heappop(right)
    righty += -A[i] - y
    right_list.append(righty)

ans = - float('inf')
for i in range(len(left_list)):
    ans = max(ans, left_list[i]+right_list[len(right_list)-1-i])

print(ans)

Measured memory_bytes: 37212
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
void _main(int tc) {
  int a, b, c;
  
  cin >> a >> b >> c;

  if (a + b == c or a + c == b or b + c == a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 256
#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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int K,S,ans=0;
        cin >> K>>S;
        rep(i, K+1)
        {
                rep(j,K+1){
                        int w = S - i - j;
                        if (0<=w && w<=K)
                        {
                                ans++;
                                
                        }
                }
                
        }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
import sys
import math
import collections
from collections import deque
#n = int(input())
#n, s = map(int, sys.stdin.readline().split())
s = input()
#a = list(map(int, sys.stdin.readline().split()))

if s[2] == s[3]:
    if s[4] == s[5]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
    





Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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

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

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> next;
    ll a, b;
    map<ll, ll> rensou;
    bool flag = false;
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        if (a == 1)
        {
            next.push_back(b);
        }
        if (b == n)
        {
            rensou[a]++;
        }
    }
    for (auto f : next)
    {
        if (rensou[f])
        {
            flag = true;
        }
    }
    if (flag)
    {
        cout << "POSSIBLE" << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 13556
#include<stdio.h>
int main(){
  
  int h,w;
  int i,j;
  
  
  while(1){
    scanf("%d %d",&h,&w);
    
    if(h < 2 && w < 2){
      break;
    }
    
    for(i = 1;i <= h;i++){
      for(j = 1;j <= w;j++){
	if(i == 1 || i == h){
	  printf("#");
	}
	else if(j == 1 || j == w){
	  printf("#");
	}
	else if(j != 1 && j != w){
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return(0);
}



Measured memory_bytes: 2008
#include<iostream>
using namespace std;
int main(){

	int m=0, f=0, r=0,sum=0;
	do{
		m = 0;
		f = 0;
		r = 0;
		sum = 0;
		cin >> m >> f >> r;
		sum = m + f;
		if (m == -1 | f == -1 && m + f + r > -3)cout << "F" << endl;
		else if (sum < 30&&sum>=0) cout << "F" << endl;
		else if (sum < 50 && sum >= 30) {
			if (r >= 50){ cout << "C" << endl; }
			else cout << "D" << endl;
		}
		 else if (sum < 65 && sum >= 50)cout << "C" << endl;
		 else	if (sum < 80 && sum >= 65)cout << "B" << endl;
		 else if (sum >= 80) cout << "A" << endl;
	} while (m + f + r != -3);
	}


Measured memory_bytes: 3092
def main(N, K):
    #初期化
    res = 1
    for i in range(N):
        #N回操作を行う
        res = greedy(res, K)
    return res

def greedy(val, K):
    #局所最適解として2つの操作結果の小さい方を返す
    valA = val * 2
    valB = val + K
    return min(valA, valB)

N = int(input())
K = int(input())
print(main(N, K))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
 
int main(void){
  string S;
  int Q;
  cin >> S >> Q;
  int muki = 1;
  string before;
  for(int i = 0; i < Q; i++){
    int T, F;
    char C;
    cin >> T;
    if(T == 1){
      muki *= -1;      
    }
    else{
      cin >> F >> C;
      if(muki == 1){
        if(F == 1) before = before + C;
      	else S = S + C;
      }
      else {
        if(F == 1) S = S + C;
      	else before = before + C;
      }
    }
  }
  reverse(before.begin(), before.end());
  S = before + S;
  if(muki == -1) reverse(S.begin(), S.end());
  cout << S;
  return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, W):
    ans = sys.maxsize
    for i in range(len(W)):
        ans = min(ans, abs(sum(W[:i]) - sum(W[i:])))
    return ans


def main():
    N = read_int()
    W = read_int_n()
    print(slv(N, W))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7740
#include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

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

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};

const D EPS = 1e-8;

int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}

// 比較関数
namespace std {
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
  bool operator==(P a, P b) {return norm(a - b) < EPS;}
}

// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 線分abに対する点cの位置
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(P a, P b, P c) {
  int s = sig(det(b - a, c - a));
  if (s) return s > 0 ? LEFT : RIGHT;
  if (a == c || b == c) return ON;
  return (a < b) == (b < c) ? FRONT : (c < a) == (a < b) ? BACK : ON;
}

// 交差判定
bool iSSs(L a, L b) {
  int cwa = ccw(a.a, a.b, b.a) | ccw(a.a, a.b, b.b);
  int cwb = ccw(b.a, b.b, a.a) | ccw(b.a, b.b, a.b);
  return (cwa & cwb) == (LEFT | RIGHT);
}

int main() {
  int na, nb;
  cin >> na >> nb;
  P a[na], b[nb];
  rep (i, na) cin >> a[i].X >> a[i].Y;
  rep (i, nb) cin >> b[i].X >> b[i].Y;
  D disa[na], disb[nb];
  rep (i, na) disa[i] = 1e100;
  rep (i, nb) disb[i] = 1e100;
  priority_queue<pair<D, int>, vector<pair<D, int> >, greater<pair<D, int> > > que;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    pair<D, int> now = que.top();
    que.pop();
    if (disa[now.second] <= now.first) continue;
    disa[now.second] = now.first;
    rep (i, na) if (now.second != i && !iSSs((L){a[now.second], a[i]}, (L){b[0], b[1]})) {
      que.push(make_pair(now.first + abs(a[now.second] - a[i]), i));
    }
  }
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    pair<D, int> now = que.top();
    que.pop();
    if (disb[now.second] <= now.first) continue;
    disb[now.second] = now.first;
    rep (i, nb) if (now.second != i && !iSSs((L){b[now.second], b[i]}, (L){a[0], a[1]})) {
      que.push(make_pair(now.first + abs(b[now.second] - b[i]), i));
    }
  }
  D ans = min(disa[1] + abs(b[0] - b[1]), disb[1] + abs(a[0] - a[1]));
  if (ans > 1e90) {
    cout << -1 << endl;
    return 0;
  }
  printf("%.12Lf\n", ans);
  return 0;
}

Measured memory_bytes: 35812
n = int(input())
v = list(map(int,input().split(" ")))

v.sort()
# print(v)
w = []

w0 = (v[0] + v[1])/2
w.append(w0)

for i in range(1,n-1):
    y = (v[i+1] + w[i-1])/2
    w.append(y)
    # print(w)
# print(w)
print(w[n-2])

Measured memory_bytes: 3064
import itertools

def input_data():
    n = int(input())
    a = []
    tmp_list = []
    lst = []
    for i in range(n):
        tmp_list = []
        tmp_a = int(input())
        a.append(tmp_a)
        for j in range(tmp_a):
            x,y = map(int,input().split())
            tmp_list.append([x-1,y])
        lst.append(tmp_list)
    return n,a,lst

def comb(x):
    return list(itertools.combinations(range(n),x))

def check(honests):
    flag = True
    check_list = [0]*n
    for i in honests:
        check_list[i] = 1
    for i in honests:
        for e in lst[i]:
            if (check_list[e[0]] != e[1]):
                flag = False
                break
        if not flag:
            break
    return flag    
  
def main():
    for i in reversed(range(n+1)):
        for honests in comb(i):
            if check(honests):
                return i

n,a,lst = input_data()
print(main())

Measured memory_bytes: 4852
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  vector<int> n;
  int k;
  for(int i=0; i<10; i++){
    cin >> k;
    n.push_back(k);
  }
  sort(n.begin(), n.end());
  cout << n[9] << "\n" << n[8] << "\n" << n[7] << endl;
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<char,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


int main(){
    vector<int> a(5);
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    int k;cin >> k;
    sort(ALL(a));
    if(a[4]-a[0]<=k) puts("Yay!");
    else puts(":(");
    return 0;
}


Measured memory_bytes: 256
import math

a, b = list(map(int, input().split()))
n = b * 10
flag = False
while n <= 1009:
    if math.floor(n * 0.1) == b and math.floor(n * 0.08) == a:
        flag = True
        break
    n += 1
print(n) if flag is True else print(-1)


Measured memory_bytes: 9116
#
import sys
import math
import numpy as np
import itertools
# ひとつ入力
n = int(input())
# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())

if n % 2 ==1:
    print("No")
    exit()

for i in range(n//2):
    if s[i] != s[i+n//2]:
        print("No")
        exit()

print("Yes")




Measured memory_bytes: 12480
#include<stdio.h>
int main(void){
  int k,l;
  double x[3][3],y[3][3];
    /* ??????[ ]???1???????????¢??¨2???????????¢????????????????????????
       ??????[ ]???1??????????????§?¨????2??????????????§?¨???§?????????*/
  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[1][1],&y[1][1],&x[1][2],&y[1\
][2],&x[2][1],&y[2][1],&x[2][2],&y[2][2])!=EOF){

    if((x[1][2]>=x[2][1] && x[2][2]>=x[1][1] && y[2][2]>=y[1][1] && y[1][2]>=y[\
2][1]) || (x[2][2]>=x[1][1] && x[1][2]>=x[2][1] && y[2][2]>=y[1][1] && y[1][2]>\
=y[2][1])){
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

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

int main() {
  
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  
  C *= 2; int64_t sum = 5000 * 2 * pow(10, 5) + 1;
  
  for (int i = 0; i <= max(X, Y); i++) {
    
    int numA = max(0, X - i); int numB = max(0, Y - i);
    
    int64_t tmp = A * numA + B * numB + C * i;
    
    sum = min(sum, tmp);
    
  }
  
  cout << sum << endl;
  
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;
    vector<int> w(40,0);
    vector<int> s(4000,0);
    w[0]=1;
    s[0]=1;
    FOR(i,A,40)w[i]|=w[i-A];
    FOR(i,B,40)w[i]|=w[i-B];
    FOR(i,C,4000)s[i]|=s[i-C];
    FOR(i,D,4000)s[i]|=s[i-D];
    int a=A,b=0;
    FOR(aa,1,40)REP(bb,4000)if(w[aa]&&s[bb]){
        if(bb>E*aa)continue;
        if(aa*100+bb>F)continue;
        if((a*100+b)*bb>(aa*100+bb)*b){
            a=aa;
            b=bb;
        }
    }
    cout<<a*100+b<<" "<<b<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	char a,b;
	cin>>a>>b;
	if(a=='H')	cout<<b<<endl;
	if(a=='D'&&b=='H')	cout<<"D"<<endl;
	if(a=='D'&&b=='D')	cout<<"H"<<endl;
	return 0;
}

Measured memory_bytes: 256