akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

typedef pair<int, int> P;
vector<pair<int,int> > G1[100001];
vector<int> dist1(1e5+1,1e18);

void dijkstra1(int s){
  bool f=true;
  priority_queue<P,vector<P>,greater<P> > que;
  dist1[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    int d=p.first;
    if(dist1[v]<d)continue;
    for(int i=0;i<G1[v].size();i++){
      int d2=d+G1[v][i].second;
      if(dist1[G1[v][i].first]>d2){
        dist1[G1[v][i].first]=d2;
        que.push(P(dist1[G1[v][i].first],G1[v][i].first));
      }
    }
  }
}

signed main(){
  int k;
  cin>>k;
  for(int i=1;i<k;i++){
    G1[i].push_back(P((i+1)%k,1));
    G1[i].push_back(P((i*10)%k,0));
  }
  dijkstra1(1);
  cout<<dist1[0]+1<<endl;
}


Measured memory_bytes: 9336
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int N;
string S;
using ull = unsigned long long;
ull csum[5010];
ull pow3[5010];

bool can(int i, int j, int x) {
  if (j + x >= S.size()) {
    return false;
  }

  if (i + x >= j) {
    return false;
  }

  ull h1 = csum[i + x + 1] - csum[i];
  ull h2 = csum[j + x + 1] - csum[j];
  return h1 * pow3[j - i] == h2;
}

bool can2(int x) {
  rep(i, 0, N) {
    rep(j, i + 1, N) {
      if (S[i] != S[j]) continue;

      if (can(i, j, x)) {
        return true;
      }
    }
  }
  return false;
}

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

  pow3[0] = 1;
  rep(i, 1, 5010) { pow3[i] = pow3[i - 1] * MOD; }

  rep(i, 0, N) { csum[i + 1] = csum[i] + S[i] * pow3[i]; }

  int ans = 0;
  int low = 0;
  int high = S.size();
  while (high - low > 1) {
    int mid = (low + high) / 2;
    if (can2(mid)) {
      low = mid;
      chmax(ans, low + 1);
    } else {
      high = mid;
    }
  }

  cout << ans;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main(){
    int n,k;
    cin >> n >> k;
    ll ans=inf;
    vector<int>ps;
    vector<int>ms;
    rep(i,n){
        int a;
        cin >> a;
        if(a>=0) ps.push_back(a);
        else ms.push_back(-a);
    }
    sort(all(ms));
    int ps_len=ps.size();
    int ms_len=ms.size();
    for(int a=0;a<=k;a++){
        ll mn;
        if(a==0){
            if(k>ms_len)continue;
            mn=ms[k-1];
        }
        else if(a==k){
            if(k>ps_len)continue;
            mn=ps[k-1];
        }
        else{
            if(ps_len<a)continue;
            if(ms_len<k-a)continue;
            mn=min(ps[a-1]*2+ms[k-a-1],ps[a-1]+ms[k-a-1]*2);
        }
        ans=min(ans,mn);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1020
N, K = list(map(int, input().split()))
S = input()

convert_dict = {'A': 'a', 'B': 'b', 'C': 'c'}

ans = ''
for i, s in enumerate(S):
    if i == K-1:
       ans += convert_dict[s] 
    else:
        ans += s

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define pb push_back
 
 
ll max(ll a,ll b)
{
    if(a>=b)
    return a;
    
    else
    return b;
}
 
int main(){
ll h;
cin>>h;
int i = 0; 
vector<ll>binaryNum(50,0);
while (h > 0){ 
binaryNum[i++] = h % 2; 
h = h / 2; 
}
  
  ll val=pow(2,i)-1;
  cout<<val;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    int N;
    std::cin >> N;
    
    int B[N-1];
    for (int i = 0; i < N-1; ++i) {
        std::cin >> B[i];
    } 
    
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        if (i == 0) {
            sum += B[0];
        }
        else if (i == (N - 1)) {
            sum += B[N-2];
        }
        else {
            sum += std::min(B[i-1], B[i]);
        }
    }
     
    std::cout << sum << std::endl;

    return 0;
}


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

#include <iomanip>
int main() {
    cout << fixed << setprecision(12);
    int n, k; cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = i;
        double p = 1;
        while (x < k) x *= 2, p /= 2;
        ans += p;
    }
    cout << ans / n << endl;
    return 0;
}

Measured memory_bytes: 256
use std::str::{
    FromStr,
};
use std::io::{ BufRead };

