akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

	int n,d;
	cin >> n >> d;

	int a[n][d];
	FOR(i, n){
		FOR(j, d){
			cin >> a[i][j];
		}
	}

	int ans = 0;
	FOR(l, n){
		FORR(i, l+1, n){
			int temp = 0;
			FOR(j, d){
				temp += pow((a[l][j]-a[i][j]), 2);
			}

			//cout << temp << endl;
			if(sqrt(temp) == (int)sqrt(temp)){
				ans++;
			}
		}
	}

	cout << ans;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    }

    static char solve(String[] S) {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    }
}

Measured memory_bytes: 21844
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		int ans = 0;
		char[][] c = new char[H][W];
		for(int i=0;i<H;i++) {
			String S = sc.next();
			char[] C = S.toCharArray();
			c[i] = C;
		}
        for (int i = 0; i < 1 << H+W; i++) {
            // bit全探索の全通りのloop
        	int[] A = new int[H+W];
            for (int j = 0; j < H+W; j++) {
                 if ((1 & i >> j) == 1) {
                	 A[j]=1;
                 }
            }
            // 行
            int[] R = new int[H];
            for(int k=0;k<H;k++) {
            	R[k]=A[k];
            }
            // 列
            int[] C = new int[W];
            for(int k=H;k<H+W;k++) {
            	C[k-H]=A[k];
            }
            int cnt = 0;
            for(int k=0;k<H;k++) {
            	for(int l=0;l<W;l++) {
            		if(c[k][l]=='#') {
            			if(C[l]==0&&R[k]==0) {
                			cnt++;
            			}
            		}
            	}
            }
            if(cnt==K) {
            	ans++;
            }

        }
        System.out.println(ans);
    }
}


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

int INF = 1e9;

int main(){
    int h,w;
    cin >> h >> w;
    int table[10][10];
    int box[h][w];
    rep(i,10)rep(j,10) cin >> table[i][j];
    rep(i,h)rep(j,w) cin >> box[i][j];

    int dp[10][10];
    rep(i,10) {
        dp[0][i] = INF;
        dp[1][i] = table[i][1];
    }
    for(int i = 1;i<=8;i++){
        rep(j,10){
            if(j==1) continue;
            dp[i+1][j] = dp[i][j];
            rep(k,10){
                if(k==j || k==1) continue;
                dp[i+1][j] = min(dp[i+1][j],dp[i][k]+table[j][k]);
            }
        }
    }
    int ans = 0;
    rep(i,h)rep(j,w){
        if(abs(box[i][j])!=1) ans += dp[9][box[i][j]];
    }

    cout << ans << endl;

}

Measured memory_bytes: 3724
map = []

for x in range(3):
    a, b = [int(x) for x in input().split(" ")]
    map.append([a, b])

cnt = [0, 0, 0, 0]

for i in range(3):
    for j in range(2):
        cnt[map[i][j]-1] += 1

for c in cnt:
    if c == 3:
        print("NO")
        exit()

print("YES")


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

#define MASU_MAX	(2019)
#define KOMA_MAX	(100)

int N;
int M;
int A;
int X[KOMA_MAX];

int main(void) {

	scanf("%d", &N);

	int tmp = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &tmp);
		X[i] = tmp;
	}

	scanf("%d", &M);
	for (int j = 0; j < M; j++) {
		scanf("%d", &A);
		if (X[A - 1] == 2019) {	// ゴールにいる場合は進めない
			continue;
		}
		int pos = X[A - 1] + 1;
		int exist = 0;
		for (int i = 0; i < N; i++) {
			if (i == A - 1) {	// 自分は見ない
				continue;
			}
			if (X[i] == pos) {
				exist = 1;
				break;
			}
		}
		if (exist == 0) {	// 移動先にいない場合は進める
			X[A - 1]++;
		}
	}

	for (int i = 0; i < N; i++) {
		printf("%d\n", X[i]);
	}

	return 0;
}



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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;

	int ans = pow(2, int(log2(n)));

	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define pi 3.14159265358979323846
int i;
int main(){
    int n,m,sum=0;cin>>n>>m;
    

    for(i=0;i<m;i++){
        int a;cin>>a;
        sum+=a;
    }

    if(n-sum>=0){cout<<n-sum<<endl;}
    else{cout<<-1<<endl;}
    return 0;
}

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

