akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int K = keyboard.nextInt();
		int X = keyboard.nextInt();
		int Y = keyboard.nextInt();
		
		int L = N - K;
		
		if(N > K) {
			System.out.println(X * K + Y * L);
		}else {
			System.out.println(X * N);
		}
			
		keyboard.close();	
	}
}


Measured memory_bytes: 21972
package main

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

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	HW   := strings.Split(sc.Text(), " ")
	H, _ := strconv.Atoi(HW[0])
	W, _ := strconv.Atoi(HW[1])
	var grid = make([][]string, H)
	for i := 0; i < H; i++ {
		sc.Scan()
		grid[i] = make([]string, W)
		grid[i] = strings.Split(sc.Text(), "")
	}
	
	canDraw := true
	for i := 0; i < len(grid); i++ {
		for j := 0; j < len(grid[i]); j++ {
			//fmt.Println(grid[i][j])
			if grid[i][j] == "#" {
				// grid[i - 1][j] 上
				if i != 0 && grid[i - 1][j] == "#" {
					continue
				}

				// grid[i + 1][j] 下
				if i != len(grid) - 1 && grid[i + 1][j] == "#" {
					continue
				}

				// grid[i][j - 1] 左
				if j != 0 && grid[i][j - 1] == "#" {
					continue
				}

				// grid[i][j + 1] 右
				if j != len(grid[i]) - 1 && grid[i][j + 1] == "#" {
					continue
				}

				canDraw = false
				break
			}
		}
		if canDraw == false {
			break
		}
	}

	if canDraw == true {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n,k;
int a[1000000];


signed main(){
  cin>>n>>k;
  rep(i,n){
    cin>>a[i];
  }

  sort(a,a+n);

  int ans = INF;
  FOR(i,k-1,n){
    ans = min(ans,a[i]-a[i-k+1]);
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1024
import sys
from pprint import pprint
import itertools

def solve(n, p, q):
    patterns = list(itertools.permutations(range(1, n+1)))
    # pprint(patterns)
    print(abs(patterns.index(p) - patterns.index(q)))


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    p = tuple(map(int, sys.stdin.readline().strip().split(" ")))
    q = tuple(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, p, q)

Measured memory_bytes: 45040
import java.util.*;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int hasMultipleSolutions = w % 2 == 0 && h % 2 == 0 && x == w/2 && y == h/2 ? 1 : 0;
        /*
        double min = Double.MAX_VALUE;
        List<Map.Entry<Integer, Integer>> toCheck = new ArrayList<>();
        toCheck.add(new AbstractMap.SimpleEntry<>(0, 0));
        toCheck.add(new AbstractMap.SimpleEntry<>(w, 0));
        toCheck.add(new AbstractMap.SimpleEntry<>(0, h));
        toCheck.add(new AbstractMap.SimpleEntry<>(w, h));
        for (Map.Entry<Integer, Integer> c : toCheck) {
            double distance = distance(x, y, c.getKey(), c.getValue());
            if (distance < min)
                min = distance;
        }
        for (Map.Entry<Integer, Integer> c : toCheck) {
            double distance = distance(x, y, c.getKey(), c.getValue());
            if (distance == min)
                hasMultipleSolutions = 1;
        }


         */

        System.out.println((double) w * (double) h / (double) 2 + " " + hasMultipleSolutions);
    }

    private static double distance(int x1, int y1, int x2, int y2) {
        return Math.sqrt((x1-x2)^2 + (y1-y2)^2);
    }

}


Measured memory_bytes: 22868
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
    int a, b;

  scanf("%d", &a);

  a = a % 1000;
  b = (a == 0) ? 1000 : (a);

  printf("%d\n", 1000 - b);

  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  string str; cin >> str;
  auto s = str.c_str();
  set<char> s1{s, s + 3};
  set<char> s2{s + 1, s + 4};

  auto ans = s1.size() == 1 || s2.size() == 1;
  cout << (ans ? "Yes" : "No") << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    string res = "";
    rep(i, 0, dx) res += "R";
    rep(i, 0, dy) res += "U";
    rep(i, 0, dx) res += "L";
    rep(i, 0, dy) res += "D";

    res += "D";
    rep(i, 0, dx+1) res += "R";
    rep(i, 0, dy+1) res += "U";
    res += "L";
    res += "U";
    rep(i, 0, dx+1) res += "L";
    rep(i, 0, dy+1) res += "D";
    res += "R";
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

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

  int back_num = (S[2] - '0') * 10 + (S[3] - '0');
  int front_num = (S[0] - '0') * 10 + (S[1] - '0');

  bool isYYMM = false, isMMYY = false;
  if (0 < front_num && front_num < 13)
  {
    isMMYY = true;
    if (0 < back_num && back_num < 13)
    {
      isYYMM = true;
    }
  }
  if (0 < back_num && back_num < 13)
  {
    isYYMM = true;
  }

  if (isYYMM == true && isMMYY == true) cout << "AMBIGUOUS" << endl;
  else if (isYYMM == true && isMMYY == false) cout << "YYMM" << endl;
  else if (isYYMM == false && isMMYY == true) cout << "MMYY" << endl;
  else cout << "NA" << endl;
}

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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

