akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
const int mod=1e9+7;
using ll = long long int;
ll dp[(int)(1e5+5)];
ll sum(int idx,int c)
{
    int l = idx-c-1;
    if(l<0)
        return dp[idx];
    return dp[idx]-dp[l];
}
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    fill(dp,dp+100005,1);
    for(int i=1;i<=n;i++)
    {
        for(int j=k;j>0;j--)
        {
            dp[j] = sum(j,arr[i]);
        }
//        for(int j=0;j<=k;j++)
//            cout<<dp[j]<<" ";
//        cout<<endl;
        for(int j=1;j<=k;j++)
            dp[j] = (1LL*dp[j]+dp[j-1])%mod;
    }
    ll ans = (dp[k]-dp[k-1]+mod)%mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 1000

int main(){
  int d;
  scanf("%d\n",&d);
  
  int* vec;
  vec = (int*)malloc(sizeof(int)*2*d);
  int center,right,left;
  right = d+1;
  left = d;

  for(int i = 0; i < d; i++){
    char s[N];
    fgets(s,N-1,stdin);
    int a,b,c;
    char* tk;
    tk = strtok(s," ");
    a = atoi(tk);
    if(a == 0){
      b = atoi(strtok(NULL," "));
      c = atoi(strtok(NULL," "));
    }else{
      b = atoi(strtok(NULL," "));
    }

    if(a == 0){
      if(b == 0){
	vec[left--] = c;
      }else{
	vec[right++] = c;
      }
    }else if(a == 1){
      printf("%d\n",vec[left+b+1]);
    }else if(a == 2){
      if(b == 0){
	left++;
      }else{
	right--;
      }
    }
  }
  free(vec);
  return 0;
 
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;
// " ", ' '

// プロトタイプ宣言
// int myfunc(int, vector<vector<int>>);

// グローバル変数

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	vector<int> L(N+1);
	L.at(0) = 2; L.at(1) = 1;
	for (int i=2; i<=N; i++) {
		L.at(i) = L.at(i-1)+L.at(i-2);
	}

	cout << L.at(N) << endl;
	
}


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

int main() {
  int n;
  cin >> n;
  
  if (n == 1) {
    cout << "Hello World" << endl;
    return 0;
  } else if (n == 2) {
    int a,b;
    cin >> a >> b;
    
    cout << a + b << endl;
    return 0;
  }
  
  return -1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int a; CI a;
	int ans = 0;
	REP(i, 35) {
		FOR(j,2, 10) {
			if (pow(i, j) > 1000)break;
			if (ans < pow(i, j)&&pow(i,j)<=a) ans = pow(i, j);
		}
	}

	CO ans EN;

	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
int a[26];

int main() {
	cin >> s;
	rep(i,s.length()) a[s[i]-'a']++;
	rep(i,26) {
		if (a[i]>=2) {
			cout << "no" << ln;
			return 0;
		}
	}
	cout << "yes" << ln;
}

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

int n, m, ans = 0;
int cnt[33] = {0};

int main() {
  cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    int k, x;
    cin >> k;
    for(int j = 0; j < k; ++j) {
      cin >> x;
      ++cnt[--x];
    }
  }
  for(int i = 0; i < m; ++i)
    if(cnt[i] == n) ++ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	
	public static void main(String args[]) throws IOException {
		char c[] = getString().toCharArray();
		if (c[0]==c[1]&&c[2]==c[3]&&c[0]!=c[2] || c[0]==c[2]&&c[1]==c[3]&&c[0]!=c[1] || c[0]==c[3]&&c[1]==c[2]&&c[0]!=c[1] ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		
	}
}


Measured memory_bytes: 21332
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll a[200010], b[200010];
std::vector<ll> G[200010];

/*std::vector<ll> next( const std::vector<ll> &st, ll v )
{
  std::vector<ll> ret = st;

  ret[v] = 0;

  bool used[200010];

  rep( i, N+1 )
    used[i] = false;

  std::queue<P> que;
  que.emplace( v, -1 );

  while( !que.empty() )
  {
    P p = que.front(); que.pop();

    used[p.first] = true;

    if( p.first != v )
    {
      ret[p.second] += ret[p.first];
      ret[p.first] = 0;
    }

    for( auto u : G[p.first] ) if( !used[u] )
    {
      que.emplace( u, p.first );
    }
  }

  return ret;
}

ll grundy( const std::vector<ll> &st )
{
  bool fl = true;

  rep( i, N )
    fl &= st[i]==0;

  if( fl )
    return 0;

  std::set<ll> S;

  std::cout << st << std::endl;

  rep( i, N ) if( st[i] )
    S.emplace( grundy( next( st, i ) ) );

  rep( i, N ) if( !S.count(i) )
    return i;

  return N;
}*/

ll subtree[200010];
ll bit[200010];
ll sv;

ll bfs( ll v )
{
  std::queue<P> que;
  que.emplace( v, 0 );

  bool used[200010];

  rep( i, N+1 )
    used[i] = false;

  ll ret = 0;

  while( !que.empty() )
  {
    P p = que.front(); que.pop();
    ll u = p.first, dist = p.second;

    used[u] = true;

    bool upd = false;

    //std::cout << p << std::endl;

    for( auto ver : G[u] ) 
    {
      //std::cout << ver << ' ' << used[ver] << std::endl;

      if( used[ver] )
        continue;

      que.emplace( ver, dist+1 );

      upd = true;
    }

    if( !upd )
    {
      if( ret < dist )
      {
        sv = u;
        ret = dist;
      }
    }
  }

  return ret;
}

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

  rep( i, N-1 )
  {
    std::cin >> a[i] >> b[i];
    --a[i], --b[i];

    G[a[i]].emplace_back( b[i] );
    G[b[i]].emplace_back( a[i] );
  }

  bfs( 0 );

  ll L = bfs(sv);

  puts( L%3==1 ? "Second" : "First" );

  return 0;
}

