akhauriyash/Code-Regression huggingface dataset:
s = input()
res_list = []
ls = len(s)
for i in range(2**(ls-1)):
    res = s[0]
    for j in range(ls-1):
        if (i >> j) & 1:
            res += '+'
        res += s[j+1]
    res_list.append(eval(res))
print(sum(res_list))
    

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>


int main() {
	char S[6];
	scanf("%s",S);
	
	if(S[2] == S[3] && S[4] == S[5] ) {
		printf("Yes");
		return 0;
	}
	printf("No");
	
	return 0;
}

Measured memory_bytes: 128
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

n=I()
a=L()
xorall=a[0]
for i in range(1,n):
    xorall=xorall^a[i]
for i in a:
    print(xorall^i,end=" ")
print()

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

int main(){
    int N;
    cin>>N;
    vector<int> Q(N);
    for(int i=0;i<N;i++)cin>>Q[i];
    sort(Q.begin(), Q.end());
    cout<<Q[N/2]-Q[N/2-1];
    return 0;
}


Measured memory_bytes: 640
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val s = sc.next
    val p = Array.ofDim[Char](4, N + 2)

    val yes = Array(
      "SSS",
      "WSW",
      "SWW",
      "WWS"
    )

    val no = Array(
      "SSW",
      "WSS",
      "SWS",
      "WWW"
    )

    def table(yesNo: Char) = yesNo match {
      case 'o' => yes
      case 'x' => no
    }

    table(s.charAt(0)).zipWithIndex foreach { case (t, j) =>
      t.indices foreach (k => p(j)(k) = t.charAt(k))
    }

    for {
      i <- 2 to N
    } {
      val ts = table(s.charAt(i - 1))
      ts foreach { t =>
        val j = ((0 until 4) find (j => t.charAt(0) == p(j)(i - 1) && t.charAt(1) == p(j)(i))).get
        p(j)(i + 1) = t.charAt(2)
      }
    }

    val ans = ((0 until 4) find (j => p(j)(0) == p(j)(N) && p(j)(1) == p(j)(N + 1))) map { j =>
      ((1 to N) map (p(j)(_))).mkString
    } getOrElse "-1"
    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  private class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}


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

#define P pair<int,int>
#define INF 1e9

int H,W;
char c[22][22];
int dx[4]{0,0,1,-1};
int dy[4]{1,-1,0,0};

int bfs(P s,P g){
  queue<P> que;
  int dist[22][22];
  rep(i,22)rep(j,22)dist[i][j]=INF;
  if(c[s.first][s.second]=='#') return INF;
  dist[s.first][s.second]=0;
  que.push(s);
  while(!que.empty()){
    P q = que.front();que.pop();
    int x=q.first,y=q.second;
    rep(i,4){
      int nx=x+dx[i],ny=y+dy[i];
      if(nx<0 || nx>=H || ny<0 || ny>=W) continue;
      if(dist[nx][ny]<=1e5) continue;
      else{
        if(c[nx][ny]=='.'){
        dist[nx][ny]=dist[x][y]+1;
        que.push(make_pair(nx,ny));
        }
      }
    }
  }
  return dist[g.first][g.second];
}


int main(){
  cin>>H>>W;
  rep(i,H)rep(j,W)cin>>c[i][j];
  int ans = 0;
  rep(i,H){
    rep(j,W){
      rep(k,H){
        rep(l,W){
          pair<int,int> s,g;
          s=make_pair(i,j);g=make_pair(k,l);
          int d = bfs(s,g);
          if(d>=1e5) continue;
          ans = max(d,ans);
        }
      }
    }
  }
  cout<<ans<<endl;
}

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

int linerSearch(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;

    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> A[i];
    }

    cin >> q;
    for (i = 0; i < q; i++) {
        cin >> key;
        if (linerSearch(A, n, key))
            sum++;
    }

    cout << sum << endl;

    return 0;   
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define ll long long
 
using namespace std;
 
int X,Y,Z;
 
