akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np
N=int(input())
nums=list(map(int,input().split(" ")))
ans_array=[]
#符号の統一
add=0
mode=0
if min(nums)>0: #全部正の場合
    mode=0
elif max(nums)<0: #全部負の場合
    mode=1
elif max(nums)==min(nums)==0: #全部0
    print("0")
    sys.exit()
else: #正負混合
    mode=2
count=0

if mode==2: #need to modify
    temp=[]
    if abs(max(nums))<abs(min(nums)):
        mode=1 #全部負にする
        add=min(nums)
        ind=np.argmin(nums)
    elif abs(max(nums))>=abs(min(nums)):
        mode=0
        add=max(nums)
        ind=np.argmax(nums)
    for i in range(len(nums)):
        nums[i]+=add
        ans_array.append("{0} {1}".format(ind+1,i+1))
        count+=1
        
        

if mode==0: #全部正
    for i in range(len(nums)-1):
        nums[i+1]+=nums[i]
        count+=1
        ans_array.append("{0} {1}".format(i+1,i+2))
    print(count)
    for i in ans_array:
       print(i)
                

elif mode==1:
    nums.reverse()
    for i in range(len(nums)-1):
        nums[i+1]+=nums[i]
        count+=1    
        ans_array.append("{0} {1}".format(len(nums)-i,len(nums)-i-1))

    print(count)
    for i in ans_array:
       print(i)


Measured memory_bytes: 12616
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if(x-r<0 || x+r>W || y-r<0 || y+r>H){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();

		int ans = 1000;

		for (int i = 0; i <= s.length() - t.length(); i++) {
			int tmp = 0;

			for (int j = 0; j < t.length(); j++) {
				if (!(s.substring(i + j, i + j + 1).equals(t.substring(j, j + 1)))) {
					tmp++;
				}
			}

			if (tmp < ans) {
				ans = tmp;
			}

		}

		System.out.println(ans);

		sc.close();
	}

}

Measured memory_bytes: 53148
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

#define Pa pair<int, int> 
const int P = 1e9 + 7;
const int N = 305;
int f[N][N][N], m, n;
vector<Pa> v[N];

inline void add(int &x, int y) {
	x += y, (x >= P) && (x -= P);
}

int main() {
	read(n), read(m);
	for (int i = 1, l, r, x;i <= m; i++)
		read(l), read(r), read(x), v[r].push_back(MP(l, x));
	f[0][0][0] = 1;
	for (int i = 1;i <= n; i++) {
		for (int j = 0;j < i; j++) {
			for (int k = 0;k <= j; k++) {
				add(f[i][j][k], f[i-1][j][k]);
				add(f[i][i-1][k], f[i-1][j][k]);
				add(f[i][i-1][j], f[i-1][j][k]);
			}
		}
		for (auto t: v[i]) {
			int l = t.fi;
			for (int j = 0;j < i; j++) 
				for (int k = 0;k <= j; k++) {
					int ct = (j >= l) + (k >= l) + 1;
					if (ct != t.se) f[i][j][k] = 0;
				}
		}
	}
	int ans = 0;
	for (int i = 0;i < n; i++)
		for (int j = 0;j <= i; j++)
			add(ans, f[n][i][j]);
	write(ans);
	return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  vector<vector<int>> S(N, vector<int>(0));
  int A, B;
  for(int i=0; i<M; i++){
    cin >> A >> B;
    S.at(A-1).push_back(B-1);
    S.at(B-1).push_back(A-1);
  }
  int Ans=0;
  for(int i=0; i<N; i++){
    int L=S.at(i).size();
    int K=1;
    for(int j=0; j<L; j++){
      if(H.at(i)<=H.at(S.at(i).at(j))){
        K=0;
      }
    }
    if(K==1){
      Ans++;
    }
  }
  cout << Ans << endl;
}

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

#define ll long long int

using namespace std;

