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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */
signed main() 
{
  int n,m;
  cin>>n>>m;
  string a[n],b[m];
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  bool j1=false;
  rep(i,n-m+1) rep(j,n-m+1) 
  {
    bool j2=true;
    rep(k,m) rep(l,m)
    {
      if(a[i+k][j+l]!=b[k][l]) j2=false;
    }
    if(j2) j1=true;
  }
  j1?print("Yes"):print("No");

  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

bool isPali(string s, ll a, ll b){
  if (b-a <= 0) return true;
  return s[a] == s[b] && isPali(s, a+1, b-1);
}

int main(){

  ios_base::sync_with_stdio (false);
  cin.tie(NULL);

  double L;
  cin >> L;

  cout << fixed << setprecision(10) << (L/3.0)*(L/3.0)*(L/3.0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int passed_all = 0;
    int passed_abroad = 0;

    rep(i, n){
        if(s[i]=='c') puts("No");

        if(s[i]=='a'){

            if(passed_all<a+b){
                puts("Yes");
                ++passed_all;
            }
            else puts("No");
        }

        if(s[i]=='b'){
            if(passed_all<a+b && passed_abroad<b){
                puts("Yes");
                ++passed_all;
                ++passed_abroad;
            }
            else puts("No");
        }
    }

    return 0;
}

Measured memory_bytes: 848
import java.util.*;

class Main
{
    public static void main(String [ ]args)
    {
        Scanner  sc  = new Scanner (System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int cost [] =new int [N];
        int []dp  = new int [N];
        Arrays.fill(dp,Integer.MAX_VALUE);
        for(int i=0;i<N;i++)
            cost[i] = sc.nextInt();
        dp [0] = 0;
        dp[1]= Math.abs(cost[1]-cost[0]);
        for(int i=2;i<N;i++)
        {   
           /* for(int j=0, c =i-1 ;c>=0 && j<K;c--,j++)
            {
                dp[i] = Math.min(dp[i],dp[c]+ Math.abs(cost[i]-cost[c]));
                
            }*/
             for(int j = i - 1, jump = 0; j  >= 0 && jump < K; j--, jump++){
                dp[i] = Math.min(dp[i], dp[j] + Math.abs(cost[j] - cost[i]));
              }
        }

        //for(int i=0;i<N;i++)
         //   System.out.println(dp[i]);
        System.out.println(dp[N-1]);

    }

}


Measured memory_bytes: 59964
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
typedef long long ll;
#define N 200010
using namespace std;
//int a[N];
map <int,int> ai;
void solve()
{
	int n;
	cin>>n;
	ll ans=0;
	for (int i=1;i<=n;i++)
	{
		int num;
		cin>>num;
		ai[i+num]++;
		if (i-num>0)
			ans+=ai[i-num];
	}	
	cout<<ans;
}
int main() 
{
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 13804
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int K, X;
  cin >> K >> X;
  for(int i=X-K+1; i<=X+K-1; i++)
    cout << i << ' ';
  cout << endl;
  return 0;
}


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

int N;
string s[100007];
int main(){
    cin >> N;
    for(int i = 0;i < N;i++) {
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }

    sort(s,s + N);

    long long int ans = 0;
    long long int j = 0;
    for(int i = 0;i < N-1 ;i++){
        //cout << s[i] << " と " << s[i+1] << endl;
        if(s[i] == s[i+1]){
            j++;
            ans = ans + j;
        }else{
            j = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int n,a,b,m[100006];
bool judge(LL x){
	LL sum=0;
	for (int i=0;i<n;++i){
		LL t =(LL)m[i]-x*b;
		if (t>0){
			sum+=(int)ceil(t*1.0/(a-b));
			if (sum>x)return 0;
		}
	}
	return 1;
}

int main(){
	cin>>n>>a>>b;
	int imax=0;
	for (int i=0;i<n;++i)scanf("%d",&m[i]),imax=max(m[i],imax);
	LL l=0,r=imax;
	while (l<r){
		LL mid=l+r>>1;
		if (judge(mid))r=mid;else l=mid+1;
	}
	printf("%lld\n",r);
	return 0;	
}

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


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

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func max(x, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := readInt(), readInt()
	cs := make([]float64, n+1)
	for i := 1; i <= n; i++ {
		p := readInt()
		cs[i] = (float64(p)+1)/2 + cs[i-1]
	}
	ans := float64(0)
	for i := k; i <= n; i++ {
		ans = max(ans, cs[i]-cs[i-k])
	}
	fmt.Println(ans)
}


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

char buf[1000000];
char buf2[1000000];

int solve(int len){ //return len
  int i, n, p;
  char k;

  for (p=0,i=0; i<len;) {
    for (n=0,k=buf[i]; k==buf[i]&&i<len; n++,i++) {
    }
    p += sprintf(buf2+p, "%d%c", n, k);
  }

  strncpy(buf, buf2, sizeof(char)*1000000);

  return p;
}

int main(){
  int l, r;

  while (scanf("%d", &r), r) {
    scanf("%s", buf);
    for (l=strlen(buf); r>0; r--) {
      l = solve(l);
    }
    printf("%s\n", buf);
  }

  return 0;
}

Measured memory_bytes: 1648
import numpy as np


def solve(string):
    n, k, *xyc = string.split()
    k = int(k)
    l = 2 * int(k)
    xy = [(int(x) % l, int(y) % l) if c == "W" else (int(x) % l, (int(y) + k) % l)
          for x, y, c in zip(xyc[::3], xyc[1::3], xyc[2::3])]
    ans = [[0 for j in range(l + 0)] for i in range(l + 0)]
    for _x, _y in xy:
        if (_x - k + 0.5) * (_y - k + 0.5) > 0:
            lt = 2
            lte = 1
            ans[0][0] += 1
        else:
            lt = -2
            lte = -1
        _x %= k
        _y %= k
        ans[_x][_y] += lt
        ans[_x + k][_y] -= lt
        ans[_x][_y + k] -= lt
        ans[_x + k][_y + k] += lt
        ans[_x + k][0] += lte
        ans[0][_y + k] += lte
        ans[_x][0] -= lte
        ans[0][_y] -= lte
    return str(np.asarray(ans).cumsum(axis=1).cumsum(axis=0).max())


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 136804
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}
vector<int>v1, v2;
int n, m;
signed main() {
	cin >> n >> m;
	for0(i, n) { v1.push_back(input()); v2.push_back(v1.back()); }
	for0(i, n) { v2.push_back(v1[i]); }
	int l, r, k = 0, sum = 0;
	while (1) {
		for0(i, m) {
			if (!i) { l = v2[k]; r = v2[k]; }
			else { l = min(v2[k], l); r = max(v2[k], r); }
			k++;
		}
		sum += r - l;
		k %= n;
		if (k == 0)break;
	}
	cout << sum << endl;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

int main(){
  int N;
  ll K;
  cin >> N >> K;
  int A[N+1];
  REP(i,N) cin >> A[i+1];

  int route[400001];
  route[0] = 1;
  REP(i,400000){
    route[i+1] = A[route[i]];
  }

  int* first = find(route, route + 400001, route[400000]);
  int* second = find(first + 1, route + 400001, route[400000]);
  int first_index = distance(route, first);
  int second_index = distance(route, second);

  if (K <= 400000)
    cout << route[K] << endl;
  else if (second - first == 1)
    cout << route[400000] << endl;
  else
    cout << route[first_index + (K - first_index) % (second_index - first_index)] << endl;

  return 0;
}

Measured memory_bytes: 5980
import sys
sys.setrecursionlimit(500000)

N, Q = map(int, input().split())

tree = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

scores = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    scores[p-1] += x

ans = [0] * N
visited = set()
def dfs(n: int, score: int):
    score += scores[n]
    ans[n] = score
    visited.add(n)
    for v in tree[n]:
        if v not in visited:
            dfs(v, score)

dfs(0, 0)

print(*ans)

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


#define mod 1000000007

int main() {
	// your code goes here
	int m,n;
	cin>>m>>n;
	char vec[m][n];
	int dp[m][n];
	for(int i=0;i<m;i++)
	
	{
		for(int j=0;j<n;j++)
		dp[i][j]=0;	}
	char a;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>vec[i][j];
		}
	}


	
	dp[0][0]=1;
	for(int i=1;i<m;i++)
	{
		if(vec[i][0]=='#')
		break;
		dp[i][0]=dp[i-1][0];
	}
	
	for(int j=1;j<n;j++)
	{
		if(vec[0][j]=='#')
		break;
		dp[0][j]=dp[0][j-1];
	}
	
	for(int i=1;i<m;i++)
	{
		for(int j=1;j<n;j++)
		{
			if(vec[i][j]=='#')
			continue;
			
			dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	
	
	cout<<dp[m-1][n-1];
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
std::vector<int> graph[100009];
std::vector<int> isvisited;
std::vector<int> max_length;
int N,M;
int dfs(int i);
int main()
{

        cin>>N>>M;
        for(int i=0; i<M; i++)
        {
                int x,y;
                cin>>x>>y;
                graph[x].push_back(y);
        }
        for(int i=0; i<=N; i++)
        {
                isvisited.push_back(0);
                max_length.push_back(0);
        }

        int max=0;
        for(int i=1; i<=N; i++)
        {
                int depth=dfs(i);
                if(max<depth)
                        max=depth;
        }


        cout<<max<<endl;

        return 0;
}
int dfs(int i){
        if(graph[i].size()==0)
                return 0;
        if(max_length[i]!=0)
                return max_length[i];
        for(int j=0; j<graph[i].size(); j++) {
                int depth=dfs(graph[i][j])+1;
                if(depth>max_length[i])
                        max_length[i]=depth;
        }

        return max_length[i];

}


Measured memory_bytes: 8740
from collections import Counter
N = int(input())
P = map(float, input().split())
dp = Counter()
dp[0] = 1
for p in P:
    dp1 = Counter()
    for k, v in dp.copy().items():
        dp1[k] += v*(1 - p)
        dp1[k+1] += v*p 
    dp = dp1.copy()
print(sum(v for k, v in dp.items() if 2*k > N))

Measured memory_bytes: 100412
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb(b) push_back(b) 
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
const int mod=1e9+7;
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;////////////////////////////////////////////////////////////
int main(){
 string s;
 ll n;
 cin>>s>>n;
  
 ll c;
 ll x=s.length();
 ll cnt=0; 
 rep(i,0,x){
  c=s[i]-'0';
  if(c!=1){
   pr(c);
   return 0;
  }
  if(i+1==n){
   pr(s[i]);
   return 0;
  }
 }
return 0;}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a <= 9 && b <= 9){
    cout << a * b;
  }else{
    cout << -1;
  }
}


Measured memory_bytes: 256
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int A[N], X[N][N], Y[N][N];//証言: "確実" | "不確実"
	rp(i, 0, N){
		cin>>A[i];
		rp(j, 0, A[i]){ cin>>X[i][j]>>Y[i][j]; X[i][j]--; }
	}

	int ans = 0;
	for(int ok=1, bits=1; bits<1<<N; ++bits, ok=1){//bits: 仮定のbit列: 0|1=不確実|確実, ok: 1|0=仮定に矛盾なし|あり
		for(int i=0; i<N && ok; ++i)
			if((bits>>i)&1)//i番目の仮定 0|1 が不確実は確認のしようがない
				for(int j=0; j<A[i] && ok; ++j) //i番目の証言は全て確実と仮定して処理
					if(((bits>>X[i][j])&1) != Y[i][j]) ok = 0;//x番目の仮定 0|1 と証言が矛盾
		if(ok) ans = max(ans, (int)bitset<16>(bits).count());//矛盾なし: 仮定から最大数を得る
	}
	cout<< ans <<endl;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    swap(a, b);
    
    const int N = 100;
    int g[N][N];
    fill(&g[0][0], &g[N - 1][N - 1] + 1, '@');

    vector<pair<int, int>> v;
    vector<pair<int, int>> u;

    set<pair<int, int>> taboo;
    taboo.insert(make_pair(0, 0));
    taboo.insert(make_pair(N-1, N-1));
    taboo.insert(make_pair(0, N-1));
    taboo.insert(make_pair(N-1, 0));
    
    int di[] = {0, +1, 0, -1};
    int dj[] = {+1, 0, -1, 0};
    {
      int dir = 0;
      int len = N;
      int i = 0;
      int j = -1;
      while (len) {
        for (int k = 0; k < len; ++k) {
          i += di[dir];
          j += dj[dir];
          g[i][j] = '#';
          unless (taboo.count(make_pair(i, j))) v.push_back(make_pair(i, j));
        }
        dir = (dir + 1) % 4;
        --len;
      }
    }

    {
      int dir = 3;
      int len = N - 1;
      int i = N;
      int j = 0;
      while (len) {
        for (int k = 0; k < len; ++k) {
          i += di[dir];
          j += dj[dir];
          g[i][j] = '.';
          unless (taboo.count(make_pair(i, j))) u.push_back(make_pair(i, j));
        }
        dir = (dir + 1) % 4;
        --len;
      }
    }

    reverse(u.begin(), u.end());

    for (int i = 0; i < a - 1; ++i) {
      int j = 2 * i + 1;
      g[v[j].first][v[j].second] = '.';
    }
    for (int i = 0; i < b - 1; ++i) {
      int j = 2 * i + 1;
      g[u[j].first][u[j].second] = '#';
    }

    cout << N << ' ' << N << endl;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        cout << (char)g[i][j];
      }
      cout << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int main()
{
	string s;
	cin>>s;
	int l=s.length();
	if(l==2)
        cout<<s<<endl;
    else
    {
        for(int i=2;i>=0;i--)
            cout<<s[i];
        cout<<endl;
    }






    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  int N, tmp;
  string X, tmp2;
  vector<pair<string, int>> M;
  cin >> N;
  for (int i=0; i<N; i++){
    cin >> tmp2 >> tmp;
    M.emplace_back(pair<string, int>(tmp2, tmp));
  }
  cin >> X;
  int ans = 0;
  bool f = false;
  for (auto e : M){
    if (f) ans += e.second;
    
    if (e.first == X){
      f = true;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
n=int(input())
p,m=[],[]
z=0
for i in list(map(int,input().split())):
    if i<0:m.append(i)
    elif i==0:
        z+=1
    else:p.append(i)
if p and m:
    print(sum(p)-sum(m))
    if z:
        for h in range(z-1):
            print("0 0")
        now=0
    else:now=p.pop()
    for j in m[1:]:
        print(now,j)
        now-=j
    if p:
        print(m[0],now)
        now=-now+m[0]
        for j in p[1:]:
            print(now,j)
            now-=j
        print(p[0],now)
    else:
        print(now,m[0])
elif p:
    if z:
        print(sum(p))
        for h in  range(z-1):
            print("0 0")
        now=0
        f=p.pop()
        for i in p:
            print(now,i)
            now-=i
        print(f,now)
    else:
        print(sum(p)-2*min(p))
        p.sort()
        now=p[0]
        k=p.pop()
        for j in p[1:]:
            print(now,j)
            now-=j
        print(k,now)
else:
    if z:
        print(-sum(m))
        for h in  range(z-1):
            print("0 0")
        now=0
    else:
        m.sort()
        print(-sum(m)+2*max(m))
        now=m.pop()
    for i in m:
        print(now,i)
        now-=i



Measured memory_bytes: 20612
// atcoder/abc078/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n, z, w;
  while (cin >> n >> z >> w) {
    vector<lli> a(n);
    cin >> a;
    if (n == 1) cout << abs(a.back() - w) << endl;
    else {
      // sort(a.begin(), a.end());
      cout << max(abs(a[n - 1] - a[n - 2]), abs(a[n - 1] - w)) << endl;
    }
  }

  return 0;
}


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

using namespace std;

#define MP make_pair
#define FF first
#define SS second

using LL = long long;
using PII = pair<LL,LL>;

const LL INF = 1e15;

int N, M, R, Q;
LL dist[10][100020];
void dijk(vector<vector<PII>>& G, int r){
  priority_queue<PII, vector<PII>, greater<PII>> pq;
  pq.push(MP(0,N+1+r));

  while(!pq.empty()){
	PII p = pq.top();
	pq.pop();
	if(p.FF > dist[r][p.SS])
	  continue;
	  
	for(auto&& e: G[p.SS]){
	  if(p.FF + e.SS < dist[r][e.FF]){
		dist[r][e.FF] = p.FF + e.SS;
		pq.push(MP(dist[r][e.FF], e.FF));
	  }
	}
  }
}

int main(){
  cin >> N >> M >> R >> Q;

  vector<vector<PII>> G(N+11);
  for(int i=0;i<M;++i){
	LL a, b, c;
	cin >> a >> b >> c;
	G[b].push_back(MP(a,c));
  }
  for(int i=0;i<=N;++i)
	G[N+1+i%R].push_back(MP(i,0));

  fill((LL*)dist, (LL*)dist+10*100020, INF);
  for(int r=0;r<R;++r)
	dijk(G, r);

  LL ans = 0;
  for(int q=0;q<Q;++q){
	LL x, y, z;
	cin >> x >> y >> z;
	LL tmp = min(dist[x%R][y], dist[y%R][x]);
	for(int r=0;r<R;++r)
	  tmp = min(tmp, dist[r][x] + dist[r][y]);

	ans += max(0ll, z-tmp);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 19464
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int a[100001];

int main() {

  int N, L; cin >> N >> L;
  rep(i, N) {
    cin >> a[i];
  }

  int idx = -1;
  rep(i, N - 1) {
    if(a[i] + a[i + 1] >= L) {
      idx = i;
    }
  }

  if(idx == -1) {
    cout << "Impossible" << endl;
  }
  else {

    cout << "Possible" << endl;

    rep(i, idx) {
      cout << i + 1 << endl;
    }
    for(int i=N-1; i>idx; i--) {
      cout << i << endl;
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const int INF=1e7;
const LL LINF=1e18;

int main(){
    LL a,b,c;
    cin >> a >> b >> c;
    LL ans=LINF;
    int t=a/2;
    ans=min(abs((a-t)*b*c-t*b*c),ans);
    t=b/2;
    ans=min(abs((b-t)*a*c-t*a*c),ans);
    t=c/2;
    ans=min(abs((c-t)*b*a-t*b*a),ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    
    if H == 0 and W ==0:
        break
    
    for i in range(H):
        if i == 0 or i == (H-1):
            print('#'*W)
        else:
            print('#' + '.'*(W-2) + '#')
    
    print('\r')



Measured memory_bytes: 5612
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
set<int> st[100001];
int ball[100001];

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  st[1].insert(0);
  fill(ball, ball + n, 1);
  for(int i = 0; i < m; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    if(st[ball[x]].find(x) == st[ball[x]].end()){
      if(st[ball[y]].find(y) != st[ball[y]].end()){
        st[ball[y]].erase(y);
        st[ball[y] + 1].insert(y);
      }
    }else{
      st[ball[x]].erase(x);
      if(ball[x] != 1)st[ball[x] - 1].insert(x);
      if(st[ball[y]].find(y) != st[ball[y]].end())st[ball[y]].erase(y);
      st[ball[y] + 1].insert(y);
    }
    ball[x]--;
    ball[y]++;
  }
  int res = 0;
  for(int i = 1; i <= n; i++){
    res += st[i].size();
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 9984
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		int H = sc.nextInt();
		
		int W = sc.nextInt();
		int ans = (N-H+1)*(N-W+1);
		System.out.println(ans);
	}

}

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

ll dp[309][309][309],A[309],S[309][309][309];
ll mod = 998244353;
void admod(ll &x, ll y){
    x = (x +y) % mod;
}
main(){
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    if(k > n) k = n;
    vector<ll> A;
    ll o = 0;
    for(ll i = 0; i < n; i++){
        if(s[i] == '1') o++;
        else A.push_back(o), o =0;
    }
    A.push_back(o);
    ll m = A.size();
    reverse(A.begin(),A.end());

    dp[0][0][0] = 1;
    for(ll i = 0; i <= m; i++){
        for(ll s = 0; s <= k; s++)
            for(ll j = k; j >=0; j--)
                admod(S[i][s][j], S[i][s][j+1]);
        for(ll car = 0; car <= k; car ++){
            for(ll pl = 0; car + pl <= k; pl++){

                admod(dp[i][car][pl], S[i][car+pl][car]);
                if(i < m){
                    admod(S[i+1][car+pl][car] , dp[i][car][pl]);
                    for(ll j = 1; j <= A[i]; j++)
                        admod(dp[i+1][car + j][pl],  dp[i][car][pl]);
                }

            }
        }
    }
    ll ans = 0;
    for(ll i = 0; i <= k; i++)
        admod(ans, dp[m][0][i] );
    cout<<ans<<endl;

}


Measured memory_bytes: 224888
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;
int k, n, ma;
int main() {
	cin >> k >> n;
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		ma = max(ma, a);
	}
	
	if(ma - 1 < k - ma) cout << 0 << endl;
	else cout << ma - 1 - (k - ma) << endl;
	
	return 0;
}

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

int main() {
	int s;
	cin >> s;
	vector<int> a;
	int now = s;

	while(1){
		a.push_back(now);
		if(now == 1){
			break;
		}

		if(now&1){
			now = 3*now+1;
		}else{
			now = now/2;
		}
	}

	rep(i,a.size()){
		if(a[i] == 4 || a[i] == 2 || a[i] == 1){
			cout << (i+1)+3 <<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

bool visited[301][301][301];
double f[301][301][301];
int n, x;

double dp(int a, int b, int c) {
    if (a < 0 || b < 0 || c < 0) {
        return 0.;
    }
    if (visited[a][b][c]) {
        return f[a][b][c];
    }

    visited[a][b][c] = true;
    if (a + b + c == 0) {
        return f[a][b][c] = 0.;
    }
    
    // f[a][b][c] = 1 + a/n * f[a-1][b][c] + b/n * f[a+1][b-1][c] + c/n * f[a][b+1][c-1] + (n-a-b-c)/n * f[a][b][c]
    f[a][b][c] = 1.;
    if (a > 0) {
        f[a][b][c] += (double)a / n * dp(a - 1, b, c);
    }
    if (b > 0) {
        f[a][b][c] += (double)b / n * dp(a + 1, b - 1, c);
    }
    if (c > 0) {
        f[a][b][c] += (double)c / n * dp(a, b + 1, c - 1);
    }
    f[a][b][c] *= (double)n / (a + b + c);
    return f[a][b][c];
}

inline void work() {
    cin >> n;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        if (x == 1) {
            ++a;
        }
        else if (x == 2) {
            ++b;
        }
        else {
            ++c;
        }
    }
    cout << setprecision(10) << dp(a, b, c) << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 239872
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int A,B; cin >> A >> B;
    int ans;
    if (A <= 5) ans = 0;
    else if (A <= 12) ans = B/2;
    else ans = B;
    cout << ans << ln;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    string s,t; cin>>s>>t;
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    sort(s.begin(),s.end());
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
  int N;
  std::string S;

  std::cin >> N >> S;

  int wc = 0, bc = 0;

  for (int i = 0; i < N; i++)
  {
    if (S[i] == '#')
    {
      bc++;
    }
    else
    {
      wc++;
    }
  }

  int wc_ = 0, bc_ = 0, ans = 1 << 30;

  for (int i = 0; i < N; i++)
  {
    ans = std::min(ans, bc_ + wc - wc_);

    if (S[i] == '#')
    {
      bc_++;
    }
    else
    {
      wc_++;
    }

    // i_ <= i を白にして i < _i を黒にする
    ans = std::min(ans, bc_ + wc - wc_);
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 832
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int cnt = N / 100;
    int n = N % 100;
    //System.out.println(n);
    cnt -= n / 5;
    n %= 5;
    cnt -= n / 4;
    n %= 4;
    cnt -= n / 3;
    n %= 3;
    cnt -= n / 2;
    n %= 2;
    if (cnt - n >= 0) {
      System.out.println(1);
      return;
    }
    System.out.println(0);
  }
}

Measured memory_bytes: 35692
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
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;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N;
int a[MAX_N];

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

  cin >> N;
  REP(i, N) cin >> a[i];
  priority_queue<int> q;
  REP(i, N) q.push(a[i]);

  int ans = 0;
  while (!q.empty()) {
    int alice = q.top();
    q.pop();
    ans += alice;
    if (!q.empty()) {
      int bob = q.top();
      q.pop();
      ans -= bob;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int K,A,B,N;
string S;
int main(){
    cin>>K>>A>>B;
    if(K==1){cout<<"OK"<<endl;return 0;}
    for(N=K;N<=B;N+=K)if(A<=N&&N<=B){cout<<"OK"<<endl;return 0;}
    cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3672
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			char c = s[0];
			int ans = 1;
			for (int i = 1; i < n; i++) {
				if (c != s[i]) {
					ans++;
					//System.Diagnostics.Debug.WriteLine($"{i} {c} {s[i]}");
				}
				c = s[i];
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define FOR(i, x, y) for(int i = x; i < y; i++)
#define endll cout << "\n"
#define For(n) for(int i = 0; i < n; i++)
const ll maxn = 1000 + 100;
const int inf = 1e9;

bool isprime(int x)
{
    if(x <= 1)
        return false;
    for(int i = 2; i * i < x; i++)
        if(x % i == 0)
            return false;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    if(n % 10 == n / 100)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
 
std::map<int, int>_Map;
#define lowbit(x) ((x) & (-x))
typedef long long ll;


int main() {
    for (int i = 1; i < 32; ++i) {
        _Map[(1 << i)] = i;
    }
    int n, tmp;
    int ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &tmp);
        tmp = lowbit(tmp);
        ans += _Map[tmp];
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    R, G, B, N = map(int, rl().split())
    
    ans = 0
    for r in range(0, N + 1, R):
        for g in range(0, N + 1, G):
            if N < r + g:
                break
            if (N - r - g) % B == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39152
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
class Main {
    static int MOD = 998244353;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[][] X = new int[N][2];
        for (int i = 0; i < N; i++) {
            X[i][0] = in.nextInt();
            X[i][1] = in.nextInt();
        }
        Arrays.sort(X, Comparator.comparing(x -> x[0]));
        int[] dp = new int[N+1];
        dp[N] = 1;
        dp[N-1] = 1;
        List<Integer> start = new ArrayList<>();
        start.add(N - 1);
        for (int i = N - 2; i >= 0; i--) {
            int j = start.size() - 1;
            int right = X[i][0] + X[i][1];
            for (; j >= 0; j--) {
                if (right > X[start.get(j)][0]) {
                    dp[i] = dp[start.get(j)] + start.remove(j) - i;
                } else {
                    break;
                }
            }
            start.add(i);
            if (dp[i] == 0) dp[i] = 1;
        }

        int res = 1;
        for (int i = N - 1; i >= 0; i--) {
            res = (res + dp[i + dp[i]]) % MOD;
            dp[i] = res;
        }
        System.out.println(res);
    }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char> > masu(H, vector<char>(W));

  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      char ch;
      cin >> ch;
      masu[i][j] = ch;
    }
  }

  vector<bool> allWhiteRow(H, true);
  vector<bool> allWhiteColumn(W, true);

  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      if(masu[i][j] == '#') {
        allWhiteRow[i] = false;
        allWhiteColumn[j] = false;
      }
    }
  }

  for(int i=0;i<H;i++) {
    if(!allWhiteRow[i]) {
      for(int j=0;j<W;j++) {
        if(!allWhiteColumn[j]) {
          cout << masu[i][j];
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a,b,s,c;
  cin>>n>>a>>b;
  s=n-a;
  c=s/b;
  if(s%b==0)
  {
  	cout<<0<<endl;
  	return 0;
  }
  cout<<n-a-b*c<<endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int t,a;
    cin >> t >> a;
    int h[1000];
    int ans=10000000;
    int count;
    int k;
    for(int i=0;i<n;i++){
        cin >> h[i];
        k=t*1000-h[i]*6;
        if(abs(k-a*1000)<ans){
            ans = abs(k-a*1000);
            count=i+1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            int a, b, flag = 0;
            long sum = 0;
            int min = 1000000001;
            
            for(int i=0; i<n; i++){
            	a = Integer.parseInt(sc.next());
            	b = Integer.parseInt(sc.next());
            	
            	sum += a;
            	if(a != b){
            		flag = 1;
            	}
            	if(a > b && min > b){
            		min = b;
            	}
            }
            
            if(flag == 0){
            	System.out.println(0);
            }else{
            	System.out.println(sum - min);
            }
            sc.close();
        }
    }
	

Measured memory_bytes: 42608
#include <bits/stdc++.h>
 #include<string>
using namespace std;
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define init(arr,value) memset(arr,value,sizeof(arr))
#define test unsigned int tet;cin >> tet;while(tet--)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int max(int a,float b){
    if(a>b)
       return a;
    return b;
}
ll gcd(ll a,ll b){
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a*b/gcd(max(a,b),min(a,b));
}
int main() {
	// your code goes here
	int t;
	cin>>t;
	cout<<t+t*t+t*t*t;
	return 0;
}

Measured memory_bytes: 3624
N,M = map(int,input().split())
X = list(map(int,input().split()))
X = sorted(X)
xlen = []
for i in range(len(X)-1):
    xlen.append(X[i+1]-X[i])
xlen = sorted(xlen)
if(M<=N):
  print("0")
else:
  print(sum(xlen[:M-N]))

Measured memory_bytes: 13968
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

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

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int main () {
	SpeedForce;
	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	ll ans = max({a*c, a*d, b*c, b*d});
	cout << ans << '\n';
	
	return Accepted;
}

// B...a


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 1e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

int main()
{
  llt a, b;
  llt x;
  cin>>a>>b>>x;
  llt aa = a /x;
  llt bb = b /x;
  llt cc = a%x==0?1:0;
  cout<<bb-aa+cc<<endl;
  return 0;
}


Measured memory_bytes: 2560