int main(){
    cin>>X>>Y>>Z;

    cout<<Z<<" "<<X<<" "<<Y<<endl;
    return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int a[110000], b[110000];
vint G[110000];

int dfs(int v, int p) {
    int a = 0;
    vint vec;
    for (int i = 0; i < G[v].size(); i++) {
        if (G[v][i] == p)continue;
        vec.push_back(dfs(G[v][i], v));
        a |= vec[vec.size() - 1];
    }
    int idx;
    for (int i = 20; i >= 0; i--) {
        if ((a & (1 << i)) == 0)idx = i;
        int cnt = 0;
        for (int j = 0; j < vec.size(); j++)cnt += (vec[j] & (1 << i)) ? 1 : 0;
        if (cnt >= 2)break;
    }
    a |= 1 << idx;
    a -= a % (1 << idx);
    return a;
}

signed main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++)cin >> a[i] >> b[i], G[a[i]].push_back(b[i]), G[b[i]].push_back(a[i]);
    int x = dfs(1, 0);
    for (int i = 20; i >= 0; i--) {
        if (x & (1 << i)) {cout << i << endl; break;}
    }
}


Measured memory_bytes: 16768
import java.util.Scanner;

public class Main {

	private static final int VAL_LIMIT = 3500 + 1;

	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in)) {
			final int N = in.nextInt();

			int h0 = N / 4 + 1;
			for (int h = h0; h < VAL_LIMIT; ++h) {
				long a = (h << 2) - N;
				long b = N * h;
				int n0 = (int)(b / a + 1);
				for (int n = n0; n < VAL_LIMIT; ++n) {
					long c = a * n - b;
					long d = b * n;
					long w = d / c;
					if (w * c == d) {
						System.out.printf("%d %d %d%n", h, n, w);
						return;
					}
				}
			}
		}
	}
}


Measured memory_bytes: 23764
#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSMutableString*)stringFromStdIn; // 標準入力から NSString を得る
+(void)printf:(NSString*)format, ...; // 標準出力へ出力
@end