int main() {
    ll n , k;
    cin >> n >> k;
    vector<ll> A(n);
    for (auto & a : A) cin >> a;

    for (ll i = 0; i < k; ++i) {
        vector<ll> B(n+1, 0);
        for (ll j = 0; j < n; ++j) {
            ll l = max(0LL, j - A[j]);
            ll r = min(n, j + A[j] + 1);
            B[l] += 1;
            B[r] -= 1;
        }
        ll cur = 0;
        for (ll j = 0; j < n; ++j) {
            cur += B[j];
            A[j] = cur;
        }

        bool ok = true;
        for (ll j = 0; j < n; ++j) {
            if (A[j] != n) {
                ok = false; break;
            }
        }
        if (ok) break;
    }

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


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

using namespace std;

bool check(vector<int> v, int n) {
    while (n > 0) {
        int a = n % 10;
        for (int i : v) if (a == i) return false;
        n /= 10;
    }
    return true;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(k);
    for (int i = 0; i < k; i++) cin >> v[i];

    while(1) {
        if (check(v, n)) break;
        n++;
    }

    cout << n;
}


Measured memory_bytes: 3568
from collections import deque
def main():
    H, W = list(map(int, input().split()))
    A = [['#'] * (W + 2)] + [['#', ] + list(input()) + ['#', ] for _ in range(H)] + [['#'] * (W + 2)]
    printl = lambda l: [print(x) for x in l]
    stack = deque([[1, 1], ])
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    INF = float('inf')
    L = [[INF] * W for _ in range(H)]
    visited = [[0] * W for _ in range(H)]
    L[0][0] = 1
    while stack:
        x, y = stack.popleft()
        if visited[x - 1][y - 1] == 1:
            continue
        visited[x - 1][y - 1] = 1
        for (dx, dy) in dxy:
            X = x + dx
            Y = y + dy
            if A[X][Y] == '#':
                continue
            if visited[X - 1][Y - 1] == 0:
                stack.append([X, Y])
            L[X - 1][Y - 1] = min(L[X - 1][Y - 1], L[x - 1][y - 1] + 1)
    ans = 0
    for a in A:
        for i in a:
            if i == '.':
                ans += 1
    if L[H - 1][W - 1] == INF:
        print(-1)
    else:
        print(ans - L[H - 1][W - 1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    vector<vector<int>> edge(N);
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
    }
    REP(i, N) { cout << edge[i].size() << endl; }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#define INF 2147483647
using namespace std;

class RMQ{
	int size;
	vector<int> minval;
	vector<int> maxval;
	pair<int,int> _query(int a,int b,int k,int l, int r){
		if(r<=a||b<=l)return make_pair(INF,-INF);
		if(a<=l&&r<=b)return make_pair(minval[k],maxval[k]);
		else{
			pair<int,int> vl=_query(a,b,k*2+1,l,(l+r)/2);
			pair<int,int> vr=_query(a,b,k*2+2,(l+r)/2,r);
			return make_pair(min(vl.first,vr.first),max(vl.second,vr.second));
		}
	}

public:
	RMQ(int k){init(k);}
	void init(int k){
		for(size=1;size<k;)size<<=1;
		//size=1<<(32-__builtin_clz(k));
		minval=vector<int>(2*size-1,INF);
		maxval=vector<int>(2*size-1,-INF);
	}

	void update(int k,int t){
		k+=size-1;
		minval[k]=maxval[k]=t;
		while(k>0){
			k=(k-1)/2;
			minval[k]=min(minval[k*2+1],minval[k*2+2]);
			maxval[k]=max(maxval[k*2+1],maxval[k*2+2]);
		}
	}

	pair<int,int> query(int a,int b){
		return _query(a,b,0,0,size);
	}
};

int main(){
	int N,Q,c,x,y;
	scanf("%d%d",&N,&Q);
	RMQ rmq(N);
	for(;Q--;){
		scanf("%d%d%d",&c,&x,&y);
		if(c){
			pair<int,int>p=rmq.query(x,y+1);
			printf("%d\n",p.first);
		}else{
			rmq.update(x,y);
		}
	}
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=2e5+100;

int a[N];
map<int,int> dp[N][2];

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

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dp[0][0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=max(0ll,i/2-5);j<=min(i,i/2+5);j++)
        {
            int cur=-1e18;
            if(dp[i-1][0].count(j))
                cur=max(cur,dp[i-1][0][j]);
            if(dp[i-1][1].count(j))
                cur=max(cur,dp[i-1][1][j]);
            dp[i][0][j]=cur;
        }
        for(int j=max(0ll,i/2-5);j<=min(i,i/2+5);j++)
        {
            int cur=-1e18;
            if(dp[i-1][0].count(j-1))
                cur=max(cur,dp[i-1][0][j-1]+a[i]);
            dp[i][1][j]=cur;
        }
    }
    cout<<max(dp[n][0][n/2],dp[n][1][n/2]);
}


Measured memory_bytes: 298972
from heapq import heappop,heappush,heapify

n,m=map(int,input().split())

que=list(map(lambda x: -int(x),input().split()))
heapify(que)

while m:
    res=-heappop(que)
    res>>=1
    heappush(que,-res)
    m-=1

print(-sum(que))

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

int main(){
  int x; cin >>x;
  for(int i = 1;;i++){
    if(x*i%360==0){
      cout << i << endl;
      return 0;
    }
  }
  return 0; 
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    ll n; cin >> n;
    ll sum = 0, i = 0;
    while (sum < n)sum += ++i;
    eFOR(j, 1, i)if (j != sum - n)cout << j << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] a_b = sc.nextLine().split(" ");
        int a = Integer.parseInt(a_b[0]);
        int b = Integer.parseInt(a_b[1]);
        if (a == b) {
            System.out.println("a == b");
        } else if (a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a < b");
        }
    }
}


