akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll N, A, B;
bool ok(ll l, vl& h){
    ll cnt = 0;
    REP(i, N){
        if(h[i] <= B*l) continue;
        cnt += (h[i] - B*l + (A-B)-1) / (A-B);
    }
    return cnt <= l;
}

int main(){
    cin >> N >> A >> B;
    vl h(N, 0); REP(i, N) cin >> h[i];
    ll l = 0ll, r = 1e9;
    while(abs(r-l) > 1){
        ll mid = (l+r)/2;
        if(ok(mid, h)) r = mid;
        else l = mid;
    }
    bool lok = ok(l, h);
    cout << (lok ? l : r) << endl;
    return 0;
}


Measured memory_bytes: 1024
def main():
    import sys
    n,k,q=map(int,input().split())
    if k-q>0:
        for i in range(n):
            print('Yes')
        sys.exit()

    a=[k-q]*n
    for i in range(q):
        a[int(input())-1]+=1
    for i in range(n):
        print('Yes' if a[i]>0 else 'No')

if __name__ == '__main__':
    main()

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

#define Lowbit(X) (X&(-X))
#define Lson (X<<1)
#define Rson (X<<1|1)
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(int i=A;i<=B;i++)
#define BOR(i,A,B) for(int i=A;i>=B;i--)
#define FOR_SIDE(i,A) for(int i=Head[A];i;i=Next[i])
#define INF 0x7fffffff
using namespace std;
const int MAXN=2e3+10;

typedef long long ll;
int DP[MAXN][MAXN];
bool Vis[MAXN][MAXN];
int Row,Line,Stax,Stay,Endx,Endy,New,A,B;
char Map[MAXN][MAXN];
int Dx[5]={0,0,-1,0,1},Dy[5]={0,1,0,-1,0};
int Dx5[21]={0,-1,-1,1,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2,2,2,2,1};
int Dy5[21]={0,1,-1,-1,1,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2};
struct Node { int E,F; };
queue<Node>Mine;

inline void DFS(int X,int Y,int Time) {
    Vis[X][Y]=true;
    DP[X][Y]=Time;
    FOR(i,1,4) {
        int Nx=X+Dx[i],Ny=Y+Dy[i];
        if(Nx>Row || Nx<1 || Ny>Line || Ny<1 || Vis[Nx][Ny]) continue;
        DFS(Nx,Ny,Time);
    }
    FOR(i,1,20) {
        int Nx=X+Dx5[i],Ny=Y+Dy5[i];
        if(Nx<=Row && Nx>=1 && Ny<=Line && Ny>=1 && !Vis[Nx][Ny]) {
            Mine.push(Node{ Nx,Ny }); 
			if(DP[Nx][Ny]) DP[Nx][Ny]=min(Time+1,DP[Nx][Ny]);
			else DP[Nx][Ny]=Time+1;
        }
    }
}

int main() {
    scanf("%d %d",&Row,&Line);
    scanf("%d %d",&Stax,&Stay);
    scanf("%d %d",&Endx,&Endy);
    FOR(i,1,Row) { 
		scanf("%s",Map[i]+1); 
		FOR(j,1,Line) if(Map[i][j]=='#') Vis[i][j]=true;
	}
	Mine.push(Node{ Stax,Stay });
	while(!Mine.empty()) {
		int W=Mine.front().E,S=Mine.front().F;
		if(Vis[W][S]) { Mine.pop(); continue; }
        DFS(W,S,DP[W][S]);
		Mine.pop();
    }
    if(!Vis[Endx][Endy]) { printf("-1\n"); }
    else { printf("%d\n",DP[Endx][Endy]); }
    system("pause");
    return 0;
}

Measured memory_bytes: 15668
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int n = in.ni(), k = in.ni();
    boolean[] has = new boolean[n + 1];
    int result = n;
    for (int i = 0; i < k; i++) {
      int d = in.ni();
      for (int j = 0; j < d; j++) {
        int next = in.ni();
        if (!has[next]) {
          result--;
        }
        has[next] = true;
      }
    }
    out.println(result);
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

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

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 33648
#include <iostream>

int main() {
    int m = 0;
    int l = 0;
    std::string s; std::cin >> s;
    for (const auto c: s) {
        switch (c) {
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                l++;
                break;
            default:
                m = std::max(m, l);
                l = 0;
                break;
        }
    }
    m = std::max(m, l);
    std::cout << m << std::endl;
    return 0;
}

Measured memory_bytes: 3156
a,b,c = map(int,input().split())
k = int(input())

