akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		if (n + m == 0) return false;

		int[] s = new int[n];
		int ssum = 0;
		for (int i=0; i<n; i++) {
			s[i] = in.nextInt();
			ssum += s[i];
		}

		int[] t = new int[m];
		int tsum = 0;
		for (int i=0; i<m; i++) {
			t[i] = in.nextInt();
			tsum += t[i];
		}

		int max = Integer.MAX_VALUE;
		int sans = -1, tans = -1;

		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				if (ssum - s[i] + t[j] == tsum - t[j] + s[i]) {
					if (max > s[i] + t[j]) {
						max = s[i] + t[j];
						sans = s[i];
						tans = t[j];
					}
				}
			}
		}

		out.println(max != Integer.MAX_VALUE ? sans+" "+tans : -1);

		return true;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 29852
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
	sys.stdin = open(name)

s = input()

if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 61848
import sys

N = int(input())
h = list(map(int, input().split()))
c = 1
if 0 in h:
    print(0)
    sys.exit()
for i in range(0, len(h)):
    c *= h[i]
    if c > 10**18:
        print(-1)
        sys.exit()
print(c)

Measured memory_bytes: 21792
N,M=map(int,input().split())
A=['.' for _ in range(N)]
B=['.' for _ in range(M)]
for i in range(N):
    A[i]=list(input())
for i in range(M):
    B[i]=list(input())
Ans=False
for i in range(N-M+1):
    for j in range(N-M+1):
        tmp=True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    tmp=False
        if tmp==True:
            Ans=True
if Ans==True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 40688
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<cstdlib>
using namespace std;
typedef long long ll;

char s[200005];
int pos[200005];

int main(){
	scanf("%s", s);
	int len = strlen(s);
	int sum = 0;
	int cnt = 0;
	ll ans = 0;
	memset(pos, -1, sizeof(pos));
	for(int i = 0; i <= len - 1; i++){
		if(s[i] == 'B') cnt++;
		if(s[i] == 'W') {
			sum++;
			pos[sum] = cnt;
			ans = pos[sum] + ans;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++)cin >> a[i];
    int sum = 1;
    for(int i = 1;i < n;i++){
        bool check = true;
        for(int j = 0;j < i;j++){
            if(a[j] > a[i])check = false;
        }
        if(check == true)sum++;
    }
    cout << sum;
}

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

void solve(){
    int n,w;
    cin>>n>>w;
    int sum=0;
    vector<int> value(n),weight(n);
    for(int i=0;i<n;i++){cin>>weight[i]>>value[i];sum+=value[i];}
    vector<ll> dp(sum+1,INT_MAX);
    int ans=0;
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=sum-value[i];j>=0;j--){
            dp[j+value[i]]=min(dp[j+value[i]],dp[j]+weight[i]);
        }
    }
    for(int i=sum;i>=0;i--){
        if(dp[i]<=w){
            cout<<i;
            return;
        }
    }
    return;
    
    
}

int main() {
	// your code goes here
	//freopen("inptmp0.txt","r",stdin);
	int T;
	
	//cin>>T;
	T=1;
	while(T--){
	    solve();
	}
	return 0;
}


Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=53,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<vector<int>> can(N,vector<int>(31));
        vector<set<int>> SE(N);
        
        for(int i=0;i<N;i++){
            int a;cin>>a;
            for(int j=0;j<a;j++){
                int b;cin>>b;
                can[i][b]=1;
            }
            SE[i].insert(i);
        }
        
        int ans=INF;
        
        for(int j=0;j<=30;j++){
            vector<set<int>> to(N);
            for(int i=0;i<N;i++){
                if(can[i][j]){
                    for(int k=0;k<N;k++){
                        if(can[k][j]){
                            for(auto it=SE[k].begin();it!=SE[k].end();it++){
                                to[i].insert(*it);
                            }
                        }
                    }
                }else to[i]=SE[i];
            }
            
            for(int i=0;i<N;i++){
                SE[i]=to[i];
                if(SE[i].size()==N) ans=min(ans,j);
            }
        }
        
        if(ans==INF) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
}







Measured memory_bytes: 3240
#include <stdio.h>
#include <math.h>

long gcd(long a, long b);
long lcm(long a, long b);

int main(void){
    long a,b;
    long g,l;

    while(1){
        a = -1;
        scanf("%ld %ld", &a, &b);
        if(a == -1)break;

        g = gcd(a, b);
        l = lcm(a, b);

        printf("%ld %ld\n", g, l);
        
    }

    return 0;
}

