akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n;

int main() {

	cin >> n;

	vector <double> p(n + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> p[i];
	}

	vector < vector <double> > dp(n + 1, vector <double>(n + 1, 0.0));

	dp[0][0] = 1.0;

	for (int i = 1; i <= n; i ++) {
		for (int j = 0; j <= i; j ++) {
			dp[i][j] = dp[i - 1][j] * p[i];
			if (j > 0) dp[i][j] += dp[i - 1][j - 1] * (1 - p[i]);
		}
	}

	double ans = 0;
	for (int i = 0; 2 * i <= n; i ++) {
		ans += dp[n][i];
	}

	cout << setprecision(9) << fixed << ans << '\n';
	return 0;
}

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

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

  string X; cin >> X;
  int N = X.size();
  int l = -1, ans = N;
  vector<bool> del(N, false);
  for (int i = 0; i < N; i++) {
    if (X[i] == 'S') {
      l = i;
    } else {
      if (l > -1) {
        ans -= 2;
        del[i] = true;
        del[l] = true;
        while (true) {
          if (del[l]) {
            l--;
          } else {
            if (X[l] == 'T') l = -1;
            break;
          }
          if (l < 0) break;
        }
      }
    }
  }

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

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

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    string s;
    cin >> s;
    int ans = s.size();
    int max_section = 0;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] != s[i-1]) {
            max_section = max(i,int(s.size()) - i);
            ans = min(ans,max_section);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "aising2020_c.cpp"

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

  int n;
  cin >> n;
  map<ll, ll> mp;
  for (ll x = 1; x < sqrt(n) + 1; x++) {
    for (ll y = 1; y < sqrt(n) + 1; y++) {
      for (ll z = 1; z < sqrt(n) + 1; z++) {
        mp[x * x + y * y + z * z + x * y + y * z + z * x]++;
      }
    }
  }

  FOR(i, 1, n + 1) { cout << mp[i] << endl; }
}


Measured memory_bytes: 5964
//#include<bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}

LL t,n,m,ans;
LL MOD=1e9+7;

int main()
{
	LL i,j,k,l,r,cnt;
	gn(n);gn(m);
	if(n>0)puts("Positive");
	else if(m<0){
		k=m-n+1;
		puts(k&1?"Negative":"Positive");
	}
	else puts("Zero");
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int n, q,i,j,k,max=0,maxIndex=0;
	int a,v,d[1000000]={0};
	scanf("%d %d",&n,&q);


	while(q) {
		scanf("%d %d", &a, &v);
		d[a] += v;
	  
		if(v > 0){
		  if(d[a] > max || max == d[a] && maxIndex > a){
		    maxIndex = a;
		    max = d[a];
		  }
		}
		else if(maxIndex == a && d[a] < max){
		  maxIndex=0;
		  max = 0;
		  for(i=1; i<=n; i++){
		    if(max < d[i]){
		      max = d[i];
		    maxIndex = i;
		    }
		  }
		}
		printf("%d %d\n",maxIndex,d[maxIndex]);
		q--;
	}
	return 0;
}

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

int dx[]={-1,0,1};

char f[90][1005];
int cnt[80001];

int calc(int x, int y)
{
	int area=0,rx=x;
	while(1)
	{
		area++;
		f[rx][y]=' ';
		
		rx++;
		if(f[rx][y]!='*')
		{
			rx--;
			break;
		}
	}
	
	y++;
	int ld, rd;
	for(int i=2; i>=0; i--)
	{
		int tx=x+dx[i];
		if(f[tx][y]=='*') ld=i;
	}
	
	for(int i=0; i<3; i++)
	{
		int trx=rx+dx[i];
		if(f[trx][y]=='*') rd=i;
	}
	
	while(1)
	{
		x+=dx[ld];
		rx+=dx[rd];
		
		if(x<0||f[x][y]!='*')
		{
			x-=dx[ld];
			rx-=dx[rd];
			y--;
			break;
		}
		
		area+=(rx-x)+1;
		f[x][y]=' ';
		f[rx][y]=' ';
		
		y++;
	}
	
	for(int i=x; i<=rx; i++)
		f[i][y]=' ';
	
	return area;
}