int main(){
    long long a,b;
    std::cin >> a >> b;
    if (a % 2019 == 0 || b % 2019 == 0){
        return !(std::cout << 0 << std::endl);
    }
    if (a / 2019 == b / 2019){
        long long min = 2019;
        for(int i = a; i <= b - 1; ++ i){
            for(int j = i + 1; j <= b; ++ j){
                min = min > ((i % 2019) * (j % 2019)  % 2019) ? ((i % 2019) * (j % 2019)  % 2019) : min;
            }
        }
        return !(std::cout << min << std::endl);
    }else return !(std::cout << 0 << std::endl);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int hh = (h2 - h1);
	int mm = (m2 - m1) + hh * 60;
	cout << max(0, mm - k) << endl;
}





Measured memory_bytes: 3640
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var a = lines[1].split(" ").map(value => Number(value));

    var counter = {};
    for (var value of a) {
        if (counter[value] === undefined) { counter[value] = 0; }
        counter[value]++;
    }

    var ans = 0;
    Object.keys(counter).forEach(i => {
        var index = Number(i);
        
        // 当該数字　=== index or 当該数字 === 0
        if (index !== counter[index]) {

            if (index < counter[index]) { ans += counter[index] - index }
            else { ans += counter[index] }
        }
    });

    console.log(ans)
});

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

struct edge{
  int u,v,w;
};

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}

  ll N,K; cin>>N>>K;
  ll n = N/K;
  ll ans = n*n*n;
  if(K%2==0){
    ll m = (N+K/2)/K;
    ans += m*m*m;
    dprint(m);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3640
N = int(input())
x = [0] * N
u = [0] * N
for i in range(N):
  x[i], u[i] = map(str, input().split())
conv = 380000
total = 0
for i in range(N):
  if u[i] == 'BTC':
    x[i] = conv * float(x[i])
  total += float(x[i])
print(total)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
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; }

const long long INF = 1LL<<60;
int N;
long long X;
vector<long long> A;

long long solve() {
    long long res = INF;
    for (int i = 0; i < N; ++i) A.push_back(A[i]);
    vector<long long> bmin(N, INF);
    for (int k = 0; k < N; ++k) {
        long long tmp = 0;
        for (int i = 0; i < N; ++i) {
            chmin(bmin[i], A[i+k]);
            tmp += bmin[i];
        }
        chmin(res, tmp + X*k);
    }
    return res;
}

