akhauriyash/Code-Regression huggingface dataset:
/*  Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+10;

int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
        return gcd(m%n,n);
}
int32_t main()
{
    IOS;
    string s,t;
    cin>>s>>t;
    set<int>st[30];
    for(int i=1;i<=s.size();i++)
    {
        st[s[i-1]-'a'].insert(i);
    }
    int curr=1;
    int sum=0;
    for(int i=0;i<t.size();i++)
    {
        if(curr==1)
        {
            if(st[t[i]-'a'].lower_bound(curr)==st[t[i]-'a'].end())
            {
                cout<<"-1"<<endl;
                return 0;
            }
            else
            {
                sum+=*st[t[i]-'a'].lower_bound(curr)-curr+1;
                //cout<<"! "<<*st[t[i]-'a'].lower_bound(curr)-curr+1<<endl;
                curr=*st[t[i]-'a'].lower_bound(curr)+1;
            }
        }
        else
        {
            if(st[t[i]-'a'].lower_bound(curr)==st[t[i]-'a'].end())
            {
                sum+=s.size()-curr+1;
                curr=1;
                if(st[t[i]-'a'].lower_bound(curr)==st[t[i]-'a'].end())
                {
                    cout<<"-1"<<endl;
                    return 0;
                }
                else
                {
                    //cout<<"!! "<<*st[t[i]-'a'].lower_bound(curr)-curr+1<<endl;
                    sum+=*st[t[i]-'a'].lower_bound(curr)-curr+1;
                    curr=*st[t[i]-'a'].lower_bound(curr)+1;
                }
            }
            else
            {
                //cout<<"!!! "<<*st[t[i]-'a'].lower_bound(curr)-curr+1<<endl;
                sum+=*st[t[i]-'a'].lower_bound(curr)-curr+1;
                curr=*st[t[i]-'a'].lower_bound(curr)+1;
            }
        }
    }
    cout<<sum<<endl;

    


}

Measured memory_bytes: 5200
N, M = map(int, input().split())
aset = set([int(input()) for _ in range(M)])
dp = [0] * (N + 1)
dp[0] = 1
for i in range(N):
    for j in range(i + 1, min(N, i + 2) + 1):
        if j not in aset:
            dp[j] += dp[i]
            dp[j] %= 10**9 + 7
print(dp[N])


Measured memory_bytes: 13216
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let ret = match line.trim() {
        "Sunny" => "Cloudy",
        "Cloudy" => "Rainy",
        "Rainy" => "Sunny",
        _ => panic!()
    };
    println!("{}", ret);
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)
	var h, p int
	fmt.Scan(&p)
	t := 0
	ans := 0
	for i := 1; i < N; i++ {
		fmt.Scan(&h)
		if h <= p {
			t++
		} else {
			t = 0
		}
		p = h
		ans = int(math.Max(float64(ans), float64(t)))
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char b;
    cin>>b;
    if(b=='A')cout<<'T'<<endl;
    if(b=='T')cout<<'A'<<endl;
    if(b=='C')cout<<'G'<<endl;
    if(b=='G')cout<<'C'<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
ll xorall(ll x){
	vector<ll> v = {x,1,x+1,0};
	return v[x%4];
}
int main() {
	ll A,B;
	cin>>A>>B;
	ll ans = xorall(A-1)^xorall(B);
	if(A == 0){
		ans = xorall(B);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

string s;
int ans = 0;
char op_tmp[3], op_ans[3];

void sum_num(int sum, int l, char op){
    if(l>0) op_tmp[l-1] = op;
    if(l == 3){
        if(op_tmp[2] == '+' && sum == 7){
            for(int i=0; i<3; i++){
               op_ans[i] = op_tmp[i]; 
            } 
            return;
        }
        else if(op_tmp[2] == '-' && sum == 7){
            for(int i=0; i<3; i++) {
                op_ans[i] = op_tmp[i];
            }
            return;
        }
        else{
            return;
        }
    }

    sum_num(sum+(s[l+1]-'0'), l+1, '+');
    sum_num(sum-(s[l+1]-'0'), l+1, '-');

}

int main(){

    cin >> s;

    sum_num(s[0]-'0',0,'0');

    cout << s[0] << op_ans[0] << s[1] << op_ans[1] << s[2] << op_ans[2] << s[3] << "=7" << endl;  
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
long double ep[1001];
int p[200001];
long double wa[200001];

int main() {
  int n,k;
  cin >> n >> k;
  cout << fixed << setprecision(10) ;
  ep[0] = 0;
  for(int i = 1;i <n+1;i++){
    cin >> p[i];
  }
  
  for(int i = 1;i < 1001;i++){
    ep[i] = ep[i-1] + i;
     //cout << ep[i] /i << endl;
  }
  wa[0] = 0;
  for(int i = 1;i < n+1;i++){
    wa[i] = (ep[p[i]])/p[i] + wa[i-1];
    //cout << ep[p[i]] << " " << p[i] <<" " << (ep[p[i]])/p[i] << endl;
    //cout << wa[i] << endl;
  }
  long double res = 0;
  for(int i = k;i < n+1;i++){
    res = max(res,wa[i] - wa[i-k])  ;
  }
  cout << res;
  
}

Measured memory_bytes: 7652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define all(v) v.begin(), v.end()
#define reall(v) v.rbegin(), v.rend()
using ll = long long;
using P = pair<int,int>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> p;
  vector<int> m;
  rep(i,n){
    cin >> a[i];
    if(a[i] >= 0) {p.push_back(a[i]);}
    else {m.push_back(a[i]);}
  }
  int s = p.size();
  int t = m.size();
  bool plus = false;

  if(s>0){
    if(k == n) plus = (t%2 == 0);
    else plus = true;
  }else{
    plus = (k%2 == 0);
  }

  mint ans = 1;
  if (!plus){
    sort(all(a), [](int x, int y){
      return abs(x) < abs(y);
    });
    rep(i,k) ans *= a[i];
  }else{
    sort(all(p));
    sort(reall(m));
    if (k%2 == 1) {
      ans *= p.back();
      p.pop_back();
    }
    vector<ll> pp;
    while(p.size() >= 2){
      ll x = p.back(); p.pop_back();
      x *= p.back(); p.pop_back();
      pp.push_back(x);
    }
    while(m.size() >= 2){
      ll x = m.back(); m.pop_back();
      x *= m.back(); m.pop_back();
      pp.push_back(x);
    }
    sort(reall(pp));
    rep(i,k/2) ans *= pp[i];
  }

  cout << ans << endl;

  return 0;
} // 通ってないよ！


Measured memory_bytes: 6420
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val c1 = sc.next
    val c2 = sc.next

    val ans = if (c1 == c2.reverse) {
      "YES"
    } else {
      "NO"
    }

    println(ans)

  }
}


Measured memory_bytes: 25916
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int b = 0;

		if (1 < k) {
			b = n - k;
		} else {
			b = 0;
		}
		System.out.println(b);

	}

}


Measured memory_bytes: 23124
def solve(N, X, L):
    x = 0
    c = 1
    for l in L:
        x += l
        if x > X:
            break
        c += 1
    return c

def main():
    N, X = [int(x) for x in input().split()]
    L = [int(x) for x in input().split()]
    print(solve(N, X, L))
    pass
main()


Measured memory_bytes: 2940
import java.util.*;


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

    int N = sc.nextInt();
    int result = 0 ;

    for(int i = 0 ; i <  N ; i ++ ){
      int l = sc.nextInt();
      int r = sc.nextInt();
      result = result + ( r - l + 1 );
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 25300
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 1000000000000
typedef long long ll;
using namespace std;

int main(){
  int m[60][60]={};
  int h,w;

  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      char t;
      cin>>t;
      if(t=='#'){
        m[i][j]=-1;
        for(int k=i-1;k<=i+1;k++){
          for(int l=j-1;l<=j+1;l++){
            if(m[k][l]!=-1)m[k][l]++;
          }
        }
      }
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(m[i][j]==-1)printf("#");
      else printf("%d",m[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 256
import heapq


class MinCostFlow:
    class Edge:
        def __init__(self, to, cap, rev, cost):
            self.to, self.cap, self.rev, self.cost = to, cap, rev, cost

    def __init__(self, V):
        self.V = V
        self.E = [[] for _ in range(V)]

    def add_edge(self, fr, to, cap, cost):
        self.E[fr].append(self.Edge(to, cap, len(self.E[to]), cost))
        self.E[to].append(self.Edge(fr, 0, len(self.E[fr])-1, -cost))

    def run(self, source, sink, f, INF=10**5):
        res = 0
        h, prevv, preve = [0] * self.V, [0] * self.V, [0] * self.V
        while (f > 0):
            pque = []
            dist = [INF] * self.V
            dist[source] = 0
            heapq.heappush(pque, (0, source))
            while pque:
                cost, v = heapq.heappop(pque)
                cost = -cost
                if dist[v] < cost:
                    continue
                for i, e in enumerate(self.E[v]):
                    if e.cap > 0 and dist[v] - h[e.to] < dist[e.to] - e.cost - h[v]:
                        dist[e.to] = dist[v] + e.cost + h[v] - h[e.to]
                        prevv[e.to], preve[e.to] = v, i
                        heapq.heappush(pque, (-dist[e.to], e.to))
            if dist[sink] == INF:
                return -1
            for v in range(self.V):
                h[v] += dist[v]

            d, v = f, sink
            while v != source:
                d = min(d, self.E[prevv[v]][preve[v]].cap)
                v = prevv[v]
            f -= d
            res += d * h[sink]
            v = sink
            while v != source:
                self.E[prevv[v]][preve[v]].cap -= d
                self.E[v][self.E[prevv[v]][preve[v]].rev].cap += d
                v = prevv[v]
        return res

V, E, F = map(int, input().split())
mcf = MinCostFlow(V)
for _ in range(E):
    u, v, c, d = map(int, input().split())
    mcf.add_edge(u, v, c, d)
print(mcf.run(0, V - 1, F))

Measured memory_bytes: 8368
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val r = hashMapOf<String, Int>()
    repeat(n) {
        val s = readLine() ?: return
        r[s] = r[s]?.let { it + 1 } ?: 1
    }
    buildString {
        appendln("AC x ${r["AC"] ?: 0}")
        appendln("WA x ${r["WA"] ?: 0}")
        appendln("TLE x ${r["TLE"] ?: 0}")
        appendln("RE x ${r["RE"] ?: 0}")
    }.let {
        println(it.trimIndent())
    }
}


Measured memory_bytes: 61572
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
    char s[1000000];
    char t[1000000];
    int op = 0, tamanho = 0;
    scanf("%s", s);
    scanf("%s", t);
    tamanho = strlen(s);
    for(int i = 0; i < tamanho; ++i){
        if(s[i] != t[i])
            op +=1;
    }
    printf("%d", op);

    return 0;
}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
#define Pb push_back
using namespace std;
typedef long long ll;
const int MAXN = 5e3 + 7, Mod = 1e9 + 7;
inline int Mop ( int na ) { return na >= Mod ? na - Mod : na; }
inline int R()
{
    int rt = 0; char ch = getchar(); bool isn = false;
    for ( ; ch < '0' || ch > '9'; ch = getchar() ) isn = ch == '-' ? true : isn;
    for ( ; ch >= '0' && ch <= '9'; ch = getchar() ) rt = rt * 10 + ch - '0';
    return isn ? -rt : rt;
}

vector<int> e[MAXN];
ll tp[MAXN], dp[MAXN][MAXN], g[MAXN];
int sz[MAXN], n;

void Dfs ( int nf, int nfa )
{
	dp[nf][1] = 1, sz[nf] = 1;
	for ( auto to : e[nf] )
	{
		if ( to == nfa )
			continue;
		Dfs ( to, nf );
		for ( int i = 0; i <= sz[nf] + sz[to]; ++i )
			tp[i] = 0;
		for ( int i = 1; i <= sz[nf]; ++i )
			for ( int j = 0; j <= sz[to]; ++j )
				tp[i + j] = Mop ( tp[i + j] + dp[nf][i] * dp[to][j] % Mod );
		sz[nf] += sz[to];
		for ( int i = 0; i <= sz[nf]; ++i )
			dp[nf][i] = tp[i];	
	}
	for ( int i = 2; i <= sz[nf]; i += 2 )
		dp[nf][0] = Mop ( dp[nf][0] + Mod - dp[nf][i] * g[i] % Mod );
}

int main()
{
	n = R();
	for ( int i = 1; i < n; ++i )
	{
		int u = R(), v = R();
		e[u].Pb ( v ), e[v].Pb ( u );
	}
	g[2] = 1;
	for ( int i = 4; i <= n; i += 2 )
		g[i] = g[i - 2] * ( i - 1 ) % Mod;
	Dfs ( 1, 0 );
	printf ( "%lld\n", Mop ( Mod - dp[1][0] ) );
	return 0;
}

Measured memory_bytes: 195200
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new java.util.Scanner(System.in);
		String s, p;

		s = sc.next();
		p = sc.next();

		if ((s+s).contains(p)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}



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

int main(){
  int ABC[3];
  for(int i = 0; i < 3; i++){
    cin >> ABC[i];
  }

  int cnt[10] = {};
  for(int i = 0; i < 3; i++){
    cnt[ABC[i]]++;
  }

  bool ans = false;
  for(int i = 0; i <= 9; i++){
    if(cnt[i] == 2){
      ans = true;
    }
  }

  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 888
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val in2 = in.map(_.split(' ').map(_.toLong).toIndexedSeq)
  val A = in2(1)
  val B = in2(2)
  
  private def func():Int = {
    val asum = A.sum
    val bsum = B.sum
    val dsum = asum - bsum
    if(dsum < 0) return -1
    if(A.indices.forall(i => A(i) >= B(i) )) return 0
    
    val d = A.indices.map(i => A(i) - B(i) )
    val dsorted = d.sorted
    
    var count=0
    var i=0
    var j=0
    var dtmp = dsum
    while(i < dsorted.size){
      //if(dsorted(i) > 0){
      //  count += 1
      //}
      if(dsorted(i) > 0){
        dtmp -= dsorted(i)
        if(dtmp > 0) count += 1
      }
      i += 1
      j -= 1
    }
	dsorted.size - count
  }
  val ret = func()
  println(ret)
}


Measured memory_bytes: 72616
#include <iostream>
#include <cstdio>
using namespace std;
int w, h, n;

bool rectangle[100][100];

void draw(int x, int y, int a){
    if(a == 1){
        for(int j = 0; j < h; j++){
            for(int i = 0; i < x; i++){
                rectangle[j][i] = false;
            }
        }
    }
    else if(a == 2){
        for(int j = 0; j < h; j++){
            for(int i = x; i < w; i++){
                rectangle[j][i] = false;
            }
        }
    }
    else if(a == 3){
        for(int j = 0; j < y; j++){
            for(int i = 0; i < w; i++){
                rectangle[j][i] = false;
            }
        }
    }
    else if(a == 4){
        for(int j = y; j < h; j++){
            for(int i = 0; i < w; i++){
                rectangle[j][i] = false;
            }
        }
    }
}

void init(){
    for(int j = 0; j < h; j++){
        for(int i = 0; i < w; i++){
            rectangle[j][i] = true;
        }
    }
}

int count(){
    int counter = 0;
    for(int j = 0; j < h; j++){
        for(int i = 0; i < w; i++){
            if(rectangle[j][i] == true){
                counter++;
            } 
        }
    }

    return counter;
}

void print(){
    for(int j = 0; j < h; j++){
        for(int i = 0; i < w; i++){
            printf("%d ", rectangle[j][i]);
        }
        printf("\n");
    }
    printf("\n");
}

int main(){
    cin >> w >> h >> n;

    init();
    //print();

    int x, y, a;

    for(int i = 0; i < n; i++){
        cin >> x >> y >> a;
        draw(x, y, a);
        //print();
    }

    //print();

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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}
int n,q;
hei(ll) seg, lazy;

void aaa(int k) {
	if (lazy[k] == 0)return ;
	if (k < n - 1) {
		lazy[k * 2 + 1] += lazy[k];
		lazy[k * 2 + 2] += lazy[k];
	}
	seg[k] += lazy[k];
	lazy[k] = 0;
}

void update(int a, int b, ll x,int k,int l,int r) {
	aaa(k);
	if (a<=l && b>=r) {
		lazy[k] += x;
		aaa(k);
	}
	else if(a<r&&l<b){
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		seg[k] = seg[k * 2 + 1]+seg[k * 2 + 2];
	}
}

ll query(int a,int b,int k,int l,int r){
	aaa(k);
	if (l >= b || r <= a)return 0;
	if (a <=l  && b >= r) {
		return seg[k];
	}
	ll v1 = query(a, b, k*2+1, l, (l + r) / 2);
	ll v2 = query(a, b, k*2+2, (l + r) / 2, r);
	return v1 + v2;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

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

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

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

int main() {
	int h, n;
	cin >> h >> n;
	hei(int) dp(h + 1, (int)INF);
	dp[0] = 0;
	rep(i, 0, n) {
		int a, b;
		cin >> a >> b;
		rep(j, 0, h + 1) {
			int x = min(h, a + j);
			dp[x] = min(dp[x], dp[j] + b);
		}
	}
	cout << dp[h] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.{util => ju}
import scala.collection.{mutable => mu}
import MyPredef._


object Main extends App {
    val H,W = nextLong
    var h=Math.min(H,W)
    var w=Math.max(H,W)
    //val h=Math.max(H,W)
    //val w=Math.min(H,W)
    //val h=H
    //val w=W
    
    val res = if(h%3==0||w%3==0){
        0
    }else{
        var res = h
        
        (Math.max(w/3,0) to Math.min(w,w/3+1)).foreach(x => {
            val wx = w-x
            val h0 = h/2
            val h1 = h-h/2
            val can = Seq(x*h,wx*h0,wx*h1)
            res = Math.min(res,can.max-can.min)
        })
         
        (Math.max(h/3,0) to Math.min(h,h/3+1)).foreach(x => {
            val hx = h-x
            val w0 = w/2
            val w1 = w-w/2
            val can = Seq(x*h,hx*w0,hx*w1)
            res = Math.min(res,can.max-can.min)
        })
        
        h=Math.max(H,W)
        w=Math.min(H,W)
        
        (Math.max(w/3,0) to Math.min(w,w/3+1)).foreach(x => {
            val wx = w-x
            val h0 = h/2
            val h1 = h-h/2
            val can = Seq(x*h,wx*h0,wx*h1)
            res = Math.min(res,can.max-can.min)
        })
         
        (Math.max(h/3,0) to Math.min(h,h/3+1)).foreach(x => {
            val hx = h-x
            val w0 = w/2
            val w1 = w-w/2
            val can = Seq(x*h,hx*w0,hx*w1)
            res = Math.min(res,can.max-can.min)
        })
        
        res
    }
    
    println(res)
}


object MyPredef {
  @inline def rep(n: Int, f: => Unit): Unit = { var c = 0; while (c < n) { f; c += 1 } }
  @inline def rep(n: Int, f: Int => Unit): Unit = { var c = 0; while (c < n) { f(c); c += 1 } }

  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}
object MyArray {
  def fillT[T : scala.reflect.ClassTag](dimX: Int, dimY: Int)(f: => T): Array[Array[T]] = {
    val arrs = Array.ofDim[T](dimX, dimY)
    for {
      y <- (0 until dimY)
      x <- (0 until dimX)
    } {
      arrs(x)(y) = f
    }
    arrs
  }
}

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

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

  long long h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) cout << 1 << '\n';
  else cout << (h*w+1) / 2 << '\n';
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define SORRY FUL Accepted 
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define Toktama Kazakhstan 

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;                                          
const int PRI = 555557;
const int pri = 997;

int tests = 1;
int n, a[N];

inline void Solve () {
	//easy
	cin >> n ;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}	

	int mx = *max_element(a + 1, a + 1 + n), x = 0, y = 0;
	for (int i = 1; i <= n; i ++) {
		if (a[i] == mx) x ++;
		else if(a[i] == mx - 1) y ++;
		else {
			cout << "No";
			exit(0);
		}
	}

	if (x == n) {
		if (mx == n - 1 || mx * 2 <= n) {
			cout << "Yes";
			exit(0);
		}
		cout << "No";
		exit(0);
	}

	if (y + 1 <= mx && mx <= x / 2 + y) {
		cout << "Yes";
		exit(0);
	}

	cout << "No";
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}

	return Accepted; 
}

Measured memory_bytes: 640
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    n.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn count_nunber_of_prime_number(v: &Vec<u32>) -> u32 {
    let mut ans = 0;
    for x in v {
        if is_prime(*x) {
            ans += 1;
        }
    }
    ans
}

fn is_prime(x: u32) -> bool {
    let mut ret = true;
    let sqrt_x = (x as f64).sqrt() as u32;
    for n in 2..sqrt_x + 1 {
        if x % n == 0 {
            ret = false;
        }
    }
    ret
}

fn main() {
    let n = read::<u32>();
    let mut v = Vec::<u32>::new();
    for _ in 0..n {
        let x = read::<u32>();
        v.push(x);
    }

    println!("{}", count_nunber_of_prime_number(&v));
}


Measured memory_bytes: 5036
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#include<deque>
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
int H,W,ch,dh,cw,dw,dis,h,w;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
tuple<int,int,int>now;
bool gone[1005][1005];
char s[1005][1005];
deque<tuple<int,int,int>> bfs;
int main(){
    scanf("%d%d",&H,&W);
    scanf("%d%d%d%d",&ch,&cw,&dh,&dw);
    for(int i=1;i<=H;i++)
        scanf("%s",s[i]+1);
    bfs.push_back({ch,cw,0});
    while(!bfs.empty()){
        now=bfs.front();
        tie(h,w,dis)=now;
        bfs.pop_front();
        if(h==dh&&w==dw){
            printf("%d",dis);
            return 0;
        }
        if(gone[h][w])
            continue;
        gone[h][w]=1;
        for(int i=0;i<=3;i++){
            int tx=h+dx[i],ty=w+dy[i];
            if(s[tx][ty]=='#'||tx<1||tx>H||ty<1||ty>W)
                continue;
            if(!gone[tx][ty])
                bfs.push_front({tx,ty,dis});;
        }
        for(int tx=h-2;tx<=h+2;tx++)
            for(int ty=w-2;ty<=w+2;ty++){
                if(s[tx][ty]=='#'||tx<1||tx>H||ty<1||ty>W)
                    continue;
                if(!gone[tx][ty])
                    bfs.push_back({tx,ty,dis+1});
            }
    }
    printf("-1");
}


Measured memory_bytes: 5860
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N,K;
    cin >> N >>K;
    int ans=0;
    while(N>=1){
        double D=N/K;
        N = D;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <map>
using namespace std;

long long N, M, fact[1000009], factinv[1000009], dp[33][100009], mod = 1000000007; vector<long long>vec;
bool used[3009][3009];

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 30; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

void init() {
	fact[0] = 1;
	for (int i = 1; i <= N; i++) fact[i] = (fact[i - 1] * i) % mod;
	for (int i = 0; i <= N; i++) factinv[i] = Div(1, fact[i], mod);
}

long long ncr(long long n, long long r) {
	if (r < 0 || n < r) return 0;
	return (fact[n] * factinv[r] % mod) * factinv[n - r] % mod;
}

int main() {
	cin >> N >> M; init();
	for (long long i = 1; i*i <= M; i++) {
		if (M%i != 0) continue;
		vec.push_back(i);
		vec.push_back(M / i);
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());


	for (int i = 0; i < vec.size(); i++) {
		for (int j = 0; j < vec.size(); j++) {
			if (vec[j] % vec[i] == 0 && j > i) used[i][j] = true;
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < 32; i++) {
		for (int j = 0; j < vec.size(); j++) {
			for (int k = 0; k < vec.size(); k++) {
				if (used[j][k] == true) {
					dp[i + 1][k] += dp[i][j];
					dp[i + 1][k] %= mod;
				}
			}
		}
	}
	long long sum = 0;
	for (int i = 0; i < 33; i++) {
		sum += ncr(N, i) * dp[i][vec.size() - 1];
		sum %= mod;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 37120
K,N = list(map(int, input().split()))
A_list = list(map(int, input().split()))

sub_A_list = A_list.copy()[1:]
sub_A_list.append(K + A_list[0])

for i in range(N):
    sub_A_list[i] -= A_list[i]

maxi = max(sub_A_list)
print(K - maxi)

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

long long solve(const string &S) {
    int N = S.size();
    vector<long long> val(2019, 0);
    long long fac = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        long long add = S[N-1-i] - '0';
        cur = (cur + fac * add) % 2019;
        fac = (fac * 10) % 2019;
        val[cur]++;
    }
    long long res = 0;
    for (int i = 0; i < val.size(); ++i) {
        res += val[i] * (val[i] - 1) / 2;
    }
    return res;
}

int main() {
    string S;
    cin >> S;
    cout << solve(S) << endl;
}


Measured memory_bytes: 3764
n = int(input())
a = [int(input()) for _ in range(n)]
s = set()
i, ans = 1, 0

while i != 2:
    if i in s:
        ans = -1
        break
    else:
        s.add(i)
        i, ans = a[i-1], ans+1
print(ans)

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

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

ll n,d,a;
ll ans;
ll ans2;

int main() {
  cin >> n >> d >> a;

  vector<P> x;
  for(int i = 0; i < n; i++) {
    ll X,H;
    cin >> X >> H;
    x.push_back(P(X,H));
  }

  sort(x.begin(),x.end());

  vector<ll> pos(n);
  for(int i = 0; i < n; i++) pos[i] = x[i].first;
  vector<ll> damage(n+1,0);

  int p = 0;

  while(p < n) {
    if(x[p].second > damage[p]) {
      // ll bomb = max((x[p].second - damage[p] - a)/a+1,1ll);
        ll bomb = max((x[p].second - damage[p] + a - 1),0ll) / a;
      ans += bomb;
      int tmp = upper_bound(pos.begin(),pos.end(),x[p].first + 2 * d) - pos.begin();
      damage[p] += bomb * a;
      damage[tmp] -= bomb * a;
    }
    p++;
    damage[p] += damage[p-1];
  }

  sort(x.begin(),x.end(),greater<P> ());
  for(int i = 0; i < n; i++) {
    pos[i] = -x[i].first;
    x[i].first = pos[i];
  }
  damage.assign(n+1,0);
 

   p = 0;

  while(p < n) {
    if(x[p].second > damage[p]) {
      ll bomb = max((x[p].second - damage[p] + a - 1),0ll) / a;
      ans2 += bomb;
      // cout << ans2 <<"   "<<x[p].first + 2 * d << endl;
      int tmp = upper_bound(pos.begin(),pos.end(),x[p].first + 2 * d) - pos.begin();
      damage[p] += bomb * a;
      damage[tmp] -= bomb * a;
    }
    p++;
    damage[p] += damage[p-1];
  }

  //  cout << ans << "    "<< ans2 << endl;
 cout << min(ans,ans2) << endl;

  
 // cout << ans << endl;
}
  


Measured memory_bytes: 7276
#include <stdio.h>

int main()
{
  int a, b, c, i, cnt = 0;
  scanf("%d %d %d", &a, &b, &c);
  for(i=a; i<b+1;i++){
    if(c%i == 0){
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A < 10 && B < 10) {
		cout << A * B << endl;
	}
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> S;
  N=S.size();
  if(N%2!=0)M=N/2+1;
  else M=N/2;
  if(N%2!=0)T=S.substr(M-1,M);
  else T=S.substr(M,M);
  S=S.substr(0,M);
  Rev(T);
  rep(i,0,M)if(S[i]!=T[i])sum++;

  Out(sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int n;

vi calc_BA(vi& a, vi& b){
    vi ret(n);
    int i = 0;
    int cnt = 0;
    rep(j, n){
        while(i < n and a[i] < b[j]){
            cnt++;
            i++;
        }
        ret[j] = cnt;
    }
    return ret;
}

vi calc_BC(vi& a, vi& b){
    vi ret(n);
    int j = n-1;
    int cnt = 0;
    rrep(i, n){
        while(j >= 0 and a[i] < b[j]){
            cnt++;
            j--;
        }
        ret[i] = cnt;
    }
    return ret;
}

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

    cin >> n;
    vi A(n), B(n), C(n);
    for(auto& e : A) cin >> e; sort(_all(A));
    for(auto& e : B) cin >> e; sort(_all(B));
    for(auto& e : C) cin >> e; sort(_all(C));

    vi BA = calc_BA(A, B);
    vi BC = calc_BC(B, C);

    ll res = 0LL;
    rep(i, n){
        ll cur = 1LL * BA[i] * BC[i];
        res += cur;
    }
    cout << res << endl;

    return 0;
}


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


int main(){
    string S, T;
    int cnt=0;
    cin>>S>>T;
    if(S.at(0)==T.at(0))cnt++;
    if(S.at(1)==T.at(1))cnt++;
    if(S.at(2)==T.at(2))cnt++;
    cout<<cnt<<endl;
    return 0;
}


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


#define M 36

typedef struct {
  char mark;
  int value;
} C;

void Bubble(C *, int);
void Selection(C *, int);
void disply(C *, int);
int Stable(C *, C *, int);

int main()
{
  C c1[M+1], c2[M+1];
  int i, N;

  scanf("%d", &N);



  for( i = 0 ; i < N ; i++ ){
    scanf(" %c%d", &c1[i].mark, &c1[i].value);
  }

  for( i = 0 ; i < N ; i++ ) c2[i] = c1[i];

  Bubble(c1, N);
  disply(c1, N);
  printf("Stable\n");

  Selection(c2, N);
  disply(c2, N);

  if( Stable(c1, c2, N) == 0 ) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}
void Bubble(C c1[], int N)
{
  int i, j;
  C t;

  for( i = 0 ; i < N ; i++ ){
    for( j = N-1 ; j > i ; j-- ){
      if( c1[j].value < c1[j-1].value ){
        t = c1[j];
        c1[j] = c1[j-1];
        c1[j-1] = t;
      }
    }
  }
}



void Selection(C c2[], int N)
{
  int i, j, minj;
  C t;

  for( i = 0 ; i < N ; i++ ){
    minj = i;
    for( j = i ; j < N ; j++ ){
      if( c2[j].value < c2[minj].value ) minj = j;
    }
    t = c2[i];
    c2[i] = c2[minj];
    c2[minj] = t;
  }
}


int Stable(C c1[], C c2[], int N)
{
  int i;

  for( i = 0 ; i < N ; i++ )
  if( c1[i].mark != c2[i].mark ) return 1;

  return 0;
}


void disply(C c[], int N)
{
  int i;

  for( i = 0 ; i < N ; i++ ){
    if( i > 0 ) printf(" ");
    printf("%c%d", c[i].mark, c[i].value);
  }
  printf("\n");
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const int MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main() {
	string S,T;
    cin >> S>>T;
    bool frag = true;
    rep(i,S.size()){
    	if(S[i]!=T[i]) frag = false;
    }
    if(frag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    cout << fixed << setprecision(10);
    LLI A, B, C, D;
    cin >> A >> B >> C >> D;
    LLI lcd = C / gcd(C, D) * D;
    cout << (B - A + 1) - B / C + (A - 1) / C - B / D + (A - 1) / D +
                B / (lcd) - (A - 1) / (lcd);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    int N = sc.nextInt();
    int M = sc.nextInt();
    int total = 0;
    int count = 0;

    int[] S = new int[N];
    
    for(int i = 0; i < N; i++) {
        int token = sc.nextInt();
        S[i] = token;
        total += token;
    }
    
    for(int i = 0; i < N; i++) {
        if( S[i] * 4 * M >= total) count++;
    }
    
    
    if(count >= M) {
        System.out.println("Yes");
    }else {
        System.out.println("No");
    }
  }
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

string s;

int dp[303030];

int rec2(int idx) {
  if(idx == s.size()) return 1;
  if(~dp[idx]) return dp[idx];
  int ret = 0;
  for(int i = 0; i < 2; i++) {
    if((s[idx] >> i) & 1) ret += rec2(idx + 1);
  }
  return dp[idx] = ret % mod;
}

int dp2[303030][3][3];

int rec1(int idx, int prefix, int prefixsz) {
  if(idx >= s.size()) return prefixsz == 1 && prefix == 1;
  if(~dp2[idx][prefix][prefixsz]) return dp2[idx][prefix][prefixsz];
  if(idx + 1 == s.size()) {
    if(prefixsz == 1) return false;
    return (s[idx] & 2) != 0;
  }
  int64 ret = 0;
  if(prefixsz == 0) {
    for(int i = 0; i < 2; i++) {
      for(int j = 0; j < 2; j++) {
        int k = (i << 1) | j;
        if((s[idx] >> i) & 1 && (s[idx + 1] >> j) & 1) {
          if(k == 0b00 && idx + 2 < s.size()) {
            for(int l = 0; l < 2; l++) if((s[idx + 2] >> l) & 1) ret += rec1(idx + 3, 0, 1);
          }
          if(k == 0b01) ret += rec1(idx + 2, 0, 0);
          if(k == 0b11) ret += rec2(idx + 2);
          if(k == 0b10 && idx + 2 < s.size()) {
            for(int l = 0; l < 2; l++) {
              if((s[idx + 2] >> l) & 1) {
                if(l == 0) {
                  if(idx + 3 < s.size()) {
                    for(int p = 0; p < 2; p++) {
                      if((s[idx + 3] >> p) & 1) ret += rec1(idx + 4, 2, 2);
                    }
                  }
                }
                if(l == 1) ret += rec1(idx + 3, 1, 1);
              }
            }
          }
        }
      }
    }
  } else if(prefixsz == 1) {
    for(int j = 0; j < 2; j++) {
      int k = (prefix << 1) | j;
      if((s[idx] >> j) & 1) {
        if(k == 0b00 && idx + 1 < s.size()) {
          for(int l = 0; l < 2; l++) if((s[idx + 1] >> l) & 1) ret += rec1(idx + 2, 0, 1);
        }
        if(k == 0b01) ret += rec1(idx + 1, 0, 0);
        if(k == 0b11) ret += rec2(idx + 1);
        if(k == 0b10 && idx + 1 < s.size()) {
          for(int l = 0; l < 2; l++) {
            if((s[idx + 1] >> l) & 1) {
              if(l == 0) {
                if(idx + 2 < s.size()) {
                  for(int p = 0; p < 2; p++) {
                    if((s[idx + 2] >> p) & 1) ret += rec1(idx + 3, 2, 2);
                  }
                }
              }
              if(l == 1) ret += rec1(idx + 2, 1, 1);
            }
          }
        }
      }
    }
  } else {
    for(int l = 0; l < 2; l++) {
      if((s[idx] >> l) & 1) {
        if(l == 0) {
          if(idx + 1 < s.size()) {
            for(int p = 0; p < 2; p++) {
              if((s[idx + 1] >> p) & 1) ret += rec1(idx + 2, 2, 2);
            }
          }
        }
        if(l == 1) ret += rec1(idx + 1, 1, 1);
      }
    }
  }
  return dp2[idx][prefix][prefixsz] = ret % mod;
}


int main() {
  cin >> s;
  for(auto &c : s) {
    if(c == '1') c = 2;
    else if(c == '0') c = 1;
    else c = 3;
  }
  memset(dp, -1, sizeof(dp));
  memset(dp2, -1, sizeof(dp2));
  cout << rec1(0, 0, 0) << endl;
}


Measured memory_bytes: 31236
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>

#define div 1000000000+7

typedef long long ll;

using namespace std;

void solve() {
    int a, b, c = 0;
    cin >> a >> b >> c;
    if((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
List=[]
List+=[a,b,c,d,e,f,g,h,i]
n=int(input())
lst=[int(input()) for i in range(n)]
p=set()
for i in lst:
  if i in List:
    p.add(List.index(i))
if 3 in p and 4 in p and 5 in p:
  print("Yes")
elif 0 in p and 1 in p and 2 in p:
  print("Yes")
elif 6 in p and 7 in p and 8 in p:
  print("Yes")
elif 0 in p and 3 in p and 6 in p:
  print("Yes")
elif 1 in p and 4 in p and 7 in p:
  print("Yes")
elif 2 in p and 5 in p and 8 in p:
  print("Yes")
elif 0 in p and 4 in p and 8 in p:
  print("Yes")
elif 2 in p and 4 in p and 6 in p:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int p = sc.nextInt();
		
		int pieces = 3*a + p;
		ans = pieces/2;
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
using namespace std;
string ps[10];
char mp[4][4][4];
int ans,used[10];
int dx[] = {1,2,3,1,2,3,1,2,3};
int dy[] = {1,1,1,2,2,2,3,3,3};

void saiki(int kai){
  if(kai == 9)ans++;
  else 
    for(int i=0;i<9;i++) {
      if(used[i] == 1) continue;
      for(int j=0;j<4;j++){
	int flg =0;
	if(abs(ps[i][j]-mp[dy[kai]][dx[kai]-1][1]) == 'a'-'A'||mp[dy[kai]][dx[kai]-1][1] == 0) flg++;
	if(abs(ps[i][(j+1)%4]-mp[dy[kai]-1][dx[kai]][2]) == 'a'-'A'||mp[dy[kai]-1][dx[kai]][2] == 0) flg++;
	if(flg == 2) {
	  for(int k=0;k<4;k++)mp[dy[kai]][dx[kai]][(3+k)%4] = ps[i][(j+k)%4];
	  used[i] = 1;
	  saiki(kai+1);
	  used[i] = 0;
	  for(int k=0;k<4;k++) mp[dy[kai]][dx[kai]][k] = 0;
	}
      }
    }
}

int main() {
  int q;
  cin >> q;
  while(q--) {
    for(int i=0;i<9;i++) cin >> ps[i];
    ans = 0;
    saiki(0);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
import sys;

v,e=map(int, input().split());

v_l=[0]*v;
e_b=[0]*e;
e_l=[0]*e;
result=0;

for i in range(v):
    v_l[i] = 0;
for i in range(e):
    e_b[i], e_l[i] = map(int, input().split());

def DFS(u):
    global result
    global v_l
    v_l[u] = 1
    for i in range(e):
        if(e_b[i] == u):
            if(v_l[e_l[i]] == 0):
                DFS(e_l[i])
            if(v_l[e_l[i]] == 1):
                result=1
    v_l[u] = 2
    
for i in range(v):
    DFS(i)
print(result)



Measured memory_bytes: 5636
#include <iostream>
#include <map>
using namespace std;
using ll = long long;

int main() {
    // input
    ll N, A_i, sum = 0, res = 0;
    cin >> N;
    map<ll, ll> mp;
    mp[0] = 1;
    
    for (ll i = 0; i < N; ++i) {
        cin >> A_i;
        sum += A_i;
        res += mp[sum];  // key がなければ 0 を返す
        mp[sum]++;
    }
    
    cout << res << "\n";
    
    return 0;
}


Measured memory_bytes: 12800
#include <stdio.h>

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

using namespace std;


int main() {
	int n, x;

	while (true) {
		vector<int> vec(3);
		int count = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		for (int i = 0; i < n; i++) {
			vec.at(0) = i + 1;


			for (int j = i + 1; j < n; j++) {
				vec.at(1) = j + 1;
				vec.at(2) = x - vec.at(0) - vec.at(1);
					if (vec.at(1)<vec.at(2)&&vec.at(2)<=n) {
						count++;

					}
					

			}
		}
		
		cout << count << endl;
	

	}
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

signed main(){
  string s, t; cin >> s >> t;
  lint lent = t.size();
  lint start = -1;
  for(lint i = 0; i + lent <= s.size(); i++){
    string r = s.substr(i, lent);
    bool ok = true;
    for(lint j = 0; j < r.size(); j++){
      if(r[j] != '?' && r[j] != t[j]) ok = false;
    }
    if(ok) start = i; 
  }
  if(start == -1){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(lint i = start; i < start + lent; i++) s[i] = t[i - start];
  for(lint i = 0; i < s.size(); i++){
    if(s[i] == '?') s[i] = 'a';
  } 
  cout << s << endl;
}

Measured memory_bytes: 256