akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


void  bubbleSort(int number[], int length);

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

	int pow[20000];

	pow[0] = 1;
	int count = 1;

	for (int i = 2; i < 32; i++) {
		int temp = i;
		while (temp*i<=1000) {
			temp *= i;
			pow[count] = temp;
			count++;
		}
	}

	bubbleSort(pow, count);

	int ans = 0;

	for (int i = 0; i < count; i++) {
		if (pow[i] <= N)ans = pow[i];
		else break;
	}

	printf("%d", ans);

}

//---数列を昇順ソート（だんだん大きくなる）----
void  bubbleSort(int number[], int length) {
	for (int i = 0; i < length; i++)
		for (int j = i + 1; j < length; j++)
			if (number[i] > number[j]) {
				int tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
}



/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  std::cout << std::fixed << std::setprecision(10);

  double t;
  double x;
  scanf("%lf %lf", &t, &x);

  cout << (t / x) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int a=0;
  for(int i=0;i<4;i++){
    char x=s.at(i);
    if(x=='+'){
      a++;
    }
    else{
      a--;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

//27日目

int main() {

	string ans;
	int n, f[101][12], p[101][12];
	cin >> n;
	for (int i = 0; i<n; ++i) {
		for (int j = 0; j<10; ++j) {
			cin >> f[i][j];
		}
	}
	for (int i = 0; i<n; ++i) {
		for (int j = 0; j <= 10; ++j) {
			cin >> p[i][j];
		}
	}
	int m = -1e9;
	for (int bit = 1; bit<1 << 10; ++bit) {

		int ans = 0;
		for (int i = 0; i<n; ++i) {
			int cnt = 0;
			for (int j = 0; j<10; ++j) {
				if (bit&(1 << j) && f[i][j])cnt++;
			}
			ans += p[i][cnt];
		}
		m = max(m, ans);
	}

	cout << m << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 1; i < (int)(n); i++)
#define invrep(i,n) for(int i = (int)(n); i > 0; i++)
using ll = long long;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if (a >= k) {
        cout << k << endl;
        return 0;
    }

    int tmp = k - a;
    rep(i, b + 1) {
        --tmp;
        if (tmp == 0) {
            cout << a << endl;
            return 0;
        }
    }

    rep(i, c + 1) {
        --tmp;
        if (tmp == 0) {
            cout << a - i << endl;
            return 0;
        }
    }
}

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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> as;
  as.push_back(0);
  for (int i = 0; i < n; ++i) {
    int a;
    std::cin >> a;
    as.push_back(a);
  }
  int cnt = 0;
  for (int i = 1; i < n+1; ++i) {
    if (i > as[i])
      continue;
    if (i == as[as[i]])
      ++cnt;
  }
  std::cout << cnt << std::endl;
}


Measured memory_bytes: 892
#include <functional>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define NDEBUG

int main()
{
    string t, p;
#ifdef NDEBUG
    cin >> t;
    cin >> p;
#else
    t = "aizucamp";
    p = "azu";
    // t = "abracadabra";
    // p = "rada";
    t = "aabc";
    p = "aabc";
#endif

    t += "$";
    p += "$";

    auto ppc = [](const std::string& s, int n, const std::vector<bool>& v) {
        stringstream ss;
        for (int i = 0; i < s.size(); ++i) {
            if (v[i]) {
                ss << "\033[31m";
            }
            if (i == n) {
                ss << "[" << s[i] << "]";
            }
            else {
                ss << s[i];
            }
            if (v[i]) {
                ss << "\033[0m";
            }
        }
        return ss.str();
    };
    auto pp = [](const std::string& s, int n) {
        stringstream ss;
        for (int i = 0; i < s.size(); ++i) {
            if (i == n) {
                ss << "[" << s[i] << "]";
            }
            else {
                ss << s[i];
            }
        }
        return ss.str();
    };

    vector<bool> exists(p.size() - 1);
    bool duplicated = false;
    int i = 0;
    int j = 0;
    char tmp = '!';
    while (j != t.size()) {
#ifndef NDEBUG
        cout << "T " << pp(t, j) << endl;
        cout << "P " << ppc(p, i, exists) << endl;
        cout << tmp << endl;
        cout << boolalpha << "duplicate: " << duplicated << "\n" << endl;
#endif
        if (p[i] == t[j]) {
            if (!exists[i]) {
                exists[i] = true;
                tmp = p[i];
                i += 1;
            }
        }
        else if (tmp == t[j]) {
            duplicated = true;
        }
        else {
            if (exists[i]) {
                i += 1;
            }
        }
        j += 1;
    }
#ifndef NDEBUG
    cout << "T " << pp(t, j) << endl;
    cout << "P " << ppc(p, i, exists) << endl;
    cout << tmp << endl;
    cout << boolalpha << "duplicate: " << duplicated << "\n" << endl;
#endif
    if (accumulate(begin(exists), end(exists), true, logical_and<>())) {
        if (!duplicated) {
            cout << "yes" << endl;
            return 0;
        }
    }
    cout << "no" << endl;
}

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

using namespace std;

int N, K;

int main() {
	cin >> N >> K;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		if (h >= K) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

ll a,b,c;

inline ll rd(){
	ll ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	a=rd(); b=rd(); c=rd();
	printf("%lld",a+b>=c?b+c:a+2*b+1);
	return 0;
}//Faze


Measured memory_bytes: 256
#include <iostream>
#include <algorithm> 
#include <cmath>
//#include <bitset>
//#include <deque>
#include <iterator>
#include <map> 
//#include <queue>
//#include <stack>
#include <string>
#include <vector>
#include <array>
//#include <tuple>
#include <unordered_map>
//#include <unordered_set>

using namespace std;

typedef long long ll;
struct __{__(){ios_base::Init i;ios_base::sync_with_stdio(0);cin.tie(0);}}__; 



int main() {
	//1 2 3 4 5
	ll n;
	cin >> n;
	int cnt = 0;
	int p = 0;
	ll i = 0;
	for (; i < n; i += p) {
		p++;
		cnt++;
	}
    cout << cnt;
} 











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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, c;
    cin >> a >> b >> c;
    a = (a % c) ? c * (a / c + 1) : a;
    b = (b % c) ? c * (b / c) : b;
    cout << (b - a) / c + 1 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    string s; cin>>s;
    deque<char> que;
    int Bcount=0;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='B')Bcount++;
        else{
            if(Bcount>0){
                Bcount--;
                continue;
            }
            que.push_front(s[i]);
        }
    }
    for(auto itr=que.begin();itr<que.end();itr++){
        cout<<*itr;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
	int a, b, n;
	
	while (scanf("%d %d %d", &a, &b, &n) != EOF){
		while (a > b){
			a -= b;
		}
		if (a % b == 0){
			puts("0");
			continue;
		}
		int sum = 0, c, d;
		for (int i = 0; i < n; i++){
			c = (a * 10) / b;
			d = (a * 10) % b;
			a = d;
//			printf("%d %d\n", c, sum);
			sum += c;
		}
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int h, w, d;
int a[310][310];
int q;
int l[100010], r[100010];
vector<int> v(300*300+1,0);
map<int, pair<int, int>> mp;
int main()
{
    cin >> h >> w>>d;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a[i][j];
            mp[a[i][j]] = make_pair(i, j);
        }
    }

    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
    }
    
    for (int i = d+1; i <=h*w; i++)
    {
        v[i] = abs(mp[i].first - mp[i - d].first) + abs(mp[i].second - mp[i - d].second)+v[i-d];
    }

    for (int i = 0; i < q; i++)
    {
        long long cnt = 0;
        cnt = v[r[i]] - v[l[i]];
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <stack>

using namespace std;

int main()
{
  stack<int> cats_stack;
  bool cave_in_cat[100] = { false };
  int n;
  int cat_number;
  
  cin >> n;

  cin >> cat_number;
  if (cat_number < 0) {
    cout << "1" << endl;
    return 0;
  } else {
    cats_stack.push(cat_number);
    cave_in_cat[cat_number] = true;
  }

  for (int i = 2; i <= n; i++) {
    cin >> cat_number;
    if (cat_number > 0) {
      if (cave_in_cat[cat_number] == false) {
        cats_stack.push(cat_number);
        cave_in_cat[cat_number] = true;
      } else {
        cout << i << endl;
        return 0;
      }   
    } else if (cat_number < 0) {
      if (!cats_stack.empty()) {
        if (cats_stack.top() == -cat_number) {
          cats_stack.pop();
          cave_in_cat[-cat_number] = false;
        } else {
          cout << i << endl;
          return 0;
        }
      } else {
        cout << i << endl;
        return 0;
      }
    }
  }

  cout << "OK" << endl;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	if(n==25)puts("Christmas");
	if(n==24)puts("Christmas Eve");
	if(n==23)puts("Christmas Eve Eve");
	if(n==22)puts("Christmas Eve Eve Eve");
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int s, w; cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
  return 0;
}


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

using namespace std;

#pragma GCC optimize("-O3")
#pragma GCC target("avx2")

#define int long long

const int INF = 1e18;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a;
    cin >> a;
    string s;
    cin >> s;
    int b = (s[0] - '0');
    b *= 10;
    b += (s[2] - '0');
    b *= 10;
    b += (s[3] - '0');
    cout << a * b / 100 << endl;
    return 0;
}