int main() {
    while (cin >> N >> X) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 3652
macro_rules! scan {
    // Scan item
    ($t:ty) => {
        {
            let mut buffer: String = String::new();
            std::io::stdin().read_line(&mut buffer).unwrap();
            buffer.trim().parse::<$t>().unwrap()
        }
    };
    // Scan tuple
    ($($t:ty),*) => {
        {
            let mut buffer: String = String::new();
            std::io::stdin().read_line(&mut buffer).unwrap();
            let mut it = buffer.split_whitespace();
            (
                $(it.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    // Scan values separated by whitespace
    ($t:ty;) => {
        {
            let mut buffer: String = String::new();
            std::io::stdin().read_line(&mut buffer).unwrap();
            buffer.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

fn main() {
    let _ = scan!(usize);
    let students = scan!(usize;);
    let mut students = students
        .into_iter()
        .enumerate()
        .map(|(i, s)| ((i + 1).to_string(), s))
        .collect::<Vec<_>>();

    students.sort_by(|&(_, a), &(_, b)| a.partial_cmp(&b).unwrap());
    let students = students.into_iter().map(|(i, _)| i).collect::<Vec<_>>();
    println!("{}", students.join(" "));
}

Measured memory_bytes: 14504
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pb push_back
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	if(n==0||k==1) cout<<"0\n";
	else{
	   if(k>=2*n) cout<<n<<"\n";
	   else{
	   while(k<2*n){
	       ll x=n/k;
	       if(x==0) x=1;
	       n = abs(n - x*k);
	   }
	   cout<<n<<"\n";
	   }
	}
	
	return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	H, W = rli()
	M = []
	#0 white, 1 black
	for _ in range(H):
		row = list(rll()[0])
		row = list(map(lambda x: 0 if x == "." else 1, row))
		M.append(row)

	dp = [[INF if i != 0 and j != 0 else 0 for j in range(W)] for i in range(H)]
	dp[0][0] = 1 if M[0][0] == 1 else 0
	
	for c in range(1, W):
		if M[0][c-1] == 0 and M[0][c] == 1:
			dp[0][c] = dp[0][c-1] + 1
		else:
			dp[0][c] = dp[0][c-1]
	for r in range(1, H):
		if M[r-1][0] == 0 and M[r][0] == 1:
			dp[r][0] = dp[r-1][0] + 1
		else:
			dp[r][0] = dp[r-1][0]

	for r in range(1, H):
		for c in range(1, W):
			c1, c2 = INF, INF
			if M[r-1][c] == 0 and M[r][c] == 1:
				c1 = dp[r-1][c] + 1
			if M[r][c-1] == 0 and M[r][c] == 1:
				c2 = dp[r][c-1] + 1
			c1 = dp[r-1][c] if c1 == INF else c1 
			c2 = dp[r][c-1] if c2 == INF else c2
			dp[r][c] = min(c1, c2)
	print(dp[-1][-1])
	stdout.close()

if __name__ == "__main__":
	main()

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n; cin >> n;
  rep2(i, 1, 10) rep2(j, 1, 10) if (i * j == n) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;

const int maxn=1000006;
//int f[maxn];

int main()
{
    ll k,n;
    cin >> k >> n;
    vll v(n+1);
    for(int i=0;i<n;i++) {
        cin >> v[i];
        //f[v[i]]++;
    }
    v[n]=k+v[0];
    ll mx=k;

    for(int i=0;i<n;i++){
        mx=min(mx,k-abs(v[i]-v[i+1]));
    }
    cout << mx << endl;


}


Measured memory_bytes: 1920
n = int(input())
h = list(map(int, input().split()))
h.reverse()
s = h[0]
z = 'Yes'
for i in range(n-1):
    if h[i] <= s:
        s = h[i]
    elif h[i]-s == 1:
        s = s
    else:
        z = 'No'
        break
print(z)

Measured memory_bytes: 20840
#include<stdio.h>

int main(){
  int i, j, data[10], stock;

  for(i = 0; i < 10; i++){
    scanf("%d",&data[i]);
  }

  for(i = 0; i < 3; i++){
    for(j = i + 1; j < 10; j++){
      if(data[i] < data[j]){
	stock = data[i];
	data[i] = data[j];
	data[j] = stock;
      }
    }
  }

  for(i = 0; i < 3; i++){
    printf("%d\n",data[i]);
  }

  return 0;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, K;
    double sum = 0;
    cin >> N >> K;
    for(ll i = 1;i <= N;i++) {
        sum += 1.0 / N * pow(0.5, ceil(max(0.0, log2((double)K / i))));
    }
    cout << fixed << setprecision(9) << sum << endl;
    return 0;
}


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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    int N;
    int a,b;
    int ress,resf;
    int dists[100001],distf[100001];
    queue<int> q;
    vector<int> g[100001];

    for(int i=0;i<100001;i++){
        dists[i] = -1;
        distf[i] = -1;
    }
    scanf("%d",&N);
    distf[1] = 0;
    dists[N] = 0;
    
    for(int i=0;i<N-1;i++){
        scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    q.push(1);

    while(q.size()>0){
        int n = q.front();
        q.pop();
        for(auto itr =g[n].begin();itr!=g[n].end();itr++){            
            if(distf[*itr]==-1){
                distf[*itr] = distf[n]+1;
                q.push(*itr);
            }
        }
        
    }

    q.push(N);

    while(q.size()>0){
        int n = q.front();
        q.pop();
        for(auto itr =g[n].begin();itr!=g[n].end();itr++){
            if(dists[*itr]==-1){
                dists[*itr] = dists[n]+1;
                q.push(*itr);
            }
        }
    }
    ress = 0;
    resf = 0;
    for(int i=1;i<=N;i++){
        if(dists[i]>=distf[i])
            resf++;
        else
            ress++;
    }
    

    if(ress<resf)
        printf("Fennec\n");
    else
        printf("Snuke\n");

    return 0;
}


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

void roll(string &a, string &b, string &c, string &d, string &e, string &f, string direction)
{
	string a3 = a, b3 = b, c3 = c, d3 = d, e3 = e, f3 = f;
	if (direction == "W")
	{
		a = c3; d = a3; f = d3; c = f3;
	}
	if (direction == "N")
	{
		e = a3; f = e3; b = f3; a = b3;
	}
	if (direction == "E")
	{
		a = d3; c = a3; d = f3; f = c3;
	}
	if (direction == "S")
	{
		a = e3; b = a3; f = b3; e = f3;
	}
	if (direction == "R")
	{
		b = d3; c = b3; e = c3; d = e3;
	}
}

bool same(string a1, string b1, string c1, string d1, string e1, string f1, string a2, string b2, string c2, string d2, string e2, string f2)
{
	if (a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2 && e1 == e2 && f1 == f2) return true;
	else return false;
}


int main()
{
	string a1, b1, c1, d1, e1, f1;
	cin >> a1 >> b1 >> c1 >> d1 >> e1 >> f1;
	string a2, b2, c2, d2, e2, f2;
	cin >> a2 >> b2 >> c2 >> d2 >> e2 >> f2;
	bool f = false;
	
	if (same(a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2) == true) f = true ;
	else
	{
		for (int i = 0; i < 4; i++)
		{
			roll(a1, b1, c1, d1, e1, f1, "R");
			if (same(a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2) == true) f = true;
		}
		roll(a1, b1, c1, d1, e1, f1, "N");
		for (int i = 0; i < 4; i++)
		{
			roll(a1, b1, c1, d1, e1, f1, "R");
			if (same(a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2) == true) f = true;
		}
		roll(a1, b1, c1, d1, e1, f1, "E");
		for (int i = 0; i < 4; i++)
		{
			roll(a1, b1, c1, d1, e1, f1, "R");
			if (same(a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2) == true) f = true;
		}
		roll(a1, b1, c1, d1, e1, f1, "N");
		for (int i = 0; i < 4; i++)
		{
			roll(a1, b1, c1, d1, e1, f1, "R");
			if (same(a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2) == true) f = true;
		}
		roll(a1, b1, c1, d1, e1, f1, "N");
		for (int i = 0; i < 4; i++)
		{
			roll(a1, b1, c1, d1, e1, f1, "R");
			if (same(a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2) == true) f = true;
		}
		roll(a1, b1, c1, d1, e1, f1, "E");
		for (int i = 0; i < 4; i++)
		{
			roll(a1, b1, c1, d1, e1, f1, "R");
			if (same(a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2) == true) f = true;
		}
	}
	cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3168
N, C = map(int, input().split())
D = []
V = [0]

for i in range(N):
    x, v = list(map(int, input().split()))
    D.append(x)
    V.append(V[i] + v)

# clockwise
L = [0]
for i in range(N):
    L.append(max(L[i], V[i + 1] - D[i]))
L_ = max(L)
# counterclockwise
R = [0]
for i in range(N):
    R.append(max(R[i], V[N] - V[N - i - 1] - (C - D[-i - 1])))
R_ = max(R)
# clockwise - counterclockwise
LR = 0
for i in range(N - 1):
    LR = max(LR, V[i + 1] - D[i] * 2 + R[N - i - 1])

# counterclockwise - clockwise
RL = 0
for i in range(N - 1):
    RL = max(RL, V[N] - V[N - i - 1] - (C - D[-i - 1]) * 2 + L[N - i - 1])

print(max(L_, R_, LR, RL))

Measured memory_bytes: 19764
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    int a[100010], b[100010];
    cin >> n;
    rep(i, n){
        cin >> a[i] >> b[i];
    }

    ll cnt = 0;
    repr(i, n-1, 0){
        if((a[i]+cnt)%b[i] == 0) continue;
        cnt += b[i] - (a[i]+cnt)%b[i];
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int x,y,z,sum=0,zi,zj;
    scanf("%d%d",&x,&y);
    for(z=x;z<=y;z++)
    {
        zi=0;
        zj=z;
        while(zj)
        {
            zi*=10;
            zi+=(zj%10);
            zj/=10;
        }
        if(zi==z)
            sum++;
    }
    printf("%d",sum);
    return 0;
}


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

int main()
{
    int K, N;
    cin >> N >> K;
    vector<int> A(N);
    map<int, int> B{};
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
        B[A.at(i)]++;
    }

    vector<int> C;
    for (pair<int, int> p : B)
    {
        C.push_back(p.second);
    }
    sort(C.begin(), C.end());

    int ans = 0;
    if (C.size() > K)
    {
        for (int i = 0; i < C.size() - K; i++)
        {
            ans += C.at(i);
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N,K=0;
  int num=1;
  cin >> N >> K;
  for(int i=0;i<N;i++){
	if(num*2 < num+K){
      num = num*2;
    }else{
      num = num+K;
    }
  }
  cout << num << endl;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, k, a[202020];
int d[202020];
void solve(){
	cin >> n >> k;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(d[a[i]] == 0) cnt++;
		d[a[i]]++;
	}
	sort(d,d+n+1);
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(d[i] == 0) continue;
		if(cnt <= k) break;
		cnt--;
		ans += d[i];
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const ll linf = 0x3f3f3f3f3f3f3f3f;

inline void chk_min(ll &a,ll b){ if(a>b) a=b;}

ll n,a,b,c,d;

int p[10] = {2,3,5};
int cost[10];
map<ll,ll> dis;

ll dfs(ll n)
{
	if(dis.find(n) != dis.end()) return dis[n];
	
	ll res = linf;
	if(n <= res/d) res = n*d;
	
	for(int i=0; i<3; ++i)
	{
		int p = ::p[i];
		ll cost = ::cost[i];
		
		chk_min(res, dfs(n/p) + cost + n%p * d);
		if(n%p) chk_min(res, dfs(n/p+1) + cost + (p-n%p) * d);
	}
	return dis[n] = res;
}

void solve(void)
{
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	cost[0] = a;
	cost[1] = b;
	cost[2] = c;
	
	dis.clear();
	dis[0]=0; dis[1]=d;
	printf("%lld\n",dfs(n));
}

int main(void)
{
	int T;
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}

Measured memory_bytes: 4132
// https://atcoder.jp/contests/abc164/tasks/abc164_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, M, S;
  cin >> N >> M >> S;

  struct Edge {
    ll to, silver_cost, time_cost;
  };

  ll sum_silver_cost = 0;

  V<V<Edge>> edge_list(N);
  VL change_cts(N);
  VL change_time_costs(N);

  rep(i, M) {
    ll u, v, silver, time;
    cin >> u >> v >> silver >> time;
    --u, --v;
    sum_silver_cost += silver;
    edge_list[u].push_back({v, silver, time});
    edge_list[v].push_back({u, silver, time});
  }

  rep(i, N) {
    cin >> change_cts[i];
    cin >> change_time_costs[i];
  }

  // ダイクストラ
  // costs[i][silver_ct]: silver_ct の枚数を持った頂点 i までの最小コスト
  VVL costs(N, VL(sum_silver_cost + 1, INF));

  ll initial_s = min(S, sum_silver_cost);

  priority_queue<P<PL, ll>, V<P<PL, ll>>, greater<P<PL, ll>>> q;
  q.emplace(PL(0, initial_s), 0);

  while (!q.empty()) {
    auto p = q.top();
    q.pop();

    ll cur_time = p.fi.fi;
    ll cur_silver = p.fi.se;
    ll u = p.se;

    if (cur_time > costs[u][cur_silver]) continue;

    for (auto e : edge_list[u]) {
      rep(changed_ct, INF) {
        ll n_silver = cur_silver + change_cts[u] * changed_ct - e.silver_cost;
        if (n_silver < 0) continue;
        if (n_silver > sum_silver_cost) break;
        ll n_time = cur_time + change_time_costs[u] * changed_ct + e.time_cost;

        if (chmin(costs[e.to][n_silver], n_time)) {
          q.emplace(PL(n_time, n_silver), e.to);
        }
      }
    }
  }

  rep(i, N) {
    if (i == 0) continue;
    ll res = *min_element(all(costs[i]));
    cout << res << "\n";
  }
}


Measured memory_bytes: 53484
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back 
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int fac(int n)
{
    if(n<2) return 1;
    return n*fac(n-1);
}

void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    int x;
    char c;
    cin>>c;
    cout<<(char)(c+1);
}


signed main()
{
 //   #ifndef ONLINE_JUDGE 
 //      freopen("input.txt","r",stdin);
 //      freopen("output.txt","w",stdout);
//#endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <cstring>
#include <set>
#include <bitset>
#include <map>
#include <chrono>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;
const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);

#define all(c) (c).begin(),(c).end()
#define forn(i, a, b) for(int i = a; i < b; i++)
#define read(x) scanf("%d", &x)
#define readv(x, n) vll x(n); forn(i,0,n) scanf("%lld", &x[i])

#define pb push_back
#define mp make_pair


int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "wt", stdout);
//#endif
    char c[20];
    int n;
    scanf("%d", &n);
    printf("0\n");
    fflush(stdout);
    scanf("%s", c);
    int p0, p1;
    if(string(c) == "Vacant") return 0;
    else if(string(c) == "Male") p0 = 0;
    else p0 = 1;
    int mid = n/2;
    printf("%d\n", mid);
    fflush(stdout);
    scanf("%s", c);
    if(string(c) == "Vacant") return 0;
    else if(string(c) == "Male") p1 = 0;
    else p1 = 1;
    int l,r;
    int pl, pr;
    int eq = 0;
    if(p0 == p1) eq = 1;
    if(mid%2 == eq) {
        l = 0;
        r = mid;
        pl = p0;
        pr = p1;
    }
    else {
        l = mid;
        r = n;
        pl = p1;
        pr = p0;
    }
    while(1) {
        int m = (r+l)/2;
        printf("%d\n", m);
        fflush(stdout);
        scanf("%s", c);
        int p;
        if(string(c) == "Vacant") return 0;
        else if(string(c) == "Male") p = 0;
        else p = 1;
        eq = 0;
        if(p==pl) eq = 1;
        if((m-l)%2 == eq) {
            r = m;
            pr = p;
        }
        else {
            l = m;
            pl = p;
        }
    }
}


Measured memory_bytes: 852
import cmath
EPS = 1e-6

#外積
def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag

#点が直線上にあるか
def IsOnLine(point, begin, end):
	return abs(OuterProduct(begin-point, end-point)) <= EPS

#3点が反時計回りか
#一直線上のときの例外処理できていない→F
def CCW(p, q, r):
	one, two = q-p, r-q
	if OuterProduct(one, two) > EPS:
		return True
	else:
		return False

def Crosspoint(a, b, c, d):
	if abs(OuterProduct(b-a, d-c)) <= EPS:
		return False
	else:
		u = OuterProduct(c-a, d-a) / OuterProduct(b-a, d-c)
		return (1-u)*a + u*b

#凹多角形の面積(多角形は反時計回りに与えられる)
def Area(dots):
	res = 0
	for i in range(len(dots)-1):
		res += OuterProduct(dots[i], dots[i+1])
	res += OuterProduct(dots[-1], dots[0])
	return res/2

n = int(input())
dots = []
for _ in range(n):
	x, y = map(float, input().split())
	dots.append(complex(x, y))

q = int(input())
for _ in range(q):
	x, y, z, w = map(int, input().split())
	p1, p2 = complex(x, y), complex(z, w)
	res = []
	for i in range(-1, n-1):
		if IsOnLine(dots[i], p1, p2) or CCW(p1, p2, dots[i]):
			res.append(dots[i])
		if not IsOnLine(dots[i], p1, p2) and not IsOnLine(dots[i+1], p1, p2) and (CCW(p1, p2, dots[i]) != CCW(p1, p2, dots[i+1])):
			res.append(Crosspoint(dots[i], dots[i+1], p1, p2))
	if not res:
		print(0)
	else:
		print(Area(res))



Measured memory_bytes: 5712
import sys
import collections

N = int(input())
List = [list(input())]
for i in range(1,N):
    tmp = list(input())
    if (tmp in List) == True:
        print('No')
        sys.exit()
    List.append(list(tmp))
    
    if tmp[0] != List[i-1][-1]:
        print('No')
        sys.exit()


print('Yes')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

template<class T>
struct segment_tree {
    using F = function<T(T,T)>;
    int n;
    vector<T> data;
    F f;
    T init_v;

    segment_tree(int n_, T init_v, F f) : f(f), init_v(init_v) {
        n = 1;
        while (n < n_) n *= 2;
        data.assign(2*n-1,init_v);
    }

    //kをaに変更
    void update(int k, T a) {
        k += n-1;
        data[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = f(data[k*2+1],data[k*2+2]);
        }
    }

    //[a,b)のquery,kは節点番号
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return init_v;
        if (a <= l && r <= b) return data[k];
        else {
            T vl = query(a,b,k*2+1,l,(l+r)/2);
            T vr = query(a,b,2*k+2,(l+r)/2,r);
            return f(vl,vr);
        }
    }

    T operator[](int a) {return data[a+n-1];}

    //[a,b)を出力
    void debug_seg(int a, int b) {
        a += n-1; b += n-1;
        for (int i = a; i < b; i++) {
            cout << data[i] << " ";
        }
        cout << endl;
    }
};

int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;
    auto f = [](P a, P b) {
        if (a.first <= b.first) return a;
        else return b;
    };
    segment_tree<P> sg(n+1,P(inf,-1),f);
    sg.update(0,P(0,0));
    vint pre(n+1,-1);
    REP(i,n+1) {
        // sg.debug_seg(0,n+1);
        if (s[i] == '1') continue;
        P p = sg.query(max(0,i-m),i);
        pre[i] = p.second;
        sg.update(i,P(p.first+1,i));
    }
    vint path;
    for (int i = n; pre[i] != -1; i = pre[i]) {
        path.push_back(i);
    }
    path.push_back(0);
    reverse(all(path));
    if (path.size() == 1) cout << -1 << endl;
    else {
        rep(i,path.size()-1) cout << path[i+1] - path[i] << endl;
    }
}

Measured memory_bytes: 6296
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

ll qpow(ll a, ll b)
{
   ll res = 1;
   while(b){
      if(b & 1)  res = res * a % mod;
      a = a * a % mod;
      b >>= 1;
   }
   return res;
}

int main()
{  
   int n;
   cin >>n;
   cout << ((qpow(10,n) - 2 * qpow(9,n)  + mod * 2) % mod + qpow(8,n) ) % mod;
   return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
long min (long x,long y)
{
    if(x > y)   return y;
    else return x;
}
int main (void)
{
    long len = 0;
    long counta = 0;
    long countb = 0;
    char n[100000];
    scanf("%s",n);
    while (n[len]) {
        len ++;
    }

    // ここまで，配列の長さを取得//
    char a[len],b[len];
    a[0] = 0;
    b[0] = 1; 
    for (int i = 1; i < len; i++)   {
        if(a[i-1] == 0) a[i] = 1;
        else a[i] = 0;
        if(b[i-1] == 0) b[i] = 1;
        else b[i] = 0;  
    }
    for (int i = 0; i < len; i++)   {
        if(a[i]+'0' != n[i])    counta ++;
        if(b[i]+'0' != n[i])    countb ++;
    }
    printf("%ld",min(counta,countb));
}

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

long long int N, a[364364], b, c;

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i)
        scanf("%lld", a + i);
    for(int i = 0, j = -1; i < N; ++i){
        b ^= a[i];
        c += a[i];
        while(b != c){
            ++j;
            b ^= a[j];
            c -= a[j];
        }
        a[360364] += i - j;
    }
    cout << a[360364] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define vin(v, N) vi v; rep(i, N) {int x; cin >> x; v.push_back(x);}
#define vout(v, N) rep(i, N) {cout << v[i] << " ";} cout << endl;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

const int MAX_N = 2e5 + 5;

ll dp[MAX_N];
ll pre[MAX_N];
void solve() {
    ll mod = 998244353;
    memset(dp, 0, sizeof(dp));
    memset(pre, 0, sizeof(pre));
    int N, K;
    cin >> N >> K;
    vii v;
    rep(i, K) {
        int l, r;
        cin >> l >> r;
        v.push_back({l, r});
    }
    dp[0] = 1;
    pre[1] = dp[0];
    REP(i, 1, N-1) {
        rep(j, K) {
            dp[i] = (dp[i] + pre[max(0, i-v[j].first+1)] - pre[max(0, i-v[j].second)] + mod) % mod;
        }
        pre[i+1] = (pre[i] + dp[i]) % mod;
    }
//    vout(dp, N)
//    vout(pre, N+1)
    cout << dp[N-1];
}

//#define LOCAL 1

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();

    return 0;
}


Measured memory_bytes: 6784
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 1e6+2;

int main()
{
    int s, w;
    scn(s); scn(w);

    puts(w >= s? "unsafe": "safe");
    
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include<vector>
#include <algorithm>
using LL = long long;
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> B(N+1, -100);
	for (int n = 1; n <= N - 1; n++) {
		cin >> B[n];
	}
	B[N] = B[N - 1];
	B[0] = B[1];
	LL res = 0;
	for (int n = 1; n <= N; n++) {
		LL temp = min(B[n], B[n - 1]);
		res += temp;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3600
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vtype(type) vector<type>
#define vvtype(type) vector<vector<type>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORTV(a,n) sort(a.begin() + 1, a.begin() + 1 + n)
#define SORTVO(a,n,order) sort(a.begin() + 1, a.begin() + n + 1, order)
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

struct edge
{
	long long to; ll name;
	bool operator<(const edge& rhs) const {
		return name > rhs.name;
	}
};

struct wall {
	ll x; ll y;
	bool operator<(const wall& rhs)const {
		if (x != rhs.x) {
			return x < rhs.x;
		}
		else {
			return y < rhs.y;
		}
	}
};

ll const MAX = 4000;
vector<wall> u(MAX);

vll fct(1e6);
vll fct_inv(1e6);

void init() {
	fct[0] = 1;
	fct_inv[0] = 1;
	REP(i, 1, 1e6-1) {
		fct[i] = mod_m(fct[i - 1], i);
		fct_inv[i] = mod_inv(fct[i]);
	}
}

ll comb(ll x, ll y) {
	return mod_m(fct[x], mod_m(fct_inv[y], fct_inv[x - y]));
}

ll ways(ll x, ll y) {
	return comb(x + y, y);
}

vll dp(MAX);

int main() {
	init();
	ll w, h, n;
	cin >> h >> w >> n;
	REP(i, 1, n) {
		ll a, b;
		cin >> a >> b;
		u[i] = { a,b };
	}
	SORTV(u, n);
	u[0] = { 1,1 };
	u[n + 1] = { h,w };
	dp[0] = 1;
	REP(i, 1, n + 1) {
		REP(j, 0, i - 1) {
			if (u[j].y <= u[i].y) {
				ll xx = u[i].x - u[j].x;
				ll yy = u[i].y - u[j].y;
				dp[i] = mod_p(dp[i], -mod_m(dp[j], ways(xx, yy)));
			}
		}
	}
	cout << (MOD - dp[n + 1]) % MOD << endl;
}

Measured memory_bytes: 16128
// 5/26
// 2-5-3 最小全域木
// 類題
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// UnionFind
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

// クラスカル法ではグラフは辺の集合として定義（無向が前提）
struct Edge {
    int u;
    int v;
    int cost;
    Edge(int u, int v, int c) : u(u), v(v), cost(c) { }
    // Edge(int u_, int v_, int c) : u(u_), v(v_), cost(c) { }
    // Edge(int u, int v, int c) {
    //     this->u = u;
    //     this->v = v;
    //     this->cost = c;
    // }
    bool operator<(const Edge& o) const {
        return cost < o.cost;
    }
};
using Graph = vector<Edge>;

ll kruskal(int N, Graph& es) {  // ここでconstはだめ。ソートするから。いっぱいエラー出る。http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/27/mst-copy.html
    sort(es.begin(), es.end());
    UnionFind uf(N);
    ll res = 0;
    for (auto e : es) {
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    int N;
    cin >> N;

    Graph es;
    vector<P> Vx, Vy;  // {x or y coordinate, index}

    rep(i, N) {
        int x, y;
        cin >> x >> y;
        Vx.push_back({x, i});
        Vy.push_back({y, i});
    }

    sort(Vx.begin(), Vx.end());
    sort(Vy.begin(), Vy.end());

    // cout << "Vx-----" << endl;
    // rep(i, N) cout << Vx[i].first << " " << Vx[i].second << endl;
    // cout << "Vy-----" << endl;
    // rep(i, N) cout << Vy[i].first << " " << Vy[i].second << endl;

    rep(i, N - 1) {
        int u, v, cost;

        u = Vx[i].second;
        v = Vx[i + 1].second;
        cost = Vx[i + 1].first - Vx[i].first;
        // cout << cost << endl;
        es.push_back(Edge(u, v, cost));

        u = Vy[i].second;
        v = Vy[i + 1].second;
        cost = Vy[i + 1].first - Vy[i].first;
        // cout << cost << endl;
        es.push_back(Edge(u, v, cost));
    }

    // rep(i, N) {
    //     for (int j = i + 1; j < N; j++) {
    //         int cost = min(abs(V[i].first - V[j].first), abs(V[i].second - V[j].second));
    //         es.push_back(Edge(i, j, cost));
    //     }
    // }

    cout << kruskal(N, es) << endl;
}


Measured memory_bytes: 7144
#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int main()
{
	string s;
	char c[10];
	int p = 0;

	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != 'B')
			c[p++] = s[i];
		else if (c[0] == '0' || c[0] == '1')
				c[--p] = '\0';
		if (i == s.size() - 1) c[p] = '\0';
	}
	printf("%s\n", c);
	return 0;
}

Measured memory_bytes: 256