akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define LL long long

void solve(long long H, long long W, long long D, std::vector<std::vector<long long>> A, long long Q, std::vector<long long> L, std::vector<long long> R){
    vector<pair<LL, LL>> flatten(H*W+1);
    for(LL i=0; i<H; i++){
        for(LL j=0; j<W; j++){
            flatten[A[i][j]] =  make_pair(i+1, j+1);
        }
    }
    vector<vector<LL>> arr(D, vector<LL>((H*W+D)/D, 0));
    for(LL i=0; i<D; i++){
        LL acc=0;
        for(LL j=1; j<(H*W+D)/D; j++){
            LL prev=D*(j-1)+i, curr=D*j+i;
            if(curr > H*W)continue;
            acc += (abs(flatten[prev].first-flatten[curr].first)+abs(flatten[prev].second-flatten[curr].second));
            arr[i][j] = acc;
        }
    }

    for(LL i=0; i<Q; i++){
        auto j=R[i]%D;
        cout << arr[j][R[i]/D] - arr[j][L[i]/D] << endl;
    }
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;

    scanf("%lld",&W);
    long long D;
    scanf("%lld",&D);
    std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> L(Q);
    std::vector<long long> R(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
    }
    solve(H, W, D, std::move(A), Q, std::move(L), std::move(R));
    return 0;
}


Measured memory_bytes: 9088
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

use std::collections::HashMap;


fn update_map(key: &i64, map: &mut HashMap<i64, i64>) {
    if map.contains_key(key) {
        if let Some(x) = map.get_mut(key) {
            *x += 1;
        }
    } else {
        map.insert(*key, 1);
    }
}

fn main() {
    let n = input!(usize);
    let a = input!(i64; n);
    let mut map: HashMap<i64, i64> = HashMap::new();

    for &a_i in a.iter() {
        update_map(&(a_i - 1), &mut map);
        update_map(&(a_i), &mut map);
        update_map(&(a_i + 1), &mut map);
    }

    let mut max = 0;
    for &value in map.values() {
        if value > max {
            max = value;
        }
    }
    println!("{}", max);
}

