akhauriyash/Code-Regression huggingface dataset:
from fractions import Fraction

a, b = input().split()
a = int(a)
num = 0
frac = 0
for i in range(len(b)):
    if b[i] == '.':
        num = b[:i]
        j = i + 1
        frac = b[j:]
num = int(num)
num *= 100
frac = int(frac)
val = num + frac
c = a * val
c = c // 100
d = c
d = int(d)
print(d)

Measured memory_bytes: 10408
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<vector<int>> s(100030);
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		s[x].push_back(y);
		s[y].push_back(x);
	}
	int seen[100050] = {};
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (seen[i] == 0) {
			ans++;
			queue<int> q;
			q.push(i);
			seen[i] = 1;
			while (q.size()) {
				int a = q.front();
				q.pop();
				for (auto j : s[a]) {
					if (seen[j] == 0) {
						q.push(j);
						seen[j] = 1;
					}
				}
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 6904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String n = sc.next();
    int d = 0;
    for (int i = 0; i < n.length(); i++) {
      d += Integer.parseInt(String.valueOf(n.charAt(i)));
      d %= 9;
    }
    if (d == 0) System.out.println("Yes");
    else System.out.println("No");
  }
}

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

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll 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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > miti(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        miti[a].emplace_back(b);
        miti[b].emplace_back(a);
    }

    for (int i : miti[0]) {
        rep(j, miti[i].size()) {
            if (miti[i][j] == n - 1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 15100
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int n, m; cin >> n >> m;
	int ans(0);
	int p(0);
	vector<pair<int, int>>card;
	rep(i, 0, m) {
		int a, b; cin >> a >> b;
		card.push_back(make_pair(a, b));
	}
	sort(all(card));
	rep(i, 1, m) {
		ans += max(0, n - card[i].first);
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long

ll n;
ll a[200005];
ll l=0, l2=0;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] >= l && a[i] > l2) {
      l2 = l;
      l = a[i];
    } else if (a[i] > l2 && a[i] < l) {
      l2 = a[i];
    }
  }
  
  for (int i = 0; i < n; i++) {
    if (a[i] == l) cout << l2 << endl;
    else cout << l << endl;
  }
}


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

