akhauriyash/Code-Regression huggingface dataset:
n,h = map(int,input().split())
a = []
b = []
for _ in range(n):
    x,y = map(int,input().split())    
    a.append(x)
    b.append(y)

b.sort(reverse=True)
ma = max(a)
throw = 0
cnt = 0

for i in b:
    if i > ma:
        throw+=i
        cnt+=1
        if throw >= h:
            print(cnt)
            exit()
    else:
        break

if (h - throw) % ma == 0:
    print((h - throw) // ma + cnt)
else:
    print((h - throw) // ma + cnt + 1)

Measured memory_bytes: 61528
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using vector = std::vector<std::pair<long double, long double> >;
using iterator = vector::iterator;

vector get_points(int n)
{
  if (n == 0)
    {
      vector vec;
      vec.push_back(std::make_pair(0.0, 0.0));
      vec.push_back(std::make_pair(100.0, 0.0));
      return vec;
    }
  auto prev = get_points(n-1);
  vector retVec;
  retVec.push_back(prev[0]);
  for (int i=0; i<prev.size()-1; i++)
    {
      auto p1 = prev[i];
      auto p2 = prev[i+1];

      auto q1 = std::make_pair(2*p1.first/3 + p2.first/3, 2*p1.second/3 + p2.second/3);
      auto q3 = std::make_pair(2*p2.first/3 + p1.first/3, 2*p2.second/3 + p1.second/3);

      auto q2_x = q1.first + 0.5*(q3.first-q1.first) - sqrt(3)/2*(q3.second-q1.second);
      auto q2_y = q1.second + sqrt(3)/2*(q3.first-q1.first) + 0.5*(q3.second-q1.second);
      auto q2 = std::make_pair(q2_x, q2_y);

      //retVec.push_back(p1);
      retVec.push_back(q1);
      retVec.push_back(q2);
      retVec.push_back(q3);
      retVec.push_back(p2);
    }

  return retVec;
}

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

  vector points = get_points(n);

  std::cout << std::fixed;
  std::cout << std::setprecision(20);
  for (auto p : points)
    {
      std::cout << p.first << " " << p.second << std::endl;
    }
}



Measured memory_bytes: 3412
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;

    if(N == 3){
        cout << "2 5 63" << endl;
        return 0;
    }
    if(N == 4){
        cout << "2 5 20 63" << endl;
        return 0;
    }
    if(N == 5){
        cout << "2 5 20 30 63" << endl;
        return 0;
    }

    VI c;
    FOR(i,1,30001){
        int mo = i % 6;
        if(mo == 0 || mo == 2 || mo == 3 || mo == 4){
            c.eb(i);
        }
    }
    // 2,5,3,5,2,
    VI ans;
    LL sum = 0;
    REP(i,N){
        ans.eb(c[i]);
        sum += c[i];
    }
    if(sum%6 == 0){
        for(auto a : ans){
            cout << a << " ";
        }
        cout << endl;
        return 0;
    }else if(sum%6 == 2){
        ans.erase(ans.begin());
        ans.eb((ans.back() / 6 + 1) * 6);
    }else if(sum %6 == 3){
        ans.erase(ans.begin()+1);
        ans.eb((ans.back() / 6 + 1) * 6);
    }else if(sum %6 == 5){
        int t1 = ans.back() + 1;
        int t2 = ans.back() + 2;
        if(t1 % 6 == 4) ans.eb(t1);
        else ans.eb(t2);

        ans.erase(ans.begin()+1);

    }
    for(auto a : ans){
        cout << a << " ";
    }
    cout << endl;


}


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

typedef long long ll;

int main() {
    ll N, M, MOD = 1e9 + 7;
    cin >> N >> M;
    vector<ll> S(N), T(M);
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];
    vector<vector<ll>> s(N + 1, vector<ll>(M + 1, 1));
    rep(i, N) {
        rep(j, M) {
            s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j];
            if (S[i] != T[j]) {
                s[i + 1][j + 1] -= s[i][j];
            }
            s[i + 1][j + 1] = (s[i + 1][j + 1] + MOD) % MOD;
        }
    }
    cout << s[N][M] << endl;
}

Measured memory_bytes: 31616
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll sum[maxn];
ll a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
        sum[i] = sum[i-1] + a[i];
    }
    ll ans = INF;
    for(int i=1; i<=n-1; i++)
    {
        ll res = abs(sum[i] - (sum[n]-sum[i]));
        ans = min(ans,res);
    }
    printf("%lld",ans);
}


Measured memory_bytes: 3328
package main
import (
	"fmt"
)

func main(){
	var s string
	var n int
	fmt.Scan(&s, &n)
	for i:=0; i<n; i++{
		var op string
		var a, b int
		fmt.Scan(&op, &a, &b)
		switch op{
		case "print":
			fmt.Println(s[a:b+1])
		case "reverse":
			s = Reverse(s, a, b)
			// fmt.Printf("reversed: %s\n", s)
		case "replace":
			var p string
			fmt.Scan(&p)
			s = s[:a]+p+s[b+1:]
			// fmt.Printf("replased: %s\n", s)
		}
	}
}


