akhauriyash/Code-Regression huggingface dataset:
n= int(input())
w=[[int(i) for i in input().split()] for j in range(n)]
w.sort(key=lambda x: x[1])
sum_a = 0
for i in range(n):
    sum_a += w[i][0]
    if sum_a > w[i][1]:
        print("No")
        break
else:
    print("Yes")

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

int main() {
  int n,count=0;
  string s;
  cin >> n;
  cin >> s;
  while(n--) {
    int c;
    string z;
    cin >> z;
    for(int i=0; i<z.size(); i++) {
      for(int j=0; j<z.size()-s.size()+1; j++) {
	c=0;
	for(int k=0; k<s.size(); k++) {
	  if(j+k+k*i>=z.size()) break;
	  if(s[k]==z[j+k+k*i]) c++;
	}
	if(c==s.size()) {
	  count++;
	  break;
	}
      }
      if(c==s.size()) break;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1208
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto ab = new int[][](n, 2);
  foreach (i; 0..n) {
    ab[i] = readln.chomp.split.to!(int[]);
  }
  sort!((a,b)=>a[1] < b[1])(ab);
  long sum;
  bool f;
  foreach (i; 0..n) {
    sum += ab[i][0];
    if (sum > ab[i][1]) {
      f = true;
      break;
    }
  }
  if (f) {
    writeln("No");
  } else {
    writeln("Yes");
  }
}


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

using namespace std;

using pii = pair<int,int>;

bool inside(pii a, int b){
    return a.first <= b && b <= a.second;
}

// TODO eraseは全削除
int main(){
    int n;
    cin>>n;

    vector<pii> v(n);
    bool f1 = false;
    bool f2 = false;
    for(int i=0; i<n; i++){
        cin >> v[i].first >> v[i].second;
        if(v[i].first > 0) f2 = true;
        if(v[i].second < 0) f1 = true;
    }
    sort(v.begin(), v.end());

    multiset<pii> left;
    multiset<pii> right;
    for(pii x: v){
        right.insert(pii(-x.first, x.second));
        left.insert(pii(x.second, x.first));
    }

    auto cl = left;
    auto cr = right;
    
    int p = 0;
    long long ans = 0;
    long long tmp1 = 0;
    if(f1) for(int i=0; i<n; i++){
        if(i&1){
            pii tr = *right.begin();
            pii tl = tr;
            tl.first *= -1;
            if(!inside(tl, p)){
                assert(p < tl.first);
                tmp1 += abs(p-tl.first);
                p = tl.first;
            }
            swap(tl.first, tl.second);
            right.erase(right.find(tr));
            left.erase(left.find(tl));
        }
        else{
            pii tl = *left.begin();
            pii tr = tl;
            swap(tr.first, tr.second);
            if(!inside(tr, p)){
                assert(tr.second < p);
                tmp1 += abs(p-tr.second);
                p = tr.second;
            }
            tr.first *= -1;
            right.erase(right.find(tr));
            left.erase(left.find(tl));
        }
    }
    tmp1 += abs(p);

    p = 0;
    left = cl;
    right = cr;
    long long tmp2 = 0;
    if(f2) for(int i=0; i<n; i++){
        // cout << "p "<<p<<" "<<tmp2<<endl;
        if(i%2==0){
            pii tr = *right.begin();
            pii tl = tr;
            tl.first *= -1;
            if(!inside(tl, p)){
                assert(p < tl.first);
                tmp2 += abs(p-tl.first);
                p = tl.first;
            }
            swap(tl.first, tl.second);
            right.erase(right.find(tr));
            left.erase(left.find(tl));
        }
        else{
            pii tl = *left.begin();
            pii tr = tl;
            swap(tr.first, tr.second);
            if(!inside(tr, p)){
                assert(tr.second < p);
                tmp2 += abs(p-tr.second);
                p = tr.second;
            }
            tr.first *= -1;
            right.erase(right.find(tr));
            left.erase(left.find(tl));
        }
    }
    // cout<<"p "<<p<<" "<<tmp2<<endl;
    tmp2 += abs(p);
    // cout << tmp1 <<" "<<tmp2<<endl;
    cout << max(tmp1, tmp2) << endl;
}

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

int main()
{
    int n,r;
    cin >> n >> r;
    int res = 0;
    if(n >= 10)
    {
        res = r;
    }
    else{
        res = (r + (100*(10-n)));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<complex>
#define Re real()
#define Im imag()
using namespace std;
typedef complex<double> Point;
typedef Point Vector;

double dot(const Point& a, const Point& b)
{
    return (conj(a)*b).Re;
}

int main()
{
    int vol;
    double x1,x2,y1,y2;
    while(~scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2))
    {
        Point p0 = Point(x1,y1),p1 = Point(x2,y2);
        Vector v0 = p1 - p0;
        scanf("%d",&vol);
        while(vol--)
        {
            double tx,ty;
            scanf("%lf%lf",&tx,&ty);
            Point pn = Point(tx,ty);
            Vector v1 = pn - p0;
            Vector v2 = dot(v0,v1)*v0/norm(v0) ;
            Vector v3 = (v2 - v1) + (v2 - v1);
            Point pa = p0 + v1 + v3;
            printf("%.10f %.10f\n",pa.Re,pa.Im);
        }
    }
    return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
#include <cassert>
#include <climits>
#include <cmath>

using namespace std;
using namespace chrono;

// 0以上UINT_MAX(0xffffffff)以下の整数をとる乱数 xorshift https://ja.wikipedia.org/wiki/Xorshift
static uint32_t randXor()
{
    static uint32_t x = 123456789;
    static uint32_t y = 362436069;
    static uint32_t z = 521288629;
    static uint32_t w = 88675123;
    uint32_t t;

    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

// 0以上1未満の小数をとる乱数
static double rand01()
{
    return (randXor() + 0.5) * (1.0 / UINT_MAX);
}

const static int NUM_TYPES = 26; // コンテストの種類数

// 全体のスコア（今回の問題のスコア）
static int getFullScore(const int D, const vector <int>& C, const vector <int>& T, const vector<vector<int>>& S)
{
    int score = 0;

    vector <int> last(NUM_TYPES, 0);

    for (int d = 0; d < D; d++)
    {
        const int j = T[d];
        last[j] = d + 1;
        for (int t = 0; t < NUM_TYPES; t++)
        {
            score -= (d + 1 - last[t]) * C[t];
        }
        score += S[d][j];
    }

    return score;
}

int main()
{
    //  入力
    int D;
    cin >> D;
    vector<int> C(NUM_TYPES);
    for (int &c : C)
    {
        cin >> c;
    }

    vector<vector<int>> S(D, vector<int>(NUM_TYPES));
    for (auto &s : S)
        for (auto &x : s)
        {
            cin >> x;
        }

    vector<int> T(D);   // T[d] d日目に開くコンテスト
    for (int d = 0; d < D; d++)
    {
        T[d] = d % NUM_TYPES;
    }

    // 焼きなまし法
    auto startClock = system_clock::now();
    int score = getFullScore(D, C, T, S);   // 現在のスコア
    int bestScore = INT_MIN;                // 最高スコア
    vector <int> bestT;                     // 最高スコアを出したときのT

    const static double START_TEMP = 1500; // 開始時の温度
    const static double END_TEMP   =  100; // 終了時の温度
    const static double END_TIME   =  1.8; // 終了時間（秒）

    double time = 0.0;   // 経過時間（秒）
    while (time = (duration_cast<microseconds>(system_clock::now() - startClock).count() * 1e-6) < END_TIME)
    {
        const double progressRatio = time / END_TIME;   // 進捗。開始時が0.0、終了時が1.0
        const double temp = START_TEMP + (END_TEMP - START_TEMP) * progressRatio;

        // 近傍 : d日目のコンテストをtに変えてみる
        const int d = randXor() % D;
        const int t = randXor() % NUM_TYPES;
        const int backupT = T[d];
        int deltaScore = 0; // スコアの差分 = 変更後のスコア - 変更前のスコア
        deltaScore -= getFullScore(D, C, T, S);
        T[d] = t;   // 変更
        deltaScore += getFullScore(D, C, T, S);
        const double probability = exp(deltaScore / temp); // 焼きなまし法の遷移確率

        if (probability > rand01())
        {
            // 変更を受け入れる。スコアを更新
            score += deltaScore;
            if (score > bestScore)
            {
                bestScore = score;
                bestT = T;
            }
        }
        else
        {
            // 変更を受け入れないので、元に戻す
            T[d] = backupT;
        }
    }

    // 出力
    for (int t : bestT)
    {
        cout << t + 1 << endl;
    }
    cerr << "bestScore: " << max(0, bestScore + 1000000) << endl;

    return 0;
}


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


int main(void)
{
	int num;
	cin >> num;
	int osu[100005];
	int ans = 1;
	for (int i = 1; i <= num; i++) {
		cin >> osu[i];
	}
	int a = 1;
	
	int b=0;
	for (int i = 1; i <= num;i++) {
		a = osu[a];
		
		if (a == 2) {
			b = ans;
			break;
		}
		ans++;
		
	}
	
	if (b == 0)
		cout << -1 << endl;
	else
		cout << b << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int w, h;
signed main() {
    cin >> w >> h;
    vector<pii> v;
    rep(i,0,w) {
        int p; cin >> p;
        v.push_back(pii(p, 0));
    }
    rep(i,0,h) {
        int q; cin >> q;
        v.push_back(pii(q, 1));
    }

    sort(v.begin(), v.end());
    int a = w+1, b = h+1, ans = 0;
    rep(i,0,v.size()) {
        if(v[i].second == 0) {
            ans += b * v[i].first;
            a--;
        }
        else {
            ans += a * v[i].first;
            b--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll h, w, c1 = 0, c2 = 0, c[30], ck = 0;
bool ok = true;
string s[110];
int main(){
	cin >> h >> w;
	REP(i, h)cin >> s[i];
	REP(i, h)REP(j, w)c[s[i][j] - 'a']++;
	REP(i, 30) {
		if (c[i] % 2 == 1)c1++;
		if (c[i] % 4 >= 2)c2++;
	}
	if (h % 2 == 1 and w % 2 == 1) {
		if(c1 != 1) ok = false;
	}
	else if (c1 != 0)ok = false;
	if (h % 2 == 1) ck += w / 2;
	if (w % 2 == 1) ck += h / 2;
	if (c2 > ck)ok = false;
	cout << (ok ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

struct mint {
	ll x;
	mint(ll x = 0) :x(x% mod) {}
	mint& operator+=(const mint a) {
		(x += a.x) %= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		(x += mod - a.x) %= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
};

mint dp[100005][4];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	for (int i = n; i >= 0; --i) {
		for (int j = 3; j >= 0; --j) {
			if (i == n) {
				dp[i][j] = (j == 3 ? 1 : 0);
			}
			else {
				dp[i][j] = dp[i + 1][j] * (s[i] == '?' ? 3ll : 1ll);
				if (j < 3 && (s[i] == '?' || s[i] == "ABC"[j])) {
					dp[i][j] += dp[i + 1][j + 1];
				}
			}
		}
	}
	mint ans = dp[0][0];
	cout << ans.x << endl;
	return 0;
}


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

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,M;
int dp[111111];
signed main(){
    cin>>N>>M;
    fill_n(dp,N,1<<25);
    rep(i,M){
        int a;
        cin>>a;
        dp[--a]=0;
    }

    reps(i,1,N)chmin(dp[i],dp[i-1]+1);
    for(int i=N-2;i>=0;i--)chmin(dp[i],dp[i+1]+1);

    cout<<*max_element(dp,dp+N)<<endl;
    return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#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 INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  cout << n * (n-1) / 2 << endl;
}

Measured memory_bytes: 256
L=[1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,72,81]
N=int(input())
print('NYoe s'[N in L::2])


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
	double x;
	cin >> x;
    double cnt=0;
    for (int i = 1; i <= x; i++)
    {
        if (i%2!=0)
        {
            cnt++;
        }
    }
    double y = cnt / x;
	printf("%f\n", y);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	result := 0
	for i := 0; i < 3; i++ {
		if s[i] == t[i] {
			result++
		}
	}
	fmt.Println(result)
}


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

min_sum = 10000000000000000000000000000000000000

for j in range(0,100):
	tmp_sum = 0
	for i in range(N):
		tmp_sum += (X[i] - j) ** 2
	if tmp_sum < min_sum:
		min_sum = tmp_sum
	#print(tmp_sum)
print(min_sum)

Measured memory_bytes: 3060
object Main {
  def main(args: Array[String]): Unit = {
    val n: Int = io.StdIn.readInt()
    val children: Array[Seq[Int]] = Array.fill(n)(Seq(-1,-1))
    val parent: Array[Option[Int]] = Array.fill(n)(None)

    for {
      _ <- 0 until n
      l = io.StdIn.readLine()
    } {
      val Seq(i, c1, c2): Seq[Int] = l.split(" ", 3).map(_.toInt)
      children(i) = Seq(c1, c2)
      if (c1 != -1) parent(c1) = Some(i)
      if (c2 != -1) parent(c2) = Some(i)
    }

    def depth: Memoized = Memoized {i =>
      parent(i) match {
        case None => 0
        case Some(x) => 1 + depth(x)
      }
    }
    def height: Memoized = Memoized {i =>
      children(i) match {
        case Seq(-1, -1) => 0
        case Seq(x,  -1) => 1 + height(x)
        case Seq(-1,  y) => 1 + height(y)
        case Seq(x,   y) => 1 + (height(x) max height(y))
      }
    }

    for (i <- 0 until n) {
      val p: Int = parent(i).getOrElse(-1)
      val s: Int = if (p == -1) -1 else children(p).filterNot(_ == i).head
      val deg: Int = children(i).filterNot(_ == -1).length
      val t = if (p == -1) "root" else if (deg == 0) "leaf" else "internal node"

      println(s"node $i: parent = $p, sibling = $s, degree = $deg, depth = ${depth(i)}, height = ${height(i)}, $t")
    }
  }

  case class Memoized(f: Int => Int) extends (Int => Int) {
    val cache: Array[Option[Int]] = Array.fill(256)(None)
    def apply(i: Int): Int = cache(i) match {
      case None => cache(i) = Some(f(i)); cache(i).get
      case Some(x) => x
    }
  }
}

Measured memory_bytes: 44876
n = int(input())
a = [int(x) for x in input().split()]
 
m = [0]*(max(a)+1)
lm = len(m)
cnt = 0
 
for i in a:
    j = 1
    while i*j < lm:
        m[i*j] += 1
        j += 1
for i in a:
    if m[i] == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 132268
/*
PROG: agc26c
LANG: C++11
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>

using namespace std;

template<class T>
void readi(T &x)
{
	T input = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = input * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	x = input;
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long randomize(long long mod)
{
	return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-10;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 18

long long normalize(long long x, long long mod = INF)
{
	return (((x % mod) + mod) % mod);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pll, pll> ppp;

int N;
int arr[2 * MAXN];
map<pll, int> mp;
ll ans;

int32_t main()
{
	ios_base::sync_with_stdio(0); 
	srand(time(0));
	//	cout << fixed << setprecision(10);	
	//	cerr << fixed << setprecision(10);
	if (fopen("agc26c.in", "r"))
	{	
		freopen ("agc26c.in", "r", stdin);
	//	freopen ("agc26c.out", "w", stdout);
	}
	cin >> N;
	string temps;
	cin >> temps;
	for (int i = 0; i < 2 * N; i++)
	{
		arr[i] = temps[i] - 'a' + 1;
	}
	for (int i = 0; i < (1 << N); i++)
	{
		ll blues = 0, reds = 0;
		for (int j = N - 1; j >= 0; j--)
		{
			if (i & (1 << j))
			{
				blues *= CO;
				blues += arr[j + N];
				blues %= BIG;
			}
			else
			{
				reds *= CO;
				reds += arr[j + N];
				reds %= BIG;
			}
		}
		mp[MP(blues, reds)]++;
	}
	for (int i = 0; i < (1 << N); i++)
	{
		ll blues = 0, reds = 0;
		for (int j = 0; j < N; j++)
		{
			if (i & (1 << j))
			{
				blues *= CO;
				blues += arr[j];
				blues %= BIG;
			}
			else
			{
				reds *= CO;
				reds += arr[j];
				reds %= BIG;
			}
		}
		ans += mp[MP(blues, reds)];
	}
	cout << ans << '\n';
	//	cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" << endl;
	return 0;
}


Measured memory_bytes: 33024
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iostream>
typedef long long ll;
using namespace std;
const int maxn=101000;
int dis[maxn][35];
int n,l,q;
int num[maxn];
int main(){
    scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]);
	scanf("%d%d",&l,&q);
	for(int i=1;i<=n;i++){
		int idx=(int)(upper_bound(num+1,num+n+1,num[i]+l)-num);
		idx--;
		dis[i][0]=idx;
	}
	for(int j=1;j<=30;j++){
		for(int i=1;i<=n;i++){
			dis[i][j]=dis[dis[i][j-1]][j-1];
		}
	}
	while(q--){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==b){
			printf("0\n");
			continue;
		}
		if(a>b) swap(a,b);
		int ans=0,cur=a;
		for(int i=30;i>=0;i--){
			if(dis[cur][i]<b){
				ans+=(1<<i);
				cur=dis[cur][i];
			}
		}
		printf("%d\n",ans+1);
	}
	return 0;
}

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

using namespace std;

int main(void){
  int c[3];
  cin >> c[0] >> c[1] >> c[2];
  sort(c,c+3);
  if(c[0]+c[1]==c[2]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from sys import stdin

S = stdin.readline().rstrip()

stack = []
count = 0

for s in S:
    # スタックが空なら
    if not stack:
        stack.append(s)
    # スタックの一番上がsでなければ
    elif stack[-1] != s:
        stack.pop()
        count += 2
    else:
        stack.append(s)

print(count)

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

using namespace std;

const long long MOD = (long long)1e9+7;
long long N;
long long d[104][6][6][6];

int main(){
    scanf("%lld", &N);
    long long ans = 0;
    for(int i=3;i<=N;++i){
        for(int j=1;j<=4;++j) for(int x=1;x<=4;++x) for(int y=1;y<=4;++y){
            if(j==1&&x==3&&y==1){
                int g = 1;
            }
            if(i==3){
                if(j==1&&x==3&&y==2) continue;
                if(j==3&&x==1&&y==2) continue;
                if(j==1&&x==2&&y==3) continue;
                d[i][j][x][y] = 1;
            }
            else{
                for(int k=1;k<=4;++k){
                    if(j==1&&x==3&&y==2) continue;
                    if(k==1&&j==3&&x==2) continue;

                    if(k==1&&x==3&&y==2) continue;
                    if(j==1&&k==3&&x==2) continue;

                    if(x==1&&j==3&&y==2) continue;
                    if(k==1&&x==3&&j==2) continue;

                    if(j==1&&y==3&&x==2) continue;
                    if(k==1&&j==3&&y==2) continue;
                    d[i][j][x][y] += d[i-1][k][j][x];
                }
            }
            d[i][j][x][y] %= MOD;
            if(i==N){
                ans += d[i][j][x][y];
            }
        }
    }
    printf("%lld\n", ans%MOD);
    return 0;
}


Measured memory_bytes: 384
import Data.List
import Data.Maybe
import Control.Monad
import Data.Array.IO
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

kruskalIO (n,edge) = do
 forest <- newListArray (0,n-1) [0..n-1] :: IO (IOUArray Int Int)
 rank <- newArray (0,n-1) 1 :: IO (IOUArray Int Int)
 ret <- foldM makepath ((forest,rank),0) edge
 return ret

makepath ((forest,rank),acc) ((a,b),d) = do
 rep1 <- untilFixM (readArray forest) a
 rank1 <- readArray rank rep1
 rep2 <- untilFixM (readArray forest) b
 rank2 <- readArray rank rep2
 if rep1 /= rep2
  then if rank1 >= rank2
   then do
    writeArray forest rep2 rep1
    writeArray forest b rep1
    writeArray rank rep1 (rank1+rank2)
    return ((forest,rank), acc+d)
   else do
    writeArray forest rep1 rep2
    writeArray forest a rep2
    writeArray rank rep2 (rank1+rank2)
    return ((forest,rank), acc+d)    
  else do
   return ((forest,rank), acc)

main = do
 getLine
 xys <- intPairs <$> B.getContents
 ret <- snd <$> kruskalIO (mkedge xys)
 print ret

mkedge xys = (n,edge)
 where
  xyis = zip (snub xys) [0..]
  n = length xyis
  xysx = sortOn fst xyis
  xysy = sortOn (snd.fst) xyis
  edgex = zipWith make xysx (tail xysx)
  edgey = zipWith make xysy (tail xysy)
  edge = sortOn snd (edgex ++ edgey)

make ((xi,yi),i) ((xj,yj),j) = ((a,b),d)
 where
  a = min i j
  b = max i j
  d = min (abs (xj-xi)) (abs (yj-yi))

snub = S.toList . S.fromList
intPairs = map ((\[x,y]->(x,y)) . map (fst . fromJust . B.readInt) . B.words) . B.lines
untilFixM f x0 = f x0 >>= \x -> if x == x0 then return x else untilFixM f x

Measured memory_bytes: 120188
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const ll INFL = 1LL<<60;

void warshall_floyd(const int& V, vector<vector<int>>& d) {
  rep(k, V) rep(i, V) rep(j, V) chmin(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> d(n, vector<int>(n,INF));
  rep(i,n) d[i][i] = 0;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    d[a][b] = d[b][a] = c;
  }
  warshall_floyd(n, d);  // 各町の間の最短間距離を求める

  vector<vector<int>> dd(n, vector<int>(n, INF));
  rep(i, n) rep(j, n) {
    if (d[i][j] <= l) dd[i][j]  = 1;  // 補給無しで行ける経路間に重さ1の辺を張る
  }

  warshall_floyd(n, dd);  // 各町の間の最小補給回数を求める

  int q;
  cin >> q;
  rep(i, q) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    if (dd[s][t] == INF) {
      cout << -1 << endl;
    } else {
      cout << dd[s][t] - 1 << endl;  // -1 はスタート時に補給無しで満タンだから
    }
  }

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
 
#define INF 987654321
#define IINF 2987654321987654321
#define MOD 1000000007


int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d", (a-1)/b + 1);
}

Measured memory_bytes: 256
import itertools
N = int(input())
num = [i for i in range(N)]
lst = [list(map(int,input().split())) for i in range(N)]
routes = list(itertools.permutations(num))
sum_route = 0
for route in routes:
  for i in range(len(route) - 1):
    x1 = lst[route[i]][0]
    y1 = lst[route[i]][1]
    x2 = lst[route[i+1]][0]
    y2 = lst[route[i+1]][1]
    sum_route += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(sum_route / len(routes))


Measured memory_bytes: 47724
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      a: i64,
      b: i64,
      h: [i64; n]
   }

   let mut high = 1000000000_i64;
   let mut low = 0;
   while high - low > 1 {
      let mid = (high + low) / 2;
      let mut c = 0;
      for i in 0..n {
         if h[i] > b * mid {
            c += (h[i] - b * mid - 1) / (a - b) + 1
         }
      }
      if c <= mid {
         high = mid;
      } else {
         low = mid;
      }
   }
   println!("{}", high);
}


Measured memory_bytes: 3808
import java.io.*;
// import java.math.*;
import java.util.*;
import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] S = reader.readLine().split ("");
        Counter<String> c = new Counter<String>();
        Arrays.stream (S).forEach (v -> c.add (v));
        System.out.println (c.size() == 2 && c.get (S[0]) == 2 ? "Yes" : "No");
        return;
    }
}

// JDK 1.8 Map.getOrDefault
class Counter<T> {
    private Map<T, Integer> map = new HashMap<>();

    public void add (T key) {
        int v = get (key);
        map.put (key, v + 1);
    }

    public int get (T key) {
        return map.getOrDefault (key, 0);
    }

    public Set<T> keySet() {
        return map.keySet();
    }

    public Set<Entry<T, Integer>> entrySet() {
        return map.entrySet();
    }

    public Collection<Integer> values() {
        return map.values();
    }

    public int size() {
        return map.size();
    }
}

Measured memory_bytes: 33876
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);

 int a; cin >> a;
 cout << a + a*a + a*a*a << endl;

  return 0;
}


Measured memory_bytes: 3656
n = int(input())

red = []
blue = []
ed = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))

inf = 10**30

node = n*2+2

for i in range(1,n+1):
    ed.append([0,i,1])
    ed.append([n+i,2*n+1,1])
    
for i in range(n):
    for j in range(n):
        if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:
            ed.append([i+1,j+n+1,1])
    


edge = len(ed)
start = 0
goal = 2*n+1

# coding: utf-8
import queue

class Dinic:
    """Implementation of Dinic's Alogorithm"""

    def __init__(self, v, inf = 10**20):
        self.V = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [0 for _ in range(v)]
        self.iter = [0 for _ in range(v)]

    def add_edge(self, from_, to, cap):
        # to: 行き先, cap: 容量, rev: 反対側の辺
        self.G[from_].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
        self.G[to].append({'to':from_, 'cap':0, 'rev':len(self.G[from_])-1})

    # sからの最短距離をbfsで計算
    def bfs(self, s):
        self.level = [-1 for _ in range(self.V)]
        self.level[s] = 0;
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e['cap'] > 0 and self.level[e['to']] < 0:
                    self.level[e['to']] = self.level[v] + 1
                    que.put(e['to'])

    # 増加バスをdfsで探す
    def dfs(self, v, t, f):
        if v == t: return f
        for i in range(self.iter[v], len(self.G[v])):
            self.iter[v] = i
            e = self.G[v][i]
            if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
                d = self.dfs(e['to'], t, min(f, e['cap']))
                if d > 0:
                    e['cap'] -= d
                    self.G[e['to']][e['rev']]['cap'] += d
                    return d

        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            # bfsで到達不可
            if self.level[t] < 0 : return flow
            self.iter = [0 for _ in range(self.V)]
            f = self.dfs(s, t, self.inf)
            while f > 0:
                flow += f
                f = self.dfs(s,t, self.inf)
                
dinic = Dinic(node)
for e in ed:
    dinic.add_edge(e[0],e[1],e[2])
print(dinic.max_flow(start,goal))

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

int main(){
  vector<int> num(4);
  for(int i=0; i<4; ++i){
    char tmp;
    cin >> tmp;
    num.at(i) = (int)tmp;
  }
  
  sort(num.begin(), num.end());
  if(num.at(0)==num.at(1) && num.at(2)==num.at(3) && num.at(1)!=num.at(2)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  
  return 0;
}


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

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

	string str2;
	int size = (int)str.size();
	str2.resize(size);
	for(int i =0; i<size;++i)
	{
		str2[size-1-i] = str[i];
	}

	cout << str2 << endl;
	return(0);
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


//for(i=0; i<N; i++) cin >> a[i];


ll N, K;
double a[MAX*2];

ll ok(double X) {
  ll i;
  ll res=0;
  for(i=0; i<N; i++) {
    res+=(ll)(a[i]/X);
    
    if(((ll)X==X) && ((ll)a[i]==a[i]) && ((ll)a[i]%(ll)X==0)) res--;
  }
  
  return res<=K;
}


int main(void) {
  ll i, j, k;
  
  cin >> N >> K;
  for(i=0; i<N; i++) cin >> a[i];
  
  double l=0, r=1e9;
  for(i=0; i<100; i++) {
    double m=(l+r)/2;
    if(ok(m)) r=m;
    else l=m;
  }
  
  pt((ll)ceil(l));
}




Measured memory_bytes: 5372
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int INF = 100000;

int main(void) {
    int H,W;
    cin >> H >> W;
    int c[10][10];
    for (int i=0; i<10; i++) {
        for (int j=0; j<10; j++) cin >> c[i][j];
    }
    int A[H][W];
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) cin >> A[i][j];
    }

    // ダイクストラ法
    int min[10];
    for (int i=0; i<10; i++) {
        vector<int> d(10, INF);
        vector<bool> used(10, false);
        d[i] = 0;
        priority_queue<P, vector<P>, greater<P> > q;
        q.push(P(0, i));
        while (!q.empty()) {
            int dis,to;
            tie(dis, to) = q.top(); q.pop();
            if (used[to]) continue;
            used[to] = true; d[to] = dis;
            for (int j=0; j<10; j++) {
                if (d[j] <= dis + c[to][j]) continue;
                q.push(P(dis + c[to][j], j));
            }
        }
        min[i] = d[1];
    }

    int ans = 0;
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (A[i][j] == -1) continue;
            ans += min[A[i][j]];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
//kmcode
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n;
vector<ll> d;
vector<int> v[100002];
map<ll,int> ret;
int siz[100002];
bool vis[100002];
ll dp[100002];
int cnt[100002];
inline void die(){
    puts("-1");
    exit(0);
}
inline void dfs(int b,int pr=-1){
    cnt[b]++;
    vis[b]=1;
    for(int i=0;i<v[b].size();i++){
        int go=v[b][i];
        if(go==pr) continue;
        if(vis[go])
            die();
        dfs(go,b);
        dp[b]+=dp[go]+cnt[go];
        cnt[b]+=cnt[go];
    }
}
ll ans[100001];
inline void dfs2(int b,int pr=-1,ll weight=0){
    ans[b]=dp[b]+weight;
    weight+=dp[b];
    for(int i=0;i<v[b].size();i++){
        int go=v[b][i];
        if(go==pr) continue;
        dfs2(go,b,weight-dp[go]-cnt[go]+(n-cnt[go]));
    }
}
vector<pii> ed;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        d.pb(a);
        ret[a]=i;
    }
    for(auto it=ret.rbegin();it!=ret.rend();it++){
        int node=(*it).se;
        ll val=(*it).fi;
        siz[node]++;
        ll op=n-siz[node];
        if(op==0) continue;
        ll nex=val+siz[node]-op;
        if(!ret.count(nex))
            die();
        int ne=ret[nex];
        siz[ne]+=siz[node];
        v[ne].pb(node);
        v[node].pb(ne);
        ed.pb(mp(ne+1,node+1));
    }
    dfs(0);
    dfs2(0);
    for(int i=0;i<n;i++){
        if(vis[i]==0)
            die();
        if(ans[i]!=d[i])
            die();
    }
    for(int i=0;i<ed.size();i++)
        cout<<ed[i].fi<<" "<<ed[i].se<<endl;
    return 0;
}

Measured memory_bytes: 21108
n, l = input().split()
n,l = int(n),int(l)
taste = []
for i in range(n):
    taste.append(l+i)
min_diff = 100000
for i in range(n):
    total_n = sum(taste) - taste[i]
    diff = abs(sum(taste)-total_n)
    if diff < min_diff:
        min_diff = diff
        min_total = total_n
print(min_total)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){

  int c=0;
  char d;
  double in1,in2,sum1=0,sum2=0,ave=0;
  while(cin >> in1 >> d >> in2!='\0'){
    sum1+=in2;
    sum2+=in1*in2;
    c++;
  }
  ave=sum1/c;
  if(ave-(int)ave>=0.5) ave+=1;

  cout << sum2 << endl << (int)ave << endl;

}

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

int main() {
int  N,X,T,sum;
    cin >> N >> X >> T ;
  if (N%X==0){
  sum =N/X*T;
  }
   else {
   sum = (N/X+1)*T;
   }
  cout << sum << endl;  
}


Measured memory_bytes: 3616
#include <stdlib.h>
#include <stdio.h>
#define N 100000
typedef struct{
    long data,kaisu;
}data;
int cmp(const void *a,const void *b){
    return ((data*)a)->data-((data*)b)->data;
}
int main(void){
    data a[N];
    long n,k,i,j,c,d;
    long dat,kai;
    scanf("%ld %ld",&n,&k);
    for(i=0;i<n;i++){
        scanf("%ld %ld",&dat,&kai);
        a[i].data=dat;
        a[i].kaisu=kai;
    }
    qsort(a,n,sizeof(data),cmp);
    //for(i=0;i<n;i++)printf("%d %d\n",a[i].data,a[i].kaisu);
    i=0;
    while(1){
        k-=a[i].kaisu;
        if(k<=0)break;
        i++;
    }
    printf("%ld\n",a[i].data);
    return 0;
}

Measured memory_bytes: 3324
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fast ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define ls (rt<<1)
#define rs (rt<<1|1)
#define All(a) (a).begin(),(a).end()
#define clr(a) memset((a),0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,a,b) for(int i=(a);i>=(b);--i)
#define FOR_edge(i,u)  for(int i=hd[u];i;i=e[i].nxt)
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,-1,1};

inline char in() {
	static char buf[10001],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,10000,stdin),p1==p2)?EOF:*p1++;
}
template <class Tp> inline void read(register Tp &s) {
	s=0;
	register bool neg=0;
	register char c;
	while(!isdigit(c=in())) if(c=='-') neg=1;
	while(s=(s<<3)+(s<<1)+c-48,isdigit(c=in()));
	s=(neg?-s:s);
}
template <class Tp> inline void write(register Tp x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
template <class Tp> inline void print(const Tp &x,const char &end) {write(x); putchar(end);}
template <class Tp> inline Tp pow(register Tp x,register Tp p,const Tp &mod) {
	register Tp res=1;
	for(;p;p>>=1,x=(x*x)%mod) if(p&1) res=(res*x)%mod;
	return res;
}
inline int comp(const double &x,const double &y) {
	const double d=x-y,eps=1e-8;
	return (d<=eps&&d>=-eps)?0:(d>eps?1:-1);
}
template <class Tp> inline Tp sqr(const Tp &x) {return x*x;}
template <class Tp> inline Tp gcd(const Tp &x,const Tp &y) {return(y==0?x:gcd(y,x%y));}
template <class Tp> inline Tp inv(const Tp &x,const Tp &MOD) {return POW(x,MOD-2,MOD);}
template <class Tp> inline Tp lowbit(const Tp &x) {return x&-x;}

int a[4];
int main() {
	read(a[1]); read(a[2]); read(a[3]);
	sort(a+1,a+4);
	int ans=inf;
	do{
		ans=min(ans,abs(a[2]-a[1])+abs(a[3]-a[2]));
	}while(next_permutation(a+1,a+4));
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;

ll n;

signed main(){
//	freopen("PERFECT1.inp","r",stdin);
//	freopen("PERFECT1.out","w",stdout);
//	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	cout << n*n*n;
}


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

using namespace std;

using ll = long long;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repn(i,n)  rep(i,0,n)

const double EPS = 1e-5;
const int MOD = 1e9+7;

const int N = 1e3;
int p[N]; //backet

int n;

int prime_judge(int num){
  //numが2であった場合
  if(num == 2){
    return 1;
  }

  //numが偶数であった場合
  if(num % 2 == 0){
    return 0;
  }

  //numが奇数であった場合
  for(int j = 3; j < sqrt(num); j = j + 2){
    if(num % j == 0){
      return 0;
    }
  }
  return 1;
}


int main(){
  int n;
  ll res = 1;

  cin >> n;
  //2 ~ nについて
  rep(i,2,n+1){
    //それ以下の数の素数を求める
    int j = 2;
    int num = i;
    while(num > 1){
      //素数であって約数である場合は
      if(prime_judge(j) == 1 && (num % j == 0)){
          p[j]++;
          num = num / j;
        //cout << num << endl;
      //素数でない場合は
      }else{
        j++;
      }
    }
  }

  rep(i,2,n + 1){
    (res *=(p[i] + 1)) %= MOD;
  }
  /*
  repn(i,n+1){
    cout << i << " " << p[i] << endl;
  }
  */

  cout << res << endl;

  return 0;


}


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

int N;
vector<double> a;

int main() {
    cin>>N;
    a.resize(N);
    double sum=0;
    for (int i=0; i<N; i++) {
        cin>>a[i];
        sum+=pow(a[i],-1);
    }
    cout<<pow(sum,-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" );
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+9, LINF = 1e18;


int main()
{
    ll n,a,b,x,y,ans=0;
    cin>>n>>a>>b>>y;
    rep(i,n-1){
        cin>>x;
        ans+=min((x-y)*a,b);
        y=x;
    }
    cout<<ans<<endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
using namespace std;

int t[100000];
int x[100000];
int y[100000];

int main() {
	int K;
	cin >> K;
	for (size_t i = 0; i < K; i++)
	{
		cin >> t[i] >> x[i] >> y[i];
	}
	
	int ct = 0;
	int cx = 0, cy = 0;
	for (size_t i = 0; i < K; i++)
	{
		int d = abs(cx - x[i]) + abs(cy - y[i]);
		int dt = t[i] - ct;
		if (d <=  t[i] && (((dt - d) % 2) == 0)) {
			cx = x[i];
			cy = y[i];
			ct = t[i];
		}
		else {
			cout << "No";
			goto END;
		}
	}
	cout << "Yes";
	END:
	return 0;
}


Measured memory_bytes: 1408
x=int(input())
count=10000
for a in range(1, x):
    suma=0
    sumb=0
    b=x-a
    while (a > 0):
        suma += a%10
        a= a//10
    while (b > 0):
        sumb += b%10
        b=b//10
    count = min(count, suma+sumb)
print(count)

Measured memory_bytes: 3064
program C
read*,ix,in

if (in==0)then
print*,ix
goto 30
end if
call sub(ix,in)
30 end program

subroutine sub(ix,in)
integer::na(1:in)
read*,(na(j),j=1,in)
ii=0
ij=0
do ixd=0,1000
ii=0
ij=0
 do k=1,in
  if ((ix-ixd)==(na(k)))then
  ii=1
  end if
    if ((ix+ixd)==(na(k)))then
  ij=1
  end if
  end do
  if (ii==0)then
   print*,ix-ixd
   goto 40
   end if
    if (ij==0)then
   print*,ix+ixd
   goto 40
   end if
 end do
40 end subroutine

Measured memory_bytes: 2796
from collections import deque

S = list(input())
d = deque(S)
Q = int(input())
r_flag = 0

def top(d,C,r_flag):
    if r_flag:
        d.append(C)
    else:
        d.appendleft(C)

def bottom(d,C,r_flag):
    if r_flag:
        d.appendleft(C)
    else:
        d.append(C)

for i in range(Q):
    tmp = list(input().split())
    if tmp[0] == "1":
        if r_flag == 0:
            r_flag = 1
        else:
            r_flag = 0
    else:
        if tmp[1] == "1":
            top(d,tmp[2],r_flag)
        else:
            bottom(d,tmp[2],r_flag)

d = list(d)
if r_flag:
    d.reverse()
print("".join(d))

Measured memory_bytes: 9460
lastDayofLastMonth = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]
dateList = ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]
inputData = []

while True:
    inputData = list(map(int, input().split()))
    if inputData[0]==0:
        break
    dd_date = lastDayofLastMonth[inputData[0]-1] + inputData[1]
    print(dateList[dd_date%7])



Measured memory_bytes: 5596
n,k=map(int,input().split())
nlst = [0]*n
total = 0
for i in range(k):
    d = int(input())
    List = [int(i) for i in input().split()]
    for num in List:
        nlst[num-1] += 1
for ans in nlst:
    if ans == 0:
        total += 1
print(total)

Measured memory_bytes: 9204
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using Graph=vector<vector<int>>;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}


signed main(){
	int N;cin>>N;
	vector<P> V(N);
	vector<int> T(N);
	rep(i,N) cin>>T[i];
	V[N-1]=P(T[0],T[0]);
	rep(i,N-1){
		if(T[i+1]>T[i]) V[N-i-2]=P(T[i+1],T[i+1]);
		else V[N-i-2]=P(0,T[i]);
	}
	vector<int> A(N);
	rep(i,N) cin>>A[N-i-1];
	V[0].first=max(A[0],V[0].first);
	V[0].second=min(A[0],V[0].second);
	rep(i,N-1){
		if(A[i+1]>A[i]){
			V[i+1].first=max(A[i+1],V[i+1].first);
			V[i+1].second=min(A[i+1],V[i+1].second);
		}
		else{
			V[i+1].second=min(A[i],V[i+1].second);
		}
	}
	//rep(i,N) cout<<V[i].first<<" "<<V[i].second<<endl;
	int ans=1;
	rep(i,N){
		int state=(V[i].first!=0);
		ans*=max(0LL,V[i].second-V[i].first+state);
		ans%=mod;
		}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328