int main()
{
	int N;
	bool fg=true;
	while(cin >> N, N)
	{
		memset(f,' ', sizeof(f));
		memset(cnt, 0, sizeof(cnt));
		
		char b[90];
		cin.ignore();
		for(int i=0; i<N; i++)
		{
			cin.getline(b,90);
			for(int j=0; j<strlen(b); j++)
				f[j][i]=b[j];
		}
		
		for(int i=0; i<N; i++)
		for(int j=0; j<80; j++)
		{
			if(f[j][i]=='*')
			{
				int area=calc(j,i);
				cnt[area]++;
			}
		}
		
		if(!fg) cout << "----------" << endl;
		fg=false;
		for(int i=4; i<=80000; i++)
			if(cnt[i]) cout << i << " " << cnt[i] << endl;
	}

}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll x;
    cin>>x;
    fr(i,-200,200)
    {
        ll a=i*i*i*i*i;
        fr(j,-200,200)
        {
            ll b=j*j*j*j*j;
            if(a-b==x)
            {
                cout<<i<<" "<<j<<endl;
                return;
            }
        }
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

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

    vector<int> s(m),c(m);
    rep(i,m) cin >> s.at(i) >> c.at(i);

    bool ans = true;

    rep(i,m) {
        rep(j,m) {
            if(s.at(i)==s.at(j)) {
                if(c.at(i) != c.at(j)) {
                    ans = false;
                    break;
                }
            }
        }
        if(ans == false) break;
    }
    rep(i,m) {
        if(c.at(i) == 0) {
            if(s.at(i) == 1 && n != 1) {
                ans = false;
                break;
            }
        }
    }

    set<int> tmp;
    arep(x, s) {
        tmp.insert(x);
    }

    vector<int> num(n);
    rep(i,m) {
        num.at(s.at(i)-1) = c.at(i);
    }

    int ans_num = 0;
    rep(i,n) {
        if(num.at(i) != 0 || i == n-1) {
            ans_num += num.at(i) * pow(10,n-1-i);
        } else {
            if(i == 0) {
                ans_num += pow(10,n-1-i);
            }
        }
    }


    // rep(i,n) {
    //     if(tmp.count(i+1)) {
    //         ans_num += num.at(i)*pow(10,n-1-i);
    //     } else {
    //         if(n==1) {
    //             ans = 0;
    //         } else {
    //             if(i == n-1) {
    //                 ans_num += 1*pow(10,n-1-i);
    //             }
    //         }
    //     }
    // }


    if(ans) {
        cout << ans_num << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define             ll  long long
#define            ull  unsigned long long
#define            P_B  push_back
#define            M_P  make_pair
#define         DBG(x)  printf("%s %d\n", #x, x)
#define       DBGLL(x)  printf("%s %lld\n", #x, x)
#define         SCI(x)  scanf("%d",&x)
#define         SCD(x)  scanf("%lf",&x)
#define         SCS(x)  scanf("%s",x)
#define         CLR(x)  memset(x, 0, sizeof(x))
#define        CLRN(x)  memset(x, -1, sizeof(x))
#define        SCLL(x)  scanf("%lld", &x)
#define      FOR(i, n)  for(int i = 0; i < n; i++)
#define  FORR(i, m, n)  for(int i = m; i < n; i++)
#define     SCI2(m, n)  scanf("%d%d", &m, &n)
#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)
#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)
#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)
#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)
#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)
#define             vi  vector<int>
#define            vii  vector<pair<int, int> >
#define            vll  vector<pair<ll, ll> >
#define            Mod  1000000007
#define            INF  1000000000
 

int main()
{
	int n, m;
	SCI2(n, m);
	int dp[n+1][m+1];
	CLR(dp);
	dp[0][1] = 1;
	FORR(i, 1, n+1){
		FORR(j, 1, m+1){
			char ch;
			scanf(" %c", &ch);
			if(ch == '#') dp[i][j] = -1;
		}
	}
	FORR(i, 1, n+1){
		FORR(j, 1, m+1){
			if(dp[i][j] != -1){
				if(dp[i-1][j] != -1) dp[i][j] += dp[i-1][j];
				dp[i][j] %= Mod;
				if(dp[i][j-1] != -1) dp[i][j] += dp[i][j-1];
				dp[i][j] %= Mod;
			}
		}
	}
	if(dp[n][m] == -1) dp[n][m] = 0;
	printf("%d\n", dp[n][m]%Mod);
}

Measured memory_bytes: 4096
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	string s;
    cin>>s;
    int a[2]={};
    a[s[0]-'A']++;
    a[s[1]-'A']++;
    a[s[2]-'A']++;
    if(a[0]!=0&&a[1]!=0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
N = int(input())
S = []
S_10_ = [] #10の倍数でない数のリスト
for i in range(N):
  s = int(input())
  S.append(s)
  if(s%10 != 0):
    S_10_.append(s)

sum_all = sum(S)
if(sum_all%10 != 0):
  ans = sum_all
else:
  if(len(S_10_) > 0):
   S_10_.sort()
   ans = sum_all - S_10_[0]
  else:
   ans = 0
print(ans)

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

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

    rep(i, q) {
        int b, c;
        cin >> b >> c;
        sum += (c - b) * m[b];

        m[c] += m[b];
        m.erase(b);

        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 6572
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>(n);
		for(int i = 0; i < n; i++) list.add(sc.nextInt());
		Collections.sort(list);
		int max = list.get(list.size()-1);
		Collections.sort(list, (i1,i2) -> Math.abs((int)((double)max/2 - (double)i1)) - Math.abs((int)((double)max/2 - (double)i2)));
		System.out.println(max + " " + list.get(0));
	}
}


Measured memory_bytes: 62800
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>



using namespace std;


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

	vector<int> vec(S.size(), 0);
	vector<int> vec2(S.size(), 0);

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'L') {
			vec[i] = -1;
		}
		else {
			vec[i] = 1;
		}
	}

	int check = 0;
	int res = 0;
	int stockb = 0;
	int stockR = 0;
	int stockL = 0;
	

	for (int j = 0; j < S.size(); j++) {

		if (res == 0 && vec[j] == 1) {
			stockR++;

		}
		else if (res == 0 && vec[j] == -1) {
			stockb = j - 1;
			res = 1;
			stockL = 1;
		}
		else if (res == 1 && vec[j] == -1) {
			stockL++;

		}
		else if (res == 1 && vec[j] == 1) {
			res = 0;
			
			check = 1;
		}

		if (check == 1||j==S.size()-1) {

			int many = 0;
			if (stockR % 2==1) {
				many = 1;
			}
			else {
				many = -1;
			}
			
			int stock = stockR + stockL;

			if (stock % 2 == 0) {
				vec2[stockb] = stock / 2;
				vec2[stockb + 1] = stock / 2;
			}
			else {
				if (many == 1) {
					vec2[stockb] = (stock + 1) / 2;
					vec2[stockb + 1] = vec2[stockb] - 1;
				}
				else {
					vec2[stockb+1] = (stock + 1) / 2;
					vec2[stockb] = vec2[stockb+1] - 1;
				}
			}

			stockR = 1;
			stockL = 0;
			check = 0;

		}

		

		




	}

	for (int k = 0; k < S.size(); k++) {
		cout << vec2[k] << endl;
	}


}


