akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define maxm 100000
#define maxn 100000

int main(){
    long n, m;
    long a[maxn];
    long b[maxn];
    scanf("%ld%ld", &n, &m);
    for(long i=0; i<n; i++){
        scanf("%ld%ld", &a[i], &b[i]);
    }
    vector<pair<long, long> > ab;
    for(long i=0; i<n; i++){
        ab.push_back(make_pair(a[i], b[i]));
    }
    sort(ab.begin(), ab.end());
    long total = 0;
    long cost, num;
    for(long i=0; i<n; i++){
        cost = ab[i].first;
        num = ab[i].second;
        if(m-num >=0){
            total+=cost*num;
            m-=num;
        }else{
            total+=cost*m;
            break;
        }
    }
    printf("%ld", total);
    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;   string s,s1;
    cin>>n>>s;
    for(int i=0;i<s.length();i++)
    {
    if(int(s[i])+ n <=90)
        s1+=char(int (s[i]+n));
    else
        s1+=char(65+n-1-(90-int (s[i])));
    }
        cout<<s1<<endl;
    }



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,b,i;
scanf("%d %d",&a,&b);

if(a==b){
for(i=1;i<=a;i++)
printf("%d",a);}

if(a<b){
for(i=1;i<=b;i++)
printf("%d",a);}

if(a>b){
for(i=1;i<=a;i++)
printf("%d",b);}

return 0;
}

Measured memory_bytes: 256
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split()))for i in range(Q)]
rui_count = []
AC_k = S.find('AC')
if AC_k == -1:
    for i in range(Q):
        print(0)
    exit()
for i in range(N):
    if AC_k+1 > i:
        if i == 0:
            rui_count.append(0)
        else:
            rui_count.append(rui_count[i-1])
        continue
    AC_k = S[i:N].find('AC')
    if AC_k == -1:
        rui_count += [rui_count[i-1]+1 for j in range(i,N)]
        break
    AC_k += i
    rui_count.append(rui_count[i-1]+1)
count = []
for i in lr:
    count.append(rui_count[i[1]-1]-rui_count[i[0]-1])
for i in count:
    print(i)


Measured memory_bytes: 34492
use std::cmp::min;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn shortest(i: i32, j: i32, x: i32, y: i32) -> usize {
    let mut short = min((i-j).abs(), (i-x).abs() + 1 + (y-j).abs());
    
    short = min(short, (i-y).abs()+1+(j-x).abs());
    (short as usize)
}

