akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int K=scan.nextInt();
		int total=0;
		for(int i=1;i<=K;i++){
			for(int j=1;j<=K;j++){
				for(int k=1;k<=K;k++){
					int min=Math.min(Math.min(i,j),Math.min(j,k));
					int gcd=1;
					for(int l=1;l<=min;l++){
						if(i%l==0&&j%l==0&&k%l==0){
							gcd=l;
						}
					}
					total+=gcd;
				}
			}
		}
		System.out.println(total);

	}

}


Measured memory_bytes: 35892
N = int(input())
A = [[0] + list(map(int, input().split())) + [0] for _ in range(2)]

R1 = [0] * (N+1)
R2 = [0] * (N+2)

for i in range(1, N+1):
  R1[i] = R1[i-1]+A[0][i]
  R2[N-i+1] = R2[N-i+2]+A[1][N-i+1]

ans = 0
for i in range(1, N+1):
  ans = max(ans, R1[i]+R2[i])
print(ans)


Measured memory_bytes: 3064
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b; cin >> a >> b;
    ll c,d; cin >> c >> d;
    cout << min(a, b) + min(c, d) << "\n";
}

Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const LL mod=1e9+7;
int n,m;
LL dp[305][305][305];
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	return x*f;}
int main()
{
//	freopen("Road of the King.in","r",stdin);
	n=read(); m=read();
	dp[0][1][1]=1;
	for(RG int i=0;i<m;i++)
	 for(RG int j=1;j<=n;j++)
	  for(RG int k=1;k<=j;k++)
	  {
			(dp[i+1][j+1][k]+=dp[i][j][k]*(n-j))%=mod;
			(dp[i+1][j][k]+=dp[i][j][k]*(j-k))%=mod;
			(dp[i+1][j][j]+=dp[i][j][k]*k)%=mod;
	  }
	printf("%lld\n",dp[m][n][n]);
	return 0;
}