Measured memory_bytes: 1536
#!/usr/bin/env python3
from bisect import bisect_left

def main():
    N, *C = map(int,open(0))
    M = max(C)
    m = 10**9+7
    # place[j]: i番目の石の位置を保持(1-index)
    place = [[] for _ in range(M+1)]
    for i in range(N):
        place[C[i]].append(i+1)
    # dp[i]: 最初からi個の石までで条件を満たす塗り方の総数
    dp = [0] * (N+1)
    dp[0] = 1
    for i in range(1,N+1):
        # 特に操作しない場合
        dp[i] += dp[i-1]
        dp[i] %= m
        
        # 操作する場合
        # 今見ているi番目の石が同じ色の石の集まりの中で何番目か
        j = bisect_left(place[C[i-1]],i)
        if j > 0:
            k = place[C[i-1]][j-1]# 同色でjより１つ前の石の位置
            if i-k > 1:
                dp[i] += dp[k]
                dp[i] %= m
    print(dp[N])

if __name__ == "__main__":
    main()

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;

const int inf =1 << 16;
const ll mod=1000000007LL;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

string field[55];
vector<int> cur;

int dist[55][55],prv[55][55][2];	


void bfs(int r,int c,int sr,int sc,int tr,int tc){
	rep(i,55)rep(j,55) dist[i][j]=inf,prv[i][j][0]=prv[i][j][1]=-1;
	queue<int> q;
	dist[sr][sc]=0,q.push(sr),q.push(sc);
	while(!q.empty()){
		int cr=q.front();q.pop();
		int cc=q.front();q.pop();
		rep(i,4){
			int nr=cr+dx[i],nc=cc+dy[i];
			if(nr<0||r<=nr||nc<0||c<=nc) continue;
			if(field[nr][nc]=='#' ) continue;
			if(chmin(dist[nr][nc],dist[cr][cc]+1)){
				q.push(nr),q.push(nc);
				prv[nr][nc][0]=cr;
				prv[nr][nc][1]=cc;
			}
		}
	}

	int cr=tr,cc=tc;
	vector<int> tmp;
	while(1){
		if(prv[cr][cc][0]==-1) break;
		tmp.push_back(cr*c+cc);
		int nr=prv[cr][cc][0];
		int nc=prv[cr][cc][1];
		swap(cr,nr),swap(cc,nc);
	}
	reverse(_all(tmp));
	copy(_all(tmp),back_inserter(cur));
	return;
}

