akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int a[4][4],n,x;
bool flag;
int main() {
	for(int i=1; i<=3; i++)
		for(int j=1; j<=3; j++)
			scanf("%d",&a[i][j]);
	scanf("%d",&n);
	//printf("%d\n",n);
	for(int k=1; k<=n; k++) {
		scanf("%d",&x);
		if(!flag) {
			for(int i=1; i<=3; i++)
				for(int j=1; j<=3; j++)
					if(a[i][j]==x) {
						a[i][j]=0;
						//printf("I found %d in (%d,%d)\n",x,i,j);
					}
			for(int i=1; i<=3; i++)
				if(a[i][1]+a[i][2]+a[i][3]==0)
					flag=1;
			if(flag) break;
			for(int i=1; i<=3; i++)
				if(a[1][i]+a[2][i]+a[3][i]==0)
					flag=1;
			if(a[1][1]+a[2][2]+a[3][3]==0)
				flag=1;
			if(a[1][3]+a[2][2]+a[3][1]==0)
				flag=1;
		}
	}
	if(flag) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
for _ in [0] * int(raw_input()):
  a, b = map(int, raw_input().split(':'))
  b = b/60.0
  x = abs((a+b)-b*12)
  if x>6: x=12-x
  if x<1: print 'alert'
  elif 3<=x: print 'safe'
  else: print 'warning'

Measured memory_bytes: 4220
n = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

for i in range(1, n):
    if A[i-1] > A[i]:
        money += stock * A[i-1]
        stock = 0
    else:
        stock += money // A[i-1]
        money %= A[i-1]
else:
    money += stock * A[-1]
    stock = 0

print(money)


Measured memory_bytes: 9004
n,W = map(int,input().split())
dp = [[0] * (W+1) for _ in range(n+1)]
w = []
v = []
for i in range(n):
    w_,v_ = map(int,input().split())
    w.append(w_)
    v.append(v_)
for i in range(n):
    for sum_w in range(W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])
        dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w]) # 選ばない場合
print(dp[n][W])


Measured memory_bytes: 120684
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<ll> T(N), A(N);
    REP(i, N) cin >> T[i] >> A[i];

    ll a = 1, b = 1;
    REP(i, N) {
        ll n = max((a-1)/T[i]+1, (b-1)/A[i]+1);
        a = n * T[i];
        b = n * A[i];
    }

    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct BIT<T> {
    n: usize,
    bits: Vec<T>,
}

impl BIT<i64> {
    fn new(n: usize) -> Self {
        let mut m = 1;
        while m < n {
            m *= 2;
        }
        BIT {
            n: m,
            bits: vec![0; m + 1],
        }
    }

    fn add(&mut self, a: usize, w: i64) {
        let mut x = a as i32;
        while x <= self.n as i32 {
            self.bits[(x as usize)] += w;
            x += x&-x;
        }
    }

    fn sum(&self, a: usize) -> i64 {
        let mut ret = 0;
        let mut x = a as i32;
        while x > 0 {
            ret += self.bits[x as usize];
            x -= x&-x;
        }
        ret
    }
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let mut s: Vec<char> = read_line().trim().chars().collect();
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let q = line[0];
    let mut memo = HashMap::new();
    for i in 0..26 {
        memo.insert(('a' as u8 + i) as char, BIT::new(n+1));
    }
    for i in 0..n {
        let c = s[i];
        let mut tar = memo.get_mut(&c).map(|tar| tar.add(i+1, 1));
    }

    for i in 0..q {
        let line: Vec<String> = read_line().split_whitespace().map(|s| s.clone().to_owned()).collect();
        let p: usize = line[0].parse().unwrap();
        if p==1 {
            let i: usize = line[1].parse().unwrap();
            let i = i-1;
            let c = line[2].chars().nth(0).unwrap();
            let d = s[i];
            s[i] = c;
            let mut tar = memo.get_mut(&d).map(|tar| tar.add(i+1, -1));
            let mut tar = memo.get_mut(&c).map(|tar| tar.add(i+1, 1));
        } else {
            let l: usize = line[1].parse().unwrap();
            let r: usize = line[2].parse().unwrap();
            let c = s[l-1];
            let d = s[r-1];

            let mut ans = 0;
            for (_, tar) in memo.iter() {
                if tar.sum(r) - tar.sum(l-1) > 0 {
                    ans += 1;
                }
            }
            println!("{}", ans);
        }
    }

}


Measured memory_bytes: 106420
import math

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