Measured memory_bytes: 3652
import itertools

str_n, str_k = input().split()
n = int(str_n)
k = int(str_k)

d = set([int(di) for di in input().split()])
opt = list({0,1,2,3,4,5,6,7,8,9} - d)

def isok(num):
    if set([int(_) for _ in list(str(num))]) - set(opt) == set():
        return True
    else:
        return False

i = 0
while True:
    if isok(n + i):
        print(n + i)
        break
    i += 1

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class UnionFind
{
public:
    UnionFind(int n)
        : mN(n)
    {
        REP(i, n)
        {
            mNodeTbl.push_back(i);
            mRankTbl.push_back(0);
        }
    }

    int find(int x)
    {
        if (x == mNodeTbl[x])
            return x;
        return mNodeTbl[x] = find(mNodeTbl[x]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    void unit(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (mRankTbl[x] < mRankTbl[y])
        {
            mNodeTbl[x] = y;
        }
        else
        {
            mNodeTbl[y] = x;
            if (mRankTbl[x] == mRankTbl[y])
                mRankTbl[x]++;
        }
    }

private:
    int mN;
    vector<int> mNodeTbl;
    vector<int> mRankTbl;
};

int X[100005], Y[100005], Z[100005];
bool U[100005];

int main()
{
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N);
    REP(i, M)
    {
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--;
        Y[i]--;

        uf.unit(X[i], Y[i]);
    }
    memset(U, 0, sizeof(U));
    REP(i, N)
    {
        U[uf.find(i)] = true;
    }
    int ans = 0;
    REP(i, N)
    {
        if (U[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2548
import sys
S,T = input(),input()
N,M = len(S),len(T)

found = []
for i in range(N-M+1):
    for j in range(M):
        c1 = S[i+j]
        c2 = T[j]
        if c1 != '?' and c1 != c2: break
    else:
        found.append(i)

if len(found) == 0:
    print('UNRESTORABLE')
    sys.exit()

ans = []
for i in range(N):
    if found[-1] <= i < found[-1] + M:
        ans.append(T[i - found[-1]])
    elif S[i] == '?':
        ans.append('a')
    else:
        ans.append(S[i])
print(''.join(ans))


Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

bef = 100000
count = 1
ans = 0

for a in A:
    # print("ans = %d" % ans)
    # print("now is %d" % a)
    if bef == a:
        count += 1
    else:
        ans += count // 2
        count = 1
        bef = a

ans += count // 2

print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

res = 0

for i in range(n):
    x = a[i] - 1
    res += b[x]

    if i < n - 1 and a[i] + 1 == a[i + 1]:
        res += c[x]

print(res)


Measured memory_bytes: 3064
#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;
const int MAX_N = 100005;
int a[MAX_N],b[MAX_N],c[MAX_N],dpa[MAX_N],dpb[MAX_N],dpc[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	dpa[0] = a[0], dpb[0] = b[0], dpc[0] = c[0];
	rep(i,N-1)
	{
		dpa[i+1] = max(dpb[i] + a[i+1], dpc[i] + a[i+1]);
		dpb[i+1] = max(dpa[i] + b[i+1], dpc[i] + b[i+1]);
		dpc[i+1] = max(dpa[i] + c[i+1], dpb[i] + c[i+1]);
	}
	cout << max(dpa[N-1],max(dpb[N-1],dpc[N-1])) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int cnt, a, b, ans[205];
char str[20];
int main()
{
    while(cin>>a>>b) {
        sprintf(str,"%d",a+b);
        ans[cnt]=strlen(str);
        cnt++;
    }
    for(int i=0; i<cnt; i++)
        printf("%d\n", ans[i]);
    return 0;
}


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

#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
                                           	
const int N = 1e5 + 123, inf = 1e9 + 123, mod = 1e9 + 7;
const ll INF = 1e18;

ll w[N], v[N], d[N];
bool dp[N];

int main() {
	cin.tie(0);  	
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = sum; j >= 0; j--) {
			if (dp[j]) {
				if (!dp[j + v[i]]) {        	
					d[j + v[i]] = d[j] + w[i];
					dp[j + v[i]] = 1;
				} else {
					d[j + v[i]] = min(d[j] + w[i], d[j + v[i]]);
				}
			}
		}
	}
	for (int i = sum; i >= 0; i--) {
		if (dp[i]) {
			if (d[i] <= m) {
				cout << i;
				return 0;
			}
		}
	}
	return 0;
}                                                

Measured memory_bytes: 1152
import java.util.Scanner;
import java.util.TreeSet;


public class Main {
	static class Range implements Comparable<Range>{
		long start;
		long depth;
		Range(long s , long d){
			start = s;
			depth = d;
		}
		public Range(Range r) {
			start = r.start;
			depth = r.depth;
		}
		@Override
		public int compareTo(Range o) {
			int c = Long.compare(start, o.start);
			if(c == 0){
				return Long.compare(o.depth, depth);
			}
			return c;
		}
		@Override
		public String toString() {
			return start+" "+depth;
		}
	}
	static class Reversi{
		long black;
		TreeSet<Range> tops;
		TreeSet<Range> lefts;
		public Reversi(int N) {
			long n = (long)N;
			tops = new TreeSet<Range>();
			lefts = new TreeSet<Range>();
			black = (n - 2) * (n - 2);
			Range r = new Range(2, n - 2);
			tops.add(r);
			lefts.add(r);
		}
		
		void put(int q, int x){
			TreeSet<Range> puts  = (q == 1) ? tops : lefts;
			TreeSet<Range> sides = (q == 1) ? lefts : tops;
			Range ins = puts.lower(new Range(x , -1));
			black -= ins.depth;
			if(ins.start == 2){
				Range p = new Range(puts.pollFirst());
				Range s = new Range(sides.pollFirst());
				s.depth = x - 2;
				sides.add(s);
				Range p2 = new Range(x + 1 , p.depth);
				puts.add(p);
				puts.add(p2);
			}
		}
		
		long black(){
			return black;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Reversi r = new Reversi(N);
		int Q = sc.nextInt();
		for(int q = 0 ; q < Q ; ++q){
			int a = sc.nextInt();
			int x = sc.nextInt();
			r.put(a, x);
		}
		System.out.println(r.black());
	}
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){

int a[10];
REP(i,10)cin>>a[i];
sort(a,a+10);
REP(i,3)cout<<a[9-i]<<endl;

  return 0;
}

Measured memory_bytes: 1176
#include<cstdio>
#include<algorithm>
struct node{
    int value;
    int place;
};
int sillysort(int m, int *seq){
    int cost=0;
    node nodes[1000],temp[1000];
    //nodes={(value=数列の値,place=ソート後の数列における位置)}
    for(int i=0;i<m;i++){
        temp[i].value=seq[i];
        temp[i].place=i;
    }
    std::sort(temp,temp+m,[](const node& a,const node& b){return a.value<b.value;});
    for(int i=0;i<m;i++){
        nodes[i].value=seq[i];
        nodes[temp[i].place].place=i;
    }
    //s=数列の最小値
    int s=temp[0].value;

    for(int i=0;i<m;i++){
        int j=nodes[i].place;
        //i番目をまだ走査したことない、かつi番目がソート済みではないなら
        //iから始まる巡回置換に対してそのコストの最小値を求める
        if(j>=0 && j!=i){
            int n=1, amin=nodes[i].value, sum=nodes[i].value;
            while(j!=i){
                int next=nodes[j].place;
                if(nodes[j].value<amin){
                    amin=nodes[j].value;
                }
                sum+=nodes[j].value;
                n++;
                nodes[j].place=-1; //以後j番目はnodesの走査で無視する
                j=next;
            }
            //巡回置換(a_1,...,a_n)のコストの最小値は、
            //(1)a_minの場所に正しい数を置くことを繰り返す（交換回数n-1回）
            //(2)a_minとsを入れ替える→(1)と同じ操作をする→a_minとsを入れ替える
            cost+=std::min(
                sum+(n-2)*amin,     // = sum_{i|a_i!=a_min}(a_i)+(n-1)*a_min ... (1)
                sum+amin+(n+1)*s);  // = 2*(a_min+s)+(sum-a_min+s)+(n-2)*s   ... (2)
        }
    }
    return cost;
}
int main(){
    int n,w[1000];
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&w[i]);
    printf("%d\n",sillysort(n,w));
    return 0;
}


Measured memory_bytes: 2792
n = int(input())
import sys
sys.setrecursionlimit(10**8)
def D(now,pre,SUM):
    dist[now] = SUM
    for BC in G[now]:
        if BC[0] == pre:
            continue
        D(BC[0],now,SUM+BC[1])



G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append((b,c))
    G[b].append((a,c))
q,k = map(int,input().split())
# xから頂点kまでの最短経路を求めておいて、kからyまでの最短経路を求めておく
k -= 1
# ここで作っとく?
dist = [0] * n
D(k,-1,0)
for i in range(q):
    x,y = map(lambda m:int(m)-1, input().split())
    print(dist[x] + dist[y])


Measured memory_bytes: 132080
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        nomore = False
        for k in range(c+1):
            s = 500*i + 100*j + 50*k
            if s == x:
                ans += 1
            elif s > x:
                break
print(ans)


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define INT_MAX 2147483647
#define INT_MIN -2147483648

typedef long long ll;			//%ld.
typedef long long int lli;		//%lld.
typedef unsigned long long ull;	//%llu.
// int %d, double %lf ,float %f ,string %s.

void swap(int *x,int *y);
int max(int x,int y);
int min(int x,int y);
void sortSeq(int dt[],int l,int r);
void sortIns(int dt[],int l,int r);
void mergeSort(int dt[],int l,int r);
int binser(int nilai,int dt[],int l,int r);
int abs(int x);
double maxD(double x,double y);
double minD(double x,double y);

//main code
int hitung(int x){
	int m = 0;
	while(x>0){
		m+=(x%10);
		x/=10;
	}
	return m;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=9;i++){
		for(int j=i;j<=9;j++)
			if(i*j==n){
				printf("Yes\n");
				return 0;
			}
	}
	printf("No\n");
}

















///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double maxD(double x,double y){
	return x > y ? x : y;
}
double minD(double x,double y){
	return x < y ? x : y;
}
int abs(int x){
	if(x<0)	return -x;
	return x;
}
void merge(int arr[], int aLeft , int aRight , int bLeft , int bRight){ //merge
	int size = bRight - aLeft + 1;
	int temp[size];                
	int tIndex = 0;
	int aIndex = aLeft;
	int bIndex = bLeft;
	while( (aIndex <= aRight)&&(bIndex <= bRight))
	{
		if(arr[aIndex]<=arr[bIndex])
		{
			temp[tIndex] = arr[aIndex];
			aIndex = aIndex +1;
		}
		else
		{
			temp[tIndex] = arr[bIndex];
			bIndex = bIndex + 1;
		}
		tIndex = tIndex + 1;
	}
	while(aIndex <= aRight)
	{
		temp[tIndex] = arr[aIndex];
		aIndex = aIndex + 1;
		tIndex = tIndex + 1;
	}
	while(bIndex <= bRight)
	{
		temp[tIndex] = arr[bIndex];
		bIndex = bIndex + 1;
		tIndex = tIndex + 1;
	}
	for(int i = 0 ; i<= size-1 ; i++)
	{
		arr[aLeft + i] = temp[i];
	}
}

void swap(int *a,int *b){ //swap
	int temp = *a;
	*a = *b;
	*b = temp;
}
int max(int a,int b){ //maksimum
	return a>b ? a : b;
}
int min(int a,int b){ //minimum
	return a<b ? a : b;
}
void sortSeq(int arr[],int l,int r){ //sequencial sort
	for(int i=l;i<=r-1;i++)
		for(int j=i+1;j<=r;j++)
			if(arr[j]<arr[i])
				swap(&arr[i],&arr[j]);
}
void sortIns(int h[],int l,int r){ //insertion sort
	for(int i=l;i<=r;i++){
		int pos=i;
		while((pos>1)&&(h[pos]<h[pos-1])){
			swap(&h[pos],&h[pos-1]);
			pos=pos-1;
		}
	}
}
void mergeSort(int arr[],int left,int right){ //merge sort
	if( left == right )
		return; 
	else{
		int mid = (left+right)/2;    	 
		mergeSort(arr,left,mid);	
		mergeSort(arr,mid+1,right);
		merge(arr,left,mid,mid+1,right); 
	}
}
int binser(int x,int dt[],int kiri,int kanan){ //tidak ada = -1
	int hasil = -1;
	while((kiri<=kanan)&&(hasil==0)){
		int tengah=(kiri+kanan)/2;
		if(x<dt[tengah])
			kanan=tengah-1;
		else if(x>dt[tengah])
			kiri=tengah+1;
		else
			hasil=tengah;
	}
	return hasil;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    mint& operator*=(const mint a) {
    	(x *= a.x) %= MOD;
    	return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(void){
    ll N; cin >> N;
    VL x(N); REP(i,N) cin >> x[i];
    VL S(N-1,0); S[0] = x[0]; REP(i,N-2) S[i+1] = S[i] + x[i+1];

    vector<mint> kai(N); kai[0] = 1; REP(i,N-1) kai[i+1] = kai[i]*(ll)(i+1);
    vector<mint> f(N-2), Sf(N-2);
    REP(i,N-2) f[i] = kai[N-1] / (i+1) / (i+2);
    Sf[0] = f[0]; REP(i,N-3) Sf[i+1] = Sf[i] + f[i+1];

    mint ans = 0;
    REP(i,N-2) ans += f[i] * (S[N-2] - S[i]);
    REP(i,N-2) ans -= Sf[N-3-i] * x[i];
    REP(i,N-1) ans += kai[N-1] * (x[N-1]-x[i]) / (N-1-i);
    cout << ans.x << endl;
    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

ll N, M;
vector<ll> A, sum;

ll counting(int x){
  ll cnt = 0;
  REP(i, N){
    int ok = -1, ng = N;
    while(abs(ok-ng) > 1){
      int mid = (ok+ng) / 2;
      if(A[i]+A[mid] >= x){
        ok = mid;
      }
      else{
        ng = mid;
      }
    }
    cnt += ok+1;
  }
  return cnt;
}

ll cal_sum(int x){
  ll res = 0, cnt = 0;
  REP(i, N){
    int ok = -1, ng = N;
    while(abs(ok-ng) > 1){
      int mid = (ok+ng) / 2;
      if(A[i] + A[mid] >= x){
        ok = mid;
      }
      else{
        ng = mid;
      }
    }
    if(ok >= 0){
      res += sum[ok+1] + A[i]*(ok+1);
      cnt += ok+1;
    }
  }
  // cout << "x:" << x << " res:" << res << " cnt:" << cnt << " x:" << x << endl;
  res -= (cnt - M) * x;
  return res;
}
int main(){
  cin >> N >> M;
  A.resize(N), sum.resize(N+1, 0);
  REP(i, N){
    cin >> A[i];
  }
  sort(A.rbegin(), A.rend());
  REP(i, N){
    sum[i+1] = sum[i] + A[i];
  }
  int ok = 0, ng = 2e5+1;
  while(abs(ok-ng) > 1){
    int mid = (ok+ng) / 2;
    if(counting(mid) >= M){
      ok = mid;
    }
    else{
      ng = mid;
    }
  }
  cout << cal_sum(ok) << endl;
  return 0;
}


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

vector<vector<char>> a(100,vector<char>(100));
int dp[100][100];
int fnc(int x, int y) {
  if(x==0&&y==0) {
    if(a[0][0]=='#') return 1;
    return 0;
  }
  int xx=300, yy=300;
  if(x>0) xx=dp[x-1][y];
  if(y>0) yy=dp[x][y-1];
  if(a[x][y]=='#') {
    if(x>0&&a[x-1][y]=='.') xx++;
    if(y>0&&a[x][y-1]=='.') yy++;
  }
  return min(xx,yy);
  }

int main() {
  int h, w;
  cin >> h >> w;
  rep(i,h) {
    rep(j,w) {
      cin >> a[i][j];
      dp[i][j]=fnc(i,j);
    }
  }
  
  cout << dp[h-1][w-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;




}

Measured memory_bytes: 256
import itertools

N,a,b,c = map(int,input().split())
L = list(int(input()) for i in range(N))

products = itertools.product(list(range(4)), repeat=N)

ans = float("inf")

for prod in products :
    A = []
    B = []
    C = []
    
    for i in range(len(prod)) :
        if prod[i] == 1 :
            A.append(L[i])
        elif prod[i] == 2 :
            B.append(L[i])
        elif prod[i] == 3 :
            C.append(L[i])
    if len(A) * len(B) * len(C) == 0 :
        continue
    
    cost = 0
    
    for li in [A,B,C] :
        cost += (len(li)-1)*10
    cost += abs(a-sum(A)) + abs(b-sum(B)) + abs(c-sum(C))
    ans = min(ans,cost)
print(ans)

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
    if(A+B < C+D){
      cout << "Right" << endl;
    }
  else if(A+B == C+D){
    cout << "Balanced" << endl;
  }
  else if(A+B > C+D){
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int A[5], k;
    for (int i = 0; i < 5; ++i) cin >> A[i];
    cin >> k;

    bool res = true;
    for (int i = 4; 0 < i; --i) {
        for (int j = i - 1; 0 <= j; --j) {
            if (k < (A[i] - A[j])) {
                res = false;
                break;
            }
        }
    }

    cout << (res ? "Yay!" : ":(") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  for(int i=0;i<100;i++){
    if(c-b>0)c=c-b;
    else {
      cout<<"Yes"<<endl;
      break;
    }
    if(a-d>0)a=a-d;
    else{
      cout<<"No"<<endl;
      break;
    }
  }

}
  

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int x=0;x<=18;x++)
	{
	
		if(s[x]==',')
		
		cout<<" ";
		
		else
		cout<<s[x];
		
}
		
		
		
	
	
	
	
	
	
	
	
	
	
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll A, B, X;
  cin >> A >> B >> X;

  if((X >= A) && (X <= A + B))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  int i,j,N,M,in,kind=0;
  cin>>N>>M;
  int K,A[M+1]={0};
 
  for(i=0;i<N;i++){
  	cin>>K;
  	for(j=1;j<K+1;j++){
  		cin>>in;
  		A[in]++;
  	}
  }
  for(i=1;i<M+1;i++){
  	if(A[i] == N) kind++;
  }
  cout<<kind<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		double T=sc.nextDouble(),A=sc.nextInt(),temp=60001;
		int ans = 0;
		for(int i=1; i<=N;i++) {
			double h = A-(T-(0.006*sc.nextDouble()));
			if(Math.abs(h) < Math.abs(temp)) {
				temp = Math.abs(h);
				ans = i;
			}
		}
		System.out.println(ans);
	}
}


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

void fnInput(int64_t& rnNum)
{
  cin >> rnNum;
}

int fnDigitsCheck(int64_t nDivisor)
{
  int nDigitCnt = 0;
  while (nDivisor)
  {
    nDigitCnt++;
    nDivisor /= 10;
  }

  return nDigitCnt;
}

int fnMultiplCheck(int64_t nNum)
{
  int nMinDigit = fnDigitsCheck(nNum);

  for (int64_t n = 2; n * n <= nNum; n++)          // int型 n だとうまく行かない
  {                                                // nNum の平方根を超えない整数～nNum
    if (nNum % n != 0)  continue;                  // を左記の検査を行うと TLE となる
    int64_t nOtr = nNum / n;
    nMinDigit = min(nMinDigit, fnDigitsCheck(nOtr));
  }
  return nMinDigit;
}

int main()
{
  int64_t nNum;
  
  fnInput(nNum);
  cout << fnMultiplCheck(nNum) << endl;

  return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
    s,p=input().split()
    l+=[[i+1,s,int(p)]]
l.sort(key=lambda x:x[2],reverse=True)
l.sort(key=lambda x:x[1])
for i in range(n):
    print(l[i][0])

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

int main(){

  long long int N;
  cin >> N;
  string ans;

  while(N>0){
    N--;
    ans += 'a' + N % 26;  
    N /= 26;
  }
  
  reverse((ans).begin(), (ans).end());
  cout << ans << "\n";
  return 0;
}//main 


Measured memory_bytes: 3600
import numpy
N = map(int, input().split())
A_list = list(map(int, input().split()))
set = numpy.abs(numpy.array(A_list))
A_abs_min = min(set)
A_abs_sum = sum(set)
n = sum(x<0 for x in A_list)%2  # 真偽値リストを作って True の数を合計する方法
if n == 1:
    ans = A_abs_sum-2*A_abs_min
else:
    ans =  A_abs_sum
print(ans)

Measured memory_bytes: 23344
def p_b():
    n = int(input())
    sp = []
    for i in range(n):
        tmp = input().split()
        sp.append((tmp[0], int(tmp[1]), i + 1))
    sp.sort(key=lambda x: x[1], reverse=True)
    sp.sort(key=lambda x: x[0])
    print(*[x[2] for x in sp])
    
p_b()

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


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

// #define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int n,s;
int main(){
	cin>>n>>s;
	s--;
	vector<pair<pll,int> > v(n);
	rep(i,n){
		cin>>v[i].F.F>>v[i].F.S;
		v[i].S=i;
		swap(v[i].F.F,v[i].F.S);
	}
	sort(ALL(v));
	rep(i,n){
		swap(v[i].F.F,v[i].F.S);
	}
	vvll vv;
	initvv(vv,n,n);
	rep(i,n){
		rep(j,n){
			cin>>vv[i][j];
		}
	}
	rep(k,n){
		rep(i,n){
			rep(j,n){
				vv[i][j]=min(vv[i][j],vv[i][k]+vv[k][j]);
			}
		}
	}
	vll dp(n,LLONG_MIN/2);
	rep(i,n){
		if(vv[s][v[i].S]>v[i].F.S) continue;
		dp[v[i].S]=v[i].F.S-max(v[i].F.F,vv[s][v[i].S]);
	}
	rep(i,n){
		rep(j,n){
			if(v[i].F.S+vv[v[i].S][v[j].S]>v[j].F.S) continue;
			ll t=v[j].F.S-max(v[j].F.F,vv[v[i].S][v[j].S]+v[i].F.S);
			dp[v[j].S]=max(dp[v[j].S],dp[v[i].S]+t);
		}
	}
	ll ans=0;
	rep(i,n){
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3120
w, h, n = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
xy = []
a = []
for i in range(n):
    xy.append([li[i][0], li[i][1]])
    a.append(li[i][2])

left, right = [0, 0], [w, h]

for i in range(n):
    if a[i] == 1:
        if left[0] < xy[i][0]:
            left[0] = xy[i][0]
    elif a[i] == 2:
        if right[0] > xy[i][0]:
            right[0] = xy[i][0]
    elif a[i] == 3:
        if left[1] < xy[i][1]:
            left[1] = xy[i][1]
    else:
        if right[1] > xy[i][1]:
            right[1] = xy[i][1]

if left[0] >= right[0] or left[1] >= right[1]:
    ans = 0
else:
    ans = (right[0]-left[0]) * (right[1]-left[1])
print(str(ans))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <complex>
#include <regex>
#include <random>
using namespace std;

#define rep(i,n)	for(lint i = 0; i < n; i++)
#define repr(i,n)	for(lint i = n - 1; i >= 0; i--)
#define repi(i,ini,n)	for(lint i = ini; i < n; i++)
#define repir(i,ini,n)	for(lint i = n-1; i >= ini; i--)
#define repb(i,start,end)	for(lint i = start; i <= end; i++)
#define repbr(i,start,end)	for(lint i = end; i >= start; i--)

#define bit(n)				(1LL << (n))

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rg(v, ini, end) v.begin() + ini, v.begin()+end

#define ret return 0;
#define chmax(a, b) a=mmax(a,b)
#define chmin(a, b) a=mmin(a,b)

using lint = long long;
using ulint = unsigned long long;
using ld = long double;
struct xy
{
	lint x, y;
	xy() :x(0), y(0) {}
	xy(lint _x, lint _y) : x(_x), y(_y) {}
	xy operator+(const xy& p) const
	{
		return xy(x + p.x, y + p.y);
	}
	bool operator<(xy p) const
	{
		if (y == p.y)
			return x < p.x;
		return y < p.y;
	}
};
struct xyd
{
	ld x, y;
	xyd() :x(0), y(0) {}
	xyd(long double _x, long double _y) : x(_x), y(_y) {}
};
using vec = vector<lint>;
using vecd = vector<ld>;
using vecs = vector<string>;
using vecp = vector<xy>;
template<class T> using vect = vector<T>;
class vec2 : public vector<vector<lint>>
{
public:
	vec2() {}
	vec2(lint n) : vector(n) {}
	vec2(lint h, lint w) : vector(h, vector<lint>(w)) {}
	vec2(lint h, lint w, lint v) : vector(h, vector<lint>(w, v)) {}
};

template<class T> using priq = priority_queue<T>;
template<class T> using rpriq = priority_queue<T, vector<T>, greater<T>>;
template<class Key, class Val> using hashmap = unordered_map<Key, Val>;
template<class Key> using hashset = unordered_set<Key>;

mt19937 mtrand((random_device())());

const double pi = 3.141592653589793238462;
const lint intmax = 9223372036854775807;
const lint inf = 1100100100100100100LL;

constexpr lint div2(lint p, lint q)
{
	return (p + q - 1) / q;
}

#if(__cplusplus < 201703L)

	lint gcd(lint a, lint b) {
		while (1) {
			if (a < b) swap(a, b);
			if (!b) break;
			a %= b;
		}
		return a;
	}

	lint lcm(lint a, lint b)
	{
		return a / gcd(a, b) * b;
	}

#endif

template<class T>
struct nval {
	lint n;		// counts
	T val;
	nval() : n(0) {};
	nval(lint _n, T _val) : n(_n), val(_val) {};
};

template<class It, class It2>
auto spacel(It i, It2 end)
{
	if (i + 1 == end)
	{
		return '\n';
	}
	else
	{
		return ' ';
	}
}

ostream& setp(ostream& ost)
{
	cout << setprecision(60) << fixed;
	return ost;
}

const ulint mod = 1000000007;
//const ulint mod = 998244353;
const ld eps = 0.0000001;

int main()
{
	while (1)
	{
		lint h, w;
		cin >> h >> w;
		if (h == 0 && w == 0)
			break;

		rep(i, h)
			cout << string(w, '#') << endl;
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String N = scan.next();
    int K = scan.nextInt();
    scan.close();

    int[][] dp0 = new int[N.length()][4];
    int[][] dp1 = new int[N.length()][4];
    dp0[0][3] = 0;
    dp0[0][2] = 0;
    dp0[0][1] = N.charAt(0) - '0' - 1;
    dp0[0][0] = 1;
    dp1[0][3] = 0;
    dp1[0][2] = 0;
    dp1[0][1] = 1;
    dp1[0][0] = 0;

    for(int i=0; i<N.length()-1; i++) {
      if(N.charAt(i+1) - '0' == 0) {
        dp0[i+1][3] = dp0[i][2] * 9 + dp0[i][3];
        dp0[i+1][2] = dp0[i][1] * 9 + dp0[i][2];
        dp0[i+1][1] = dp0[i][0] * 9 + dp0[i][1];
        dp0[i+1][0] = dp0[i][0];
        dp1[i+1][3] = dp1[i][3];
        dp1[i+1][2] = dp1[i][2];
        dp1[i+1][1] = dp1[i][1];
        dp1[i+1][0] = dp1[i][0];
      }
      else {
        dp0[i+1][3] = dp0[i][2] * 9 + dp0[i][3] + dp1[i][2] * (N.charAt(i+1)-'0'-1) + dp1[i][3];
        dp0[i+1][2] = dp0[i][1] * 9 + dp0[i][2] + dp1[i][1] * (N.charAt(i+1)-'0'-1) + dp1[i][2];
        dp0[i+1][1] = dp0[i][0] * 9 + dp0[i][1] + dp1[i][0] * (N.charAt(i+1)-'0'-1) + dp1[i][1];
        dp0[i+1][0] = dp0[i][0] + dp1[i][0];
        dp1[i+1][3] = dp1[i][2];
        dp1[i+1][2] = dp1[i][1];
        dp1[i+1][1] = dp1[i][0];
        dp1[i+1][0] = dp1[i][0];
      }
    }

    System.out.println(dp0[N.length()-1][K] + dp1[N.length()-1][K]);
  }
}

Measured memory_bytes: 21844
N,K=map(int, input().split())
R,S,P=map(int, input().split())
T=list(input())
D={"r":P, "s":R, "p":S}
result=["none"]*N
ans=0
for i in range(N):
    if i<K:
        ans+=D[T[i]]
        result[i]=T[i]
    else:
        if T[i]!=result[i-K]:
            ans+=D[T[i]]
            result[i]=T[i]
print(ans)

Measured memory_bytes: 4788
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int p[] = new int[N];
        for(int i=0;i<N;i++){
            p[i] = sc.nextInt();
        }
        Arrays.sort(p);
        for(int l=0;l<K;l++ ){
            sum += p[l];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 39024
import java.util.Scanner;

public class Main{
	Main(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int[] ts = new int[n+1];
			int[] te = new int[n+1];
			int[] a = new int[2*n+1];
			int q = 0, u, v;
			for(int i = 0; i < n; i++){
				ts[i] = Integer.parseInt((sc.next()).replaceAll(":", ""));
				te[i] = Integer.parseInt((sc.next()).replaceAll(":", ""));
				
				boolean af, bf;
				af = bf = true;
				for(int j = 0; j < q; j++){
					if(a[j] == ts[i]){
						af = false;
						if(!bf){
							break;
						}
					}
					if(a[j] == te[i]){
						bf = false;
						if(!af){
							break;
						}
					}
				}
				if(af){
					a[q++] = ts[i];
				}
				if(bf){
					a[q++] = te[i];
				}
			}
			
			for(int i = q-1; i >= 0; i--){
				for(int j = 1; j <= i; j++){
					if(a[j] < a[j-1]){
						u = a[j];
						a[j] = a[j-1];
						a[j-1] = u;
					}
				}
			}
			v = u = 0;
			boolean f = true;
			for(int i = 0; i < q; i++){
				for(int j = 0; j < n; j++){
					if(a[i] == te[j]){
						u--;
					}

					if(a[i] == ts[j]){
						u++;
					}
				}
			        if(u > v){
					v = u;
				}
			}
			
			System.out.println(Integer.toString(v));
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 13000