func Reverse(s string, a int, b int) string {
	r := []rune(s)
	for i, j := a, b; i < (a+b)/2+1; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}


Measured memory_bytes: 1416
import sys
input=sys.stdin.buffer.readline

n,m=map(int,input().split())
edges=[[] for i in range(n)]
table=[-1]*n
for i in range(m):
    a,s=map(int,input().split())
    edges[a-1].append(s-1);edges[s-1].append(a-1)
l=[0]
print()
from collections import deque as que
q=que([(-1,0)])
p=que()
flag=1
ok=0
while flag:
    flag=0
    while len(q):
        flag=1
        pre,now=q.pop()
        if table[now]==-1:
            ok+=1
            table[now]=pre+1
            for i in edges[now]:
                if table[i]==-1:
                    p.append((now,i))
    p,q=q,p






if ok==n:
    print("Yes")
    for i in range(1,n):
        print(table[i])
else:print("No")

Measured memory_bytes: 42056
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int N = 100010;
const int oo = 100000000;
int v[N], n, dp[N][2];
int f(int i, int pos){
    if(dp[i][pos] != -1) return dp[i][pos];
    if(i == n - 1) return abs(v[i] - v[i - pos]);
    if(i > n) return oo;
    if(i == n - 2)
        return dp[i][pos] = f(i + 1, 1) + abs(v[i] - v[i - pos]);
    else return dp[i][pos] = min(f(i + 1, 1), f(i + 2, 2)) + abs(v[i] - v[i - pos]);
}
int main(){
    memset(dp, -1, sizeof dp);
	cin >> n;
	for(int i = 0; i < n; i++)
        cin >> v[i];
    cout << min(f(1, 1), f(2, 2)) << "\n";
	return 0;
}


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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

int n, a[N];
vector <int> ans;

int main()
{
      cin >> n;

      for(int i = 1; i <= n; i ++)
            cin >> a[i];

      int i;
      for(i = n; i >= 1; i -= 2)
            ans.pb(a[i]);
      if(n % 2) i = 2;
      else i = 1;
      for(; i <= n; i += 2)
            ans.pb(a[i]);
      for(int to : ans)
            cout << to << " ";
}


Measured memory_bytes: 3828
N=int(input())
T,A=map(int, input().split())
H_list=list(map(int, input().split()))

diff_min=1000
ans=0

for h in range(N):
    tmp=abs(A-T+0.006*H_list[h])
    if tmp<diff_min:
        diff_min=tmp
        ans=h
    else:
        ans=ans 

print(ans + 1)

Measured memory_bytes: 3064
def readln():
    return list(map(int, input().split()))


N = readln()[0]
S = input()


dic = {s: 0 for s in S}
for s in S:
    dic[s] += 1
ans = 1
for count in dic.values():
    # print(count)
    ans *= count + 1

# print(ans)
print((ans-1) % (10**9+7))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5005;
const int mod = 1e9+7;
int dp[N][N];
// breif solution 
signed main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int len = s.length();

	dp[0][0] = 1;
	for(int i=1;i<=n;i++)
	{
		dp[i][0] = ( dp[i-1][0] + dp[i-1][1] ) % mod;
		for(int j=1;j<=i;j++)
		{
			dp[i][j] = ( dp[i-1][j-1]*2 + dp[i-1][j+1] ) % mod;
		}
	}

	for(int i=1;i<=len;i++)
	{
		dp[n][len] = (dp[n][len] * (mod+1)/2) % mod;
	}
	cout<<dp[n][len];
}

Measured memory_bytes: 193920
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
#define INF 1000000007
using namespace std;
signed main(){
    int n;
    cin>>n;
    int a;
    cin>>a;
    if(n>=a)cout<<10<<endl;
    else cout<<0<<endl;
    return 0;
}




Measured memory_bytes: 764
package main

import (
	"fmt"
	"strconv"
)

func main() {
	// bit全探索
	// 長さnの文字列には2^(n-1)個の'+'を挟む場所があるので、これを全列挙する
	var s string
	fmt.Scan(&s)
	n := len(s)
	ans := 0
	for bit := 0; bit < (1 << uint(n-1)); bit++ {
		v, s0 := 0, 0
		for j := 0; j < n; j++ {
			if bit&(1<<uint(j)) != 0 {
				v, _ = strconv.Atoi(s[s0 : j+1])
				ans += v
				s0 = j + 1
			}
		}
		v, _ = strconv.Atoi(s[s0:n])
		ans += v
	}
	fmt.Println(ans)
}


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

