akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
    long long a, b, k, tkhs, aok;
    cin >> a >> b >> k;
    if(a + b <= k) {
        tkhs = 0;
        aok  = 0;
    }
    else if(a <= k) {
        tkhs = 0;
        aok  = b - (k - a);
    }
    else {
        tkhs = a - k;
        aok  = b;
    }
    cout << tkhs << ' ' << aok << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

int N;

int input() {
  string S;
  cin >> S;
  int h, m, s;
  h = (S[0] - '0') * 10 + (S[1] - '0');
  m = (S[3] - '0') * 10 + (S[4] - '0');
  s = (S[6] - '0') * 10 + (S[7] - '0');
  return h * 3600 + m * 60 + s;
}

int main(void) {
  while(cin >> N, N) {
    pii T[20000];
    REP(i, 0, N) {
      T[i * 2] = pii(input(), 1);
      T[i * 2 + 1] = pii(input(), 0);
    }

    sort(T, T + N * 2);

    int ans = 0, cnt = 0;
    REP(i, 0, N * 2) {
      if(T[i].se == 0) cnt--;
      if(T[i].se == 1) cnt++;
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3140
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int a, b;
    cin >> a >> b;
    forn (i, 0, 1e6) {
        if (i * 8 / 100 == a && i * 10 / 100 == b)
            return cout << i, 0;
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <deque>
#include <numeric>
#include <set>
using namespace std;

typedef long long ll;

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

    string s;
    ll k;
    cin >> s >> k;
    int n = (int)s.length();

    if(n == 1){
        cout << k / 2 << endl;
        return 0;
    }

    // n >= 2
    ll ans = 0;
    if(s[0] != s[n - 1]){
        int id = 0;
        int cnt = 1;
        while(id < n - 1){
            if(s[id] != s[id + 1]){
                ++id;
            }
            else{
                while(id < n - 1 && s[id] == s[id + 1]){
                    ++id;
                    ++cnt;
                }
                ans += cnt / 2;
                cnt = 1;
            }
        }
        ans *= k;
    }
    // s[0] == s[n-1]
    // 両端と連結部分と真ん中部分で分ける
    else{
        // 左端
        int id = 0;
        ll cnt = 1;
        while(id < n - 1 && s[id] == s[id + 1]){
            ++id;
            ++cnt;
        }

        // 全て同じの場合
        if(id == n - 1){
            ans = (cnt * k) / 2;
        }

        // 全て同じではない場合
        else{
            ans += cnt / 2;

            string t = s;
            t += s.substr(0, id + 1);

            int left = id + 1;

            // 右端
            id = n - 1;
            cnt = 1;
            while(id > 0 && s[id] == s[id - 1]){
               --id;
               ++cnt;
            }
            ans += cnt / 2;

            int right = id;
            // 中間部分[left, right)
            id = left;
            cnt = 1;
            ll temp = 0;
            while(id < right){
                if(s[id] != s[id + 1]){
                    ++id;
                }
                else{
                    while(id < right && s[id] == s[id + 1]){
                        ++id;
                        ++cnt;
                    }
                    temp += cnt / 2;
                    cnt = 1;
                }
            }
            ans += temp * k;

            // 連結部分
            int limit = t.length();
            temp = (ll)(limit - right) / 2;
            ans += temp * (k - 1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import kotlin.system.exitProcess

private fun distanceP(xValues: List<Double>, yValues: List<Double>, p: Int): Double {
    return Math.pow(xValues.zip(yValues).map {
        Math.pow(Math.abs(it.first - it.second), p.toDouble())
    }.sum(), 1 / p.toDouble())
}


private fun distanceChebyshev(xValues: List<Double>, yValues: List<Double>): Double {
    return xValues.zip(yValues).map { Math.abs(it.first - it.second) }.max()!!
}

fun main(args: Array<String>) {
    val elemNum = readLine()!!.toInt()
    if (elemNum == 0) {
        exitProcess(1)
    }
    val xValues = readLine()!!.split(" ").map(String::toDouble)
    val yValues = readLine()!!.split(" ").map(String::toDouble)
    println("${distanceP(xValues, yValues, 1)}")
    println("${distanceP(xValues, yValues, 2)}")
    println("${distanceP(xValues, yValues, 3)}")
    println("${distanceChebyshev(xValues, yValues)}")
}



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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto & x : a) {
    cin >> x;
  }

  for(int i = 1; i < n; ++i) {
    if(a[i] < a[i - 1]) return cout << "No\n", 0;
    else if(a[i] - 1 >= a[i - 1]) a[i]--;
  }
  cout << "Yes\n";
}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    int x; cin >> x;
    int a = x % 100, b = x / 100;
    int ch;
    if(a % 5 == 0){
        ch = a / 5;
    }else{
        ch = a / 5 + 1;
    }
    if(ch <= b){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&xs[i])
	}
	result := abs(xs[0] - x)
	for i := 1; i < n; i++ {
		result = gcd(result, abs(xs[i]-x))
	}
	fmt.Print(result)
}


Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll seg[1<<19],n,q;
void add(ll a,ll b,ll r,ll l,ll k,ll x){
    if(a<=r&&l<=b){
        seg[k]=x;
        return;
    }
    if(l<a||b<r)return;
    if(seg[k]>=0){
        seg[k*2+1]=seg[k];
        seg[k*2+2]=seg[k];
        seg[k]=-1;

    }
    add(a,b,r,(r+l-1)/2,k*2+1,x);
    add(a,b,(r+l+1)/2,l,k*2+2,x);
}
ll find(ll x,ll r,ll l,ll k){
    if(seg[k]>=0)return seg[k];
    if((r+l-1)/2>=x)return find(x,r,(r+l-1)/2,k*2+1);
    else return find(x,(r+l+1)/2,l,k*2+2);
}
int main(void){
    cin>>n>>q;
    for(ll i=0;i<(1<<19)-1;i++)seg[i]=-1;
    seg[0]=2147483647;
    for(ll i=0;i<q;i++){
        ll a;
        cin>>a;
        if(a){
            ll x;
            cin>>x;
            cout<<find(x,0,(1<<18)-1,0)<<endl;
        }else{
            ll s,t,x;
            cin>>s>>t>>x;
            add(s,t,0,(1<<18)-1,0,x);
            
        }
    }
}

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

using namespace std;
using ll = long long;

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> ps(n, k - q);
  rep(i, q) {
    int a;
    cin >> a;
    a--;
    ps[a]++;
  }
  rep(i, n) {
    if (0 < ps[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


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

#define ll                                 long long
#define mp                                 make_pair
#define pb                                 push_back
#define pii                              pair<long long,long long>
#define vi                                 vector<long long>
#define setbits(x)                          __builtin_popcountll(x)
#define zrobits(x)                          __builtin_ctzll(x)
#define mod                              1000000007
#define inf                               1e18
#define make_array(array_name,array_size,type)   type array_name[array_size];
#define print_array(array_name,array_size)        for(int i=0;i<n;i++){cout<<array_name[i]<<" ";}cout<<endl;
#define input_array(array_name,array_size)       for(int i=0;i<n;i++){cin>>array_name[i];}

long long binexpo(long long a, long long b)
{
   long long res = 1;
   while (b > 0)
   {
      if (b & 1)
         res = res * a;
      a = a * a;
      b >>= 1;
   }
   return res;
}

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

   string a, b;
   cin >> a >> b;
   ll num = stoi(a + b);
   for (int i = 1; i <= 10000; i++)
   {
      if ((i * i) == num)
      {
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;
   return 0;
}

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

using namespace std;

const int N =1e5 + 5;

int arr[N];

int cnt[2][N];
set<pair<int,int> > st;
int main() {

    int n;
    cin>>n;
    for(int i = 0 ; i<n ; ++i) scanf("%d" , &arr[i]);
    int ans = 1e9;
    for(int i = 0 ; i<n ; i+=2)
    {
        ++cnt[0][arr[i]];
    }

    for(int i = 1 ; i<n ; i+=2)
    {
       ++cnt[1][arr[i]];
    }

    for(int i = 1 ; i<N ; i++)
    {
       st.insert({-cnt[1][i] , i});
    }

    for(int i = 1 ; i<N ; ++i)
    {
        int a = n/2 - cnt[0][i];
        st.erase({-cnt[1][i] , i});
        if(st.empty()) a+= n/2;
        else a+= n/2 + st.begin()->first;
        st.insert({-cnt[1][i] , i});
        ans = min(ans , a);
    }

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


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

int main()
{
  	int n;
  	cin >> n;
  	int a[n];
  	bool flag = false;
  	for(int i=0;i<n;++i)
    {
    	cin >> a[i];
      if(a[i] % 2 == 0)
      {
      	if(!(a[i] % 3 == 0) && !(a[i] % 5 ==0))
        {
        	flag = true;
        }
      }
    }
  	if(flag){
    	cout << "DENIED" << endl;
    }
  	else{
    	cout << "APPROVED" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

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

	vector<int> dist(K, 1e8);
	dist[1] = 0;
	deque<int> deq;
	deq.push_front(1);
	while(!deq.empty()){
		int x = deq.front();
		deq.pop_front();
		if(dist[x%K]+1 < dist[(x+1)%K]){
			deq.push_back((x+1)%K);
			dist[(x+1)%K] = dist[x%K]+1;
		}
		if(dist[x%K] < dist[10*x%K]){
			deq.push_front(10*x%K);
			dist[10*x%K] = dist[x%K];
		}
	}

	cout << dist[0]+1 << endl;


	return 0;
}


Measured memory_bytes: 896
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Circle
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int r;
  scanf("%d", &r);
  printf("%d\n", r * r);
  return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


h, w = map(int, input().split(' '))
a = [list(map(int, input().split(' '))) for i in range(h)]
l = []
for r in range(h):
    for c in range(w):
        if a[r][c]%2:
            if c+1<w:
                l.append([r, c, r, c+1])
                a[r][c+1]+=1
            elif r+1<h:
                l.append([r, c, r+1, c])
                a[r+1][c]+=1
print(len(l))
for i in l:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

Measured memory_bytes: 26368
import sys


def input():
    return sys.stdin.readline().strip()


N = int(input())
A = [int(input()) for _ in range(N)]
left = [0] * N
right = [0] * N
for i in range(1, N):
    left[i] = max(A[i - 1], left[i - 1])
    right[N - i - 1] = max(A[N - i], right[N - i])
[print(max(left[i], right[i])) for i in range(N)]

Measured memory_bytes: 17268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string s; cin >> s;
    if(s[0] == s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> H(N+1);
    rep(i, N) cin >> H[i+1];
    H[0] = 0;

    int res=0;
    for(int i=1; i<=N; i++) {
        int f=1;
        for(int j=0; j<i; j++) {
            if(H[j] > H[i]) {
                f=0;
                break;
            }
        }
        if(f) res++;
    }

    cout << res << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 3030;

VI g[MAX];

int DP[MAX][MAX];
int A[MAX];

int dfs(int x, int p)
{
	if (DP[x][p] != -1) return DP[x][p];

	int res = 0;
	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (to == p) continue;

		if (A[to] >= A[x]) continue;
		int val = dfs(to, x);
		if (val == 0) res = 1;
	}

	return DP[x][p] = res;
}


int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	FOR (i, 0, n)
	{
		int x;
		scanf("%d", &x);
		A[i] = x;
	}

	FOR (i, 0, n-1)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		g[x].PB(y);
		g[y].PB(x);
	}

	FILL(DP, -1);

	FOR (i, 0, n)
	{
		if (dfs(i, i))
		{
			printf("%d ", i + 1);
		}
	}
	printf("\n");


}


Measured memory_bytes: 36352
#include "bits/stdc++.h"
using namespace std;
//template <typename... T> void read(T& ... t){ ((cin >> t), ...); }
//template <typename... T> void write(T ... t){ ((cout << t), ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define space ' '
using LL = long long;
using pii = pair<int,int>;
const int INF = 2e9;
const int NN = 2e3;
const int MOD = 998244353;
namespace Mm{
	inline int _chk(const int &x){ return (x < MOD) ? x : (x-MOD < MOD) ? x-MOD : x%MOD; }
	inline int mul(const int &x, const int &y) { return ((LL)x*y)%MOD; }
	inline int add(const int &x, const int &y) { return (x+y)%MOD; }
	inline int power(const int &x, const int &n){ if(n == 0) return 1; int y=power(x, n>>1); y=mul(y,y); return (n&1)?mul(y,x):y; }
	inline int inv(const int &x){ return power(x, MOD-2); }
	int _fact[2*NN] = {0};
	inline int fact(const int &x){ return (x == 0 ? 1 : (_fact[x] != 0 ? _fact[x] : _fact[x]=mul(x, fact(x-1)))); }
	int _cnk[2*NN+1][2*NN+1] = {0};
	inline int cnk(const int &n, const int &k){ return (n<k) ? 0 : _cnk[n][k]; }
} using namespace Mm;
int n,k;
int dp[NN+1][NN+1];
int nbPairs[2*NN+1];

#define read(a,b) cin>>a>>b
#define write(a,b) cout<<a<<b

int32_t main(){ FAST;
	for(int a=0; a<=2*NN; ++a) for(int b=0; b<=2*NN; ++b){
		if(b > a) _cnk[a][b] = 0;
		else if(b == 0) _cnk[a][b] = 1;
		else _cnk[a][b] = add(_cnk[a-1][b], _cnk[a-1][b-1]);
	}

	read(k,n);
	dp[0][0] = 1;
	for(int i=1; i<=NN; ++i){ // #pairs
		int prefSum = 0;
		for(int j=0; j<=NN; ++j){ // #items to distribute on pairs
			dp[i][j] = add(dp[i-1][j], add(prefSum, prefSum)); // k € [1;j]
			prefSum = add(prefSum, dp[i-1][j]);
		}
	}

	for(int i=1; i<=k; ++i) for(int j=i+1; j<=k; ++j) ++nbPairs[i+j];

	for(int i=2; i<=2*k; ++i){
		int ans = 0;
		int others = k - 2*nbPairs[i];

		if(i&1){
			if(others == 0){
				ans = dp[nbPairs[i]][n];
				write(ans, ln);
				continue;
			}

			for(int giveOthers=0; giveOthers<=n; ++giveOthers){
				int givePairs = n-giveOthers;
				ans = add(ans, mul(dp[nbPairs[i]][givePairs], cnk(others+giveOthers-1, giveOthers)));
			}
		}
		else{
			--others;
			if(others == 0){
				ans = add(dp[nbPairs[i]][n], dp[nbPairs[i]][n-1]);
				write(ans, ln);
				continue;
			}
			
			for(int giveOthers=0; giveOthers<=n; ++giveOthers){
				int givePairs = n-giveOthers;
				ans = add(ans, mul(dp[nbPairs[i]][givePairs], cnk(others+giveOthers-1, giveOthers)));
			}
			for(int giveOthers=0; giveOthers<=n-1; ++giveOthers){
				int givePairs = n-1-giveOthers;
				ans = add(ans, mul(dp[nbPairs[i]][givePairs], cnk(others+giveOthers-1, giveOthers)));
			}
		}

		write(ans, ln);
	}
}

Measured memory_bytes: 78592
#include <stdio.h>
int main(){
  int n;
  scanf("%d", &n);
  int ans = 0;
  int i;
  int pre = 100000;
  for(i=0;i<n-1;i++){
    int b;
    scanf("%d", &b);
    if (pre < b) {
      ans += pre;
    } else {
      ans += b;
    }
    pre = b;
  }
  ans += pre;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

vector<vector<ll>>a(10002);
vector<ll>b;ll p;
ll c[10002],ans;
void dep(ll now){
	for(ll i=0;i<a[now].size();i++){
		ll next=a[now][i];
		if(c[next]!=0){
			continue;
		}
		c[next]=b[p];
		p++;
		ans+=min(c[now],c[next]);
		dep(next);
	}
}
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		b.push_back(x);
	}
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	c[0]=b[0];
	p++;
	dep(0);
	cout << ans<<endl;
	for(ll i=0;i<n;i++){
		cout << c[i]<<" ";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	const int mod = 1e9 + 7;
	int n; cin >> n;
	string s; cin >> s;
	vector<vi> dp(n + 1, vi(n + 1));
	dp[0][0] = 1;
	
	rep(i, n) rep(j, i + 1) if(dp[i][j]){
		if(j) (dp[i + 1][j - 1] += dp[i][j] * 2ll % mod) %= mod;
		else (dp[i + 1][0] += dp[i][j]) %= mod;
		if(j < n) (dp[i + 1][j + 1] += dp[i][j]) %= mod;
	}
	cout << dp[n][s.size()] << endl;
	return 0;
}

Measured memory_bytes: 98176
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli x,xc;
    cin >> x;
    xc = x;
    x %= 100;
    lli rec = 0;
    rec += (x / 5) * 105;
    x -= (x / 5) * 5;
    rec += (x / 4) * 104;
    x -= (x / 4) * 4;
    rec += (x / 3) * 103;
    x -= (x / 3) * 3;
    rec += (x / 2) * 102;
    x -= (x / 2) * 2;
    rec += (x / 1) * 101;
    x -= (x / 1) * 1;

    cout<<(rec > xc ?0:1)<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,l;
    cin >> n >> l;
    vector<string> str(n);
    for(int i=0;i<n;i++)
        cin >> str.at(i);
    sort(str.begin(),str.end());
    for(int i=0;i<n;i++)
        cout << str.at(i);
    cout << endl;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

i=-1
j=0
ans=[]
for x in range(h):
  l=[]
  for y in range(w):
    i+=1
    if i==a[j]:
      i=0
      j+=1
    l.append(j+1)
  ans.append(l)
for i in range(0,len(ans),2):
  ans[i].reverse()
print("\n".join(map(lambda x:" ".join(map(str,x)),ans)))


Measured memory_bytes: 70440
<?php
  fscanf(STDIN,"%d %d %d",$a,$b,$c);
  if ($a == $b && $a != $c ||
      $b == $c && $a != $b ||
      $a == $c && $a != $b){
    echo "Yes\n";
  }else {
    echo "No\n";
  }
  


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;

int main(){
    cin >> s;
    ll ans = INF;
    rep(i,s.size() - 2){
        ll num = 100 * (s[i] - '0') + 10 * (s[i+1] - '0') + (s[i+2] - '0');
        ans = min(ans,abs(num - 753));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i,length,time;
  scanf("%d",&n);
  int plan[n+1][3];
  plan[0][0]=0;
  plan[0][1]=0;
  plan[0][2]=0;
  for(i=1;i<=n;i++)
    scanf("%d%d%d",&plan[i][0],&plan[i][1],&plan[i][2]);
  for(i=1;i<=n;i++){
    length=abs(plan[i][1]-plan[i-1][1])+abs(plan[i][2]-plan[i-1][2]);
    time=plan[i][0]-plan[i-1][0];
    if(time<length || (time-length)%2==1){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    fori (i, SZ(a))
        out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
    return out;
}

void smain();

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


#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#define cerr cout
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}

const int N = 1009;
const int L = 2e4 + 9;
const ll oo = 1e18;
ll dp[N][L];

inline bool cmp(const tuple<int, int, int> &a, const tuple<int, int, int> &b) {
    int f, s, t;
    tie(f, s, t) = a;
    int ff, ss, tt;
    tie(ff, ss, tt) = b;
    return f + s < ff + ss;
}

void smain() {

    int n;
    cin >> n;
    vector<tuple<int, int, int>> obj(n);
    fori (i, n){
        int w, s, v;
        cin >> w >> s >> v;
        obj[i] = tuple<int,int,int>(w, s, v);
    }
    sort(ALL(obj), cmp);
    fori (i, N) fori (j, L) dp[i][j] = -oo;
    dp[0][0] = 0;
    fori (i, n) {
        int w, s, v;
        tie(w, s, v) = obj[i];
        fori (j, L) if (dp[i][j] >= 0) {
            inmax(dp[i + 1][j], dp[i][j]);
            if (j <= s && j + w < L) inmax(dp[i + 1][j + w], dp[i][j] + v);
        }
    }
    cout << *max_element(dp[n], dp[n] + L);
}

Measured memory_bytes: 157952
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
  
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
  
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
  
using namespace std;
//using namespace __gnu_pbds;
         
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using pld = pair <ld, ld>;
 
/*
const ll MAX_MEM = 5e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
 
*/
 
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
         
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
         
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
         
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
         
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("circlecover.in", "r", stdin);
    //freopen("circlecover.out", "w", stdout);
}

signed main()
{
    Start();
    int n, m;
    cin >> n >> m;
    swap(n, m);
    vector <int> a(n);
    cin >> a;
    int cnt = 0;
    for (int i = 0; i < n; ++i)
        if (a[i] % 2 == 1)
            ++cnt;
    if (cnt > 2)
        return cout << "Impossible", 0;
    vector <int> b, c;
    for (int i = 0; i < n; ++i)
        if (a[i] % 2 == 0)
            b.pb(a[i]);
        else
            c.pb(a[i]);
    while (c.size())
    {
        b.pb(c.back());
        reverse(all(b));
        c.pop_back();
    }
    a = b;
    b[0]--;
    if (b.size() == 1)
        b.pb(1);
    else
        b.back()++;
    if (b[0] == 0)
        b.erase(b.begin());
    cout << a << endl << b.size() << endl << b;
    return 0;
}



Measured memory_bytes: 380
# -*- coding: utf-8 -*-


def main():
    n = list(map(int, input()))
    c = n[0]

    if len(n) > 1:
        k = set(n[1:])

        if len(k) == 1 and k == {9}:
            print(c + 9 * (len(n) - 1))
        else:
            print(c + 9 * (len(n) - 1) - 1)
    else:
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
bool ok[100001],ok1[100001];
int ans[100001];
bool isprime(int x){
	
	for(int i=2;i*i<=x;i++){
		if(x%i==0)
		re false;
	}
	re true;
}
int main(){
	forn(i,2,100001)
	ok[i]=isprime(i);
	
	forn(i,2,100001){
		if(i%2==0||!ok[(i+1)/2]||!ok[i])
		ok1[i]=false;
		else
		ok1[i]=true;
	}
	forn(i,3,100001){
		ans[i]=ans[i-1]+ok1[i];
	}
	int q,l,r;
	cin>>q;
	while(q--){
		cin>>l>>r;
		l--;
		cout<<ans[r]-ans[l]<<"\n";
	}
	re 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
int  a[105], b[105];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	int cnt = 0,res=0;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			cnt++;
		}
		if (cnt >= 3) {
			res = 1;
		}
		if (a[i] != b[i]) {
			cnt = 0;
		}
	}
	if (res) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let it = stdin.lock().bytes().map(|c| c.unwrap() as char);
    let (fs, ft) = (|c: &char| c.is_whitespace(), |c: &char| !c.is_whitespace());
    let token = it.skip_while(fs).take_while(ft).collect::<String>();
    token.parse().ok().unwrap()
}
#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    f(std::io::BufWriter::new(out.lock()));
}
#[allow(unused_macros)]
macro_rules! debug {
    ($($var:expr),*) => { #[cfg(debug_assertions)] {
        $({ match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } })*
        eprintln!();
    }};
}

fn main() {
    let n: usize = input();
    let mut xy: Vec<(i32, i32)> = (0..n).map(|_| (input(), input())).collect();
    xy.sort_by(|a, b| {
        f64::atan2(a.1 as f64, a.0 as f64)
            .partial_cmp(&f64::atan2(b.1 as f64, b.0 as f64))
            .unwrap()
    });

    let mut ans = 0.0;
    for l in 0..n {
        let mut v = (0, 0);
        for r in 0..n {
            let mut i = l + r;
            if i >= n {
                i -= n;
            }
            let (x, y) = xy[i];
            v.0 += x;
            v.1 += y;
            ans = f64::max(
                ans,
                f64::sqrt(v.0 as f64 * v.0 as f64 + v.1 as f64 * v.1 as f64),
            );
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int n;
const int MAX = 1e6;
bool a[MAX];

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

    int n;
    cin >> n;
    int l = 0;
    a[0] = 1;

    rep(q, n) {
        int x;
        cin >> x;

        if (x < l) {
            cout << "No" << endl;
            continue;
        }

        cout << "Yes" << endl;
        if (x >= MAX) continue;
        for (int i = x; l <= i; --i) {
            if (a[i] == 1) {
                a[i] = 0;
                for (int j = i + 1; j <= x; ++j) {
                    a[j] = 1;
                }
                while (l < MAX && !a[l]) {
                    l++;
                }
                break;
            }
        }
    }
}

Measured memory_bytes: 4100
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static int argmax( final int[] array ){
	    
	int index = 0;
	int maxVal = Integer.MIN_VALUE;
	for ( int i = 0; i < array.length; i++ ) {
	    if ( maxVal < array[ i ] ) {
		index = i;
		maxVal = array[ i ];
	    }
	}
	return index;
    }
    
    static int argmin( final int[] array ){
	
	int index = 0;
	int minVal = Integer.MAX_VALUE;
	for ( int i = 0; i < array.length; i++ ) {
	    if ( minVal > array[ i ] ) {
		index = i;
		minVal = array[ i ];
	    }
	}
	return index;
    }
    
    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int n = stdin.nextInt();
	    if ( n == 0 ) {
		break;
	    }

	    int[][] map = new int[ n ][ n ];
	    for ( int i = 0; i < n; i++ ){
		for ( int j = 0; j < n; j++ ){
		    map[ i ][ j ] = stdin.nextInt();
		}		    
	    }

	    ArrayList<Integer> mins = new ArrayList<Integer>();
	    for ( int i = 0; i < n; i++ ){
		mins.add( map[ i ][ argmin( map[ i ] ) ] );
	    }

	    ArrayList<Integer> maxs = new ArrayList<Integer>();
	    int[] cols = new int[ n ];
	    for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n; j++ ) {
		    cols[ j ] = map[ j ][ i ];
		}
		maxs.add( map[ argmax( cols ) ][ i ] );
	    }

	    Collections.sort( maxs );
	    boolean success = false;
	    for ( int i = maxs.size() - 1; i >= 0; i-- ) {
		final int val = maxs.get( i );
		if ( mins.contains( val ) ) {
		    System.out.println( val );
		    success = true;
		    break;
		}
	    }
	    if ( !success ) {
		System.out.println( 0 );
	    }
	}	
    }    
}