Measured memory_bytes: 20464
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


x=int(data())
if x>=30:
    out("Yes")
else:
    out("No")






Measured memory_bytes: 72776
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
 
int main() {
    int n, m;
    cin>>n>>m;
    char grid[n][m];
    long long int dp[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>grid[i][j];
            dp[i][j] = 0;
        }
    }
    
    for(int i=n-1; i>=0; i--){
        for(int j=m-1; j>=0; j--){
            if(grid[i][j]!='#'){
                if(i==n-1 && j==m-1){
                    dp[i][j] = 1;
                }
                else if(j!=m-1 && i==n-1){
                    dp[i][j] = dp[i][j+1];
                }
                else if(i!=n-1 && j==m-1){
                    dp[i][j] = dp[i+1][j];
                }
                else{
                    dp[i][j] = ((dp[i+1][j] % mod) + (dp[i][j+1] % mod)) % mod;
                }
            }
            else
                dp[i][j] = 0;
            
        }
    }
    
    // for(int i=0; i<n; i++){
    //     for(int j=0; j<m; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    
    cout<<dp[0][0];
}

Measured memory_bytes: 12372
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m=0,x=0;string s;cin>>n>>s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='I'){
      x++;
      m=max(m,x);
    }
    else x--;
  }
  cout<<m<<endl;
}


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