ll per[55][55],on[55][55],off[55][55];
ll num[2510];

int main(void){
	int r,c,m;
	cin >> r >> c >> m;
	rep(i,r) cin >> field[i];
 	rep(i,r)rep(j,c) cin >> per[i][j];
	rep(i,r)rep(j,c) cin >> on[i][j];
	rep(i,r)rep(j,c) cin >> off[i][j];
	
	int pr=-1,pc=-1;
	rep(i,m){
		int cr,cc;
		cin >> cr >> cc;
		if(pr==-1&&pc==-1) 
			cur.push_back(cr*c+cc);
		else
			bfs(r,c,pr,pc,cr,cc);
		swap(cr,pr),swap(cc,pc);
	}

	int n=cur.size();
	vector<int> tmp(n,0);
	clr(num,-1);
	
	rrep(i,n){
		tmp[i]=num[cur[i]];
		num[cur[i]]=i;
	//	cerr << tmp[i] << " " << num[cur[i]] << endl;	
	}

	ll ans=0LL;
	rep(i,n){
		int cr=cur[i]/c,cc=cur[i]%c;
		// cerr << i << " " << cr << " " << cc << " " << tmp[i] << endl;
		if(tmp[i]!=-1)
			ans+=min(per[cr][cc]*(tmp[i]-i),on[cr][cc]+off[cr][cc]);
		else
			ans+=on[cr][cc]+off[cr][cc];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13224
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;

int n, a[1000], m, i, j;
long long sum, sum1, sum2;

int main()
{
	while(cin >> n)
	{
		sum1 = 0, sum2 = 0;
		for(i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a + n, greater<int>());
		for(i = 0; i < n; i++)
		{
			if(i % 2 == 0) sum1 += a[i];
			if(i % 2 == 1) sum2 += a[i];
		}
		cout << abs(sum2 - sum1) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
/* ex6_2
   offNaria */
#include <stdio.h>
#include <string.h>

int main(void){
  int length;
  char input[100];
  scanf("%s", &input);
  length = strlen(input);
  printf("%c%d%c\n", input[0], length-2, input[length-1]); //入力の先頭，先頭と末尾以外の長さ，末尾を出力
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int x = 0;
	int cout = 0;
	int temp = 0;
	int ans = 1;
	for(int i = 1; i <= n; i++) {
		x = i;
		while(x % 2 == 0) {
			temp++;
			x /= 2;
		}
		if(temp > cout) {
			cout = temp;
			ans = i;
		}
		temp = 0;
	}
	System.out.println(ans);
}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;
const ll MOD = 1e9+7;

int main(){
    int h, w; cin >> h >> w;
    vector<int> data(26,0);
    rep(i,h){
        string s; cin >> s;
        rep(j,w) data[s[j]-'a']++;
    }
    vector<int> data2(4,0);
    rep(i,26){
        int k = data[i]%4;
        data2[k]++;
    }
    if(h%2==0 && w%2==0){
        cout << (data2[1]==0 && data2[2]==0 && data2[3]==0 ? "Yes" : "No") << endl;
    }
    else if(h%2==1 && w%2==0){
        if(!(data2[1]+data2[3] == 0)) cout << "No" << endl;
        else if(w/2>=data2[2] && (w/2-data[2])%2==0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(h%2==0 && w%2==1){
        if(!(data2[1]+data2[3] == 0)) cout << "No" << endl;
        else if(h/2>=data2[2] && (h/2-data[2])%2==0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        if(!(data2[1]+data2[3] == 1)) cout << "No" << endl;
        else if(h+w-2>=(data2[2]+data2[3])*2 && (h+w-2-(data2[2]+data2[3])*2)%4==0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
string a,b;
int len1,len2;
int main()
{
	cin>>a>>b;
	len1=a.size();
	len2=b.size();
	for(int i=0;i<len1;++i)
	{
		if(a[i]!='\0')
			cout<<a[i];
		if(b[i]!='\0')
			cout<<b[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import heapq
import numpy

n, k = map(int, input().split())
h = list(map(int, input().split()))

h = numpy.array(h)
h *= -1
h = list(h)
heapq.heapify(h)

for i in range(k):
    if i > n-1:
        break
    heapq.heappop(h)
print(sum(h)*-1)



Measured memory_bytes: 34224
import Control.Monad

main::IO()
main=do
  nc<-getLine
  let n = read nc ::Int
  ls<-forM [1..n] (\_->getLine)
  let intpair= map (\s->map read (words s)) ls ::[[Int]]
  print (sum (map (\(a:b:[])->((b-a)+1)) intpair))

Measured memory_bytes: 1660
#include<cstdio>
using namespace std;
int main(){
	for(;;){
		int a[10][10]={0};
		if(scanf("%1d",&a[0][0]) == EOF){break;}
		for(int i=1; i<10; i++){scanf("%1d",&a[0][i]);}
		for(int i=1; i<10; i++){
			for(int j=0; j<10-i; j++){
				a[i][j] = (a[i-1][j]+a[i-1][j+1])%10;
			}
		}
		printf("%d\n",a[9][0]);
	}
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC142A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int odd = 0;
            if (N % 2 == 0)
            {
                odd = N / 2;
            }
            else
            {
                odd = (N + 1) / 2;
            }
            decimal ans = (decimal)odd / N;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27560
a = list(map(int, input().split()))
b = int(input())

t = 0
s = 0
while a[1] <= a[0]:
    a[1] = a[1] * 2
    t = t + 1
while a[2] <= a[1]:
    a[2] = a[2] * 2
    s = s + 1

if t+s <=b:
    print("Yes")
else:
    print("No")

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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 2e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e17;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

map <int, int> mp;

signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int sz;
   string s;
   cin >> s;
   bool ok = false;
   sz = s.size();
   int i = 0;
   while (i < s.size()) {
      if (i + 1 == s.size()) break;
      if (s[i] != s[i + 1]) {
         i++;
         continue;
      }
      sz--;
      i+= 3;
   }
   cout << sz;

}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scn = new Scanner(System.in);

        Integer num1 = scn.nextInt();
        Integer num2 = scn.nextInt();

        Integer area = num1 * num2;
        Integer line = 2*num1 + 2*num2;

        System.out.println(area + " " + line);

        scn.close();
    }

}


Measured memory_bytes: 26192
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)
# 添字調整
a_arr.unshift(nil)

# i日目の最大所持金
dp = [nil, 1000]
(2..n).each do |i|
  # 前日から何もしない場合
  dp[i] = dp[i-1]
  # j日目で買ってi日目で売る場合
  (1..i-1).each do |j|
    # j日目で買う株数
    stock = dp[j] / a_arr[j]
    # j日目の残金 + i日目で得られる金額
    tmp_yen = (dp[j] - stock * a_arr[j]) + stock * a_arr[i]
    dp[i] = tmp_yen if tmp_yen > dp[i]
  end
end

puts dp[-1]


Measured memory_bytes: 14320
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

void lcs(string s, string t){
    int m = s.size() + 1;
    int n = t.size() + 1;
    vector<vector<int>> dp(m, vector<int>(n));
    rep(i, m) dp[i][0] = 0;
    rep(i, n) dp[0][i] = 0;
    for (int i = 1; i < m; i++){
        for (int j = 1; j < n; j++){
            if (s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else if (dp[i - 1][j] >= dp[i][j - 1])
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = dp[i][j - 1];
        }
    }
    cout << dp[m - 1][n - 1] << endl;
}

int main(){
    int q;
    cin >> q;
    string s, t;
    rep(k, q) {
        cin >> s >> t;
        lcs(s, t);
    }
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int m = 1000;
    for (int i = 0;i < s.size() - 2; i++) {
        m = min(m, abs(100 * (s[i] - '7') + 10 * (s[i + 1] - '5') + s[i + 2] - '3'));
    }
    cout << m << endl;
}
     

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	
	int L,N;
	string tmp;
	vector<string> S;
	cin>>N>>L;

	for(int i=0;i<N;i++){
		cin>>tmp;
		S.push_back(tmp);
	}

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

	for(int i=0;i<N;i++){
		cout<<S[i];
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<int> a(n*3);
    rep(i,n*3)cin>>a.at(i);
    priority_queue<int,vector<int>,greater<int>> prique;
    vector<int> fr(n+1);
    int sum=0;
    rep(i,n){
        sum+=a.at(i);
        prique.push(a.at(i));
    }
    fr.front()=sum;
    rep(i,n){
        sum+=a.at(n+i);
        prique.push(a.at(n+i));
        int p=prique.top(); prique.pop();
        sum-=p;
        fr.at(i+1)=sum;
    }
    priority_queue<int> prique2;
    vector<int> ba(n+1);
    int sum2=0;
    for(int i=n*3-1; i>=n*2; i--){
        sum2+=a.at(i);
        prique2.push(a.at(i));
    }
    ba.back()=sum2;
    for(int i=n-1; i>=0; i--){
        sum2+=a.at(n+i);
        prique2.push(a.at(n+i));
        int p=prique2.top(); prique2.pop();
        sum2-=p;
        ba.at(i)=sum2;
    }
    int ans=-INF;
    rep(i,n+1){
        chmax(ans, fr.at(i)-ba.at(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6516
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 1e5 + 10;
char s[N];

int main() {
  int n;
  scanf("%d%s", &n, s);
  int ret = 0;
  for (int i = 0, j; i < n; i = j) {
    for (j = i + 1; j < n && s[j] == s[i]; ++j);
    ret += 1;
  }
  printf("%d\n", ret);
  return 0;
}


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

int main(){
	string s, s1;
	int n;
	while(cin >> n, n){
		cin >> s;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < s.size();j++){
				char c[10];int max = 0;
				while(s[j] == s[j + 1])j++, max++;
				sprintf(c, "%d", max + 1);
				s1 += c;
				s1 += s[j];
			}
			s = s1;s1 = "";
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3304
/*************************************************************************
 > File Name: E.cpp
 > Author: codecode
 > Mail: 2466734364@qq.com
 > Created Time: 2020.1.26:20:20
 ************************************************************************/
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e3+10;
int h,n,ans=233333333333,s,f[maxn*10];
struct juju{
	int a,b;
}t[maxn];
#undef int
int main(){
#define int long long
	cin>>h>>n;
	for(int i=1;i<=n;i++)
		cin>>t[i].a>>t[i].b,
		s=max(s,t[i].a);
	for(int i=0;i<h;i++)f[i]=2333333333333;
	for(int i=1;i<=n;i++)
		for(int j=h-t[i].a;j>=0;j--)
			f[j]=min(f[j],f[j+t[i].a]+t[i].b);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=t[i].a;j++)
			ans=min(ans,f[j]+t[i].b);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;
int a[200];

int main(){
  cin >> n;
  REP(i,n) cin >> a[i];
  sort(a,a+n);
  reverse(a,a+n);
  int ans = 0;
  REP(i,n){
    if(i%2==0) ans += a[i];
    else ans -= a[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int n,k;
    scanf("%d %d",&n,&k);
    vector<int>A(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    vector<int>dp(k+1,0);
    for(int i=0;i<=A[0];i++) dp[i] = 1;

    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++) dp[j] = (dp[j-1] + dp[j])%mod;
        vector<int>newdp(k+1,0);
        for(int j = 0;j<=k;j++){
            int range = min(k,A[i]);
            int r = ((j-range-1)<0)?0:dp[j-range-1];
            r = (dp[j] - r+mod)%mod;
            newdp[j] = r;
        }
        dp = newdp;
    }
    printf("%d\n",dp[k]);
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

string s;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  int n;cin>>n;
  cin>>s;
  stack<char> st;
  int i=0;
  while(i<(int)s.length()){
    if(s[i]=='('){
      st.push('(');
    }else {
      if(st.empty()){
        s="("+s;
        i++;
      }else{
        st.pop();
      }
    }
    i++;
  }
  for(i=0;i<(int)st.size();i++){
    s+=")";
  }
  cout<<s<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  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;
typedef pair<int, int> P;

int main() {
	int n, m;
	cin >> n >> m;
	int l = 0, r = 1000000;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		l = max(l, a);
		r = min(r, b);
	}
	cout << max(0, r - l + 1) << endl;
	return 0;
}


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

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(N, D, A, XH):
    XH.sort()
    X = [x for x, _ in XH]
    H = [h for _, h in XH]

    q = deque()
    ans = 0
    dmg = 0
    for x, h in XH:
        while q and q[0][0] < x:
            _, d = q.popleft()
            dmg -= d
        if h <= dmg:
            continue
        a = -(-(h - dmg) // A)
        ans += a
        q.append((x+2*D, a*A))
        dmg += a*A
    return ans


def main():
    N, D, A = read_int_n()
    XH = [read_int_n() for _ in range(N)]
    print(slv(N, D, A, XH))


if __name__ == '__main__':
    main()


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

using namespace std;

#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

void solve (int u) {

    ll n, W;
    cin >> n >> W;

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

    ll sum = 0;
    for (int c : v) sum += c;

    vector <ll> dp (sum + 1, 1e18L + 5);
    dp[0] = 0;

    for (int i = 0; i < n; ++i) {

        for (int j = sum - v[i]; j >= 0; --j) {
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
        }
    }

    ll res = 0;

    for (ll i = 0; i <= sum; ++i) {
        if (dp[i] <= W) {
            res = max(res, i);
        }
    }

    cout << res << "\n";

//    cout << "Case #" << k << ": " << count << "\n";

}

int main () {

    ios::sync_with_stdio(0);
    cin.tie(0);

    //int t;
    //cin >> t;
    //int k = 1;
    //while (t--) {
    //    solve(k);
    //    k++;
    //}

    solve(0);
}


Measured memory_bytes: 1024
#include <cmath>
#include <iostream>

using namespace std;

int N, D;
void solve();

int main() {
  cin >> N >> D;
  solve();
}

void solve() {
  int ans = (N / (1 + 2 * D));
  if (N % (1 + 2 * D) != 0) {
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	t := 1
	ans := 0
	for i := 0; i < n; i++ {
		a := readInt()
		if a == t {
			t++
		} else {
			ans++
		}
	}
	if ans == n {
		fmt.Println(-1)
		return
	}
	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

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

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second　   //pairの二つ目の要素

int main(){
    int n;
    cin>>n;
    int ans=0;
    int minv=INF;
    int p;
    rep(i,n){
        cin>>p;
        if(p<=minv){ 
            ans++;
            minv=p;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define M 100001
#define MAX(a,b) ((a) < (b) ? (b) : (a))
 
int par[M],sib[M],deg[M];
int height[M],deph[M];
 
void init(int);
int depth(int,int);
 
int main(void){
  int n,i,id,l,r,t;
 
  scanf("%d" ,&n); 
  init(n);  
 
  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d" ,&id ,&l ,&t);
 

    if(l != -1){
      par[l] = id;
      deg[id]++;
    }
    if(t != -1){
      par[t] = id;
      deg[id]++;
    }
    if(l != -1 && t != -1){
      sib[l] = t;
      sib[t] = l;
    }
  }
 
  for(i = 0 ; i < n ; i++){
    deph[i] = depth(i,0);
  }
 
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, sibling = %d, "
       ,i, par[i], sib[i]);
 
    printf("degree = %d, depth = %d, height = %d, "
       , deg[i], deph[i], height[i]);
     
    if(par[i] == -1){
      printf("root\n");
    }else if(deg[i] != 0){
      printf("internal node\n");
    }else{
      printf("leaf\n");
    }
  }
 
  return 0;
}
 
void init(int n){
  int i;
 
  for(i = 0 ; i < n ; i++){
    par[i] = sib[i] = -1;
    deg[i] = height[i] = 0;
  }
}
 
int depth(int x,int dep){
  height[x] = MAX(height[x],dep);
  if(par[x] == -1){
    return dep;
  }else{
    return depth(par[x],dep+1);
  }
}

Measured memory_bytes: 628
res = []
while True:
    m, f, r = (int(x) for x in input().split())
    if(m == -1 and f == -1 and r == -1): break
    if (m == -1 or f == -1): res.append("F")
    elif (m + f >= 80): res.append("A")
    elif (m + f >= 65): res.append("B")
    elif (m + f >= 50): res.append("C")
    elif (r >= 50): res.append("C")
    elif (m + f >= 30): res.append("D")
    else: res.append("F")

for result in res:
    print(result)


Measured memory_bytes: 5604
#include <stdio.h>

int main(void) {
    int s_1;
    scanf("%d",&s_1);
    int s[4];
    s[0] = s_1 / 1000;
    s[1] = (s_1 / 100) % 10;
    s[2] = (s_1 / 10) % 10;
    s[3] = s_1 % 10;
    if((s[2] * 10 + s[3] <= 12 && s[2] * 10 + s[3] >= 1)  &&  (s[0] * 10 + s[1] > 12 || s[0] * 10 + s[1] < 1)) {
        printf("YYMM\n");
    } else if((s[0] * 10 + s[1] <= 12 && s[0] * 10 + s[1] >= 1)  &&  (s[2] * 10 + s[3] > 12 || s[2] * 10 + s[3] < 1)) {
        printf("MMYY\n");
    } else if((s[2] * 10 + s[3] <= 12 && s[2] * 10 + s[3] >= 1)  &&  (s[0] * 10 + s[1] <= 12 && s[0] * 10 + s[1] >= 1)) {
        printf("AMBIGUOUS\n");
    } else {
        printf("NA\n");
    }
    return 0;
}


Measured memory_bytes: 128
N, M = (int(x) for x in input().split())
H = [int(x) for x in input().split()]

high = set()
low = set()
lonely = set()

for i in range(M):
	i1, i2 = [int(x) for x in input().split()]
	if H[i1 - 1] > H[i2 - 1]:
		high.add(i1)
		low.add(i2)
	elif H[i1 - 1] < H[i2 - 1]:
		high.add(i2)
		low.add(i1)
	else:
		low.add(i1)
		low.add(i2)
	lonely.add(i1)
	lonely.add(i2)

result = len((high - low)) + (N  - len(lonely))
print(result)

Measured memory_bytes: 27456
#include <cstdio>

#define maxn 100

int a[maxn + 2], b[maxn + 2];
int main() {
    int nra = 0, nrb = 0;
    char x = fgetc(stdin);
    int y;
    while (x != '\n') {
        y = x - '0';
        nra++;
        a[nra] = y;
        x = fgetc(stdin);
    }
    x = fgetc(stdin);
    while (x != '\n') {
        y = x - '0';
        nrb++;
        b[nrb] = y;
        x = fgetc(stdin);
    }
    if (nra > nrb)
        printf("GREATER");
    else if (nra < nrb)
        printf("LESS");
    else {
        int p = 0;
        for (int i = 1; i <= nra && p == 0; i++) {
            if (a[i] > b[i])
                p = 1;
            else if (a[i] < b[i])
                p = 2;
            else
                p = 0;
        }
        if (p == 1)
            printf("GREATER");
        else if (p == 2)
            printf("LESS");
        else
            printf("EQUAL");
    }

    return 0;
}


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

int main() {
  int H, N;
  cin >> H >> N;
  
  int A;
  
  for (int i = 0; i < N; i++) {
    cin >> A;
    H -= A;
  }
  
  if (H > 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	
	while (scanf("%d %d", &a, &b) != EOF){
		a = a + b;
		b = 0;
		do{
			b++;
			a /= 10;
		}while (a != 0);
		printf("%d\n", b);
	}
	
	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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 (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n, k;
	cin >> n >> k;
	vi h(n);
	rep(i, n) cin >> h[i];

	priority_queue<int> pq;
	rep(i, n) pq.push(h[i]);

	rep(i, k) pq.pop();

	ll ans = 0;
	rep(i, n-k)
	{
		ans += pq.top();
		pq.pop();
	}

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

Measured memory_bytes: 2168
#include<stdio.h>

int sensearch(int *,int,int);

int main()
{
  int n,i,key,sum=0,q;

  scanf("%d",&n);

  int a[n];

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

  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&key);
      if(sensearch(&a[0],n,key))sum++;
    }
  printf("%d\n",sum);

  return 0;
}

int sensearch(int *a,int n,int key)
{
  int i=0;
  a[n]=key;
  while(a[i]!=key)i++;

  return i != n;
}



Measured memory_bytes: 2104
# N個のマス
N = int(input())

# タイルの高さ（H）のリスト
H_list = list(map(int,input().split()))

Judge = True

# 最初のマスは,単調非現象にするには必ず１低くするのが最適
H_list[0]-=1

for i in range(N-1):
    # 右側i+1のマスが高ければ必ず１低くする
    if H_list[i] < H_list[i+1]:
        H_list[i+1]-=1
    elif H_list[i] > H_list[i+1]:
    # 左側が高くなれば　単調非現象は成立しない
        Judge = False

if Judge == True:
    print('Yes')
elif Judge == False:
    print('No')

Measured memory_bytes: 14252
#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++)
static const int MAX = 100;
int in(){int x; scanf("%d",&x); return x;}

int main(){
  int N = in();
  int x, prev = 987654321, sum = 0;
  rep(i, N-1){
    x = in();
    sum += min(x, prev);
    prev = x;
  }
  cout << sum + prev << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[])
{
    int n, a, b;
    std::cin >> n >> a >> b;

    int result = 0;
    for(int i=1; i<=n; ++i)
    {
        int sum = 0;
        int val = i;
        while(true)
        {
            if(val == 0)
            {
                break;
            }
            int tmp = val % 10;
            val /= 10;
            sum += tmp;
        }
        if(sum >= a && sum <= b)
        {
            result += i;
        }
    }

    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
	int A,B,K,temp,temp1;

	scanf("%d %d",&A,&B);

	K=A+B;
	if(K%2==1){
		printf("IMPOSSIBLE\n");
	}
	else{
		printf("%d\n",K/2);
	}
}

Measured memory_bytes: 256