x = [list(map(int, input().split())) for i in range(n)]

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(dist).is_integer():
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
<?php
//W,H,x,y,r
fscanf(STDIN, "%d %d %d %d %d", $W, $H, $x, $y, $r);
if(!($x - $r < 0 || $x + $r > $W) && !($y - $r < 0 || $y + $r > $H)){
    echo "Yes". PHP_EOL;
}else{
    echo "No". PHP_EOL;
}

Measured memory_bytes: 15096
#include<bits/stdc++.h>
using namespace std;
int main(){

	vector<int64_t> data(87);
  
	data.at(0)=2;
  	data.at(1)=1;
  	
  	int N;	
  
  	cin >> N;
  	for(int i=2;i<=N;i++){
    	data.at(i)=data.at(i-2)+data.at(i-1);
    }
	cout << data.at(N) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<n; i++)

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans=0;
    ll c = n/(a+b);
    ans = c*a;
    ll remain = n%(a+b);
    ans += min(remain, a);
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n;
  cin >> n;
  rep(i,9){
    rep(j,9){
      if(i*j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>                                             
#include <string>                                               
#include <algorithm>                                            
using namespace std;                                            
                                                                
int main(void){                                                 
  string str, ope, p, str_rev;                                  
  int q, a, b;                                                  
  cin >> str >> q;                                              
  for (int i=0; i<q; i++) {                                     
    cin >> ope >> a >> b;                                       
    if (ope=="replace") {                                       
      cin >> p;                                                 
      str.replace(a,p.size(),p);                                
    } else if (ope=="reverse") {                                
      str_rev = str.substr(a,b-a+1);                            
      reverse(str_rev.begin(),str_rev.end());                   
      str.replace(a,str_rev.size(),str_rev);                    
    } else {                                                    
      cout << str.substr(a,b-a+1) <<endl;                       
    }                                                           
  }                                                             
  return 0;                                                     
}                                                               
           

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() 配列名.Length()
using namespace std;
typedef unsigned long long ll;

int main(void){
	int a,b,c;
	cin >>a >> b >> c;
	cout << (b + c - a >= 0?b+c-a:0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);
    switch ((a >= b) * -1 + (a <= b)){
      case -1: printf("a > b\n");  break;
      case  0: printf("a == b\n"); break;
      case  1: printf("a < b\n");  break;
    }
    return (0);
}

Measured memory_bytes: 1812
package main
import (
        "fmt"
        "bufio"
        "os"
        "strings"
        "strconv"
)

var (
        cardInfo []string
        cardType [4]string = [4]string{"S","H","C","D"}
)

func main(){
        cardEachNum := 13
        cardInfo = make([]string, cardEachNum*4)

        for i := 0;i < cardEachNum*4; i++ {
                j := i / cardEachNum
                k := (i % cardEachNum )+ 1

                cardInfo[i] = cardType[j] + strconv.Itoa(k)
        }

        readAndReplace()

        for i := 0;i < cardEachNum*4 ; i++ {
                mCard := cardInfo[i]
                if mCard != "" {
                        fmt.Printf("%s %s\n",mCard[0:1],mCard[1:])
                }
        }
}

func readAndReplace(){
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Scan()
        for scanner.Scan(){
                lineArgs := strings.Fields(scanner.Text())

                str := strings.Join(lineArgs,"")
                replaceBlank(cardInfo,str)
        }
}

func replaceBlank(strs []string, chk string){
        for i := 0; i<len(strs); i++{
                if strs[i] == chk {
                        strs[i] = ""
                }
        }
}


Measured memory_bytes: 1064
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

int main(){
    ll h,n; cin >> h >> n;
    vector<ll> dp(h+1,INF);
    vector<ll> a(n), b(n);
    rep(i,n)cin >> a[i] >> b[i];
    dp[0] = 0;
    rep(i,n){
        rep(j,h){
            if(dp[j] != INF){
                ll nj = min(h,j + a[i]);
                chmin(dp[nj], dp[j] + b[i]);
            }
        }
        // debug(i);
        // print(dp[i]);
    }

    cout << dp[h] << endl;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
from collections import deque
mod = 10**9 + 7

n, k = [int(x) for x in input().split()]
g = [[] for _ in range(n)]

for _ in range(n - 1):
    a, b = [int(x) for x in input().split()]
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

color = [-1]*n
ans = k

def bfs(u):
    global ans
    queue = deque([u])
    color[u] = k
    while queue:
        v = queue.popleft()
        cnt = 0
        if v == 0:
            start = k - 1
        else:
            start = k -2
        for i in g[v]:
            if color[i] < 0:
                color[i] = start - cnt
                cnt += 1
                ans *= color[i]
                ans %= mod
                queue.append(i)

bfs(0)
print(ans)
# print(color)

Measured memory_bytes: 61744
from itertools import product

N, A = map(int, input().split())
x = [int(x) for x in input().split()]

X = max(max(x), A)
dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
dp[0][N * X] = 1

for j, t in product(range(1, N + 1), range(2 * N * X + 1)):
    y = x[j - 1] - A
    if t - y < 0 or t - y > 2 * N * X:
        dp[j][t] = dp[j - 1][t]
    elif 0 <= t - y <= 2 * N * X:
        dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
print(dp[N][N * X] - 1)

Measured memory_bytes: 5972
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int h, n;
  cin >> h >> n;
  int a[n + 5], b[n + 5];
  reps(i, n){
    cin >> a[i] >> b[i];
  }
  vector<vector<lol> > dp(1005, vector<lol>(10005, LINF)); //dp[i][j] : i番目までの魔法で体力をj削るのに必要な最小魔力
  dp[1][0] = 0;
  reps(i, n){
    for(int j = 0;j <= h;j ++){
      dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
      if(j + a[i] > h){
	dp[i][h] = min(dp[i][h], dp[i][j] + b[i]);
      } else {
	dp[i][j + a[i]] = min(dp[i][j + a[i]], dp[i][j] + b[i]);
      }
      //cout << dp[i][j] << " ";
    }
    //cout << '\n';
  }
  cout << dp[n][h] << '\n';
  return 0;
}


Measured memory_bytes: 81848
def f():
  n = int(input())
  *li,=map(int, input().split())
  from collections import Counter
  c = Counter()
  for i in li:
    c[i] += 1
  ans=0
  from math import comb
  for i in c.values():
    ans += comb(i, 2)
  for i in li:
    print(ans - comb(c[i], 2) + comb(c[i]-1, 2))
f()
  

Measured memory_bytes: 32212
# dp[v] i番目までの品物で、価値がv以上になるよう選んだときの重さの最小値。
# 品物を増やすごとに、配列を更新して使いまわす。
# とれる価値の最大値VmaxはN*max(vi) 添え字は0<=v<=Vmax dpリストの長さはVmax+1
# ループは1~N回回す　添え字は0<=i<=N-1<N
# 解答はN回ループした後のdp[j]<=Wとなる最大のj

import numpy as np

# 入力 table[i][0]は重さ、table[i][1]は価値
N, W = map(int, input().strip().split())
t = []
for i in range(N):
    t.append(list(map(int, input().strip().split())))
table = np.array(t)

# 初期化 wiの最大値は10^9
Vmax = N * max(table[:, 1])
dp = np.full(Vmax + 1, 10 ** 9)
dp[0] = 0

# dp
for i in range(N):
    w = table[i][0]
    v = table[i][1]
    dp[v:] = np.minimum(dp[v:], dp[:-v] + w)

# 解答　dpの後ろから見て、最初にWを下回ったときのi
for j in range(Vmax, 0, -1):
    if dp[j] <= W:
        print(j)
        break

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i];
    }
    sort(all(a), greater<Int>());
    Int sum = 0;
    for (Int i = 0; i < (Int)k; i++) {
        sum += a[i];
    }
    print(sum);
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import sys
input = sys.stdin.readline


def dijkstra(graph: list, node: int, start: int) -> list:
    # graph[node] = [(cost, to)]
    INF = float('inf')
    dist = [INF] * node

    dist[start] = 0
    heap = [(0, start)]
    while heap:
        cost, thisNode = heappop(heap)
        for NextCost, NextNode in graph[thisNode]:
            dist_cand = dist[thisNode] + NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap, (dist[NextNode], NextNode))
    return dist
    # dist = [costs to nodes]