int main() {
	int N;
	int L;
	cin >> N>>L;
	int r;
	
	if (L < 0) {
		if (N > -L) {
			for (int i = 1; i <= N; i++) {
				if (0 == L + i - 1) r = i;
			}
		}else {
			r = N;
		}
	}
	else {
		r = 1;
	}

	int ans=0;
	for (int i = 1; i <= N; i++) {
		if(i!=r) ans += L + i - 1;
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int M = max({a, b, c});
    if ((3 * M) % 2 != (a + b + c) % 2)
        ++M;
    cout << (3 * M - a - b - c) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long p,i,j,n,m,a,b,c[12],x,k,y[12][12],s[12],z=10000000000;
bool r[12],f;
int main(){
  for(cin>>n>>m>>x;i<n;i++){
    cin>>c[i];
    for(j=0;j<m;j++)cin>>y[i][j];
  }
  
  for (int bit = 0; bit < (1<<n); ++bit) {
    for(i=0;i<n;i++)r[i]=false;
    for(i=0;i<m;i++)s[i]=0;
    for(i=0;i<n;i++)if(bit&(1<<i))r[i]=true;
    f=true;
    p=0;
    for(i=0;i<n;i++){
      if(r[i]){
        for(j=0;j<m;j++)s[j]+=y[i][j];
        p+=c[i];
      }
    }
    for(i=0;i<m;i++){
      if(s[i]<x){
        f=false;
        break;
      }
    }
    if(f){
      a++;
      z=min(z,p);
    }
  }
  cout<<(a==0?-1:z);
}

Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string a,b;cin>>a>>b;
  rep(i,b.size()){
    cout<<a[i];
    cout<<b[i];
  }
  if(a.size()>b.size())cout<<a[a.size()-1];
  cout<<endl;
}

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

int min(int a,int b){
    if(a>=b){
        return b;
    }
    else{
        return a;
    }
}

int main(){
    int n;
    scanf("%d",&n);
    int vector[n];
    for(int i=0;i<n;i++){
        scanf("%d",&vector[i]);
    }
    int small=n+1;
    int count=0;
    for(int i=0;i<n;i++){
        small=min(small,vector[i]);
        if(small==vector[i]){
            count++;
        }
    }
    printf("%d",count);
}    

Measured memory_bytes: 896
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] abc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int a = abc[0];
        int b = abc[1];
        int c = abc[2];
        int ans = 0;

        while(!(abc[0] == abc[1] && abc[1] == abc[2]))
        {
            Array.Sort(abc);
            if(abc[0] < abc[1])
            {
                abc[0] += 2;
            }else if(abc[0] == abc[1])
            {
                abc[0] += 1;
                abc[1] += 1;
            }
            ans++;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int a,b;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
int main(){
	a=read(),b=read();
	printf("%d\n",max(a+b,max(a-b,a*b)));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 200010
int n,k,c,f[N],g[N],lst;
char s[N];
int main()
{
	scanf("%d%d%d",&n,&k,&c);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	  {
	  f[i]=f[i-1];
	  if(i>lst && s[i]=='o')f[i]++,lst=i+c;
	  }
	lst=n+1;
	for(int i=n;i>=1;i--)
	  {
	  g[i]=g[i+1];
	  if(i<lst && s[i]=='o')g[i]++,lst=i-c;
	  }
	for(int i=1;i<=n;i++)
	  if(f[i]>f[i-1] && g[i]>g[i+1] && f[i]+g[i]==k+1)
	    printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 3200
function Main(input) {
  input = input.split("\n");
  var N = input[0].split(" ").map(Number);
  var A = input[1].split(" ").map(Number);
if(N[0]+1==A[0]){
  console.log(1);
}else{
  console.log(0);
}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
import math
a, b, c, d = map(int, input().split())

def lcm(m,n):
    return (m*n) // math.gcd(m,n)

if a%c == 0:
    x = a//c
else:
    x = a//c + 1

if a%d == 0:
    y = a//d
else:
    y = a//d + 1

if a%lcm(c,d) == 0:
    z = a//lcm(c,d)
else:
    z = a//lcm(c,d) + 1
    
X = b//c
Y = b//d
Z = b//lcm(c,d)
    
print((b-a+1) - ((X-x+1) + (Y-y+1) - (Z-z+1)))



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

int main(void) {
  int n,m,l;
  int a[110];
    int j=0;
  cin >> n>>m>>l;
  for (int i = 1; i < 105; i++) {

    if(n%i==0&&m%i==0){

      a[j]=i;
    

      j++;

    }
  }
  cout<<a[j-l];


  return 0;
}


Measured memory_bytes: 256
(*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*)

open System;

let n = int(Console.ReadLine());
let l = Console.ReadLine().Split(' ');

let rec ans i j =
    if j < n then int(l.[i]) * int(l.[j]) + ans i (j+1)
    else if i < n then ans (i+1) (i+2)
    else 0

Console.WriteLine(ans 0 1);

Measured memory_bytes: 11220
#include<stdio.h>
int main(void)
{
	int a,b,c,d,k=0,j=0;
	scanf("%d %d %d %d ",&a,&b,&c,&d);
	if(-d<=(c-a)&&(c-a)<=d) {
		printf("Yes");
	}else {
		if(-d<=(b-a)&&(b-a)<=d) k=1; 
                if(-d<=(b-c)&&(b-c)<=d) j=1;
                if(j==1 && k==1) printf("Yes");
	else printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    ll l, r; cin >> l >> r;
    if(r - l >= 2050) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 2018;
    FOR(i, l, r) FOR(j, i+1, r+1) {
        chmin(ans, (i * j) % 2019LL);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>

using namespace std;

int n;
string str;
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		bool left=false,right=false,lr=false;
		int cnt=0;
		for(int i=0;i<n;i++){
			cin >> str;
			if(str=="lu")left=true;
			if(str=="ru")right=true;
			if(str=="ld")left=false;
			if(str=="rd")right=false;
			if(!lr && left && right){
				cnt++;
				lr=true;
			}
			if(lr && !left && !right){
				cnt++;
				lr=false;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

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

int H,W,N;
int a[201][201];
int A[201][201];


int calc(int h,int w,int H,int W){
  return A[H][W]-A[H][w]-A[h][W]+A[h][w];
}


bool solve(int h,int w,int H,int W,int N,int M){
  int res=0,total=calc(h,w,H,W);
  if(N==1)return (total>=M);
  
  for(int i=h+1;i<H;i++){
    if(calc(h,w,i,W)<M)continue;
    if(solve(i,w,H,W,N-1,M))return true;
    break;
  }
  
  for(int j=w+1;j<W;j++){
    if(calc(h,w,H,j)<M)continue;
    if(solve(h,j,H,W,N-1,M))return true;
    break;
  }

  for(int i=H-1;i>h;i--){
    if(calc(i,w,H,W)<M)continue;
    if(solve(h,w,i,W,N-1,M))return true;
    break;
  }

  for(int j=W-1;j>w;j--){
    if(calc(h,j,H,W)<M)continue;
    if(solve(h,w,H,j,N-1,M))return true;
    break;
  }
  return res;
}

bool check(int nv,int sv,int M){
  int ev=0,wv=0;
  while( calc(0,0,wv,nv) < M ){
    wv++;
    if(wv>=H)return false;
  }
  
  while( calc(0,nv,ev,W) < M ){
    ev++;
    if(ev>=H)return false;
  }

  if(sv<nv)ev=max(ev,wv);
  if(sv>nv)wv=max(ev,wv);
  
  if( calc(wv,0,H,sv) < M)return false;
  if( calc(ev,sv,H,W) < M)return false;

  return true;
}

bool check(int M){
  if(N==4){
    for(int nv=1;nv<W;nv++)
      for(int sv=1;sv<W;sv++)
        if(check(nv,sv,M))return true;
  }
  if( solve(0,0,H,W,N,M) )return true;
  return false;
}

int compute(){
  int L=0,R=1e9,M;
  while(R-L>1){
    M=(L+R)/2;
    if(check(M))L=M;
    else R=M;
  }
  return L;
}

int main(){
  scanf("%d %d %d",&H,&W,&N);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      scanf("%d",&a[i][j]);
      A[i+1][j+1]=a[i][j]+A[i+1][j]+A[i][j+1]-A[i][j];
    }
  }

  int ans=compute();
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 3540
#include <stdio.h>
int main(void){
  int i,j,a,n,m=0;
  scanf("%d",&n);
  j=1;
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a==j){
      j++;
    }else{
      m++;
    }
  }
  if(m==n){
    m=-1;
  }
  printf("%d",m);
  return 0;
}

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

int main() 
{
    ll n, m;
    cin >> n >> m;
    if (n==1 && m==1)
        cout << 1;
    else if (n==1 && m!=1)
        cout << m-2;
    else if (n!=1 && m==1)
        cout << n-2;
    else 
        cout << (n-2)*(m-2);  
    return 0;
}

Measured memory_bytes: 256
#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>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}


#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;

main(){
    int m=in(),d=in();
    int ans=0;
    rep2(i,1,m){
        rep2(j,1,d){
            int d1=j%10;
            int d2=j/10;
            if(d2<2||d1<2)continue;
            if(i==d1*d2)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

//UNION FIND
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    
    //n要素で初期化
    UnionFind(int n) : par(n), rank(n){
        for (int i=0; i<n; ++i){
            par[i] = i;
            rank[i] = 0;
        }
    }

    //木の根を求める
    int root(int x){
        if (par[x] == x){
            return x;
        }else{
            return par[x] = root(par[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if (rank[x] == rank[y]) ++rank[x];
        }
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int p[110000], x[110000], y[110000];
    REP(i, N) cin >> p[i];
    REP(i, M) cin >> x[i] >> y[i];
    UnionFind tree(N);
    REP(i, M) tree.unite(x[i]-1,y[i]-1);
    int ans = 0;
    REP(i, N){
        if (tree.same(i, p[i]-1)) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int b = q - k;
        int[] r = new int[n];
        for (int i = 0; i < q; i++) {
            r[sc.nextInt() - 1]++;
        }
        IntStream.of(r).mapToObj(ri -> (b < ri) ? "Yes" : "No").forEach(System.out::println);
    }
}


Measured memory_bytes: 55620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;
const int INF=1000000000;

int xs[10001];
int ys[10001];
int ds[10001];
int cs[10001];
int ps[10001];
int qs[101][101];
int rs[101][101];
int d[101][101][101];
int d2[101][101];

int calcCost(int dist,int company){
  int res=0;
  for(int i=0;i<ps[company];i++){
    if(i==ps[company]-1)
      res+=dist*rs[company][i];
    else if(i==0){
      int a=min(dist,qs[company][0]);
      dist-=a;
      res+=rs[company][0]*a;
    }
    else{
      int a=min(dist,qs[company][i]-qs[company][i-1]);
      dist-=a;
      res+=rs[company][i]*a;
    }
  }
  return res;
}

int main(){
  int n,m,c,s,g;
  while(cin>>n>>m>>c>>s>>g&&(n|m|c|s|g)){
    s--;g--;
    for(int i=0;i<m;i++){
      cin>>xs[i]>>ys[i]>>ds[i]>>cs[i];
      xs[i]--;ys[i]--;cs[i]--;
    }
    for(int i=0;i<c;i++)cin>>ps[i];
    for(int i=0;i<c;i++){
      for(int j=0;j<ps[i]-1;j++)cin>>qs[i][j];
      for(int j=0;j<ps[i];j++)cin>>rs[i][j];
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)
	for(int k=0;k<n;k++)
	  if(j==k)d[i][j][k]=0;
	  else d[i][j][k]=INF;
    }
    for(int i=0;i<m;i++){
      d[cs[i]][xs[i]][ys[i]]=min(d[cs[i]][xs[i]][ys[i]],ds[i]);
      d[cs[i]][ys[i]][xs[i]]=min(d[cs[i]][ys[i]][xs[i]],ds[i]);
    }
    // 線路会社ごとの最短経路
    for(int l=0;l<c;l++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  for(int k=0;k<n;k++)
	    d[l][j][k]=min(d[l][j][k],d[l][j][i]+d[l][i][k]);
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(i==j)d2[i][j]=0;
	else d2[i][j]=INF;
    // それぞれの値をコストに置き換える
    for(int l=0;l<c;l++){
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  if(d[l][i][j]!=INF)
	    d[l][i][j]=calcCost(d[l][i][j],l);
	  d2[i][j]=min(d2[i][j],d[l][i][j]);
	}
      }
    }
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	for(int k=0;k<n;k++)
	  d2[j][k]=min(d2[j][k],d2[j][i]+d2[i][k]);
    if(d2[s][g]==INF)cout<<-1<<endl;
    else cout<<d2[s][g]<<endl;
  }
  return 0;
}

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

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

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

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int a, b, c;
    read(a, b, c);
    
    FOR(1e5) {
        int x = (a * i) % b;
        if (x == c) {
            print("YES");
            return;
        }
    }
    
    print("NO");
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        
        solve();
        
    }
    
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
#define P pair<int,int>
typedef long long ll;
using namespace std;

int main(){
    int h,w; cin >> h >> w;
    vector<string> rd(h);
    rep(i,h) cin >> rd[i];
    int rev=0;
    if(rd[0][0]=='#') rev=1;
    int ans[h+1][w+1];
    rep(i,h+1) ans[i][0]=0;
    rep(i,w+1) ans[0][i]=0;
    rep(i,h)rep(j,w){
        int tate=ans[i][j+1];
        int yoko=ans[i+1][j];
        if(i!=0){
            if(rd[i][j]=='#'){
                if(rd[i-1][j]=='.') tate++;
            }
        }
        if(j!=0){
            if(rd[i][j]=='#'){
                if(rd[i][j-1]=='.') yoko++;
            }
        }
        if(i==0 && j==0) ans[i+1][j+1]=0;
        else if(i==0) ans[i+1][j+1]=yoko;
        else if(j==0) ans[i+1][j+1]=tate;
        else ans[i+1][j+1]=min(tate,yoko);
    }
    cout << ans[h][w]+rev << endl;
return 0;
}


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

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* main */
void Main(void)
{
    while (true)
    {
        int w, h;
        cin >> h >> w;
        if (w == 0 && h == 0)
        {
            break;
        }
        else
        {
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    cout << "#";
                }
                cout << endl;
            }
            cout << endl;
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



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

// recursive approach
long long knapsack(vector<pair<int, long long>> &wv, int w, int i){
    if(w < 0)
        return LONG_LONG_MIN;
    if(w == 0 or i < 0){
        return 0;
    }

    return max(knapsack(wv, w - wv[i].first, i-1) + wv[i].second,
                knapsack(wv, w, i-1));
}

// dynamic programming approach
long long knapsack1(vector<pair<int, long long>> &wv, int w){
    vector<vector<long long>> dp(wv.size() + 1, vector<long long>(w + 1, 0));

    for(int i = 0;i <= wv.size();i++){
        for(int wt = 0;wt <= w;wt++){
            if(i == 0 || wt == 0)
                dp[i][wt] = 0;
            else if(wv[i-1].first <= wt){
                dp[i][wt] = max(wv[i-1].second + dp[i-1][wt - wv[i-1].first], dp[i-1][wt]);
            }else{
                dp[i][wt] = dp[i-1][wt];
            }
        }
    }

    return dp[wv.size()][w];
}


// dynamic programming approach, memory optimized
long long knapsack2(vector<pair<int, long long>> &wv, int w){
    vector<long long> dp(w + 1, 0);

    for(int i = 0;i < wv.size();i++){
        // wt is the weight of items already considered in knapsack
        for(int wt = w-wv[i].first;wt >= 0;wt--){
            // now to that already filled knapsack we want to add item with weight w[i] or else not
            dp[wt + wv[i].first] = max(dp[wt + wv[i].first], wv[i].second + dp[wt]);
        }
    }

    long long ans = 0;
    for(int i = 0;i <= w;i++){
        ans = max(ans, dp[i]);
    }

    return ans;
}

int main(){
    int n, w;
    cin >> n >> w;
    vector<pair<int, long long>> wv(n);

    for(int i = 0;i < n;i++){
        cin >> wv[i].first >> wv[i].second;
    }

    cout << knapsack2(wv, w) << endl;

    return 0;
}

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

int main(){
//srandom((unsigned long)time(NULL));

int n,m;
cin>>n>>m;
vector<int> a;
int sum=0;
for(int i=0;i<n;i++){
    int x;
    cin>>x;
    sum+=x;
    a.emplace_back(x);
}
sort(a.begin(),a.end());
for(int i=0;i<n;i++){
 if(a[i]>=(double)sum/4/m){
     if(n-i>=m){
         cout<<"Yes"<<endl;
         return 0;
     }
 }
}
cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>
#include <cstdlib>  // abs() for integer

using namespace std;

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


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

char s[200001];

template<typename T>
constexpr T pow_mod(T a, T b, T m)
{
	T r = 1;
	while (b > 0)
	{
		if ((b & 1) != 0) r = (r * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return r;
}

int main()
{
	int n;
	scanf("%d%s", &n, s);
	long long org_ones = 0;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == '1')
		{
			org_ones += 1;
		}
	}
	long long x_mod_plus = 0;
	long long x_mod_minus = 0;
	for (int i = 0; i < n; ++i)
	{
		x_mod_plus = (x_mod_plus * 2 + s[i] - '0') % (org_ones + 1);
	}
	if (org_ones > 1)
	{
		for (int i = 0; i < n; ++i)
		{
			x_mod_minus = (x_mod_minus * 2 + s[i] - '0') % (org_ones - 1);
		}
	}

	for (int i = 0; i < n; ++i)
	{
		int ans = 0;
		if (s[i] == '0')
		{
			long long x = (x_mod_plus + pow_mod(2LL, (long long)(n - 1 - i), org_ones + 1)) % (org_ones + 1);
			ans += 1;
			while (x > 0)
			{
				x = x % __builtin_popcountl(x);
				ans += 1;
			}
		}
		else
		{
			if (org_ones != 1)
			{
				long long x = (x_mod_minus + (org_ones - 1) - pow_mod(2LL, (long long)(n - 1 - i), org_ones - 1)) % (org_ones - 1);
				ans += 1;
				while (x > 0)
				{
					x = x % __builtin_popcountl(x);
					ans += 1;
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 2020
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [set() for _ in range(n)]
b = [set() for _ in range(n)]
for i in range(n):
    nn = int(input())
    for j in range(nn):
        x,y = list(map(int, input().split()))
        x -= 1
        if y==1:
            a[i].add(x)
        else:
            b[i].add(x)
ans = -1
for bit in range(1<<n):
    tmpa = set()
    tmpb = set()
    tmp2a = set()
    tmp2b = set()
    for j in range(n):
        if bit>>j&1:
            tmpa |= a[j]
            tmpb |= b[j]
            tmp2a.add(j)
        else:
            tmp2b.add(j)
    if len(tmpa&tmpb)==0 and len(tmp2a&tmpb)==0 and len(tmpa&tmp2b)==0: #and tmpa==tmp2:
        ans = max(ans, len(tmp2a))
print(ans)

Measured memory_bytes: 74556
X,A,B=input().split()
x=int(X)
a=int(A)
b=int(B)
if x>a:
  p=x-a
else:
  p=a-x
if x>b:
  q=x-b
else:
  q=b-x
if p<q:
  print("A")
else:
  print("B")

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

typedef long long ll;
using namespace std;

int main() {
    char S[4];
    cin >> S;

    for (int i = 0; i < 3; ++i) {
        if (S[i] == S[i + 1]) {
            cout << "Bad";
            return 0;
        }
    }
    cout << "Good";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int dp[100005];

int q[1000005];

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    dp[i] = 1 << 25;
  }
  dp[1] = 1;
  int ql = 500000;
  int qr = 500000;
  q[qr++] = 1;
  while(ql != qr) {
    int curr = q[ql++];
    if(dp[(curr+1)%n] > 1 + dp[curr]) {
      dp[(curr+1)%n] = 1 + dp[curr];
      q[qr++] = (curr+1)%n;
    }
    if(dp[(10*curr)%n] > dp[curr]) {
      q[--ql] = (10*curr)%n;
      dp[(10*curr)%n] = dp[curr];
    }
  }
  printf("%d\n", dp[0]);
}


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

class Main {

  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

    int N = in.nextInt();
    int W = in.nextInt();
    int[] w = new int[N], v = new int[N];
    for (int i = 0; i < N; i++) {
      w[i] = in.nextInt();
      v[i] = in.nextInt();
    }

    long[] dp = new long[W + 1];
    for (int i = 0; i < N; i++) {
      for (int j = W; j >= w[i]; j--) {
        dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]);
      }
    }


    System.out.println(dp[W]);
  }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

bool pal(char *s, char *t){
	int n = t-s;
	REP(i, n){
		if(s[i] != s[n-1-i]) return false;
	}
	return true;
}

char s[100];
int main(){
	scanf("%s", s);
	int n = strlen(s);
	if(pal(s, s+n) && pal(s, s + n/2) && pal(s + n/2 + 1, s + n)){
		printf("Yes\n");
	} else {
		printf("No\n");
	}
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;

int main() {
  int a;
  cin >> a;
  vector<int> v(a);
  int mmax = -1;
  for (int i = 0; i < a; ++i)
    cin >> v[i];
  for (int i = 0; i < a; ++i)
    for (int j = 0; j < a; ++j)
      if (abs(v[i] - v[j]) > mmax) mmax = abs(v[i] - v[j]);
  
  cout << mmax << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int n,lma[200010],rma[200010],a[200010];

signed main(){
	cin >> n;
	lma[0] = 0;
	rma[n] = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		lma[i + 1] = max(lma[i],a[i]);
	}
	for(int i = n - 1;i >= 0;i--){
		rma[i] = max(rma[i + 1],a[i]);
	}
	for(int i = 0;i < n;i++){
		cout << max(lma[i],rma[i + 1]) << endl;
	}
}


Measured memory_bytes: 6272
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct RollingHash {
    static const ll b1 = 1007, b2 = 2009;
    static const ll mod1 = 1000000007, mod2 = 1000000009;
    vll h1, h2, p1, p2;

    RollingHash(const string &s) {
        ll n = s.size();
        h1.assign(n + 1, 0);
        h2.assign(n + 1, 0);
        p1.assign(n + 1, 1);
        p2.assign(n + 1, 1);
        for (int i = 0; i < n; ++i) {
            h1[i + 1] = (h1[i] * b1 + s[i]) % mod1;
            h2[i + 1] = (h2[i] * b2 + s[i]) % mod2;
            p1[i + 1] = (p1[i] * b1) % mod1;
            p2[i + 1] = (p2[i] * b2) % mod2;
        }
    }
    
    inline pll get(ll l, ll r) const {
        ll res1 = h1[r] - h1[l] * p1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        ll res2 = h2[r] - h2[l] * p2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return make_pair(res1, res2);
    }
};

void solve() {
    string t, p;
    cin >> t >> p;
    RollingHash ht(t), hp(p);
    vll ans;
    for(ll i = 0; i + p.size() <= t.size(); i++) {
        pll pp = hp.get(0, p.size());
        pll pt = ht.get(i, i + p.size());
        if(pp == pt) {
            ans.push_back(i);
        }
    }
    for(auto i : ans) cout << i << endl;
    return;
}

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


Measured memory_bytes: 44576
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
	int n, a, b,x;
	cin >> n >> a >> b;
	x = n * a;
	if (x <= b) {
		cout << x << endl;
	}
	else {
		cout << b << endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+5;
int prime[MAXN]={0};
vector<int>fac[MAXN];
void getprime(){
    for(int i=2;i<MAXN;i++){
        if(!prime[i]){
            //fac[i].push_back(i);
            for(int j=i*2;j<MAXN;j+=i)
            {
                prime[j]=1;
                fac[j].push_back(i);
            }
        }
    }
    for(int i=2;i<MAXN;i++){
        if(!prime[i])
            fac[i].push_back(i);
    }

}
int a[MAXN]={0};
map<int,int>mm;
int solve(int n){
    if(mm[n]>1)
        return 0;
    vector<int>vv;
    vv.push_back(1);
    for(auto pr:fac[n]){
        vector<int>cc;
        int p1=pr;
        while(n%p1==0){
            cc.push_back(p1);
            p1*=pr;
        }
        int sz = vv.size();
        for(int i=0;i<sz;i++){
            for(auto p:cc){
                vv.push_back(vv[i]*p);
            }
        }
    }
    for(auto ele:vv){
        //cout <<ele <<" ";
        if(ele!=n&&mm[ele]){
            return 0;
        }
    }
    return 1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    getprime();
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mm[a[i]]++;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        ans+=solve(a[i]);
    }
    cout <<ans << endl;
    return 0;
}


Measured memory_bytes: 92584
import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
n,k=map(int,input().split())
A=list(map(int,input().split()))
#n,k=5,3
#A=[-30,-10,10,20,40]
ans=inf
for i in range(n-k+1):
    ans=min(ans, abs(A[i])+abs(A[i]-A[i+k-1]), abs(A[i+k-1])+abs(A[i+k-1]-A[i]) )
print(ans)

Measured memory_bytes: 14756