long gcd(long a, long b) {
  long v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  };
  return v1;
}

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

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int tree[N][30],cnt[30],n;
inline int lowbit(int x){return (x&(-x));};
void update(int x,int y,int num)
{
	while(x<=n)
	{
		tree[x][y]+=num;
		x+=lowbit(x);
	}
	return;
}
void ask(int x,bool ty)
{
	while(x)
	{
		for(int i=0;i<26;i++)if(ty)cnt[i]+=tree[x][i];else cnt[i]-=tree[x][i];
		x-=lowbit(x);
	}
}
int q;string s;
int main()
{
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++)
		update(i+1,s[i]-'a',1);
	cin>>q;
	while(q--)
	{
		int ty,a,b;
		cin>>ty>>a;
		if(ty==1)
		{
			char c;
			cin>>c;
			update(a,s[a-1]-'a',-1);
			update(a,c-'a',1);
			s[a-1]=c;
		}
		else
		{
			cin>>b;
			for(int i=0;i<26;i++)cnt[i]=0;
			ask(b,1);
			ask(a-1,0);
			int ans=0;
			for(int i=0;i<26;i++)if(cnt[i])ans++;
			cout<<ans<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 59524
#include<bits/stdc++.h>
using namespace std;
#define N 1111116

int n,l,t,x[N],w[N],cnt;

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();l=read();t=read();
	for (int i=0;i<n;i++) x[i]=read(),w[i]=read();
	for (int i=0;i<n;i++){
		x[i]+=(w[i]==1)?t:-t;
		cnt=(cnt+x[i]/l)%n;x[i]%=l;
		if (x[i]<0) cnt--,x[i]+=l;
	}	
	sort(x,x+n);
	for (int i=0;i<n;i++)
		printf("%d\n",x[((i+cnt)%n+n)%n]);
	return 0;
}

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

using namespace std;

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

  vector<vector<long long>> dp(n, vector<long long>(16));
  vector<vector<long long>> dp2(n, vector<long long>(16));
  for (int i = 0; i < 16; i++) {
    dp[n - 1][i] = i;
    dp2[0][i] = i;
  }

  for (int i = n - 2; i >= 0; i--) {
    long long j1 = 0;
    long long j2 = 0;
    long long c1 = a[i];
    long long c2 = a[i + 1];
    while (c1 <= c2 && j1 < 16) {
      dp[i][j1] = dp[i + 1][0] + j1;
      c1 *= 4;
      j1++;
    }
    while (j2 < 16 && c2 < c1) {
      c2 *= 4;
      j2++;
    }
    while (j1 < 16) {
      if (j2 > 15) {
        dp[i][j1] = dp[i + 1][15] + (j2 - 15) * (n - 1 - i) + j1;
      }
      else {
        dp[i][j1] = dp[i + 1][j2] + j1;
      }
      j1++;
      j2++;
    }
  }

  for (int i = 1; i < n; i++) {
    long long j1 = 0;
    long long j2 = 0;
    long long c1 = a[i];
    long long c2 = a[i - 1];
    while (c1 <= c2 && j1 < 16) {
      dp2[i][j1] = dp2[i - 1][0] + j1;
      c1 *= 4;
      j1++;
    }
    while (j2 < 16 && c2 < c1) {
      c2 *= 4;
      j2++;
    }
    while (j1 < 16) {
      if (j2 > 15) {
        dp2[i][j1] = dp2[i - 1][15] + (j2 - 15) * i + j1;
      }
      else {
        dp2[i][j1] = dp2[i - 1][j2] + j1;
      }
      j1++;
      j2++;
    }
  }

  long long ans = 2 * dp[0][0];
  for (int i = 1; i < n; i++) {
    long long steps = dp[i][0] * 2 + dp2[i - 1][0] * 2 + i;
    ans = min(ans, steps);
  }
  cout << ans;
}