n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    l, r, c = map(int, input().split())
    l -= 1
    r -= 1
    edge[l].append((c, r))
for i in range(1, n):
    edge[i].append((0, i - 1))

dist = dijkstra(edge, n, 0)
ans = dist[-1] if dist[-1] != float("inf") else -1

print(ans)


Measured memory_bytes: 43844
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mm 1000000007
int main()
{
    IOS;
    ll a,b,c,d,e;
    cin>>a;
    b=a%1000;
    if(b==0)
    cout<<0<<endl;
    else
    cout<<1000-b<<endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String args[] ) throws Exception {
    	new Main().exec(args);
    }

    public Main() {
    }

    public void exec(String args[]) throws Exception {
    	Scanner sc = new Scanner(System.in);
    	int N=sc.nextInt();
    	sc.nextLine();
    	String s=sc.nextLine();
    	String t=sc.nextLine();

    	int NO=Math.max(N, Math.max(s.length(), t.length()));
    	char[] cas = s.toCharArray();
    	char[] cat = t.toCharArray();

    	for(;true;NO++) {
        	boolean flg=true;
        	for(int i=0; i<NO; i++) {
        		if(i<cas.length && NO-cat.length<=i && cas[i]!=cat[i-(NO-cat.length)]) {
        			flg=false;
        			break;
        		}
        	}
        	if(flg) {
        		break;
        	}
    	}
    	System.out.println(NO);
    }
}