fn solve() {
    let input = read_vec::<i32>();
    let n = input[0];
    let x = input[1] - 1;
    let y = input[2] - 1;

    let mut len = vec![0; (n - 1) as usize];

    for i in 0..n {
        for j in i+1..n {
            let index = shortest(i,j,x,y) - 1;
            len[index] += 1;
        }
    }


    for i in len.iter() {
        println!("{}", i);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(8)
        .name("solve".into())
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

Measured memory_bytes: 6524
#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;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }

ll sum(int mx, int mn){
    if(mx < mn) swap(mx, mn);

    ll ret = 0;
    for(int i=1; i<=mx; i++) ret += i;
    for(int i=1; i<mn; i++) ret += i;

    return ret;
}

int main(){ 
    string s; cin >> s;
    bool is_up = true;

    ll res = 0, up = 0, down = 0;
    rep(i, s.size()){
        char c = s[i];
        if(is_up && c == '>') is_up = false;
        if(!is_up && c == '<'){
            res += sum(up, down);
            is_up = true, up = 0, down = 0;
        }

        if(c == '<') up++;
        else down++;
    }
    res += sum(up, down);
    cout << res << ln;
}

Measured memory_bytes: 900
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> A(N);
	rep(i,N)cin>>A[i];
	vector<int> now(3, 0);
	ll ans = 1;
	rep(i,N){
		ll cnt = 0;
		rep(j,3){
			if(A[i] == now[j]) ++cnt;
		}
		ans *= cnt;
		ans %= MOD;
		rep(j,3){
			if(A[i] == now[j]){now[j] ++; break;}
		}
	}
	if(ans < 0)ans += MOD;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
  
  string A, B;

  cin >> A >> B;

  if(A.size() > B.size()) {
    cout << "GREATER" << endl;
    return 0;
  }
  else if(A.size() < B.size()) {
    cout << "LESS" << endl;
    return 0;
  }
  
  for(int i=0;i<A.size();i++) {
    if(A[i] > B[i]) {
      cout << "GREATER" << endl;
      return 0;
    }
    else if(A[i] < B[i]) {
      cout << "LESS" << endl;
      return 0;
    }
  }
  cout << "EQUAL" << endl;

  return 0;
}


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

int main() {
    long long N, A, B;
    cin >> N >> A >> B;

    if ((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
    } else {
        cout << min(A - 1, N - B) + (B - A - 1) / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

A, B = list(map(int, input().split()))

if A%2 == B%2:
    ptn1 = (A+B) / 2
    ptn2 = (A-B) / 2
    ptn3 = (B-A) / 2
    ptn4 = (-A-B) / 2
    if abs(A - ptn1) == abs(B - ptn1):
        print(int(ptn1))
    elif abs(A - ptn2) == abs(-B + ptn2):
        print(int(ptn2))
    elif abs(-A + ptn3) == abs(B - ptn3):
        print(int(ptn3))
    elif abs(-A + ptn4) == abs(-B + ptn4):
        print(int(ptn4))
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
li = [0] * n
cou = [0] * (n+2)
for i in range(n):
    if li[a[i]-1] != 0:
        cou[li[a[i]-1]+1] += 1
    li[a[i]-1] += 1
y = 0
ma = max(li)
for i in range(ma-1):
    k = cou[ma-i] - cou[ma-i+1]
    y += (ma-i) * (ma-i-1) * k // 2
for i in range(n):
    x = li[a[i]-1]
    if x >= 2:
        print(y-x+1)
    else: print(y)

Measured memory_bytes: 26140
package main

import "fmt"

func is_unique(ss []string) bool {
	smap := make(map[string]int)
	for _, v := range ss {
		smap[v]++
	}
	for _, v := range smap {
		if v > 1 {
			return false
		}
	}
	return true
}

func is_connectable(ss []string) bool {
	for i := 0; i < len(ss)-1; i++ {
		from := ss[i]
		to := ss[i+1]
		if from[len(from)-1] != to[0] {
			return false
		}
	}
	return true
}

func main() {
	var n int
	fmt.Scan(&n)
	ss := make([]string, n)
	for i := range ss {
		fmt.Scan(&ss[i])
	}
	if is_unique(ss) && is_connectable(ss) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */


int main(void){ 
    int n,m;
    cin >> n >> m;
    vector<int> foods(m+1);
    for(int i=1; i<=m; i++){
        foods[i] = 0;
    }
    
    for(int i=0; i<n; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int a; cin >> a;
            foods[a] += 1;
        }
    }

    int ans = 0;
    for(int i=1; i<=m; i++){
        if(foods[i] == n) ans += 1;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
inline int pl(int x,int y){return (x+=y)>=mod?x-mod:x;}
inline int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
int C[310][310],jc[310],jcv[310];
int n,k,ans;
char s[100];
int p[100],pos[100];
bool used[100];
int CNT;
void calc(int m)
{
	++CNT;
//	printf("%d:",m);
//	for(int i=1;i<=m;++i)printf("%d ",p[i]);printf("\n");
	memset(used+1,0,n);
	for(int i=1,last=1;i<=m;++i)
	{
		while(last<=k&&s[last]!='r')++last;
		if(last>k)return;
		pos[i]=last;used[last]=1;++last;
	}
	for(int i=1,last=1;i<=m;++i)
		if(p[i]>=2)
		{
			if(last<=pos[i])last=pos[i]+1;
			while(last<=k&&s[last]!='b')++last;
			if(last>k)return;
			pos[i]=last;used[last]=1;++last;
		}
	for(int i=1,last=1;i<=m;++i)
		if(p[i]>2)
		{
			if(last<=pos[i])last=pos[i]+1;
			int d=p[i]-2;
			while(d)
			{
				while(last<=k&&used[last])++last;
				if(last>k)return;
				--d;++last;
			}			
		}
	int res=jc[m],up=n-m+1,dn=m+1;
	for(int i=1,r;i<=m;i=r+1)
	{
		r=i;
		while(r<m&&p[r+1]==p[i])++r;
		res=1ll*res*jcv[r-i+1]%mod;
	}
	for(int i=1;i<=m;++i)up-=p[i]==1?1:2*p[i]-3,dn+=2*p[i]-1;
	res=1ll*res*C[up+dn-1][dn-1]%mod;
	add(ans,res);
//	printf("%d:",m);
//	for(int i=1;i<=m;++i)printf("%d ",p[i]);printf("\n");
//	printf("%d %d %d\n",up,dn,res);
}
void dfs(int w,int res,int last,int sum)
{
	calc(w-1);
//	printf("%d %d %d\n",w,res,last);
	if(!res)return;
	for(int i=min(last,res);i;--i)
		if(sum+1+(i==1?1:2*i-3)<=n)p[w]=i,dfs(w+1,res-i,i,sum+1+(i==1?1:2*i-3));
}
int main()
{
	for(int i=0;i<=300;++i)
	{
		C[i][0]=1;
		for(int j=1;j<=i;++j)C[i][j]=pl(C[i-1][j-1],C[i-1][j]);
	}
	jc[0]=1;
	for(int i=1;i<=300;++i)jc[i]=1ll*jc[i-1]*i%mod;
	jcv[300]=kpow(jc[300],mod-2);
	for(int i=300;i;--i)jcv[i-1]=1ll*jcv[i]*i%mod;
	scanf("%d %d",&n,&k);
	scanf("%s",s+1);
	dfs(1,k,k,-1);
	printf("%d",ans);
//	printf("\n%d",CNT);
	return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

#define MOD 998244353
#define FACT_MAX 1000000

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }

  long long div(long long n1,long long n2){
    return n1*power(n2,mod-2)%mod;
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0LL;
    if(k==n || k==0) return 1LL;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};

int n,m,k;

int main(){
  cin>>n>>m>>k;
  LL ret = 0;
  Combinatrics comb;
  REP(i,k+1){
    ret += ((m*(comb.power(m-1,n-i-1))%MOD)*comb.nck(n-1,i)%MOD);
    ret %= MOD;
  }
  cout<<ret<<endl;
  return 0;
}


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

int main() {
  int N,K;
  int x[N];
  cin >> N >> K;
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> x[i];
    if((K-2*x[i])>0){
      sum+=2*x[i];
    }
    else{
      sum+=2*(K-x[i]);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        long N = cin.nextLong();
        long M = cin.nextLong();

        if (N == M / 2) Console.WriteLine(N);
        else if (N < M / 2) Console.WriteLine(N + (M - 2 * N) / 4);
        else Console.WriteLine(M / 2);

    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

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



int main(int argc, char **argv){
    int x, y;
    cin >> x >> y;
    set < int > s;
    s.insert(1);
    s.insert(3);
    s.insert(5);
    s.insert(8);
    s.insert(7);
    s.insert(10);
    s.insert(12);
    if(s.find(x) != s.end() && s.find(y) != s.end()){
        cout << "Yes";
        return 0;
    }
    s.clear();
    s.insert(4);
    s.insert(6);
    s.insert(9);
    s.insert(11);
    if(s.find(x) != s.end() && s.find(y) != s.end()){
        cout << "Yes";
        return 0;
    }
    if(x == 2 && y == 2){
        cout << "Yes";
        return 0;
    }
    cout << "No";
}

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

int main(){
	vector<vector<int>> a(3,vector<int>(3));
  	for(int i = 0; i < 3; i++){
    	for(int j = 0; j < 3; j++){
          	cin >> a.at(i).at(j);
        }}
  	
  	int n;	cin >> n;	
  	vector<int> b(n);	for(int i = 0; i < n; i++){cin >> b.at(i);}
    for(int i = 0; i < 3; i++){
    	for(int j = 0; j < 3; j++){
          	for(int k = 0; k < n; k++){
            	if(a.at(i).at(j) == b.at(k)){a.at(i).at(j) = 0; break;}
            }
        }}
  	
  	for(int i = 0; i < 3; i++){
    	if(a.at(0).at(i) == 0 && a.at(1).at(i) == 0 && a.at(2).at(i) == 0){
        	cout << "Yes" << endl;	return 0;
        }
      	else if(a.at(i).at(0) == 0 && a.at(i).at(1) == 0 && a.at(i).at(2) == 0){
          cout << "Yes" << endl;	return 0;
        }
    }
  	
  	if(a.at(0).at(0) == 0 && a.at(1).at(1) == 0 && a.at(2).at(2) == 0){
       	cout << "Yes" << endl;	return 0;
    }
  	else if(a.at(0).at(2) == 0 && a.at(1).at(1) == 0 && a.at(2).at(0) == 0){
       	cout << "Yes" << endl;	return 0;
    }
  	cout << "No" << endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, h, m = list(map(int, readline().split()))
    deg_a = 30 * h + (m / 60) * 30
    deg_b = 6 * m
    if deg_a > deg_b:
        deg = deg_a - deg_b
    else:
        deg = deg_b - deg_a
    import math
    if deg > 180:
        deg = 360 - deg

    c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(deg))
    print(c2 ** 0.5)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62484
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> W(N);
  for(int i=0;i<N;i++){
    cin>>W[i];
  }
  
  int ans=100000;
  
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=W[i];
  }
  
  for(int i=0;i<N;i++){
    int sum_1=0;
    for(int j=0;j<=i;j++){
      sum_1+=W[j];
      
    int sum_2=sum-sum_1;
    
    ans=min(abs(sum_1-sum_2),ans);
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
n=int(input())
a=list(map(int,input().split()))
count=0
total=0
for i in range(n):
    if a[i]%2==0:
        count+=1
        if a[i]%3==0 or a[i]%5==0:
            total+=1
if count==total:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 9124
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'

template<typename Type>
istream &operator>>(istream &in,vector<Type>&vec){
	int n=vec.size();	
	for(int i=0;i<n;i++)
		in>>vec[i];
	return in;
}
template<typename Type>
ostream &operator<<(ostream &out,vector<Type>&vec){
	for(auto val:vec)
		out<<val<<" ";
	out<<endl;
	return out;
}

void solve(){
	int n,k;
	cin>>n>>k;
	vector<int>h(n);
	cin>>h;
	vector<int>dp(n+1);
	for(int i=2;i<=n;i++){
		dp[i]=abs(h[i-1]-h[i-2])+dp[i-1];
		for(int j=max(i-k,1LL);j<i-1;j++){
			dp[i]=min(dp[i],abs(h[i-1]-h[j-1])+dp[j]);
		}
	}
	cout<<dp[n]<<endl;
}

int32_t main(){

	//remove for interactive problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

	return 0;
}

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

typedef complex<double> ci;
typedef pair<double,pair<double,int> > pdd;
pint fg[400];
bool used[400];
int main(){
    int n;
    while(cin>>n,n){ 
        rep(i,n) cin>>fg[i].first>>fg[i].second;
        sort(fg,fg+n);
        memset(used,0,sizeof(used));
        ci ppr(0,0),pre(0,0),cur(fg[0].first,fg[0].second);
        double sum=abs(cur-pre);
        used[0]=true;
        ppr=pre;pre=cur;
        FOR(i,1,n){
            vector<pdd> vp;
            double mxag=10;
            rep(j,n){
                if(used[j]) continue;
                ci c(fg[j].first,fg[j].second);
                ci scur=c-pre;
                double prag=arg(pre-ppr)+M_PI;
                double cuag=arg(scur)+M_PI;
                cuag=prag-cuag;
                if(cuag<0) cuag+=2*M_PI;
                mxag=min(cuag,mxag);
                if(mxag==cuag){
                    cuag=mxag;
                    vp.pb(mp(cuag,mp(abs(scur),j)));
                }
            }
            pdd p=*min_element(vp.begin(),vp.end());
            used[p.second.second]=true;
            sum+=p.second.first;
            ppr=pre;
            pre=ci(fg[p.second.second].first,fg[p.second.second].second);
        }
        cout<<fixed<<setprecision(1)<<sum<<endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);

  int n;
  double t, a;
  cin >> n >> t >> a;
  int ans = -1;
  double absa = 1000.0;
  for (int i = 0; i < n; ++i) {
    double x;
    cin >> x;
    x = t - (x * 0.006);
    // cerr << x << '\n';
    if (absa > abs(a - x)) {
      absa = abs(a - x);
      ans = i + 1;
    }
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3724
H,W,M=map(int,input().split())
bomb=[]
h=[0]*H
w=[0]*W
for i in range(M):
    hi,wi=map(int,input().split())
    h[hi-1] += 1
    w[wi-1] += 1
    bomb.append([hi,wi])    
maxh = max(h)
maxw = max(w)
ans = maxh +  maxw
lh=[]
lw=[]
for i in range(len(h)):
    if h[i] == maxh:
        lh.append(i+1)
for i in range(len(w)):
    if w[i] == maxw:
        lw.append(i+1)
a = 0
for i in range(M):
    if ans == h[bomb[i][0]-1]+w[bomb[i][1]-1]:
        a += 1
if a == len(lh)*len(lw):
    print(ans-1)
else:
    print(ans)

Measured memory_bytes: 82588
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string x[105];;
    int l,n,i,chk=0,j;
    char a,b;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x[i];
        if(i!=0)
        {
            l=x[i-1].length();
            a=x[i-1][l-1];
            b=x[i][0];
            if(a!=b)
                chk=5;

            for(j=i-1;j>=0;j--)
            {
                if(x[i]==x[j])
                    chk=5;
            }
        }
    }
    if(chk==5)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void A()
{
	int S[10000];
	int T[500];
	int N;
	int Q;
	int C = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> S[i];
	}

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

	for (int i = 0; i < Q; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (T[i] == S[j])
			{
				C++;
				break;
			}
		}
	}

	cout << C << endl;
}

void B()
{
	int S[100001];
	int T[50000];
	int N;
	int Q;
	int C = 0;

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

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

	for (int i = 0; i < Q; i++)
	{
		int left = 0;
		int right = N;
		while (left < right)
		{
			int center = (left + right) / 2;

			if (T[i] == S[center])
			{
				C++;
				break;
			}

			if (T[i] > S[center])
			{
				left = center + 1;
			}
			else
			{
				right = center;
			}
		}
	}

	cout << C << endl;
}

int main()
{
	//A();
	B();
	return 0;
}

Measured memory_bytes: 1744
import java.io.*;
import java.util.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] words=br.readLine().split(" ");
HashMap<String,Integer> map=new HashMap<String,Integer>();
int maxoccured=0;
String maxoccuredword="";
int maxlength=0;
String maxlengthword="";
for(String word:words){
if(!map.containsKey(word)){
map.put(word,1);
}
else{
map.put(word,map.get(word)+1);
}
if(map.get(word)>maxoccured){
maxoccured=map.get(word);
maxoccuredword=word;
}
if(word.length()>maxlength){
maxlength=word.length();
maxlengthword=word;
}
}
System.out.println(maxoccuredword+" "+maxlengthword);
}
}

Measured memory_bytes: 16896
import std;

void main() {
    int n; scan(n);
    int m = n % 10;
    if (m == 3) writeln("bon");
    else if (m == 0 || m == 1 || m == 6 || m == 8) writeln("pon");
    else writeln("hon");
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x=n,i,j,c=0;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
LL nibtan(LL* a,LL n,LL x){LL p=0,q=n/2,r=n-1;while(r-p>1){if(x>=a[q])p=q;if(x<=a[q])r=q;q=(p+r)/2;}return a[p]==x?p:r;}
//snippet

#define N 100009

void run() {
	int n, a[N] = { 0 }, A;
	in("%d", &n);
	if (n % 2)a[0]--;
	rep(i, n)if ((n - i) % 2)a[i] += 2;
	rep(i, n) { in("%d", &A); a[A]--; }
	rep(i, n)if (a[i]) { printf("0\n"); return; }
	printf("%lld\n", modpow(2, n / 2, MOD));
}

int main(void) {
	int test = 1;
//	in("%d", &test);
	while (test--) {
		run();
	}
	return 0;
}

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

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

    if (S == 'a'||S == 'i'||S == 'u'||S == 'e'||S == 'o')
      cout << "vowel" << endl;
  
      else
      cout << "consonant" << endl;
}

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

signed main()
{
	int n;
	cin >> n;
	int a[n];
	int even = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		even += a[i] % 2 == 0 ? 1 : 0;
	}
	cout << (pow(3, n) - pow(2, even)) << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
     
   int k,s;
   cin>>k>>s;
   int c=0;
   for(int i=0;i<=k;i++)
   {
      for(int j=0;j<=k;j++)
      {

        if(s-i-j<=k && s-i-j>=0)
        {
            c++;
        }
      }
   }
   cout<<c;




 return 0;
}








Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		char[] c = sc.next().toCharArray();
		int n = c.length;
		int[] count = new int['z' + 1];
		for (int i = 0; i < n; i++) {
			count[c[i]]++;
		}
		for (int i = 'a'; i <= 'z'; i++) {
			if (count[i] % 2 != 0) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

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


Measured memory_bytes: 8660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int h, w, want;
    cin >> h >> w >> want;

    vector<vector<int>> raw_ban(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            raw_ban[i][j] = s[j] - '0';
        }
    }

    ll ret = 0;
    for (int remove_x = 0; remove_x < h; remove_x++) {
        for (int remove_y = 0; remove_y < w; remove_y++) {
            ll now = 0;
            auto ban = raw_ban;
            ban[remove_x][remove_y] = -1;
            int times = 0;
            while (true) {
                for (int i = 0; i < w; i++) {
                    vector<int> v;
                    for (int j = h - 1; j >= 0; j--) if (ban[j][i] > 0)v.push_back(ban[j][i]);

                    for (int j = 0; j < h; j++) {
                        if (j < v.size())ban[h - 1 - j][i] = v[j];
                        else ban[h - 1 - j][i] = -1;
                    }
                }

                bool found = false;

                for (int i = 0; i < h; i++) {
                    for (int j = 0; j < w; j++) {
                        int x = ban[i][j];
                        if (x < 0)continue;
                        for (int k = w; k >= j + want; k--) {
                            bool same = true;
                            for (int l = j; l < k; l++)
                                if (ban[i][l] != x || ban[i][l] < 0)same = false;

                            if (same) {
                                found = true;
                                now += x * (k - j) << times;
                                for (int l = j; l < k; l++)ban[i][l] = -1;
                                break;
                            }
                        }
                    }
                }
                if (!found)break;
                times++;
            }
            ret = max(ret, now);
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

const int MOD = 1e9 + 7;

int mpow(int base, int exp) {
  int res = 1;
  while (exp) {
    if (exp & 1) {
      res = ((ll)res * base) % MOD;
    }
    base = ((ll)base * base) % MOD;
    exp /= 2;
  }
  return res;
}

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

  int n;
  cin >> n;
  vector<int> a;
  unordered_map<int, int> answer;
  while (n--) {
    int x;
    cin >> x;
    a.push_back(x);
    unordered_map<int, int> cnt;
    for (int i = 2; i * i <= x; ++i) {
      while (x % i == 0) {
        ++cnt[i];
        x /= i;
      }
    }
    if (x != 1) {
      ++cnt[x];
    }

    for (auto i : cnt) {
      answer[i.first] = max(answer[i.first], i.second);
    }
  }

  int lcm = 1;
  for (auto i : answer) {
    for (int j = 0; j < i.second; ++j) {
      lcm = ((ll)lcm * i.first) % MOD;
    }
  }

  int sum = 0;
  for (int x : a) {
    cerr << "x=" << x << " mpow(x, MOD - 2)=" << mpow(x, MOD - 2) << '\n';
    sum = (sum + (ll)lcm * mpow(x, MOD - 2)) % MOD;
  }
  cout << sum;
}


Measured memory_bytes: 768
a = []
for i in range(5):
    a.append(int(input()))

b = []
c = []
for j in range(5):
    if a[j] % 10 == 0:
        c.append(10)
        b.append(a[j]-10)
    else:
        c.append(a[j] % 10)
        b.append(a[j] - c[j])
        

b_sum = sum(b)
c_min = min(c)
c_sum = c_min + 4*10

print(b_sum + c_sum)

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

int main()
{
  int64_t n;
  cin >> n;
  vector<int64_t> v(5);
  for (int i = 0; i < 5; i++) {
    cin >> v[i];
  }
  vector<int64_t> t(5);
  for (int i = 0; i < 5; i++) {
    t[i] = (n + v[i] - 1) / v[i];
  }
  sort(begin(t), end(t));
  int64_t ans = t[4] + 4;
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
map<ll, ll> mp;

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

  cin >> n;
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    ans += mp[i - a[i]];
    mp[a[i] + i]++;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 27932
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  double n,m,sum=0; cin>>n>>m;
  vector<ll> a(n);
  for(ll i=0; i<n; i++) {
    cin>>a[i];
    sum += a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  double l = sum/4/m;
  if(a[m-1]>=l) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
s = input()
tap_odd = ["R", "U", "D"]
tap_even =  ["L", "U", "D"]
flg = 0
for i in range(len(s)):
    if i % 2 !=0 and s[i] in tap_even:
        pass
    elif i % 2 ==0 and s[i] in tap_odd:
        pass
    else:
        flg = 1
        break
if flg == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N =1e6+5;
const long long M = (long long)1e9+7;
#define     ll      long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%I64d",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>t abs(t a) {
    if(a>=0)return a;
    return -a;
}
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     vi          vector<int>
#define     vl          vector<ll>
#define     pb          push_back
#define     all(x)      x.begin(),x.end()
#define     LB          lower_bound
#define     UB          upper_bound
#define     Mx(a,b)     (a>b)?a:b
#define     Mn(a,b)     (a<b)?a:b
int a[N];

int main() {
    int n=Int;
    for(int i=1; i<=n; i++)
        a[i]=Int;
    sort(a+1,a+n+1);
    vi v;
    int x=0;
    for(int i=n; i>1; i--) {
            //error(i,a[i]);
        if(a[i]==a[i-1]) {
            v.pb(a[i]);
    //error(a[i],x);
            i--;
            x++;
            if(x==2)
                break;
        }
    }
    if(v.size()<2)return puts("0"),0;
    ll y=1LL*v[0]*1LL*v[1];
    cout<<y;
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
typedef long long ll;
typedef int64_t in;
using namespace std;


int main() {
	int N;
    cin >> N;
    int n;
    n = 2 * N;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int sum=0;
    int i=0;
    while(!l.empty()){
        l.pop_back();
        sum += l.back(); 
        l.pop_back();
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		while (i < 3000) {
			int x = scan.nextInt();
			int y = scan.nextInt();

			if (0 <= x && x <= 10000 && 0 <= y && y <= 10000) {
				if (x == 0 && y == 0) {
					break;
				} else if (x <= y) {
					System.out.println(x + " " + y);
				} else {
					System.out.println(y + " " + x);
				}
			}
			i++;
		}

	}

}

Measured memory_bytes: 36228
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

vector <pll> conn[100050];
ll dis[100050];

int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i < N; i++) {
		int t1, t2, t3;
		scanf("%d %d %d", &t1, &t2, &t3);
		conn[t1].emplace_back(t3, t2);
		conn[t2].emplace_back(t3, t1);
	}

	vector <int> Vu;
	Vu.push_back(1);
	memset(dis, 0x3f, sizeof(dis));
	for (i = 0; i < Vu.size(); i++) {
		for (auto it : conn[Vu[i]]) {
			if (dis[it.second] != LL_INF) continue;
			dis[it.second] = it.first + dis[Vu[i]];
			Vu.push_back(it.second);
		}
	}

	for (i = 1; i <= N; i++) printf("%lld\n", dis[i] % 2);
	return 0;
}

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    if(d[N/2] == d[N/2-1]) cout << 0 << endl;
    else cout << d[N/2] - d[N/2-1] << endl;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i=s.length()-1;i < (n);i++)
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[s.length()-1]=='3'){
        cout<<"bon";
    }else if(s[s.length()-1]=='0'||s[s.length()-1]=='1'||s[s.length()-1]=='6'||s[s.length()-1]=='8'){
        cout<<"pon";
    }else cout<<"hon";
    }


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

using namespace std;

#define int64 long long 
#define fi first
#define se second
const int mod = (int) 1e9 + 7;

const int nax = 2e5 + 5;


void test_case(){
	int x;
	cin >> x;
	cout<< 1 - x;
}

int main(){
	int t=1;
	//cin>>t;
	while(t--){
		test_case();
	}
}


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

using lint = int64_t;
const lint MOD = 1e9 + 7;

int main() {
    lint l, r;
    cin >> l >> r;
    if (r - l > 2020) cout << 0 << endl;
    else {
        lint ans = 2020;
        for (lint i = l; i <= r; i++) {
            for (lint j = i + 1; j <= r; j++) {
                ans = min(ans, i * j % 2019);
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
#define int ll


#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) f(i,0,n-1)cin>>a[i]
#define in1(a,n) f(i,1,n)cin>>a[i]
#define out(a,n) f(i,0,n-1)cout<<fixed<<setprecision(20)<<a[i]<<" ";cout<<"\n"
#define ff first
#define ss second
#define f(i,a,b) for (int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,n) f(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
#define endl '\n'

const int M=(int)1e9+7;

string num;
int n,d;

ll dp[10005][2][105][2];
bool vis[10005][2][105][2];

ll go(int pos, int f, int sum, int start)
{
	if (pos==n)
	{
		if (sum==0)
			return 1;
		else
			return 0;
	}

	ll &ans=dp[pos][f][sum][start];

	if (vis[pos][f][sum][start])
		return ans;

	vis[pos][f][sum][start]=true;
	ans=0LL;

	int LMT=(f)? 9 : num[pos]-'0';

	if (!start)
	{
		f(i,0,LMT)
		{
			int nf=1;
			if (f==0 && i==LMT)nf=0;
			ans=(ans+go(pos+1,nf,(sum+i)%d,start))%M;
		}
	}
	else
	{
		f(i,1,LMT)
		{
			int nf=1;
			if (f==0 && i==LMT)nf=0;
			ans=(ans+go(pos+1,nf,(sum+i)%d,0))%M;
		}
		ans=(ans+go(pos+1,1,sum%d,1))%M;
	}

	return ans;
} 

ll dp1[1005][2][9055][2];
bool vis1[1005][2][9055][2];
 
ll go1(int pos, int f, int sum, int start)
{
	if (pos==n)
	{
		if (sum%d==0 && sum > 0LL)
			return 1;
		else
			return 0;
	}
 
	ll &ans=dp1[pos][f][sum][start];
 
	if (vis1[pos][f][sum][start])
		return ans;
 
	vis1[pos][f][sum][start]=true;
	ans=0LL;
 
	int LMT=(f)? 9 : num[pos]-'0';
 
	if (!start)
	{
		f(i,0,LMT)
		{
			int nf=1;
			if (f==0 && i==LMT)nf=0;
			ans=(ans+go1(pos+1,nf,sum+i,start))%M;
		}
	}
	else
	{
		f(i,1,LMT)
		{
			int nf=1;
			if (f==0 && i==LMT)nf=0;
			ans=(ans+go1(pos+1,nf,sum+i,0))%M;
		}
		ans=(ans+go1(pos+1,1,sum,1))%M;
	}
 
	return ans;
 
 
}

signed main(int argc, char const *argv[])
{
	crap;
	cin>>num;
	n=num.length();
	cin>>d;
	if (n>=1005)
		cout<<go(0,0,0LL,1)-1<<endl;
	else
		cout<<go1(0,0,0,1)<<endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int n, k;
vi a;
vi dp(112345, -1);

int who(int x) {
  if (dp[x] != -1) return dp[x];
  int win = 0;
  for (auto y: a) {
    if (y>x) break;
    if (not who(x-y)) {
      win = 1;
      break;
    }
  }
  return dp[x] = win;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  cin >> n >> k;
  rep(i,0,n) {
    int x;
    cin >> x;
    a.pb(x);
  }

  if (who(k)) cout << "First\n";
  else cout << "Second\n";
}


Measured memory_bytes: 5376
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#endif

int N;
int A[100001];
bool lit[100001];

int main() {
	cin >> N;
	REP(i, 1, N + 1) {
		cin >> A[i];
	}
	int now = 1;
	int count = 0;
	while (!lit[now]) {
		++count;
		lit[now] = true;
		now = A[now];
		if (now == 2) {
			cout << count << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


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

int main() {
  int k, s, count = 0;
  std::cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (0 <= s - i - j && k >= s - i - j) count++;
    }
  }
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
int main(void)
{
    int n;
    int a[100];

    cin >> n;

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

    sort(a, a+n);

    cout << a[n-1] - a[0] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	int a,b,c;

	scanf("%d %d %d\n", &a, &b, &c);

	if(c > b && b > a){
		printf("%d %d %d\n", a, b, c);
	}

	if(b > c && c > a){
		printf("%d %d %d\n", a, c, b);
	}

	if(a > c && c > b){
		printf("%d %d %d\n", b, c, a);
	}

	if(c > a && a > b){
		printf("%d %d %d\n", b, a, c);
	}

	if(b > a && a > c){
		printf("%d %d %d\n", c, a, b);
	}

	if(a > b && b > c){
		printf("%d %d %d\n", c, b, a);
	}

	if(a == b && b == c){
		printf("%d %d %d\n", a, a, a);
	}

	if(a == b && b > c){
		printf("%d %d %d\n", c, a, a);
	}

	if(a == b && c > b){
		printf("%d %d %d\n", a, a, c);
	}

	if(a > c && b == c){
		printf("%d %d %d\n", b, b, a);
	}

	if(c > a && b == c){
		printf("%d %d %d\n", a, b, b);
	}

	if(a == c && b > c){
		printf("%d %d %d\n", a, a, b);
	}

return(0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
  int k,n,mini=0; cin>>k>>n;
  vector<int> a(n),b(n-1);
  rep(i,n) cin>>a[i];
  for(int i=0;i<n-1;i++){
    mini=max(mini,a[i+1]-a[i]);
  }
  mini=max(mini,a[0]+k-a[n-1]);
  cout<<k-mini;
}

Measured memory_bytes: 4844