int main(){
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if(x == 1) ans += 300000;
  else if(x == 2) ans += 200000;
  else if(x == 3) ans += 100000;
  if(y == 1) ans += 300000;
  else if(y == 2) ans += 200000;
  else if(y == 3) ans += 100000;
  if(x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(void) {
  int n; cin >> n;
  vector<char> c(n);

  ll r=0;

  rep(i,n){
    cin >> c.at(i);
    if(c.at(i)=='R') r++;
  }

  ll w = 0;

  rep(i,r){
    if(c.at(i)=='W') w++;
  }

  cout << w << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j;
pair <int, int> p[100009];
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(i=1; i<=a; i++){
        cin>>p[i].first;
        p[i].second=i;
    }
    sort(p+1,p+a+1);
    for(i=1; i<=a; i++) cout<<p[i].second<<" ";
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
 
int main()
{
	ios_base::sync_with_stdio(false);
	ll n,m,k,i,maxrow=0,maxcol=0;
	cin>>n>>m>>k;
	vector <pll> v;
	ll row[n+2]={0}, col[m+2]={0};
	for(i=0;i<k;i++)
	{
		ll x,y;
		cin>>x>>y;
		row[--x]++;
		col[--y]++;
		v.pb({x,y});
	} 
	set <ll> idrow, idcol;
	for(i=0;i<n;i++)
	{
		maxrow = max(maxrow, row[i]);
	}
	for(i=0;i<m;i++)
	{
		maxcol = max(maxcol, col[i]);
	}
	for(i=0;i<n;i++)
	{
		if(row[i]==maxrow)
			idrow.insert(i);
	}
	for(i=0;i<m;i++)
	{
		if(col[i]==maxcol)
			idcol.insert(i);
	}
	ll count = 0;
	for(i=0;i<k;i++)
	{
		if(idrow.find(v[i].ff)!=idrow.end() && idcol.find(v[i].ss)!=idcol.end())
		{
			count++;
		}
	}
	if(count == (idrow.size() * idcol.size()))
		cout<<maxrow+maxcol-1<<nl;
	else
		cout<<maxrow+maxcol<<nl;
	return 0;
}

Measured memory_bytes: 40832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,q;
  cin >>  n >> q;
  vec a(n),sum(n+1),sum2(n+1);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    sum[i+1]=sum[i]+a[i];
    sum2[i+1]=(i?sum2[i-1]:0)+a[i];
  }
  vec x(q);
  for(ll i=0;i<q;i++) cin >> x[i];
  for(ll i=0;i<q;i++) {
    ll lb=0,ub=n+1;
    while(ub-lb>1) {
      ll t=(lb+ub)>>1;
      if(abs(a[n-(t+1)/2]-x[i])>=abs(a[n-t]-x[i])) {
        lb=t;
      }
      else {
        ub=t;
      }
    }
    cout << sum2[max(n-lb-(lb&1),0LL)]+(sum[n]-sum[n-(lb+1)/2]) << endl;
  }
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

int merge(vector<int> &A, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	vector<int> L(n1 + 1), R(n2 + 1);
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = 1000000001;
	int i = 0, j = 0, cnt = 0;
	for (int k = left; k < right; k++){
		cnt++;
		if (L[i] <= R[j]) A[k] = L[i++];
		else A[k] = R[j++];
	}
	return cnt;
}

int merge_sort(vector<int> &A, int left, int right){
	int sum = 0;
	if (left + 1 < right){
		int mid = (left + right) / 2;
		sum = merge_sort(A, left, mid) + merge_sort(A, mid, right);
		sum += merge(A, left, mid, right);
	}
	return sum;
}

void solve(){
	int n, sum;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) cin >> A[i];
	sum = merge_sort(A, 0, n);
	for (int i = 0; i < n; i++){
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl << sum << endl;
}

signed main(){
	solve();
}

Measured memory_bytes: 6736
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,val[N];
bool judge(){
    if(n==1) return val[1]!=1;
    int num[2]={0,0};
    for(int i=1;i<=n;i++) num[val[i]%2]++;
    if(num[0]%2==1) return true;
    if(num[1]>1) return false;
    for(int i=1;i<=n;i++)
        if(val[i]%2==1&&val[i]!=1) val[i]--;
        else if(val[i]==1) return false;
    int gcd=val[1];
    for(int i=1;i<=n;i++) gcd=__gcd(gcd,val[i]);
    for(int i=1;i<=n;i++) val[i]/=gcd;
    return !judge();
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&val[i]);
    if(judge()) puts("First");
    else puts("Second");
    return 0;
}

Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans,res=0,0
if A[0]<=B[0]:
  ans+=A[0]
  res=B[0]-A[0]
else:
  ans+=B[0]
for i in range(1,N):
  if res>=A[i]:
    res=B[i]
    ans+=A[i]
  else:
    ans+=res
    A[i]-=res
    if A[i]<=B[i]:
      ans+=A[i]
      res=B[i]-A[i]
    else:
      ans+=B[i]
      res=0
if res>=A[N]:
  ans+=A[N]
else:
  ans+=res
print(ans)


Measured memory_bytes: 24060
from collections import Counter
mod = 10**9+7
s = input()
k = 1
a = 0
ab = 0
abc = 0
for c in s:
    if c == "A":
        a += k
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = 3*abc + ab
        ab = 3*ab + a
        a = 3*a + k
        k *= 3
    a %= mod
    ab %= mod
    abc %= mod
    k %= mod
print(abc%mod)



Measured memory_bytes: 3444
n, k = map(int, input().split())
v = [int(i) for i in input().split()]
res = []
for l in range(min(k+1, n+1)):
    tmp1 = v[:l]
    res.append(sum(tmp1))
    for r in range(min(k, n) - l):
        if r == 0:
            tmp2 = tmp1
        else:
            tmp2 = tmp1 + v[-r:]
        res.append(sum(tmp2))
        for a in range(min(len(tmp2), k-l-r)):
            tmp2.sort()
            tmp3 = tmp2[a+1:]
            res.append(sum(tmp3))
print(max(res))


Measured memory_bytes: 4760
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const N = nextInt()
    let arr = []
    while(hasNext()){
        arr.push(nextIntArray())
    }
    arr.sort((a,b) => a[1]-b[1])
    let time = 0
    let res = "Yes"
    for(let i = 0; i<arr.length; i++){
        if(time > arr[i][1]-arr[i][0]){
            res = "No"
            break
        }
        time += arr[i][0]
    }

    console.log(res)
}
Main()

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