Measured memory_bytes: 9808
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, k, i;
	cin >> k >> n;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	sort(arr, arr + n);
	
	vector <int> v;
	fo(i, 1, n)
	v.pb(arr[i] - arr[i - 1]);
	v.pb(k - (arr[n - 1] - arr[0]));
	
	sort(all(v));
	ll sum = accumulate(all(v), 0ll);
	sum -= *max_element(all(v));
	cout << sum;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int res=0;
    rep(i,100000){
        auto from=lower_bound(a,a+n,i);
        auto to=upper_bound(a,a+n,i+2);
        res=max(res,int(to-from));
    }
    cout << res<< endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       Scanner scan= new Scanner(System.in);
       int x=scan.nextInt();
       int y=scan.nextInt();
       int M=scan.nextInt();

       int count=0;
       for(;x<=y;x++){

           if(M%x==0){
               count++;
           }
       }

        System.out.println(count);
    }
}



Measured memory_bytes: 26236
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,m,p,q,r;
  while(cin>>n,n){
    cin>>m>>p>>q>>r;
    using P = pair<Int, Int>;
    vector<P> cur;
    cur.emplace_back(0,n);
    for(Int i=0;i<m;i++){
      Int x,y;
      cin>>x>>y;
      Int cnt=0;
      vector<P> mid,nxt;
      for(Int j=0;j<(Int)cur.size();j++){
	Int len=cur[j].second-cur[j].first;
	if(cnt+len<=x){
	  cnt+=len;
	  continue;
	}
	if(y<=cnt){
	  nxt.emplace_back(cur[j]);
	  cur[j]=P(-1,-1);
	  cnt+=len;
	  continue;
	} 
      
	if(cnt<=x&&y<=cnt+len){
	  P a(cur[j].first,cur[j].first+(x-cnt));
	  P b(cur[j].first+(x-cnt),cur[j].first+(y-cnt));
	  P c(cur[j].first+(y-cnt),cur[j].second);
	  mid.emplace_back(b);
	  nxt.emplace_back(c);
	  cur[j]=a;
	  cnt+=len;
	  continue;
	}

	if(x<=cnt&&cnt+len<=y){
	  mid.emplace_back(cur[j]);
	  cur[j]=P(-1,-1);
	  cnt+=len;
	  continue;
	}

	if(cnt<=x){
	  P a(cur[j].first,cur[j].first+(x-cnt));
	  P b(cur[j].first+(x-cnt),cur[j].second);
	  mid.emplace_back(b);
	  cur[j]=a;
	  cnt+=len;
	  continue;
	}

	if(y<=cnt+len){
	  P a(cur[j].first,cur[j].first+(y-cnt));
	  P c(cur[j].first+(y-cnt),cur[j].second);
	  mid.emplace_back(a);
	  nxt.emplace_back(c);
	  cur[j]=P(-1,-1);
	  cnt+=len;
	  continue;
	}
	
      }

      for(P x:mid) nxt.emplace_back(x);
    
      for(Int j=0;j<(Int)cur.size();j++)      
        if(cur[j].second-cur[j].first)
	  nxt.emplace_back(cur[j]);
    
      swap(cur,nxt);

      if(0){
	for(auto x:mid) cout<<x.first<<":"<<x.second<<endl;
	for(auto x:cur) cout<<x.first<<" "<<x.second<<endl;
	cout<<endl;
      }
    }
    
    Int x=p-1,y=q;
    Int cnt=0;
    vector<P> mid,nxt;
    for(Int j=0;j<(Int)cur.size();j++){
      Int len=cur[j].second-cur[j].first;
      if(cnt+len<=x){
	cnt+=len;
	continue;
      }
      if(y<=cnt){
	nxt.emplace_back(cur[j]);
	cur[j]=P(-1,-1);
	cnt+=len;
	continue;
      } 
      
      if(cnt<=x&&y<=cnt+len){
	P a(cur[j].first,cur[j].first+(x-cnt));
	P b(cur[j].first+(x-cnt),cur[j].first+(y-cnt));
	P c(cur[j].first+(y-cnt),cur[j].second);
	mid.emplace_back(b);
	nxt.emplace_back(c);
	cur[j]=a;
	cnt+=len;
	continue;
      }

      if(x<=cnt&&cnt+len<=y){
	mid.emplace_back(cur[j]);
	cur[j]=P(-1,-1);
	cnt+=len;
	continue;
      }

      if(cnt<=x){
	P a(cur[j].first,cur[j].first+(x-cnt));
	P b(cur[j].first+(x-cnt),cur[j].second);
	mid.emplace_back(b);
	cur[j]=a;
	cnt+=len;
	continue;
      }

      if(y<=cnt+len){
	P a(cur[j].first,cur[j].first+(y-cnt));
	P c(cur[j].first+(y-cnt),cur[j].second);
	mid.emplace_back(a);
	nxt.emplace_back(c);
	cur[j]=P(-1,-1);
	cnt+=len;
	continue;
      }
	
    }

    Int ans=0;
    for(P x:mid){
      if(x.second<=r) ans+=x.second-x.first;
      else if(x.first<r) ans+=r-x.first;
    }
      
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3520
#include <bits/stdc++.h>
 #include <math.h>
using namespace std;
#define ll long long
#define pi 3.14159265359

int main(){
 int n,k;
  cin>>n>>k;
 vector<int>a(n);
  int count=0;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
    if(a[i]>=k)count++;
  }
  cout<<count<<endl;
}
    

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int a,b,c,sum=0;
  scanf("%d%d%d",&a,&b,&c);
  if(a==5)
    ++sum;
  else if(a==7)
    sum+=2;
  if(b==5)
    ++sum;
  else if(b==7)
    sum+=2;
  if(c==5)
    ++sum;
  else if(c==7)
    sum+=2;
  if(sum==4)
    printf("YES");
  else
    printf("NO");
  return 0;
  }


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char *argv[])
{
	string s,t;
	cin >> s >> t;
	cout << t+s << endl;
	return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll N,ans,m,ind,mnew,ch,chr,mm;
  vl A;
  cin >> N;
  REP(i,N){
		int x;
		cin >> x;
		A.push_back(x);
	}
  m = 0;
  ch = 0;
  REP(i,N){
    mnew = max(A[i],m);
    if(m!=mnew){
      ch =i;
    }
    m = mnew;
  }
  A[ch] = 0;
  mm = 0;
  chr = 0;
  REP(i,N){
    mnew = max(A[i],mm);
    if(mm!=mnew){
      chr =i;
    }
    mm = mnew;
  }
  REP(i,N){
    if(i!=ch){
      cout << m << endl;
    }else{
      cout << mm << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;


/**
 *
 * @author
 *
 *
 *
 */

public class Main {
    public static void main(String[] args) throws IOException {
        MyScanner scanner = new MyScanner();
        PrintStream out = System.out;

        int[] data = scanner.nextIntArray();
        String string = scanner.next();

        String regex = "\\d{" + data[0] +"}-" + "\\d{" + data[1]  + "}" ;

        if (string.matches(regex)) {
            out.println("Yes");
        } else {
            out.println("No");
        }

        scanner.reader.close();
        out.close();
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader reader;

        public MyScanner() {
            this.reader = new BufferedReader(new InputStreamReader(System.in));
        }

        public void close() throws IOException {
            this.reader.close();
        }

        int nextInt() {
            return Integer.parseInt(this.next());
        }

        long nextLong() {
            return Long.parseLong(this.next());
        }

        double nextDouble() {
            return Double.parseDouble(this.next());
        }

        String next() {
            String str = "";
            try {
                str = this.reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        String[] nextStringArray() {
            String[] str = null;
            try {
                str = this.reader.readLine().trim().split(" ");
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArray() {
            String[] data  = nextStringArray();
            int[] a  = new int[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(data[i]);
            }

            return a;
        }

        Integer[] nextIntegerArray() {
            String[] data  = nextStringArray();
            Integer[] a  = new Integer[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(data[i]);
            }

            return a;
        }

        long[] nextLongArray() {
            String[] data  = nextStringArray();
            long[] a  = new long[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Long.parseLong(data[i]);
            }

            return a;
        }
    }
}



Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
#define PI 3.14159265359

int main() {
  ll N;
  cin >> N;
  ll n = N % 10;
  string str = "hon";
  if (n == 3) {
    str = "bon";
  } else if (n == 0 || n == 1 || n == 6 || n == 8) {
    str = "pon";
  }
  cout << str << endl;

  return 0;
}

Measured memory_bytes: 3596
k, n = map(int,input().split())

a = list(map(int,input().split()))
a.append(k+a[0])
maxgap = 0
al = a[-1] - a[0]

for l in range(n):
    gap = a[l+1] - a[l]
    maxgap = max(maxgap,gap)
print(al - maxgap)

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

const ll INF = 1e18;

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a+2), t(b+2);
    s[0] = t[0] = -INF;
    s[a+1] = t[b+1] = INF;
    rep1(i, a+1) cin >> s[i];
    rep1(i, b+1) cin >> t[i];
    rep(i, q) {
        ll x; cin >> x;
        ll ans = INF;
        int si = lower_bound(all(s), x) - s.begin();
        int ti = lower_bound(all(t), x) - t.begin();
        for (int j = si-1; j <= si; j++) {
            for (int k = ti-1; k <= ti; k++) {
                ll S = s[j];
                ll T = t[k];
                ans = min(ans, abs(S-x) + abs(T - S));
                ans = min(ans, abs(T-x) + abs(S - T));
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    rep(i,N) cin >> A[i]; sort(A.begin(),A.end());
    rep(i,N) cin >> B[i]; 
    rep(i,N) cin >> C[i]; sort(C.begin(),C.end());
    

    ll ans = 0;
    
    rep(i,N) {
	
	ll a = lower_bound(A.begin(),A.end(),B[i]) - A.begin();
	ll c = N - (upper_bound(C.begin(),C.end(),B[i]) - C.begin());
	ans += a*c;
//	cout << a << " " << c << endl;	
    }
    cout << ans << endl;

    
    return 0;
}



Measured memory_bytes: 5608
//#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
/*
int a[15];
int check(ll x){
	int i,top=0;
	while(x){
		a[++top]=x%10;
		x/=10;
	}
	for(i=2;i<=top;i++)
		if(abs(a[i]-a[i-1])>1)return 0;
	return 1;
}
int main(){
	int cnt=0;
	ll i,n;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
		if(check(i))
		 cnt++,printf("%lld,",i);
	printf("cnt= %d\n",cnt);
	system("pause");
}*/
ll num[maxn]={1,2,3,4,5,6,7,8,9};
int main()
{
	int k;
	scanf("%d",&k);
	if(k<=12)
	{
		printf("%d\n",k);
		system("pause");
		return 0;
	}
	int cnt=0;
	for(int i=9; i<k; )
	{
		if(!(num[cnt]%10))
		{
			num[i]=num[cnt]*10;
			num[i+1]=num[cnt]*10+1;
			i+=2;
		}
		else if(num[cnt]%10==9)
		{
			num[i]=num[cnt]*10+8;
			num[i+1]=num[cnt]*10+9;
			i+=2;
		}
		else
		{
			num[i]=num[cnt]*10+num[cnt]%10-1;
			num[i+1]=num[cnt]*10+num[cnt]%10;
			num[i+2]=num[cnt]*10+num[cnt]%10+1;
			i+=3;
		}
		cnt++;
	}
	printf("%lld\n",num[k-1]);
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n; 
struct node{
	int id,d;
	node(int d1=0,int id1=0){d=d1,id=id1;}
	friend bool operator <(node a,node b){return a.d<b.d;}
}a[maxn];
int sz[maxn],u[maxn],v[maxn],dis,cnt;
signed main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=node(read(),i),sz[i]=1;
	}
	sort(a+1,a+1+n);
	for(int i=n;i>1;i--){
		int d=a[i].d-n+(sz[i]<<1);
		int p=lower_bound(a+1,a+1+n,node(d,0))-a;
		if(a[p].d!=d){puts("-1");return 0;}
		cnt++;
		u[cnt]=a[i].id;v[cnt]=a[p].id;
		sz[p]+=sz[i];
		dis+=sz[i];
	}
	if(a[1].d!=dis){
		puts("-1");return 0;
	}
	for(int i=1;i<=cnt;i++){
		printf("%d %d\n",u[i],v[i]);
	}
	return 0;
}


Measured memory_bytes: 5248
string = input()
answer = True

if(not string.count('C') == 1 or not string[0] == 'A'):
    answer = False
for i in range(len(string)):
    if(string[i] == 'A'):
        if(i != 0):
            answer = False
            break;
    elif(string[i] == 'C'):
        if(i<2 or i == len(string)-1):
            answer = False
            break;
    elif(string[i].islower() == False):
        answer = False
        break;

if answer:
    print("AC")
else:
    print("WA")


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

int main() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    rep(i,m) {
        int a;
        cin >> a;
        sum += a;
    }
    if(sum > n) cout << -1 << endl;
    else cout << n-sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

vector<ll> S[15];
ll P[15];

int main(){
	ll N, M;
	cin >> N >> M;

	rep(i, M) {
		ll k;
		cin >> k;
		rep(j, k) {
			ll s;
			cin >> s;
			s--;
			S[i].push_back(s);
		}
	}

	rep(i, M) {
		cin >> P[i];
	}

	ll ans = 0;
	rep(state, (1<<N)) {
		bool ok = true;
		rep(i, M) {
			ll num = 0;
			for(ll s: S[i]) {
				if((state>>s)&1) {
					num++;
				}
			}

			if(num%2 != P[i]) {
				ok = false;
			}
		}
		if(ok) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>

int compareInt(const void* a, const void* b)
{
  int aNum = *(int*)a;
  int bNum = *(int*)b;

  return aNum - bNum;
}

int main(void){
  int n, m, sum=0;
  scanf("%d %d", &n, &m);
  int x[m], c[m-1];
  for(int i=0; i<m; i++){
    scanf("%d", &x[i]);
  }
  qsort(x, m, sizeof(int), compareInt);
  for(int j=0;j<m-1;j++){
    c[j] = x[j+1]-x[j];
  }
  qsort(c, m-1, sizeof(int), compareInt);
  for(int k = 0; k< m-n; k++){
    sum+=c[k];
  }
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 2760
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


# https://atcoder.jp/contests/code-festival-2016-qualb/tasks/codefestival_2016_qualB_b
N, A, B = ints()
S = read()[:-1]
cnt = Counter('')
for s in S:
    if s == 'a' and cnt['a'] + cnt['b'] < A + B:
        print('Yes')
        cnt.update(s)
    elif s == 'b' and cnt['a'] + cnt['b'] < A + B and cnt['b'] < B:
        print('Yes')
        cnt.update(s)
    else:
        print('No')
    # print(cnt)


Measured memory_bytes: 76836
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int l[8], n, a, b, c;
int dfs(int idx, int aa, int bb, int cc) {
  if (idx == n) {
    if (aa > 0 && bb > 0 && cc > 0) return abs(aa - a) + abs(bb - b) + abs(cc - c) - 30;
    else return INF;
  }
  return min({dfs(idx + 1, aa, bb, cc), dfs(idx + 1, aa + l[idx], bb, cc) + 10, dfs(idx + 1, aa, bb + l[idx], cc) + 10, dfs(idx + 1, aa, bb, cc + l[idx]) + 10});
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  cin >> n >> a >> b >> c;
  REP(i, n) cin >> l[i];
  cout << dfs(0, 0, 0, 0) << '\n';
  return 0;
}


Measured memory_bytes: 256
A, B = map(int, input().split())

cnt = 0
for i in range(A, B+1):
    man = i // 10000
    sen = (i % 10000) // 1000
    ten = (((i % 10000) % 1000) % 100) // 10
    one = i % 10
    if man == one and sen == ten:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
int main(){
    ll n,a,b; cin >> n >> a >> b;
    vl x(n);
    rep(i,n) cin >> x[i];
    ll ans = 0;
    rep(i,n-1){
        if((x[i+1]-x[i]) * a > b) ans += b;
        else ans += (x[i+1] - x[i]) * a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[51],b[51];
int main(){
    int n,r,p,c;
    while(cin>>n>>r,n){
        rep(i,n) a[i]=n-i;
        rep(i,r){
            cin>>p>>c;
            FOR(j,p-1,p+c-1) b[j-p+1]=a[j];
            for(int j=p-2;j>=0;--j) a[j+c]=a[j];
            rep(j,c) a[j]=b[j];
        }
        cout<<a[0]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3064
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e5+4;

int main()
{
	int x,y,a,b,c;

	scn(x); scn(y); scn(a); scn(b); scn(c);

	vector<pair<int,int>> v;

	rep(i,0,a)
	{
		int val; scn(val);

		v.emplace_back(val,1);
	}

	rep(i,0,b)
	{
		int val; scn(val);

		v.emplace_back(val,2);
	}

	rep(i,0,c)
	{
		int val; scn(val);

		v.emplace_back(val,3);
	}

	sort(v.rbegin(),v.rend());

	ll ans=0; int cnt=0,xx=0,yy=0;

	rep(i,0,(int)v.size())
	{
		if(xx+cnt+yy==x+y)
		break;

		if(v[i].S==3)
		cnt++,ans+=v[i].F;
		else if(v[i].S==1 and xx<x)
		xx++,ans+=v[i].F;
		else if(v[i].S==2 and yy<y)
		yy++,ans+=v[i].F;
	}

	lpri(ans);

    return 0;
}

Measured memory_bytes: 6256
/* Murad Eynizade */

#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second

using namespace std;

const int sz = 100005;

int n , m , x , y , used[sz] , ans[sz] , mx;

vector<int>v[sz];

void dfs(int s) {
    used[s] = 1;
    int res = 0;
    for (int to : v[s]) {
        if (!used[to])dfs(to);
        res = max(res,ans[to] + 1);
    }
    ans[s] = res;
    mx = max(mx,ans[s]);
}

int main()
{
    FAST_READ;
    cin>>n>>m;
    for (int i = 1;i<=m;i++) {
        cin>>x>>y;
        v[x].push_back(y);
    }
    for (int i = 1;i<=n;i++)
        if (!used[i])dfs(i);
    cout<<mx<<endl;
    return 0;
}


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

int main()
{
    unsigned long long n, a, b, s, x;
    scanf("%llu %llu %llu", &n, &a, &b);
    s = a + b;
    x = n % s;
    printf("%llu\n",(n / s) * a + min(a, x));
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		while(n!=0||x!=0)
		{
			for(int i=1;i<n-1;i++)
			{
				for(int j=i+1;j<n;j++)
				{
					for(int k=j+1;k<=n;k++)
					{
						if((i+j+k)==x && (i!=j && i!=k && j!=k))
						{
							count++;
							//System.out.print(i+" "+j+" "+k);
						}
					}
				}
			}
			System.out.println(count);
			count=0;
			n = scan.nextInt();
			x = scan.nextInt();
		}
	}
}

Measured memory_bytes: 19624
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int a = (s[0] - '0');
	int b = (s[1] - '0');
	int c = (s[2] - '0');
	int d = (s[3] - '0');
	rep(i,2){
		rep(j,2){
			rep(k,2){
				int val = a;
				if(i) val -= b;
				else val += b;
				if(j) val -= c;
				else val += c;
				if(k) val -= d;
				else val += d;
				if(val == 7){
					cout << a << (i ? "-" : "+");
					cout << b << (j ? "-" : "+");
					cout << c << (k ? "-" : "+");
					cout << d << "=7" << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

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

int main() {
  int a,b,c;
  char d,e;
  cin >> a >> d >> b >> c >> e;
  if(a < 2019){
    cout << "Heisei" << endl;
  }
  else if(b <= 4){
    cout << "Heisei" << endl;
  }
  else{
    cout << "TBD" << endl;
  }
}


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


int main(void){
  char s[1005],t[1005];  


  
  
  scanf("%s",s);
  scanf("%s",t);
   int ans = strlen(t);
  int lena = strlen(s);
  int lenb = strlen(t);

for(int i=0;i<lena-lenb+1;i++){
    int sum = 0;

   for(int j=0;j<lenb;j++){
    

      if(s[i+j]!=t[j]){
        sum= sum+1;
      }
        
    }
      
      if(sum<ans){
        ans = sum;
           //printf("%d", ans);

      }
    
  }
  

   printf("%d", ans);

    return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int fn(int i){
	if(i<=9) return i;
	else return i%10+fn(i/10);
}
 
int main(void){
	int N,A,B;
	ll result=0;
	cin>>N>>A>>B;
	FOR(i,1,N+1){
		int tmp=fn(i);
		if(A<=tmp&&tmp<=B) result+=i;
	}
	print(result);
	return 0;
}


Measured memory_bytes: 256