fn main() {
    let stdin = std::io::stdin();
    let mut t = Tokenizer::new(stdin.lock().lines().map(|x| x.unwrap()));

    let _n = t.take::<usize>();
    let a = t.take::<usize>()-1;
    let b = t.take::<usize>()-1;
    let c = t.take::<usize>()-1;
    let d = t.take::<usize>()-1;
    let s: Vec<char> = t.take::<String>().chars().collect();
    if !check( &s, a, c ) || !check( &s, b, d ) {
        println!("No");
        return;
    }
    if c < d {
        println!("Yes");
        return;
    }
    if check2( &s, b, d ) {
        println!("Yes");
        return;
    }
    println!("No");
}

fn check2( s: &Vec<char>, a: usize, b:usize ) -> bool {
    for i in a .. b+1 {
        if s[i] == '.' && s[i-1] == '.' && s[i+1] == '.' {
            return true
        }
    }
    false
}

fn check( s: &Vec<char>, a: usize, b:usize ) -> bool {
    for i in a+1 .. b {
        if s[i] == '#' && s[i-1] == '#' {
            return false
        }
    }
    true
}

struct Tokenizer<S: Iterator<Item = String>>  {
    input: S,
    items: Vec<String>,
}

impl<S: Iterator<Item = String>> Tokenizer<S> {
    pub fn new( input: S ) -> Self {
        Tokenizer { input: input, items: Vec::new() }
    }

    pub fn take<T: FromStr>(&mut self) -> T {
        loop {
            if let Some(r) = self.items.pop() {
                return r.parse().ok().expect("parse failed");
            }
            let mut items = self.input.next().unwrap().split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>();
            items.reverse();
            self.items = items;
        }
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define debug(var) cout << #var << ": " << var << endl;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
using ll = long long;
using ull = unsigned long long;
using vvint = vector<vector<int>>;
constexpr ll mod = 1e9 + 7;

int main() {

  int K, X; cin >> K >> X;

  for (int i = X - K + 1; i <= X + K - 1; i++)cout << i << " ";

  return 0;
}

Measured memory_bytes: 256
def main():
    x = int(input().strip())

    ns = []
    for i in range(1, 33):
        for j in range(2, 10):
            ns.append(i ** j)

    ns = list(set(ns))
    ns.sort()

    for i, n in enumerate(ns):
        if x < n:
            print(ns[i-1])
            return

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
S = input()
ACGT = ['A', 'C', 'G', 'T']
count = 0
max_count = 0
for w in S:
    if w in ACGT:
        count += 1
    if count > max_count:
        max_count = count
    if w not in ACGT:
        count = 0
print(max_count)


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

int main() {
    

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    string a;
    
    cin >> a;
    
    if (a == "Sunny") {
        cout << "Cloudy" << endl;
    }
   
    if (a == "Cloudy") {
        cout << "Rainy" << endl;
    }
    
    if (a == "Rainy") {
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    List<Double> list = new ArrayList<>();
    int n = sc.nextInt();
    double sum = 0;

    for(int i = 0 ; i < n ; i++){
        list.add(sc.nextDouble());
    }

    for(int i = 0 ; i < n ; i++){
        sum += 1/ list.get(i);
    }

    System.out.println(1 / sum);



    
    
    







}
}

Measured memory_bytes: 37640
fn main() {
    let (n, k): (u32, u32) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        let nk: Vec<u32> = buf
            .trim()
            .split_whitespace()
            .map(|e| e.trim().parse().ok().unwrap())
            .collect();
        (nk[0], nk[1])
    };
    println!("{}", k * (k - 1).pow(n - 1));
}


Measured memory_bytes: 4352
N = gets.to_i
ss = Array.new(N) { gets.chomp }
M = gets.to_i
ts = Array.new(M) { gets.chomp }

h = Hash.new(0)
ss.each { |s| h[s] += 1 }
ts.each { |t| h[t] -= 1 }


ans = [h.values.max, 0].max
puts ans


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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  t = 1;

  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> u >> k;
    --u;
    for(int j = 0; j < k; ++j){
      cin >> v;
      v--;
      m[u][v] = 1; 
    //隣接行列
    }
  }

  for(int i = 0; i < n; ++i){
    if(visit[i]==0){
      dfs(i);
    }
  }

  for(int i=0; i < n; ++i){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }

  return (0);
}


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

#define Need_For_Speed ios_base::sync_with_stdio;cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define mp make_pair

#define bg begin
#define en end

#define sz size()

#define fe first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e6 + 17, maxN = 4 * N, darr = 1e3 + 17, mod = 1e9 + 7;

int n, res, p;
int a[N];

ll binpow (int a, int b) {
	if (b == 0) {
		return 1;
	}
	if (b % 2 == 0) {
		ll r = (binpow(a, b / 2));
		return r * r;
	}
	else {
		return binpow(a, b - 1) * a;
	}
}

