akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  int N;
  cin >> N;
  double ans = 0;
  rep(i,0,N){
    double x;
    str u;
    cin >> x >> u;
    if(u == "JPY"){
      ans += x;
    }
    else{
      ans += x * 380000.0;
    }

  }

  print(ans);


 return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.swing.JTabbedPane;
public class Main{
	static class FastScanner{//用于快速读入大量数据
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in),16384);
			eat("");
		}
		public void eat(String s) {
			st = new StringTokenizer(s);
		}
		public String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}
		public boolean hasNext() {
			while(!st.hasMoreTokens()) {
				String s = nextLine();
				if(s==null) return false;
				eat(s);
			}
			return true;
		}
		public String next() {
			hasNext();
			return st.nextToken();
		}
	    
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
	static FastScanner cin = new FastScanner(System.in);//快读
	static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));//快速输出
    static int mod=1000000007;

   


   static  String str;
    public static void main(String[] args) {
       int n;
       n=cin.nextInt();
       str=cin.next();
       int len=str.length();
       int ans=0;
       Vector<Integer>vec=new Vector<Integer>();
       for(int i=len-1;i>=0;i--) {
    	   if(str.charAt(i)=='R') {
    		   vec.add(i);
    	   }
       } 
       int cc=0;
       for(int i=0;i<len;i++) {
    	   if(str.charAt(i)=='W') {
    		   if(cc+1<=vec.size()&&vec.elementAt(cc)>i) {
    			   cc++;
    			   ans++;
    		   }
    	   }
       }
       out.println(ans);
       out.flush();
       return ;
	}
 
}


Measured memory_bytes: 42444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));

	if (a[n - 1] - a[0] > 1) {
		cout << "No" << endl;
	}
	else if (a[0] == a[n - 1]) {
		if (a[0] == n - 1) {
			cout << "Yes" << endl;
		}
		else if (a[0] <= n / 2) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	else {
		int k = upper_bound(all(a), a[0]) - a.begin();
		int l = n - k;
		if (1 <= a[n - 1] - k && a[n - 1] - k <= l / 2) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}

}

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

using namespace std;

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

    vector<int> lights;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        lights.push_back(tmp - 1);
    }

    int now = 0, index = 0;
    while (index < n) {
        if (now == 1) {
            break;
        }
        index++;
        now = lights[now];
    }

    if (now == 1) {
        cout << index << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>
#define N 100
int main(){
  int n,i,j,flag=0,minj;
  int A[N];
 
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  for(i=0;i<n-1;i++)
    {
      for(j=n-1;j>i;j--)
	{
	  if(A[j]<A[j-1])
	    {
	      minj=A[j-1];
	      A[j-1]=A[j];
	      A[j]=minj;
	      flag=flag+1;
	    }
	}
    }
  for(i=0;i<n-1;i++)
    {
      printf("%d ",A[i]); 
   }
  printf("%d",A[i]);
  printf("\n");
  printf("%d\n",flag);
 
return 0;
}

Measured memory_bytes: 604
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

pub struct Combination {
    m: usize,
    f: Vec<usize>,
    g: Vec<usize>,
}

fn inv(a: usize, m: usize) -> usize {
    let m = m as i64;
    let mut a = a as i64;
    let mut b = m as i64;
    let mut u = 1;
    let mut v = 0;
    let mut tmp;
    while b != 0 {
        let t = a / b;
        a -= t * b;
        tmp = a;
        a = b;
        b = tmp;
        u -= t * v;
        tmp = u;
        u = v;
        v = tmp;
    }
    u %= m;
    if u < 0 {
        u += m;
    }
    return u as usize;
}

impl Combination {
    pub fn new(m: usize) -> Combination {
        Combination {
            m,
            f: vec![1],
            g: vec![1],
        }
    }
    pub fn combinations(&mut self, n: usize, k: usize) -> usize {
        for i in self.f.len()..=n {
            self.f.push(self.f[i - 1] * i % self.m);
            self.g.push(inv(self.f[i], self.m));
        }
        self.f[n] * self.g[k] % self.m * self.g[n - k] % self.m
    }
    pub fn permutations(&mut self, n: usize, k: usize) -> usize {
        for i in self.f.len()..=n {
            self.f.push(self.f[i - 1] * i % self.m);
            self.g.push(inv(self.f[i], self.m));
        }
        self.f[n] * self.g[n - k] % self.m
    }
    pub fn factorial(&mut self, n: usize) -> usize {
        for i in self.f.len()..=n {
            self.f.push(self.f[i - 1] * i % self.m);
            self.g.push(inv(self.f[i], self.m));
        }
        self.f[n]
    }
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let mut c = Combination::new(M);
    for i in 1..=k {
        if n + 1 < k || n + 1 < k + i {
            println!("0");
        } else {
            let x = c.combinations(dbg!(n + 1 - k), dbg!(n + 1 - k - i));
            let y = c.combinations(dbg!(k - 1), dbg!(k - i));
            eprintln!("{} {}", x, y);
            println!("{}", x * y % M);
        }
    }
}


Measured memory_bytes: 2192
#include<stdio.h>
int main(void) {
	int n, i, sum = 0, x;
	char a[100], b[100], c[100];
	char k;
	scanf("%d %s %s %s", &n, a, b, c);
	for (i = 0; i < n; i++) {
		x = 0;
		if (b[i] == c[i] && a[i] == b[i]);
		else if(a[i]==b[i]||b[i]==c[i]||a[i]==c[i])x++;
		else x += 2;
		sum += x;
	}
	printf("%d\n", sum);
}


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

ll vis[100001];
void dfs(vector<ll> v[],int e)
{
	vis[e]=1;
	for(auto itr: v[e])
	{
		if(!vis[itr])
		{
			dfs(v,itr);
		}
	}
}


int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n],i;
	for(i=0;i<n;i++)
		cin>>a[i];
	double dp[n];
	double mx=0.0;
	for(i=0;i<k;i++)
	{
		ll s=a[i]*(a[i]+1)/2;
		dp[i]=(double)s/(double)a[i];
		mx+=dp[i];
	}
	double sum=mx;
	for(i=k;i<n;i++)
	{
		ll s=a[i]*(a[i]+1)/2;
		dp[i]=(double)s/(double)a[i];
		sum=sum-dp[i-k]+dp[i];
		mx=max(mx,sum);
	}
	printf("%.10lf\n", mx);
	return 0;
}