while(k):
    if a < b:
        break
    else:
        b *= 2

    k -= 1

while(k):
    if b < c:
        break
    else:
        c *= 2

    k -= 1

if a < b and b < c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9180
#include <iostream>

int main()
{
    int A, B, C, D;
    std::cin >> A >> B >> C >> D;

    int until_first_die = (A + D - 1) / D;
    int until_second_die = (C + B - 1) / B;

    if (until_first_die >= until_second_die) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0) return 0;
    vector<int> h(n),w(m),rh(n+1),rw(m+1),hh(n*(n+1)/2),ww(m*(m+1)/2);
    rh[0]=rw[0]=0;
    for(int i=0;i<n;i++){
      cin >> h[i];
      rh[i+1]=rh[i]+h[i];
    }
    int now=0;
    for(int i=0;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        hh[now]=rh[j]-rh[i];
        now++;
      }
    }
    for(int i=0;i<m;i++){
      cin >> w[i];
      rw[i+1]=rw[i]+w[i];
    }
    now=0;
    for(int i=0;i<=m;i++){
      for(int j=i+1;j<=m;j++){
        ww[now]=rw[j]-rw[i];
        now++;
      }
    }
    sort(all(ww));
    LL ans=0;
    for(int i=0;i<n*(n+1)/2;i++){
      ans+=distance(lower_bound(all(ww),hh[i]),upper_bound(all(ww),hh[i]));
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 11848
#include <stdio.h>
int main(){
  int t,h,m,s;
  scanf("%d",&t);
  if(t>=0 && t<=86400){
    h=t/3600;
    s=t%60;
    m=(t-h*3600-s)/60;
    printf("%d:%d:%d\n",h,m,s);
  }else printf("");
  return 0;
}

Measured memory_bytes: 592
n = int(input())
D = [list(map(int, input().split())) for i in range(n)]
for i in range(2, n):
    if D[i-2][0] == D[i-2][1] and \
        D[i-1][0] == D[i-1][1] and \
            D[i][0] == D[i][1]:
                print('Yes')
                exit()
print('No')

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

int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='A'&&s[i+1]== 'B' &&s[i+2]== 'C' )cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3524
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let mut n: i64 = iter.next().unwrap().parse().unwrap();
    let k: i64 = iter.next().unwrap().parse().unwrap();

    // 0がでたら終了
    // 暫定Nと同じ値がでたら終了

    // 計算時間短縮の為、n/kの余りを計算
    n = n % k;

    let mut min_n: i64 = n;

    loop {
        let abs: i64 = (n - k).abs();
        if abs == 0 {
            min_n = abs;
            break;
        } else if abs == min_n {
            break;
        } else if abs < n {
            min_n = abs;
        }
        n = abs;
    }

    println!("{}", min_n);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
int main() {
    int A,B,C,D,E;

    cin >> A >> B >> C;
    D = A -B;
    E = C-D;
    if ( E <= 0){
      cout << 0 << endl;
    }
    else{
      cout << E <<endl;
    }
}





Measured memory_bytes: 256
def is_prime?(num)
  return false if num <= 1

  2.upto(Math.sqrt(num).floor) do |n|
    return false if num != n && num % n == 0
  end

  true
end

x = gets.to_i

loop do
  if is_prime?(x)
    puts x
    break
  end
  x += 1
end

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll H,W;
    cin >> H >> W;
    cin >> n;
    ll ret = n / max(H, W);
    if(n%max(H,W)>0)ret++;
                     cout
             << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
zmax=-float('inf')
zmin = float('inf')
wmax = -float('inf')
wmin = float('inf')

for _ in range(N):
    x,y=map(int,input().split())
    z=x+y
    w=x-y
    zmax = max(z,zmax)
    zmin = min(z,zmin)
    wmax = max(w,wmax)
    wmin = min(w,wmin)
print(max(zmax-zmin,wmax-wmin))


Measured memory_bytes: 9432
using System;
using System.Collections.Generic;
 
class Program {
  static void Main (string[] args) {
    string s = Console.ReadLine();
    string s1 = s.Substring(0, 2);
    string s2 = s.Substring(2);
    int i1 = (s1[0] != '0') ? int.Parse(s1) : int.Parse(s1[1].ToString());
    int i2 = (s2[0] != '0') ? int.Parse(s2) : int.Parse(s2[1].ToString());
    bool a = false;
    bool b = false;
    if (i1 >= 1 && i1 <= 12) {
      a = true;
    }
    if (i2 >= 1 && i2 <= 12) {
      b = true;
    }
    if (!a && !b) {
      Console.WriteLine("NA");
    } else if (a && b) {
      Console.WriteLine("AMBIGUOUS");
    } else if (a && !b) {
      Console.WriteLine("MMYY");
    } else if (!a && b) {
      Console.WriteLine("YYMM");
    }
  }
}