@implementation StdIO
+(NSMutableString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    NSUInteger length = [result length];
    if (length >= 1 && [result characterAtIndex:length-1] == '\n') { // 入力末尾に改行文字があれば削除
        [result deleteCharactersInRange:NSMakeRange(length-1,1)];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat:format arguments:arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
    va_end(arguments);
}
@end

NSInteger CEIL(double x) {
    NSInteger n = (NSInteger)x;
    return n + (((x != n) && (x > 0)) ? 1 : 0);
}

NSInteger FLOOR(double x) {
    NSInteger n = (NSInteger)x;
    return n + (((x != n) && (x < 0)) ? -1 : 0);
}

int main() {
    @autoreleasepool {
        NSArray *numbers = [[StdIO stringFromStdIn] componentsSeparatedByString:@"\n"];
        NSInteger A = [[numbers objectAtIndex:0] integerValue];
        NSInteger B = [[numbers objectAtIndex:1] integerValue];
        NSInteger C = [[numbers objectAtIndex:2] integerValue];
        NSInteger X = [[numbers objectAtIndex:3] integerValue] / 50;
        NSInteger count = 0;
        for (NSInteger x=0; x <= MIN(A,X/10); x++) {
            NSInteger Y = X-10*x;
            count += MAX( MIN(B, FLOOR((double)Y/2)) - MAX(0, CEIL((double)(Y-C)/2)) + 1, 0);
            
        }
        [StdIO printf:@"%ld", count];
    }
    return 0;
}


Measured memory_bytes: 2404
n = gets.to_i
s = gets.chomp.chars

left = {}
right = {}
s.each { |c| right[c] = right[c].to_i + 1 }
('a'..'z').each { |c| left[c] = 0 }
('a'..'z').each { |c| right[c] = 0 if right[c].nil? }

ans = 0
cnt = 0
s.each do |c|
  b1 = left[c] > 0 && right[c] > 0
  left[c] += 1
  right[c] -= 1
  b2 = left[c] > 0 && right[c] > 0

  if !b1 && b2
    cnt += 1
  elsif b1 && !b2
    cnt -= 1
  end
  ans = cnt if ans < cnt
end
puts ans

Measured memory_bytes: 1788
#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 int INF = 1e9;
const ll mod = 1e9 + 7;

int main(){
	int A, B, m;
	cin >> A >> B >> m;
	vector<int> a(A), b(B);
	rep(i,A) cin >> a[i];
	rep(i,B) cin >> b[i];
	int ans = INF, num;
	rep(i,m) {
		int x, y, c;
		cin >> x >> y >> c;
		num = a[x-1] + b[y-1] - c;
		ans = min(ans, num);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	num = a[0] + b[0];
	ans = min(ans,num);
	cout << ans << endl;
	return 0;
}

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

void main_()
{
    auto num_of_devide_by_2 = [](int n) {
        int count = 0;
        while (n % 2 == 0) {
            count++;
            n /= 2;
        }
        return count;
    };

    int N;
    cin >> N;
    vector<int64_t> as;
    copy_n(istream_iterator<int64_t>(cin), N, back_inserter(as));
    vector<int64_t> dividable_counts;
    transform(
        begin(as), end(as), back_inserter(dividable_counts),
        num_of_devide_by_2);

    int ans = accumulate(begin(dividable_counts), end(dividable_counts), 0);

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;

int main() {
	std::string str;
	std::stack<int> s;
	int a,b;
	while (std::cin >> str) {
		if (str == "+") {
			a = s.top();
			s.pop();
			b = s.top();
			s.pop();
			s.push(a + b);
		}
		else if (str == "-") {
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a - b);
		}
		else if (str == "*") {
			a = s.top();
			s.pop();
			b = s.top();
			s.pop();
			s.push(a*b);
		}
		else {
			s.push(std::stoi(str));
		}
	}
	std::cout << s.top() << std::endl;
}

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

int main(void){

  int N = 0;
  int K = 0;
  scanf("%d\n",&N);
  scanf("%d\n",&K);
  int inputData = 0;
  int result = 0;


  for(int i = 0;i < N;i++){
    scanf("%d\n",&inputData);
    if(inputData >= K){
      result++;
    }
  }

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

}


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

int a[200005];

int main() {
    //freopen("input.txt", "r", stdin);
     
    int k, n;
    cin >> k >> n;

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

    int res = 1e9;
    for (int i = 1; i <= n; i++) {
        int x = k - (a[i + 1] - a[i]);
        int y = k - (a[i] - a[i - 1]);

        if (i == 1) {
            y = a[n] - a[i];
        }
        if (i == n) {
            x = a[i] - a[1];
        }

        res = min(res, x);
        res = min(res, y);
        //cout << x << " " << y << endl;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

#define MAX_N 50

struct Edge {
    ll to;
    ll a, b;
};

vector<Edge> edge[MAX_N];

ll cost[MAX_N][2501];

// inputs
ll N, M, S;
vll C(MAX_N), D(MAX_N);

bool chmin(ll& a, ll b) {
    return a > b && (a = b, true);
}


void dijkstra() {

    typedef pair<ll, pair<int, ll>> st;
    priority_queue<st, vector<st>, greater<>> que;

    REP(i, N) REP(j, N * 50) cost[i][j] = INF;
    S = min(S, N * 50);
    cost[0][S] = 0;
    que.push({0, {0, S}});

    while(!que.empty()) {
        st e = que.top(); que.pop();

        ll c = e.fi;
        int to; ll cur;
        tie(to, cur) = e.se;

        if (cost[to][cur] < c) continue;

        // exchange
        if (chmin(cost[to][min(cur + C[to], N * 50)], c + D[to])) {
            que.push({c + D[to], {to, min(cur + C[to], N * 50)}});
        }

        // move
        for(auto e_nx: edge[to]) {
            if (e_nx.a > cur) continue;

            ll c_nx = cost[to][cur] + e_nx.b;
            if (chmin(cost[e_nx.to][cur - e_nx.a], c_nx)) {
                que.push({c_nx, {e_nx.to, cur - e_nx.a}});
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> N >> M >> S;

    REP(i, M) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        --u; --v;

        edge[u].pb({v, a, b});
        edge[v].pb({u, a, b});
    }

    REP(i, N) {
        cin >> C[i] >> D[i];
    }

    dijkstra();

    FOR(i, 1, N) {
        ll ans = INF;
        REP(j, N * 50) {
            chmin(ans, cost[i][j]);
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 7344
#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 repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int N;
    cin >> N;
    ll t,a,ct,ca;
    cin >> ct >> ca;
    rep(i,N-1){
        cin >> t >> a;
        ll k = max((ct-1)/t+1,(ca-1)/a+1);
        ct = k*t, ca = k*a;
    }
    pr(ct+ca);
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

import javax.swing.tree.TreeNode;
class Main{


	static final int MOD = 1000000007;

	static	ArrayList<TreeNode> tree;
	static HashSet<Integer> set;
	static int[] ans;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int k = sc.nextInt();
		int x = sc.nextInt();
		
		int left = x - (k-1);
		int right = x + (k-1);
		for(int i = left;i <= right;i++){
			System.out.print(i+" ");
		}
	}





	static int upperbond(int k,ArrayList<Integer> data){		//k以下で最大の値をdataの中から探し、返す二分探索
		if(data == null){
			return -1;
		}
		int max = data.size();
		int min = -1;
		while(max-min > 1){
			int mid = (max+min)/2;
			if(data.get(mid) <= k){
				min = mid;
			}else{
				max = mid;
			}
		}

		
//		if(min != -1){
//			min = data.get(min);
//		}
		
//		System.out.println(max);
		return min;					//indexを返している
	}

	static int lowerbond(int k,ArrayList<Integer> data){		//k以上で最小の値をdataの中から探し、返す二分探索
		if(data == null){
			return -1;
		}
//		System.out.println("lo");
//		System.out.println("lo");
		int max = data.size();
		int min = -1;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data.get(mid) >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;			//indexを返している
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



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




}

class Pair implements Comparable{
	int from;
	int end;
	public Pair(int from,int end) {
		this.from = from;
		this.end = end;
		// TODO 自動生成されたコンストラクター・スタブ
	}

	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  from - otherpair.from;
	}








}






Measured memory_bytes: 23892
#include<iostream>

int main(){

  int a1, a2, a3, tmp = 0;

  std::cin >> a1 >> a2 >> a3;

  if(a1 > a2){
    tmp = a2;
    a2 = a1;
    a1 = tmp;
  }
  
  if(a2 > a3){
    tmp = a3;
    a3 = a2;
    a2 = tmp;
  }
  
  if(a1 > a2){
    tmp = a2;
    a2 = a1;
    a1 = tmp;
  }
  
  std::cout << a1 << ' ' << a2 << ' ' << a3 << std::endl;

  return 0;
}

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

int main(int argc, char const *argv[])
{
	int n,a;
	cin>>n>>a;
	if (n%500<=a)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void EducationalDP_N()
{
	int N;
	cin >> N;
	vi a(N);
	for (auto& x : a)
		cin >> x;
	vl b(N+1);
	for (int i = 0; i < N; ++i)
		b[i + 1] = b[i] + a[i];

	vvl dp(N, vl(N, 1e16));
	for (int i = 0; i < N; ++i)
		dp[i][i] = 0;
	for (int k = 1; k < N; ++k)
	{
		for (int i = 0; i < N; ++i)
		{
			int j = i + k;
			if (j >= N)
				continue;
			ll B = b[j + 1] - b[i];
			for (int m = i; m < j; ++m)
			{
				dp[i][j] = min(dp[i][j], dp[i][m] + dp[m + 1][j] + B);
			}
		}
	}
	cout << dp[0][N - 1] << endl;
}
int main()
{
	EducationalDP_N();
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 

 int main(){
 ll n,a,b ; cin>>n>>a>>b ;
 vector<ll> X(n) ;
 rep(i,n) cin>>X[i] ;
 ll dai = -1 ;
 rep(i,n){
   chmax(dai,(X[i]+b+1)/b) ;
 }
 ll add = a-b ;
 ll l= 0 ;
 ll r= dai+5 ;
 while( r-l >1){
  ll now = (r+l)/2 ;
  ll need=0 ;
 
  rep(i,n){
   if(X[i]>now*b){
     need+= ((X[i]-now*b)+add-1)/add ;
   }
  }
  if(now<need) l=now ;
  else r= now ;

 }
  cout<<r<<endl ;
  
   return 0 ;
}



Measured memory_bytes: 4032
import itertools

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

k = []
s = []


for i in range(m):
    items = [int(item) for item in input().split()]
    k.append(items[0])
    s.append(items[1:])

p = [int(item) for item in input().split()]

count = 0

for switch in range(2 ** n):
    for l in range(m):
        ons = 0
        for j in s[l]:
            if switch >> (j - 1) & 1:
                ons += 1
        if ons % 2 != p[l]:
            break
    else:
        count += 1
print(count)


Measured memory_bytes: 3064
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
int d[N],n,m;
int main(){
	scanf("%d%d",&n,&m);
	for(R int i=1,u,v;i<=m;++i)scanf("%d%d",&u,&v),++d[u],++d[v];
	fp(i,1,n)if(d[i]&1)return puts("NO"),0;
	puts("YES");
	return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
#define Mohamed_Gad fast()
#define ll long long
#define ull unsigned long long
#define all(v) v.begin(),v.end()
#define endl "\n"
#define sz(x) size(x)
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    //freopen("Output.txt", "w", stdout);
#endif

}
//long long frq[100009],prf[100009];

int main() {
    fast();
     multiset<int>s;
     int n,a,sum=0;
     cin>>n;
     for(int i=0;i<2*n;i++){
        cin>>a;
        s.insert(a);
     }
     multiset<int>::iterator it=s.begin();
     for(it;it!=s.end();it++){
        sum+=*it;
        it++;
     }
   cout<<sum<<endl;

}


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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

vvt<int> grid;

void dfs(int y, int x, int num, pair<i64, i64> &p) {
  if(grid[y][x] != num) return;
  grid[y][x] = -1;
  if(num == 0) p.first++;
  else p.second++;

  rep(i, 0, 4) {
    dfs(y + dy[i], x + dx[i], !num, p);
  }
}

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

  int h, w;
  cin >> h >> w;
  grid = vvt<int>(h + 2, vt<int>(w + 2, -1));
  rep(i, 0, h) {
    string s;
    cin >> s;
    rep(j, 0, w) {
      if(s[j] == '#') grid[i + 1][j + 1] = 0;
      else grid[i + 1][j + 1] = 1;
    }
  }

  i64 ans = 0;
  rep(i, 1, h + 1) {
    rep(j, 1, w + 1) {
      if(grid[i][j] == 0) {
        pair<i64, i64> p;
        dfs(i, j, 0, p);
        ans += p.first * p.second;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8448
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>

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

    std::vector<int> a(n), b(n - 1);

    for(int i = 0; i < n - 1; ++i){
        std::cin >> b.at(i);
    }

    a.at(0) = b.at(0);
    a.at(n - 1) = b.at(n - 2);

    for(int i = 1; i < n - 1; ++i){
        a.at(i) = std::min(b.at(i - 1), b.at(i));
    }

    std::cout << std::accumulate(a.begin(), a.end(), 0);

    return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

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

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

func main() {
	defer stdout.Flush()

	n := readInt()
	factors := make([]int, n+1)
	for i := 1; i <= n; i++ {
		m := i
		for j := 2; j <= m; j++ {
			for m%j == 0 {
				factors[j]++
				m /= j
			}
		}
	}

	ans := 1
	for i := 2; i <= n; i++ {
		ans = (ans * (factors[i] + 1)) % 1000000007
	}

	println(ans)
}


Measured memory_bytes: 640
N, K = map(int, input().split())

no_treat = [True] * (N + 1)

for _ in range(K):
    _ = input()
    A = list(map(int, input().split()))
    for a in A:
        no_treat[a] = False

ans = -1

for snuke in no_treat:
    if snuke:
        ans += 1

print(ans)

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

using namespace std;

int main(){
    int n,l;
    cin>>n>>l;
    int apple[200];
    bool flag[200];
    long s=0;
    for(int i=0;i<n;i++)
    {
        apple[i] = l + i;
        s += apple[i];
    }
    int a = 1000;
    for(int i=0;i<n;i++)
    {
        if(abs(a)>abs(apple[i]))a = apple[i];
        apple[i] = abs(apple[i]);
    }
    cout<<s-a;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter

    n, m = map(int, readline().split())
    a = list(map(int, readline().split()))

    counter = Counter()
    counter[0] = 1

    cur = 0
    for x in a:
        cur += x
        cur %= m
        counter[cur] += 1

    ans = 0
    for key, val in counter.items():
        ans += val * (val - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58736
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=1e9+7;

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

    string s;
    cin >>s;
    ll ans=0;
    for(auto ch:s){
        if(ch=='o') ans++;
    }
    ans=ans*100+700;
    cout <<ans << endl;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    s <- getLine
    t <- getLine
    putStrLn $ if take (length s) t == s then "Yes" else "No"


Measured memory_bytes: 3652
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    p, q, r = sorted(map(int, input().split()))
    print(p + q)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29292
#include<iostream>
//#include<vector>

int main() {
	int a,b,p,count=1;
	std::cin >> a>>b;

	if (b == 1) {
		std::cout << 0 << std::endl;
		exit(0);
	}

	p = a;

	for (int i = 0; p < b; i++) {
		p += (a - 1);
		count++;
	}

	/*
	while (p < b) {
		p += (a - 1);
		count++;
	}
	*/

	std::cout << count << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int ans=0;
  
    int a[N];
    for(int i=0;i<N;i++)cin>>a[i];

    for(int i=0;i<N;i++){
      if(i%2==0 && a[i]%2==1)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	int r, d, x;
	cin >> r >> d >> x;

	for (int i = 1; i <= 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}

}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline
MOD = 2019


def main():
    l, r = get_li()
    if r - l >= MOD:
        print(0)
        return
    ans = inf
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, (i * j) % MOD)
    print(ans)


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()


Measured memory_bytes: 70764
#include <iostream>
using namespace std;
int main(void){
    int table[200][200] = {{0}};
    int c,r;
    cin >> r >> c;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> table[i][j];
        }
    }
    
    for(int i = 0; i < r+1; i++){
        int sum = 0;
        for(int j = 0; j < c; j++){
            sum += table[i][j];
        }
        table[i][c] = sum;
    }
    
    for(int j = 0; j < c+1; j++){
        int sum = 0;
        for(int i = 0; i < r; i++){
            sum += table[i][j];
        }
        table[r][j] = sum;
    }
    

    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            cout << table[i][j] << " ";
        }
        cout << table[i][c] << endl;
    }
}



Measured memory_bytes: 3244
n, d = map(int, input().split())


x = []
y = []
for i in range(n):
    i1, i2 = map(int, input().split())
    x.append(i1)
    y.append(i2)


ans = 0

for i in range(n):
    dist = x[i]*x[i] + y[i]*y[i]
    if dist <= d*d:
        ans = ans+1

print(ans)


Measured memory_bytes: 24916
#include <bits/stdc++.h>
#define rep(i, n, init) for (int i = init, len = (n); i < len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define _GLIBCXX_DEBUG
#define int long long
#define float long double
#define len(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;

template <class Key, class Value>
pair<Key, Value> findMaxValuePair(unordered_map<Key, Value> const &x) {
  return *max_element(
      x.begin(), x.end(),
      [](const pair<Key, Value> &p1, const pair<Key, Value> &p2) { return p1.second < p2.second; });
}

string padStart(int target, int len, char padString) {
  ostringstream ss;
  ss << setfill(padString) << right << setw(len) << target << flush;
  return ss.str();
}

bool isEven(const int &n) {
  return !(n & 1);
}

int ctoi(const char c) {
  return ('0' <= c && c <= '9') ? (c - '0') : -1;
}

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

  int N;
  cin >> N;

  long double total = 0;

  rep(i, N, 0) {
    int A;
    cin >> A;
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (i == 0) {
      total = A;
    } else {
      total *= A;
    }
  }
  const int m = 1000000000000000000LL;

  if (total > m) {
    cout << -1 << endl;
    return 0;
  };

  cout << fixed << setprecision(0);
  cout << total << endl;
}


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

int n;

struct item{
    char name[256];
    int cost;
    char used[100][256];
    int size;
} ;

item list[100];

int getCost(int vertex)
{
    int i, j;
    int ans;
    
    if (list[vertex].size == 0){
        return (list[vertex].cost);
    }
    else {
        ans = 0;
        for (i = 0; i < list[vertex].size; i++){
            for (j = 0; j < n; j++){
                if (strcmp(list[vertex].used[i], list[j].name) == 0){
                    ans += getCost(j);
                }
            }
        }
        list[vertex].cost = list[vertex].cost > ans ? ans : list[vertex].cost;
    }
    return (list[vertex].cost);
}

int main(void)
{
    int i, j, k;
    int m, kk;
    char key[256], temp[256];
    int look, sum;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%s%d", list[i].name, &list[i].cost);
            list[i].size = 0;
        }
        
        scanf("%d", &m);
        for (i = 0; i < m; i++){
            scanf("%s", key);
            for (j = 0; j < n; j++){
                if (strcmp(key, list[j].name) == 0){
                    look = j;
                }
            }
            scanf("%d", &kk);
            list[look].size = kk;
            for (j = 0; j < kk; j++){
                scanf("%s", temp);
                for (k = 0; k < n; k++){
                    if (strcmp(temp, list[k].name) == 0){
                        strcpy(list[look].used[j], temp);
                    }
                }
            }
        }
        scanf("%s", key);
        for (j = 0; j < n; j++){
            if (strcmp(key, list[j].name) == 0){
                look = j;
            }
        }
        
        printf("%d\n", getCost(look));
        
    }
    
    return (0);
}

Measured memory_bytes: 1204
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;

//WA なんでだかよくわからない

const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

int main(){
    while(1){
        long long int n;
        cin >> n;
        if(!n) break;

        int num[12];
        fill(num,num+12,0);
        int i=0;
        long long int p = -100000000000;
        while(p!=0){
            if(p<0){
                int p_b = p * 9 / 100;
                int temp = p_b / 100;
                while(temp!=0){
                    p_b += temp;
                    temp /= 100;
                }
                while(n < p_b){
                    n -= p;
                    num[i]++;
                }
            }else{
                int p_b = p * 9 / 100;
                int temp = p_b / 100;
                while(temp!=0){
                    p_b += temp;
                    temp /= 100;
                }
                while(n > p_b){
                    n -= p;
                    num[i]++;
                }
            }
            p /= -10;
            i++;
        }
        bool is_start = false;
        for(int i=0;i<12;i++){
            if(!is_start&&num[i]>0){
                is_start = true;
            }
            if(is_start || i==11){
                cout << num[i];
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1156
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         1000000000000000000
using namespace std;
 
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
 
int dp[3005][3005];

signed main()
{
    tezz
 
    string s,t;
    cin>>s>>t;

    memset(dp,0,sizeof(dp));
    int n = s.length(), m = t.length();

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j]+1;
            else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
    }

    string ans = "";
    int i=n,j=m;
    while(i>0 && j>0){
        //cout<<i<<" "<<j<<endl;
        if(dp[i-1][j] == dp[i][j]) i--;
        else if(dp[i][j-1] == dp[i][j]) j--;
        
        else {ans+=s[i-1]; i--; j--;}
    }
    reverse(all(ans));
    cout<<ans;
}

Measured memory_bytes: 70784
h, n = (int(x) for x in input().split())
w = []
v = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    w.append(a)
    v.append(b)
dp = [[float('inf')] * (h) for _ in range(n + 1)]
for i in range(n):
    for j in range(h):
        if j < w[i]:
            dp[i + 1][j] = min(dp[i][j], v[i])
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - w[i]] + v[i])
print(dp[n][h - 1])

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

vector<int> p(10000001);

void sieve() {
  int n=10000001;
  for(int i=2; i<n; i++) p[i]=i;
  for(int i=2; i*i<n; i++) {
    if(p[i]) {
      for(int j=i*i; j<n; j+=i) p[j]=0;
    }
  }
}

int main() {
  sieve();
  int n;
  while(cin >> n && n) {
    for(int i=n; i>=13; i--) {
      if(p[i] && p[i-2] && p[i-6] && p[i-8]) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 40108
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i32 n;
i64 t[100000], a[100000];
i64 h[100000], l[100000];

i32 main()
{
    cin >> n;
    times(n, i) {
        cin >> t[i];
    }
    times(n, i) {
        cin >> a[i];
    }
    times(n, i) {
        h[i] = t[i];
        if (i == 0 || t[i-1] < t[i]) {
            l[i] = t[i];
        } else {
            l[i] = 1;
        }
    }
    times(n, i) {
        if (i == n-1 || a[i+1] < a[i]) {
            if (!(l[i] <= a[i] && a[i] <= h[i])) {
                cout << 0 << endl;
                return 0;
            }
        }
        h[i] = min(h[i], a[i]);
        if (i == n-1 || a[i+1] < a[i]) {
            l[i] = a[i];
        }
    }

    i64 ans = 1;
    times(n, i) {
        if (h[i] < l[i]) {
            ans *= 0;
        }
        ans = (ans * (h[i]-l[i]+1)) % MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
S=input()
n=int(input())

list1=[]

if len(S)%n>=1:
    A=1
elif len(S)%n==0:
    A=0
    
for i in range(len(S)//n+A):
    list1.append(S[0+n*i])

ans="".join(list1)
print(ans)
    

Measured memory_bytes: 3060
N=int(input())
H= list(map(int, input().split()))
A=0
t=H[0]
a=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        a+=1
    else:
        if a>A:
            A=a
        a=0
A=max(a,A)
print(A)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;




int main() {
	string s;
	cin >> s;
	int len = s.length();

	int cnt_g = 0;
	int cnt_p = 0;
	int score = 0;
	for (int i = 0; i < len; i++) {
		if (cnt_g > cnt_p && s[i] == 'g') {
			cnt_p++;
			score++;

		}
		else if (s[i] == 'g') {
			cnt_g++;
		}
		else if (s[i] == 'p' && cnt_g == cnt_p){
			cnt_g++;
			score--;
		}
		else {
			cnt_p++;
		}

	}
	cout << score << endl;
}


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

int main() {
	int n;
	cin >> n;
	int ans = 1e9;
	for (int i = 0;i <= n;i++) {
		int ch = 0;
		int t = i;
		while (t > 0) {
			ch += t % 6;
			t /= 6;
		}
		int u = n - i;
		while (u > 0) {
			ch += u % 9;
			u /= 9;
		}
		if (ans > ch)ans = ch;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
char s[210000];
stack<char>stk;
int main() {
	scanf("%s", s+1);
	int n = strlen(s+1);
	for(int i = 1; i <= n; i ++ ) {
		if(!stk.empty() && stk.top() == 'S' && s[i] == 'T') {
			stk.pop();
			continue;
		}
		else {
			stk.push(s[i]);
		}
	}
	printf("%d\n", stk.size());
}


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

int n, x[10];
bool vis[301][301][301];
double f[301][301][301];

double dp(int a, int b, int c) {
    if (a + b + c == 0) return 0;
    if (vis[a][b][c]) return f[a][b][c];
    vis[a][b][c] = 1;
    double res = 1;
    if (a) res += dp(a - 1, b, c) * a / n;
    if (b) res += dp(a + 1, b - 1, c) * b / n;
    if (c) res += dp(a, b + 1, c - 1) * c / n;
    res = res * 1.0 * n / (a + b + c);
    return f[a][b][c] = res;
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n;
    for (int i = 1, a; i <= n; ++i)
        scanf("%d", &a), x[a]++;
    printf("%.10f\n",dp(x[1], x[2], x[3]));
    return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

ll cal(vector<pii>& v, int n){
	ll rtn =0;
	int m = sz(v);
	sort(v.rbegin(), v.rend());
	bitset<200002> bt;
	bt.set();
	
	rep(i, m) {
		int stp = max(n-m, v[i].second);
		int ps = bt._Find_next(stp);
		if(ps > n) continue;
		rtn += v[i].first;
		bt.reset(ps);
	}
	return rtn;
}

void solove(){
	int n; cin >>n;
	vector<pii> lf, rg;
	ll ans = 0;
	rep(i, n){
		int k, l, r;
		cin >>k >>l >>r;
		if(l >r){
			lf.emplace_back(l-r, n-k);
		}else if(l < r){
			rg.emplace_back(r-l, k);
		}
		ans += min(l, r);
	}
	
	ans += cal(lf, n) + cal(rg, n);
	cout << ans <<"\n";
}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int t;
	cin >>t;
	rep(_g, t) solove();
	return 0;
}


Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long n,k,max=0,ans=1e11;
    cin >> n >> k;
    vector<int> a(n),b(n);//b:i番もふくめ左側のmaxhの場所
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(max<a[i]) max = a[i];
        b[i] = max;
    }
    for(int i=0;i<(1<<n);i++){
        long cost=0,cnt=0;
        bitset<15> s(i);
        vector<int> cand,c=a,d=b;//使う建物の番号,maxh情報の初期化
        for(int j=0;j<n;j++){
            if(s.test(j)) cand.push_back(j);
        }
        for(auto j:cand){
            cost += (d[j]-c[j])+1;//c[j]をd[j]+1に差し替える
            c[j] = d[j]+1;
            int k=j+1;
            while(c[k]<d[j]+1&&k<n){
                d[k] = d[j]+1;
                k++;
            }
        }
        int max1 = 0;
        rep(j,n){
            if(max1<c[j]){
                max1 = c[j];
                cnt++;
            }
        }
        if(k <= cnt) ans = min(cost,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632