Measured memory_bytes: 66688
#include<iostream>
using namespace std;
char a[57][57];
int x,y,b[57][57];
int main(){
    cin>>x>>y;
    for(int i=0;i<x;i++) cin>>a[i];
    for(int i=0;i<x;i++)
    	for(int j=0;j<y;j++)
    		if(a[i][j]=='#')  
			{
				b[i][j]++;
				b[i][j+1]++;
				b[i][j+2]++;
				b[i+1][j]++;
				b[i+1][j+1]++;
				b[i+1][j+2]++;
				b[i+2][j]++;
				b[i+2][j+1]++;
				b[i+2][j+2]++;
			}	
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++)
        if(a[i][j]=='#') cout<<'#';
        else cout<<b[i+1][j+1];
        cout<<endl;
    }

}

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

int v[100005], suff[100005], pref[100005];

int main(){

    int n; cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    for(int i = n; i >= 1; i--)
        suff[i] = suff[i+1] + abs(v[i+1]-v[i]);
    for(int i = 1; i <= n; i++)
        pref[i] = pref[i-1] + abs(v[i]-v[i-1]);

    for(int i = 1; i < n; i++){
        int res = pref[i-1] + suff[i+1] + abs(v[i+1]-v[i-1]);
        cout << res << endl;
    }
    cout << pref[n-1] + abs(v[n-1]) << endl;
    
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;

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

  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
  
}


Measured memory_bytes: 764
#include <cstdio>
#include <algorithm>

using namespace std;

int h[100000];
int dp[100000];

int main() {
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &h[i]);
    
    for (i = 0; i < n; i++) dp[i] = 1e9;
    
    dp[0] = 0;
    
    for (i = 0; i < n - 1; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    
    printf("%d\n", dp[n - 1]);
    
    return 0;
}


Measured memory_bytes: 896
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
//long long int c=0;
int main()
{
    string s;
    cin>>s;
    string res;
    if(s[s.length()-1]=='s')
    {
        res=s.substr(0,s.length())+"es";
        
    }
    else
    res=s+"s";
    //cout<<s.substr(0,s.length()-1);
    cout<<res;
}


Measured memory_bytes: 3584
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
	LL N, T, A;
	cin >> N;
	cin >> T >> A;
	vector<double> H, S;
	H.resize(N);
	S.resize(N);
	REP(i, N) {
		LL X;
		cin >> X;
		H[i] = (double)T - ((double)X * 0.006);
		S[i] = abs((double)A - H[i]);
	}

	double m = INF;
	int index = -1;
	REP(i, N) {
		if (S[i] < m) {
			m = S[i];
			index = i;
		}
	}
	cout << index + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 9999999
#define MAX 101

