akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    FOR(i, 0, n) {
        cin >> a[i];
    }
    vector<long long> diff(n + 1);
    vector<long long> diff2(n + 1);
    diff[0] = 0;
    diff2[0] = 0;
    partial_sum(a.begin(), a.end(), diff.begin() + 1);
    FOR(i, 0, n) {
        diff2[i + 1] = diff2[i] + max(0LL, a[i]);
    }

    long long maxx = -1;
    for (int i = 0; i + k <= n; i++) {
        long long d = diff[i + k] - diff[i];
        long long d1 = diff2[i];
        long long d2 = diff2[n] - diff2[i+k];
        maxx = max(maxx, max(0LL, d) + d1 + d2);

    }

    cout << maxx << endl;

    return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<math.h>
#include <iomanip>

using namespace std;

int main(){
  long double a,b,x;
  long double y;
  cin >> a >> b >> x;
  if(x >= a * a * b / 2) y = atan(2*b/a-2*x/a/a/a);
    else y = atan((a*b*b)/(2*x));
      cout << setprecision(10) << y * 180 / 3.14159265358979323;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var L = Lcm(N, M);
            var S = ReadLine();
            var T = ReadLine();
            var dct=new Dictionary<long,char> ();
            for (var i = 0; i < N; ++i)
            {
                var k = (L / N) * i + 1;
                dct[k] = S[i];
            }
            for (var i = 0; i < M; ++i)
            {
                var k = (L / M) * i + 1;
                if (dct.ContainsKey(k))
                {
                    if (dct[k] != T[i])
                    {
                        WriteLine(-1);
                        return;
                    }
                }
            }
            WriteLine(L);
            //Out.Flush();
        }
        static long Gcd(long x, long y) => y == 0 ? x : Gcd(y, x % y);
        static long Lcm(long x, long y) => x * y / Gcd(x, y);
    }
}

Measured memory_bytes: 19936
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,now=1000;cin>>n;
  V<ll> v(n);rep(i,0,n)cin>>v[i];

  rep(i,0,n-1){
    if(v[i]<v[i+1]){
      ll num=now/v[i];
      now-=num*v[i];
      now+=num*v[i+1];
    }
  }
  cout<<now<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

int main() {
	ll x;
	cin >> x;

	int y = 0;
	ll bank = 100;
	while (bank < x) {
		bank += bank*0.01;
		y += 1;
	}

	cout << y << endl;

	return 0;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
g = [[] for _ in range(N+1)]
for a,b in AB:
    g[a].append(b)
    g[b].append(a)
 
cnt = [0] * (N+1)
for p,x in PX:
    cnt[p] += x

def dfs(v, p, add):
    cnt[v] += add
    for nv in g[v]:
        if nv == p:
            continue
        dfs(nv, v, cnt[v])

dfs(1, 0, 0)

print(' '.join(map(str, cnt[1:])))    


Measured memory_bytes: 285892
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll a,b,c,x;
	cin>>a>>b>>c>>x;
	ll co=0;
	for(ll i=0; i<=a; i++){
		for(ll j=0; j<=b; j++){
			for(ll k=0; k<=c; k++){
				if(i*500+j*100+k*50==x){
					co++;
				}

			}
		}
	}
	cout<<co;

}

Measured memory_bytes: 3480
a,b,c,x = 4.times.map { gets.to_i }

cnt = 0

(0..a).each do |n|
  (0..b).each do |m|
    (0..c).each do |l|
      cnt += 1 if 500 * n + 100 * m + 50 * l == x
    end
  end
 end

puts cnt

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