Measured memory_bytes: 218624
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long long int N,H,x,y,ans=0;
    vector<long long int> a,b;
    cin >> N >> H;
    while(N--){
        cin >> x >> y;
        a.push_back(x);
        b.push_back(y);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int i= b.size()-1;
    int j = a.size()-1;
    while(b[i]>=a[j]&&i>=0){
        if(H<=0) break;
        H-=b[i];
        ans++;
        i--;
    }
    if(H>0){
        if((H%a[j])!=0)   ans+=((H/a[j])+1);
        else ans+=(H/a[j]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2036
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=200*1000;
int a[L];
int b[L];
int s[L];
int main() {
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	for(int i=0;i<N;i++){
		cin >> b[i];
	}
	int r=0;
	for(int p=0;p<29;p++){
		int u=1<<p;
		for(int i=0;i<N;i++){
			s[i]=a[i]%(2*u);
		}
		sort(s,s+N);
		int c=0;
		for(int i=0;i<N;i++){
			int v=b[i]%(2*u);
			int z=lower_bound(s,s+N,2*u-v)-lower_bound(s,s+N,u-v);
			int y=lower_bound(s,s+N,4*u-v)-lower_bound(s,s+N,3*u-v);
			/*
			if(p==3){
				cerr << v << ": " << z << ", " << y << endl;
			}
			*/
			c+=z+y;
			c%=2;
		}
		//cerr << u << ", " << c << endl;
		r+=c%2*u;
	}
	cout << r << endl;


	return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
int n,m;
string s[505];
int sy,sx,ey,ex;
struct edge{
    int to,cap,rev;
};
vector<edge> adj[505];
int level[505],iter[505];
void bfs(int s){
    memset(level, -1,sizeof(level));
    queue<int> q; q.push(s); level[s]=0;
    while(!q.empty()){
        int here = q.front(); q.pop();
        for(int i=0;i<adj[here].size();i++){
            edge &e =adj[here][i];
            if(e.cap > 0){
                if(level[e.to] == -1){
                    level[e.to] = level[here]+1;
                    q.push(e.to);
                }
            }
        }
    }
}
int dfs(int t,int here,int f){
    if(t == here)return f;
    for(int &i=iter[here];i<adj[here].size();i++){
        edge & e=adj[here][i];
        if(e.cap > 0 && level[e.to] > level[here]){
            int d =dfs(t,e.to,min(f,e.cap));
            if(d>0){
                e.cap-=d; adj[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int maxFlow(int source,int sink){
    int f=0;
    while(true){
        bfs(source);
        if(level[sink]==-1)return f;
        int r=1;
        memset(iter,0,sizeof(iter));
        while(r){
            r = dfs(sink,source,1e9);
            f+=r;
        }
    }
}
void addEdge(int from,int to,int cap){
    adj[from].push_back({to,cap,(int)adj[to].size()});
    adj[to].push_back({from,0,(int)adj[from].size()-1});
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int source = n+m+5; int sink=source+1;
    for(int i=0;i<n;i++)for(int j=0;j<m;j++){
        if(s[i][j] == 'S'){
            addEdge(source,i,1e9);
            addEdge(i,j+n,1e9);
            addEdge(j+n,i,1e9);
         //   addEdge(source,j+n,1e9);
        }
        else if(s[i][j]=='T'){
           // addEdge(i,sink,1e9);
            addEdge(j+n,sink,1e9);
            addEdge(i,j+n,1e9);
            addEdge(j+n,i,1e9);
        }
        else if(s[i][j]=='o'){
            addEdge(i,j+n,1);
            addEdge(j+n,i,1);
        }
    }
    int min_cut = maxFlow(source,sink);
    if(min_cut>=1e9)min_cut=-1;
    cout<<min_cut;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >>m;
  int s[m];
  int c[m];
  int ans[n]={1};
  if(n==1){
    ans[0]=0;
  }
  rep(i,m){
    cin >> s[i];
    cin >> c[i];
    if(ans[s[i]-1]==0||ans[s[i]-1]==c[i]){
      ans[s[i]-1]=c[i];
    }
    else if(ans[0]==1&&s[i]==1){
      ans[s[i]-1]=c[i];
    }
    else{
      cout << "-1" << endl;
      return 0;
    }
  }
  if(ans[0]==0&&n>1){
    cout << "-1" <<endl;
    return 0;
  }
  rep(i,n){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    int n,m;
    std::cin >> n>>m;
    std::cout << (n-1)*(m-1) << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int A, B;
	cin >> A >> B;

	if (B % A == 0)
	{
		cout << A + B;
	}
	else
	{
		cout << B - A;
	}

	return 0;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <algorithm>
using namespace std;
int N, W, w[101], v[101];
long long dp[101][100001];
int main() {
  scanf("%d %d", &N, &W);
  for(int i = 1; i <= N; i++) scanf("%d %d", &w[i], &v[i]);
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= W; j++) {
      if(j >= w[i]) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
      else dp[i][j] = dp[i-1][j];
    }
  }
  printf("%ld", dp[N][W]);
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 2e5+5, inf = 1e9+7;
int n, k, i, j;
int A[N];

class matrix
{
    public:
        int n;
        vector<vi> val;
        matrix(int n);
        matrix operator+(const matrix&) const;
        matrix operator-(const matrix&) const;
        matrix operator*(const matrix&) const;
        matrix& operator=(const matrix& b)
        {
            if(this!=&b)
            {
                val = b.val;
                n = b.n;
            }
            return *this;
        }
};

matrix::matrix(int x)
{
    n=x;
    val.resize(x);
    rep(i,0,x)
    val[i].resize(x);
}
matrix matrix::operator* (const matrix& b) const
{
    class matrix r(n);
    assert(this->n==b.n);
    for(int i=0;i<this->n;i++)
        for(int j=0;j<this->n;j++)
        {
            int res=0;
            for(int k=0;k<b.n;k++)
                res += this->val[i][k]*b.val[k][j]%inf;
            r.val[i][j] = res%inf;
        }
    return r;            
}


class matrix matpow(class matrix a, int n)
{
    if(n==1)
        return a;
    class matrix x = matpow(a,n/2);
    class matrix r = x*x;
    if(n%2==1)
        r=r*a;
    return r;            
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    cin>>n>>k;
    matrix m(n);
    rep(i, 0, n) rep(j, 0, n) cin>>m.val[i][j];
    m = matpow(m, k);
    rep(i, 0, n) rep(j, 0, n) ans+= m.val[i][j];
    cout<<ans%inf;
}

Measured memory_bytes: 1664
def in_rectangle(w,h,x,y,r):
    return (r <= x and x <= w-r and r <= y and y <= h-r)


if __name__ == "__main__":
    w,h,x,y,r = [int(x) for x in input().split()]
    if in_rectangle(w,h,x,y,r):
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 5604
#include<iostream>

using namespace std;

int main(){
	int n, m, x;
	int h[100][100];
	
	cin >> n >> m;
	
	for ( int i = 0; i < n; i++ ){
		for ( int j = 0; j < m; j++ ){
			cin >> x;
			h[i][j] = x;
		}
	}

	
	for ( int i = 0; i < n; i++ ){
		int sum = 0;
		for (int j = 0; j < m; j++ ){
			sum += h[i][j]; 
			cout << h[i][j] << " ";
		}
		cout << sum <<endl;
	}
	
	int total = 0;
	
	for ( int j = 0; j < m; j++ ){
		int sum = 0;
		for ( int i = 0; i < n; i++ ){
			sum += h[i][j];
		}
		total += sum;
		cout << sum << " ";
	}
	cout << total <<endl;
	
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef struct point
{
	int x,y,c;
}POINT,*PPOINT;
POINT a[200];
vector <POINT> vec;
bool x(const POINT & a,const POINT & b)
{
	return a.x<b.x;
}
bool y(const POINT & a,const POINT & b)
{
	return a.y<b.y;
}
int main()
{
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a[i].x,&a[i].y);
		a[i].c=0;
	}
	for(i=n;i<2*n;i++)
	{
		scanf("%d %d",&a[i].x,&a[i].y);
		a[i].c=1;
	}
	sort(a,a+2*n,x);
	for(i=0;i<2*n;i++)
	{
		if(a[i].c==0)
		{
			vec.insert(lower_bound(vec.begin(),vec.end(),a[i],y),a[i]);
		}
		else
		{
			if(vec.empty())
			{
				continue;
			}	
			vector<POINT>::iterator it;
			it=lower_bound(vec.begin(),vec.end(),a[i],y);
			if(it!=vec.begin())
			{
				ans++;
				vec.erase(--it);
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = 998244353; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
struct Combination {
    vector<ll> fact, ifact;
    Combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1; for (int i = 0; i < n; ++i) fact[i + 1] = fact[i] * (i + 1) % MOD;
        ifact[n] = mpow(fact[n], MOD - 2); for (int i = n; i > 0; --i) ifact[i - 1] = ifact[i] * i % MOD;
    }
    ll operator ()(int n, int k) { return k < 0 || k > n ? 0 : fact[n] * ifact[n - k] % MOD * ifact[k] % MOD; }
} C(1e3);
int dp[502][1 << 9], dp2[502][1 << 9];

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

    dp[0][0] = 1;
    for (int i = X; i >= 0; --i) {
        rep(i, 502) fill(dp2[i], dp2[i] + (1 << 9), 0);
        rep(j, N + 1) rep(k, 1 << 9) {
            dp2[j][k] = (dp2[j][k] + dp[j][k]) % MOD;
            dp2[j + 1][k ^ i] = (dp2[j + 1][k ^ i] + dp[j][k]) % MOD;
        }
        swap(dp, dp2);
    }

    ll ans = 0;
    for (int j = N % 2; j <= N; j += 2) {
        ans = (ans + dp[j][X] * C((N - j) / 2 + X, X)) % MOD;
    }
    write(ans);
}


Measured memory_bytes: 5244
#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

const int CMax = 100002;

int n, A[CMax];
string S;
long long k;

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

    n = S.length();

    for (int i = 0; i < n; i++) {
        if (S[i] != '1' || (long long)(i + 1) == k) {
            cout << S[i] << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
m = int(input())
lis = []
for i in range(m):
    lis.append(list(map(int, input().split())))
summ = sum(t)
for i in range(m):
    idx = lis[i][0] - 1
    val = lis[i][1]
    ans = summ + val - t[idx]
    print(ans)


Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var (t, x, y) = (0L, 0L, 0L);
            for (var i = 0; i < N; ++i)
            {
                var (nt, nx, ny) = Slice3<long>();
                var dxy = Abs(nx - x) + Abs(ny - y);
                var dt = nt - t;
                if (dxy <= dt && ((dt % 2) == (dxy % 2))) { }
                else
                {
                    WriteLine("No");
                    return;
                }
                (t, x, y) = (nt, nx, ny);
            }
            WriteLine("Yes");
        }
        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;

ll n,a[101010]={0},m;
ll dp[101010]={0},s[101010]={0};


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

    dp[0]=1;
    for(int i=0;i<m;++i){
        s[a[i]]=-1;
    }
    for(int i=0;i<n;++i){
        if(s[i+1]==0){
            dp[i+1]+=dp[i];
            dp[i+1]%=MOD;
        }
        if(s[i+2]==0){
            dp[i+2]+=dp[i];
            dp[i+2]%=MOD;
        }
    }

    cout<<dp[n]<<endl;

    return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int quantum = in.nextInt();
		
		Queue<String> names = new LinkedList<String>();
		Queue<Integer> times = new LinkedList<Integer>();
		
		for(int i = 0; i < num; i++) {
			names.add(in.next());
			times.add(in.nextInt());
		}
		
		int totTime = 0;
		Queue<String> resultNames = new LinkedList<String>();
		Queue<Integer> resultTimes = new LinkedList<Integer>();
		
		while(!names.isEmpty()) {
			
			int tempTime = times.remove();
			
			if(tempTime <= quantum) {
				
				totTime += tempTime;
				resultNames.add(names.remove());
				resultTimes.add(totTime);
				
			} else {
				
				totTime += quantum;
				names.add(names.remove());
				times.add(tempTime - quantum);
				
			}
		}
		
		for(int i = 0; i < num; i++) {
			
			System.out.println(resultNames.remove() + " " + resultTimes.remove());
			
		}
		
		in.close();
		
	}

}



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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N;
  cin >> N;

  ll ans = 1e13;
  for(ll i = 1; i * i <= N; i++){
    if(N % i == 0){
      chmin(ans, i + N/i-2);
    }
  }

  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 256
<?php
$S = str_split(trim(fgets(STDIN)));

$a = [];
$b = [];

$cnt = count($S);

for ($i = 0; $i <= $cnt - 1; $i++) {
    if ($i % 2 == 0) {
        $a[] = '1';
        $b[] = '0';
    } else {
        $a[] = '0';
        $b[] = '1';
    }
}

echo min(count(array_diff_assoc($S, $a)), count(array_diff_assoc($S, $b))) . "\n";


Measured memory_bytes: 24180
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a, b, c ,n = 0;
  cin >> a >> b >> c;
  n = a- b;
  if(c <= n){
    cout << "0\n";
    return 0;
  }
  cout << c - n << "\n";
}

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

const int MAX_N=1e3+10;

int L[2*MAX_N],N;
long long ans=0;

inline bool check(int a,int b,int c){
	if(a+b<=c) return false;
	if(a+c<=b) return false;
	if(b+c<=a) return false;
	return true;
}

inline void solve(int lft,int rgt){
	int low=rgt+1,high=N,ret=0;
	while(low<high){
		int mid=(low+high)/2;
		if(check(L[lft],L[rgt],L[mid])) ret=max(ret,mid),low=mid+1;
		else high=mid;
	}
	ans+=max(ret-rgt,0);
}

signed main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>N; for(int i=0;i<N;i++) cin>>L[i]; sort(L,L+N);
	for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) solve(i,j);
	cout<<ans<<endl;
	return 0;
}

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

#define endl '\n'

using namespace std;

int k;
void read()
{
    cin >> k;
}

void solve()
{
    queue <long long> q;
    for (int i = 1; i <= 9; i++)
        q.push(i);

    for (;;)
    {
        auto curr = q.front();
        q.pop();
        k--;

        if (k == 0)
        {
            cout << curr << endl;
            break;
        }

        int t = curr % 10;
        if (t > 0)
            q.push(curr * 10 + t - 1);

        q.push(curr * 10 + t);

        if (t < 9)
            q.push(curr * 10 + t + 1);
    }
}

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

    read();
    solve();
}


Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    int h,k;
    cin>>h>>k;
    char x[h][k];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<k;j++)
        {
            cin>>x[i][j];
        }
    }
     for(int i=0;i<h;i++)
    {
        for(int j=0;j<k;j++)
        {
            if(x[i][j]=='#')
                {
                    cout<< x[i][j];
                    continue;
                }
                int cnt=0;
                for(int di=-1;di<=1;di++)
                    {
                        for(int dj=-1;dj<=1;dj++)
                        {
                if( i+di>=0 && i+di<h && j+dj>=0 && j+dj<k && x[i+di][j+dj]=='#' )cnt++;
                        }
                    }
                cout<<cnt;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 26 18:32:31 JST 2020
 **/

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

signed main() {
    Int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    Int ans = 0;
    REP(i, n) {
        Int acc = 0;
        REP(c, 'a', 'z' + 1) {
            acc += std::find(s.begin(), s.begin() + i, c) != s.begin() + i &&
                   std::find(s.begin() + i, s.end(), c) != s.end();
        }
        chmax(ans, acc);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
class DoublyList

  class Elem
    attr_accessor :key, :prev, :post

    def initialize key, prev, post
      @key = key
      @prev = prev
      @post = post
    end

  end

  def initialize
    @head = Elem.new(nil, nil, nil)
    @head.prev = @head.post = @head
  end

  def insert x
    x_elem = Elem.new(x, @head, @head.post)
    @head.post.prev = x_elem if @head.post
    @head.post = x_elem
  end

  def query x
    target = @head
    begin
      target = target.post
      return target if target.key == x
    end while target.post.key != nil
  end

  def delete x
    target = query x
    return unless target
    target.prev.post = target.post
    target.post.prev = target.prev if target.post
  end

  def delete_first
    target = @head.post
    target.post.prev = @head
    @head.post = target.post
  end

  def delete_last
    target = @head.prev
    target.prev.post = @head
    target.post.prev = target.prev
  end

  def disp
    target = @head
    result = []
    begin
      target = target.post
      result << target.key
    end while target.post.key != nil
    puts result*' '
  end
end

dl = DoublyList.new
n = gets.to_i
n.times do
  command = gets.split
  case command[0]
  when "insert" then
    dl.insert command[1].to_i
  when "delete" then
    dl.delete command[1].to_i
  when "deleteFirst" then
    dl.delete_first
  when "deleteLast" then
    dl.delete_last
  end
end

dl.disp

Measured memory_bytes: 82252
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


void print_vec(vll a)
{
	cout << "start printing the vector\n";
	for (ll i = 0; i < a.size(); i++)
		cout << a[i] << " ";
	cout << "\n";
}
void print_mat(vector<vll> a)
{
	cout << "start printing the matrix\n";
	for (ll i = 0; i < a.size(); i++)
	{
		for (ll j = 0; j < a[i].size(); j++)
		{
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}
}

/******************************************
* NUMBER THEORY ;) *
******************************************/



ll powermod(ll x, ll y)
{
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}
ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i)
			res = (res * i) % mod;
		n /= mod;
	}
	res %= mod;
	return res;
}



void solve()
{
	ll n;
	cin >> n;
	string s;
	map<string , ll> vis;
	vis["AC"] = 0;
	vis["TLE"] = 0;
	vis["WA"] = 0;
	vis["RE"] = 0;
	vector<string> arr = {"AC", "WA",
	                      "TLE",
	                      "RE"
	                     } ;
	while (n--)
	{
		cin >> s;
		vis[s]++;
	}
	for (auto u : arr)
	{
		cout << u << " " << "x" << " " << vis[u] << "\n";
	}
}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin >> t;
	// while (t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 3664
K,N=map(int,input().split())
A=list(map(int,input().split()))
ans=K
for i in range(1,N-1):
  ans=min(ans,K-abs(A[i]-A[i-1]),K-abs(A[i-1]-A[i]),K-abs(A[i]-A[i+1]),K-abs(A[i+1]-A[i]))

ans=min(ans,K-K+abs(A[0]-A[-1]),K-abs(A[0]-A[1]))

ans=min(ans,K-abs(A[-1]-A[-2]),K-abs(K-A[-1]))

print(ans)

Measured memory_bytes: 26444
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                String str = s.substring(i, j);
                int cnt = 0;
                for (int k = 0; k < str.length(); k++) {
                    char ch = str.charAt(k);
                    if (!(ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T')) {
                        cnt = 0;
                        break;
                    }
                    cnt++;
                }
                ans = Math.max(ans, cnt);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Zp {
    const int p = 1000000007;
    ll r;
    void set(ll x) {
        if (x < 0) {
            x += (-x + p) / p * p;
        }
        r = x % p;
    }

public:
    Zp(ll x) { set(x); }
    Zp() { set(0); }

    Zp operator-() const { return Zp(-r); }
    Zp &operator=(ll y) {
        set(y);
        return *this;
    }
    Zp &operator=(const Zp &y) { return *this = y.r; }

    Zp &operator+=(ll y) {
        set(r + y);
        return *this;
    }
    Zp &operator-=(ll y) { return *this += -y; }
    Zp &operator*=(ll y) {
        set(r * y);
        return *this;
    }
    Zp &operator/=(ll y) { return *this *= inv(y); }
    Zp operator+(ll y) const { return Zp(r + y); }
    Zp operator-(ll y) const { return *this + (-y); }
    Zp operator*(ll y) const { return Zp(r * y); }
    Zp operator/(ll y) const { return *this * inv(y); }

    Zp &operator+=(const Zp &y) { return *this += y.r; }
    Zp &operator-=(const Zp &y) { return *this -= y.r; }
    Zp &operator*=(const Zp &y) { return *this *= y.r; }
    Zp &operator/=(const Zp &y) { return *this /= y.r; }
    Zp operator+(const Zp &y) const { return *this + y.r; }
    Zp operator-(const Zp &y) const { return *this - y.r; }
    Zp operator*(const Zp &y) const { return *this * y.r; }
    Zp operator/(const Zp &y) const { return *this / y.r; }

    Zp pow(int n) const {
        if (n == 0) return 1;
        if (n % 2) return *this * pow(n - 1);
        Zp tmp = pow(n / 2);
        return tmp * tmp;
    }
    Zp inv(int x) const { return Zp(x).pow(p - 2); }
    Zp inv() const { return inv(r); }

    ll get() const { return r; }

    friend istream &operator>>(istream &istr, Zp &x) {
        istr >> x.r;
        x.set(x.r);
        return istr;
    }
    friend ostream &operator<<(ostream &ostr, const Zp &x) {
        ostr << x.r;
        return ostr;
    }
};
class Comb {
    vector<Zp> fact, ifact;

public:
    Comb(int N) : fact(N + 1), ifact(N + 1) {
        fact[0] = 1;
        REP(i, N)
        fact[i + 1] = fact[i] * (i + 1);
        ifact[N] = fact[N].inv();
        REPR(i, N)
        ifact[i] = ifact[i + 1] * (i + 1);
    }
    Zp operator()(int n, int k) const {
        return fact[n] * ifact[n - k] * ifact[k];
    }
    Zp f(int k) const { return fact[k]; }
    Zp invf(int k) const { return ifact[k]; }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int m, n;
    cin >> m >> n;
    if (n % 2 == 0) m = -m;
    cout << Zp(m).pow(n) << endl;

    return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    ll ans = 0;
    while(N){
        N/=K;
        ans++;
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3620
#include<iostream>
int main(){
	int n;
	int a, b, c, d;
	int count;
	while (std::cin >> n){
		count = 0;
		for (a = 0; a < 10; a++){
			for (b = 0; b < 10; b++){
				for (c = 0; c < 10; c++){
					for (d = 0; d < 10; d++){
						if (a + b + c + d == n){
							count++;
							break;
						}
					}
				}
			}
		}
		std::cout << count << std::endl;
	}
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> P(N);
    rep (i, N) {
        cin >> P[i];
    }

    ll ans = 0;
    ll cnt = INF;
    rep (i, N) {
        cnt = min(cnt, P[i]);
        if (cnt == P[i]) {
            ans++;
        }
    }

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

Measured memory_bytes: 1920
w = str(input())
dic = {}
for s in w:
    dic.setdefault(s,0)
    dic[s] += 1
#print(dic)
isOK = True
for i in dic.values():
    if i % 2 != 0:
        isOK = False
        break
if isOK:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9004
def merge(A, left, mid, right):
    global cnt
    inf = 1000000001
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


cnt = 0
input()
A = list(map(int, input().split()))
merge_sort(A, 0, len(A))
print(*A)
print(cnt)

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

int main() {
    ll N, X, M;
    cin >> N >> X >> M;
    vector<ll> exist(M, -1);
    ll pos = N;
    ll ans = 0;
    while (exist[X] == -1 && pos >= 1) {
        exist[X] = pos;
        ans += X;
        X = (X*X)%M;
        pos--;
    }
    
    if (pos == 0) {
        cout << ans << endl;
        return 0;
    }
    
    ll periodsum = X;
    ll kari = X*X%M;
    while (kari != X) {
        periodsum += kari;
        kari = kari*kari%M;
    }
    
    
    ll period = exist[X]-pos;
    ans += (pos/period)*periodsum;
    pos %= period;
    while (pos > 0) {
        ans += X;
        X = X*X%M;
        pos--;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4044
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long int N,M,kakaku=0,ans=0;
    cin >> N >> M;
    vector<pair<long long int,long int>> P(N);

    rep(i,N){
        cin >> P[i].first >> P[i].second;
    }

    sort(P.begin(),P.end());

    for(int i=0; i<N; i++){
        while(P[i].second>0){
            kakaku+=P[i].first;
            P[i].second = P[i].second-1;
            ans++;
            if(ans>=M){
                break;
            }
        }
        if(ans >= M) break;
    }

    cout << kakaku<< endl;
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll n, k;
  cin >> n >> k;
  cout << min(n%k,abs(n%k-k)) << endl;
  return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> s(M + 1), c(M + 1), num(M + 1);
  for(int i = 1; i <= M; i++){
    cin >> s[i] >> c[i];
  }
  bool exist = true;
  for(int i = 1; i <= M; i++){
    if(N > 1 && s[i] == 1 && c[i] == 0) exist = false;
  }
  for(int i = 1; i <= M; i++){
    for(int j = 1; j <= M; j++){
      if(i != j){
        if(s[i] == s[j] && c[i] != c[j]) exist = false;
      }
    }
  }
  int ans = 0;
  if(!exist) cout << -1 << endl;
  if(exist){
    for(int i = 1; i <= M; i++){
      for(int j = 1; j <= M; j++){
        if(i != j && s[i] == s[j]){
          s[i] = -1;
        }
      }
    }
    for(int i = 1; i <= M; i++){
      if(s[i] != -1) ans += c[i]*pow(10, N - s[i]);
    }
    bool saigo = true;
    for(int i = 1; i <= M; i++){
      if(s[i] == 1) saigo = false;
    }
    if(saigo) ans += pow(10, N - 1);
    if(N == 1 && M == 0) ans = 0;
    cout << ans << endl;
  } 
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll x, a, b;

	cin >> x >> a >> b;

	if (a - b >= 0) {
		cout << "delicious" << endl;
	}
	else if (x + a - b >= 0) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
}

Measured memory_bytes: 256
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff = -1
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Measured memory_bytes: 9212
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <ctime>
#include <stdio.h>
#include <memory.h>
#include <sstream>
bool f1, f2, f3, f4;
int main()
{
	std::string s;
	std::cin >> s;
	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == 'E') f1 = true;
		if (s[i] == 'W') f2 = true;
		if (s[i] == 'N') f3 = true;
		if (s[i] == 'S') f4 = true;
	}
	if (f1 != f2 || f3 != f4) std::cout << "No";
	else std::cout << "Yes";
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
string s;
ll m[12]={1,10,100,1000,10000,100000,1000000,
10000000,100000000,1000000000,10000000000},ans;
bool add[12];
void dfs(int x,int res)
{
    if(x==s.size()-1)
    {
        ll num=0;
        int t=0;
        for(int i=x;!add[i]&&i>=0;i--)
            num+=(s[i]-'0')*m[t++];
        ans+=res+num;
        return ;
    }
    add[x]=0;
    dfs(x+1,res);
    ll num=0;
    int t=0;
    for(int i=x;!add[i]&&i>=0;i--)
        num+=(s[i]-'0')*m[t++];
    add[x]=1;
    dfs(x+1,res+num);
}
int main()
{
	cin>>s;
	dfs(0,0);
	cout<<ans;
}


Measured memory_bytes: 256
S = input()

ans_1 = 1 if S[0] == "A" else 0

count_c = 0
c_i = 0
for i in range(2, len(S)-1):
    if S[i] == "C":
        count_c += 1
        c_i = i


ans_2 = 1 if count_c == 1 else 0

check_str = S[1:c_i] + S[c_i+1:]
#print(check_str)
ans_3 = 1 if check_str.islower() == 1 else 0

#print(ans_1)
#print(ans_2)
#print(ans_3)
print( "AC" if ans_1 and ans_2 and ans_3 else "WA")


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  long ok = *max_element(A.begin(), A.end()), ng = 0;
    while (ok - ng > 1) {
      long mid = (ok + ng) / 2;
      auto f = [&](int mid) {
        int cut = 0;
        for (int i = 0; i < N; i++) {
          cut += (A.at(i) + mid - 1) / mid - 1;
        }
        return (cut <= K) ? true : false;
      };
      (f(mid)) ? ok = mid : ng = mid;
    }
  cout << ok << "\n";
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    cout << (C - min(A-B, C)) << endl;
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int,input().split()))
p = {}
for j in d:
    if j not in p:
        p[j] = 1
    else:
        p[j] += 1
for i in t:
    if i not in p or p[i] == 0:
        print("NO")
        exit()
    p[i] -= 1
print("YES")

Measured memory_bytes: 43976
def resolve():
    MOD = 10**9+7
    K = input()
    D = int(input())
    N = len(K)

    # dp[keta][D][smaler]
    dp = [[[0]*2 for _ in range(D)] for _ in range(N+1)]
    dp[0][0][0] = 1

    for i in range(N):
        num = int(K[i])
        for j in range(D):
            for smaller in range(2):
                for d in range(10):
                    ni = i+1
                    nsmaller = smaller
                    nj = (j+d)%D
                    if smaller == 0:
                        if d < num:
                            nsmaller = 1
                        if d > num:
                            continue
                    dp[ni][nj][nsmaller] += dp[i][j][smaller]
                    dp[ni][nj][nsmaller] %= MOD
    print((dp[N][0][1] + dp[N][0][0] - 1) % MOD)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 162700