Measured memory_bytes: 19520
if __name__ == '__main__':
    Num = list(map(int, input().split()))
    st = [Num[0], Num[2]]
    en = [Num[1], Num[3]]
    if min(en) - max(st) > 0:
        print(min(en) - max(st))
    else:
        print('0')


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

int main(void){
    
    ll n, ans=0;
    ll c[509]={};
    ll s[509]={};
    ll f[509]={};
    
    cin >> n;
    
    if(n<=1){
        
        cout << "0" << endl;
        return 0;
        
    }
    
    for(ll i=1; i<=n-1; i++){
        
        cin >> c[i] >> s[i] >> f[i];
        
    }
    
    for(ll i=1; i<=n-1; i++){
        
        ans = 0;
        
        for(ll j=i; j<=n-1; j++){
            
            if(ans<=s[j]){
                
                ans = s[j];
                
            } else if(ans%f[j]==0){
                
                // ans = ans;
                
            } else {
                
                ans = (ans/f[j]+1) * f[j];
                
            }
            
            ans += c[j];
            
        }
        
        cout << ans << endl;
        
    }
    
    cout << "0" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
long long n;
int ans=0;
void dfs(long x,bool a,bool b,bool c){
  if(x>n)return;
  
  if(a&&b&&c)ans++;
  dfs(x*10+7,true,b,c);
  dfs(x*10+5,a,true,c);
  dfs(x*10+3,a,b,true);
  
}
int main(){
  cin>>n;
  dfs(0,false,false,false);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;

int main()
{

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

    int n=0;
    cin>>n;

    int temp = n%10;
    if(temp==2 || temp==4 || temp==5 || temp==7 || temp==9)
    	cout<<"hon"<<endl;
    else if(temp==0 || temp==1 || temp==6 || temp==8)
    	cout<<"pon"<<endl;
    else
    	cout<<"bon"<<endl;

    

}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
ll dp[3002][3002][4];
ll mat[3002][3002];
ll r,c,qt;
bool can(int x,int y){
    if(x>=0 && x<r && y>=0 && y<c)return true;
    else return false;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>r>>c>>qt;
    memset(mat,0,sizeof mat);
    rep(i,0,qt){
        ll a,b,x;
        cin>>a>>b>>x;
        a--;
        b--;
        mat[a][b]=x;
    }
    rep(i,0,r){
        rep(j,0,c){
            rep(k,0,4)dp[i][j][k]=-INF;
    }
}
    if(mat[0][0]>0)dp[0][0][1]=mat[0][0];
    dp[0][0][0]=0;
    rep(i,0,r){
        rep(j,0,c){
            rep(k,0,4){
                if(mat[i][j]>0){///pegando
                    if(can(i-1,j))dp[i][j][1] = max(dp[i][j][1],dp[i-1][j][k]+mat[i][j]);
                    if(k<3 && can(i,j-1))dp[i][j][k+1] = max(dp[i][j][k+1],dp[i][j-1][k]+mat[i][j]);
                }
                if(can(i-1,j))dp[i][j][0] = max(dp[i][j][0],dp[i-1][j][k]);
                if(can(i,j-1))dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k]);
            // cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<"\n";
            }
        }
    }
    cout<<max({dp[r-1][c-1][0],dp[r-1][c-1][1],dp[r-1][c-1][2],dp[r-1][c-1][3]})<<"\n";
    return 0;  
}   