Measured memory_bytes: 13140
def f(ai):
    if ai % 2 == 0:
        return ai/2
    else:
        return 3*ai + 1
s = int(input())
a = [s]
for n in range(2,1000002):
    tmp = f(a[len(a)-1])
    if tmp in a:
        print(len(a)+1)
        exit()
    else:
        a.append(tmp)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int h, m; cin >> h >> m;
	vi bit(h);
	rep(i, m){
		int x, y; cin >> x >> y;
		bit[y] |= 1 << x;
	}
	vector<vi> dp(2, vi(1 << 4, -1));
	dp[0][bit[0]] = 0;
	
	int cur = 0, next = 1;
	rep(i, h - 1){
		fill(all(dp[next]), -1);
		rep(j, 1 << 4) if(dp[cur][j] >= 0){
			int nj = bit[i + 1];
			dp[next][nj] = max(dp[next][nj], dp[cur][j]);
			if(((j | nj) & 3) == 0){//0,1
				dp[next][nj | 3] = max(dp[next][nj | 3], dp[cur][j] + 1);
			}
			if(((j | nj) >> 1 & 3) == 0){//1,2
				dp[next][nj | 6] = max(dp[next][nj | 6], dp[cur][j] + 1);
			}
			if((j | nj) >> 2 == 0){//2,3
				dp[next][nj | 12] = max(dp[next][nj | 12], dp[cur][j] + 1);
			}
			if(j == 0 && nj == 0){//0-3
				dp[next][15] = max(dp[next][15], dp[cur][j] + 2);
			}
		}
		swap(cur, next);
	}
	cout << *max_element(all(dp[cur])) << endl;
	
	return 0;
}


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

int n, m;
vector<int> s[10];
int p[10];