Measured memory_bytes: 12540
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  if(n % 2 == 0){
    cout << n << endl;
  } else {
    cout << n * 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int i, n, n100, n10, n1, hikaku;

	scanf("%d", &n);

	n100 = n / 100 % 10;
	n10  = n /  10 % 10;
	n1   = n %  10;

	for (i = 1; i < 10; i++) {
		if (n100 == i) {
			hikaku = i * 100 + i * 10 + i;
			if (n > hikaku) printf("%d%d%d\n", n100 + 1, n100 + 1, n100 + 1);
			else printf("%d%d%d\n", n100, n100, n100);
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

char a[810][810];
int p[810 * 810][2];
int d[810][810];
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 };

inline void relax(int &res, int d, int k) {
	res = min(res, (d + k - 1) / k);
}

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	double beg = clock();
#endif

	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	FOR(i, 0, n) {
		scanf("%s", a[i]);
	}
	int x = -1;
	int y = -1;
	FOR(i, 0, n) {
		FOR(j, 0, m) {
			if (a[i][j] == 'S') {
				x = i;
				y = j;
			}
		}
	}
	MEMS(d, -1);
	d[x][y] = 0;
	p[0][0] = x;
	p[0][1] = y;
	int l = 0;
	int r = 0;
	while (l <= r) {
		int x = p[l][0];
		int y = p[l++][1];
		FOR(k, 0, 4) {
			int nx = x + dx[k];
			int ny = y + dy[k];
			if ((nx >= 0) && (nx < n) && (ny >= 0) && (ny < m) && (a[nx][ny] == '.') && (d[nx][ny] == -1)) {
				r++;
				p[r][0] = nx;
				p[r][1] = ny;
				d[nx][ny] = d[x][y] + 1;
			}
		}
	}
	int res = 100500;
	FOR(i, 0, n) {
		FOR(j, 0, m) {
			if ((d[i][j] != -1) && (d[i][j] <= k)) {
				relax(res, i, k);
				relax(res, j, k);
				relax(res, n - i - 1, k);
				relax(res, m - j - 1, k);
			}
		}
	}
	cout << res + 1 << endl;

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 8576
#include <stdio.h>

#define NUM 100

int main(void)
{
	int n;
	int m;
	int l;
	int a[NUM][NUM];
	int b[NUM][NUM];
	double c[NUM][NUM] = { 0 };
	int i;
	int j;
	int k;

	scanf("%d %d %d", &n, &m,&l);

	for (i = 0; i < n; i++){
		for (j = 0; j < m; j++){
			scanf("%d", &a[i][j]);
		}
	}

	for (i = 0; i < m; i++){
		for (j = 0; j < l; j++){
			scanf("%d", &b[i][j]);
		}
	}

	for (i = 0; i < n;i++){
		for (j = 0; j < l; j++){
			for (k = 0; k < m; k++){
				c[i][j] += a[i][k]*b[k][j];
			}
		}
	}

	for (i = 0; i < n; i++){
		for (j = 0; j < l; j++){
			if (j < l-1)printf("%.lf ", c[i][j]);
			else printf("%.lf\n", c[i][j]);
		}
	}

	return 0;
}

Measured memory_bytes: 796
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    std::cin >> s;
    for (int i = 0; i < s.length(); i++) {
        for (int j = i+1; j < s.length(); j++) {
            if(s[j]==s[i]){
                std::cout << "no" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "yes" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)

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

ll pow(ll a, ll b) {
  ll ret = 1;
  REP(i, b) ret *= 3;
  return ret;
}

int digit;
int N;
ll dfs(int d, int num, int sev, int fiv, int thr)
{
  if (num > N) return 0;
  if (d == digit) {
    if (num <= N && sev > 0 && fiv > 0 && thr > 0) {
      return 1;
    }
    else return 0;
  }
  ll ret = 0;
  ret += dfs(d + 1, 10*num+3, sev, fiv, thr+1);
  ret += dfs(d + 1, 10*num+5, sev, fiv+1, thr);
  ret += dfs(d + 1, 10*num+7, sev+1, fiv, thr);
  return ret;
}

int main()
{
   cin >> N;

  ll tmp = N;
  ll ans = 0;
  while (tmp > 0) { 
    tmp /= 10;
    digit++;
    if (digit >= 3) ans += dfs(0, 0, 0, 0, 0);
  }
  cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
N,K=input().split()
N=int(N)
K=int(K)

have_number=[]
have_who=[]

for i in range(K):
    i = input().split()
    j = input().split()
    have_number.append(i)
    have_who.append(j)

    #人
list1=[]
for k in range(1,N+1):
    list1.append(k)
list1

#持っている人の番号
t_have_who=sum(have_who,[])
for c in range(0,len(t_have_who)):
    t_have_who[c]=int(t_have_who[c])
t_have_who  

#人と持っている人の番号の非重複
list1=set(list1)
t_have_who =set( t_have_who )
diff = list1 ^ t_have_who  

print(len(diff))

Measured memory_bytes: 9816
import math

def main():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    x = math.sqrt(N)
    if x.is_integer():
        print(int(x+N/x-2))
    else:
        while x >= 1:
            x = math.ceil(x)-1
            y = N/x
            if y.is_integer():
                print(int(x+y-2))
                break

        
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int h, w, white;
	char c;
	bool wb[100][100];
	int notout[100] = {0};
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		white = 0;
		for(int j = 0; j < w; j++){
			cin >> c;
			wb[i][j] = (c == '.' ? 1 : 0);
			white += wb[i][j];
			notout[j] += wb[i][j];
		}
		if(white == w){
			i -= 1;
			h -= 1;
			for(int j = 0; j < w; j++){
				notout[j] -= 1;
			}
		}
	}
	for(int i = 0; i < h; i++){
		
		for(int j = 0; j < w; j++){
			if(notout[j] != h) cout << (wb[i][j] == 1 ? '.' : '#') << flush;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int K;
int cnt[30];
int main(){
  int Lj4PdHRW, i, res=0;
  rd(N);
  rd(M);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    int KL2GvlyY;
    rd(K);
    for(KL2GvlyY=0;KL2GvlyY<K;KL2GvlyY++){
      rd(i);i += (-1);
      cnt[i]++;
    }
  }
  for(i=0;i<M;i++){
    if(cnt[i]==N){
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N, M, K;
// int cnt[30];
// {
//   int i, res = 0;
//   
//   rd(N,M);
//   rep(N){
//     rd(K);
//     rep(K){
//       rd(i--);
//       cnt[i]++;
//     }
//   }
// 
//   rep(i,M) if(cnt[i]==N) res++;
//   wt(res);
// }


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

inline int read()
{
	int x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

const int MAXN = 600005;
const int mod = 924844033;
std::vector<int> G[MAXN];
int fac[MAXN],ifac[MAXN],cnt[MAXN],sz[MAXN];
int f[MAXN],g[MAXN],rev[MAXN];
int n;

inline void addedge(int u,int v)
{
	G[u].push_back(v);
	G[v].push_back(u);
}

inline int qpow(int x,int k)
{
	int res=1;
	for(int i=k; i; i>>=1,x=1ll*x*x%mod)
		if(i&1) res=1ll*res*x%mod;
	return res;
}

inline void init(int n)
{
	for(int i=fac[0]=1; i<=n; ++i)
		fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n; i; --i)
		ifac[i-1]=1ll*ifac[i]*i%mod;
}

inline int cat(int n,int k)
{return 1ll*fac[n]*ifac[k]%mod*ifac[n-k]%mod;}

inline void dfs(int x,int fa)
{
	sz[x]=1;
	for(int y : G[x])
		if(y^fa) dfs(y,x),sz[x]+=sz[y],++cnt[sz[y]];
	++cnt[n-sz[x]];
}

inline void ntt(int *a,int n,int op)
{
	for(int i=0; i<n; ++i) if(i<rev[i]) swap(a[i],a[rev[i]]);
	for(int i=1; i<n; i<<=1)
	{
		int rot=qpow(op==1?5:554906420,(mod-1)/(i<<1));
		for(int j=0; j<n; j+=i<<1)
			for(int k=0,w=1; k<i; ++k,w=1ll*w*rot%mod)
			{
				int x=a[j+k],y=1ll*w*a[j+k+i]%mod;
				a[j+k]=(x+y)%mod,a[j+k+i]=(x-y+mod)%mod;
			}
	}
	if(op==-1)
	{
		int inv=qpow(n,mod-2);
		for(int i=0; i<n; ++i) a[i]=1ll*a[i]*inv%mod;
	}
}

int main(int argc, char const *argv[])
{
	n=read();
	for(int i=1; i<n; ++i) addedge(read(),read());
	dfs(1,0); init(n);
	for(int i=1; i<=n; ++i) f[i]=1ll*cnt[i]*fac[i]%mod;
	for(int i=(reverse(f,f+n+1),0); i<=n; ++i) g[i]=ifac[i];
	int lim=1,l=0;
	for(; lim<=n<<1; lim<<=1,++l);
	for(int i=0; i<lim; ++i)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
	ntt(f,lim,1),ntt(g,lim,1);
	for(int i=0; i<lim; ++i)
		f[i]=1ll*f[i]*g[i]%mod;
	ntt(f,lim,-1);
	reverse(f,f+n+1);
	for(int i=1; i<=n; ++i)
		printf("%lld\n",(1ll*n*cat(n,i)%mod
		                 -1ll*ifac[i]*f[i]%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 46496
#include <bits/stdc++.h>
using namespace std;
int main()
{
    double n,k;
    cin>>n>>k;
    double p=0;
    for(int i=1; i<=n; i++)
    {
        double pr=1.0/n;
        int cur=i;
        while(cur<k)
        {
            cur*=2;
            pr/=2;
        }

        p+=pr;
    }
    cout<<setprecision(12)<<p;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

struct CODE
{
	char before;
	char after;
};

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		vector<CODE> code;
		
		while (n-- > 0){
			CODE c;
			scanf(" %c %c", &c.before, &c.after);
			code.push_back(c);
		}
		
		int m;
		scanf("%d", &m);
		while (m-- > 0){
			char c;
			
			scanf(" %c", &c);
			for (int i = 0; i < code.size(); i++){
				if (c == code[i].before){
					c = code[i].after;
					break;
				}
			}
			putchar(c);
		}
		puts("");
	}
	
	return 0;
}

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

using namespace std;
using ll = long long;

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

  int n;
  ll x;
  cin >> n >> x;

  vector<ll> p(51);
  vector<ll> pb(51);
  p[0] = 1;
  pb[0] = 1;
  for (int i = 1; i < 51; i++) {
    p[i] = p[i - 1] * 2 + 1;
    pb[i] = pb[i - 1] * 2 + 3;
  }

  // レベルnからx枚食べた時のパティの数
  function<ll(int, ll)> f = [&](int n, ll x) -> ll {
    if (n < 0 || x <= 0)
      return 0ll;

    if (x >= pb[n])
      return p[n];

    if (x <= pb[n] / 2) {
      return f(n - 1, x - 1);
    } else {
      return p[n - 1] + 1 + f(n - 1, x - pb[n - 1] - 2);
    }
  };

  cout << f(n, x) << endl;

  return 0;
}


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

void answer1() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  vector<bool> alice_on(101, false);
  for (int i = a; i < b; i++) {
    alice_on.at(i) = true;
  }

  int count = 0;
  for (int i = c; i < d; i++) {
    if (alice_on.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}

void answer2() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a <= c && c < b) {
    if (d < b) {
      cout << d - c << endl;
    } else {
      cout << b - c << endl;
    }
  } else if (c <= a && a < d) {
    if (b < d) {
      cout << b - a << endl;
    } else {
      cout << d - a << endl;
    }
  } else {
    cout << 0 << endl;
  }
}

void answer3() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << max(0, min(b, d) - max(a, c)) << endl;

}

int main() {
  //answer1();
  //answer2();
  answer3();
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	bt, bx, by := 0, 0, 0
	for i := 0; i < n; i++ {
		t, x, y := readInt(), readInt(), readInt()
		dt, dx, dy := t-bt, abs(x-bx), abs(y-by)
		if mv := dx + dy; mv > dt || dt%2 != mv%2 {
			fmt.Println("No")
			return
		}
		bt, bx, by = t, x, y
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 1792
#include<cstdio>
                                                                                                                    
int main(){                                                                                                         
        int N;                                                                                                      
        scanf("%d", &N);                                                                                            
        if(N%2==0) printf("%d", N);                                                                                 
        else printf("%d", N*2);                                                                                     
        return 0;                                                                                                   
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    
    string s;
    cin >> s;
    ll N = s.size();
    vector<ll> pre(26, -1);
    rep(i, 0, N){
        if(pre[s[i]-'a'] == -1){
            pre[s[i]-'a'] = i;
        }else{
            ll d = i - pre[s[i]-'a'];
            if(d > 2){
                pre[s[i]-'a'] = i;
            }else{
                cout << pre[s[i]-'a']+1 << " " << i+1 << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}

Measured memory_bytes: 512
import  java.util.*;
class Main{
    int a;
    int b;
    int c;
    Main(){
	Scanner sc=new Scanner(System.in);
	a=sc.nextInt();
        b=sc.nextInt();
	c=sc.nextInt();

	if( (a==1 && b==1 && c==0) || (a==0 && b==0 && c==1) ){
	    System.out.println("Open");
	}else{
	    System.out.println("Close");
	}
    }

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

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

int main() {
  string s;
  cin >> s;
  int len;
  len = s.size();
  int a;
  a = len / 2;
  int cnt = 0;
  for (int i = 0; i < a; i++){
    if (s.at(i) != s.at(len-1-i)) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

int main() {

	int r, c; cin >> r >> c;
	
	vector<vector<char>> a(r + 2, vector<char>(c + 2, 'e'));
	for (int i = 1; i <= r; i++) for (int j = 1; j <= c; j++) cin >> a[i][j];
	
	vector<vector<bool>> used(r + 2, vector<bool>(c + 2, false));
	ll ans = 0;
	ll b, w;	
	for (int sy = 1; sy <= r; sy++) {
		for (int sx = 1; sx <= c; sx++) {

			if (used[sy][sx]) continue;
			b = 0;
			w = 0;

			// BFS のためのデータ構造
			queue<pair<int, int>> que;
			used[sy][sx] = true;

			// 初期条件
			que.push({ sy,sx });

			const int dy[4] = { 1, 0, -1, 0 };
			const int dx[4] = { 0, 1, 0, -1 };

			// BFS 開始 (キューが空になるまで探索を行う)
			while (!que.empty()) {

				pair<int, int> p = que.front(); // キューから先頭頂点を取り出す
				que.pop();

				int y_now = p.first;
				int x_now = p.second;
				if (a[y_now][x_now] == '.') w++;
				else b++;
				
				// p から辿れるマスをすべて調べる
				for (int i = 0; i < 4; i++) {

					int y_next = p.first + dy[i];
					int x_next = p.second + dx[i];

					if (a[y_next][x_next] == 'e') continue;
					if (a[y_next][x_next] == a[y_now][x_now]) continue;
					if (used[y_next][x_next]) continue;					

					used[y_next][x_next] = true;					
					que.push({ y_next, x_next });

				}

			}
			ans += b * w;
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3800
import java.util.*;

public class Main {
    private static Scanner sc;
    static int w;
    static int h;
    static int x;
    static int y;
    static int r;
    

	public static void main(String[] args) {
    	sc = new Scanner(System.in);
    	w = sc.nextInt();
    	h = sc.nextInt();
    	x = sc.nextInt();
    	y = sc.nextInt();
    	r = sc.nextInt();
    	if (x-r<0||x+r>w ||y-r<0||y+r>h){
    		System.out.println("No");
    	}else{
    		System.out.println("Yes");
    	}
    }
}
    	

Measured memory_bytes: 17348
import java.util.*;
public class Main{
    static Scanner sc = new Scanner(System.in);
    static HashMap<String, Item> pmap;
    static HashMap<String, Integer> fmap;
    public static void main(String[] args){
	while(sc.hasNext()){
	    int n = sc.nextInt();
	    if(n!=0){
		solve(n);
	    }
	}
    }

    static void solve(int n){
	//テ・ツ?・テ・ツ環崚ィツェツュテ」ツ?ソティツセツシテ」ツ?ソテ」ツ?禿」ツ?禿」ツ?凝」ツつ?
	pmap = new HashMap<String, Item>();
	fmap = new HashMap<String, Integer>();
	int i, j;
	for(i=0; i<n; i++){
	    String name = sc.next();
	    int price = sc.nextInt();
	    pmap.put(name, new Item(name, price));
	}
	int m = sc.nextInt();
	for(i=0; i<m; i++){
	    String name = sc.next();
	    int k = sc.nextInt();
	    String[] r = new String[k];
	    for(j=0; j<k; j++){
		r[j] = sc.next();
	    }
	    if(pmap.containsKey(name)){
		pmap.get(name).setRecipe(r);
	    }
	    else{
		Item item = new Item(name, -1);
		item.setRecipe(r);
		pmap.put(name, item);
	    }
	}
	//テ・ツ?・テ・ツ環崚ィツェツュテ」ツ?ソティツセツシテ」ツ?ソテ」ツ?禿」ツ?禿」ツ?セテ」ツ?ァ

	String x = sc.next();
	int ans = search(x);
	System.out.println(ans);
    }


    static int search(String name){
	//System.out.println(name);
	if(pmap.containsKey(name) && pmap.get(name).getRecipe()!=null){
	    if(fmap.containsKey(name))
		return fmap.get(name);  //テヲツ慊?・ツョツ嘉・ツ?、テァツ「ツコテ・ツョツ堙ヲツクツ?
	    else{
		String[] r = pmap.get(name).getRecipe();
		int res = 0;
		int i;
		for(i=0; i<r.length; i++){
		    res += search(r[i]);
		}
		if(pmap.get(name).getPrice()!=-1){
		    res = Math.min(res, pmap.get(name).getPrice());
		}
		fmap.put(name, res);
		return res;
	    }
	}
	else if(pmap.containsKey(name)){
	    int res = pmap.get(name).getPrice();
	    fmap.put(name, res);
	    return res;
	}
	else{
	    //System.out.println("テ」ツつィテ」ツδゥテ」ツδシ");
	    return 1<<30;
	}
    }
}

class Item{
    String name;
    int price;
    String[] recipe;
    public Item(String n, int p){
	name = n;  price = p;
    }
    public void setRecipe(String[] r){
	recipe = r;
    }
    public String[] getRecipe(){
	return recipe;
    }
    public int getPrice(){
	return price;
    }
}
			

Measured memory_bytes: 25036
#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200050;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

void Yes() {
	cout<<"Yay!"<<endl; exit(0);
}
void No() {
	cout<<":("<<endl; exit(0);
}

void solve() {
	bool found = false;
	int N; cin >> N;
	ll ans = 0;
	REP(i, N + 1) {
		if (i * 108 / 100 == N) {
			found = true;
			ans = i;
		}
	}
	if (found) {
		print(ans);
	}
	else No();
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long union_tree[200000];
long long union_find(long long now) {
	if (union_tree[now] == now) return now;
	return union_tree[now] = union_find(union_tree[now]);
}
void union_merge(long long a, long long b) {
	a = union_find(a);
	b = union_find(b);
	union_tree[a] = b;
	return;
}
int main() {
#define int long long
	int n, m, query;
	cin >> n >> m >> query;
	vector<tuple<long long, long long, long long>> inputs;
	REP(i, query) {
		long long a, b, c;
		cin >> a >> b >> c;
		inputs.push_back(make_tuple(c, a, b));
		if (c == 1&&n == m + 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	sort(inputs.begin(), inputs.end());
	REP(i, n) {
		union_tree[i] = i;
	}
	REP(i, query) {
		if (get<0>(inputs[i]) == 0) {
			union_merge(get<1>(inputs[i]), get<2>(inputs[i]));
		}
	}
	REP(i, query) {
		if (get<0>(inputs[i]) == 1) {
			if (union_find(get<1>(inputs[i])) == union_find(get<2>(inputs[i]))) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	long long cnt = 0;
	REP(i, n) {
		if (union_find(i) == i) {
			cnt++;
		}
	}
	long long hoge = cnt * (cnt - 3LL) / 2LL;
	hoge += n;
	if (m <= hoge) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  int X,A,B;
  cin >> X >> A >> B;
  
  if((B-A) <= 0) cout << "delicious" << endl;
  else if((B-A) <= X) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
m;f(r,n,i,t){if(n==1)return r>i&r<10;for(;i++<9&i<r;)t+=f(r-i,n-1,i,0);return t;}main(s){for(;scanf("%d%d",&m,&s),m;printf("%d\n",f(s,m,-1,0)));return 0;}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()

#define INF 1e+9
#define MAX_V 100000

struct edge {
    int to;
    int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}



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

    int e, r;
    cin >> V >> e >> r;

    for(int i=0; i<e; i++){
        int a, b, c;
        cin >> a >> b >> c;

        edge e = {b, c};
        G[a].push_back(e);
    }
    dijkstra(r);
    for(int i=0; i <V; i++){
      if(d[i] == INF){
        cout << "INF" << ln;
      } else{
      cout << d[i] << ln;
      }
    }
  
}



Measured memory_bytes: 12904
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int n;
  cin>>n;
  int sum=0;
  int test=n;
  while(test){
	int temp;
    temp=test%10;
    sum=sum+temp;
    test=test/10;
  }
  if(n%sum==0){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
    return 0;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << char(s1[0] - 32) << char(s2[0] - 32) << char(s3[0] - 32) << '\n';
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNIGNS 
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>

using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> pll;

int main(void)
{
	map<string, int> red,blue;
	vector<string> b_s, r_s;

	int n, m;
	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		blue[s]++;
		b_s.push_back(s);
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		string s;
		cin >> s;
		red[s]++;
		r_s.push_back(s);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, max(0, blue[b_s[i]] - red[b_s[i]]));
	}

	cout << ans;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
bool inq[N],vis[N];
int n,m,dis[N],hd[N],nxt[N*4],to[N*4],w[N*4],tot;
void add(int u,int v,int x)
{nxt[++tot]= hd[u],to[tot]= v,w[tot]= x,hd[u]= tot;}
int spfa(int bg)
{
	int nw,v;
	queue<int>q;
	dis[bg]=0,q.push(bg),inq[bg]=vis[bg]=1;
	while(!q.empty())
	{
		nw= q.front(),q.pop();
		for(int i= hd[nw];i;i= nxt[i])
		{
			v=to[i];
			if(dis[v]>1e9)
			{
				vis[v]=1;
				dis[v]= dis[nw] + w[i];
				if(!inq[v])q.push(v);inq[v]=1;
			}
			else if(dis[v]!=dis[nw]+w[i])puts("No"),exit(0);
		}
		inq[nw]=0;
	}
}
int main()
{
	int l,r,d;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&l,&r,&d);
		add(l,r,d),add(r,l,-d);
	}
	memset(dis,127,sizeof dis);
	for(int i=1;i<=n;i++)
		if(!vis[i])spfa(i);
	puts("Yes");	
}


Measured memory_bytes: 6272
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
    }
    else if (n > k) {
        cout << n - k << endl;
    }
    else if (n % k == 0) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
S = [str(input()) for _ in range(n)]
m = int(input())
T = [str(input()) for _ in range(m)]

from collections import Counter
CS = Counter(S)
CT = Counter(T)

ans = 0
for k in CS.keys():
    if k not in CT:
        ans = max(CS[k], ans)
    else:
        ans = max(ans, max(0, CS[k]-CT[k]))
print(ans)


Measured memory_bytes: 67020
## coding: UTF-8

N = int(input())
A = [0]
A = A + list(map(int,input().split()))
#print(A)

i_minus_Ai = [0] * (N+1)
j_plus_Aj = [0] * (N+1)

for i in range(1, N+1):
    minus = i - A[i]
    plus = i + A[i]
    #print(i,A[i],minus, plus)
    if(2 <= minus and minus <= N):
        i_minus_Ai[minus] += 1
    if(2 <= plus and plus <= N):
        j_plus_Aj[plus] += 1
#print(i_minus_Ai)
#print(j_plus_Aj)
ans = 0
for i in range(N+1):
    ans += i_minus_Ai[i] * j_plus_Aj[i]
print(ans)

Measured memory_bytes: 94236
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for (int (i)=(a);(i)<(int)(n);++(i))
#define erep(i,a,n) for (int (i)=(a);(i)<=(int)(n);++(i))

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int64_t x = 1, y = 1;
    rep(i,0,n) {
        int A, B;
        cin >> A >> B;
        int64_t a = max((x - 1) / A + 1, (y - 1) / B + 1);
        x = A * a;
        y = B * a;
    }

    cout << x+y << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{

  static int h;
  static long[] a;

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    h = sc.nextInt();
    a = new long[h+1];
    for (int i=1; i<=h; i++){
      a[i] = sc.nextLong();
    }
    buildMaxHeap();
    for (int i=1; i<=h; i++){
      System.out.print(" "+a[i]);
    }
    System.out.println();
  }

  public static int left(int i){
    return 2*i;
  }

  public static int right(int i){
    return 2*i+1;
  }

  public static int parent(int i){
    return i/2;
  }

  public static void maxHeapify(int i){
    int l = left(i);
    int r = right(i);
    int largest;
    if (l <= h && a[l]>a[i]){
      largest = l;
    } else {
      largest = i;
    }
    if (r <= h && a[r] > a[largest]){
      largest = r;
    }

    if (largest != i){
      long t = a[i];
      a[i] = a[largest];
      a[largest] = t;
      maxHeapify(largest);
    }
  }

  public static void buildMaxHeap(){
    for (int i=h/2; i>0; i--){
      maxHeapify(i);
    }
  }
}


Measured memory_bytes: 175392
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long H = inputArray[1];

			var inpArray = new List<Tuple<long, bool>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				inpArray.Add(new Tuple<long, bool>(inp[0], false));
				inpArray.Add(new Tuple<long, bool>(inp[1], true));
			}
			var sortedArray = inpArray.OrderByDescending(x => x.Item1).ToArray();

			var position = 0;
			long count = 0;

			while (H >0) {
				var attack = sortedArray[position];

				H -= attack.Item1;
				count++;
				if (attack.Item2) {
					position++;
					continue;
				}

				//刀を投げないときは、割り算で計算してしまう
				var kaisu = H / attack.Item1;
				if (H % attack.Item1 >0) {
					kaisu++;
				}

				count += kaisu;
				break;

			}


			//答えの出力
			var ans = count;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 56536
n, m = map(int,input().split())
list = []
for i in range(n):
    a,b = map(int,input().split())
    list.append((a,b))

list = sorted(list,key=lambda x:x[0],reverse=False)
hon = 0
ans = 0
flag = True
for a,b in list:
    if(flag):
        for i in range(b):
            ans += a
            hon += 1
            if hon==m:
                flag=False
                break;
print(ans)


Measured memory_bytes: 18932
import copy
N = int(input())

A = []
for i in range(2):
    A.append(list(map(int,input().split())))

dp = copy.deepcopy(A)

for i in range(2):
    for j in range(N):
        if i == 0 and j == 0 :
            dp[i][j] = A[i][j]
        elif i == 0 and j > 0:
            dp[i][j] = dp[i][j-1] + A[i][j]
        elif i == 1 and j == 0:
            dp[i][j] = dp[i-1][j] + A[i][j]
        elif i == 1 and j > 0:
            if dp[i-1][j] + A[i][j] >= dp[i][j-1] + A[i][j]:
                dp[i][j] = dp[i-1][j] + A[i][j]
            elif dp[i-1][j] + A[i][j] < dp[i][j-1] + A[i][j]:
                dp[i][j] = dp[i][j-1] + A[i][j]

print(dp[1][N-1])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int p1 = N % 10;
  int p2 = (N / 10) % 10;
  int p3 = (N/100) % 10;
  int p4 = (N/1000) % 10;
  if (p2 == p3 && ( p1 == p2 || p3 == p4 ) ) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
}
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll r, l; cin >> l >> r;
        ans += r - l + 1;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int d;
int c[26],s[365][26],last[26];

int main() {
  cin >> d;
  for(int i=0;i<26;i++) {
    cin >> c[i];
  }
  for(int i=0;i<d;i++) {
    for(int j=0;j<26;j++) {
      cin >> s[i][j];
    }
  }
  int score=0;
  for(int i=0;i<d;i++) {
    int t=0;
    for(int j=1;j<26;j++) {
      if(s[i][j]>s[i][t]) t=j;
    }
    cout << t+1 << endl;
  }
}

Measured memory_bytes: 3672
#include <algorithm>
#include <sstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;


int main()
{
	int n, cnt;
	while (cin >> n && n != EOF) {
		cnt = 0;
		for (int a = 0; a < 10; a++) {
			for (int b = 0; b < 10; b++) {
				for (int c = 0; c < 10; c++) {
					for (int d = 0; d < 10; d++) {
						if (n == a + b + c + d) cnt++;
					}
				}
			}
		}

		cout << cnt << endl;
	}
}



Measured memory_bytes: 3064
// 2020-07-24 00:32:31
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

set<int> idxs[26];
void answer() {
  string s, t;
  cin >> s >> t;
  int s_sz = s.size();
  rep(i, s_sz) {
    int ci = s[i] - 'a';
    idxs[ci].emplace(i + 1);
    idxs[ci].emplace(i + 1 + s_sz);
  }
  int cur = 1;
  ll ans = 0;
  rep(i, t.size()) {
    int ci = t[i] - 'a';
    auto itr = idxs[ci].lower_bound(cur);
    if(itr == idxs[ci].end()) {
      cout << -1 << '\n';
      return;
    } else {
      ans += *itr - cur + 1;
      cur = *itr + 1;
      if(s_sz < cur) cur -= s_sz;
    }
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 13240
//ysh_gpta
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
typedef long long ll;
#define vb vector<bool>
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define mkp make_pair
#define pb push_back
#define INF 1000000000000000
#define MOD 1000000007
#define ff first
#define ss second
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//ll gcd( ll a, ll b ){if(b==0) return a; else return gcd( b, a%b );}
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
//void printArray(vi &v){for(int i=0;i<v.size();i++) cout<<v[i]<<endl; cout<<endl; }
int main(){
   FastIO
   ll n;
   cin>>n;
   vector<double> v(n+1);
   for(int i=1;i<=n;i++)
   cin>>v[i];
   double dp[n+1][n+1];
   memset(dp,0.0,sizeof(dp));
   dp[0][0] = 1.0;
   for(int i=1;i<=n;i++){
       for(int j=0;j<=i;j++){
           if(j==0)
           dp[i][j] = dp[i-1][j]*(1-v[i]);
           else
           dp[i][j] = dp[i-1][j]*(1-v[i]) + dp[i-1][j-1]*v[i];
       }
   }
   double ans = 0.0;
   for(int i=(n+1)/2;i<=n;i++){
       ans += dp[n][i];
   }
   printf("%0.9f",ans);
   return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9;
#define LINF = 1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << = << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

void aru(int mark[], int num){
    mark[num-1] = 0;
}
void nai(char mk, int mark[]){
    rep(i, 13){
        if(mark[i])cout << mk << " " << mark[i] << endl;
    }
}

int main(){
    int n;
    cin >> n;
    int S[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
    int H[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
    int C[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
    int D[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};

    rep(i, n){
        char mark;
        int num;
        cin >> mark >> num;
        if(mark == 'S')aru(S, num);
        else if(mark == 'H')aru(H, num);
        else if(mark == 'C')aru(C, num);
        else aru(D, num);
    }

    nai('S', S);
    nai('H', H);
    nai('C', C);
    nai('D', D);

}


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

int main(){
    int N;
    int a[1009];
    cin >> N;
    int flag = 0;

    for(int i = 0;i<N;i++){
        cin >> a[i];
    }

    for(int i = 0;i<N;i++){
        if(a[i]%2 == 0){
            if(a[i]%3 != 0 && a[i]%5 != 0){
                flag = 1;
                break;
            }
        }
    }

    if(flag == 0){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" <<endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    string s;
    cin>>s;
    if(((s[0]==s[1])&&(s[1]==s[2]))||((s[1]==s[2])&&(s[2]==s[3])))
    {
        cout<<"Yes"<<NL;
    }
    else
    {
        cout<<"No"<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  long a,b,c,k,ans;

  scanf("%ld %ld %ld %ld",&a,&b,&c,&k);

  if(a >= k)
    ans = k;
  else if(a+b >= k)
    ans = a;
  else
    ans = a - (k-a-b);

  printf("%ld",ans);
  return 0;
}


Measured memory_bytes: 1652
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, a: "List[int]"):
    a = sorted(a)
    print(a[-1] - a[0])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a, b;

    cin >> a >> b;

    cout << max(0, a - 2 * b);

    return 0;

}


Measured memory_bytes: 256