int main()
{
    char s[4];
    for (int i = 0; i < 4; i++)
    {
        cin >> s[i];
    }

    int a = s[0] - '0';
    int b = s[1] - '0';
    int c = s[2] - '0';
    int d = s[3] - '0';

    if (a + b + c + d == 7)
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
    else if (a + b + c - d == 7)
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
    else if (a + b - c + d == 7)
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
    else if (a + b - c - d == 7)
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
    else if (a - b + c + d == 7)
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
    else if (a - b - c + d == 7)
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
    else if (a - b + c - d == 7)
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
    else if (a - b - c - d == 7)
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
vll a;
vi G[5005];

int num[5005];
ll dp[5005][5005][2]; // vで条件を満たすようにi辺取り除いたときvの連結成分の和の最小値(j=1なら全ての成分が正である)

void dfs(int v, int p){
  vi child;
  for(auto &nv: G[v]){
    if(nv==p) continue;
    dfs(nv,v);
    child.push_back(nv);
  }
  
  dp[v][0][(a[v]>0)]=a[v];
  
  for(auto &nv: child){
    vvll sub(num[v]+num[nv]+2, vll(2,LINF));
    for(int i=0; i<=num[v]; i++){
      for(int j=0; j<=num[nv]; j++){
        rep(k1,2) rep(k2,2){
          ll v1=dp[v][i][k1], v2=dp[nv][j][k2];
          if(max(v1,v2)==LINF) continue;
          chmin(sub[i+j][k1&k2], v1+v2);
          if(k2==1 || v2<0) chmin(sub[i+j+1][k1], v1);
        }
      }
    }
    num[v]+=num[nv]+1;
    for(int i=0; i<=num[v]; i++) for(int j=0; j<2; j++){
      dp[v][i][j]=sub[i][j];
    }
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n;
  a.resize(n);
  rep(i,n) cin>>a[i];
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  rep(i,n+1) rep(j,n+1) rep(k,2) dp[i][j][k]=LINF;
  dfs(0,-1);
  
  ll ans=LINF;
  // rep(i,n) cout<<dp[0][i][0]<<' ';
  // cout<<endl;
  // rep(i,n) cout<<dp[0][i][1]<<' ';
  // cout<<endl;
  
  rep(i,n){
    if(dp[0][i][0]<0 || dp[0][i][1]!=LINF){
      ans=i;
      break;
    }
  }
  
  cout<<ans<<endl;
  
}

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

bool is_kaibun(string s)
{
    string s1 = s;
    string s2 = s;
    reverse(s2.begin(), s2.end());
    if (s1 == s2)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    string s, s1, s2;
    int N;
    bool result = false;

    cin >> s;
    N = s.length();
    s1 = s.substr(0, (N - 1) / 2);
    s2 = s.substr((N + 3) / 2 - 1);

    if (is_kaibun(s))
    {
        if (is_kaibun(s2))
        {
            if (is_kaibun(s1))
            {
                result = true;
            }
        }
    }

    if(result){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[1000];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  int maxs = 0;
  int ans = 0;
  for(int i=0;i<n;i++){
    if(maxs<=h[i]){
      ans++;
      maxs = h[i];
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main(int argc, const char *argv[])
{
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int max_dist = a[1] - a[0], sum = max_dist;
  for (int i = 2; i < n; i++) {
    sum += a[i] - a[i - 1];
    max_dist = max(max_dist, a[i] - a[i - 1]);
  }

  sum += a[0] + (k - a[n - 1]);
  max_dist = max(max_dist, a[0] + (k - a[n - 1]));

  cout << sum - max_dist << "\n";

  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(void){
    int A,B,C,D,E,x,y,cou=0,v[3];
    char S[3],s[3],X,Y;
    scanf("%d %d %d",&A,&B,&C);
    if((A>B)&&(A>C)){
        printf("%d",B+C);
    }else if((B>C)&&(B>A)){
        printf("%d",A+C);
    }else{
        printf("%d",A+B);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {
	int g = gcd(a, b);
	return a / g * b;
}

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

	int N, X;
	cin >> N >> X;

	cout << 3 * (N - gcd(N, X)) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
 
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(y,x%y);
}
 
ll lcm(ll x, ll y){
	return (x*y/gcd(x,y));
}
 
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int n;
	cin >> n;
	int a=0;

	if(n/100>0&&n/100<=12) a++;
	//cout << a << endl;
	if(n%100>0&&n%100<=12) a+=10;
	//cout << a << endl;

	if(a==0) cout << "NA" << endl;
	else if(a==1) cout << "MMYY" << endl;
	else if(a==10) cout << "YYMM" << endl;
	else if(a==11) cout << "AMBIGUOUS" << endl;
	
/////////////////////////////////////////////
}

Measured memory_bytes: 256
#include <deque>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

const int MAXN = 100100;

int n;

void load() {
	scanf("%d", &n);
}

deque<ll> D;
int bio[MAXN];

void solve() {
	D.push_front(1);
	FOR(i, MAXN) bio[i] = 1e9;
	bio[1] = 1;
	while (!D.empty()) {
		ll x = D.back(); D.pop_back();
		ll sus1 = (x + 1) % n;
		ll sus2 = (x * 10) % n;
		if (bio[sus2] > bio[x]) {
			D.push_back(sus2);
			bio[sus2] = bio[x];
		}
		if (bio[sus1] > bio[x] + 1) {
			D.push_front(sus1);
			bio[sus1] = bio[x] + 1;
		}
	}
	printf("%d\n", bio[0]);
}

int main() {
	load();
	solve();
	return 0;
}


Measured memory_bytes: 1024
// 公式の解説は意味不明だがこれがわかりやすかった https://qiita.com/hkrutknouch/items/29568f18163d5d39ac10

package main
import "fmt"
func main(){
	var N int
	fmt.Scan(&N)
	A := make([]int, N+2)
	A[0], A[N+1] = 0, 0
	for i:=0; i<N; i++{
		fmt.Scan(&A[i+1])
	}
	SUM:=0
	Dif := []int{}
	for i:=1; i<N+2; i++{
		Dif = append(Dif, abs(A[i]-A[i-1]))
		SUM+=Dif[i-1]
	}
	for i:=1; i<N+1;i++{
		fmt.Println(SUM+abs(A[i+1] - A[i-1]) - abs(Dif[i-1]+Dif[i]))
	}
}

func abs(x int)int{
	if x < 0{
		x*=-1
	}
	return x
}

Measured memory_bytes: 8444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	final static int[][] serials = { { 18680908, 1868, 9, 8 },
			{ 19120730, 1912, 7, 30 }, { 19261225, 1926, 12, 25 },
			{ 19890108, 1989, 1, 8 } };

	final static String[] eras = { "pre-meiji", "meiji", "taisho", "showa",
			"heisei" };

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int[] serial = toSerial(line.split(" "));
			String era = "";

			for (int i = 0; i < 5; ++i) {
				if (i < 4) {
					if (serial[0] < serials[i][0]) {
						era = eras[i];
					}
				} else {
					era = eras[i];
				}
				if (!era.isEmpty()) {
					if (i > 0) {
						serial[1] -= serials[i - 1][1] - 1;
						era += " " + serial[1] + " " + serial[2] + " "
								+ serial[3];
					}
					break;
				}
			}
			System.out.println(era);
		}

	}

	static int[] toSerial(String[] units) {
		int y, m, d;
		y = Integer.parseInt(units[0]);
		m = Integer.parseInt(units[1]);
		d = Integer.parseInt(units[2]);
		return new int[] { y * 10000 + m * 100 + d, y, m, d };
	}
}

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

int main(){
  int num;
  int maxCnt = 0;
  string str;
  map<string,int> mp;
  vector<string> vec;
  
  cin >> num;
  
  for(int i = 0; i < num; i++){
    cin >> str;
    mp[str]++;
    
    maxCnt = max(maxCnt, mp[str]);
  }
  
  for(auto x : mp){
    if(x.second == maxCnt){
      vec.push_back(x.first);
    }
  }
  
  for(int i = 0; i < vec.size(); i++) cout << vec.at(i) << endl;
}

Measured memory_bytes: 26868
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
   int N; cin >> N;
   vector<int> a(N);
   int cnt2 = 0;
   int cnt4 = 0;
   rep(i,N){
       cin >> a[i];
       if(a[i] % 2 == 0) cnt2++;
       if(a[i] % 4 == 0) cnt4++;
   }
   cnt2 -= cnt4;
   bool ok = false;

   if(N/2 <= cnt4) ok = true;
   else{
       int cnt = ((N/2) - cnt4 - 1) * 2 + (int)(N % 2 == 1) + 2;
       if(cnt2 >= cnt) ok = true;
   }

   if(ok) cout << "Yes" << endl;
   else cout << "No" << endl;

}


Measured memory_bytes: 640
n=int(input())
s=input()
cnt1=0
for i in range(n):
    if s[i]=="(":
        cnt1+=1
    else:
        if cnt1>0:
            cnt1-=1
        else:
            pass

cnt2=0
for i in range(n-1,-1,-1):
    if s[i]==")":
        cnt2+=1
    else:
        if cnt2>0:
            cnt2-=1
        else:
            pass

print(cnt2*"("+s+cnt1*")")


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";
const ld pie = 3.14159265358979 ;

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ; cin >> n ;

    vld v ( n ) ;
    for ( int i=0 ; i <n ; i++ ) cin >> v[i] ;

    sort ( all ( v ) ) ;

    ld s = ( v[0] + v[1] ) / 2 ;
    for ( int i=2 ; i < n ; i++ )
    {
        s = ( s + v[i] ) / 2 ;
    }

    pp ( s ) ;
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a_list = input().split()
a_list = [int(x) for x in a_list]

zentori = 3**n

a_list_2 = [x%2 for x in a_list]
from collections import Counter

counter = Counter(a_list_2)

bad_tori = (2**counter[0])

print(zentori-bad_tori)

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

int main() {
    string s;
    cin >> s;
    int sum = 0;
    bool nine = false;
    if (s.size() == 1) sum += s.at(0) - '0';
    for (int i = 1; i < s.size(); i++) {
        int d1 = s.at(i) - '0';
        int d0 = s.at(i-1) - '0';
        if (d1 != 9) {
            sum += d0 - 1;
            sum += 9 * (s.size() - i);
            break;
        }
        sum += d0;
        if (i == s.size()-1) sum += d1;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const ll INF=0x3f3f3f3f3f3f3f3f;

#define lson o<<1
#define rson o<<1|1
#define Lson L,mid,lson
#define Rson mid+1,R,rson
const int maxn=1e5+7;
int n;
vc<PII> event[maxn];
ll mi[maxn<<2];
ll lz[maxn<<2];
inline void pushdown(int o)
{
	if(lz[o]!=INF)
	{
		mi[lson]=min(mi[lson],lz[o]);
		mi[rson]=min(mi[rson],lz[o]);
		lz[lson]=min(lz[lson],lz[o]);
		lz[rson]=min(lz[rson],lz[o]);
		lz[o]=INF;
	}
}
inline void pushup(int o)
{
	mi[o]=min(mi[lson],mi[rson]);
}
void update(int l,int r,ll val,int L=1,int R=n,int o=1)
{
	if(l<=L&&r>=R)
	{
		mi[o]=min(mi[o],val);
		lz[o]=min(lz[o],val);
		return;
	}
	pushdown(o);
	int mid=L+R>>1;
	if(l<=mid) update(l,r,val,Lson);
	if(r>mid) update(l,r,val,Rson);
	pushup(o);
}
ll query(int p,int L=1,int R=n,int o=1)
{
	if(L==R) return mi[o];
	int mid=L+R>>1;
	pushdown(o);
	if(p<=mid) return query(p,Lson);
	else return query(p,Rson);
}

int main()
{
	memset(lz,0x3f,sizeof(lz));
	memset(mi,0x3f,sizeof(mi));
	int m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int l,r,c;
		scanf("%d%d%d",&l,&r,&c);
		event[l].push_back(make_pair(r,c));
	}
	update(1,1,0);
	for(int i=1;i<n;i++)
	{
		ll val=query(i);
		for(auto& v:event[i])
			update(i,v.first,val+v.second);
	}
	ll ans=query(n);
	if(ans==INF) ans=-1;
	printf("%lld\n",ans);
}


Measured memory_bytes: 11904
#include<vector>
#include<algorithm>
#include<cstdint>
#include<queue>
#include<iostream>

struct TreeQuery{
    std::vector<std::vector<std::pair<int,int>>> tree;
    std::vector<int> dist;
    TreeQuery() = delete;
    TreeQuery(const std::vector<std::vector<std::pair<int,int>>>&& t){
        tree = t;
        dist.assign(tree.size(), -1);
    }

    void memDist(const size_t v, const int d){
        if(dist[v] != -1) return;
        dist[v] = d;
        for(const std::pair<int,int> next : tree[v]) memDist(next.first, d+next.second);
    }

    size_t twoPointDist(const size_t x, const size_t y){
        std::fill(dist.begin(), dist.end(), -1);
        memDist(x, 0);
        return dist[y];
    }

    size_t furthestPoint(const size_t start){
        std::fill(dist.begin(), dist.end(), -1);
        memDist(start, 0);
        return std::max_element(dist.begin(), dist.end()) - dist.begin();
    }   

    size_t diameter(const size_t v=0){
        size_t x = furthestPoint(v);
        size_t y = furthestPoint(x);
        return dist[y];
    }
};

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
using i64 = long long;
#define rep(i,N) for(int (i) = 0; (i) < (N); (i)++)
int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> P(N);
    rep(i, N){
        int p; cin >> p;
        P[i] = {p, i+1};
    }
    sort(P.rbegin(), P.rend());

    multiset<int> st = {0, 0, N+1, N+1};
    i64 ans = 0;

    rep(i ,N){ 
        st.insert(P[i].second);
        auto itr = st.find(P[i].second);

        int k = P[i].second;

        auto low_itr = itr; low_itr--;
        int x = *low_itr--;
        int w = *low_itr;

        auto high_itr = itr; high_itr++;
        int y = *high_itr++; 
        int z = *high_itr;

        i64 cnt =  (x - w)*(y - k) + (k - x)*(z - y);
        ans += P[i].first * cnt;
    }

    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int a=n;
    int s=0;
    while(a>0){
        s+=a%10;
        a=a/10;
    }
    if(n%s==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
//httips://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let sum = a.iter().fold(0, |s, a| s + *a);
    let w = 8 * std::mem::size_of::<usize>();
    let mut dp = vec![0usize; (sum + 1 + w - 1) / w];
    dp[0] = 1;
    for a in a {
        let (q, r) = (a / w, a % w);
        if r == 0 {
            for i in (q..dp.len()).rev() {
                dp[i] |= dp[i - q];
            }
        } else {
            for i in ((q + 1)..dp.len()).rev() {
                let x = dp[i - q];
                let y = dp[i - q - 1];
                dp[i] |= (x << r) | (y >> (w - r));
            }
            dp[q] |= dp[0] << r;
        }
    }
    let mut ans = (sum + 1) / 2;
    while (dp[ans / w] >> (ans % w)) & 1 == 0 {
        ans += 1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

int main(){
 ios_base::sync_with_stdio(false);
 cin.tie(NULL); 
 int n;
  cin>>n;
  int a[n];
  for(int i=0; i<n; i++) cin>>a[i];
  
  int dp[n+1];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = abs(a[1] - a[0]);
  for(int i=3; i<n+1; i++)
    dp[i] = min((abs(a[i-1]-a[i-2]) + dp[i-1]),(abs(a[i-1]-a[i-3]) + dp[i-2]));
    
   cout<<dp[n]<<endl;
   return 0;
}

Measured memory_bytes: 4332
#include<cstdio>
using namespace std;

int main(){
    int numk,nums;
    int count = 0;
    int i,j,k;
    scanf("%d%d",&numk,&nums);
    for(i=0;i<=numk;i++){
        for(j=0;j<=numk;j++){
            k=nums-i-j;
            if(k>=0 && k<=numk){
                count += 1;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        int V = nextInt(), E = nextInt();

        adjacency = new HashMap<>();

        for (int i = 0; i < V; i++) adjacency.put(i + 1, new ArrayList<>());

        for (int i = 0; i < E; i++) adjacency.get(nextInt()).add(nextInt());

        seen = new boolean[V + 1];

        longestPathFrom = new int[V + 1];

        for (int i = 1; i <= V; i++) if (!seen[i]) calcLongestPathFrom(i);

        System.out.println(Arrays.stream(longestPathFrom).max().getAsInt());
    }

    private static Map<Integer, ArrayList<Integer>> adjacency;
    private static boolean[] seen;
    private static int[] longestPathFrom;

    private static int calcLongestPathFrom(int v) {
        if (seen[v]) return longestPathFrom[v];
        seen[v] = true;
        if (adjacency.get(v).isEmpty()) return 0;
        int longestPath = 0;
        for (int adj: adjacency.get(v)) longestPath = Math.max(longestPath, 1 + calcLongestPathFrom(adj));

        longestPathFrom[v] = longestPath;
        return longestPath;
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

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

Measured memory_bytes: 65176
#各文字列をソートしながらハッシュテーブルへぶち込む
import sys
input = sys.stdin.readline

def cmb(n, r):
    if n - r < r: r = n - r
    if n == 1: return 0
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
 
N = int(input())
table = {}
cache = {}
for x in range(N):
    s = ''.join(sorted(list(input())))
    s = s.strip()
    if s in table:
        table[s] = table[s] + 1
    else:
        table[s] = 1

ans = 0
for x in table:
    if table[x] not in cache:
        p = cmb(table[x], 2)
        cache[x] = p
    ans = ans + cache[x]
    #print("{}: {} → {}".format(x, table[x], cache[x]))
print(ans)


Measured memory_bytes: 27868
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    vector <ll> num;
    vector <bool> used;
    REP(i, n){
        used.push_back(false);
        if ((i==0) && n > 1){
            num.push_back(1);
        } else {
            num.push_back(0);
        }
    }
    ll m; cin >> m;
    REP(i, m){
        ll s; cin >> s; s--;
        ll c; cin >> c;
        if (used[s] && (num[s] != c)){
            cout << -1 << endl;
            return 0;
        }
        used[s] = true;
        num[s] = c;
    }
    ll ans = 0;
    REP(i, n){
        ans += pow(10, n-i-1) * num[i];
    }
    if ((n > 1) && (ans < pow(10, n-1))){
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    dumparr(num)
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for ( int i = 1 ; i < 11 ; i++ ) {
    if ( i*1000 >= n ) {
      cout << i*1000 - n << endl;
      break;
    }
  }
}

Measured memory_bytes: 3620
import java.io.*;
import java.util.*;

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    List<Integer> list = new ArrayList<>();
    int min,y,n;

    private void permutations(int num){
        //out.println(num);
        if(cntDigits(num) == y){
            if(num >= n){
                min = Math.min(min,num);
                return;
            }
        }

        if(cntDigits(num) == y+1){
            if(num >= n){
                min = Math.min(min,num);
            }
            return;
        }

        for(int i:list){
            permutations(num*10+i);
        }
    }

    private int cntDigits(int x){
        int cnt = 0;
        while(x>0){
            x/=10;
            cnt++;
        }
        return cnt;
    }

    private void solve() {
        n = in.nextInt();
        int k = in.nextInt();

        y= cntDigits(n);

        boolean[] mrk = new boolean[11];
        Arrays.fill(mrk,false);
        for(int i=0;i<k;i++){
            mrk[in.nextInt()] = true;
        }
        min = 100000000;
        list = new ArrayList<>();
        for(int i=0;i<10;i++){
            if(!mrk[i]){
                list.add(i);
            }
        }
        Collections.sort(list);
        for (int idx:list){
            if(idx == 0) continue;
            permutations(idx);
        }
        out.print(min);
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }

    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


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

#define slld(longvalue) scanf("%lld", &longvalue)
#define plld(longvalue) printf("%lld\n", longvalue)

#define slf(longvalue) scanf("%lf", &longvalue)
#define plf(longvalue) printf("%lf\n", longvalue)
#define sc(letter) scanf("%c", &letter)
#define pc(letter) printf("%c", letter)

#define ss(name) scanf("%s", name)
#define ps(name) printf("%s", name)

#define pnew printf("\n")

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >
#define pii pair < int, int >

#define printcase(indexing,ans) printf("Case %lld: %lld\n", indexing, ans)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009


using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

    // freopen("in.txt", "r", stdin);

    ll a, b;

    while(cin >> a >> b >> k)
    {
        bool on = 0;

        for(i = 1; i <= k; i++)
        {
            if(on == 0)
            {
                if(a % 2) a--;

                b += a / 2;
                a /= 2;
            }
            else
            {
                if(b % 2) b--;

                a += b / 2;
                b /= 2;
            }

//            cout << a << " " << b << endl;

            on ^= 1;

        }

        on ^= 1;

        cout << a << " " << b << endl;
    }


}




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

int main()
{
    int n; std::cin >> n;
    std::vector<int> d(n);
    for (int i = 0; i < n; i++) {
        std::cin >> d[i];
    }

    int m; std::cin >> m;
    std::vector<int> t(m);
    for (int j = 0; j < m; j++) {
        std::cin >> t[j];
    }

    std::sort(d.begin(), d.end());
    std::sort(t.begin(), t.end());

    bool b = true;
    size_t dd = 0, tt = 0;
    while (dd < d.size() && tt < t.size()) {
        if (d[dd] == t[tt]) {
            dd++; tt++;
        } else if (d[dd] < t[tt]) {
            dd++;
        } else {
            b = false;
            break;
        }
    }
    if (tt < t.size()) {
        b = false;
    }
    std::cout << (b?"YES":"NO") << std::endl;


    return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))

ans, xor, cnt = 0, 0, 0
for i in range(n):
    while cnt < n and xor & a[cnt] == 0:
        xor ^= a[cnt]
        cnt += 1
    ans += cnt - i
    xor ^= a[i]
print(ans)


Measured memory_bytes: 99176
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#pragma GCC optimize("Ofast")
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native" )
#define endl "\n"
#define int unsigned long long
#define debug(x) cout << #x << " is " << x << endl;
using namespace std;
int fastpow(int a, int b) {
	if (!b) return 1ll;
	if (b % 2 == 1) return fastpow(a, b - 1) * a;
	int t = fastpow(a, b / 2);
	return t * t;
}
void solve() {
	int n, ans = 0; cin >> n;
	vector <int> a(n);
	for (auto & x: a) cin >> x;
	for (int i = 0; i < n; ++i) {
		ans ^= a[i];
	}
	for (int i = 0; i < n; ++i) {
		int cur = ans ^ a[i];
		cout << cur << " ";
	}
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t; t = 1;
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 4712
let n1 = Int(readLine()!)!
    
    let n2 = readLine()!.split(separator: " ").compactMap{Int($0)}
    
    var dict = [Int : Int]()
    
    for i in 1 ... n1 {
      
      dict[i] = 0
    }
    
    for j in n2 {
      
      if dict.keys.contains(j) {
        
        dict[j] = dict[j]! + 1
        
      }
    }
    
    for n in dict.keys.sorted(by: {$0 < $1}) {
      print(dict[n]!)
      }

Measured memory_bytes: 27496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        int cnt = 0;
        for(int j = 1;j <= i;j++)
        {
            if(i % j == 0&&i%2==1) cnt++;
        }
        if(cnt == 8)
            ans++;
    }
    cout << ans;
    return 0;
}

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

using namespace std;

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

  int w_sum = 0;
  int b_sum = 0;
  
  int res = 0;
  /* find start */
  for (int i = 0; i < N; i++) {
	if (S[i] == '#')
	  b_sum++;
	else
	  w_sum++;
  }

  b_sum = 0;

  res = b_sum + w_sum;
  for (int i = 0; i < N; i++) {
	if (S[i] == '#')
	  b_sum++;
	else
	  w_sum--;
	if (res > (b_sum + w_sum))
	  res = b_sum + w_sum;
  }

  cout << res << endl;

  return 0;
}


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


def _kakko(s):
    l, lr = 0, 0
    for c in s:
        if c == ')':
            if lr == 0:
                l = l + 1
            else:
                lr = lr - 1
        else:
            lr = lr + 1
    return (l, lr)


s = [_kakko(input()) for _ in range(n)]

sl = [ss for ss in s if ss[1] >= ss[0]]
sr = [ss for ss in s if ss[1] < ss[0]]

sl.sort(key=lambda x: x[0])
sr.sort(key=lambda x: x[1], reverse=True)

r = 0
for ss in sl:
    if ss[0] > r:
        print('No')
        exit(0)
    r = r + ss[1] - ss[0]

for ss in sr:
    if ss[0] > r:
        print('No')
        exit(0)
    r = r + ss[1] - ss[0]

if r != 0:
    print('No')
    exit(0)

print('Yes')


Measured memory_bytes: 92116
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, m; scanf("%d %d", &n, &m); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	i64 ans = 0;
	std::map<int, int> vec;
	std::vector<i64> s(n + 1, 0);
	for(int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
	for(int i = 0; i <= n; i++) {
		ans += vec[s[i] % m];
		vec[s[i] % m]++;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4352
from collections import deque, defaultdict

N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N-1)]

#print(ab)
outs = defaultdict(list)
ins = defaultdict(int)

for v1, v2 in ab:
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(1,N+1) if ins[v1] == 0)
hoji = []
dicthoji = {1: 0}

while q:
    v1 = q.popleft()
    count = 0
    for v2 in outs[v1]: #v1のノードから出ている矢印をみる．
        count += 1
        if dicthoji[v1] == count: #前に色を使っていたら飛ばす
            count += 1
        ins[v2] -= 1
        q.append(v2)
        dicthoji.update([(v2,count)])
        hoji.append(count)
#print(dicthoji)

print(max(hoji))
for i in range(N-1):
    print(dicthoji[ab[i][1]])

Measured memory_bytes: 55016
#include <iostream>
#include <vector>
#include <cmath>

int main() {
  long int N, D;
  std::cin >> N >> D;

  std::vector<long int> X(N);
  std::vector<long int> Y(N);

  for (int i=0; i < N; i++) {
    std::cin >> X[i] >> Y[i];
  }

  long int cnt = 0;
  for (long int i=0; i < N; i++) {
    if (sqrt(pow(X[i],2) + pow(Y[i], 2)) <= D) {
      cnt++;
    }
  }
  std::cout << cnt << std::endl;

}

Measured memory_bytes: 6480
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    int a,b;cin>>a >>b;
    int sum = 0;
    for(int i = 1; i <= b - a; i++) sum += i;
    cout << sum - b << endl;
    return 0;
    
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[0] == s.back()){
    if(s.length()%2) cout << "Second" << endl;
    else cout << "First" << endl;
  }else{
    if(s.length()%2) cout << "First" << endl;
    else cout << "Second" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
import numpy as np

N = int(input())

t = [0]
x = [0]
y = [0]
for i in range(N):
    a = input().split(" ")
    t.append(int(a[0]))
    x.append(int(a[1]))
    y.append(int(a[2]))

flag = 0
for i in range(1,N+1):
    t[i] = t[i]-t[i-1]
    x[i] = x[i]-x[i-1]
    y[i] = y[i]-y[i-1]
    if (x[i]+y[i])%2 == t[i]%2:
        if x[i] >= 0:
            if y[i] <= -x[i] + t[i] and y[i] >= x[i] - t[i]:
                continue
            else:
                print("No")
                flag = 1
                break
        else:
            if y[i] <= x[i] + t[i] and y[i] >= -x[i] - t[i]:
                continue
            else:
                print("No")
                flag = 1
                break
    else:
        print("No")
        flag = 1
        break

if flag == 0:
    print("Yes")


Measured memory_bytes: 21408
#include <stdio.h>
#include <stdlib.h>

// -- 比較用の関数 cmp --
int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}

int main(){
    int i,j,N;
    int cntARC,cntABC;
    int n,min,max,mid,midminus;
    int cnt = 0;
    int d[100001];
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&d[i]);
    qsort(d,N,sizeof(int),cmp);
    min = d[0];
    mid = d[N/2];
    midminus = d[N/2-1];
    max = d[N-1];
    cnt = mid - midminus;
    /*for(i=min;i<=max;i++){
        cntARC = 0;
        cntABC = 0;
        for(j=0;j<N;j++){
            if(i>=d[j]){
                cntARC++;
            }else{g
                cntABC++;
            }
        }
        if(cntARC == cntABC) cnt++;
    }*/
    
    printf("%d\n",cnt);
}

Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll N;
    cin >> N;
    double v[N];
    rep(i,N) cin >> v[i];
    sort(v,v+N);
    rep(i,N-1){
        v[i+1] = (v[i]+v[i+1])/2.0;
        v[i] = 0;
    }
    cout << fixed << setprecision(5) << v[N-1] << endl;
    return 0;
}


Measured memory_bytes: 256
day = input()

if day == "SUN":
    print(7)
elif day == "MON":
    print(6)
elif day == "TUE":
    print(5)
elif day == "WED":
    print(4)
elif day == "THU":
    print(3)
elif day == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 3060
#include<string.h>
#include <iostream>
#include<cstdio>
#include <stack>
#include <vector>
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];
int dis[maxn];
int findset(int x)
{
    if(x==pre[x])   return x;
    int root=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];
    return pre[x]=root;
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;       //input members
int main()    //main body
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");          //output
   else     printf("No\n");
}

Measured memory_bytes: 1656