Measured memory_bytes: 26136
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int main() {
	int a, b, c;
	cin>>a>>b>>c;
	if(a+b+c>=22) puts("bust");
	else puts("win");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int d,N;
  cin >> d >> N;
  int counter = 0;
  int factor = 0;
  int ans = -1;
  if(d == 0){
    for(int i = 0; i < N; i++){
      factor++;
      while(factor % 100 == 0)factor++;
    }
    ans = factor;
  }else if(d == 1){
    for(int i = 0; i < N; i++){
      factor++;
      while(factor*100 % 10000 == 0)factor++;
    }
    ans = factor * 100;
  }else if(d == 2){
    for(int i = 0; i < N; i++){
      factor++;
      while(factor*10000 % 1000000 == 0)factor++;
    }
    ans = factor * 10000;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M;
ll A[100010],B[100010],Y[100010];
ll X[100010];
vector<vector<pair<int,ll>>> v(100010);
vector<pair<ll,int>> edges;
int p[100010] = {0},r[100010] = {0};
ll s[100010] = {0};
void init(int N){
	for(int i=0;i<=N;++i){
		p[i] = i;
		s[i] = X[i];
	}
}
 
int root(int a){
	if(p[a] == a) return a;
	return (p[a] = root(p[a]));
}
 
bool is_same_set(int a,int b){
	return root(a) == root(b);
}
 
void unite(int a, int b){
	a = root(a);
	b = root(b);
	if(a==b) return;
	if(r[a]<r[b]){
		p[a] = b;
		s[b] += s[a];
		s[a] = s[b];
	}else{
		p[b] = a;
		s[a] += s[b];
		s[b] = s[a];
		if(r[a] == r[b]) r[a]++;
	}
}
 
int visited[100010] = {},ans = 0;
void dfs(int n,int c){
	for(auto& a:v[n]){
		int b = a.first;ll id = a.second;
		if(visited[id]==0 && Y[id]<=c){
			visited[id] = 1; ans++;
			dfs(b,c);
		}
	}
}
 
int main(){
	cin >> N >> M;
	for(int i=1;i<=N;i++){
		cin >> X[i];
	}
	init(N);
	for(int i=1;i<=M;i++){
		cin >> A[i] >> B[i] >> Y[i];
		v[A[i]].push_back({B[i],i});
		v[B[i]].push_back({A[i],i});
		edges.push_back({Y[i],i});
	}
	sort(edges.begin(),edges.end());
	stack<int> S;
	for(auto& a:edges){
		int id = a.second;
		unite(A[id],B[id]);
		if(s[root(A[id])]>=Y[id]) S.push(id);
	}
	while(!S.empty()){
		int a = S.top(); S.pop();
		if(visited[a]==0) dfs(A[a],Y[a]);
	}
	cout << M-ans << endl;
}

Measured memory_bytes: 19184
N,M = map(int,input().split())
A = list(map(int,input().split()))
from collections import defaultdict
r = defaultdict(lambda:0)

s = 0
for i in range(N):
    s += A[i]
    s %= M
    r[s] += 1

ans = r[0]
for s in r:
    ans += (r[s]*(r[s]-1))//2

print(ans)

Measured memory_bytes: 14224
n, k = map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(n)]
l.sort()
l.append((0, k))
d = [l[0][1]]
for i in range(1,n+1):
    d.append(d[i-1] + l[i][1])
t = 0
while d[t] < k:
    t += 1
print(l[t][0])

Measured memory_bytes: 21524
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int a,b,k;
	cin>>a>>b>>k;

	a=a-k;

	if(a<0)
	{
		b-=abs(a);
		a=0;
	}

	if(b<0)
	{
		b=0;
	}

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

}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main(){
    string s;
    cin>>s;

    map<int,int> m;
    m[0]++;
    int mod=2019;

    int r=0;
    int k=1;

    for(int i=s.size()-1;i>=0;i--){
        r+=k*((int)s[i]-'0');
        r%=mod;
        //cout<<r<<endl;
        m[r]++;

        k*=10;
        k%=mod;
    }

    long long ans=0;
    for(auto p:m){
        int x=p.second;
        if(x>=2){
            //cout<<p.first<<endl;
            ans+=(x*(x-1)/2);
        }
    }

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

Measured memory_bytes: 3696
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;



int main()
{
	int n;
	while (cin >> n && n > 0)
	{
		vector<int> a = vector<int>(n);
		for (int i = 0; i < n; i++)
			cin >> a[i];

		vector<int> s = vector<int>(1, 0);
		bool f = true;
		bool plus = false;
		for (int i = 0; i < n; i++)
		{
			if (a[i] >= 0)
			{
				if (!f)
					f = true;
				if (!plus)
					plus = true;
				s[0] += a[i];
			}
			else if(s[0] > abs(a[i]))
			{
				if (f)
				{
					s.push_back(s[0]);
					f = false;
				}
				s[0] += a[i];
			}
			else
			{
				s[0] = 0;
			}

		}
		if (!plus)
		{
			int max = a[0];
			for (int i = 1; i < n; i++)
			{
				if (max < a[i])
					max = a[i];
			}
			cout << max << endl;
			continue;
		}
		for (int i = 1; i < s.size(); i++)
		{
			if (s[i] > s[0])
				s[0] = s[i];
		}
		cout << s[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

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


Measured memory_bytes: 256
N,L=map(int,input().split())
taste=[]
taste2=[]
tot=0
for i in range(1,N+1):
  taste.append((L+i-1))
  taste2.append(abs(L+i-1))
  tot+=L+i-1
index=taste2.index(min(taste2))
print(tot-taste[index])

Measured memory_bytes: 3060
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define all(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x,y)* mod_pow(kai(y,y), mod - 2, mod) % mod;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};
using pint=pair<int, int>;
int n;
vector<vector<pint>>v;
// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
	// i 人目の証言を検証する
	rep(i, n) {
		// i 人目が「不親切」だったら、証言はすべて無意味
		if(!(bit&(1<<i)))continue;
		for (pint xy : v[i]) {
			int x = xy.first;
			int y = xy.second;
			// y = 1 なのに「不親切」
			if (y == 1 && !(bit & (1 << x))) return false;
			// y = 0 なのに「正直者」だったらダメ
			if (y == 0 && (bit & (1 << x))) return false;
		}
	}
	return true;
}
signed main() {
	cin >> n;
	v.resize(n);
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		v[i].resize(a);
		for (int j = 0; j < a; ++j) {
			cin >> v[i][j].first >> v[i][j].second;
			v[i][j].first--; 
		}
	}
	int ans = 0;
	for (int bit = 0; bit < (1 << n); ++bit) {
		if (judge(bit)) {
			int cnt = 0;
			// bit に含まれる人数を数える
			rep(i, n) {
				if (bit & (1 << i))cnt++;
			}
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
def main(h,w):
    a = h * h + w * w
    ans = []
    for x in range(1,151):
        for y in range(x+1,151):
            if a <= x ** 2 + y ** 2:
                b = x ** 2 + y ** 2
                ans.append((b, x, y))
    ans.sort()
    for b, x, y in ans:
        if a < b or x > h:
            ans = [x, y]
            break
    print(" ".join(list(map(str,ans))))
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    main(h,w)


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

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

    if(abs(b-a) <= d && abs(c-b)<=d ) cout<<"Yes"<<endl;

    else if(abs(a-c) <= d) cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static long[] arr;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextLong() - (i + 1);
        }

        Arrays.sort(arr);

        long right = 1000000000;
        long left = -1000000000;
        while (Math.abs(left - right) > 2) {
            //System.err.println(left+" "+right);
            long midLeft = left + (right - left) / 3;
            long midRight = right - (right - left) / 3;
            long midLeftResult = calc(midLeft);
            long midRightResult = calc(midRight);
            if (midLeftResult > midRightResult) {
                left = midLeft;
            } else {
                right = midRight;
            }
        }
        // System.err.println(left+" "+right);
        System.out.println(calc(left + 1));
    }

    static long calc(long b) {
        long result = 0;
        for (long num : arr) {
            result += Math.abs(num - b);
        }
        return result;
    }
}


Measured memory_bytes: 88220
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXM = 202020;
vector<pii> G[3*MAXM];
map<pii, int> sid;
int lastId = 0;
int P[MAXM], Q[MAXM], C[MAXM];

int getid(int v, int c) {
    pii p(v, c);
    if (sid.find(p) != sid.end()) return sid[p];
    return sid[p] = lastId++;
}

void addEdge(int p, int q, int c) {
    int v = getid(p, c), u = getid(q, c);
    G[v].emplace_back(u, 0);
    G[u].emplace_back(v, 0);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> P[i] >> Q[i] >> C[i];
        P[i]--; Q[i]--;
        addEdge(P[i], Q[i], C[i]);
    }
    for (int i = 0; i < M; i++) {
        G[getid(P[i], C[i])].emplace_back(lastId+P[i], 1);
        G[getid(Q[i], C[i])].emplace_back(lastId+Q[i], 1);
        G[lastId + P[i]].emplace_back(getid(P[i], C[i]), 1);
        G[lastId + Q[i]].emplace_back(getid(Q[i], C[i]), 1);
    }
    const int INF = 1e9;
    vector<int> d(lastId+N, INF); d[lastId] = 0;
    priority_queue<pii> que;
    que.push(pii(0, lastId));
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        int u = p.second, dist = -p.first;
        if (dist > d[u]) continue;
        for (auto e : G[u]) {
            int v = e.first, c = e.second;
            if (d[v] > d[u]+c) {
                d[v] = d[u]+c;
                que.push(pii(-d[v], v));
            }
        }
    }
    int ans = d[lastId+N-1];
    if (ans == INF) ans = -1;
    else ans /= 2;
    cout << ans << endl;
    return 0;
}


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