Measured memory_bytes: 355388
#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 EPS      (double)1e-9
#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> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	long double x;
	cin>>x;
	
	llong tmp=100;
	int ans=0;
	while(tmp<x){
		tmp+=tmp*0.01;
		ans++;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3752
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class DInsertion {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n;
	    string s;
	    in >> n >> s;

	    int l = 0, r = 0;
	    for(int i=0; i<s.length(); i++){
	        if(s[i] == '(') r++;
	        else {
	            if(!r) l++;
	            else r--;
	        }
	    }

	    string res;
	    for(int i=0; i<l; i++){
	        res += "(";
	    }
	    res += s;
	    for(int i=0; i<r; i++){
	        res += ")";
	    }

        out << res << endl;
	}
};


int main() {
	DInsertion solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import itertools
import sys

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

for i, j in itertools.product(range(H), range(W)):  # jが先に増える
    c = 0
    if S[i][j] == "#":
        if i != 0 and S[i - 1][j] == "#":
            c += 1

        if i != H - 1 and S[i + 1][j] == "#":
            c += 1

        if j != 0 and S[i][j - 1] == "#":
            c += 1

        if j != W - 1 and S[i][j + 1] == "#":
            c += 1

        if c == 0:
            print("No")
            sys.exit()
            break
else:
    print("Yes")


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
typedef long long ll;
using namespace std;

int main() {
  int A,B; cin>>A>>B;
  cout<<(A-1)*(B-1)<<endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<unordered_set>

using namespace std;




vector<int> prime_sieve(int n)
{
    int* arr = new int[n+1];
    
    int i, p;
    for (i = 0; i <= n; ++i) {
        arr[i] = i;
    }
    for (i = 2; i <= n; ++i) {
        if (arr[i] != 0) {
            for (p = arr[i] * arr[i]; p <= n; p += arr[i]) {
                arr[p] = 0;
            }
        }
    }
    vector<int> primes;
    for (i = 2; i <= n; ++i) {
        if (arr[i] != 0) {
            primes.push_back(arr[i]);
        }
    }
    return primes;
}

int min(int a, int b)
{
    return a < b ? a : b;
}



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

    long long rem;
    rem = n % (a + b);
    if (rem > a) {
        rem = a;
    }
    long long ans;
    ans = rem + ((n) / (a + b))*a;
    cout << ans;
    
}

    


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
 
#define f first
#define s second
#define MAX_N 155
#define INF 1000000000
 
using namespace std;
 
typedef pair<int,int> P;
 
int main(void){
 
  int n,m,k,a,b;
 
  while(cin >> n >> m,n|m){
    vector<P>v[MAX_N];
     
    for(int i=1;i<=n;i++){
      cin >> k;
      for(int j=0;j<k;j++){
    	cin >> a >> b;
   		 v[i].push_back(make_pair(a,b));
      }
    }
 
    int dp[MAX_N][11][80];
 
    for(int i=0;i<MAX_N;i++)
      	for(int j=0;j<11;j++)
  			for(int k=0;k<80;k++)
      			dp[i][j][k]=INF;
 
    for(int i=0;i<11;i++)
      for(int j=0;j<80;j++)
    	dp[0][i][j]=dp[1][i][j]=0;
 
    for(int i=2;i<=n;i++){
      for(int j=0;j<v[i].size();j++){
    	for(int l=m;l>=0;l--){
      		for(int k=0;k<v[i-1].size();k++)
        	dp[i][j][l]=min(dp[i][j][l],dp[i-1][k][l]+(v[i][j].s+v[i-1][k].s)*abs(v[i][j].f-v[i-1][k].f));
      		
      		if(l<m){
        		if(i==2)dp[i][j][l]=0;
        		for(int p=0;p<v[i-2].size();p++)
          			dp[i][j][l]=min(dp[i][j][l],dp[i-2][p][l+1]+(v[i][j].s+v[i-2][p].s)*abs(v[i][j].f-v[i-2][p].f));
      		}
    	}
      }
    }
     
    int ans=INF;
    for(int i=0;i<v[n].size();i++)ans=min(ans,dp[n][i][0]);
    if(m>0)for(int i=0;i<v[n-1].size();i++)ans=min(ans,dp[n-1][i][1]);
 
    cout << ans << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1760