int main () {
	Need_For_Speed;
	cin >> n >> p;
	int e = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i]; e += (a[i] % 2);
	}
	ll ans = binpow(2, n - 1);
	if (!e) {
		if (p == 0) {
			cout << ans * 2;
		}
		else {
			cout << 0;
		}
		return 0;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
v = na()
c = na()
sum = 0
for i in range(n):
    if v[i] - c[i] > 0:
        sum += v[i] - c[i]
print(sum)

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

int main()
{
  int n,m;
  cin>>n>>m;
  if(n<m)
  {
    for(int i=0;i<m;i++)
      cout<<n;
  }
  else
  {
    for(int j=0;j<n;j++)
      cout<<m;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N;
int A[200005];
int B[200005];
signed main(){
    scanf("%lld",&N);
    rep(i,N){
        scanf("%lld",&A[i]);
        B[A[i]]++;
    }
    int ans=0;
    rep(i,N+1){
        if(B[i]>1){
            ans+=(B[i]*(B[i]-1))/2;
        }
    }
    rep(i,N){
        int sans=ans;
        if(B[A[i]]>1)sans-=(B[A[i]]*(B[A[i]]-1))/2-((B[A[i]]-1)*(B[A[i]]-2))/2;
        printf("%lld\n",sans);
    }
    
    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<char> N(3);
  for(int i=0;i<3;i++){
    cin>>N.at(i);
  }
if(N.at(0)==N.at(2)){
  cout<<"Yes"<<endl;
}
  else{
cout<<"No"<<endl;
  }
  return 0;
}


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

using namespace std;

#define PI 3.14159265359

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double n1 = h * 60 + m;
    double arat = n1 / 720;
    double brat = n1 / 60;
    arat = arat - (int) arat;
    brat = brat - (int) brat;
    double arad = 2 * PI * arat;
    double brad = 2 * PI * brat;
    double c;
    double rad;
    if (abs(arad - brad) * 2 > 2 * PI) {
        if (arad * 2 > 2 * PI) rad = 2 * PI - arad + brad;
        else if (brad * 2 > 2 * PI) rad = 2 * PI - brad + arad;
        c = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    } else {
        rad = abs(arad - brad);
        c = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    }
    printf("%.10f\n", c);
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    bool flag = false;
    rep(i, 0, s.size()){
        if(flag){
            ans++; flag = false;
        }
        else if(s[i] != s[i+1]){
            ans++;
        }
        else{
            ans++;
            flag = true;
            i++;
        }
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3700
N = int(input())
K = int(input())
count = int(0)

data = list(map(int, input().split()))

for i in range(N):
    A = abs(data[i])
    B = abs(K - data[i])
    if A < B:
        count += A*2
    else:
        count += B*2

print(count)

Measured memory_bytes: 3060
#ABC_150_C
import itertools
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = [i for i in range(1,N+1)]
#itertoolsでLを並び替えたリストを作成する。
#ただし、中の各要素はタプルになっているところに注意する。
M = list(itertools.permutations(L))
#[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
#Pはリストなので、タプルに変換してから、indexを求める
p = M.index(tuple(P))
q = M.index(tuple(Q))
print(abs(p-q))

Measured memory_bytes: 8052
#include <iostream>
using namespace std;
int main (){
    int a, b, c, i = 0 , ans = 0;
    cin >> a >> b >> c ;
    for (i = a;  i <= b; i += 1){
        if (c % i == 0) ans += 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long int
using namespace std;

int main(void) {
  int n , m;
  cin >> n >> m;
  
  printf("%d\n", (m*(m-1))/2 + (n* (n-1))/2);
  
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int N,W;
    cin >> N >> W;
    vi w(N),v(N);
    rep(i,N){
        cin >> w[i] >> v[i];
    }
    
    //cout << "OK1" << endl;
    vl dp(W+1,-1);
    dp[0]=0;
    rep(i,N){
        for(int j=W; j>=0; j--){
            if(dp[j]!=-1 && j+w[i] <= W){
                chmax(dp[j+w[i]],dp[j]+v[i]);
                //cout << dp[j+w[i]] << endl;
            }
        }
        //cout << endl;
    }
    //cout << "OK2" << endl;
    
    ll ans=0;
    rep(i,W+1){
        chmax(ans,dp[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

constexpr int INF = INT_MAX;
constexpr int MAX_N = 1000005;
constexpr ll MOD = ll(1e9)+7;

int n;
double dp[303][303][303];

double rec(int x, int y, int z){
    if(x == 0 && y == 0 && z == 0) return 0;
    if(dp[x][y][z] > 0) return dp[x][y][z];
    if(x>0) dp[x][y][z] += (rec(x-1,y,z)+1)*double(x)/n;
    if(y>0) dp[x][y][z] += (rec(x+1,y-1,z)+1)*double(y)/n;
    if(z>0) dp[x][y][z] += (rec(x,y+1,z-1)+1)*double(z)/n;
    dp[x][y][z] = (dp[x][y][z]+1)*(double(n)/(x+y+z))-1;
    return dp[x][y][z];
}

int main() {
    int cnt[3]{};
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        cnt[a-1]++;
    }
    
    printf("%.10lf\n",rec(cnt[0],cnt[1],cnt[2]));
    return 0;
}


Measured memory_bytes: 217344
#include <iostream>
#include <istream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
//#include <unordered_map>
#include <cstring>
#include <string.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <list>
#include <sstream>
//#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

#define fopen freopen("substrcmp.in", "r", stdin); freopen("substrcmp.out","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(A,value) memset(A,value,sizeof(A))
#define IOSFAST ios::sync_with_stdio(false); cin.tie(0)

const ll MOD = 1000LL * 1000 * 1000 + 7;
const int INF = 1e9;
const ll base = 1e18;
const int MAX = 1000;
const double EPS = 1e-9;
const double PI = acos(-1.);

int n;
int cx,cy,ct;

int main()
{
	cin >> n;
	FOR(i,0,n)
	{
		int t,x,y;
		cin >> t>> x >> y;
		//cout << abs(cx-x)+abs(cy-y) << endl;
		if (abs(cx-x)+abs(cy-y)+ct>t)
		{
			cout << "No";
			return 0;
		} else if ((t-abs(cx-x)-abs(cy-y)-ct)%2)
		{
			cout <<"No";
			return 0;
		}
		cx = x;
		cy = y;
		ct = t;
	}
	cout << "Yes";
	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	int a, b;
	int num;
	int sum=0;
	cin >> a >> b;
	num = b - a;
	for (int i = 1; i <= num; i++) {
		sum += i;
	}
	cout << sum - b << endl;
	
}


Measured memory_bytes: 256
<?php
  
// 標準入力を一行ずつ配列に代入します
while ($line = fgets(STDIN)) {
   $stdin[] = trim($line);
}

$dis = ((int)$stdin[4]-(int)$stdin[0]);
if($dis > (int)$stdin[5])
{
  print ":(";
}
else
{
  print "Yay!";
}

Measured memory_bytes: 3956
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/



/*ここからmain関数*/

int main()
{
	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;

	vector<long long int> A(X);
	vector<long long int> B(Y);
	vector<long long int> C(Z);
	for (int i = 0;i < X;i++)
		cin >> A.at(i);
	for (int i = 0;i < Y;i++)
		cin >> B.at(i);
	for (int i = 0;i < Z;i++)
		cin >> C.at(i);

	vector<long long int> AB(X*Y);
	int p = 0;
	for(int i=0;i<X;i++)
		for (int j = 0;j < Y;j++)
		{
			AB.at(p) = A[i] + B[j];
			p++;
		}

	sort(AB.begin(), AB.end());
	reverse(AB.begin(), AB.end());

	//cout << "A+Bのソート\n";
	//for (int i = 0;i < X*Y;i++)
	//	cout << AB.at(i) << "\n";

	int T = min(X*Y, K);
	vector<long long int> ans(T*Z);
	p = 0;
	for(int i=0;i<T;i++)
		for (int j = 0;j < Z;j++)
		{
			ans.at(p) = AB[i] + C[j];
			p++;
		}

	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());

	//cout << "A+B+Cのソート\n";
	//for (int i = 0;i < T*Z;i++)
	//	cout << ans.at(i) << "\n";

	for (int i = 0;i < K;i++)
		cout << ans.at(i) << "\n";

	return 0;
}

Measured memory_bytes: 31616
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"


using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N;
	string s, t, u;
	cin >> s >> t >> u;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == t[i] && s[i] == u[i])ans += 0;
		else if (s[i] == t[i])ans++;
		else if (s[i] == u[i])ans++;
		else if (t[i] == u[i])ans++;
		else ans += 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
            using namespace std;
			typedef long long int ll; 
     
            int main() {
              ll N;
              cin>> N; 
              ll B[N-1];
              ll A[N]; 
 			  A[0]=100000000000;	
              for(int i=0; i<N-1; i++){
                cin >> B[i] ;
              }
              
               A[0]=B[0];
              for(int i=1; i<N-1; i++){
                cin >> B[i] ; 
                A[i] = min( B[i-1], B[i] );
              }
              A[N-1] = B[N-2]; 
              ll S=0; 
              for(int i=0; i<N; i++){
                S+= A[i];
              }
              cout<<  S << endl; 
            }


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int N, M, K;
ll A[202020], B[202020];
ll Asum[202020], Bsum[202020];


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

	cin >> N >> M >> K;
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < M; i++)cin >> B[i];

	for (int i = 0; i < N; i++)Asum[i + 1] = Asum[i] + A[i];
	for (int i = 0; i < M; i++)Bsum[i + 1] = Bsum[i] + B[i];

	int ans = 0;
	for (int i = -1; i < N; i++) {
		if (Asum[i + 1] > K)break;
		int ok = -1, ng = M;
		while (ng - ok > 1) {
			int mid = (ng + ok) / 2;
			if (Asum[i + 1] + Bsum[mid + 1] <= K)ok = mid;
			else ng = mid;
		}
		ans = max(ans,(i + 1) + (ok + 1));
	}
	puts(ans);
	

	return 0;
}

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

struct edge { int from, to, cost; };

const int MAX_N = (int)205;
const int INF = (int)1e7;
int H, W;
int cost[10][10];
int A[MAX_N][MAX_N];
int d[10][10];

int V = 10;
int E = 100;

edge es[105];

void shortest_path(int s) {
  d[s][s] = 0;
  while (true) {
    bool update = false;
    for (int i = 0; i < E; ++i) {
      edge e = es[i];
      if (d[s][e.from] != INF && d[s][e.to] > d[s][e.from] + e.cost) {
        d[s][e.to] = d[s][e.from] + e.cost;
        update = true;
      }
    }
    if (!update) break;
  }
}

int main(void) {
    // Here your code !
    int tmp;
    scanf("%d %d", &H, &W);
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
        scanf("%d ", &tmp);
        es[i * 10 + j].from = (int)i;
        es[i * 10 + j].to = (int)j;
        es[i * 10 + j].cost = (int)tmp;
        d[i][j] = INF;
      }
    }
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        scanf("%d", &A[i][j]);
      }
    }

    for (int i = 0; i < 10; ++i) {
      shortest_path(i);
    }

    int ans = 0;
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        if (A[i][j] != -1 && A[i][j] != 1) {
          ans += d[A[i][j]][1];
        }
      }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

import sys
from operator import add

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

class SegTree:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_val: 区間[l, r)の値を得る
    """
 
    def __init__(self, n, func, init):
        """
        :param n: 要素数
        :param func: 値の操作に使う関数(min, max, addなど)
        :param init: 要素の初期値
        """
        self.n = n
        self.func = func
        self.init = init
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def get_val(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        return self._get_val(a, b, 1, 0, self.n2)
 
    def _get_val(self, a, b, k, l, r):
        """
        [a, b)の値を得る内部関数
        :param k: 現在調べている区間のtree内index
        :param l, r: kが表す区間の左右端index [l, r)
        :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値
        """
        # 範囲外なら初期値
        if r <= a or b <= l:
            return self.init
        # [a,b)が完全に[l,r)を包含するならtree[k]の値を採用
        if a <= l and r <= b:
            return self.tree[k]
        # 一部だけ範囲内なら2つに分けて再帰的に調査
        m = (l + r) // 2
        return self.func(
            self._get_val(a, b, k << 1, l, m),
            self._get_val(a, b, (k << 1) + 1, m, r)
        )

N,Q=MAP()
# 1-indexed対応
st=SegTree(N+1, add, 0)
for _ in range(Q):
    com,x,y=MAP()
    if com==0:
        st.update(x, y+st.get_val(x, x+1))
    else:
        print(st.get_val(x, y+1))



Measured memory_bytes: 11004
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>

#define INF 100000000
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; }

using namespace std;

int main(){
  int i,j,k,n,d,a;
  string s;
  cin >>a>>s;

  if(a>=3200)cout <<s<<endl;
  else cout << "red"<<endl;

  return 0;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a;
    double sum = 0;
    for (int i=0; i<n; ++i) {
        int ai;
        cin >> ai;
        sum += ai;
        a.push_back(ai);
    }
    sort(a.begin(),a.end(),greater<int>());
//    bool flg = true;
    for (int j=0; j<=m-1;++j) {
//        cout << a.at(j) << endl;
        if(a.at(j) < (double)(sum / (4*m)) ) {
//            flg = false;
            cout << "No" << endl;
            return 0;
        }
    }
//    if (flg) {
//        cout << "Yes" << endl;
//    }else{
//        cout << "No" << endl;
//    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
n, m=map(int,input().split())
pic_a = [input() for _ in range(n)]
pic_b = [input() for _ in range(m)]
top = pic_b[0][0]
if m==1:
    for line_a in pic_a:
        for chr_a in line_a:
            if top==chr_a:
                print('Yes')
                exit()
    print('No')
    exit()
for i, line_a in enumerate(pic_a[:-m+1]):
    for j, chr_a in enumerate(line_a[:-m+1]):
        if top == chr_a:
            for k, line_b in enumerate(pic_b):
                if line_b != pic_a[i+k][j:j+m]:
                    break
            else:
                print('Yes')
                exit()
print('No')


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int n, m;	cin >> n >> m;
  	if(n == m)	cout << "Yes" << endl;
  	else cout << "No" << endl;
}


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

int main() {
    ll n,k;cin>>n>>k;
    vector<ll>v(n,0);
    for(ll i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    ll ans=0;
    for(ll i=0;i<k;i++)ans+=v[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u){
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if (u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i, v, l, r, root;

  scanf("%d",&n);
  for(i = 0;i<n;i++){
    T[i].p = NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }

  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



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

int main() {
  int n, m;
  cin>>n>>m;
  priority_queue<double> q;
  double d;
  rep(i, n) {
    cin>>d;
    q.push(d);
  }
  rep(i, m) {
    d = q.top();
    q.pop();
    d/=2;
    q.push(d);
  }
  ll ans = 0;
  rep(i, n){
    d = q.top();
    q.pop();
    int s = floor(d);
    ans+=s;
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main() {

	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;

	cout << (char)(s1[0]-32) << (char)(s2[0]-32) << (char)(s3[0]-32) << endl;
	return 0;

}

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

int main(){
  string S;
  cin>>S;
  unordered_map<char,int> hash;
  for(int i=0; i<S.size(); i++){
    if(hash.count(S[i])==0){
      hash[S[i]]=0;
    }else{
      hash[S[i]]++;
    }
  }
  if(hash.size()==2){
    if(hash[S[0]]==1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  long long D;
  cin >> D;
  D *= D;

  int count = 0;
  rep(i, N)
  {
    long long x, y;

    cin >> x >> y;
    if (x * x + y * y <= D)
      count++;
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3632
N, D = map(int, raw_input().split())
X = [map(int, raw_input().split()) for _ in range(N)]

ans = 0
for i in range(N):
  for j in range(i):
    t = sum((X[i][k]-X[j][k])**2 for k in range(D))
    if int(t**0.5+0.01)**2==t:
      ans += 1
print ans


Measured memory_bytes: 2568
//
// Created by 27420 on 2020/8/15.
//

#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
    char s[20];
    scanf("%s",s);
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R'){
        printf("3\n");
    }else if(s[0]=='S'&&s[1]=='R'&&s[2]=='R'){
        printf("2\n");
    }else if(s[0]=='R'&&s[1]=='R'&&s[2]=='S'){
        printf("2\n");
    }else if(s[0]=='S'&&s[1]=='S'&&s[2]=='R'){
        printf("1\n");
    }else if(s[0]=='S'&&s[1]=='R'&&s[2]=='S'){
        printf("1\n");
    }else if(s[0]=='R'&&s[1]=='S'&&s[2]=='R'){
        printf("1\n");
    }else if(s[0]=='R'&&s[1]=='S'&&s[2]=='S'){
        printf("1\n");
    }else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S'){
        printf("0\n");
    }
}

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

k = n % 10

if k == 2 or k == 4 or k == 5 or k == 7 or k == 9:
  print("hon")
elif k == 0 or k == 1 or k == 6 or k == 8:
  print("pon")
else:
  print("bon")



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

int main()
{
  int n,k,a[100100],b=0;
  scanf("%d %d",&n,&k);
  char s[100100];
  scanf("%s",s);
  int i=0;
  while(i<n)
    {
      a[b]=0;
      while(i<n&&s[i] == '1')
	{
	  a[b]++;
	  i++;
	}

      b++;
      a[b]=0;
   while(i<n&&s[i] == '0')
	{
	  a[b]++;
	  i++;
	}
   b++;
    };

  k = 2*k+1;

  if(k > 100000)
    k=100000;
  int now,max=0;
  for(i=0;i<k;i++)
    max += a[i];

  if(max == n)
    printf("%d\n",max);

  else
    {

  now = max;

  for(i=k;i<b;i+=2)
    {
    now += a[i] + a[i+1] - a[i-k] - a[i-k+1];
    if(now > max)
      max=now;
    }

  printf("%d\n",max);
    }
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int a[5],k,i,j,x,s=0;
  for(i=0;i<5;i++){
  	scanf("%d",&a[i]);
  }
  scanf("%d",&k);
  for(i=0;i<5;i++){
    for(j=i+1;j<5;j++){
      x=a[j]-a[i];
      if(x<=k){
      }else{
       s++;
      }
    }
  }
  if(s==0){
    printf("Yay!");
  }else{
    printf(":(");
  }
  return 0;
}

Measured memory_bytes: 128
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
import math


def isp(n):
    if n <= 1:
        return False

    if n == 2:
        return True

    if n % 2 == 0:
        return False

    for i in range(3, math.ceil(math.sqrt(n)), 2):
        if n % i == 0:
            return False

    return True

n = int(input())
nso = not isp(n)
while(nso):
    n += 1
    nso = not isp(n)
print(n)


Measured memory_bytes: 3060
#include<iostream>
long n,k,a=0,i,j,m=1e9+7,v[2<<20];main(){std::cin>>n>>k;for(i=0;i<n;i++)std::cin>>v[i];for(i=0;i<n;i++)for(j=0;j<n;j++){if(i==j)continue;if(v[i]>v[j]){if(i<j)a+=k;(a+=k*(k-1)/2)%=m;}}std::cout<<a;}


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

    int n = sn.nextInt();
    int m = sn.nextInt();
    
    int cnt = 0;
    
    if (n > 1) {
      for (int i = 1; i < n; i ++) {
        cnt = cnt + (n - i);
      }
    }
    
    if (m > 1) {
      for (int i = 1; i < m; i ++) {
        cnt = cnt + (m - i);
      }
    }
    
    System.out.print(cnt);
  }
}

Measured memory_bytes: 21460
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main() {
	
	int a, b, i;

	cin >> a >> b;

		if (a % 2 == 0 && b % 2 != 0 || a % 2 != 0 && b % 2 == 0) {
			cout << "IMPOSSIBLE" << endl;
		} else {
			cout << (a + b) / 2 << endl;
		}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

class union_find{
  int n_; 
  vector<int> par, rank, size;
public:
  union_find(int n): n_{n} {
    par.resize(n_);
    rank.resize(n_);
    size.resize(n_);

    REP(i, n_){
      par[i] = i;
      rank[i] = 1;
      size[i] = 1;
    }
  } 

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

  void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if(x == y) return;

    if(rank[x] > rank[y]){
      par[y] = x;
      size[x] += size[y];
    } else {
      par[x] = y;
      size[y] += size[x];
      if(rank[x] == rank[y]) rank[y]++;
    }
  }

  int find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  vector<int> getPar(){ return par; }
};

int main() {
  int n, k, l; cin >> n >> k >> l;
  union_find a(n), b(n);
  REP(i, k){
    int s, t; cin >> s >> t;
    --s; --t;
    a.unite(s, t);
  }

  REP(i, l){
    int s, t; cin >> s >> t;
    --s; --t;
    b.unite(s, t);
  }

  map<pair<int, int>, int> mp;
  REP(i, n){
    mp[make_pair(a.find(i), b.find(i))]++;
  }

  REP(i, n) cout << mp[make_pair(a.find(i), b.find(i))] << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 16640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <limits>
#include <climits>
#include <functional>
#include <numeric>

using namespace std;

#define alloc(type,n) (type*)calloc(sizeof(type),(n));
typedef long long lli;

int n;
char s[100005];
char ans[100005];

void next(int i){
	if((ans[i] == 'S' && s[i] == 'o') || (ans[i] == 'W' && s[i] == 'x')){
		ans[i+1] = ans[i-1];
	}else{
		ans[i+1] = ans[i-1] == 'S' ? 'W' : 'S';
	}
}

bool judge(){
	if((ans[0] == 'S' && s[0] == 'o' )|| (ans[0] == 'W' && s[0] == 'x')){
		if(ans[1] == ans[n-1]){
			return true;
		}
	}else{
		if(ans[1] == (ans[n-1] == 'S' ? 'W' : 'S')){
			return true;
		}
	}
	return false;
}
bool judge2(){
	if((ans[n-1] == 'S' && s[n-1] == 'o' )|| (ans[n-1] == 'W' && s[n-1] == 'x')){
		if(ans[0] == ans[n-2]){
			return true;
		}
	}else{
		if(ans[0] == (ans[n-2] == 'S' ? 'W' : 'S')){
			return true;
		}
	}
	return false;
}

int main(){
	cin >> n >> s;
	ans[0] = 'S';
	ans[1] = 'S';
	for(int i = 1;i < n-1;i++) next(i);
	if(judge() && judge2()){
		cout << ans << endl;
		return 0;
	}

	ans[0] = 'S';
	ans[1] = 'W';
	for(int i = 1;i < n-1;i++) next(i);
	if(judge() && judge2()){
		cout << ans << endl;
		return 0;
	}

	ans[0] = 'W';
	ans[1] = 'S';
	for(int i = 1;i < n-1;i++) next(i);
	if(judge() && judge2()){
		cout << ans << endl;
		return 0;
	}

	ans[0] = 'W';
	ans[1] = 'W';
	for(int i = 1;i < n-1;i++) next(i);
	if(judge() && judge2()){
		cout << ans << endl;
		return 0;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 512
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int x, n;
    cin >> x >> n;
    auto p = unordered_set<int>(n);
    for (auto i = 0; i < n; ++i) {
        auto p_i = 0;
        cin >> p_i;
        p.insert(p_i);
    }

    auto ans = 0;
    for (auto dist = 0;; ++dist) {
        auto smaller = x - dist;
        auto larger = x + dist;

        auto itr = p.find(smaller);
        if (itr == p.end()) {
            ans = smaller;
            break;
        }
        itr = p.find(larger);
        if (itr == p.end()) {
            ans = larger;
            break;
        }
    }

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


Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int A = sc.nextInt();
			
			int[] x = new int[N];
			for(int i = 0; i < N; i++) {
				x[i] = sc.nextInt();
			}
			long[][][] dp = new long[N+1][N+1][2501]; // N枚のカードを使って  合計がNになる組み合わせ
			for(int i = 0; i < N+1; i++) {
				dp[i][0][0] = 0;
			}
			dp[0][0][0] = 1;
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < N; j++) {
					for(int k = 0; k < 2501; k++) {
						if(x[i] + k <= 2500) {
							dp[i+1][j + 1][k + x[i]] += dp[i][j][k];
						}
						dp[i+1][j][k] += dp[i][j][k];
					}
				}
			}
			long sum = 0;
			for(int i = 1; i <= N; i++) {
				if(A * i <= 2500) {
						sum += dp[N][i][A * i];
				}
			}
			System.out.println(sum);
			
			
			
		}

		

}


Measured memory_bytes: 77648
#include<bits/stdc++.h>
#include <functional>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N,M,TARGET[110]={};
  cin >> N >> M;
  int ans[N]={};
  rep(i,M) cin >> TARGET[i];
  rep(i,M){
    int B[N]={},c=0;
    rep(j,N){
      cin >> B[j];
    }
    rep(j,N){
      if(B[j]==TARGET[i]) ans[j]++;
      else c++;
    }
    //cout << "c" << c << endl;
    ans[TARGET[i]-1]+=c;
  }
  rep(i,N) cout << ans[i] << endl;
  return 0;
}



Measured memory_bytes: 3100
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MD 1000000007

char sep[3] = " \n";
double PI = acos(-1);


class Dice {
  int i, j;
 public:
  int s[6];
  Dice(){};
  
  void roll(int i, int j, int k, int l) {
    int t = s[i]; s[i] = s[j]; s[j] = s[k]; s[k] = s[l]; s[l] = t;
  }
  void moveN() { roll(0, 1, 5, 4); }
  void moveW() { roll(0, 2, 5, 3); }
  void moveH() { roll(1, 2, 4, 3); }

  void move(char c) {
    if (c == 'N') moveN();
    if (c == 'S') rep(i,3) moveN();
    if (c == 'W') moveW();
    if (c == 'E') rep(i,3) moveW();
  }

  void read() { rep(i,6) cin >> s[i]; }
  
  bool eq(Dice* d2) {
    rep(i,6) if (s[i] != d2->s[i]) return false;
    return true;
  }

  bool match(Dice* d2) {
    int i, j;
    rep(i,4) {
      moveN();
      rep(j,4) {
        moveH();
        if (eq(d2)) return true;
      }
    }
    rep(i,4) {
      moveW();
      rep(j,4) {
        moveH();
        if (eq(d2)) return true;
      }
    }
    return false;
  }
};


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

  Dice* d[110];
  cin >> n;
  rep(i,n) { d[i] = new Dice; d[i]->read(); }
  rep(i,n) REP(j,i+1,n) if (d[i]->match(d[j])) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;

  return 0;
}
  

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll A, B, K; cin >> A >> B >> K;
    if(A <= K)
    {
        K -= A;
        A = 0;
        B = max(B-K, (ll)0);
    }
    else
    {
        A -= K;
    }
    cout << A << " " << B << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cout << boolalpha;

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

void solver(){

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
	int n;
	cin >> n;
	string s;
	map<string,int>m;
	for(int i=0; i<n; i++){
		cin >> s;
		m[s]++;
	}
	cout << "AC x "<< m["AC"] << "\n";
	cout << "WA x " << m["WA"] << "\n";
	cout << "TLE x " << m["TLE"] << "\n";
	cout << "RE x " << m["RE"] << "\n";
	return 0;
}	



Measured memory_bytes: 3672
N, K = map(int, input().split())

def getNum(num):
    res = 0
    while True:
        if num >= K:
            break
        res += 1
        num *= 2
    return res

res = 0
for i in range(1, N+1):
    res += (1 / N) * (0.5 ** getNum(i))
print(res)


Measured memory_bytes: 2940