vector<ll> divisor(ll n){
  vector<ll> div;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      div.push_back(i);
      if(i*i!=n){
        div.push_back(n/i);
      }
    }
  }
  return div;
}

int main(){
  ll N;
  cin >> N;
  auto v = divisor(N);
  //v.erase(unique(v.begin(), v.end()), v.end());
  ll ans=0;
  rep(i,v.size()){
    if(v[i]==1)continue;
    ll m = v[i]-1;
    if(N/m == N%m)ans += m;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
def main():
    import sys
    buf = sys.stdin.buffer

    class SegmentTree:
        def __init__(self, target, no_effect):
            target_size = len(target)
            leaves_size = 1
            while leaves_size < target_size:
                leaves_size *= 2
            self.tree_size = leaves_size * 2 - 1
            self.tree = [no_effect] * self.tree_size
            self.no_effect = no_effect
            self.initialize_tree(target)

        @classmethod
        def initialize_func(cls, value):
            return 1 << (ord(value) - ord('a'))

        @classmethod
        def merge_func(cls, a, b):
            return a | b

        def merge_child_data(self, node):
            child1 = node * 2 + 1
            child2 = node * 2 + 2
            merged = self.merge_func(self.tree[child1], self.tree[child2])
            return merged

        def initialize_tree(self, target):
            initial_leaf = self.tree_size // 2
            leaves = range(initial_leaf, initial_leaf+len(target))
            for value, leaf in zip(target, leaves):
                self.tree[leaf] = self.initialize_func(value)

            for parent in range(initial_leaf-1, -1, -1):
                self.tree[parent] = self.merge_child_data(parent)

        def update(self, new_value, index):
            leaf = self.tree_size//2 + index
            new_data = self.initialize_func(new_value)
            if self.tree[leaf] == new_data:
                return
            self.tree[leaf] = new_data

            parent = (leaf-1) // 2
            while parent >= 0:
                new_data = self.merge_child_data(parent)
                if self.tree[parent] == new_data:
                    break
                self.tree[parent] = new_data
                parent = (parent-1) // 2

        def resolve_query(self, _from, to):
            result = self.no_effect
            left, right = _from + self.tree_size//2, to + self.tree_size//2
            while left <= right:
                result = self.merge_func(result, self.tree[left])
                result = self.merge_func(result, self.tree[right])
                left //= 2
                right = right//2 - 1

            return bin(result).count('1')

    n, S, _, *queries = buf.read().split()
    S = S.decode()
    seg_tree = SegmentTree(target=S, no_effect=0)

    for type, a, b in zip(*[iter(queries)]*3):
        if type == b'1':
            index, new = int(a)-1, b
            seg_tree.update(new, index)

        elif type == b'2':
            _from, to = int(a)-1, int(b)-1
            print(seg_tree.resolve_query(_from, to))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62548
#include <iostream>
#include <vector>
using namespace std;
 
int n, m, q;
int dp[100000];
vector<int> v[100000];
 
void solve1(int p, int idx) {
    if (dp[p]<0) {
        dp[p]=idx;
        for (int i=0;i<v[p].size();i++) {
            solve1(v[p][i],idx);
        }
    }
}
 
void syoki(){
    int idx=0;
    for(int i=0;i<n;i++) {
        if(dp[i]<0) {
            solve1(i,idx++);
        }
    }
}
 
 
int main(){
    int s, t;
    cin>>n>>m;
    for (int i=0;i<m;i++){
        cin>>s>>t;
        v[s].push_back(t);
        v[t].push_back(s);
    }
    cin>>q;
    fill(dp,dp+n,-1);
    syoki();
    for(int j=0;j<q;j++){
        cin>>s>>t;
        if(dp[s]==dp[t]){
            cout<<"yes"<<endl;
        }
        else{
            cout<<"no"<<endl;
        }
    }
 
    return 0;
}


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

#define N 100

int pop(void);
void push(int);

int top,S[N];

int main(){
  int x,y;
  top = 0;
  char T[N];
  while(scanf("%s",T) != EOF){
    if(T[0] == '+'){
      x = pop();
      y = pop();
      push(x+y);
    }
    else if(T[0] == '-'){
      y = pop();
      x = pop();
      push(x-y);
    }
    else if(T[0] == '*'){
      x = pop();
      y = pop();
      push(x*y);
    }
    else{
      push(atoi(T));
    }
  }
  printf("%d\n",pop());

  return 0;
}

int pop(void){
  top--;
  return S[top+1];
}

void push(int z){
  S[++top] = z;
}

Measured memory_bytes: 548
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t,cnt,ans;
char a[maxn];
int main()
{
    int i,j;
    scanf("%s",a);
    for(i=0;a[i];i++)
    {
        if(a[i]=='g')
        {
            if(cnt)cnt--,ans++;
            else cnt++;
        }
        else
        {
            if(cnt)cnt--;
            else ans--,cnt++;
        }
    }
    printf("%d\n",ans);
    //system("Pause");
    return 0;
}


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

int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long ans = 0;
  ans = max({a*c, a*d, b*c, b*d});
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3644
program c
    implicit none
    real(16) :: A,B,H,M,ans,pi

    read(*,*) A,B,H,M

    ans = 0.0_16
    pi = 3.1415926535897932384_16
    ans = ans + (A*cos(pi*H/6.0_16 + pi*M/360.0_16) - B*cos(pi*M/30.0_16))**2
    ans = ans + (A*sin(pi*H/6.0_16 + pi*M/360.0_16) - B*sin(pi*M/30.0_16))**2
    ans = sqrt(ans)
	write(*,*) ans
    stop
end program c

Measured memory_bytes: 2980
#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)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m; cin >> n >> m;
    vector<string> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    bool exist = false;
    rep(i, n) {
        rep(j, n) {
            if (i+m-1>=n || j+m-1>=n) continue;
            bool match = true;
            rep(y, m) {
                rep(x, m) {
                    if(a[i+y][j+x] != b[y][x]) match = false;
                }
            }
            if (match) exist = true;
        }
    }
    if (exist) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc092/tasks/arc093_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <regex>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, sum = 0;
    vector<int16_t> v;
    cin >> n;

    // 先頭と末尾に0を追加
    v.push_back(0);
    for (int i = 0; i < n; i++) {
        cin >> m;
        v.push_back(m);
        sum += abs(v[i + 1] - v[i]);
    }
    sum += abs(v[n]);
    v.push_back(0);

    for (int i = 1; i <= n; i++) {
        if (v[i - 1] < v[i] && v[i] < v[i + 1] ||
            v[i - 1] > v[i] && v[i] > v[i + 1]) {
            cout << sum << "\n";
        } else if (abs(v[i] - v[i - 1]) < abs(v[i] - v[i + 1])) {
            cout << sum - 2 * abs(v[i] - v[i - 1]) << "\n";
        } else {
            cout << sum - 2 * abs(v[i] - v[i + 1]) << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 1532
# -*- coding: utf-8 -*-
N, K, S = map(int, input().split())

if S == 10 ** 9:
    ans_num = 10 ** 9 - 1
else:
    ans_num = 10 ** 9

print(" ".join([str(S) for _ in range(K)]) + " " + " ".join([str(ans_num) for _ in range(N - K)]))

Measured memory_bytes: 11288
package main

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

func isqrt(n int) int {
	if n < 0 {
		panic("isqrt argument must be nonnegative")
	}

	if n <= 1 {
		return n
	}

	ok := 0
	ng := 3037000500 // 3037000499 * 3037000499 < math.MaxInt64 < 3037000500 * 3037000500
	if n < ng {
		ng = n
	}
	for ng-ok > 1 {
		m := ok + (ng-ok)/2
		if m*m <= n {
			ok = m
		} else {
			ng = m
		}
	}
	return ok
}

func gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

func primeFactorize(n int) [][2]int {
	var result [][2]int
	for i := 2; i < isqrt(n)+1; i++ {
		if n%i != 0 {
			continue
		}
		t := [2]int{i, 0}
		for n%i == 0 {
			n /= i
			t[1]++
		}
		result = append(result, t)
	}
	if n != 1 {
		result = append(result, [2]int{n, 1})
	}
	return result
}

func main() {
	defer flush()

	A := readInt()
	B := readInt()

	println(len(primeFactorize(gcd(A, B))) + 1)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 1840
import sys
readline = sys.stdin.readline

# 残った数の中で最大の数とペアになれる（可能性のある）数は一意に決まる。
# 15に15以下の数を足して作れる2べきは16だけ、32は作れない。
# 8 * 2 < 15 * 2 < 16 * 2だから。
# 大きいほうから見ていって、ペアになれる数を特定出来たらペアにする。
# 以下を別々で持つ
# ・大きい順の管理
# ・探している数へのO(1)での到達と、残数管理（同じ数が複数回出てくる可能性があるため）

N = int(readline())
A = list(map(int,readline().split()))

from collections import defaultdict

balls_count = defaultdict(int) # 個数の管理

for a in A:
  balls_count[a] += 1

A = sorted(A, reverse = True)

def get_pair_num(x): # xとペアになれる数を探す
  tar = 2
  while tar < x:
    tar *= 2
  if tar == x:
    return tar
  return tar - x

ans = 0
for ball in A:
  if balls_count[ball] == 0: # すでに使用済みのボールである
    continue
  # 取り出した時点で、このあとペアにするか破棄するかのどちらかである。
  # 同じボールを取り出すことのないよう、この時点で1引いておく
  balls_count[ball] -= 1
  pair = get_pair_num(ball)
  if balls_count[pair] > 0:
    ans += 1
    balls_count[pair] -= 1

print(ans)

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

signed main(){
  string s;
  cin>>s;
  int n=s.size();
  int sa=0,sc=0,lq=0,rq=0;
  int a[111111],c[111111],l[111111],r[111111];
  int t[111111];
  t[0]=1;
  for(int i=1;i<111111;i++){
    t[i]=t[i-1]*3;
    t[i]%=MOD;
  }
  for(int i=0;i<n;i++){
    if(s[i]=='A')sa++;
    if(s[i]=='?')lq++;
    if(s[n-1-i]=='C')sc++;
    if(s[n-1-i]=='?')rq++;
    a[i]=sa;
    l[i]=lq;
    c[n-1-i]=sc;
    r[n-1-i]=rq;
  }
  int ans=0;
  for(int i=1;i<n-1;i++){
    if(s[i]=='B'||s[i]=='?'){
      int f=(s[i]=='?'?1:0);
      ans+=(((a[i]*c[i])%MOD)*t[lq-f])%MOD;
      ans%=MOD;
      ans+=(((a[i]*r[i+1])%MOD)*t[lq-f-1])%MOD;
      ans%=MOD;
      ans+=(((l[i-1]*c[i])%MOD)*t[lq-f-1])%MOD;
      ans%=MOD;
      ans+=(((l[i-1]*r[i+1])%MOD)*t[lq-f-2])%MOD;
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4736
package main

/*
明日から太郎君の夏休みが始まります。 太郎君は夏休みの計画を立てることにしました。
夏休みはN日からなります。各i(1 <= i <= N)について、i日目には太郎君は次の活動のうちひとつを選んで行います。
・A: 海で泳ぐ。幸福度a[i]を得る。
・B: 山で虫取りをする。 幸福度b[i]を得る。
・C: 家で宿題をする。 幸福度c[i]を得る。
太郎君は飽き性なので、2日以上連続で同じ活動を行うことはできません。
太郎君が得る幸福度の総和の最大値を求めてください。
*/

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

func main() {
	var N int
	fmt.Scanln(&N)

	a := make([]map[int]int, N)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := range a {
		mp := make(map[int]int)
		sc.Scan()
		mp[0], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		mp[1], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		mp[2], _ = strconv.Atoi(sc.Text())
		a[i] = mp
	}

	dp := make([]map[int]int, N+10)
	for i := range dp {
		dp[i] = map[int]int{0: 0, 1: 0, 2: 0}
	}

	for i := 0; i < N; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k {
					continue
				}
				dp[i+1][k] = max(dp[i+1][k], dp[i][j]+a[i][k])
			}
		}
	}
	fmt.Println(max(max(dp[N][0], dp[N][1]), dp[N][2]))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}


Measured memory_bytes: 42752
#include <iostream>

using namespace std;
int r,D,x;

int newx(int x){
  return r*x-D;
}

int main(){
  cin>>r>>D>>x;
  int old_x = x;
  for(int i=0;i<10;i++){
    int new_x1=0;
    new_x1 = newx(old_x);
    cout << new_x1 << endl;
    old_x = new_x1;
  }
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
long long mod = 1000000007;
 
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit (0);
}
void no() {
    cout << "No" << endl;
    exit (0);
}
 
 
int main() {
    long long h, n, sum = 0;
    cin >> h >> n;
    vector<int>as(n);
    for (int i = 0; i < n; i++){
        cin >> as[i];
        sum += as[i];
    }
    if (sum >= h){
        yes();
    }else{
        no();
    }
}

Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		Stack<String> stk=new Stack<>();
		boolean J=true;
		for(int i=0;i<n;i++) {
			String str=in.next();
			
			if(str.equals("A")) stk.push("A");
			else {
				if(stk.isEmpty()) {
					J=false;
					break;
				}
				else stk.pop();
			}
		}
		
		if(J && stk.isEmpty())System.out.println("YES");
		else System.out.println("NO");
	}

}



Measured memory_bytes: 26368
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;


int main(){
    ll n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n,x,t;
	cin>>n>>x>>t;
	
	cout<<((n+x-1)/x)*t<<endl;
	
	
	return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>

int search(int A[], int n, int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(){
  int i, n, A[10000 + 1], q, key, sum = 0;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++) scanf("%d", &A[i]);

  scanf("%d", &q);
  for(i = 0 ; i < q ; i++){
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 2144
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){
    int n,m;
    string s[110];
    string t[110];

    cin >> n ;
    rep(i,n) cin >> s[i];
    cin >> m;
    rep(i,m) cin >> t[i];

    int ans = 0;
    rep(i,n){
    int store = 0;
        rep(j,n) if(s[j] == s[i]) store++;
        rep(j,m) if(t[j] == s[i]) store--;
        ans = max(ans,store);
        }

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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
static private Scanner s = new Scanner(System.in);
static Node root = null;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
	int n = s.nextInt();
	String str = new String();

	 for(int i = 0;i < n;i++) {
	 str = s.next();
		 if(str.equals("insert")) {
		 Insert(s.nextInt());
		 }else if(str.equals("find")){
			 if(find(root,s.nextInt())) {
				 sb.append("yes\n");
			 }else{
				 sb.append("no\n");
			 }
		 }else if(str.equals("print")){
				 inorder(root);
				 sb.append("\n");
				 preorder(root);
				 sb.append("\n");
			 }
		 }
	 System.out.print(sb);
}

Node mins(int n,Node[] a) {
	Node min = a[0];
	for(int i = 1;i < n;i++) {
		if(min.key > a[i].key) {

		}
	}
	return min;
}

static void Insert(int k) {
	Node y = null;
	Node x = root;
	Node z = new Node();

	z.key = k;
	z.l = null;
	z.r = null;
	while(x != null) {
		y = x;
		if(z.key < x.key) {
			x = x.l;
		}else {
			x = x.r;
		}
	}
	z.parent = y;
	if(y == null) {
		root = z;
	}else if(z.key < y.key) {
		y.l = z;
	}else {
		y.r = z;
	}
}

static void preorder(Node a) {
		if(a ==null)return;
		sb.append(" " + a.key);
		preorder(a.l);
		preorder(a.r);
}

static void inorder(Node a) {
		if(a == null) return;
		inorder(a.l);
		sb.append(" " + a.key);
		inorder(a.r);
}

static boolean find(Node a,int k) {
	while(a != null) {
		if(k == a.key)
		return true;
	if(k < a.key) {
		a = a.l;
	}else {
		a = a.r;
	}
	}
	return false;
}
}

class Node{
	int key;
	Node l = null;
	Node r = null;
	Node parent;


	Node(){
	}
}




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

int main() {
int H,N;
  cin >> H >> N;
  int a;
  if(H%N == 0){
  	a = 0;
  }
  else{
  	a = 1;
  }
  cout << H / N  + a<< endl;
}

Measured memory_bytes: 256
N, X = map(int, input().split())

# レベルLバーガーの厚さ, レベルLバーガーに含まれるパティの数
thick, patti = [1], [1]
for i in range(N):
    thick.append(2 * thick[-1] + 3)
    patti.append(2 * patti[-1] + 1)


def solve(n, x):
    if n == 0:
        return 0 + (x >= 1)

    # レベルL-1バーガー
    elif x <= 1 + thick[n - 1]:
        return solve(n - 1, x - 1)

    # 2つ目のレベルL-1バーガーにかかる
    else:
        return patti[n - 1] + 1 + solve(n - 1, x - 1 - thick[n - 1] - 1)


print(solve(N, X))


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
static const int MAXN = 1e5 + 4;

int n;
char s[MAXN];

inline bool unbalanced(char a, char b, char c)
{
    return (a == b || a == c || b == c);
}

int main()
{
    scanf("%s", s); n = strlen(s);

    if (n == 2) {
        if (s[0] == s[1]) puts("1 2"); else puts("-1 -1");
    } else {
        for (int i = 2; i < n; ++i) {
            if (unbalanced(s[i - 2], s[i - 1], s[i])) {
                printf("%d %d\n", i - 1, i + 1); return 0;
            }
        }
        puts("-1 -1");
    }

    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <string>
using namespace std;
 
int main(){
  string S;
  int hug=0;
  int len;
  
  cin >> S;

  len = S.length();
  
  for(int i=0; i<(int)(len/2); i++){
    
    if(S[i] != S[len-1-i]) hug++;
    
  }
      
  
  cout << hug;
  
 return 0;
  
}

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

int main(){
    int N, K;
    cin >> N >> K;
    
    int x[N];
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> x[i];
        if(abs(x[i] - K) >= abs(x[i] - 0)){
            sum += abs(x[i] - 0) * 2;
        }else{
            sum += abs(x[i] - K) * 2;
        }
    }
    
    cout << sum << endl;
    

    
}

Measured memory_bytes: 256