const int maxn = 22;

long long d, det[maxn], ten[maxn];
int len, mid;
long long ans, temp;

void dfs(long long now, int depth, long long cnt, int flag)
{
    if (d == now && depth > mid) {
        temp += cnt;
        return;
    }
    if (depth > mid) {return;}
    long long rua = ten[depth] - ten[len + 1 - depth];
    for (int i = -9; i <= 9; i++)
    {
        if (llabs(now + rua * i - d) >= ten[len + 1 - depth]) continue;
        dfs(now + rua * i, depth + 1, cnt * (10 - flag - abs(i)), 0);
    }
}

void init ()
{
    ten[1] = 1;
    for (int i = 2; i <= 19; i++) ten[i] = ten[i - 1] * 10;
}

int main()
{
    //freopen("C:/Users/MACHENIKE/Desktop/data.in","r",stdin);
    scanf("%lld", &d);
    init();
    for (len = 1; len <= 19; len++)
    {
        temp = 0;
        mid = len / 2;
        dfs(0, 1, 1, 1);
        if (len & 1) temp *= 10;
        ans += temp;
    }
    printf("%lld", ans);
    return 0;
}


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

int main () {
  int n;
  string s;
  cin >> n >> s;
  if(n % 2 != 0) {
      cout << "No";
      return 0;
  }
  for(int i = 0;i < n/2; i++){
    if(s[i] != s[i+n/2]){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

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

using namespace std;

long double v[1000];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	long double ans = 0, val;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	sort(v, v + n);
	val = v[0];
	for (int i = 1; i < n; ++i) {
		val = (val + v[i]) / 2;
	}
	ans = max(ans, val);
	cout << ans << '\n';
	return 0;
}

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

int main() {
  int n;cin>>n;
  ll ans=0;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin>>a[i];
  // 数列aを降順にソート
  sort(a.rbegin(), a.rend());
  for(int i=1; i<=n-1; i++) {
    ans+=a[i/2];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
int a,b,c,k;
int main(){
	cin>>a>>b>>c>>k;
	while(k!=0){
		if(a<b && b<c){
			cout<<"Yes";
			return 0;
	}
		if(a>=b){
			k--;b*=2;
		}
		else if(b>=c){
			k--;c*=2;
		}
		
	}
	if(a<b && b<c){
			cout<<"Yes";
			return 0;
	}
	cout<<"No";
	return 0;
} 

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

using namespace std;

struct Node { 
	int x, y;
}S[90001];
int sum[90001];
int res;
int n;
int m;
int d;

int main() {
	scanf("%d%d%d", &n, &m, &d);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			int k;
			scanf("%d", &k);
			S[k].x = i;
			S[k].y = j;
		}
	for(int i = d + 1; i <= n * m; i++)
		sum[i] = sum[i - d] + abs(S[i].x - S[i - d].x) + abs(S[i].y - S[i - d].y);
	int Q;
	scanf("%d", &Q);
	while(Q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", sum[r] - sum[l]);
		res = 0;
	}
	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>

void swap(int *a, int *b){
  *a ^= *b;
  *b ^= *a;
  *a ^= *b;
}

typedef struct{
  int value;
  int height;
}DATA;
void DATAinit(DATA *d){
  d->value=0;
  d->height=0;

}

// サイコロの構造体
enum Direction{TOP,WEST,SOUTH,EAST,NORTH,BOTTOM,CLOCKWISE,COUNTER};

typedef struct{
  int top,south,east,north,west,bottom;
}DICE;
void DICEinit(DICE *d){
  d->top = 1;
  d->west = 2;
  d->south = 3;
  d->east = 5;
  d->north = 4;
  d->bottom = 6;
}
void DICErotate(DICE *d, int dir){
  if(dir==SOUTH){
    swap(&d->top,&d->north);
    swap(&d->north,&d->bottom);
    swap(&d->bottom,&d->south);
  }
  if(dir==EAST){
    swap(&d->top,&d->west);
    swap(&d->west,&d->bottom);
    swap(&d->bottom,&d->east);
  }
  if(dir==WEST){
    swap(&d->top,&d->east);
    swap(&d->east,&d->bottom);
    swap(&d->bottom,&d->west);
  }
  if(dir==NORTH){
    swap(&d->top,&d->south);
    swap(&d->south,&d->bottom);
    swap(&d->bottom,&d->north);
  }
  if(dir==CLOCKWISE){
    swap(&d->west,&d->north);
    swap(&d->west,&d->east);
    swap(&d->west,&d->south);
  }
  if(dir==COUNTER){
    swap(&d->west,&d->south);
    swap(&d->west,&d->east);
    swap(&d->west,&d->north);
  }
}
void DICEset(DICE *d, int top, int front){
  DICEinit(d);
  switch(top){
  case 1:
    break;
  case 2:
    DICErotate(d,EAST);
    break;
  case 3:
    DICErotate(d,NORTH);
    break;
  case 4:
    DICErotate(d,SOUTH);
    break;
  case 5:
    DICErotate(d,WEST);
    break;
  case 6:
    DICErotate(d,NORTH);
    DICErotate(d,NORTH);
    break;
  }
  while(d->south != front){
    DICErotate(d,CLOCKWISE);
  }
}
int DICEface(DICE *d, int dir){
  int n;
  switch(dir){
  case TOP:
    n=d->top;
    break;
  case WEST:
    n=d->west;
    break;
  case SOUTH:
    n=d->south;
    break;
  case EAST:
    n=d->east;
    break;
  case NORTH:
    n=d->north;
    break;
  case BOTTOM:
    n=d->bottom;
    break;
  }
  return n;
}

int main(void)
{
  int n, t, f;
  int ans[6];
  while( scanf("%d", &n), n ){
    DICE d;
    DATA field[100][100];
    int max, dir;
    int i, j;
    int x, y;
    int dx[5] = {0,-1,0,1,0};
    int dy[5] = {0,0,1,0,-1};
    int stop;
    for(i = 0; i < 100; i++){
      for(j = 0; j < 100; j++){
	DATAinit(&field[i][j]);
      }
    }
    for(i = 0; i < n; i++){
      scanf("%d %d", &t, &f);
      DICEset(&d, t, f);
      y = x = n/2+1;
      stop = 0;
      while(!stop){
	max = -1;
	j = 0;
	for(j = 1; j < 5; j++){
	  if(field[y][x].height <= field[y+dy[j]][x+dx[j]].height)continue;
	  if( DICEface(&d, j) < 4 )continue;
	  if( DICEface(&d, j) < max )continue;
	  max = DICEface(&d, j);
	  dir = j;
	}
	if(max == -1){
	  stop = 1;
	  field[y][x].height++;
	  field[y][x].value = d.top;
	}else{
	  DICErotate(&d, dir);
	  y += dy[dir];
	  x += dx[dir];
	}
      }
    }

    for(i = 0; i < 6; i++){
      ans[i] = 0;
    }
    for(i = 0; i < 100; i++){
      for(j = 0; j < 100; j++){
	if(field[i][j].value == 0)continue;
	ans[ field[i][j].value - 1 ]++;
      }
    }

    printf("%d", ans[0]);
    for(i = 1; i < 6; i++){
      printf(" %d", ans[i]);
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//conversion
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//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(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

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

#define PUTS(x) cout << (x) << endl;

int H,W;
char S[400][400] = {0};
int visited[400][400] = {0};
LL black = 0;
int white = 0;
int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};

void f(int i, int j, char pre){
    if(!(0<=i && i<H && 0<=j && j<W))return;
    if(visited[i][j])return;
    char now = S[i][j];
    if(now == pre)return;
    visited[i][j] = 1;
    if(now == '#')black++;
    if(now == '.')white++;
    f(i+1, j, now);
    f(i-1, j, now);
    f(i, j+1, now);
    f(i, j-1, now);
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>H>>W;
    REP(i,H)REP(j,W)cin>>S[i][j];
    LL ans = 0;
    REP(i,H)REP(j,W){
        black = 0;
        white = 0;
        f(i, j, 'X');
        ans += black * white;
    }
    PUTS(ans);
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll inf=1e15+7;
int main()
{
	    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (k >= x/d) {
        k -= x/d;
        x -= x/d * d;
        k = k%2;
    }
    cout << abs(x - d*k) << endl;
    return 0;
}
	


Measured memory_bytes: 3628
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]

c = Counter(S)

target = c.most_common()[0][1]

ans_list = []

for item in c.most_common():
    if target == item[1]:
        ans_list.append(item[0])
    else:
        break

ans_list.sort()

for s in ans_list:
    print(s)

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


int main() {
  int x;
  cin >> x;
  int A = x / 1000;
  int B = x / 100 % 10;
  int C = x / 10 % 10;
  int D = x % 10;
  if (A + B + C + D == 7) {
    cout << A << '+' << B << '+' << C << '+' << D << "=7" << endl;
  }
  else if (A + B + C - D == 7) {
    cout << A << '+' << B << '+' << C << '-' << D << "=7" << endl;
  }
  else if (A + B - C + D == 7) {
    cout << A << '+' << B << '-' << C << '+' << D << "=7" << endl;
  }
  else if (A + B - C - D == 7) {
    cout << A << '+' << B << '-' << C << '-' << D << "=7" << endl;
  }
  else if (A - B + C + D == 7) {
    cout << A << '-' << B << '+' << C << '+' << D << "=7" << endl;
  }
  else if (A - B + C - D == 7) {
    cout << A << '-' << B << '+' << C << '-' << D << "=7" << endl;
  }
  else if (A - B - C + D == 7) {
    cout << A << '-' << B << '-' << C << '+' << D << "=7" << endl;
  }
  else if (A - B - C - D == 7) {
    cout << A << '-' << B << '-' << C << '-' << D << "=7" << endl;
  }  
}

Measured memory_bytes: 256
s = input()
alphabet = list(chr(ord("a")+i)for i in range(26))
a = [0]*26

for i in s:
    for j in range(26):
        if i == alphabet[j]:
            a[j] = 1

b = []
for i in range(26):
    if a[i] == 0:
        b.append(alphabet[i])

if len(b) != 0:
    print(b[0])
else:
    print("None")


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

void swap(int array[],int lo,int hi){
  int temp=array[lo];
  array[lo]=array[hi];
  array[hi]=temp;
}

void shuffle(int array[],int size){
  for(int i=0;i<size;i++){
    int j=rand()%size;
    swap(array,i,j);
  }
}

int partition(int array[],int low,int hig){
  int i=low;
  int j=hig+1;
  while(1){
    while(array[++i]<array[low]){
      if(i == hig) break;}
    while(array[low]<array[--j]){
      if(j==low) break;}
    if(i>=j) break;
    swap(array,i,j);
  }
  swap(array,low,j);
  return j;
}

void sort(int array[],int lo,int hi){
  if(hi<=lo) return;
  int j=partition(array,lo,hi);
  sort(array,lo,j-1);
  sort(array,j+1,hi);
}

void quicksort(int array[],int size){
  shuffle(array,size);
  sort(array,0,size-1);
}

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

  quicksort(a,n);

  int f=0;
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      f=1;
      break;}}

  if(f==0) printf("YES\n");
  else printf("NO\n");

  return 0;
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    N %= 10;
    if(N == 3) {
        cout << "bon" << endl;
    } else if(N == 0 || N == 1 || N == 6 || N == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

int main(){
    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n*a, b) << endl;
    
    return 0;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
elif n == 2 and m == 2:
    print(0)
else:
    print((n-2) * (m-2))


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 50;
const int M = 20;
const int mod = 998244353;
int n,m;
int to[(N << 1) + 5],pre[(N << 1) + 5],first[N + 5];
inline void add(int u,int v)
{
    static int tot = 0;
    to[++tot] = v,pre[tot] = first[u],first[u] = tot;
}
int fa[N + 5],s[N + 5];
int q[N + 5],head,tail;
void bfs()
{
    q[++tail] = 1;
    for(register int p;head < tail;)
    {
        p = q[++head];
        for(register int i = first[p];i;i = pre[i])
            if(to[i] ^ fa[p])
                fa[to[i]] = p,q[++tail] = to[i];
    }
}
int full;
long long f[2][(1 << M) + 5];
int main()
{
    scanf("%d",&n);
    int u,v;
    for(register int i = 2;i <= n;++i)
        scanf("%d%d",&u,&v),add(u,v),add(v,u);
    bfs();
    scanf("%d",&m),full = (1 << m) - 1;
    for(register int i = 1;i <= m;++i)
        scanf("%d%d",&u,&v),s[v] ^= (1 << i - 1),s[u] ^= (1 << i - 1);
    for(register int i = n;i;--i)
        s[fa[q[i]]] ^= s[q[i]];
    f[0][0] = 1;
    for(register int i = 2,cur = 0;i <= n;++i,cur ^= 1)
    {
        memset(f[cur ^ 1],0,sizeof f[cur ^ 1]);
        for(register int j = 0;j <= full;++j)
            f[cur ^ 1][j] += f[cur][j],
            f[cur ^ 1][j | s[i]] += f[cur][j];
    }
    printf("%lld\n",f[(n & 1) ^ 1][full]);
}

Measured memory_bytes: 18116
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);
int get_digent(int);


int main(){
  often();
  int n,ans=0;
  cin >> n;
  vi a(n),b(n-1);
  rep(i,n-1) cin >> b[i];
  rep(i,n-2){
    ans += min(b[i],b[i+1]);
  }
  ans += b[0];
  ans += b[n-2];
  cout << ans << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int get_digent(int x){
  string s;
  s = to_string(x);
  int digent = s.size();
  return digent;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int x, a, b; cin >> x >> a >> b;
  if (b <= a) {
    cout << "delicious" << endl;
  } else if (b <= a+x) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl; 
  }
}

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

int main() {
	int card[4][14] = { 0 }, n, number, collerint;
	char coller, coller2[4] = { 'S','H','C','D' };

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> coller >> number;
		switch (coller) {
		case 'S':collerint = 0;
			break;
		case 'H':collerint = 1;
			break;
		case 'C':collerint = 2;
			break;
		case 'D':collerint = 3;
			break;
		}
		card[collerint][number] = true;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= 13; j++) {
			if (card[i][j] == 0)
				cout << coller2[i] << ' ' << j << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, h;
    cin >> n >> h;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    int mxa = a[0];
    int nh = 0, cnt = 0;
    for(int i = 0; i < n; i++) {
        if(mxa > b[i]) break;
        nh += b[i];
        cnt++;
        if(nh >= h) {
            cout << cnt << endl;
            return 0;
        }
    }
    cnt += (h-nh+mxa-1)/mxa;
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ll n,a[100005],b[100005];

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
ll two=0,one=0;

rep(i,0,n-1)cin>>a[i];
rep(i,0,n-1)cin>>b[i];
rep(i,0,n-1)a[i]-=b[i];

rep(i,0,n-1)
{
	if(a[i]<0)
	{
		two+=(abs(a[i]-1)/2);
		one+=(abs(a[i])%2);
	}
	else
	{
		one+=abs(a[i]);
	}
}

if(one<=two)
{
	ol("Yes");
}
else
{
	ol("No");
}

return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string a;
    int b;
    while(1){
        cin>>a;
        if(a=="0") break;
        for(int i=0;i<a.size();i++){
          b+=a[i]-'0';  
        }
        cout<<b<<endl;
        b=0;
    }
}



Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf = 1e+9;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    int N, M; cin >> N >> M;
    int d[120][120];
    rep(i, N) {
        rep(j, N) {
            d[i][j] = inf;
        }
    }
    rep(i, N) d[i][i] = 0;
    int a[1200], b[1200], c[1200];
    rep(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        a[i] --; b[i] --;
        d[a[i]][b[i]] = c[i]; d[b[i]][a[i]] = c[i];
    }
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    bool used[1200];
    rep(i, M) used[i] = false;
    rep(i, N) {
        rep(j, N) {
            rep(k, M) {
                if(d[i][j] == d[i][a[k]] + c[k] + d[b[k]][j]) {
                    used[k] = true;
                }
                if(d[i][j] == d[i][b[k]] + c[k] + d[a[k]][j]) {
                    used[k] = true;
                }
            }
        }
    }
    int ans = 0;
    rep(i, M) {
        if(!used[i]) ans ++;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N,vector<int>(D,0));
  for (int i=0;i<N;i++){
    for (int j=0;j<D;j++){
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i=0;i<N-1;i++){
    for (int j=i+1;j<N;j++){
      double dist = 0;
      for (int k=0;k<D;k++){
        dist += (double)((X[i][k] - X[j][k])*(X[i][k] - X[j][k]));
      }
      dist = sqrt(dist);
      if (round(dist) == dist) {
        ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int) x.size())
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    int d, t, s;
    cin >> d >> t >> s;

    if ( t * s < d ) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int mod = 1e9+7;
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

string s, t;

int main() {
    cin >> s >> t;
    ll cnt = 0;
    rep(i, s.length()) {
        if(s[i] == t[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    c=[-1]*n
    flg=0
    A=0
    for i in range(m):
        a,b=map(int,input().split())
        if c[a-1]==-1:
            c[a-1]=b
        elif c[a-1]!=b:
            flg=1
    if flg==1:
        print(-1)
    else:    
        if n==1:
            if c[0]==-1 or c[0]==0:
                print(0)
            else:
                print(c[0])
        else:
            if c[0]==0:
                print(-1)
            else:
                for i in range(n):
                    if c[i]==-1:
                        if i==0:
                            c[i]=1
                        else:
                            c[i]=0
                    A=A*10+c[i]
                print(A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = 0
    cnt = 1
    for i in range(1, n):
        if a[i] > a[i-1]:
            if b == 0:
                b = 1
            elif b == -1:
                cnt += 1
                b = 0
        elif a[i] < a[i-1]:
            if b == 0:
                b = -1
            elif b == 1:
                cnt += 1
                b = 0
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 62704
#include<bits/stdc++.h>
#define maxn 10010
using namespace std;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
int n,g,d_cnt;
int a[maxn],b[maxn],d[maxn];
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
bool pri(int x)
{
    int lim=sqrt(x);
    for(int i=2;i<=lim;++i)
        if(x%i==0)
            return false;
    return true;
}
void work(int x)
{
    int lim=sqrt(x);
    for(int i=2;i<=lim;++i)
    {
        if(x%i) continue;
        d[++d_cnt]=i;
        while(x%i==0) x/=i;
    }
    if(x>1) d[++d_cnt]=x;
}
bool check(int p)
{
    if(a[0]%p) return false;
    memcpy(b,a,sizeof(a));
    for(int i=n;i>=p-1;--i)
        b[i-(p-1)]=(b[i-(p-1)]+b[i])%p,b[i]=0;
    for(int i=0;i<=n;++i)
        if(b[i]%p)
            return false;
    return true;
}
int main()
{
    read(n);
    for(int i=n;i>=0;--i)
        read(a[i]),g=gcd(g,abs(a[i]));
    work(g);
    for(int i=2;i<=n;++i)
        if(pri(i)&&check(i))
            d[++d_cnt]=i;
    sort(d+1,d+d_cnt+1);
    for(int i=1;i<=d_cnt;++i)
        if(d[i]!=d[i-1])
            printf("%d\n",d[i]);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <tuple>
#include <utility>
#include <string>
#include <iomanip>

using namespace std;

#define int long long

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

  int h, w, x, y;
  cin >> w >> h >> x >> y;
  //cout << h << "|" << w << "|" << x << "|" << y << "|" << (x * y) << endl;
  //cout << (w * h / 2.) << " " << (2 * x == w && 2 * y == h ? "1": "0") << endl;
  //cout << fixed << setprecision(15) << (w * h / 2.) << " " << (2 * x == w && 2 * y == h ? "1": "0") << endl;
  int res = (2 * x == w && 2 * y == h) ? 1: 0;
  cout << fixed << setprecision(15) << (w * h / 2.0) << " " << res << endl;
  
}


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

using i64 = int64_t;

using Graph = vector<vector<int>>;

class StronglyConnectedComponents {
private:
    const Graph &graph;
    Graph g, rg;
    deque<int> order;
    deque<bool> used;
    vector<int> num_components;

    void dfs(int v) {
        used[v] = true;
        for(auto to: g[v]) {
            if(!used[to])
                dfs(to);
        }
        order.push_front(v);
    }

    void rdfs(int v, int k) {
        num_components[v] = k;
        for(auto to: rg[v]) {
            if(num_components[to] == -1)
                rdfs(to, k);
        }
    }

public:
    StronglyConnectedComponents(Graph &graph) : graph(graph), g(graph.size()), rg(graph.size()), used(graph.size()), num_components(graph.size(), -1) {
        for(int i=0;i<graph.size();i++) {
            for(auto e: graph[i]) {
                g[i].push_back((int)e);
                rg[(int)e].push_back(i);
            }
        }
    }

    int operator[](int v) {
        return num_components[v];
    }

    int decompose() {
        for(int v=0;v<(int)g.size();v++) {
            if(used[v]) continue;
            dfs(v);
        }

        int k = 0;
        for(int v: order) {
            if(num_components[v] != -1) continue;
            rdfs(v, k);
            k++;
        }

        return k;
    }
};

int main(){
    int v, e;
    cin >> v >> e;
    Graph graph(v+1, vector<int>());
    for(int i=0;i<e;++i){
        int s, t;
        cin >> s >> t;
        graph[s].push_back(t);
    }

    StronglyConnectedComponents scc(graph);
    scc.decompose();

    int q;
    cin >> q;
    for(int i=0;i<q;++i){
        int u, v;
        cin >> u >> v;
        if(scc[u] == scc[v])cout << 1;
        else cout << 0;
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 4984
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
mod=10**9+7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def comb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
ans=0
# min
for i in range(n-k+1):
  ans += -(a[i])*comb(n-i-1,k-1,mod)
  ans%=mod
# max
for i in range(k-1,n):
  ans += a[i]*comb(i,k-1,mod)
  ans %= mod
print(ans)

Measured memory_bytes: 20688
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll result = 0;
  result += min(a, k);
  k -= min(a, k);

  if (k) {
    k -= min(b, k);

    if (k) {
      result -= min(c, k);
      k -= min(c, k);
    }
  }

  cout << result << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> Type igcd(Type x,Type y){if(x==0||y==0)return (x>y)?x:y;return (y%x)?igcd(y%x,x):x;}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n,m;
	cin>>n>>m;
	
	vi a(m),b(m),c(m);
	vvi d(n,vi(n,INF));
	REP(i,m){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		a[i]--, b[i]--;
		d[a[i]][b[i]]=d[b[i]][a[i]]=c[i];
	}
	
	REP(k,n)REP(i,n)REP(j,n){
		chmin(d[i][j],d[i][k]+d[k][j]);
	}
	
	int ans=0;
	REP(i,m){
		if(c[i]>d[a[i]][b[i]]) ans++;
	}
	
	cout<<ans<<endl;
}

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

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

Measured memory_bytes: 256