akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    int v, e, r;
    cin >> v >> e >> r;

    vector<vector<pair<int, int>>> g(v, vector<pair<int, int>>(0));
    for (auto i = 0; i < e; i++) {
        int s, t, d; cin >> s >> t >> d;
        g[s].emplace_back(t, d);
    }

    vector<int> cost(v, -1);
    // デフォルトは降順 first = dist, second = point
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
    q.push({0, r}); cost[r] = 0;
    while(not q.empty()){
        pair<int, int> start = q.top();
        q.pop();
//        cout << start.second << " " << start.first << " " << cost[start.second] << endl;
        if(cost[start.second] < start.first) continue;
        for (auto elm : g[start.second]) {
            int dist = start.first + elm.second;
            if(cost[elm.first] > dist or cost[elm.first] < 0) {
                cost[elm.first] = dist;
                q.push({dist, elm.first});
            }
        }
    }

    for (auto i = 0; i < v; i++) {
        if(cost[i] < 0) cout << "INF" << endl;
        else cout << cost[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 12956
/*input
5 9
3 2
3 1
4 1
4 2
3 5
5 3
3 4
1 2
2 5

2 2
1 2
2 1

3 3
1 2
1 3
2 3
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N 1005
#define bit(x,y) ((x>>y)&1LL)
#define loop(i,l,r) for(int i=(signed)(l); i<=(signed)(r); i++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
    return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    for (unsigned int i = 0; i < a.size(); i++)
        os << a[i] << (i < a.size() - 1 ? ", " : "");
    os << ']';
    return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
    os << '{';
    for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
        typename set<T>::iterator jt = it;
        os << *it << (++jt != a.end() ? ", " : "");
    }
    os << '}';
    return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
    os << "{\n";
    for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
        typename map<T1, T2>::iterator jt = it;
        os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
    }
    os << '}';
    return os;
}

int n, m;
vector<vector<pair<int, int> > > a(N);
int cnt[N][N];
int mark[N][N];
bool ansOrder[200005];

void dfs(int u, int p, const int root, const int source) {
    if (u == root) return;
    if (cnt[root][u] >= 2) return;
    if (cnt[root][u] == 1 && mark[root][u] == source) return;
    cnt[root][u]++; mark[root][u] = source;
    for (auto it : a[u]) {
        int v = it.fi;
        if (v == p) continue;
        dfs(v, u, root, source);
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    loop(i, 1, m) {
        int u, v; cin >> u >> v;
        a[u].push_back(mp(v, i));
    }
    loop(u, 1, n) {
        for (auto it : a[u]) {
            int v = it.fi;
            dfs(v, u, u, v);
        }
    }
    loop(u, 1, n) {
        for (auto it : a[u]) {
            int v = it.fi;
            bool diff = false;
            if (cnt[u][v] >= 2) {
                if (cnt[v][u] == 0) diff = true;
            }
            else if (cnt[u][v] == 1) {
                if (cnt[v][u] >= 1) diff = true;
            }
            ansOrder[it.se] = diff;
        }
    }
    loop(i, 1, m) {
        if (ansOrder[i] == false) cout << "same" << endl;
        else cout << "diff" << endl;
    }
}

Measured memory_bytes: 12288
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
main()
{
    int n,h,w,sum=0;
    scanf("%d%d%d",&n,&h,&w);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i+w-1<=n&&j+h-1<=n) sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();
        int N = r.i();
        int[] tmp = r.ii();
        ArrayList<Double> v = new ArrayList<>();
        for(int i : tmp)
            v.add((double)i);
        for(int i = 0; i < N-1; i++){
            v.sort(null);
            double x = v.remove(0);
            double y = v.remove(0);
            v.add(0, (x+y)/2);
        }
        println(v.get(0));
    }
    
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21332
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}



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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

// doc: https://shibh308.github.io/library/library/lib/classes/modint.cpp.html
template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> v(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        --a[i];
        v[a[i]] = i;
    }
    vector<int> res(n - 1);
    for(int i = 0; i < n - 1; ++i)
        res[i] = (v[i] < v[i + 1]);
    int ans = 0;
    int cn = 0;
    for(int i = 0; i < n - 1; ++i){
        if(res[i]){
            ++cn;
            chmax(ans, cn);
        }
        else{
            cn = 0;
        }
    }
    cout << n - ans - 1 << endl;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans=1e6;
  int count=0;
  for(int i=0;i<n;i++){
    if(s.at(i)=='.'){
      count++;
    }
  }
  ans=min(ans,count);
  for(int i=0;i<n;i++){
    if(s.at(i)=='#'){
      count++;
    }
    else{
      count--;
    }
   ans=min(ans,count);
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 640
N,K=map(int, input().split())
instr=input()
lft=0
rgt=1
voids=0 if instr[0] == '1' else 1

rlast='1' if instr[0] == '1' else '0'
llast='1' if instr[0] == '1' else '0'
maxlen=0
while lft < rgt:
    # print("lft {} rgt {} maxlen {} void {} {}".format(lft, rgt, maxlen, voids, instr[lft:rgt]))
    if voids <= K and rgt < N:
        maxlen = max(maxlen, rgt-lft)
        if instr[rgt-1] == '1' and instr[rgt] == '0':
            voids+=1
            rlast = '0'
        rlast = instr[rgt-1]
        rgt += 1
    else:
        if (voids <= K):
            maxlen = max(maxlen, rgt-lft)
        llast = instr[lft]
        if lft+1 < N and instr[lft] == '0' and instr[lft+1] == '1':
            voids -= 1
        lft += 1

print(maxlen)


Measured memory_bytes: 3316
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use ascii::ToAsciiChar;

#[fastout]
fn main() {
    input! {
    mut n: usize
    }
    let mut ans = vec![];
    while n > 0 {
        let mut c = ((n % 26) as u8 + 96) as char;
        if c == '`' {
            c = 'z';
        }
        n -= 1;
        n /= 26;
        ans.push(c)
    }
    ans.reverse();
    for i in ans {
        print!("{}", i)
    }
}


Measured memory_bytes: 2184
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#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 rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
using LD = long double;

int N;
LD d[414514];
LD ds[414514];
LD x;

LD f(int n) {
  if (n == 0) return 0;
  LD t = 1 + 1/LD(n);
  return 1 + t * f(n-1);
}

int main() {
  cin >> N >> d[0] >> x;
  LD c = d[0] + x*((2*N-1)/LD(2));
  cout << fixed << setprecision(20) << f(N)*c << endl;
  //printf("%.15f\n", ans);
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define f first
#define s second
#define mp make_pair
#define sz size()
#define ll long long
int n;
bool was[3010][3010];
ll dp[3010][3010];
ll a[3010];
ll calc(int l, int r) {
	if(l > r) return 0;
	if(l == r) return a[r];
	if(was[l][r]) return dp[l][r];
	was[l][r] = 1;
	dp[l][r] = max(a[l] - calc(l + 1, r), a[r] - calc(l, r - 1)); // max(áåð¸ì ïåðâûé, áåð¸ì ïîñë.)
//	cout << "podotrezok " << l << ' ' << r << " answer is " << dp[l][r] << '\n';
	return dp[l][r];
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	ll ans = calc(1, n);
	cout << ans;
	return 0;
}

Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll a, b, k;
  cin >> a >> b >> k;
  ll cnt = 0;
  for (ll i = 100; i > 0; --i) {
    if (a%i == 0 && b%i == 0) ++cnt;
    if (cnt == k) {
      cout << i << '\n';
      return 0;
    }
  }

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3644
<?php
 $input = fgets(STDIN);
 $array = explode(" ", $input);
 $a_a = (int)$array[0] + (int)$array[1];
 $b_s = (int)$array[0] - (int)$array[1];
 $c_m = (int)$array[0] * (int)$array[1];
 $x=[$a_a,$b_s,$c_m]; 
 rsort($x);
 echo $x[0]."\n";
?>

Measured memory_bytes: 4984
import java.util.ArrayDeque
import java.util._
import java.io._
import scala.io.Source

object Main {
	val sc = new Scanner(System.in)
	def main(args: Array[String]): Unit = {
	  var count = 0
	  var n = sc.nextInt
	  var S = new Array[Int](n)
	  for(i <- 0 until n){
	    S(i) = sc.nextInt
	  }
	  var q = sc.nextInt
	  for(i <- 0 until q){
	    if(S.contains(sc.nextInt)){
	      count += 1
	    }
	  }
	  println(count)
	}
}

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

int main() {
	int x, y;
	cin >> x >> y;
	if (x + y >= x - y and x + y >= x * y) {
		cout << x + y;
	}
	else if (x - y >= x + y and x - y >= x * y) {
		cout << x - y;
	}
	else if (x * y >= x - y and x * y >= x + y) {
		cout << x * y;
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll dp[101010];

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

    const ll INF = (1ll<<60);
    REP(i, 101010) dp[i] = INF;
    dp[0] = 0;

    ll N;
    cin >> N;

    vector<ll> cand;
    cand.push_back(1);
    ll tmp = 6;
    while(tmp<=N){
    	cand.push_back(tmp);
    	tmp *= 6;
    }
    tmp = 9;
    while(tmp<=N){
    	cand.push_back(tmp);
    	tmp *= 9;
    }

    REP(i, N){
    	REP(j, cand.size()){
    		if(i+cand[j]<101010)chmin(dp[i+cand[j]], dp[i]+1);
    	}
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int a[200000];
int main()
{
    int m,i,f=1,f1,k=0;
    scanf("%d",&m);
    for(i=0;i<m;i++)
        scanf("%d",&a[i]);
    for(i=1;i<m;i++)
        if(f)
        {

            if(a[i]>a[i-1])
            f=0,f1=i-1,k++;

        }
        else
        {
            if(a[i]<a[f1])
                f=1;
            else
               k++;
        }
    printf("%d",m-k);
    return 0;
}


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

int ans, n, m, p[10], k[10], d[10][10];

void dfs(int a[], int l){
    if(l == n){
        bool f = true;
        for(int i = 0; i < m; i++){
            if(a[i] != p[i]) f = false;
        }
        if(f) ans++;
        return;
    }
    int aa[10];
    for(int i = 0; i < n; i++) aa[i] = a[i];
    for(int i = 0; i < n; i++) aa[i] = (aa[i] + d[l][i]) % 2;
    dfs(aa, l + 1);
    dfs(a, l + 1);
    return;
}

int main()
{
    int s[10][10];
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
            s[i][j]--;
            d[s[i][j]][i] = 1;
        }
    }
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }
    int a[10] {0};
    dfs(a, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100

int main(){

  int i, j, num, count, temp, min;
  int data[MAX];

  count = 0;

  scanf("%d", &num);

  for(i = 0; i < num; i++){

    scanf("%d", &data[i]);

  }

  for(i = 0; i < num - 1; i++){

    min = i;

    for(j = i + 1; j < num; j++){

      if(data[min] > data[j]){
	
	min = j;
	
      }
	
    }


    if(data[i] != data[min]){

      temp = data[min];

      data[min] =  data[i];

      data[i] = temp;

      count++;

    }
     
  }

  for(i = 0; i < num - 1; i++){
    
    printf("%d ", data[i]);

  }

  printf("%d\n%d\n", data[i], count);
  
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main() {
    int n, sum = 0;
    for (int i = 0; i < 5; i++) {
        cin >> n;
        n = max(n, 40);
        sum += n;
    }
 
    cout << sum / 5 << endl;
 
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
using namespace std;
 
int N, A, B;
typedef long long ll;
ll v[51];
ll com[53][53];
 
void init(int N) {
  for(int i = 0; i <= N; i++) {
    com[i][i] = com[i][0] = 1;
  }
 
  for(int i = 2; i <= N; i++) {
    for(int j = 1; j < i; j++) {
      com[i][j] = com[i-1][j-1] + com[i-1][j];
    }
  }
}
 
ll nCr(int n, int r) {
  return com[n][r];
}
  
int main() {
  cin >> N >> A >> B;
 
  init(N);
 
  for(int i = 0; i < N; i++)  cin >> v[i];
  
  sort(v,v+N,greater<ll>());
 
  int c = 0;
 
  
  
  ll ans = 0;
  
  for(int i = 0; i < A; i++) ans += v[i];
  
  cout <<fixed<< ans /(double)A<<endl;
 
 
 
  if(v[0] != v[A-1]) {
    int c = 0;
    int tmp = 0;
    for(int i = 0; i < N; i++) {
      if(v[i] == v[A-1]) break;
      tmp++;
    }
    
    for(int i = 0; i < N; i++) {
      if(v[i] == v[A-1]) c++;
    }
    cout <<fixed<< nCr(c,A-tmp) <<endl;
  }
 
  else {
    int c = 0;
    for(int i = 0; i < N; i++) {
      if(v[0] != v[i]) break;
      c++;
    }
 
    ll ans2 = 0;
 
    for(int i = A; i <= B; i++) {
      ans2 += nCr(c,i);
    }
    cout <<fixed<< ans2 <<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdio>

using namespace std;

int a1, a2, a3, dmp;
int ans = 0;

int main(){
	cin >> a1 >> a2 >> a3;
	
	
	if (a2 < a3) {
		dmp = a2;
		a2 = a3;
		a3 = dmp;
		dmp = 0;
	}
	if (a1 < a2) {
		dmp = a1;
		a1 = a2;
		a2 = dmp;
		dmp = 0;
	}
	if (a2 < a3) {
		dmp = a2;
		a2 = a3;
		a3 = dmp;
		dmp = 0;
	}
	if (a1 < a2) {
		dmp = a1;
		a1 = a2;
		a2 = dmp;
		dmp = 0;
	}
	
	ans = a2 - a3 + a1 - a2;
	cout << ans;
	
	return 0;
}


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

int main(void){
    int n;
    cin>>n;
    int b[n];
    rep(i,n-1) cin>>b[i];
    int sum=b[0];
    rep(i,n-2) {
        if(b[i]>b[i+1]) b[i]=b[i+1];
        sum+=b[i];
    }
    sum+=b[n-2];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <string>
#include <map>
#include <iostream>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <climits>
#include <limits>
#include <queue>
#include <utility>

using namespace std;



#define ll long long

	int main() {

		int n;
		cin >> n;

		vector<int> arr(n);

		for (int i = 0; i < n; i++) {
			int val;
			cin >> val;
			arr[i] = val;
		}
		int totalXor = 0;
		for (int i = 0; i < n; i++)
			totalXor = totalXor ^ arr[i];

		for (int i = 0; i < n; i++) {
			
			cout << (totalXor ^ arr[i]) << " ";

		}
		
		cout << endl;
		return 0;
	}

	



Measured memory_bytes: 4044
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

vector<vector<int>> tree;
void dfs(int now,int d,vector<int> &dist){
    for(auto v:tree[now]){
        if(dist[v]>=0) continue;
        dist[v]=dist[now]+1;
        dfs(v,d+1,dist);
    }
}

int main(){
    int N,u,v;
    cin>>N>>u>>v;
    u--;v--;
    tree.resize(N);
    REP(i,N-1){
        int a,b; cin>>a>>b;
        a--;b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> du(N,-1),dv(N,-1);
    du[u]=0;dv[v]=0;
    dfs(u,0,du);
    dfs(v,0,dv);
    int ans=0;
    REP(i,N){
        if(du[i]<dv[i]){
            ans=max(ans,dv[i]-1);
        }
    }
    cout<<ans<<endl;
}


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

int main(){
  ll n;
  cin >> n;
  ll ans = 1;
  rep(i,n){
    ans *= i;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

a,b,c=map(int,input().split())
if a*b*c%2==0:
    print(0)
else:
    print(min(a*b,b*c,c*a))

Measured memory_bytes: 61996
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

#define REP(i, n) for((i) = 0; (i) < (n); (i)++)
#define READ1(n1) scanf("%d", &(n1))
#define READ2(n1, n2) scanf("%d%d", &(n1), &(n2))
#define READ3(n1, n2, n3) scanf("%d%d%d", &(n1), &(n2), &(n3))
#define P1(n1) printf("%d\n", (n1))
#define P2(n1, n2) printf("%d, %d\n", (n1), (n2))
#define P3(n1, n2, n3) printf("%d, %d, %d\n", (n1), (n2), (n3))
#define CLEAR(p) memset((p), 0, sizeof((p)))
int main(void)
{
	while(1) {
		int i, j, k;
		int base_num, road_num, supply, dest1, dest2;
		int answer = INT_MAX;
		int cost[200][200];

		READ2(base_num, road_num);

		READ3(supply, dest1, dest2);

		if(base_num == 0) break;

		REP(i, base_num) {
			REP(j, base_num) {
				cost[i][j] = (INT_MAX - 1) / 3;
			}
		}

		REP(i, base_num) {
			cost[i][i] = 0;
		}

		REP(i, road_num) {
			int from, to, value;

			READ3(from, to, value);

			cost[from-1][to-1] = value;
		}

		while(1) {
			int flag = false;

			REP(i, base_num) {
				REP(j, base_num) {
					REP(k, base_num) {
						if(cost[i][j] + cost[j][k] < cost[i][k]) {
							cost[i][k] = cost[i][j] + cost[j][k];
							flag = true;
						}
					}
				}
			}

			if(!flag) break;
		}

		REP(i, base_num) {
			if(cost[supply-1][i] + cost[i][dest1-1] + cost[i][dest2-1] < answer) {
				answer = cost[supply-1][i] + cost[i][dest1-1] + cost[i][dest2-1];
			}
		}

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

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
   int n;
   cin >> n;
   vector<ll>a(n);
   rep(i, 0, n)cin >> a[i];
   ll ans =0;
   rep(i, 1, n){
       if(a[i]<a[i-1]){
           ans += (a[i-1]-a[i]);
           a[i] = a[i-1];
       }
   }
   cout << ans << endl;
}

Measured memory_bytes: 4784
def kaijo(x):
    v=1
    for i in range(1,x+1):
        v*=i
    return v


n,m=map(int,input().split())
mod=10**9+7
if abs(n-m)>=2:
    ans=0
else:
    ans=1
    for i in range(1,n+1):
        ans*=i
        ans%=mod
    for i in range(1,m+1):
        ans*=i
        ans%=mod
    if n==m:
        ans*=2
        ans%=mod

print(ans)


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

struct point {
    int x, y;
};

double dist(point r1, point r2) {
    return sqrt((r2.x - r1.x)*(r2.x - r1.x) + (r2.y - r1.y)*(r2.y - r1.y));
}


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

    point r[n];
    for (int i = 0; i < n; i++) {
        cin >> r[i].x >> r[i].y;
    }

    double total_distance = 0.0;
    for (int i = 0; i < n-1; i++) {
        for (int j = i + 1; j < n; j++) {
            point current = r[i];
            point next = r[j];
            total_distance += dist(current, next);
        }
    }

    double ans = total_distance * 2 / n;

    cout << fixed << setprecision(10) << ans << endl;

    return 0;   
}


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

using namespace std;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    //freopen("solution.out", "w", stdout);
    freopen("1.in", "r", stdin);
#endif
}

const int maxn = 101, maxw = 1e5 + 1;
const long long inf = 1e18;
long long dp[maxn][maxw];

int main() {
    setIO();

    int n, w;
    cin >> n >> w;
    vector<pair<int, int> > item(n); // first = weight, second = value
    for (int i = 0; i < n; ++i) {
        cin >> item[i].first >> item[i].second;
        for (int j = 0; j < w + 1; ++j) {
            dp[i][j] = -inf;
        }
        dp[i][item[i].first] = item[i].second;
    }
    long long sol = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= w; ++j) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j + item[i + 1].first <= w) {
                dp[i + 1][j + item[i + 1].first] = max(
                        {dp[i + 1][j + item[i + 1].first], dp[i][j] + item[i + 1].second});
            }
            if (i == n - 1) {
                sol = max(sol, dp[i][j]);
            }
        }
    }
    cout << sol << "\n";
    return 0;
}

Measured memory_bytes: 82464
#include <cstdio>
#include <algorithm>
typedef struct {
	int cost, ddl;
} St;

int n;
St l[200005];

bool cmp(St &x, St &y)
{
	return x.ddl < y.ddl;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &l[i].cost, &l[i].ddl);
	}
	std::sort(l, l + n, cmp);
	int time = 0;
	int flag = 1;
	for (int i = 0; i < n; i++) {
		time += l[i].cost;
		if (time > l[i].ddl) {
			flag = 0;
			break;
		}
	}
	if (flag)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 1664
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;

int[int[]] memo;
int dfs(int[] a, int depth = 0)
{
	if (a.reduce!max >= 100) {
		return 1 << 28;
	}
	if (a in memo) {
		return memo[a];
	}
	if (a[0] == a[1] && a[0] == a[2]) {
		return depth;
	}
	int ans = int.max;
	for (int i = 0; i < 3; ++i) {
		for (int j = i + 1; j < 3; ++j) {
			int[] b = a.dup;
			b[i]++;
			b[j]++;
			ans = min(ans, dfs(b, depth + 1));
		}
	}
	for (int i = 0; i < 3; ++i) {
		int[] b = a.dup;
		b[i] += 2;
		ans = min(ans, dfs(b, depth + 1));
	}
	memo[a.idup] = ans;
	return ans;
}

void main()
{
	auto arr = readln.chomp.split.map!(to!int).array;
	dfs(arr).writeln;
}


Measured memory_bytes: 102012
N = int(input())
S = input()

cum_lw = [0] * N
cum_rw = [0] * N

if S[0] == ".":
    cum_lw[0] = 1

if S[-1] == ".":
    cum_rw[-1] = 1 

for i in range(1,N):
    if S[i] == ".":
        cum_lw[i] = cum_lw[i-1] + 1
    else:
        cum_lw[i] = cum_lw[i-1]

    if S[N-1-i] == ".":
        cum_rw[N-1-i] = cum_rw[N-i] + 1
    else:
         cum_rw[N-1-i] = cum_rw[N-i]

ans = N
for i in range(N):
    if i != N-1:
        bb = cum_lw[i] + cum_rw[i+1]
        wb = (i+1)-cum_lw[i] + cum_rw[i+1]
        ww = (i+1)-cum_lw[i] + (N-1-i)-cum_rw[i+1]
    else:
        bb = cum_lw[i]
        wb = (i+1)-cum_lw[i]
        ww = (i+1)-cum_lw[i]
    ans = min([ans, bb, wb, ww])

print(ans)

Measured memory_bytes: 19100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <stack>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
ll v[3333][3333], dp[4][3333][3333];

void solve() {
	int r, c, k; cin >> r >> c >> k;
	for (int i = 0; i < k; i++) {
		ll rr, cc, w; cin >> rr >> cc >> w;
		v[rr - 1][cc - 1] = w;
	}
	for (int i = 0; i < r; i++)for (int j = 0; j < c; j++) {
			if (v[i][j] > 0) {
				for (int cur = 2; cur >= 0; cur--) {
					dp[cur + 1][i][j] = max(dp[cur + 1][i][j], dp[cur][i][j] + v[i][j]);
				}
			}
			for (int cnt = 0; cnt < 4; cnt++) {
				dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[cnt][i][j]);
				dp[cnt][i][j + 1] = max(dp[cnt][i][j + 1], dp[cnt][i][j]);
			}
		}
	ll ans = 0;
	for (int i = 0; i < c; i++)for (int cnt = 0; cnt < 4; cnt++)ans = max(1ll * ans, dp[cnt][r - 1][i]);
	cout << ans;




}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

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

long long getKey(const string &s){
  long long res = 0;

  for(int i = 0; i < s.size(); i++){
    res *= 10;

    switch(s[i]){
    case 'A': res += 1; break;
    case 'C': res += 2; break;
    case 'G': res += 3; break;
    case 'T': res += 4; break;
    }
  }

  return res;
}

/*
int getKey(const string &s){
  int res = 0;
  for(int i = 0; i < s.size(); i++){
    res *= 5;
    switch(s[i]){
      case 'A': res += 1; break;
      case 'C': res += 2; break;
      case 'G': res += 3; break;
      case 'T': res += 4; break;
    }
  }
  return res;
}
*/

int main(){
  set<long long> s;
  int n;
  cin >> n;

  for(int i = 0; i < n; i++){
    string op;
    string str;
    cin >> op >> str;

    if(op == "insert"){
      s.insert(getKey(str));
    }
    else if(s.find(getKey(str)) != s.end()){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }
}

Measured memory_bytes: 14128
N,K=(int(i) for i in input().split())  

bw = [ 2**i for i in range(22)]

ans = 0.0

for i in range(1,N+1):
    for j in range(22):
        if(K<=i*bw[j]):
            ans += 1.0/bw[j]
            break

print(ans/N)


Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL MAXN = 10;

string A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int h, w, cnt = 0, r = 0, c = 0, res = 1;
	cin >> h >> w;
	REP(i, h) cin >> A[i];
	REP(i, h) REP(j, w)
		cnt += A[i][j] == '#';
	while (true)
	{
		if (r + 1 < h && A[r + 1][c] == '#')
		{
			++res;
			++r;
			continue;
		}
		if (c + 1 < w && A[r][c + 1] == '#')
		{
			++res;
			++c;
			continue;
		}
		break;
	}
	if (res == cnt) cout << "Possible";
	else cout << "Impossible";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dcm(a) setprecision(a)<<fixed
#define MOD 1000000007
#define clr(memo, a) memset(memo,a,sizeof(memo))
#define PI acos(-1)

int const N=1e5+5;
int a[N][3];
int dp[N][3];
void solve(){
int n;
cin>>n;
for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
    cin>>a[i][j];
for(int i=0;i<n-1;i++){
for(int j=0;j<3;j++){
dp[i+1][j]=max(dp[i][(j+1)%3]+a[i][(j+1)%3],dp[i][(j+2)%3]+a[i][(j+2)%3]);
}

}
cout<<max(dp[n-1][0]+a[n-1][0],max(dp[n-1][1]+a[n-1][1],dp[n-1][2]+a[n-1][2]))<<endl;
}

int main(){
    fast;

solve();

return 0;}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<sstream>
#define INF (1<<24)
using namespace std;
 
struct State{
  int pos;
  int S;
  vector <string> rt;
};
 
int n,m,k,flg;
vector <int> t[15];
vector <int> u[15];
bool vd[15][(1<<15)];
 

 
int start;

void input();
void init();
//void print_bit(int);
void dijkstra();
string change(int x);
 
int main(){
  while(cin>>n>>m){
    if(n==0&&m==0)break;
    init();
    input();
    dijkstra();
  }
  return 0;
}
 
void init(){
  for(int i=0;i<15;i++){
    t[i].clear();
    u[i].clear();
    for(int j=0;j<(1<<15);j++){
      vd[i][j]=false;
    }
  }
  start=flg=0;
}
 
void input(){
  int a,b;
 
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;
    b--;
    t[a].push_back(b);
    t[b].push_back(a);
  }
 
  for(int i=0;i<n;i++){
    cin>>a;
    if(a==1)start|=(1<<i);
  }
   
  for(int i=0;i<n;i++){
    cin>>a;
    for(int j=0;j<a;j++){
      cin>>b;
      if (i + 1 != b)u[i].push_back(b-1);
    }
    sort(u[i].begin(),u[i].end());
  }
}
 
void dijkstra(){
queue < State > Q;
  State A,X;
  int p;
 
  A.pos=0;
  A.S=start;
  A.rt.clear();
  Q.push(A);
 
  while(!Q.empty()){
 
    X=Q.front();Q.pop();
 
    if(vd[X.pos][X.S]==true)continue;
    vd[X.pos][X.S]=true;

    if(X.pos==n-1){
      flg=1;
      if(X.S == (1<<(n-1)) ){
	cout<<"You can go home in "<<X.rt.size()<<" steps."<<endl;
	for(int i=0;i<(int)X.rt.size();i++)cout<<X.rt[i]<<endl;
	return;
      }
    }
 
    for(int i=0;i<(int)t[X.pos].size();i++){
      p=t[X.pos][i];
      
      if (!(X.S & 1 << t[X.pos][i])) continue;

      A.pos=p;A.S=X.S;A.rt=X.rt;
      A.rt.push_back("Move to room "+change(p)+".");
      Q.push(A); 
    }
 
    for(int i=0;i<(int)u[X.pos].size();i++){
      p=u[X.pos][i];
 
      A.pos=X.pos; A.S=X.S^(1<<p);A.rt=X.rt;

      if((X.S>>p)&1)A.rt.push_back("Switch off room "+change(p)+".");
      else A.rt.push_back("Switch on room "+change(p)+".");
      Q.push(A);
 
    }
 
  }
   
 
  if(flg==1){
    cout<<"You can not switch off all lights."<<endl;
  }else{
    cout<<"Help me!"<<endl;
  }
}
 
/*
vector <int> print_b;
void print_bit(int x){
  print_b.clear();
  for(int i=0;i<15;i++){
    print_b.push_back(x%2);
    x/=2;
  }
  for(int i=14;i>=0;i--){
    cout<<print_b[i];
  }
  cout<<endl;
}
*/

string change(int x){
  x++;
  string res;
  stringstream ss;
  ss<<x;
  ss>>res;
  return res;
}

Measured memory_bytes: 15720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000
struct edge{
    int a, b, cost;
};
vector<int> adj[3000];
int vis[3000]{0};
void dfs(int u){
	if(vis[u]) return;
	vis[u] = 1;
	for(int v:adj[u]){
		dfs(v);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,P,v=0,t;
	cin >> n >> m >> P;
	t = n-1;
	vector<edge> e(m);
	for(int i=0;i<m;i++){
		int a,b,c;
		cin >> a >> b >> c;
		e[i] = {a-1,b-1,-(c-P)};
		adj[b-1].push_back(a-1);
	}
    vector<int> d (n, INF);
    d[v] = 0;
    vector<int> p (n, -1);
    int x;
    for (int i=0; i<n; ++i)
    {
        x = -1;
        for (int j=0; j<m; ++j)
            if (d[e[j].a] < INF)
                if (d[e[j].b] > d[e[j].a] + e[j].cost)
                {
                    d[e[j].b] = max (-INF, d[e[j].a] + e[j].cost);
                    p[e[j].b] = e[j].a;
                    x = e[j].b;
                }
    }
    /*for(int i=0;i<n;i++){
    	cout << "d[" << i << "]=" << d[i] << "\n";
    }*/
    if (x == -1){
    	if(d[t] == INF){
    		cout << "-1\n";
    	}else{
    		cout << max(-d[t],0) << '\n';
    	}
    }else{
        int y = x;
        for (int i=0; i<n; ++i)
            y = p[y];

        vector<int> path;
        for (int cur=y; ; cur=p[cur])
        {
            path.push_back (cur);
            if (cur == y && path.size() > 1)
                break;
        }
        reverse (path.begin(), path.end());

		dfs(t);
		for(int i:path){
			if(vis[i]){
				cout << "-1\n";
				return 0;
			}
		}
    	cout << max(-d[t],0) << '\n';
    }
	return 0;
}

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

#define N 100000
#define INF 1000000
#define MIN(X,Y) ((X)<(Y)?(X):(Y))

int main(void){
  int ans = INF;
  int n, k, l, r, a[N];
  int flg[N+1], cnt;
  
  cin >> n >> k;
  for (int i=0; i<n; i++) cin >> a[i];
  for (int i=1; i<=k; i++) flg[i] = 0;
  cnt = 0;
  l = 0; r = -1;
  while (true){
    while (r<n && cnt < k){
      r++;
      if (a[r]<=k){
        if (flg[a[r]]==0) cnt++;
        flg[a[r]]++;
      }
    }
    if (r==n) break;
    ans = MIN(ans, r-l+1);
//    cout << l << " to " << r << " (" << ans << ")" << endl;
    if (a[l] <= k){
      flg[a[l]]--;
      if (flg[a[l]]==0) cnt--;
    }
    l++;
  }
  cout << (ans==INF?0:ans) << endl;
  return 0;
}
  
  



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

int main() {
  int n,x;
  cin >> n >> x;
  
  vector<int> l(n);
  for (int i=0; i<n; i++){
    cin >> l.at(i);
  }
  
  int d = 0;
  int cnt = 1;
  
  for (int i=0; i<n; i++){
    d += l.at(i);
    if (d > x) break;
    else cnt++;
  }
  
  cout << cnt  << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 118：B - Foods Loved by Everyone


def main():
    N, M = [int(i) for i in raw_input().strip().split(' ')]
    A = []
    for _ in range(N):
        a = [int(i) for i in raw_input().strip().split(' ')][1:]
        A.append(a)
    Hantei = [True for _ in range(M)]

    for a in A:
        # print a
        for i in range(1, M+1):
            if i in a:
                pass
            else:
                Hantei[i-1] = False

    # print Hantei
    print Hantei.count(True)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）
 
#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// ----- template end ---- //
 
// ------- library ------- //


// ----- library end ----- //



int main() {

  int N;
  cin >> N;

  //N+1 * N+1 の隣接行列を全て0で初期化（添字でバグらせないよう、1-indexedにする）
  vector<vector<int> > adj_matr(N+1, vector<int>(N+1, 0) );

  //隣接行列の左下領域をすべて1にする
  REP(i, 1, N+1){
    REP(j, 1, N+1){
      //i!=jのときのみ（真ん中の斜め線）
      //かつ　i>jのときのみ（左下領域）
      if (i>j){
        adj_matr.at(i).at(j) = 1;
      }
    }
  }

  if (N%2 == 0){ //偶数の場合
    //表の真ん中に右上がりのナナメ線を引く
    REP(i, 1, N+1){
      REP(j, 1, N+1){
        if ((i>j) && (i+j==N+1)){
          adj_matr.at(i).at(j) = 0;
        }
      }
    }
  }
  else{ //奇数の場合
    //表の真ん中から一段上がったところに右上がりのナナメ線を引く
    REP(i, 1, N+1){
      REP(j, 1, N+1){
        if ((i>j) && (i+j==N)){
          adj_matr.at(i).at(j) = 0;
        }
      }
    }
  }
 
  //辺の本数を数えつつ、vectorに出力を入れる
  int edges = 0;
  vector<string> output;
  REP(i, 1, N+1){
    REP(j, 1, N+1){
      if (adj_matr.at(i).at(j) == 1){
        edges += 1;
        output.PB(to_string(i)+" "+to_string(j));
      }
    }
  }

  cout << edges << endl;
  for (string eachans : output){
    cout << eachans << endl;
  }
  

// -- main() end -- //
}


 

Measured memory_bytes: 640
#include<iostream>
#include<string.h>
#include<map>
#include<string>
using namespace std;
string s[100005];
int a[26];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
      cin>>s[i];
    for(int i=0;i<n;i++)
        a[s[i][0]-'A']++;
    if(n<3)
    {            
       cout<<0<<endl;
       return 0;
    }
   long long ans=1,flag=0,cnt=0,c[5];
   memset(c,0,sizeof(c));
    if(a['M'-'A'])
    c[0]=a['M'-'A'],cnt++;
    if(a['A'-'A'])
    c[1]=a['A'-'A'],cnt++;
    if(a['R'-'A'])
    c[2]=a['R'-'A'],cnt++;
    if(a['C'-'A'])
    c[3]=a['C'-'A'],cnt++;
    if(a['H'-'A'])
    c[4]=a['H'-'A'],cnt++;
    if(cnt>=3)
      {
          ans=0;
       for(int i=0;i<5;i++)
        for(int j=1;j<5;j++)
         for(int k=2;k<5;k++)
         if(i<j&&j<k)
         ans+=c[i]*c[j]*c[k];
       cout<<ans<<endl;
      }
      else if(cnt<3) cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 6144
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] w = new int[n];
    int bef = 0;
    int aft = 0;
    for(int i = 0;i<n;i++){
      w[i] = sc.nextInt();
      bef += w[i];
    }
    int dis = bef;
    for(int i = n-1;i>1;i--){
      bef -= w[i];
      aft += w[i];
      dis = Math.min(dis,Math.abs(bef - aft));
    }
    System.out.println(dis);
  }
}


Measured memory_bytes: 35852
import java.util.*;
public class Main {
    static class N{
        long a,b,c;
        N(long x,long y,long z){
            a=x;b=y;c=z;
        }
        public String toString(){ 
            return (a+" "+b+" "+c);}
        public boolean equals(Object o){
            N n = (N)o;
            return this.a==n.a && this.b==n.b && this.c==n.c;
        }
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();int m =sc.nextInt();
        PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
        List<N> al1 = new ArrayList<>();
        for(int i=0;i<n;i++){
            long x = sc.nextLong();
            long y = sc.nextLong();
            long z = sc.nextLong();
            al1.add(new N(x,y,z));
        }
        long ans =0l;
        for(int i=-1;i<=1;i+=2){
            for(int j=-1;j<=1;j+=2){
                for(int k=-1;k<=1;k+=2){
                    List<N> al = new ArrayList<>();
                    for(int f = 0;f<n;f++){
                        al.add(new N(1l*i*al1.get(f).a,1l*j*al1.get(f).b,1l*k*al1.get(f).c));
                    }
                    
                    
                    Collections.sort(al, new Comparator<N>(){
                        public int compare(N n1,N n2){
                            if(n1.a+n1.b+n1.c>n2.a+n2.b+n2.c){
                                return -1;
                            }
                            if(n1.a+n1.b+n1.c<n2.a+n2.b+n2.c){
                                return 1;
                            }
                            return 0;
                        }
        });
        long ss=0l;
        for(int ii=0;ii<m;ii++){
            ss+=al.get(ii).a+ al.get(ii).b+al.get(ii).c;
        }
        ans = Math.max(ans, ss);
        
                }
            }
            
        
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26288
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int v[] = new int[n];
        double wa = 0;
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
            wa += v[i];
        }
        Arrays.sort(v);
        double tmp = v[0];
        for (int i = 0; i < n; i++) {
            tmp = (tmp + v[i]) / 2;
        }
        System.out.println(tmp);

        sc.close();
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
    int n,i,x;
    int a[100006];
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(i=1; i<n; i++)
    {
        if(i==1)
        {
            x=a[i-1]^a[i];
        }
        else
        {
            x=x^a[i];
        }
    }
    if(x!=0)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
    cout<<"Yes";
    else
    cout<<"No";
}

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

vector<vector<int>> cnt(10, vector<int>(10, 0));

void count(int n)
{
    string s;
    s = to_string(n);

    cnt[s[0] - '0'][s[s.size() - 1] - '0']++;
}

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

    for (int i = 1; i <= n; i++)
        count(i);

    int ans = 0;
    rep (i, 10)
        rep (j, 10)
            ans += cnt[i][j] * cnt[j][i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#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++)

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
int main()
{
    int n;
    cin >> n;
    vector<P> students(n);
    rep(i, n)
    {
        students.at(i).second = i + 1;
        cin >> students.at(i).first;
    }

    sort(students.begin(), students.end());

    rep(i, n)
    {
        cout << students.at(i).second << " ";
    }
}

Measured memory_bytes: 1536