long long n,a[200005];

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

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]-=i;
    }
    sort(a+1,a+1+n);
    long long b=a[(n+1)/2];
    long long s=0;
    for(int i=1;i<=n;i++)
        s+=abs(a[i]-b);
    cout<<s<<endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  double vs = 0, t;
  for(int i = 0; i < n; i++) {
    cin >> t;
    vs += 1 / t;
  }
  cout << setprecision(10) << 1 / vs << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((ll)3e5+5)
#define MOD ((ll)1e9 + 7)
#define INF ((ll)1e9 + 9)
#define ll unsigned long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<ll,ll>
#define mid ((l+r)/2)

ll n;
ll ct[65];
ll pw[65];
ll ans;

void addself(ll&a, ll b)
{
	a += b%MOD;
	a %= MOD;
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;

	pw[0] = 1;
	for (int j = 1; j < 61; ++j)
		pw[j] = (pw[j-1]*2) % MOD;

	for (ll i = 0; i < n; ++i)
	{
		ll x;
		cin >> x;	

		for (int j = 0; j < 61; ++j)
		{
			if((x>>j)&1) // exist
			{
				addself(ans, (i - ct[j]) * (pw[j]));
				ct[j]++;
			}
			else
				addself(ans, ct[j] * pw[j]);
		}
	}

	cout << ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    int N;
    cin >> N;
    LL ans = 0;
    int BXA = 0, BXX = 0, XXA = 0;

    REP0 (i, N)
    {
        string S;
        cin >> S;

        REP0 (i, S.length() - 1)
        {
            if (S[i] == 'A' and S[i + 1] == 'B')
            {
                ans++;
            }
        }

        if (S[0] == 'B' and S[S.length() - 1] == 'A')
        {
            BXA++;
        }
        else if (S[0] == 'B')
        {
            BXX++;
        }
        else if (S[S.length() - 1] == 'A')
        {
            XXA++;
        }
    }

    ans += max(0, BXA - 1);
    if (BXA != 0)
    {
        if (XXA != 0)
        {
            ans++;
            XXA--;
        }
        if (BXX != 0)
        {
            ans++;
            BXX--;
        }
    }

    ans += min(BXX, XXA);
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
    int h,w,k; scanf("%d%d%d",&h,&w,&k);
    vector<string> g(h); int s;
    rep(i,0,h){
        cin>>g[i];
        rep(j,0,w)if(g[i][j]=='#')s=i;
    }
    int ans[310][310],idx=1;
    rep(i,s,h){
        int cnt=0,last;
        rep(j,0,w)if(g[i][j]=='#')cnt++,last=j;
        if(cnt==0){
            rep(j,0,w)ans[i][j]=ans[i-1][j];
            continue;
        }
        rep(j,0,w){
            ans[i][j]=idx;
            if(g[i][j]=='#'&&j!=last)idx++;
        }
        idx++;
    }
    rrep(i,s-1,-1){
        int cnt=0,last;
        rep(j,0,w)if(g[i][j]=='#')cnt++,last=j;
        if(cnt==0){
            rep(j,0,w)ans[i][j]=ans[i+1][j];
            continue;
        }
        rep(j,0,w){
            ans[i][j]=idx;
            if(g[i][j]=='#'&&j!=last)idx++;
        }
        idx++;
    }
    rep(i,0,h){
        rep(j,0,w)printf("%d ",ans[i][j]);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1280
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

n , d = map(int , input().split())
ans = 0
for i in range(n):
	x , y = map(int , input().split())
	ans += 1 if math.sqrt(x**2 + y**2) <= d else 0
print(ans)










Measured memory_bytes: 9476
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep2(i,n) for(int i = (n - 1); i >= 0; i--)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

int to[200000];
const int si[] = { -1,0,1,0 };
const int sj[] = { 0,-1,0,1 };

struct UnionFind {

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

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

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

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

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

};

int main() {

	int n, m;
	cin >> n >> m;

	UnionFind UF(n);
	vector<int> size(n, 0);

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		UF.unite(a, b);
	}
	
	for (int i : UF.par) {
		size[UF.root(i)]++;
	}
	sort(size.begin(), size.end());

	cout << size[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 11096
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[200005];
int vis[200005];
int level[200005];
void bfs(int n){
    vis[n]=1;
    queue<int>Q;
    Q.push(n);
    while(!Q.empty()){
        int u=Q.front();
        Q.pop();
        for(int i=0;i<adj[u].size();i++){
            int v=adj[u][i];
            if(vis[v]==0){
                Q.push(v);
                vis[v]=1;
                level[v]=u;
            }
        }
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    int ok=0;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        if(u==1 || v==1){
            ok=1;
        }
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(ok){
        bfs(1);
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++){
            cout<<level[i]<<endl;
        }
        return 0;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 13048
#include<stdio.h>
#define MAX 100000
int A[MAX],n;
int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t=A[i+1];A[i+1]=A[r];A[r]=t;
  return i+1;
}
int main(){
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  q=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2244
import Control.Applicative
func :: Int -> [Int] -> [String]
func n []			   	  = []
func n (x:xs) | x==0 	  = []
	 		  | otherwise = ("Case " ++ (show n) ++ ": " ++ (show x)) : (func (n+1) xs)
	 
main = do
	x <- map (read::String->Int) . lines <$> getContents
	mapM_ putStrLn $ func 1 x

Measured memory_bytes: 4940
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String str;
		while(sc.hasNextLine()){
			str = sc.nextLine();
			while(true){
				char[] chars = new char[str.length()+1];
				chars = str.toCharArray();
				for(int i = 0; i < str.length(); i++){
					if(chars[i] == 'Z'){
						chars[i] = 'A';
					}else if(chars[i] == 'z'){
						chars[i] = 'a';
					}else if('a' <= chars[i] && chars[i] <= 'z' || 'A' <= chars[i] && chars[i] <= 'Z'){
						chars[i]++;
					}
				}
				str = String.valueOf(chars);
				if(str.indexOf("the") != -1 || str.indexOf("that") != -1 || str.indexOf("this") != -1){
						break;
				}
			}
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

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

    int count = 0;
    for(int i = 0; i <= (N/4); i++){
        for(int j = 0; j <= (N/7); j++){
            if(i * 4 + j * 7 == N) count ++;
        }
    }

    if(count > 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x; 
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    ll n;
    cin >> n;

    ll ans = 0;
    REP(i, n - 1) {
        ans += i + 1;
    }

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


Measured memory_bytes: 256
#include<stdio.h>

#define MOD 1000000007

int main(void){
	int n;
	int k;
	int i,j;
	long long int ret = 0;
	long long int u;
	long long int l;

	scanf("%d %d",&n,&k);

	u = 0;
	l = 0;
	for(i=0;i<k;i++){
		l += i;
		u += (n-i);
	}


	for(j=k;j<n+1;j++){
		ret = ret % MOD;
		ret += ((u-l)+1)%MOD;
		l += i;
		u += (n-i);
		i++;
//		printf("%d : %lld\n",j,ret);
	}
	ret = ret % MOD;
	ret++;

	printf("%lld\n",ret);

	return 0;

}



Measured memory_bytes: 1732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


bool isValid(string tmp){
	int count[300]={};
	rep(i,tmp.size())count[tmp[i]]++;
	rep(i,300)if(count[i]>4)return false;
	
	sort(all(tmp));
	
	rep(i,tmp.size()-1){
		if(tmp[i]==tmp[i+1]){
			string s="";
			rep(j,tmp.size()){
				if(j!=i&&j!=i+1)s+=tmp[j];
			}
			
			vector<bool> used(s.size(),false);
			
			rep(k,s.size()){
				if(used[k])continue;
				int same=0,plus1=0,plus2=0;
				for(int l=k+1;l<s.size();l++){
					if(used[l]==false&&s[k]==s[l])same++;
					if(used[l]==false&&s[k]+1==s[l])plus1++;
					if(used[l]==false&&s[k]+2==s[l])plus2++;
				}
				if(same>=2){
					used[k]=true;
					int c=0;
					for(int l=k+1;l<s.size();l++){
						if(used[l]==false&&s[k]==s[l]){
							used[l]=true;
							c++;
						}
						if(c>=2)break;
					}
				}
				else if(plus1&&plus2){
					used[k]=true;
					for(int l=k+1;l<s.size();l++){
						if(used[l]==false&&s[k]+1==s[l]){
							used[l]=true;
							break;
						}
					}
					for(int l=k+1;l<s.size();l++){
						if(used[l]==false&&s[k]+2==s[l]){
							used[l]=true;
							break;
						}
					}
				}
			}
			bool f=false;
			rep(j,used.size()){
				if(used[j]==false)f=true;
			}
			if(!f)return true;
		}
	}
return false;
}

int main(){
	string s;
	while(cin>>s){
		int c=0;
		for(int i=1;i<=9;i++){
			string tmp = s;
			tmp+='0'+i;
			if(isValid(tmp)){
				if(c)cout<<" ";
				cout<<i;
				c++;
			}
		}
		if(c==0)cout<<0;
		cout<<endl;
	}
}

Measured memory_bytes: 3088
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

pub fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let nmx: Vec<u32> = (0..3).map(|_| (read(&mut stdin).unwrap())).collect();
    let a: Vec<u32> = (0..nmx[1]).map(|_| (read(&mut stdin).unwrap())).collect();

    let res1: u32 = a.iter().filter(|&x| x < &nmx[2]).fold(0, |acc, _| acc + 1);
    let res2: u32 = a.iter().filter(|&x| x > &nmx[2]).fold(0, |acc, _| acc + 1);

    println!("{:?}", if res1 < res2 { res1 } else { res2 });
}


Measured memory_bytes: 4352
n, m = map(int, input().split())
x = [list(map(int, input().split())) for i in range(m)]
for i in range(10**(n-1) if n>1 else 0, 10**n):
    i = str(i)
    for s, c in x:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 38256
H, W = map(int, input().split())
if (H==1 or W==1):
    print(1)
elif (H%2==0):
    H /=2
    print(int(H*W))
else:
    H //= 2
    if(W%2==0):
        print(int(H*W+(W/2)))
    else:
        print(int(H*W+(W//2+1))) 


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

int main() {
  int A;
  int B;
  char op;

  cin >> A >> op >> B;

  if(op == '+'){
      cout << A+B << endl;
  }
  else if(op == '-'){
      cout << A-B << endl;
  }
  else {
      cout << "false" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
  vector<pair<int,int> > v;
  int a, b;
  while(cin >> a >> b && (a || b)){
    v.push_back(make_pair(a, b));
  }
  for(int i=0;i<(int)v.size();i++){
    for(int j=0;j<v[i].first;j++){
      for(int k=0;k<v[i].second;k++){
        if(j==0 || k==0 || j==v[i].first-1 || k==v[i].second-1){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;
public class Main{
    public static void main(String args[]) {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] arr = new int[n][3];
    
    for(int i =0 ; i<n; i++)
    {
        for(int j =0; j<3; j++)
        arr[i][j]=sc.nextInt();
    }
    
    int ans = 0;
    //ans = Math.max(dpc(arr, 0, n, 0), Math.max(dpc(arr,1,n,0), dpc(arr,2,n, 0)));
  ans = dpx(arr,n);
      System.out.println(ans);
      
      
    }
    
    static int min(int[] arr, int n)
    { 
        if(n==1) return 0;
        if(n==2) return Math.abs(arr[n-1]-arr[n-2]);
            int op1 = Math.abs(arr[n-1]-arr[n-2]) +min(arr,n-1);
            int op2 = Math.abs(arr[n-1]-arr[n-3]) +min(arr,n-2);
          int res = Math.min(op1, op2);
          
          return res;
    }
    
    static int dpc(int[][] arr, int i, int n, int row)
    {
        if(row==n)
            return 0;
            int j=0;
            int k=0;
            if(i==1)
                {
                    j=0;
                    k=2;
                }
                
            else  if(i==0)
                {
                    j=1;
                    k=2;
                }    
                
            else
            {
                j =0;
                k=1;
            }
            
            return arr[row][i]+Math.max(dpc(arr,j,n,row+1),dpc(arr,k,n,row+1));
        
    }
    
    static int dpx(int[][] arr, int n)
    {
        int[][] dp = new int[n][3];
        
        dp[0][0]=arr[0][0];
        dp[0][1]=arr[0][1];
        dp[0][2]=arr[0][2];
        
        for(int i=1; i<n; i++)
        {
            for(int in=0; in<3;in++)
            {  int j=0,k=0;
                 if(in==1)
                {
                    j=0;
                    k=2;
                }
                
            else  if(in==0)
                {
                    j=1;
                    k=2;
                }    
                
            else
            {
                j =0;
                k=1;
            }
                dp[i][in] = Math.max(dp[i-1][k] ,dp[i-1][j]) +arr[i][in];
            }
        }
        

        return Math.max(dp[n-1][0], Math.max(dp[n-1][1], dp[n-1][2]));
       
    }
   
    
}

Measured memory_bytes: 64284
#include<stdio.h>
#include<string.h>
#define rep(i,n) for(int (i)=0; (i) < (n); (i)++)
int w[40],addr;
int length(int n){
    int i, len=w[addr];
    if(len==n) { addr++; return 1;}
    for(i=addr+1; len<n; i++){
        len+=w[i];
        addr=i+1;
    }
    if(len==n) return 1;
    else return 0;
}
int main(void){
    while(1){
        int n;
        int i, flag, len, clear; char text[10];
        scanf("%d",&n); if(n==0) break;
        rep(i,n) {scanf("%s",text); w[i]=strlen(text);}
        for(i=0; i<n; i++){
            addr=i;
            if(length(5)==0) continue;
            if(length(7)==0) continue;
            if(length(5)==0) continue;
            if(length(7)==0) continue;
            if(length(7)==0) continue;
            break;
        }
        printf("%d\n",i+1);
    }
    return 0;
}



Measured memory_bytes: 2044
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    total = sum(A)
    ans = INF
    s = 0
    for i in range(N-1):
        s += A[i]
        if ans > abs(total - 2 * s):
            ans = abs(total - 2 * s)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 103260
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
    
   ll n,k;
   cin>>n>>k;
   if(k%2==1){
       cout<<(n/k)*(n/k)*(n/k)<<endl;
   }
   else{
       ll count=0;
       for(int i=1;i<=n;i++){
           if(i%k==k/2)count++;
       }
       cout<<(n/k)*(n/k)*(n/k)+count*count*count<<endl;
   }
   
   
    
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  ll mod = 1e9+7;
  ll acc = 0, carry = 0, ans = 1;
  for (int i = 0; i < n*2; i++) {
    int v = (s[i]=='B')^(i ? (s[i-1]=='B') : 0)^carry;
    if (v) {
      acc++;
      carry = 0;
    } else {
      (ans *= acc--) %= mod;
      if (acc < 0) ans = 0;
      carry = 1;
    }
  }
  if (acc) ans = 0;
  for (int i = 1; i <= n; i++)
    (ans *= i) %= mod;
  cout << ans << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

static const int MAX = 100;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];  //d[i][j]の最短コストを記録するDPテーブル

void floyd() {

  for( int k = 0; k < n; k++){         //経由する頂点数
    for(int i = 0; i < n; i++){         //始点
      if( d[i][k] == INFTY ) continue;

      for(int j = 0; j < n; j++){       //終点
        if( d[k][j] == INFTY ) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        //i -> j   i -> k -> j //iからｊへの最短経路を示す

      }
    }
  }
}


int main(){
  int H, W;
  cin >> H >> W;

  n = 10;


  REP(i,n)REP(j,n) cin >> d[i][j];
  floyd();


  //int field[H][W];

  ll ans = 0;
  REP(h,H)REP(w,W){
    int a;
    cin >> a;
    if(a == -1) continue;
    ans += d[a][1];
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
    for(T &in : v)
        is >> in;
    return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    for(int i = 0; i < (int)v.size(); i++)
        os << (i ? " " : "") << v[i];
    return os;
}
/*-------------------------------------------*/

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

    vector<string> ans(100);
    rep(i, 100) ans[i].resize(100, i < 50 ? '#' : '.');

    int a, b;
    cin >> a >> b;

    for(int i = 0; i < 50; i += 2)
        for(int j = 0; j < 100; j += 2)
            if(--a > 0) ans[i][j] = '.';

    for(int i = 51; i < 100; i += 2)
        for(int j = 0; j < 100; j += 2)
            if(--b > 0) ans[i][j] = '#';

    cout << "100 100\n";

    for(auto &&s : ans)
        cout << s << "\n";

    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int l = Integer.parseInt(sc.next());
		int r = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int count = 0;
		for(int i=l; i<=r; i++){
			if(i % d == 0) count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 35508
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
ansum = 0
for B in b:
    index = bisect.bisect_left(a,B)
    index2= bisect.bisect_right(c,B)
    ansum += index*(n-index2)
print(ansum)


Measured memory_bytes: 23092
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	long long int a,b,c,k,x; 
	cin >> a >> b >> c >> k;
        x=a-b;
	if(x > 1000000000000000000 || x < -1000000000000000000 ){
		cout << "Unfair" << endl;
	}else if(k%2 == 0){
		cout << x << endl;
    }else if(k%2 != 0){
		cout << -x << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(n + 1, 0);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    c[a]++;
    c[b]++;
  }
  bool ok = true;
  for(int i = 0; i <= n; i++) {
    if(c[i] % 2 != 0) {
      ok = false;
      break;
    }
  }
  if(ok) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  int cm4 = 0;
  int cm2 = 0;
  int cmm = 0;
  rep(i,n) {
    if (v[i] % 4 == 0) cm4++;
    else if (v[i] % 2 == 0) cm2++;
    else cmm++;
  }
  if (cm4 >= cmm) {
    cout << "Yes" << endl;
    return;
  }
  if (cm4 == cmm - 1 && cm2 == 0) {
    cout << "Yes" << endl;
    return;
  }
  cout << "No" << endl;
}

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

Measured memory_bytes: 3784
#include <stdio.h>

int main(){

  int x,y,r;

  scanf("%d%d",&x,&y);

  if(x<y){
    r=x;
    x=y;
    y=r;
  }

  while(y>0){

    r=x%y;
    x=y;
    y=r;
      }

  printf("%d\n",x);

  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
int main()
{
    string b;
    cin >> b;
    int count = 0;
    bool flag = false;
    int max = 0;
    for (int i = 0; i < b.size(); i++)
    {
        const char tmp = b[i];
        if (tmp == 'A' || tmp == 'G' || tmp == 'C' || tmp == 'T')
        {
            count++;
        }
        else
        {
            count = 0;
        }
        if (count > max)
            max = count;
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn ok(n: usize) -> bool {
    n % 10 == (n / 10) % 10 && n % 10 == n / 100
}

fn main() {
    input!{
        n: usize,
    };

    for i in n..999 + 1 {
        if (ok(i)) {
            println!("{}", i);
            return
        }
    }
}


Measured memory_bytes: 2096
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            num.add(sc.nextInt());
        }
        Collections.sort(num,Collections.reverseOrder());
        int a = 0;
        int b = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                a += num.get(i);
            } else {
                b += num.get(i);
            }
        }
        System.out.println(a - b);
    }
}

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

/*vector<int> p(n);
cin >> p[i]*/

int main(){

    int a, b, c;
    int tmp=0;
    cin >> a >> b >> c;

    tmp = a;
    a = b;
    b = tmp;

    tmp = a;
    a = c;
    c = tmp;

    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
#Volume0-0003
n = int(input())
for a in range(n):
  x,y,z = (input().split())
  x = int(x)
  y = int(y)
  z = int(z)
  for a in range (3):
    if x > y:
      x,y = y,x
    if y > z:
      y,z = z,y
  if z**2 == x**2+y**2:
    print("YES")
  else:
    print("NO")


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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main() {
    int K, N; cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    vector<int> dist(N);
    int M = 0;
    for (int i = 0; i < N - 1; i++) {
        dist.at(i) = A.at(i + 1) - A.at(i);
        M = max(M, dist.at(i));
    }
    dist.at(N - 1) = A.at(0) + (K - A.at(N - 1));
    M = max(M, dist.at(N - 1));
    int ans = K - M;
    cout << ans << endl;
}

Measured memory_bytes: 1920
N = int(input())
W = list(map(int, input().split(' ')))

s_min = 100 * 100 + 1

for i in range(N):
    s_dif = abs(sum(W[0:i]) - sum(W[i:]))
    if s_dif < s_min:
        s_min = s_dif

print(s_min)


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int n;
long long int a,b,num[102030],sum = 0,d;
bool Find_(long long int x){
    long long int ans = 0;
    for(int i = 1; i <= n && num[i] > x * b; i++){
        long long int k = (num[i] - x * b - 1) / d + 1;
        ans += k;
    }
    if(ans <= x)
        return 1;
    return 0;
}
bool cmp(int a, int b){
    return a > b;
}
int main()
{
    scanf("%d%lld%lld",&n,&a,&b);
    d = a - b;
    for(int i = 1; i <= n ; i ++){
        scanf("%lld",&num[i]);
    }
    sort(num+1,num+1+n,cmp);
    long long int l = 1, r = num[1] / b + 100;
    long long int ans;
    while(l <= r){
        int m = (l + r) >> 1;
        if(Find_(m))
            r = m ,ans = r;
        else
            l = m + 1;
        //if(cnt && l == r) break;
        if(l == r) break;//cnt = 1;
        
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 896
#pragma GCC optimize(2)
#include<iostream> 
#include<cstdio> 
#include<algorithm> 
#define File(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
#define re register
#define ri re int
#define gtch() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#define For(i,a,b) for(ri i=a;i<=b;++i) 
#define iFor(i,a,b) for(ri i=a;i>=b;--i) 
using namespace std;
typedef long long ll;
char buf[1<<21],*p1=buf,*p2=buf;
inline ll fr()
{
	re char ch=getchar();re ll res=0;int bl=0;
	while(!isdigit(ch)) bl=(ch=='-'),ch=getchar();
	while(isdigit(ch)) res=(res<<1)+(res<<3)+ch-'0',ch=getchar();
	return bl?-res:res;
}
const ll MOD=998244353;
const int MAXNlog=3e6+5;
const int MAXN=2e5+5;
ll val[MAXN],tag[MAXNlog];
#define ls (pos<<1)
#define rs (pos<<1|1)
inline void psd(int pos)
{
	if(!tag[pos]) return ;
	tag[ls]+=tag[pos],tag[rs]+=tag[pos];
	tag[ls]%=MOD,tag[rs]%=MOD,tag[pos]=0;
}
inline ll query(int pos,int l,int r,int x)
{
	if(l==r){return (val[x]+tag[pos])%MOD;}
	psd(pos);
	int mid=(l+r)>>1;
	if(x<=mid) return query(ls,l,mid,x);
	return query(rs,mid+1,r,x);
}
inline void modify(int pos,int l,int r,int ql,int qr,ll v)
{
	if(ql<=l&&r<=qr){tag[pos]+=v;return ;}
	int mid=(l+r)>>1;
	if(ql<=mid) modify(ls,l,mid,ql,qr,v);
	if(qr>mid) modify(rs,mid+1,r,ql,qr,v);
}
int rl[15],rr[15];
int n,k;
inline void prc()
{
	modify(1,1,n,1,1,1);
	For(i,1,n)
	{
		ll v=query(1,1,n,i)%MOD;
//		cerr<<i<<" "<<v<<"\n";
		For(j,1,k)
		{
			ri l=rl[j]+i,r=rr[j]+i;
			if(l>n) continue;
			if(r>n) r=n;
			modify(1,1,n,l,r,v);
		}
	}
	cout<<query(1,1,n,n);
}
inline void input()
{
	n=fr(),k=fr();
	For(i,1,k) rl[i]=fr(),rr[i]=fr();
}
signed main()
{
//	File("temp")
	input();
	prc();
	return 0;
}

Measured memory_bytes: 7720
#include<bits/stdc++.h>
using namespace std;
const int maxn=100050;
int book[maxn];
int x,n;
int ma=0;
int main() {
	cin>>n;
	while(n--) {
		cin>>x;
		book[x]++;
		if(x>0)
			book[x-1]++;
		book[x+1]++;
	}
	for(int i=1;i<=100000;i++)
		ma=max(ma,book[i]);
	cout<<ma<<endl; 
	return 0;
} 

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int w = Integer.parseInt(line[0]);
    int h = Integer.parseInt(line[1]);
    int x = Integer.parseInt(line[2]);
    int y = Integer.parseInt(line[3]);
    int r = Integer.parseInt(line[4]);
    if (r<=x && x<=w-r && r<=y && y<=h-r){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 24304
a = input()
x = ""
if a[0] == "1":
    x += "9"
else:
    x += "1"
if a[1] == "1":
    x += "9"
else:
    x += "1"
if a[2] == "1":
    x += "9"
else:
    x += "1"
print(x)

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = (int)1e5 + 1000;
vpi g[maxn];
int ans[maxn], a, b, n, vis[maxn];
 
void dfs(int pre, int co, int now) {
	int c = 1;
	for (auto it : g[now]) {
		if (it.fi == pre) continue;
		if (c == co) ++c;
		ans[it.se] = c;
		dfs(now, c, it.fi);
		++c;
	}
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	int max_bian = -1;
	cin >> n;
	forn(i, n - 1) {
		cin >> a >> b;
		g[a].pb({b, i});
		g[b].pb({a, i});
		max_bian = max(max_bian, int(g[a].size()));
		max_bian = max(max_bian, int(g[b].size()));
	}
	cout << max_bian << '\n';
	dfs(-1, -1, 1);
	forn(i, n - 1) {
		cout << ans[i] << '\n';
	}

#ifdef LOCAL_DEFINE          
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

ll red=0,blue=0 ;

void DFS(vvll &g,vll &color,int p,int c){
	if(color.at(p)!=0) return ;
	color.at(p) = c ;
	if(c==1) red++ ;
	else blue++ ;
	c *= -1 ;
	for(int i=0;i<g.at(p).size();i++){
		DFS(g,color,g.at(p).at(i),c) ;
	}
}

int main(){
	ll n ; cin >> n ;
	vvll g(n,vll(0)) ;
	for(int i=0;i<n-1;i++){
		ll f,t ;
		cin >> f >> t ;
		f-- ; t-- ;
		g.at(f).push_back(t) ;
		g.at(t).push_back(f) ;
	}
	vll color(n,0) ;
	DFS(g,color,0,1) ;
	vb use(n+1,true) ;
	vll ans(n,-1) ;
	if(red<=n/3){
		ll pos = 1 ;
		for(int i=0;i<n;i++){
			if(color.at(i)==1){
				ans.at(i) = pos*3 ;
				use.at(pos*3) = false ;
				pos++ ;
			}
		}
		pos = 1 ;
		for(int i=0;i<n;i++){
			if(color.at(i)==-1){
				while(!use.at(pos)) pos++ ;
				ans.at(i) = pos ;
				use.at(pos) = false ;
			}
		}
	}else if(blue<=n/3){
		ll pos = 1 ;
		for(int i=0;i<n;i++){
			if(color.at(i)==-1){
				ans.at(i) = pos*3 ;
				use.at(pos*3) = false ;
				pos++ ;
			}
		}
		pos = 1 ;
		for(int i=0;i<n;i++){
			if(color.at(i)==1){
				while(!use.at(pos)) pos++ ;
				ans.at(i) = pos ;
				use.at(pos) = false ;
			}
		}		
	}else{
		ll pos = 0 ;
		for(int i=0;i<(n+2)/3;i++){
			while(color.at(pos)==-1) pos++ ;
			ans.at(pos) = i*3+1 ;
			use.at(i*3+1) = false ;
			pos++ ;
		}
		pos = 0 ;
		for(int i=0;i<(n+1)/3;i++){
			while(color.at(pos)==1) pos++ ;
			ans.at(pos) = i*3+2 ; 
			use.at(i*3+2) = false ;
			pos++ ;
		}
		pos = 1 ;
		for(int i=0;i<n;i++){
			if(ans.at(i)==-1){
				while(!use.at(pos)) pos++ ;
				ans.at(i) = pos ;
				use.at(pos) = false ;
			}
		}
	}
	for(int i=0;i<n;i++) cout << ans.at(i) << (i==n-1?'\n':' ') ;
}




Measured memory_bytes: 23936
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST

a#b = abs$a-b

main = B.interact$B.pack.show.g.unfoldr(B.readInt.B.dropWhile isSpace)

g (n:h1:h2:hr)=runST $ do
    dp <- newListArray (1,n) (0:h2#h1:repeat 0)::ST s (STUArray s Int Int)
    forM_ (zip [3..n] (tails (h1:h2:hr))) $ \(i,a:b:c:_) -> do
        c1 <- (+ c#a) <$> readArray dp (i-2)
        c2 <- (+ c#b) <$> readArray dp (i-1)
        writeArray dp i (min c1 c2)
    readArray dp n
    where
        hv = listArray (1,n) (h1:h2:hr)

Measured memory_bytes: 2684