int main(){
    int n,m,s,g1,g2,d[MAX+1][MAX+1],a,b,c;
    while(cin >> n >> m >> s >> g1 >> g2 , n+m+s+g1+g2){
        fill(d[0],d[MAX],INF);
        for(int i = 0 ; i < m ; i++){
            cin >> a >> b >> c;
            d[a][b] = c;
        }
        
        for(int k = 1 ; k <= n ; k++)
            for(int i = 1 ; i <= n ; i++)
                for(int j = 1 ; j <= n ; j++)
                    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
        
        int res = INF;
        for(int i = 1 ; i <= n ; i++){
            d[i][i] = 0;
            res = min(res,d[s][i]+d[i][g1]+d[i][g2]);
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define rep(i, n) reps(i, 0, n)
using namespace std;
using ll = long long;

map<int64_t,int > mp;

map<int64_t, int> prime_factor(int64_t n)
{
    map<int64_t, int> ret;
    for (int64_t i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

int main()
{
    int n=0;
    cin >> n;

    reps(i,2,n+1){
        for(auto p : prime_factor(i)){
            mp[p.first] += p.second;
        }
    }
    int v3=0,v5=0,v15=0,v25=0,v75=0;

    for(auto p : mp){
        if(p.second+1 >= 75) v75++;
        if(p.second+1 >= 25) v25++;
        if(p.second+1 >= 15) v15++;
        if(p.second+1 >= 5)  v5++;
        if(p.second+1 >= 3)  v3++;
    }

    int ans = 0;
    ans += v75;
    ans += v25 * (v3-1);
    ans += v15 * (v5-1);
    ans += (v3-2) * (v5-1) * (v5)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());


int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    vector<int> cont[m];
    int k;
    int s;
    for(int i = 0 ; i < m ; i ++ ){
        cin >> k;
        for(int j = 0 ; j < k ; j ++ ){
            cin >> s;
            -- s;
            cont[i].push_back(s);
        }
    }
    int p[n];
    for(int i = 0 ; i < m; i ++ )
        cin >> p[i];
    bool ok;
    int check;
    int res = 0;
    for(int i = 0 ; i < (1 << n);  i ++ ){
        ok = true;
        for(int j = 0 ; j < m ; j ++ ){
            check = 0;
            for(auto p : cont[j]){
                if(i & (1 << p)){
                    check ^= 1;
                }
            }
            if(check != p[j])
                ok = false;
        }
        if(ok)
            res ++ ;
    }
    cout << res;
    return 0;
}

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


int main()
 {
	int a,b,m;
	cin>>a>>b>>m;
	int arr[a],brr[b];
	for(int i=0;i<a;i++)
		cin>>arr[i];
	for(int i=0;i<b;i++)
		cin>>brr[i];

    int min1=INT_MAX;
    for(int i=0;i<m;i++)
    {
    	int x1,y1,c1;
    	cin>>x1>>y1>>c1;
    	min1=min(min1,arr[x1-1]+brr[y1-1]-c1);
    }
    sort(arr,arr+a);sort(brr,brr+b);
    min1=min(min1,arr[0]+brr[0]);
    cout<<min1<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long N, A[1 << 18], B[1 << 18], C[1 << 18], sum, cnt; vector<long long>X;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		if (A[i] >= B[i]) X.push_back(A[i] - B[i]);
		else { sum += (B[i] - A[i]); cnt++; }
	}
	sort(X.begin(), X.end()); reverse(X.begin(), X.end());
	for (int i = 0; i < X.size(); i++) {
		if (sum > 0) { sum -= X[i]; cnt++; }
	}
	if (sum > 0) cnt = -1;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 5496
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    bool x;
    cin>>x;
    cout<<!x<<endl;
    return 0;
}

Measured memory_bytes: 3648
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

immutable long mod = 10^^9 + 7;
int n;
int[] t, a;

void main() {
    scan(n);
    t = readln.split.to!(int[]);
    a = readln.split.to!(int[]);

    auto L = new int[](n);
    auto H = new int[](n);

    L[0] = H[0] = t[0];

    foreach (i ; 1 .. n) {
        if (t[i - 1] < t[i]) {
            L[i] = H[i] = t[i];
        }
        else {
            L[i] = 1;
            H[i] = t[i];
        }
    }

    if (!(L[n - 1] <= a[n - 1] && a[n - 1] <= H[n - 1])) {
        writeln(0);
        return;
    }

    L[n - 1] = H[n - 1] = a[n - 1];

    foreach_reverse (i ; 0 .. n - 1) {
        if (a[i] > a[i + 1]) {
            if (L[i] <= a[i] && a[i] <= H[i]) {
                L[i] = H[i] = a[i];
            }
            else {
                writeln(0);
                return;
            }
        }
        else {
            if (L[i] == H[i]) {
                if (H[i] > a[i]) {
                    writeln(0);
                    return;
                }
            }
            else {
                H[i] = min(H[i], a[i]);
            }
        }
    }

    long ans = 1;

    foreach (i ; 0 .. n) {
        (ans *= (H[i] - L[i] + 1)) %= mod;
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 8392
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

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



Measured memory_bytes: 1024
/*
 * stable sort check
 *
 */

#include <stdio.h>
#define MAX 36

typedef struct{
    char type;
    int number;
}Card;

int main(void){
    int n;
    scanf("%d", &n);

    int i, j, key_num, k;
    char c, key_type;
    Card card_b[n], card_s[n];
    for(i=0;i<n;i++){
        scanf(" %c%d", &c, &k);
        card_b[i].type = card_s[i].type = c;
        card_b[i].number = card_s[i].number = k;
    }

    //Bubble Sort Algo
    for(i=0; i<=n-1; i++){
        for(j=n-1; j>=i+1; j--){
            if(card_b[j].number < card_b[j-1].number){
                key_num = card_b[j].number;
                key_type = card_b[j].type;
                card_b[j].number = card_b[j-1].number;
                card_b[j].type = card_b[j-1].type;
                card_b[j-1].number = key_num;
                card_b[j-1].type = key_type;
            }
        }
    }

    for(i=0;i<n-1;i++){
        printf("%c%d ", card_b[i].type, card_b[i].number);
    }
    printf("%c%d\n", card_b[n-1].type, card_b[n-1].number);
    printf("Stable\n");
    

    int minj;
    //Selection Sort Algo
    for(i=0; i<=n-2; i++){
        minj = i;
        for(j=i; j<=n-1; j++){
            if(card_s[j].number < card_s[minj].number){
                minj = j;
            }
        }

        if(minj != i){
            key_num = card_s[i].number;
            key_type = card_s[i].type;
            card_s[i].number = card_s[minj].number;
            card_s[i].type = card_s[minj].type;
            card_s[minj].number = key_num;
            card_s[minj].type = key_type;
        }
    }

    int isStable = 1;
    for(i=0;i<n-1;i++){
        printf("%c%d ", card_s[i].type, card_s[i].number);
        if(card_s[i].type != card_b[i].type && card_s[i].number == card_b[i].number){
            isStable = 0;
        }
    }
    printf("%c%d\n", card_s[n-1].type, card_s[n-1].number);
    printf(isStable ? "Stable\n" : "Not stable\n");

    return 0;

}

Measured memory_bytes: 2740
n,m = map(int,input().split())
l = [[] for i in range(n)]
sc = [0]*n
  
for i in range(n-1):
  x,y = map(int, input().split())
  l[x-1].append(y-1)
  l[y-1].append(x-1)

for i in range(m):
    p,x = map(int,input().split())
    sc[p-1] += x

from collections import deque
d=deque()
d.append(0)
t = [False]*(n)
t[0] = True

while d:
    a = d.popleft()
    for b in l[a]:
      if not t[b]:
          t[b] = True
          d.append(b)
          sc[b] += sc[a]

print(*sc)

Measured memory_bytes: 56160
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        if (N == 1) {
            Console.WriteLine("Hello World");
            return;
        }
        int A = int.Parse(Console.ReadLine());
        int B = int.Parse(Console.ReadLine());
            Console.WriteLine(A + B);
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;

char s[100][100];
int dist[100][100];

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  int cnt = 0;
  for(int i=0;i<=w+1;i++){
    s[0][i] = 'N';
    s[h+1][i] = 'N';
  }
  for(int i=0;i<=h+1;i++){
    s[i][0] = 'N';
    s[i][w+1] = 'N';
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> s[i][j];
      if(s[i][j] == '#') cnt++;
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) dist[i][j] = -1;
  }
  // bread first search
  queue<pair<int, int> > Q;
  Q.push(make_pair(1, 1));
  dist[1][1] = 1;
  while(!Q.empty()){
    auto p = Q.front(); Q.pop();
    int x = p.first, y = p.second;
    if(x == h && y == w) break;
    // check adjacent node
    if(s[x-1][y] == '.' && dist[x-1][y] == -1){
      dist[x-1][y] = dist[x][y] + 1;
      Q.push(make_pair(x-1, y));
    }
    if(s[x+1][y] == '.' && dist[x+1][y] == -1){
      dist[x+1][y] = dist[x][y] + 1;
      Q.push(make_pair(x+1, y));
    }
    if(s[x][y-1] == '.' && dist[x][y-1] == -1){
      dist[x][y-1] = dist[x][y] + 1;
      Q.push(make_pair(x, y-1));
    }
    if(s[x][y+1] == '.' && dist[x][y+1] == -1){
      dist[x][y+1] = dist[x][y] + 1;
      Q.push(make_pair(x, y+1));
    }
  }
  // confirm
  /*
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) cout << dist[i][j] << endl;
  }
  */
  if(dist[h][w] == -1){
    cout << -1 << endl;
  }else{
    cout << h*w - dist[h][w] - cnt << endl;
  }
}

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())


void solve(ll N, ll M, vector<ll> a, vector<ll> b){
    vector<pair<ll, ll>> P;
    rep(i, M) {
        P.push_back(make_pair(a[i], b[i]));
    }
    sort(P.begin(), P.end());
    ll ans = 0;
    ll lcur = P[0].first;
    ll rcur = P[0].second;
    rep(i, M) {
        if (P[i].first >= rcur) {
            ans++;
            lcur = P[i].first;
            rcur = P[i].second;
        } else {
            lcur = P[i].first;
            rcur = min(rcur, P[i].second);
        }
        // cout << lcur << " " << rcur << endl;
    }
    cout << ans + 1 << endl;
}

int main() {
  ll N;
    scanf("%lld",&N);
    ll M;
    scanf("%lld",&M);
    vector<ll> a(M);
    vector<ll> b(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
  solve(N, M, move(a), move(b));
  return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <assert.h>
#include <unordered_map>

using namespace std;

const int maxN = 1e5 + 10;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define F first
#define S second
#define PB push_back
#define LL long long
#define BIT(x, i) ((x >> i) & 1)
#define PINT pair < int, int >
#define MP make_pair

int n, a[maxN], res;

int main() {
    cin >> n;
    FORU(i, 1, n) cin >> a[i];
    int p = 0;
    FORU(i, 1, n)
        if (a[i] == i) {
            if (p) p = 0;
            else ++res, p = 1;
        }
        else p = 0;
    cout << res;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n,i;
long long a[2000001],b[2000001],c[2000001];
long long dp[200000][3];
main(){
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
    for(i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
    }
    cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;
}

Measured memory_bytes: 12544
N,K=map(int,input().split())
a=[int(i) for i in input().split()]
b=[max([a[i],0]) for i in range(N)]
S=[0 for i in range(N+1)]
T=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+a[i]
    T[i+1]=T[i]+b[i]
ans=-10**15
for i in range(N-K+1):
    tmp=T[N]+S[i+K]-T[i+K]+T[i]-S[i]
    if ans<tmp:
        ans=tmp
for i in range(N-K+1):
    tmp=T[N]
    M=T[i+K]-T[i]
    tmp-=M
    if ans<tmp:
        ans=tmp
print(ans)



Measured memory_bytes: 17668
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	int sum = z, cnt = 0;
	while (true) {
		sum += z;
		sum += y;
		cnt++;
		if (sum >= x) {
			break;
		}
	}
	if (sum > x) cnt--;
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int ans=0;
  int count=0;
  char x = s[0];
  for(int i=1; i<s.size(); i++){
    if(x==s[i]){
      count++;
      ans = max(ans,count);
    }else{
      count=0;
      x=s[i];
    }
  }
  
  if(ans>=2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<vector<ll>> pascals_triangle(int n) {
    vector<vector<ll>> combi(n + 1, vector<ll>(n + 1));
    REP(i, n + 1) REP(j, i + 1) {
        if (j == 0 || j == i) combi[i][j] = 1LL;
        else combi[i][j] = combi[i - 1][j - 1] + combi[i - 1][j];
    }
    return combi;
}

ll gcd(ll m, ll n) {
    return n != 0 ? gcd(n, m % n) : m;
}

ll lcm(ll m, ll n) {
    // If both m and n are large numbers, the result is overflow without parentheses.
    return m * (n / gcd(m, n));
}

void solve() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    REP(i, h) {
        REP(j, w) {
            if (i < b and j < a or i >= b and j >= a) cout << "0";
            else cout << "1";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
module Main where

import Data.Int


data Mod = Mod Int64 

instance Show Mod where
        show (Mod a) = show a


instance Num Mod where
        (+) (Mod a) (Mod b) = Mod $ (a + b) `mod` (10^9 + 7)
        (*) (Mod a) (Mod b) = Mod $ (a * b) `mod` (10^9 + 7)
        abs (Mod a) = Mod $ abs a
        signum (Mod a) = Mod $ signum a
        fromInteger = Mod . fromInteger
        negate (Mod a) = Mod . negate $ a

ans :: [Mod] -> Mod
ans
        = snd 
        . foldr 
                (\x (xsSum, totSum) -> (x + xsSum, totSum + x * xsSum)) 
                (Mod 0, Mod 0)


main :: IO ()
main = interact
        $ (++ "\n")
        . show
        . ans
        . map (Mod . read)
        . words
        . (!! 1)
        . lines
 


Measured memory_bytes: 153068
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int LEN = 100005;

struct p {
    char name[100];
    int t;
}Q[LEN];

int head, tail, n;

void enqueue(p x);
p dequeue();

int main()
{
    int elaps = 0, c;
    int q;
    p u;
    scanf("%d %d", &n, &q);

    for (int i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;

    while (head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t > 0) enqueue(u);
        else
            printf("%s %d\n", u.name, elaps);
    }

    return 0;
}

void enqueue(p x)
{
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

p dequeue()
{
    p x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

Measured memory_bytes: 12708
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<bitset>


using namespace std;

#define endl "\n"

constexpr long long INF = (long long)1e9;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	constexpr int num = 26;
	string s;
	int N;
	int con = 0, ans = 0;
	map<int,int> mp;
	
	cin>>s;
	
	N = s.size();
	
	mp[0] = 0;
	
	for(int i = 0; i < N; i++){
		con ^= (1<<(s[i] - 'a'));
		int minimum = INF;
		
		for(int j = 0; j < num; j++){
			int hoge = con ^ (1<<j);
			
			if(mp.count(hoge)) {
				minimum = min(mp[hoge] + 1, minimum);
			}
		}
		
		if(mp.count(con)) {
			minimum = min(mp[con] + 1, minimum);
			mp[con] = min(mp[con], minimum);
		} else {
			mp[con] = minimum;
		}
		ans = minimum;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 9876
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;


import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			long[] as = new long[N];
			for(int i = 0; i < N; i++) {
				as[i] = sc.nextLong();
			}
			
			boolean hasZero = false;
			for(int i = 0; i < N; i++) {
				hasZero |= as[i] == 0;
			}
			
			double x = 0;
			for(int i = 0; i < N; i++) {
				x += Math.log10(as[i]);
			}
			
			if(hasZero) {
				System.out.println(0);
			}else if(x >= 18 + 1e-10) {
				System.out.println(-1);
			}else {
				long mult = 1;
				for(int i = 0; i < N; i++) {
					mult *= as[i];
				}
				
				if(mult <= 1000000000000000000l) {
					System.out.println(mult);
				}else {
					System.out.println(-1);
				}
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 48652
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll y[101010];
ll a[201010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

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

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

    }

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

int main(){
    cin>>N;
    ans=0;
    rep(i,0,N+1){
        ll num=i;
        ll tmp=0;
        while(num>=1){
            num/=10;
            tmp++;
        }
        if(tmp %2==1){
            ans++;
        }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
using namespace std;

const unsigned long long BASE = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

int priceA[100001], priceB[100001];

int main()
{
    int a, b, m;
    cin >> a >> b >> m;
    int minA = 200000, minB = 200000;
    FROM_0(i, a)
    {
        cin >> priceA[i];
        minA = min(minA, priceA[i]);
    }
    FROM_0(i, b)
    {
        cin >> priceB[i];
        minB = min(minB, priceB[i]);
    }
    int minPrice = minA + minB;
    FROM_0(i, m)
    {
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        int price = priceA[x] + priceB[y] - c;
        minPrice = min(price, minPrice);
    }
    cout << minPrice << endl;

    return 0;
}


Measured memory_bytes: 4392
S = input()
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
ans = 'Yes'
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] not in odd:
            ans = 'No'
            break
    else:
        if S[i] not in even:
            ans = 'No'
            break
print(ans)

Measured memory_bytes: 3060
n = int(input())
table = [0] * (n + 1)
divider = 2
cnt = 0
able3 = 0
able5 = 0
able15 = 0
able25 = 0
able75 = 0


def nCr(n, r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
    return numerator // denominator


for i in range(1, n + 1):
    while True:
        if i == 1:
            divider = 2
            break
        elif i % divider == 0:
            table[divider] += 1
            i //= divider
        else:
            divider += 1

for i in table:
    if 2 <= i:
        able3 += nCr(2, i)
    if 4 <= i:
        able5 += nCr(4, i)
    if 14 <= i:
        able15 += nCr(14, i)
    if 24 <= i:
        able25 += nCr(24, i)
    if 74 <= i:
        able75 += nCr(74, i)

cnt += (able5 - 1) * able15  # 5 * 25
cnt += (able3 - 2) * (able5 - 1) * able5 // 2  # 3 * 5 * 5
cnt += (able3 - 1) * able25  # 25 * 3
cnt += able75  # 75
print(cnt)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 300005
#define LOG 10
#define M (N-5)
#define inf 1000000000
#define MOD 1000000007
using namespace std;

int main() {

	int n;

	scanf("%d",&n);

	int cnt[3]={0};
	int ans=1;

	for(int i=1;i<=n;i++) {

		int x;

		scanf("%d",&x);

		int t=0;

		for(int j=0;j<3;j++) t+=(cnt[j]==x);

		ans=(ll)ans*t%MOD;

		for(int j=0;j<3;j++) {
			if(cnt[j]==x) {
				cnt[j]++;
				break;
			}
		}

	}

	printf("%d",ans);

}

Measured memory_bytes: 256
def calc(s,t)
    cnt=0
    for c in "a".."z" do
        flag = false
        for i in 0..s.size-1 do
            if(s[i]==c)
                flag=true
                break
            end
        end
        if(flag)
            for i in 0..t.size-1 do
                if(t[i]==c)
                    cnt+=1
                    break
                end
            end
        end
    end
    return cnt
end


n = gets.to_i
str = gets.chomp

ans=0
for i in 1..str.size-1 do
    tmp = calc(str[0,i],str[i,str.size])
    ans = [tmp,ans].max
end

puts ans

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

using namespace std;

using ll = long long;

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

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

    ll n, x, X;

    cin >> n >> X >> x;

    ll ans = abs(x - X);
    for (int i = 0; i < n - 1; ++i) {
        cin >> x;
        ans = gcd(ans, abs(X - x));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;

int main() {
  int N,M;
  cin >> N >> M;
  vint A(N,0);
  repeat(i,M){
    int a,b;
    cin >> a >> b;
    if(a>b) swap(a,b);
    a--;
    b--;
    A[a]++;
    A[b]--;
  }
  debugArray(A,N);
  bool isok = true;
  repeat(i,N-1){
    A[i+1] += A[i];
    isok &= !(A[i]&1);
  }
  isok &= !(A[N-1]&1);
  debugArray(A,N);
  cout << (isok? "YES":"NO") << endl;
  return 0;
}


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

using namespace std;

int main(){
	string s;
	cin >> s;
	int n = s.size();
	bool not_possible = (s.back() != '0' || s[0] != '1');
	for(int i = 0; i < n - 1; ++ i){
		not_possible |= (s[i] != s[n - i - 2]);
	}
	if(not_possible) return cout << "-1\n", 0;
	int now = 0;
	for(int i = 1; i < n; ++ i){
		cout << now + 1 << " " << i + 1 << "\n";
		if(s[i - 1] == '1') now = i;
	}
	return 0;
}


Measured memory_bytes: 1664
//デバッグ用

import java.io.*;
import java.util.Scanner;//スキャナつかう

public class Main {
	public static void main(String[] args) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      	Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();

		int A[] = new int[N];

		for (int i = 0; i < N; i++) {
			A[i] = 0;
        }
      
		for (int i = 0; i < N - 1; i++) {
			int count = scan.nextInt();
			A[count - 1]++;
		}

		for (int i = 0; i < N; i++) {
			System.out.println(A[i]);
		}
	}
}


Measured memory_bytes: 60172
import sys
from itertools import accumulate
from numba import njit

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

@njit
def solve(n, k, a):
    b = [0]*n
    for _ in range(k):
        for i in range(n):
            if i > a[i]:
                b[i-a[i]] += 1
            else:
                b[0] += 1
            if i + a[i] + 1 < n:
                b[i + a[i] + 1] -= 1
        for i in range(n-1):
            b[i+1] += b[i]
            a[i] = 0
        a[-1] = 0
        b, a = a, b
        if min(a) >= n:
            break
    return a

n, k = nm()
a = nl()
print(*solve(n, k, a))


Measured memory_bytes: 125696
s=input()
sng=len(s)
k=int(input())
answer=0

if s[0]!=s[-1]:
    swit=0
    for i in range(sng-1):
        if s[i]==s[i+1]:
            if swit==0:
                answer+=1
                swit=2
            else:
                swit+=1
                if swit%2==0:
                    answer+=1
        else:
            swit=0
    answer*=k
    print(answer)
else:
    now=0
    while s[now]==s[0]:
        now+=1
        if now==sng:
            break
    
    if now==sng:
        print((sng*k)//2)
    
    else:
        now2=sng-1
        while s[now2]==s[0]:
            now2-=1
            if now2==sng:
                break
        
        kaeshi=s[now:now2+1]
        swit=0
        for i in range(len(kaeshi)-1):
            if kaeshi[i]==kaeshi[i+1]:
                if swit==0:
                    answer+=1
                    swit=2
                else:
                    swit+=1
                    if swit%2==0:
                        answer+=1
            else:
                swit=0
        answer*=k
        
        kaeshi2=now+sng-now2-1
        #print(answer)
        answer+=((kaeshi2//2)*(k-1))
        answer+=(now//2)
        answer+=(sng-now2-1)//2
        print(answer)

Measured memory_bytes: 38460
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
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; }

int main(){
    ll a,v,b,w,t;cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    ll x=v-w;
    ll dis =abs(a-b);
    if(x*t>=dis){
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3592