int main() {
    int k;
    int ans = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> k;
        s[i].resize(k);
        for (int j = 0; j < k; j++) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for (int i = 0; i < m; i++) cin >> p[i];

    for (int bits = 0; bits < (1 << n); bits++) {
        bool ok = true;
        for (int i = 0; i < m; i++) {
            int cnt = 0;
            for (int j = 0; j < s[i].size(); j++) {
                if (bits & (1 << s[i][j])) cnt++;
            }
            if (cnt % 2 != p[i]) {
                ok = false;
                break;
            }
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
l, r = map(int, input().split())

r = min(r, l+673)
ans = 2018

for i in range(l, r+1, 1):
  for j in range(i+1, r+1, 1):
    x = i*j%2019
    ans = min(ans, x)

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#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 MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n, a, b;

	cin >> n >> a >> b;

	cout << min(n*a, b) << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	bool ans=!((s[0]==s[1])||(s[1]==s[2])||(s[2]==s[3]));
	cout<<(ans?"Good":"Bad")<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld unsigned long long int
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()

ll dp[100001];
ve<ll>ar(100001);

ll fun(ll n,ll k){
	if(n==0){
		return 0;
	}
	if(dp[n]==-1){
		dp[n]=abs(ar[n]-ar[n-1])+fun(n-1,k);
		for(ll i=1;i<k;i++)
			if(n>i){
				dp[n]=min(dp[n],abs(ar[n]-ar[n-i-1])+fun(n-i-1,k));
			}
			else{
				break;
			}
	}
	return dp[n];
}

	int main(){
		ios_base::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
		ll n,k;
		cin>>n>>k;
		lr(n){
			cin>>ar[i];
		}
		lr(100001){
			dp[i]=-1;
		}
		cout << fun(n-1,k) << "\n";
		return 0;
	}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll=long long;
const ll mod = 1e9 + 7;


template<class T>
T gcd(T a, T b)
{
  if(a && b) {
    return gcd(min(a, b), max(a, b) % min(a, b));
  } else {
    return a;
  }
}

template<class T>
T lcm(T a, T b)
{
  return a / gcd(a, b) * b;
}

ll power(ll base, ll exponent, ll module)
{
  if(exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if(exponent) {
    ll root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}

struct combination
{
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1)
  {
    fact[0] = 1;
    for(int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2, mod);
    for(int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll P(int n, int r)
  {
    if(r < 0 || n < r) return 0;
    return (fact[n] * inv[n - r] % mod);
  }
  ll C(int p, int q)
  {
    if(q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};

template<typename T>
void print_vec(vector<T>& v)
{
  for(const auto& e: v) {
    cout << e << " ";
  }
  cout << endl;
}
template<typename T>
void print_2dvec(vector<vector<T>>& m)
{
  for(const auto& v: m) {
    for(const auto& e: v) {
      cout << e << " ";
    }
    cout << endl;
  }
}


int main(int argc, char const* argv[])
{
  string a, b;

  cin >> a >> b;

  if (a < b) {
    for (int i = 0; i < stoi(b); i++) {
      cout << a;
    }
  } else {
    for (int i = 0; i < stoi(a); i++) {
      cout << b;
    }
  }
  cout << endl;

  return 0;
}


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

public class BinarySearch{
	public static void Main()
	{
		Console.ReadLine();
		var sList = ReadLineAndToIntList();
		Console.ReadLine();
		var tList = ReadLineAndToIntList();
	
		int count = 0;
	
		tList.ForEach(t =>
		{
			if(sList.BinarySearch(t) > -1) count++;
		});
		
		Console.WriteLine(count);
	}
	
	//??????????????????????????????
	public static List<int> ReadLineAndToIntList()
	{
		return Console.ReadLine().Split().Select (c => int.Parse(c)).ToList();
	}
}

Measured memory_bytes: 20644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=1e6+10;

int main(){
    int n,l;
    scanf("%d%d",&n,&l);
    int t=l*n+n*(n-1)/2;
    if(l+n-1<0)t-=l+n-1;
    else if(l>0)t-=l;
    printf("%d",t);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N;
	int d1,d2,d3,d4;
	scanf("%d",&N);
	d1=N/1000;
	d2=(N-1000*d1)/100;
	d3=(N-1000*d1-100*d2)/10;
	d4=(N-1000*d1-100*d2)%10;
	if((d1==d2&&d2==d3&&d3==d4)||(d1==d2&&d2==d3)||(d2==d3&&d3==d4)){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int noOfItems = in.nextInt();
		long W = in.nextLong();
		Item[] items = new Item[noOfItems];

		for (int k = 0; k < noOfItems; k++) {
			items[k] = new Item(in.nextLong(), in.nextInt());
		}

		int pSum = 0;
		for (Item x : items) {
			pSum += x.price;
		}
		
		Long[] dp = new Long[pSum + 1];
		for (int k = 0; k <= pSum; k++) {
			dp[k] = Long.MAX_VALUE;
		}
		dp[0] = 0L;

		for (int i = 0; i < items.length; i++) {
			for (int j = pSum; j >= items[i].price; j--) {
				if (dp[j - items[i].price] != Long.MAX_VALUE) {
					dp[j] = Math.min(dp[j], items[i].weight + dp[j - items[i].price]);
				}

			}
		}
		int ans = 0;
		for (int k = 0; k <= pSum; k++) {
			if (dp[k] <= W) {
				ans = Math.max(ans, k);
			}

		}
		System.out.println(ans);
	}

	static class Item {
		Long weight;
		int price;

		public Item(Long w, int p) {
			this.weight = w;
			this.price = p;
		}

	}
}


Measured memory_bytes: 58272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxn=2e5+5;
ll n,a[maxn],h[maxn],dp[maxn];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,1,n+1) cin>>h[i];
    rep(i,1,n+1) cin>>a[i];
    auto cmp=[&](ll i, ll j){return h[i]<h[j];};
    set<ll,decltype(cmp)> bst(cmp);
    bst.insert(0);
    rep(i,1,n+1) {
        auto l=--bst.lower_bound(i);
        dp[i]=dp[*l++]+a[i];
        auto r=l; while(r!=bst.end() && dp[*r]<=dp[i]) r++;
        bst.erase(l,r);
        bst.insert(i);
    }
    ll ans=0;
    rep(i,1,n+1) ans=max(ans, dp[i]);
    cout<<ans<<"\n";
}


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

int main(){
    string s,t;
    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  
  int count = 0;
  for(int i = 0; i <= N/R; i++) {
      for(int j = 0; j <= N/G; j++) {
          int k = (N - i*R - j*G) / B;
          if(k < 0)
              break;
          if(i*R + j*G + k*B == N)
              count++;
      }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
INF = 0x7fffffff

def prim(g, n)
  d = Array.new(n, INF)
  pi = Array.new(n, -1)
  color = Array.new(n, 0)
  
  d[0] = 0  
  sum = 0
  loop do
    u = -1
    mincost = INF
    (0...n).each do |i|
      if mincost > d[i] && color[i] != 2
        u = i
        mincost  = d[i]
      end
    end
    break if u == -1
    color[u] = 2
    
    (0...n).each do |i|
      if color[i] != 2 && d[i] > g[u][i] && g[u][i] != INF
          d[i] = g[u][i]
          pi[i] = u
          color[i] = 1
      end
    end
  end
  (0...n).each do |j|
    sum += g[j][pi[j]] unless pi[j] == -1
  end
  return sum
end

n = gets.to_i
g = Array.new(n) { Array.new(n) }

(0...n).each do |i|
  g[i] = gets.split.map(&:to_i)
  (0...n).each do |j|
    g[i][j] = INF if g[i][j] == -1
  end
end
puts prim(g, n)

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

using namespace std;

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

	cin >> a >> b >> c;

	set< int > st;

	st.insert(a);
	st.insert(b);
	st.insert(c);

	cout << (st.size() == 2 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
while True:
	num=input().split()
	h=int(num[0])
	w=int(num[1])
	if h==0 and w==0:
		break
	else:
		print('#'*w)
		for i in range(h-2):
			print('#'+('.'*(w-2))+'#')
		print('#'*w )
		print('')


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

int ori[3], head, tail, que[10000010][4], ans;
bool vis[60][60][60];

int main() {
	scanf("%d%d%d", &ori[0], &ori[1], &ori[2]);
	sort(ori, ori + 3, greater<int>());
	que[0][0] = ori[0]; que[0][1] = ori[1]; que[0][2] = ori[2]; que[0][3] = 0;
	while (head <= tail) {
        register int aa = que[head][0], bb = que[head][1], cc = que[head][2], dd = que[head++][3];
        if (vis[aa][bb][cc])
			continue;
		vis[aa][bb][cc] = 1;
        if (aa == bb && bb == cc) {
			ans = dd;
			break;
        }
        que[++tail][0] = aa + 1; que[tail][1] = bb + 1; que[tail][2] = cc; que[tail][3] = dd + 1;
        que[++tail][0] = aa + 1; que[tail][1] = bb; que[tail][2] = cc + 1; que[tail][3] = dd + 1;
        que[++tail][0] = aa; que[tail][1] = bb + 1; que[tail][2] = cc + 1; que[tail][3] = dd + 1;
        que[++tail][0] = aa; que[tail][1] = bb + 2; que[tail][2] = cc; que[tail][3] = dd + 1;
        que[++tail][0] = aa; que[tail][1] = bb; que[tail][2] = cc + 2; que[tail][3] = dd + 1;
	}
	printf("%d", ans);
	return 0;
}

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

using namespace std;

const int N = 1e5;
int n, stones[N];
int memo[N];

int jumps(int ind) {
    if (ind == (n - 1)) return 0;
    if (ind >= n) return INT_MAX;

    if (memo[ind] != -1) return memo[ind];

    int oneJump = abs(stones[ind] - stones[ind+1]) + jumps(ind+1);
    int twoJumps = INT_MAX;

    if (ind + 2 < n) {
        twoJumps = abs(stones[ind] - stones[ind+2]) + jumps(ind+2);
    }

    return memo[ind] = min(oneJump, twoJumps);
}


int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif 

    memset(memo, -1, sizeof(memo));
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> stones[i];
    }

    // We will start from first stone
    cout << jumps(0) << endl;

    return 0;
}

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

int N, A, B, C;
vector<int> L;

int dfs(int i, int a, int b, int c){
    if (i==N){
        if (!a||!b||!c) return 1<<16;
        return abs(A-a)+abs(B-b)+abs(C-c) -30;
    }

    int resN = dfs(i+1, a, b, c);

    int resA = dfs(i+1, a+L[i], b, c) + 10;
    int resB = dfs(i+1, a, b+L[i], c) + 10;
    int resC = dfs(i+1, a, b, c+L[i]) + 10;

    int minval = resN;
    minval = min(minval, resA);
    minval = min(minval, resB);
    minval = min(minval, resC);
    return minval;
}

int main()
{
    cin >> N >> A>>B>>C;

    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        L.push_back(a);
    }

    cout << dfs(0,0,0,0) << endl;

   return 0;
}

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

#define MAX_N 100000

using namespace std;

int numbers[MAX_N + 5], L[MAX_N + 5];

int main()
{
    int n, i, length = 1;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &numbers[i]);
    }
    L[0] = numbers[0];
    for (i = 1; i < n; i++) {
        if (numbers[i] > L[length - 1]) {
            L[length++] = numbers[i];
        }
        else {
            *lower_bound(L, L + length, numbers[i]) = numbers[i];
        }
    }

    printf("%d\n", length);
}

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

int main(){
    int n;
    string c;
    cin>>n>>c;
    int w=0,r=0;
    for(int i=0;i<n;i++){
        if(c[i]=='R') r++;
    }
    int ans=1e9;
    for(int i=0;i<=n;i++){
        if(i-1>=0&&c[i-1]=='W') w++;
        else if(i-1>=0&&c[i-1]=='R') r--;
        ans=min(ans,max(w,r));
    }
    cout<<ans<<endl;
}

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

int main()
{
  int N, A, B, total = 0;
  cin >> N >> A >> B;

  for (int i = 0; i <= N; i++)
  {
    string str_i = to_string(i);
    int digits = str_i.size();
    int SumeDigits = 0;

    for (int i = 0; i < digits; i++)
      SumeDigits += str_i[i] - '0';

    if (A <= SumeDigits && B >= SumeDigits)
      total += i;
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 1000000
#define ll long long int
#define pr pair<ll,ll>
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define r(i,a,b) for(ll i=a;i>=b;i--)
#define ms(a,b) memset(a,b,sizeof(a));
using  namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll tt = 1;  
    //cin>>tt;
    while(tt--){
        string s,t;
        cin>>s>>t;
        cout<<t<<s;
        cout<<endl;
    }
    return 0;
}

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

namespace AtCoderSolve
{
    class Solve
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string s = Console.ReadLine();
            for(var i = 0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                {
                    Console.Write(s[i]);
                    continue;
                }
                continue;
            }
            Console.WriteLine();

            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 11232
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		HashMap<Character,Integer> map = new HashMap<Character,Integer>();
		int dupflag = 0;
		for(int i=0;i<N;i++) {
			char c = S.charAt(i);
			if(map.containsKey(c)) {
				map.put(c, map.get(c)+1);
				dupflag = 1;
			}
			else map.put(c, 1);
		}
		long M = (long) (Math.pow(10, 9)+7);
		long a = 1;
		long b = 1;
		int sum = 0;
		long mult = 1;
		for(int i=0;i<N;i++) {
			a = (a*2) % M;
		}
		if(dupflag == 1) {
			for(int x : map.values()) {
				if(x==1) continue;
				sum += x;
				mult = (mult * (x+1)) % M;
				for(int i=0;i<x;i++) {
					b = (b*2) % M;
				}
			}
			if(b-mult <0) b = M+b-mult;
			else b = b-mult;
			for(int i=0;i<N-sum;i++) {
				b = (b*2)%M;
			}
		}
		else b = 0;
		//System.out.println(a + " " + b);
		if(a-1-b<0) System.out.println(M+a-1-b);
		else System.out.println(a-1-b);
	}
	
}

Measured memory_bytes: 26316
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

int gcd(int a,int b)  {
	if (a%b==0)  return(b);
	else return(gcd(b,a%b));
}

int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    int N; cin >> N;
    int ans = N;
    if(N%2) ans*=2;
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int map[100][100];

int main(){
    int M,N;
    cin>>M>>N;
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++){
            char c;
            cin>>c;
            if(c=='-')continue;
            if(c=='o'){
                map[i][j]=1;
                if(j>0) map[i][j-1]=1;
                if(j!=N-1) map[i][j+1]=1;
            }
            if(c=='x'){
                for(int di=-1;di<2;di++){
                    for(int dj=-1;dj<2;dj++){
                        if(di+i>=0&&di+i<M&&dj+j>=0&&dj+j<N)
                            map[di+i][dj+j]=1;
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<M;i++){
        for(int j=0;j<N;j++){
            if(!map[i][j]) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  string S;

  cin >> N >> K;
  cin >> S;
  
  K--;
  if(S.at(K) == 'A'){
    S.at(K) = 'a';
  }else if(S.at(K) == 'B'){
    S.at(K) = 'b';
  }else if(S.at(K) == 'C'){
    S.at(K) = 'c';
  }

  cout << S <<endl;

  return 0;
}

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


#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define mp  make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a; i<=b;i++)
#define F first
#define S second
#define ccM 1000000007

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



int32_t main()
{
	fastio;
    ios::sync_with_stdio(0);
 #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
 #endif

	
	int n ;
	cin >>  n;

	switch ( n%10)

	{
		case 2 :
		case 4:
		case 5 :
		case 7 :
		case 9 :

		cout <<  "hon " << endl;
		break;

		case 0 :
        case 1 :
        case 6 :
        case 8 :
        cout << "pon " <<  endl;
        break ;

        case 3 :

        cout << "bon" << endl;
       

	}

return 0;

}

Measured memory_bytes: 3644
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int cmp(int x,int y)
{
	return x<y;
}
main()
{
	int a[5];
	int k;
	for(int i=0;i<5;i++)
	{
		cin>>a[i];
	}
	cin>>k;
	sort(a,a+5,cmp);
	if(a[4]-a[0]<=k) cout<<"Yay!";
	else cout<<":(";
	
return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{


public static void main(String[] args){
Scanner obj=new Scanner(System.in);
int n=obj.nextInt();
float o=0;
float ans=0;
for(int i=1;i<=n;i++){

if(i%2!=0){
o++;
}

}

ans=o/n;
System.out.println(ans);






}




}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define ADD(a, b) a = (a + b) % MOD

int H, W, N;
int sr, sc;
string S, T;
vector<int> mv_h, wh_h;
vector<int> mv_w, wh_w;

bool stay(int len, int start, vector<int> mv, vector<int> wh) {
  int mn = 0, mx = len - 1;
  RREP(i, mv.size()) {
    if (wh[i]) {  // 青木君のターン
      if (mv[i] == -1)
        mx = min(len - 1, mx + 1);
      else
        mn = max(0, mn - 1);
    } else {  // 高橋君のターン
      if (mv[i] == -1)
        mn++;
      else
        mx--;
    }
    if (mn > mx) return false;
  }
  return mn <= start && start <= mx;
}

int main() {
  cin >> H >> W >> N;
  cin >> sr >> sc;
  sr--, sc--;
  cin >> S >> T;
  REP(i, N) {
    if (S[i] == 'U') {
      mv_h.push_back(-1);
      wh_h.push_back(0);
    }
    if (S[i] == 'D') {
      mv_h.push_back(1);
      wh_h.push_back(0);
    }
    if (T[i] == 'U') {
      mv_h.push_back(-1);
      wh_h.push_back(1);
    }
    if (T[i] == 'D') {
      mv_h.push_back(1);
      wh_h.push_back(1);
    }
  }
  REP(i, N) {
    if (S[i] == 'L') {
      mv_w.push_back(-1);
      wh_w.push_back(0);
    }
    if (S[i] == 'R') {
      mv_w.push_back(1);
      wh_w.push_back(0);
    }
    if (T[i] == 'L') {
      mv_w.push_back(-1);
      wh_w.push_back(1);
    }
    if (T[i] == 'R') {
      mv_w.push_back(1);
      wh_w.push_back(1);
    }
  }
  if (stay(H, sr, mv_h, wh_h) && stay(W, sc, mv_w, wh_w))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(M),B(M),C(N,0);
  for(int i=0;i<M;i++){
    cin >> A.at(i) >> B.at(i);
    C.at(A.at(i)-1)++;
    C.at(B.at(i)-1)++;
  }
  for(int i=0;i<N;i++){
    cout << C.at(i) << endl;
  }
}

Measured memory_bytes: 256
import math
n = int(input())
s = (-1+math.sqrt(1+8*n))/2
if (int(s)!=s):
    print("No")
else:
    print("Yes")
    s = int(s)
    print(s+1)
    A = []
    w = 1
    for i in range(s+1):
        print(s, end=" ")
        for j in range(len(A)):
            print (A[j][i-j-1], end=" ")
        A.append([])
        for j in range(s-len(A)+1):
            print(w, end=" ")
            A[i].append(w)
            w+=1
        print()

Measured memory_bytes: 8504
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
	fastio();
	int n;
	cin>>n;
	int k;
	cin>>k;
	swap(k,n);
	int ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	int mi=k;
	int ans=k;
	for(int i=0;i<n;i++)
	{
		ans=min(ans,k-(ar[(i+1)%n]-ar[i]+k)%k);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define ll              long long 
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define gcd(m,n)        __gcd(m,n)   
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}


template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template<typename... Args>
  Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
  }
};


#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
 
//////////////////////////////code//////////////////////////////

int32_t main()
{
  fast();
  
  string s;
  cin>>s;
  int n=s.size();
  
  int dp[2019]={0},temp[2019]={0};
  int ans=0;
  
  for(int i=0;i<n;i++)
  {  
    temp[s[i]-'0']++;
    
    for(int j=0;j<2019;j++)
    {
    	int curr = (j*10+s[i]-'0')%2019;
    	
    	temp[curr]+=dp[j];
    }
    
    for(int j=0;j<2019;j++)
    dp[j]=temp[j];
    
    memset(temp,0,sizeof(temp));
    
    ans+=dp[0];
    
   }
  
  cout<<ans;
  

}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t[2], a[2], b[2];cin>>t[0]>>t[1]>>a[0]>>a[1]>>b[0]>>b[1];
    if (t[0]*a[0]+t[1]*a[1] == t[0]*b[0] + t[1]*b[1]) {
        cout << "infinity" << endl;
    } else if (a[0] > b[0] && t[0]*a[0]+t[1]*a[1] > t[0]*b[0]+t[1]*b[1]
            || b[0] > a[0] && t[0]*a[0]+t[1]*a[1] < t[0]*b[0]+t[1]*b[1]) {
        cout << 0 << endl;
    } else {
        ll diff = abs(t[0]*a[0]+t[1]*a[1] - (t[0]*b[0]+t[1]*b[1]));
        ll diff1 = abs(a[0]-b[0]) * t[0];
        DEBUG{
            cout << diff << " " << diff1 << endl;
        }
        if (diff1%diff==0) {
            cout << diff1/diff * 2  << endl;
        } else{
        cout << diff1 / diff * 2 + 1 << endl;

        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 998244353;
const ld PI = acosl(-1);

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

    int N, S;
    cin >> N >> S;

    vector<vector<ll>> dp(N + 1, vector<ll>(S + 1));
    dp[0][0] = 1;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        for (int j = 0; j <= S; ++j) {
            dp[i + 1][j] += dp[i][j];
            if (j >= A)
                dp[i + 1][j] += dp[i][j - A];
            dp[i + 1][j] %= MOD;
        }
        dp[i + 1][0]++;
    }

    ll ans = 0;
    for (int i = 0; i <= N; ++i)
        ans += dp[i][S];
    cout << ans % MOD << endl;

    return 0;
}


Measured memory_bytes: 73656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll INF = 1e15;
const ll MAX_MONEY = 2500;
ll n, m, s;
ll C[55], D[55];
vector<vector<ll>> g[55];

//(idx, time, money)
//始点sとした最短距離を求める O((V+E)logV)
vector<vector<ll>> dijkstra(ll s) {
  vector<vector<ll>> d(n, vector<ll>(MAX_MONEY + 1, INF));
  priority_queue<vector<ll>, vector<vector<ll>>,
                 function<bool(vector<ll>, vector<ll>)>>
      pq([&](vector<ll> a, vector<ll> b) { return a[1] > b[1]; });
  vector<vector<bool>> fixed(n, vector<bool>(MAX_MONEY, false));

  d[0][s] = 0;
  pq.push({0, 0, s});
  while (!pq.empty()) {
    vector<ll> f = pq.top();
    pq.pop();
    ll cv = f[0], cd = f[1], cm = f[2];
    fixed[cv][cm] = true;
    if (d[cv][cm] < cd) continue;
    FOREACH(p, g[cv]) {
      ll nv = p[0];
      ll wgt = p[1];
      ll money = p[2];
      ll nm = cm - money;
      if (nm < 0 || fixed[nv][nm]) continue;
      if (d[nv][nm] <= d[cv][cm] + wgt) continue;
      d[nv][nm] = d[cv][cm] + wgt;
      pq.push({nv, d[nv][nm], nm});
    }
    // 両替
    ll nm = cm + C[cv];
    if (nm > MAX_MONEY || fixed[cv][nm]) {
      continue;
    }
    ll nd = cd + D[cv];
    if (d[cv][nm] <= nd) {
      continue;
    }
    d[cv][nm] = nd;
    pq.push({cv, nd, nm});
  }
  return d;
}

int main() {
  cin >> n >> m >> s;
  s = min(s, MAX_MONEY);
  REP(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    g[u].push_back({v, b, a});
    g[v].push_back({u, b, a});
  }
  REP(i, n) { cin >> C[i] >> D[i]; }
  auto d = dijkstra(s);

  // REP(i, n) {
  //   REP(j, 5) { cout << d[i][j] << " \n"[j == 4]; }
  // }

  FOR(i, 1, n) {
    ll ans = INF;
    REP(j, MAX_MONEY + 1) { ans = min(ans, d[i][j]); }
    cout << ans << endl;
  }
}

Measured memory_bytes: 9296
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

a,b,c,d = map(int, input().split())

while True:
    c -= b
    if c <= 0:
        print('Yes')
        exit()
    a -= d
    if a <= 0:
        print('No')
        exit()


Measured memory_bytes: 9104