Measured memory_bytes: 3328
n=gets.to_i
a1=gets.split.map(&:to_i)
a2=gets.split.map(&:to_i)
low=a1[0]+a2.inject(:+)
high=a1[0]+a2.inject(:+)
1.upto(n-1).each do |i|
  high=high+a1[i]-a2[i-1]
  low=[high,low].max
end
puts low

Measured memory_bytes: 1788
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if (s == "ABC")
  {
    /* code */
    cout << "ARC" << endl;
  }else if(s == "ARC"){
    cout << "ABC" << endl;
  }
  
}
  

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

int main() {
    int n;
    cin >> n;
    pair<long long, long long> p[n];
    for(int i = 0; i < n; i++) {
        long long a, b;
        cin >> a >> b;
        p[i] = make_pair(b, a);
    }

    sort(p, p + n);

    long long time = 0;
    for(int i = 0; i < n; i++) {
        time += p[i].second;
        if(time > p[i].first) {
            cout << "No" << endl;
            return 0;
        } 
    }

    cout << "Yes" << endl;    

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

struct Dinner {
    ll A, B;
};

int main() {
    ll N;
    cin >> N;
    vector<Dinner> dinners(N);
    for (ll i = 0; i < N; i++) {
        cin >> dinners[i].A >> dinners[i].B;
    }

    sort (dinners.begin(), dinners.end(), [](Dinner& lhs, Dinner& rhs) {
       return lhs.A + lhs.B > rhs.A + rhs.B;
    });

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ans += (i % 2 == 0 ? dinners[i].A : -dinners[i].B);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdint>
#include <algorithm>

int main() {
    int64_t N;
    scanf("%lld", &N);

    auto f=[](int64_t u) {
        int res=0;
        while (u) {
            ++res;
            u /= 10;
        }
        return res;
    };

    int res=810;
    for (int64_t i=1; i*i<=N; ++i)
        if (N % i == 0)
            res = std::min(res, std::max(f(i), f(N/i)));

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


Measured memory_bytes: 256
#include<cstdio>
 
int main(){
    double sum;
    double a;
    int i;
    while(~scanf("%lf",&a)){
        sum=0;
        sum+=a;
        for(i=2;i<=10;i++){
 
            if(i%2==0){
                a=2*a;
            }else{
                a=a/3;
            }
            sum+=a;
        }
        printf("%f\n",sum);
    }
     
    return 0;
}

Measured memory_bytes: 1076
(n,an,bn) = list(map(int,input().split()))
s = list(input())
count = 1
foreign = 1
for i in s:

  if i=='a' and an+bn >= count:
    print('Yes')
    count += 1
  elif i=='b' and an+bn >= count and bn >= foreign:
    print('Yes')
    count += 1
    foreign += 1
  else:
    print('No')

Measured memory_bytes: 4708
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), c.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


int main() {
  int H, W;
  while(true) {
    scanf("%d %d", &H, &W);
    if(H==0 && W==0) break;
    rep(i, H) {
      rep(j, W) {
        if((i+j)%2==0) printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int>T;
typedef pair<int,int>P;
const int N=100000,M=262144,inf=2000000000;
vector<vector<T>>e(N);
vector<vector<P>>tour_d(N);
vector<int>tour_v;
vector<int>segt(M*2,inf);
vector<vector<int>>sum(N-1,vector<int>(1));
vector<vector<int>>num(N-1,vector<int>(1));
vector<vector<int>>p(N-1,vector<int>(1));
int dist[N],newv[N],t[N];
int cnt=0,vis=0;
void dfs(int v,int before){
    int nowv=cnt;
    newv[v]=cnt;
    if(t[cnt]==0)t[cnt]=vis;
    cnt++,vis++;
    tour_v.push_back(nowv);
    for(int i=0;i<e[v].size();i++){
        int u=get<0>(e[v][i]),col=get<1>(e[v][i]),len=get<2>(e[v][i]);
        if(u!=before){
            dist[cnt]=dist[nowv]+len;
            tour_d[col].push_back({len,1});
            p[col].push_back(vis);
            dfs(u,v);
            tour_v.push_back(nowv);
            tour_d[col].push_back({-len,-1});
            p[col].push_back(vis);
            vis++;
        }
    }
}
int segmin(int l,int r,int n,int nl,int nr){
    int mid=(nl+nr)/2;
    if(r<=nl || nr<=l)return inf;
    else if(l<=nl && nr<=r)return segt[n];
    else return min(segmin(l,r,n*2,nl,mid),segmin(l,r,n*2+1,mid,nr));
}
int dis(int v,int x,int y){
    v=upper_bound(p[x].begin(),p[x].end(),v)-p[x].begin()-1;
    return num[x][v]*y-sum[x][v];
}
int main(){
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        e[a-1].emplace_back(b-1,c-1,d);
        e[b-1].emplace_back(a-1,c-1,d);
    }
    dfs(0,-1);
    for(int i=0;i<tour_v.size();i++)segt[M+i]=tour_v[i];
    for(int i=M-1;i;i--)segt[i]=min(segt[i*2],segt[i*2+1]);
    for(int i=0;i<n-1;i++){
        for(int j=0;j<tour_d[i].size();j++){
            sum[i].push_back(sum[i][j]+tour_d[i][j].first);
            num[i].push_back(num[i][j]+tour_d[i][j].second);
        }
    }
    int ans[q];
    for(int i=0;i<q;i++){
        int u,v,x,y;
        cin>>x>>y>>u>>v;
        u=newv[u-1],v=newv[v-1],x--;
        int lca=segmin(min(t[u],t[v]),max(t[u],t[v])+1,1,0,M);
        ans[i]=dis(t[u],x,y)+dis(t[v],x,y)-2*dis(t[lca],x,y)
              +dist[u]+dist[v]-2*dist[lca];
    }
    for(int i=0;i<q;i++)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 44228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string s;
  cin >> s;
  int head = 0, tail = s.size() - 1;
  int ans = 0;
  while (tail - head > 0)
  {
    if (s[head] == s[tail])
    {
      head++;
      tail--;
    }
    else if (s[head] == 'x')
    {
      head++;
      ans++;
    }
    else if (s[tail] == 'x')
    {
      tail--;
      ans++;
    }
    else
    {
      cout << -1 << endl;
      return 0;
    }
  }

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

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://cf16-final-open.contest.atcoder.jp/tasks/codefestival_2016_final_b>
問題文============================================================
 ある年のCODE FESTIVALの決勝では N 問の問題が出題されました。
 
 i(1≦i≦N) 番目の問題の配点は i 点です。
 
 高橋くんは、このコンテストでちょうど N 点を取りたいと思い、そのために解く問題の集合をどうするかを考えています。
 
 配点が高い問題は難しいので、解く問題の配点のうちの最大値が最小になるようにしようと考えました。
 
 高橋くんが解くべき問題の集合を求めてください。
 

=================================================================

解説=============================================================

================================================================
*/
void solve(ll n,vector<ll>& dp){
    cout << dp[n] << endl;
    if(dp[n] != n) solve(n - dp[n],dp);
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    
    vector<ll> cusum(N+1,0);
    for(int i = 0; i < N;i++) cusum[i+1] = cusum[i] + i;
    vector<ll> dp(N+1,INF);
    for(int i = 1; i <= N;i++){
        dp[i] = lower_bound(cusum.begin(),cusum.end(),i) - cusum.begin() - 1;
    }
    solve(N,dp);
	return 0;
}


Measured memory_bytes: 156544
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, P;
int c[64];

int main(){
  while(scanf("%d%d", &N, &P) && N+P){
    memset(c, 0, sizeof(c));
 
    int n = 0, w = P;
    while(1){
      if(w){
	w--;
	c[n]++;
      }else{
	w = c[n];
	c[n] = 0;
      }

      if(c[n] == P){
	printf("%d\n", n);
	break;
      }
      n++;
      n %= N;
    }
  }
  return 0;
}

Measured memory_bytes: 1188
unittest
{
	assert( [ "4", "RRGB" ].parse.expand.solve == 1 );
	assert( [ "39", "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB" ].parse.expand.solve == 1800 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	const long[ dchar ] CS = [ 'R':0L, 'G':1L, 'B':2L ];
	
	auto tss = new long[][]( 1 + s.length, CS.length );
	foreach_reverse( i, c; s )
	{
		foreach( j; 0L .. tss[ i ].length.signed )
		{
			tss[ i ][ j ] = tss[ i + 1 ][ j ] + ( j == CS[ c ] );
		}
	}
	
	auto ans = 0L;
	foreach( i; 0L .. tss.length.signed - 3 )
	{
		foreach( j; i + 1 .. tss.length.signed - 2 )
		{
			if( s[ i ] == s[ j ] ) continue;
			auto d = j - i;
			auto c = CS.length.signed - CS[ s[ i ] ] - CS[ s[ j ] ];
			ans += tss[ j + 1 ][ c ] - ( j + d < s.length && CS[ s[ j + d ] ] == c );
		}
	}
	return ans;
}


Measured memory_bytes: 2856
n = input()

def bitlist(n, a, b):
  res = []
  for i in range(2**n):
    pattern = []
    for j in range(n):
      if (i >> j) & 1:
        pattern.insert(0, a)
      else:
        pattern.insert(0, b)
    res.append(pattern)
  return res

m = len(n)
lst = bitlist(m-1, "+", "")
SUM = 0
for i in range(2**(m-1)):
  calc = ""
  for j in range(m-1):
    calc += n[j] + lst[i][j]
  calc += n[-1]
  spl = calc.split('+')
  for c in spl:
    SUM += int(c)
print(SUM)

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

int main(){
  vector<int> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  sort(vec.begin(),vec.end());
  if(vec.at(0) == 5 &&
      vec.at(1) == 5 &&
        vec.at(2) == 7 ){
    cout << "YES" << endl;
    return 0;
  }
  
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

struct Node{
    int to;
};

typedef vector<int> Edge;
typedef vector<Edge> Graph;

int N;
int A[100000];
Graph graph;
bool ok;

int rec(int v, int prev){
    int sum = 0;
    int mx = 0;
    REP(i, graph[v].size()){
        if(graph[v][i] == prev)continue;
        int c = rec(graph[v][i], v);
        sum += c;
        mx = max(mx, c);
    }
    if(sum == 0){
        return A[v];
    }
    int up = 2 * A[v] - sum;

    // check
    ok = ok && (up >= 0);
    ok = ok && (2*max(mx,up) <= up+sum);


    // cout << "v:" << v << ",A[v]:" << A[v] << ",up:" << up << ",ok:" << ok << endl;

    return up;
}

int main(){
    cin >> N;
    REP(i, N)cin >> A[i];
    graph.assign(N, Edge());
    REP(i, N-1){
        int a, b;
        cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    ok = true;
    int res = rec(0, -1);
    ok = ok && (res == (graph[0].size()==1 ? A[0] : 0));

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


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

int main()
{
    int a[300009], n, i;
    cin >> n;

    for(i = 0; i < 3*n; i++)
        cin >> a[i];

    sort(a, a+3*n);

    long long ans = 0;
    for(i = 3*n-2; i >= n; i -=2)
        ans = ans + a[i];

    cout << ans;
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define int long long
 
struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};
 
signed main() {
    int n, m;
    while (cin >> n >> m) {
        uf_tree uf(n);
        vector<int> p(n), pos(n);
        rep(i, n) cin >> p[i], --p[i], pos[p[i]] = i;
        rep(i, m) {
            int a, b;
            cin >> a >> b;
            --a; --b;
            uf.unite(a, b);
        }
        int cnt = 0;
        rep(i, n) if (uf.is_same(i, pos[i])) ++cnt;
        cout << cnt << endl;
    }
    
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <utility>
#include <map>
const int N=1e5+5;
typedef long long ll;
using namespace std;

int main() {
	string s,t;
	cin >> s;
	cin >> t;
	bool ok=1;
	for (int i=0; i<s.length(); i++) {
		if (s[i]!=t[i]) ok=false;
	}
	if (ok) cout << "Yes";
	else cout << "No";
}



Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

using LL = long long;
const int kN = 200000 + 5;
int n;
LL L;
int go[kN][2];
int root = 1, tot = 2;
int sg[kN];
int depth[kN];

std::string show(int d)
{
    std::string ret;
    while (d) {
        ret.push_back(d % 2 + '0');
        d /= 2;
    }
    std::reverse(ret.begin(), ret.end());
    return ret;
}

LL entire_sg(LL d)
{
    if (d < 0) return 0;
    if (d == 0) return 1;
    // return sg[d];
    d += 1;
    int c = 0;
    while (~d & 1) ++ c, d >>= 1;
    return 1LL << c;
}

int main()
{
    sg[0] = 1;
    for (int i = 1; i <= 1000; ++ i) {
        std::set<int> set;
        for (int j = 0; j < i; ++ j) {
            int val = 0;
            for (int k = j; k < i; ++ k)
                val ^= sg[k];
            set.emplace(val);
        }
        int x = 1;
        while (set.count(x)) ++ x;
        sg[i] = x;
        // printf("sg[%d] = %d, %s\n", i, x, show(i + 1).c_str());
    }
    // return 0;

    scanf("%d%lld", &n, &L);
    for (int i = 0; i < n; ++ i) {
        static char s[kN];
        scanf("%s", s);
        int u = root;
        for (int j = 0; s[j]; ++ j) {
            int c = s[j] - '0';
            if (go[u][c] == 0) {
                go[u][c] = tot ++;
                depth[go[u][c]] = depth[u] + 1;
            }
            u = go[u][c];
        }
    }

    LL val = 0;
    for (int u = tot - 1; u > 0; -- u) {
        if (go[u][0] + go[u][1] == 0) continue;
        for (int c = 0; c < 2; ++ c) {
            if (go[u][c] == 0) {
                // printf("u = %d, c = %d, depth[u] = %d\n", u, c, depth[u]);
                val ^= entire_sg(L - depth[u] - 1);
                // printf("got %lld, %lld\n", L - depth[u] - 1, entire_sg(L - depth[u] - 1));
            }
        }
    }
    puts(val ? "Alice" : "Bob");
}


Measured memory_bytes: 1536
n = int(input()) #参加人数
d,x = map(int,input().split()) #日数、残り
ass = [int(input()) for _ in range(n)] #係数
thirst= ass.copy()

ate = n #1日目

for i in range(2,d+1): #毎日、食べた人数を足していく
  for j,a in enumerate(ass):
    t = thirst[j]
    t -= 1
    if t == 0:
      ate += 1
      thirst[j] = a
    else: thirst[j] = t

print(ate + x) #元々の個数


Measured memory_bytes: 3064
#include<iostream>
#include <string>
using namespace std;
int main(){
  string input;
  cin>>input;
  int size=input.size(),flag=0;
  for (int i=0;i<size;i=i+2) {
    if(input[i]!='h' || input[i+1]!='i')
      flag=1;
  }
  if (flag) {
    printf("No");
  }
  else
  printf("Yes");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N){
        cin>>a[i]; a[i]--;
    }

    int cur=0;
    for(int i=1;i<=N-1;i++){
        cur=a[cur];
        if(cur==1){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,q;
    cin >> n;
    vector<long long> s(n);
    for(int i=0 ;i<n;i++){
        cin>> s[i];
    }
    cin >>q;
    int ans=0;
    for(int i=0; i<q;i++){
        long long t;
        cin >> t;
        for(int j=0 ;j<n;j++){
            if(s[j]==t){
                ans++;
                break;
            }
        }
    }
    cout <<ans<<endl;
    return 0;
}
    


Measured memory_bytes: 3128
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

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

    vector<ll> d(k);
    rep(i, k) cin >> d[i];

    while (q--) {
        int n, x, m;
        cin >> n >> x >> m;
        x %= m;

        int ans = n - 1;

        int L = n / k;
        ll add = 0;
        rep(i, k) {
            int ct = L;
            if (i == k - 1) {
                --ct;
                if ((n - 1) % k != k - 1) ++ct;
            } else {
                int r = (n - 1) % k;
                if (r != k - 1 && i < r) ++ct;
            }
            // printf(" %d : %d\n", i, ct);

            ll b = d[i] % m;
            if (b == 0) ans -= ct;
            add += b * ct;
        }
        ans -= (add + x) / m;

        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const ll MOD = (ll)1e9 + 7LL;
const int MAX_N = 2*(int)1e5 + 5;

ll fact[MAX_N], rfact[MAX_N];

ll mod_pow(ll n, ll p, ll M){
	ll res = 1LL;
	while(p > 0LL){
		if (p % 2LL == 1LL){
			res = (res * n) % M;
		} // end if
		n = (n * n) % M;
		p >>= 1;
	} // end while
	return res;
}

void initFact(void){
	memset(fact, 0LL, sizeof(fact));

	fact[0] = 1LL;
	for (int i = 1; i < MAX_N; ++i){
		fact[i] = (fact[i-1] * (ll)i) % MOD;
	} // end for
}

ll comb(ll n, ll r){
	if (n < r) return 0LL;
	if (r == 0LL || n == r) return 1LL;

	ll deno = (fact[r] * fact[n-r]) % MOD;
	ll res = (fact[n] * mod_pow(deno, MOD - 2LL, MOD)) % MOD;

	return res;
}

int main()
{
	initFact();
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll N, M; cin >> N >> M;

	ll orgM = M;
	map<int,int> cnt; cnt.clear();

	for (int i = 2; i * i <= orgM; ++i){
		if (M % (ll)i == 0LL){
			while(M > 0LL && (M % (ll)i == 0LL)){
				++cnt[i];
				M /= (ll)i;
			} // end while
		} // end if
	} // end rep
	
	if (M != 1LL){
		++cnt[(int)M];
	} // end if

	ll res = 1LL;

	map<int,int>::iterator it = cnt.begin();
	for (; it != cnt.end(); ++it){
		int p = (*it).first;
		int b = (*it).second;
		res = (res * comb((ll)b + N - 1LL, (ll)b)) % MOD;
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;

const int N=30;
vector<int>rot_l(vector<int>&v) {
	int k=v[1];
	v[1]=v[2];
	v[2]=v[4];
	v[4]=v[3];
	v[3]=k;
	return v;
}
vector<int>rot_u(vector<int>&v) {
	int k=v[1];
	v[1]=v[0];
	v[0]=v[4];
	v[4]=v[5];
	v[5]=k;
	return v;
}
vector<int>zero_top(vector<int>v) {
	{
		int x = find(v.begin(), v.end(), 0) - v.begin();
		if (x == 0) {

		}
		else if (x == 1) {
			rot_u(v);
			rot_u(v);
			rot_u(v);
		}
		else if (x == 5) {
			rot_u(v);
			rot_u(v);
			
		}
		else if (x == 4) {
			rot_u(v);
		}
		else if (x == 2) {
			rot_l(v); 
			rot_u(v);
			rot_u(v);
			rot_u(v);
		}
		else if (x == 3) {
			rot_l(v);
			rot_u(v);
		}
	}
	assert(v[0]==0);
	return v;
}
bool same(vector<int>l, vector<int>r) {
	l=zero_top(l);
	r=zero_top(r);
	for (int i = 0; i < 4; ++i) {
		if(l==r)return true;
		rot_l(l);
	}
	return false;
}

int main() {
	while (true) {
		int N; cin >> N;if(!N)break;
		vector<vector<int>>cubes;
		for (int i = 0; i < N; ++i) {
			string color_st = "MRYBGC";
			vector<int>v;
			for (int j = 0; j < 6; ++j) {
				string st; cin >> st;
				int k = color_st.find(st[0]);
				v.push_back(k);
			}
			bool ok=true;
			for (auto cube : cubes) {
				if(same(cube,v))ok=false;
			}
			if (ok) {
				cubes.emplace_back(v);
			}
		}
		cout<<N-cubes.size()<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3096
import heapq
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]

AB.sort(reverse=True)
works=[]
heapq.heapify(works)
ans=0
AB=AB+[[0,0]]
for i in range(1,M+1):
  day=M-i
  latest=i
  while len(AB)>=2 and AB[-2][0]<=latest:
    a,b=AB.pop(-2)
    heapq.heappush(works,-b)
  if not works:
    continue
  ans-=heapq.heappop(works)

print(ans)


Measured memory_bytes: 28272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 998244353;

int main() {
	
	int n;
	cin >> n;
	vi a(n);
	ll sum = 0;
	map<int, int>mp;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
		mp[a[i]]++;
	}

	int q;
	cin >> q;
	while (q--) {
		int b, c;
		cin >> b >> c;
		sum += (ll)mp[b] * (c - b);
		cout << sum << endl;
		mp[c] += mp[b];
		mp[b] = 0;
	}
}

Measured memory_bytes: 8008
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	vector<int>a(10), b(10);
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 10; i++)cin >> b[i];
	sort(a.begin(), a.end(), greater<int>());
	sort(b.begin(), b.end(), greater<int>());
	cout << a[0] + a[1] + a[2] << " " << b[0] + b[1] + b[2] << endl;


	return 0;
}

Measured memory_bytes: 3040
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)
tmp = A[0]
for i in range(1, N):
    if tmp + 1== A[i]:
        ans += C[tmp - 1]
    tmp = A[i]

print (ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  FOR(a, 1, 3501) FOR(b, 1, 3501){
    if(4*a*b-N*(a+b) <= 0) continue;
    if(N*a*b%(4*a*b-N*(a+b)) == 0){
      cout << a << " " << b << " " << N*a*b/(4*a*b-N*(a+b)) << "\n";
      return 0;
    }
  }

  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int d[222][222],d2[222][222];
bool used[1111];
PPI es[1111];

int main(){
	cin.sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	rep(i,222)rep(j,222)d[i][j]=(i==j?0:INF);
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--; b--;
		d[a][b]=d2[a][b]=c;d[b][a]=d2[b][a]=c;
		//es[i]=PPI(P(a,b),c);
	}
	rep(k,n)rep(i,n)rep(j,n)minch(d[i][j],d[i][k]+d[k][j]);
	int res=m;
	rep(a,n)repl(b,a+1,n){
		if(d[a][b]==d2[a][b]){
			res--;
			d2[a][b]=d2[b][a]=-1;
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<15;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<ll> A(N);
  int negnum = 0;
  bool zero = false;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    if (A[i] < 0) {
      negnum++;
      A[i] = -A[i];
    }
    if (A[i] == 0) zero = true;
  }
  ll ans = accumulate(A.begin(), A.end(), 0LL);
  if (not zero && negnum%2 == 1){
    sort(A.begin(), A.end());
    ans -= 2*A[0];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("Hello World");
            return;
        } else System.out.println(sc.nextInt() + sc.nextInt());
    }
}


Measured memory_bytes: 27092
import java.util.Scanner;
class Main {


public static void main(String args[]) {
Scanner s=new Scanner(System.in);
long ans,max;
int i,j,a[][];
int t=s.nextInt();
a=new int[t][2];
for(j=0;j<2;j++)
{for(i=0;i<t;i++)
a[i][j]=s.nextInt();
}
ans=a[0][0];
for(i=0;i<t;i++) ans=ans+a[i][1];
max=ans;
for(i=1;i<t;i++)
{
    ans=ans-a[i-1][1]+a[i][0];
    if(ans>max) max=ans;
}
System.out.println(max);
}
}



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

int main(){
 
  string w;
  cin >> w;
  string count;
  
  for (int i = 0; i < w.size(); i++) {
    if (count.size() == 0) {
      count.push_back(w.at(i));
    } else {
      int c = 0;
      for (int j = 0; j < count.size(); j++) {
        if (w.at(i) == count.at(j) && c == 0) {
          count.at(j) = '0';
          c++;
        }
      }
      if (c == 0) {
        count.push_back(w.at(i));
      }
    }
  }
  
  int check = 0;
  for (int i = 0; i < count.size(); i++) {
    if (count.at(i) != '0') {
      check++;
    }
  }
  
  if (check > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
      


  
  return 0;
}
    


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	}
	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
}


Measured memory_bytes: 23892
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);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; }

int main() {
  int n;
  cin >> n;
  double sum = 0;
  rep(i, n){
    double x; string u;
    cin >> x >> u;
    if(u == "JPY") sum += x;
    else sum += x * 380000;
  }
  cout << sum << ln;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n,i,ans;
  int s[100];

  for(;;){
    int max=0,min=1000,sum=0;
    scanf("%d", &n);
    if(n==0) break;

    for(i=0;i<n;i++){
      scanf("%d", &s[i]);
      if(s[i]>max) max=s[i];
      if(s[i]<min) min=s[i];
      sum+=s[i];
    }
    ans=(sum-max-min)/(n-2);
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 600
S = input()
pos = []
before = 'R'
S+='z'
cnt = 0
for i,s in enumerate(S):
  if s == before:
    cnt += 1
  else:
    pos.append(cnt)
    cnt = 1
  before = s
R = pos[0:][::2]
L = pos[1:][::2]
res = [0 for i in range(len(S)-1)]
pos = -1
for i in range(len(R)):
  pos += R[i]
  if R[i] != L[i]:
    if (R[i] + L[i])%2==0:
      res[pos] = (R[i] + L[i])//2
      res[pos+1] = (R[i] + L[i])//2
    else:
      if R[i] > L[i]:
        if (10**100-(R[i] - 1))%2==0:
          res[pos] = (R[i] + L[i])//2+1
          res[pos+1] = (R[i] + L[i])//2
        else:
          res[pos] = (R[i] + L[i])//2
          res[pos+1] = (R[i] + L[i])//2+1
      else:
        if (10**100-(L[i] - 1))%2==0:
          res[pos] = (R[i] + L[i])//2
          res[pos+1] = (R[i] + L[i])//2+1
        else:
          res[pos] = (R[i] + L[i])//2+1
          res[pos+1] = (R[i] + L[i])//2
  else:
    res[pos] = R[i]
    res[pos+1] = L[i]
  pos += L[i]
print(" ".join(list(map(str,res))))

Measured memory_bytes: 52276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  ll N,A,B;
  cin >> N >> A >> B;
  if(!((B-A)%2)) cout << (B-A)/2 << endl;
  else {
    ll X=min(A-1,N-B);
    cout << X+1+(B-A-1)/2 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    int p[25]={};
    scanf("%d",&n);
    REP(i,n)scanf("%d",&p[i]);
    int ans=0;
    for(int i=1;i<n-1;i++){
        int a=p[i-1];
        int b=p[i];
        int c=p[i+1];
        if((a<b&&b<c)||(a>b&&b>c))ans++;
    }
    printf("%d\n",ans);
    return 0;
}

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

int r, c, tsum;

int main() {
    cin >> r >> c;
    int a[r*c], rsum[r], csum[c];
    for (int i=0; i<r*c; i++) cin >> a[i];
    for (int i=0; i<r; i++) rsum[i]=0;
    for (int i=0; i<c; i++) csum[i]=0;
    for (int i=0; i<r; i++) {
        for (int j=0; j<c; j++) {
            rsum[i]+=a[i*c+j];
            csum[j]+=a[i*c+j];
        }
    }
    for (int i=0; i<r; i++) {
        for (int j=0; j<c; j++) cout << a[i*c+j] << " ";
        cout << rsum[i] << endl;
    }
    for (int j=0; j<c; j++) cout << csum[j] << " ";
    for (int j=0; j<c; j++) tsum+=csum[j];
    cout << tsum << endl;
}


Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static long n;
    static string[] s;
    static HashSet<string> hs = new HashSet<string>();

    static void Main(string[] args)
    {
        var nabc = Console.ReadLine().Split(' ');
        n = long.Parse(nabc[0]);
        var a = long.Parse(nabc[1]);
        var b = long.Parse(nabc[2]);
        var c = long.Parse(nabc[3]);
        root = new string[n];

        s = new string[n];

        for (var i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }

        var idx = 0L;

        Sub1(idx, a, b, c);

        if (goal == false) Console.WriteLine("No");
    }

    static bool goal = false;
    static string[] root;

    static void Sub1(long idx, long a, long b, long c)
    {
        if (hs.Contains(string.Concat(idx + "_" + a + "_" + b + "_" + c))) return;
        if (goal) return;

        if (idx == n)
        {
            goal = true;
            Console.WriteLine("Yes");
            foreach (var k in root)
            {
                Console.WriteLine(k);
            }
            return;
        }

        if (s[idx] == "AB")
        {
            if (a < b)
            {
                if (b != 0) { root[idx] = "A"; Sub1(idx + 1, a + 1, b - 1, c); }
                if (a != 0) { root[idx] = "B"; Sub1(idx + 1, a - 1, b + 1, c); }
            }
            else
            {
                if (a != 0) { root[idx] = "B"; Sub1(idx + 1, a - 1, b + 1, c); }
                if (b != 0) { root[idx] = "A"; Sub1(idx + 1, a + 1, b - 1, c); }
            }
        }
        else if (s[idx] == "BC")
        {
            if (b < c)
            {
                if (c != 0) { root[idx] = "B"; Sub1(idx + 1, a, b + 1, c - 1); }
                if (b != 0) { root[idx] = "C"; Sub1(idx + 1, a, b - 1, c + 1); }
            }
            else
            {
                if (b != 0) { root[idx] = "C"; Sub1(idx + 1, a, b - 1, c + 1); }
                if (c != 0) { root[idx] = "B"; Sub1(idx + 1, a, b + 1, c - 1); }
            }
        }
        else if (s[idx] == "AC")
        {
            if (a < c)
            {
                if (c != 0) { root[idx] = "A"; Sub1(idx + 1, a + 1, b, c - 1); }
                if (a != 0) { root[idx] = "C"; Sub1(idx + 1, a - 1, b, c + 1); }
            }
            else
            {
                if (a != 0) { root[idx] = "C"; Sub1(idx + 1, a - 1, b, c + 1); }
                if (c != 0) { root[idx] = "A"; Sub1(idx + 1, a + 1, b, c - 1); }
            }
        }

        hs.Add(string.Concat(idx + "_" + a + "_" + b + "_" + c));
    }
}


Measured memory_bytes: 123500
import sys
from collections import defaultdict
from math import factorial
input = sys.stdin.buffer.readline
mod = 10**9+7

# comb init
nmax = 10 ** 5 + 2  # change here
fac = [0] * (nmax + 1)
finv = [0] * (nmax + 1)
inv = [0] * (nmax + 1)
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def comb(n, r):
    if n < r:
        return 0
    else:
        return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod


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

pos = defaultdict(lambda: -1)
for i in range(N+1):
    if pos[a[i]] == -1:
        pos[a[i]] = i
    else:
        same = (pos[a[i]], i)
        break

for k in range(1, N+2):
    print((comb(N+1, k) - comb(same[0] + (N-same[1]), k-1))%mod)


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

int A,B,C;

int main()
{
    scanf("%d%d%d",&A,&B,&C);
    printf("%d\n",min(A,min(B,C)) + A + B + C -
                  min(A,min(B,C)) -
                  max(A,max(B,C)));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;
int main()
{
	while (true)
	{
		int n, r;
		cin >> n >> r;
		if (!n && !r)
			break;
		stack<int> S;
		stack<int> s1;
		stack<int> s2;
		for (int i = 1; i <= n; i++)
			S.push(i);
		for (int i = 1; i <= r; i++)
		{
			int p, c;
			cin >> p >> c;
			for (int i = 1; i <= p - 1; i++)
			{
				int t = S.top();
				S.pop();
				s1.push(t);
			}
			for (int i = 1; i <= c; i++)
			{
				int t = S.top();
				S.pop();
				s2.push(t);
			}
			for (int i = 1; i <= p - 1; i++)
			{
				int t = s1.top();
				s1.pop();
				S.push(t);
			}
			for (int i = 1; i <= c; i++)
			{
				int t = s2.top();
				s2.pop();
				S.push(t);
			}
		}
		cout << S.top() << endl;
	}
}


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

using namespace std;

using ll = long long int;

const ll MAXN=1e6+7;
const ll MOD=1e9+7;

ll fast_power(ll base,int exp){
    if (exp==0) return 1ll;
    auto temp=fast_power(base,exp/2);
    if (exp%2) return temp*temp%MOD*base%MOD;
    else return temp*temp%MOD;
}

int main(){
    int N;
    scanf("%d",&N);
    ll rev=(MOD-fast_power(9,N));
    ll ans=(((fast_power(10,N)+rev)%MOD+rev)%MOD+fast_power(8,N))%MOD;

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

    return 0;
}

Measured memory_bytes: 1732