bool safe(ll a,ll b){
	int lasta=-1,lastb=0;
	for(ll aa=1,i=0;aa<=a;aa<<=1,++i)if(aa&a)lasta=i;
	for(ll aa=1,i=0;aa<=a;aa<<=1,++i)if(aa&b)lastb=i;
	return lasta+lastb<64;
}

int main(){
	ll n;
	cin>>n;
	ll res=1;
	bool al=false;
	bool good=true;
	for(int i=0;i<n;++i){
		ll val;cin>>val;
		if(val==0)al=true;
		if(!safe(val,res))good=false;
		res*=val;
		if(res<0||res>ll(1e18))good=false;
	}
	if(good||al)cout<<res<<endl;
	else cout<<-1<<endl;
}


Measured memory_bytes: 3624
import java.util.*;

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

        String N = sc.next();

        if (N.charAt(0) == '7' || N.charAt(1) == '7' || N.charAt(2) == '7') {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35536
// Circle
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_B
//
// Accepted

use std::f64::consts::PI;
use std::io::{Read, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let mut buf = String::new();
    stdin.read_to_string(&mut buf).unwrap();

    let r: f64 = buf.trim().parse().unwrap();

    println!("{} {}", r * r * PI, r * 2f64 * PI);
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    cout << (ll) pow(N, 3) << '\n';

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 4016
from collections import deque

n, m = map(int, input().split())
nodes = range(1, n+1)
edges = {i: [] for i in nodes}
for _ in range(m):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

sign = {}
reached = {i: False for i in nodes}
reached[1] = True
queue = deque([1])
while queue:
    v = queue.popleft()
    for w in edges[v]:
        if not reached[w]:
            reached[w] = True
            queue.append(w)
            sign[w] = v

print('Yes')
for i in range(2, n+1):
    print(sign[i])

Measured memory_bytes: 59044
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

map<string, int> id;
int n, m, k;
inline int get(const string &s){
	if(id.count(s)) return id[s];
	return id[s] = k++;
}
bool e[200][200], g[200][200];
int v[200], p[200];
void dfs(int c, int col){
	v[c] = col;
	rep(i, k) if(e[c][i]){
		if(v[i] && v[i] == col) assert(0);
		if(!v[i]) dfs(i, -col);
	}
}
int root(int x){
	if(x == p[x]) return x;
	return p[x] = root(p[x]);
}

int main(){
	while(cin >> n, n){
		id.clear();
		k = 0;
		rep(i, 200) p[i] = i;
		memset(e, 0, sizeof(e));
		memset(g, 0, sizeof(g));
		memset(v, 0, sizeof(v));
		
		string s, t;
		rep(i, n){
			cin >> s;
			int pos = s.find("-");
			t = s.substr(pos + 1);
			s = s.substr(0, pos);
			int a = get(s), b = get(t);
			e[a][b] = e[b][a] = 1;
			g[a][b] = 1;
			a = root(a); b = root(b);
			if(a != b) p[a] = b;
		}
		rep(i, k) if(!v[i]) dfs(i, 1);
		rep(i, k) rep(j, k) e[i][j] = g[i][j];
		rep(i, k) rep(j, k){
			bool ok = 0, ng = 0;
			rep(l, k){
				if(e[l][i] && e[j][l] || e[l][j] && e[i][l]) ng = 1;
				if(e[l][i] && e[l][j] || e[i][l] && e[j][l]) ok = 1;
			}
			if(ok && !ng) g[i][j] = g[j][i] = 1;
		}
		rep(l, k) rep(i, k) rep(j, k) g[i][j] |= g[i][l] && g[l][j];
		
		cout << k << endl;
		cin >> m;
		rep(i, m){
			cin >> s;
			int p = s.find("-");
			t = s.substr(p + 1);
			s = s.substr(0, p);
			int a = get(s), b = get(t);
			
			if(root(a) != root(b) || v[a] == v[b] || !g[a][b])
				cout << "NO" << endl;
			else cout << "YES" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1336
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub

		BufferedReader br=new BufferedReader(new  InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		int[] W=new int[n];
		String[] in=br.readLine().split("\\s+");
		
		for(int i=0;i<n;i++){
			W[i]=Integer.parseInt(in[i]);
		}
		System.out.println(minCost(W));
	}

	public  static int minCost(int[] W){
		int[] sort=W.clone();
		Arrays.sort(sort);
		int cost=0;
		for(int i=0;i<W.length;i++){
			int a=indexOf(W,sort[i]);
			int j=0;
			while(a>i){
				j++;
				int b=indexOf(W, sort[a]);
				cost+=W[b];
				
				int work=W[a];
				W[a]=W[b];
				W[b]=work;
				
				a=b;
			}
			cost+=Math.min(sort[i]*j, sort[i]*2+sort[0]*(j+2));
		}
		return cost;
	}

	private static int indexOf(int[] A, int x) {
		// TODO Auto-generated method stub
		for(int i=0;i<A.length;i++){
			if(A[i]==x)
				return i;
		}
		
		return -1;
	}
}



Measured memory_bytes: 25524
import sys

arg = input()
scavenger=''
warehouse=[]
longest=0
i=0

for tmp in arg[0:]:
  if tmp=='A' or tmp=='T' or tmp=='C' or tmp=='G':
    scavenger=scavenger+tmp
  else:
    warehouse.append(scavenger)
    scavenger=''

warehouse.append(scavenger)

for tmp in warehouse[0:]:
  if len(tmp)>longest:
    longest=len(tmp)

print(longest)

Measured memory_bytes: 3060
#include <stdio.h>
typedef long long ll;

ll gcd(ll a, ll b) {
  ll t;
  while(b) t = a % b, a = b, b = t;
  return a;
}

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  for(i = 1; i <= n; ++i) for(j = 1; j <= n; ++j) for(k = 1; k <= n; ++k) ans += gcd(i, gcd(j, k));
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 1e5;
int A[MAXN+10], F[2][MAXN+10];
int n;
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &A[i]);
		F[i%2][A[i]]++;
	}
	int ans = INF;
	for(int i = 0; i < n - 1; i++){
		if(A[i] == A[i+1]) continue;
		ans = min(ans, n - F[i%2][A[i]] - F[(i+1)%2][A[i+1]]);
	}
	if(ans == INF) ans = n/2;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1408
use std::io::*;

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

fn is_prime_1(n: usize) -> bool {
    if n % 2 == 0 {
        return false;
    }
    let mut k = 3;
    while k * k <= n {
        if n % k == 0 {
            return false;
        }
        k += 2;
    }
    return true;
}

fn main() {
    let n = read::<usize>();
    let mut a = 11;
    let mut i = 0;
    while i < n {
        if is_prime_1(a) {
            println!("{}",a);
            i += 1;
        }
        a += 10;
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>

using namespace std;


void Main142_c(void) {
	int n;
	vector <int> a;
	int i, temp;
	map <int, int> mp;


	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> temp;
		a.push_back(temp);
		mp[temp] = i + 1;
	}

	for (i = 0; i < n; i++) {
		cout << mp[i + 1] << " ";
	}

	cout << endl;

	return;
}




int main(void) {
	Main142_c();
	return 0;
}

Measured memory_bytes: 5880
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int MOD = 1e9 + 7;
#define INF ((1<<30)-1)
#define LINF (1LL<<30)

int dp[3100][3100];
int main() {
    string s, t;
    cin >> s >> t;
    int m = s.size();
    int n = t.size();
    for(int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if(i == 0 || j == 0){
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            if(s[i-1] ==t[j-1]){
                dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
            }
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    //cout << dp[m][n] << endl;

    string revans = "";
    while(m>0 && n>0){
        if(dp[m][n] == dp[m-1][n])m--;
        else if (dp[m][n] == dp[m][n-1])n--;
        else{
            revans += s[m-1];
            m--;
            n--;
        }
    }
    int l = revans.size();
    for(int i = 0;i<l;i++){
        cout << revans[l-i-1];
    }
    cout << endl;
    
}

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

int main() {
  int A,B,n=0;
  cin >> A >> B;

  for(int x = A; x <= B; x++){
    if((x % 10 == x / 10000) &&(x % 100 / 10 == x / 1000 % 10))
      n++;
  }

  cout << n << endl;
}


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

using ll = long long;

using namespace std;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (4*a*b < (c - a - b) * (c - a - b) && c - a - b >= 0 ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans

S = input()
ans = 0
N = len(S)
si, i = 0, 0
while i < N:
  if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1
ans += sol(S[si:])
print(ans)

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

const int maxn = 2505;
int N, M, P;
struct Edge
{
    int to, wt;
};

vector<Edge> adj[maxn];
vector<Edge> rev[maxn];

bool vis2[maxn], vis0[maxn], vis[maxn];

void dfs(int i) {
    vis2[i] = true;
    for (auto e: rev[i]) {
        if (vis2[e.to]) continue;
        dfs(e.to);
    }
}

void dfs2(int i) {
    vis0[i] = true;
    vis[i] = vis2[i];
    for (auto e: adj[i]) {
        if (vis0[e.to]) continue;
        dfs2(e.to);
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M >> P;
    for (int i = 0; i < M; i++) {
        int a, b, c; cin >> a >> b >> c;
        adj[a].push_back({b,P-c});
        rev[b].push_back({a,P-c});
    }
    dfs(N);
    dfs2(1);
    /*
    for (int i = 1; i <= N; i++) {
        cout << i << ": " << vis[i] << '\n';
    }
    */
    //bellman-ford
    vector<int> dist(N+1,2e9);
    dist[1] = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int u = 1; u <= N; u++) {
            if (!vis[u]) continue;
            for (Edge& e: adj[u]) {
                int v = e.to;
                if (!vis[v]) continue;
                int wt = e.wt;
                if (dist[u] + wt < dist[v]) {
                    dist[v] = dist[u] + wt;
                }
            }
        }
    }
    bool hasNegCycle = false;
    //check for negative-weight
    for (int u = 1; u <= N; u++) {
        if (!vis[u]) continue;
        for (Edge& e: adj[u]) {
            int v = e.to;
            if (!vis[v]) continue;
            int wt = e.wt;
            if (dist[u] + wt < dist[v]) {
                /*
                cout << u << '\n';
                cout << dist[u] << ' ' << wt << ' ' << dist[v] << '\n';
                */
                hasNegCycle = true;
                break;
            }
        }
    }
    //output
    if (hasNegCycle) {
        cout << -1 << '\n';
    }
    else {
        cout << max(0,-dist[N]) << '\n';
    }
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <list>
using namespace std;

int main(){
	int ans = 0;
	string str;
	cin >> str;
	if (str[0] - '0') ans++;
	if (str[1] - '0') ans++;
	if (str[2] - '0') ans++;
	cout << ans << endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,A,B,C;

ll mo=1000000007;
ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
ll modpow(ll a, ll n=mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B>>C;
	
	ll ret=0;
	ll Awin=A*modpow(A+B)%mo;
	ll Bwin=B*modpow(A+B)%mo;
	ll num=(A+B+C)*modpow(A+B)%mo;
	
	
	for(i=0;i<=N-1;i++) {
		ret+=comb(N-1+i,i)*modpow(Awin,N)%mo*modpow(Bwin,i)%mo*(N+i)%mo;
		ret+=comb(N-1+i,i)*modpow(Bwin,N)%mo*modpow(Awin,i)%mo*(N+i)%mo;
	}
	cout<<ret%mo*num%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
string s,t,ans;
bool check(string x,string y){
	for(int i=0;i<x.size();i++){
		if(x[i]!='?'&&x[i]!=y[i])return 0;
	}
	return 1;
}
int main(){
	cin>>s>>t;
	ans="~";
	int ls=s.size(),lt=t.size();
	for(int i=0;i<=ls-lt;i++){
		string st=s.substr(i,t.size());
		if(check(st,t)){
			string tmp=s;
			tmp.replace(i,t.size(),t);
			for(int j=0;j<tmp.size();j++)if(tmp[j]=='?')tmp[j]='a';
			ans=min(ans,tmp);
		}	
	}
	if(ans=="~")cout<<"UNRESTORABLE"<<endl;
	else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <cstring>

inline void display(int n, const bool* is_sheep) {
    for (int i = 0; i < n; i++) {
        std::cout << (is_sheep[i] ? 'S' : 'W');
    }
    std::cout << std::endl;
}

inline bool is_correct(int n, int idx, const bool* tolds, const bool* is_sheep) {
    // idx番目の動物の発言が矛盾するかチェック
    int left = (idx == 0) ? n-1 : idx-1;
    int right = (idx == n-1) ? 0 : idx+1;

    if (is_sheep[idx] && tolds[idx]) {
        return (is_sheep[left] == is_sheep[right]);
    }

    if (is_sheep[idx] && !tolds[idx]) {
        return (is_sheep[left] != is_sheep[right]);
    }

    if (!is_sheep[idx] && tolds[idx]) {
        return (is_sheep[left] != is_sheep[right]);
    }

    if (!is_sheep[idx] && !tolds[idx]) {
        return (is_sheep[left] == is_sheep[right]);
    }

    return false;
    // return (is_sheep[left] == is_sheep[right]) ^ is_sheep[idx] ^ tolds[idx];
}

void eval(int n, const bool* tolds) {
    bool* is_sheep = new bool[n];
    std::memset(is_sheep, 0, n);

    std::stack<int> stack;
    stack.push(0);
    stack.push(1);

    while (stack.size()) {
        int val = stack.top();
        int idx = val >> 1;
        bool sheep = val&1;
        stack.pop();

        // std::cout << "idx: " << idx << ", sheep: " << sheep << std::endl;

        is_sheep[idx] = sheep;

        // 終了判定
        if (idx == n-1) {
            if (is_correct(n, n-1, tolds, is_sheep) && is_correct(n, 0, tolds, is_sheep)) {
                display(n, is_sheep);
                return;
            }
            continue;
        }

        // 羊としてテスト
        is_sheep[idx+1] = true;
        if (idx == 0 || is_correct(n, idx, tolds, is_sheep)) {
            stack.push(((idx+1) << 1) | 1);
        }

        // 狼としてテスト
        is_sheep[idx+1] = false;
        if (idx == 0 || is_correct(n, idx, tolds, is_sheep)) {
            stack.push((idx+1) << 1);
        }
    }

    std::cout << "-1" << std::endl;
}

int main(void) {
    int n;
    std::string str;

    std::cin >> n;
    std::cin >> str;

    const char* str_c = str.c_str();
    bool* tolds = new bool[n];
    for (int i = 0; i < n; i++) {
        tolds[i] = (str_c[i] == 'o');
    }

    eval(n, tolds);
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

enum type { DOWN, UP, QUERY};

struct T {
  int pos;
  int x;
  type tp;
  bool operator<(const T& t) const {
    if (pos != t.pos) return pos < t.pos;
    else return tp < t.tp;
  }
};

int q[5 + (int)2e5];

int main () {
  int N, Q;
  while (cin >> N >> Q) {
    vector<T> tasks;
    for (int i = 0; i < N; i++) {
      int s, t, x;
      cin >> s >> t >> x;
      tasks.push_back(T{s-x, x, UP});
      tasks.push_back(T{t-x, x, DOWN});
    }
    for (int i = 0; i < Q; i++) {
      int d;
      cin >> d;
      tasks.push_back(T{d, i, QUERY});
      q[i] = -1;
    }
    sort(tasks.begin(), tasks.end());
    multiset<int> s;
    for (auto t: tasks) {
      // cout << t.pos << ' ' << t.x << ' ' << t.tp << endl;
      if (t.tp == UP) {
        s.insert(t.x);
      } else if (t.tp == DOWN) {
        auto it = s.find(t.x);
        s.erase(it);
      } else if (t.tp == QUERY) {
        if (s.size()) {
          int v = *s.begin();
          q[t.x] = v;
          // cout << t.x << ' ' << v << endl;
        }
      }
    }
    for (int i = 0; i < Q; i++) {
      cout << q[i] << endl;
    }
  }
}


Measured memory_bytes: 19048
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int D = sc.nextInt();
    int x = sc.nextInt();

    for (int i = 0; i < 10; i++) {
      // xi+1=r*xi−D
      System.out.println(r * x - D);
      x = r * x - D;
    }

  }
}


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

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

    int n, m;
    cin >> n >> m;
    long long A[n][3];
    REP(i, n) REP(j, 3) cin >> A[i][j];

    long long maxi = -1e18;
    for(int i = 0; i < 8; i++){
        vector<long long> B(n);
        for(int j = 0; j < n; j++){
            long long cost = 0;
            for(int k = 0; k < 3; k++){
                cost += A[j][k] * ((i >> k) & 1 ? 1 : -1);
            }
            B[j] = cost;
        }
        sort(B.begin(), B.end(), greater<long long>());
        long long tmp = 0;
        REP(i, m) tmp += B[i];
        maxi = max(maxi, tmp);
    }
    cout << maxi << endl;  

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    void solve(){
	Scanner sc = new Scanner(System.in);

	while(true){
	    int a = sc.nextInt();
	    int b = sc.nextInt();
	    if(a==0 && b==0) break;

	    ArrayList<Integer> a1 = new ArrayList<Integer>();
	    ArrayList<Integer> b1 = new ArrayList<Integer>();
	    for(int i=1; i*i<=a; i++){
		if(a%i==0) a1.add(i);
	    }
	    for(int i=1; i*i<=b; i++){
		if(b%i==0) b1.add(i);
	    }

	    int min = Integer.MAX_VALUE;
	    int[] data = new int[4];
	    int square = 0;
	    for(int i=0; i<a1.size(); i++){
		for(int j=0; j<b1.size(); j++){
		    data[0] = a1.get(i);
		    data[1] = a/a1.get(i);
		    data[2] = b1.get(j);
		    data[3] = b/b1.get(j);
		    Arrays.sort(data);
		    square = (data[1]-data[0])*(data[1]-data[0])+(data[2]-data[1])*(data[2]-data[1])+(data[3]-data[2])*(data[3]-data[2]);
		    min = Math.min(min,square);
		}
	    }

	    System.out.println(min);
	}
    }

    public static void main(String[] args){
	new Main().solve();
    }
}

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

int main() {
    int n;
    int s=0;
    
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) cin >> d[i];

    for (int j = 0; j < n-1; j++)
    {
        for (int k = j+1; k < n; k++)
        {
            s = s + d[j]*d[k];
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	string s;
	char c[10000][6];
	int cnt = 0;
	int dcnt = 0;
	while(cin >> s) {
		rep(i,s.length()) {
			if(isdigit(s[i])) {
				c[cnt][dcnt] = s[i];
				dcnt++;
			} else {
				if(dcnt != 0) {
					dcnt = 0;
					cnt++;
				}
			}
		}
		if(dcnt != 0) {
			dcnt = 0;
			cnt++;
		}
	}
	int ret = 0;
	rep(i,cnt) {
		ret += atoi(c[i]);
	}
	cout << ret << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> o;
    while(n--){
        int x;
        cin >> x;
        if(x % 2) o.push_back(x);
    }
    if(o.size()%2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 640
import numpy as np
import heapq

H = []

x, y, a, b, c = map(int, input().split())

ps = list(map(int,input().split()))
ps.sort()

qs = list(map(int, input().split()))
qs.sort()

rs = list(map(int, input().split()))
rs.sort()

ans = np.zeros(1, dtype=np.uint64)

for i in range(x):
    heapq.heappush(H, ps[-(i+1)])
    ans += ps[-(i+1)]

for i in range(y):
    heapq.heappush(H, qs[-(i+1)])
    ans += qs[-(i+1)]

for i in range(min(c, (x+y))):
    minimum = heapq.heappop(H)
    if minimum > rs[-(i+1)]:
        break
    else:
        ans = ans - minimum + rs[-(i+1)]

print(ans[0])

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

int main() {
    int h, w;
    cin >> h >> w;
    int moding = pow(10, 9) + 7;

    vector<vector<char>> f(h, vector<char>(w));

    for(vector<char> &v : f)
        for(char &el : v)
            cin >> el;

    vector<vector<int>> dp(h, vector<int>(w, 0));
    
    for(int i = 0; i < h; i++) {
        if(f[i][0] == '#') break;
        dp[i][0] = 1;
    }
    
    for(int i = 1; i < w; i++) {
        if(f[0][i] == '#') break;
        dp[0][i] = 1;
    }

    for(int i = 1; i < h; i++) {
        for(int j = 1; j < w; j++) {
            if(f[i][j] == '#') continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % moding;
        }
    }

    cout << dp[h-1][w-1] << '\n';
}

Measured memory_bytes: 5248
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int m, n;
ll k;

vector<ll> a, b;

int main()
{
  int bkmax=0;
  int amax, bmax;
  int i, j;

  cin >> n >> m >> k;
  a.resize(n+1); b.resize(m+1);

  a[0] = 0;
  for (i=1; i<=n; i++) {
    cin >> a[i];
    a[i] += a[i-1];
//printf("a[%d] = %lld\n", i, a[i]);
    if (a[i-1] <= k && a[i] > k) amax = i-1;
  }
  if (a[n] <= k) amax = n;
//printf("amax = %d\n", amax);
  b[0] = 0;
  for (i=1; i<=m; i++) {
    cin >> b[i];
    b[i] += b[i-1];
//printf("b[%d] = %lld\n", i, b[i]);
    if (b[i-1] <= k && b[i] > k) bmax = i-1;
  }
  if (b[m] <= k) bmax = m;
//printf("bmax = %d\n", bmax);

  i=amax;
  for (j=0; j<=bmax; j++) {
    if (a[i] + b[j] > k) {
      break;
    }
  }
  j--;
  bkmax = max(bkmax, i+j);
//printf("bkmax = %d, a[%d]+b[%d] = %lld\n", bkmax, i, j, a[i]+b[j]);
  for (i--; i>=0 && j<=m ; i--) {
    while (a[i] + b[j] <= k && j<=m) {
      bkmax = max(bkmax, i+j);
//printf("bkmax = %d, a[%d]+b[%d] = %lld\n", bkmax, i, j, a[i]+b[j]);
      j++;
    }
  }

  cout << bkmax << endl;

  return 0;
}


Measured memory_bytes: 6388
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    ll s[60] = {};
    int p[60] = {};

    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;

        ll t = 1;
        for (int k = 0; k < 60; k++) {
            s[k] += (a & t) ? i - p[k]++ : p[k];
            t <<= 1;
        }
    }

    ll r = 0;
    for (int k = 0; k < 60; k++) {
        r += (1LL << k) % P * (s[k] % P) % P;
    }
    r %= P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
import copy
N, K = map(int, input().split())

mod = 10**9+7

if N == 1:
    ans = 1
else:
    Keys = set()
    for n in range(1, int(math.sqrt(N))+2):
        Keys.add(n)
        Keys.add(N//n)

    L = sorted(list(Keys))
    Counts = {1: 1}
    for i in range(len(L)-1):
        Counts[L[i+1]] = L[i+1]-L[i]

    dp = copy.copy(Counts)
    for _ in range(K-1):
        sdp = {}
        c = 0
        for l in L:
            c = (c + dp[l]) % mod
            sdp[l] = c

        for l in L:
            r = N//l
            dp[l] = sdp[r] * Counts[l] % mod

    ans = 0
    for v in dp.values():
        ans = (ans + v) % mod
print(ans)

Measured memory_bytes: 207776
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[2];
cin>>s;
for(int i=0;i<2;i++){
if(s[i]>='A'&&s[i]<='Z'){
    cout<<"A"<<endl;
    return 0;
}
 else
      {cout<<"a"<<endl;
return 0;
      }

}
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

string s;

int main()
{
	cin >> s;

	int ope = 0;
	for (int i = 0; i < s.length()-1; i++) {
		if (s[i] == 'A') {
			if (s[i + 1] == 'C') {
				ope++;
			}
		}
	}
	if (ope != 0)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
L = int(input())

p = 0
ans = []
while(L >= 2 ** (p + 1)):
    ans.append([p + 1, p + 2, 2 ** p])
    ans.append([p + 1, p + 2, 0])
    p += 1

endN = p + 1

tmp = 2 ** p
L -= tmp

while(L != 0):
    p = 0
    while(L - 2 ** p >= 0):
        p += 1

    ans.append([p, endN, tmp])
    L -= 2 ** (p - 1)
    tmp += 2**(p - 1)

# print(p, ans)

print(endN, len(ans))
for a, b, c in ans:
    print(a, b, c)

Measured memory_bytes: 3064
N = int(input())
res = [0]*4
for i in range(N):
    s = input()
    if s == "AC":
        res[0] += 1
    elif s == "WA":
        res[1] += 1
    elif s == "TLE":
        res[2] += 1
    elif s == "RE":
        res[3] += 1

print(f"AC x {res[0]}")
print(f"WA x {res[1]}")
print(f"TLE x {res[2]}")
print(f"RE x {res[3]}")

Measured memory_bytes: 9140
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000;
//#define PI 3.14159265359

int main() {
    // input
    ll N;
    cin >> N;
    Vec A(N);
    rep(i, N) {
        cin >> A[i];
    }

    // process
    ll ans = 1000;
    ll stock = 0;
    rep(i, N - 1) {
        ans += stock * A[i];
        stock = 0;
        if (A[i] < A[i + 1]) {
            stock += ans / A[i];
            ans -= stock * A[i];
        }
    }


    ans += stock * A[N - 1];

    cout << ans << endl;

    return 0;
}


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

int w[100], v[100];
ll dp[100001];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, W;
  cin >> n >> W;
  for (int i = 0; i < n; i++)
    cin >> w[i] >> v[i];
  fill_n(dp, n*1000+1, 1e18);
  dp[0] = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = n*1000; j >= v[i]; j--) {
      dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
      if (dp[j] <= W) ans = max(ans, 1ll*j);
    }
  cout << ans << endl;
}


Measured memory_bytes: 1024
PROGRAM Ubiquity
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 16, m = 10**9 + 7
      integer(p) :: ans,n,i,temp1=1,temp2=1,temp3=1
      
      read*,n
      
      do i = 1,n
        temp1 = mod(temp1*9,m)
      end do
      temp1 = mod(temp1*2,m)
      
      do i = 1,n
        temp2 = temp2 * 10
        temp2 = mod(temp2,m**2_p)
      end do
      do i = 1,n
        temp3  = mod(temp3*8,m)
      end do
      
      ans = -temp1 + temp3 + temp2
      ans = mod(ans,m)
      print*,ans
      
      
      
      
      
      stop
      !debugg
      print*, ''
      print*,temp1
      print*,temp2
      print*,temp3
      
      
      END PROGRAM

Measured memory_bytes: 2772
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(n*3)]
for i in range(m):
  u,v = map(int,input().split())
  for j in range(3):
    graph[n*j+u-1].append((n*(j+1)+v-1)%(3*n))
s,t = map(int,input().split())
wait = [s-1]
cnt = 0
done = [0]*(3*n)
while wait:
  cnt += 1
  now = copy.copy(wait)
  wait = []
  for i in now:
    for j in graph[i]:
      if not done[j]:
        done[j] = 1
        wait.append(j)
      if j == t-1:
        print(cnt//3)
        quit()
print(-1)

Measured memory_bytes: 80624
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;
    int price = INF;
    REP(i,100001){
        int now = C*2*i+A*max(X-i,(long long)0)+B*max(Y-i,(long long)0);
        price =min(now,price);
    }
    Out(price);
}

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

//random_device rd;
//mt19937_64 gen(rd());
//
//template<typename T>
//T rand(T l, T r) {
//    uniform_int_distribution<T> uid(l, r);
//    return uid(gen);
//}

const int maxn = 109;
int dp[maxn][maxn];
int a[maxn][maxn];
int n, m;
int inf = 1e9;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        for (int e = 0; e < m; e++)
        {
            a[i][e] = (s[e] == '#');
            dp[i][e] = inf;
        }
    }
    dp[0][0] = a[0][0];
    for (int i = 0; i < n; i++)
    {
        for (int e = 0; e < m; e++)
        {
            dp[i + 1][e] = min(dp[i + 1][e], dp[i][e] + ((!a[i][e] && a[i + 1][e]) ? 1 : 0));
            dp[i][e + 1] = min(dp[i][e + 1], dp[i][e] + ((!a[i][e] && a[i][e + 1]) ? 1 : 0));
        }
    }
    cout << dp[n - 1][m - 1];
}


Measured memory_bytes: 384
import heapq
l = []
heapq.heapify(l)
while True:
    o = input().split()
    if o[0].lower() == 'end':
        break
    elif o[0] == 'insert':
        heapq.heappush(l,int(o[1])*-1)
    elif o[0] == 'extract':
        print(heapq.heappop(l)*(-1))



Measured memory_bytes: 45304
n = int(input())
sL = [input() for i in range(n)]
m = int(input())
tL = [input() for i in range(m)]
L = list(set(sL))
maxnum = 0
for i in range(len(L)):
    num = max(0, sL.count(L[i])-tL.count(L[i]))
    if num > maxnum:
        maxnum = num
print(maxnum)


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

int main(){
    int N, W;
    int v[100], w[100];
    scanf("%d%d", &N, &W);
    for(int i = 0; i < N; i++){
        scanf("%d%d", v + i, w + i);
    }
    int dp[10001];
    fill(dp, dp + W + 1, 0);
    for(int i = 0; i < N; i++){
        for(int j = w[i]; j <= W; j++){
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    printf("%d\n", dp[W]);
    return 0;
}

Measured memory_bytes: 1228
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int MAX = 100000;

std::vector<int> GetPrime(int max) {
  std::vector<int> result;
  bool is_onlist[200001];
  for (int i = 2; i <= max; i++) {
    is_onlist[i] = true;
  }
  for (int i = 2; i <= max; i++) {
    if (!is_onlist[i]) continue;
    result.push_back(i);
    for (int j = i; j <= max; j += i) {
      is_onlist[j] = false;
    }
  }
  return result;
}

void Show(std::vector<int> vec) {
  for (auto x : vec) {
    cerr << "\033[93m" << x << "\033[m" << endl;
  }
}

int Solve(int n, int p, const std::vector<int>& prime) {
  // FIXME: 2+13=15も「和を並べたもの」の中に入るはずだけど，問題文の中にない
  std::multiset<int> sumset;
  int i_count = 0;
  for (int i = 0; i < prime.size(); i++) {
    if(prime[i]<=n) continue;
    int j_count = 0;
    for (int j = i; j < prime.size(); j++) {
      if (prime[j] <= n) continue;
      sumset.insert(prime[i] + prime[j]);
      j_count++;
      if (j_count > p) break;
    }
    i_count++;
    if (i_count > p) break;
  }

  auto itr = sumset.begin();
  for (int i = 1; i < p; i++) {
    // cerr << "\033[93m" << *itr << "\033[m" << endl;
    itr++;
  }
  return *itr;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::vector<int> prime = GetPrime(200000);

  while (1) {
    int n, p;
    cin >> n >> p;
    if (n == -1) {
      break;
    }
    cout << Solve(n, p, prime) << endl;
  }

  return 0;
}



Measured memory_bytes: 3876
s = str(input())

max = 0
i = 0
while i < len(s):
    if s[i] == 'A':
        b = i
        i += 1
        while i < len(s):
            if s[i] == 'Z':
                e = i
                max = e - b +1
                i += 1
            else:
                i += 1
    else:
        i += 1
print(max)



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

int main(){
  rep(i, 5){
    int x;
    cin>>x;
    if(x == 0){
      cout << i+1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3596