akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//typedef
//------------------------------------------
template<class T> using v=vector<T>;
using VI = v<int>;
using VVI = v<v<int>>;
using VS = v<string>;
using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
using VLL = v<LL>;
using VVLL = v<VLL>;

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

//update
//------------------------------------------
template<class T>inline T updmax(T& target, T val) { return target = max(target, val); }
template<class T>inline T updmin(T& target, T val) { return target = min(target, val); }

const int N = 100005;
int a[N], b[N];
LL f(int mask, int n) {
	LL ret = 0;
	REP(i, n) ret += ((a[i] & mask) == a[i]) ? b[i] : 0;
	return ret;
}

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	REP(i, n)scanf("%d%d", &a[i], &b[i]);
	LL ret = f(k, n);
	REP(i, 31) if (k & (1 << i))updmax(ret, f((k & (~(1 << i))) | ((1 << i) - 1), n));
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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


struct comp {
	bool operator()(const pii &a, const pii &b) const{
		return a.first + a.second < b.first + b.second;
	}
};

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,k;
	cin >> n >> k;
	--k;
	vector<bool> taken(2*n);
	vector<pii> res;
	int _tar = 2*n + 1 + n/2;
	int _l = 1 + n/2;
	int l=_l,tar=2*n;
	while(l >= 1){
		res.emplace_back(l,tar);	
		--l,--tar;
	}
	rep(i,_l+1,n+1){
		res.emplace_back(i,i + n - _l);
	}
	sort(all(res), comp());
	rep(i,0,n){
		if(res[i].first + res[i].second + 2*k > i + 2*n + 1 + k){
			cout << -1 << '\n';
			return 0;
		}
	}
	rep(i,0,n){
		cout << res[i].first + k << ' ' << res[i].second + k << ' ' << 2*n + 1 + k + i<< '\n';
	}
}


Measured memory_bytes: 4280
#include<stdio.h>

int main()
{
	int H;
	int W;
	int iCount;
	int iCount1;
	int iCount2;
	int iPutNum=0;
	int iH[1000];
	int iW[1000];

	//Hの入力
	scanf("%d", &H);
	//Wの入力
	scanf("%d", &W);

	while(H != 0 || W != 0)
	{
		
		iH[iPutNum] = H;
		iW[iPutNum] = W;
		//Hの入力
		scanf("%d", &H);
		//Wの入力
		scanf("%d", &W);
		iPutNum++;

	}

	//長方形を書く部分
	for (iCount=0;iCount<iPutNum;iCount++) 
	{
		//縦のループ
		for (iCount1 = 0; iCount1 < iH[iCount]; iCount1++)
		{
			//横のループ
			for (iCount2 = 0; iCount2 < iW[iCount]; iCount2++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

}


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

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

int a[100];
vector<pair<int,int> > res;

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

    int n;
    cin >> n;
    int ind = 0;
    int absMax = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if(abs(absMax) <= abs(a[i]))
        {
            absMax = a[i];
            ind = i;
        }
    }

    for(int i = 1; i <= n; i++)
    {
        if(ind != i)
        {
            res.pb(mp(ind, i));
            a[i] += absMax;
        }
    }

    if(absMax >= 0)
    {
        int pref = a[1];
        for(int i = 2; i <= n; i++)
        {
            res.pb(mp(i-1, i));
            //a[i] += pref;
            //pref = a[i];
        }
    }
    else
    {
        int pref = a[n];
        for(int i = n-1; i >= 1; i--)
        {
            res.pb(mp(i+1, i));
            //a[i] += pref;
            //pref = a[i];
        }
    }
    cout << res.size() << "\n";
    for(int i = 0; i < res.size(); i++) cout << res[i].fi << " " << res[i].se << "\n";

    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    d = [[0] * 10 for _ in range(10)]
    for i in range(1, N + 1):
        s = str(i)
        h, t = int(s[0]), int(s[-1])
        if h * t == 0:
            continue
        d[h][t] += 1
    r = 0
    for h in range(10):
        for t in range(10):
            r += d[h][t] * d[t][h]
    print(r)


main()


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace  std;

struct StPnt
{
  double m_nx;
  double m_ny;

  StPnt() :
    m_nx(0), m_ny(0)
  { }
  StPnt(double nx, double ny) :
    m_nx(nx), m_ny(ny)
  { }

  ~StPnt() { }
};

void fnInput(int &rnRcSiz)
{
  cin >> rnRcSiz;
}

void fnKochCrv( const StPnt &cnroPnt1, const StPnt &cnroPnt2, vector<StPnt> &rvoRtnPnt)
{
  rvoRtnPnt[0] = cnroPnt1;
  rvoRtnPnt[1].m_nx = (2 * cnroPnt1.m_nx + cnroPnt2.m_nx) / 3;
  rvoRtnPnt[1].m_ny = (2 * cnroPnt1.m_ny + cnroPnt2.m_ny) / 3;
  rvoRtnPnt[3].m_nx = (cnroPnt1.m_nx + 2 * cnroPnt2.m_nx) / 3;
  rvoRtnPnt[3].m_ny = (cnroPnt1.m_ny + 2 * cnroPnt2.m_ny) / 3;

  rvoRtnPnt[2].m_nx =  (rvoRtnPnt[3].m_nx - rvoRtnPnt[1].m_nx) * cos(M_PI / 3) 
                     - (rvoRtnPnt[3].m_ny - rvoRtnPnt[1].m_ny) * sin(M_PI / 3);
  rvoRtnPnt[2].m_nx += rvoRtnPnt[1].m_nx;
  rvoRtnPnt[2].m_ny =  (rvoRtnPnt[3].m_nx - rvoRtnPnt[1].m_nx) * sin(M_PI / 3)
                     + (rvoRtnPnt[3].m_ny - rvoRtnPnt[1].m_ny) * cos(M_PI / 3);
  rvoRtnPnt[2].m_ny += rvoRtnPnt[1].m_ny;

  rvoRtnPnt[4] = cnroPnt2;
}

void fnKochCtl(int nRcSiz, vector<vector<StPnt>> &rvvoPnt)
{
  StPnt oPntB(0.0, 0.0);
  StPnt oPntE(100.0, 0.0);

  rvvoPnt.resize(7);
  rvvoPnt[0].clear();
  rvvoPnt[0].push_back(oPntB);
  rvvoPnt[0].push_back(oPntE);

  for (int nRc = 0; nRc < nRcSiz; nRc++)
  {
    rvvoPnt[nRc + 1].clear();
    rvvoPnt[nRc + 1].push_back(oPntB);
    for (int i = 0; i < rvvoPnt[nRc].size() - 1; i++)
    {
      StPnt oPnt1 = rvvoPnt[nRc][i];
      StPnt oPnt2 = rvvoPnt[nRc][i + 1];
      vector<StPnt> voRtnPnt(5);

      fnKochCrv(oPnt1, oPnt2, voRtnPnt);
      for (int j = 1; j < 5; j++)
        rvvoPnt[nRc + 1].push_back(voRtnPnt[j]);
    }
  }
}

void fnResult(int nRcSiz, const vector<vector<StPnt>> &cnrvvoPnt)
{
  for (int i = 0; i < cnrvvoPnt[nRcSiz].size(); i++)
    cout << cnrvvoPnt[nRcSiz][i].m_nx << " " << cnrvvoPnt[nRcSiz][i].m_ny << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(8);

  int nRcSiz;
  vector<vector<StPnt>> vvoPnt;

  fnInput(nRcSiz);
  fnKochCtl(nRcSiz, vvoPnt);

  fnResult(nRcSiz, vvoPnt);

  return 0;
}

Measured memory_bytes: 1388
#include<iostream>  
#include<cstring>  
#include<cstdio>
#include<cstdlib>
#include<algorithm>  
using namespace std;  
#define ll long long

int main()  
{  
  	
  	ll n,m,i;
  	scanf("%lld%lld",&n,&m);
  	if(n==1&&m==1)
  		printf("1\n");
  	else
  	if(n==1||m==1)
  		printf("%lld\n",n*m-2);
  	else
  	printf("%lld\n",n*m-n-n-m-m+4);
    return 0;  
}


Measured memory_bytes: 256
N,P = map(int, input().split())
S = input()


"""
たとえばSが 123456789 だとすると
3456 = (3456789 - 789) // 1000
と表せる。
これがPで割り切れる場合、基本的には 3456789 と 789 がPで割り切れるとよい。
これはPと 10**x が互いに素の場合。
なので、10**x とPが互いに素の場合は、
・S[l:]をPで割った時余りがXXXになるものが何個、という情報を、Sの右端から集めていく。ただし、
・あるindexのlのS[l:]を見ているときに、その部分をPで割って余りがKになるなら、そのlに対してlより右にあるrについて、
　S[r:]をPで割った余りがKになるようにrを選んでS[l:r]を作ると、Pで割り切れる数字が得られる。その時点でのmod P = Kの個数に対応する。
　ただし、rに何も選ばない場合（lから端までを数字にする場合）もあるので、これも考慮に入れる。

Pが10と互いに素でない場合は、2と5がありうる。
これについて、それぞれ末尾が2の倍数か5の倍数であれば割り切れるので、
Sを左から見ていって、その数字が見つかれば、そのindexをふくむ左の位置で数字を作ればPで割れる数字ができる
"""

ans = 0
if P in [2, 5]:
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i+1

else:
    mod_P = [0] * P
    mod_P[0] += 1
    
    # Sを右端から何個かまで見てできる数字をPで割ってできる余り。
    # 数字のまま持っておいて、都度mod P をとるとTLEになるので。
    # 3543 で　3543 % P = (3000 + 543) % P のような感じで右から左にSを見ていく
    curr = 0
    for i in range(N):
        curr = curr + int(S[N-1-i]) * pow(10, i, P)
        curr %= P
        ans += mod_P[curr]
        mod_P[curr] += 1

print(ans)

Measured memory_bytes: 41308
#include <bits/stdc++.h>
using namespace std;
void init(){
cin.tie(0);
cin.sync_with_stdio(0);}

int main(){
init();

int n,m;  long long res=0;
cin>>n>>m;
int arr[m];
for(int i=0;i<m;i++){
    cin>>arr[i];
    res +=arr[i];}
  if(n-res>=0)
        cout<<n-res<<"\n";
  else  cout<<-1<<"\n";

}









Measured memory_bytes: 3668
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mx = 1e7;
ll arr[mx + 7];
int main() {
    for (int i = 1; i <= mx; ++i)
    	for (int j = i; j <= mx; j += i)
    		++arr[j];
    for (int i = 1; i <= mx; ++i)
    	arr[i] *= i, arr[i] += arr[i - 1];

    int n;
    cin >> n;
    cout << arr[n] << endl;
}

Measured memory_bytes: 81756
n=int(input())

s="0"
def dfs(s):
    if int(s)>n:
        return 0
    ret = 1 if all(s.count(c) >0 for c in "753") else 0
    for c in "753":
        ret += dfs(s+c)
    return ret

print(dfs("0"))

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

int main(){
    int n, cnt = 0;
    int p[20];

    cin >> n;
    for(int i = 0; i < n; i++){ cin >> p[i];}
    for(int i = 1; i < n-1; i++){
        if(p[i-1] > p[i] && p[i+1] < p[i] ||
            p[i-1] < p[i] && p[i+1] > p[i]){
                cnt++;
            }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*
ID: aditya7
LANG: C++
TASK: beads
*/


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    scanf("%d", &n);
    vector<int>a(n);
    for(int i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    vector<int>dp(n);
    dp[0] = 0;
    dp[1] = abs(a[0]-a[1]);
//    long long ans = dp[1];
    for(int i = 2; i < n; ++i){
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout << dp[n-1] << endl;


    return 0;
}


Measured memory_bytes: 4076
#include <iostream>
#include <cstdio>
#include <string.h>

using namespace std;

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int h1(int key)
{
    return (key%M);
}

int h2(int key)
{
    return 1+(key%(M-1));
}

int getChar(char ch)
{

    if(ch=='A') return 1;
    else if(ch=='B') return 2;
    else if(ch=='C') return 3;
    else if(ch=='D') return 4;
    else return 0;
}

long long getKey(char str[])
{
    long long sum=0,p=1;
    for(int i=0;i<strlen(str);i++)
    {
        sum+=p*(getChar(str[i]));
        p*=5;
    }
    return sum;
}


int inser(char str[])
{
    int h;
    int key=getKey(str);
    for(int i=0;;i++)
    {
      h=(h1(key)+i*h2(key))%M;
      if(strcmp(H[h],str)==0) return 1;
      else if(strlen(H[h])==0)
      {
          strcpy(H[h],str);
          return 0;
      }
    }
    return 0;
}

int Find(char str[])
{
   int h;
   int key=getKey(str);
   for(int i=0;;i++)
   {
       h=(h1(key)+i*h2(key))%M;
       if(strcmp(H[h],str)==0) return 1;
       else if(strlen(H[h])==0) return 0;
   }
   return 0;
}

int main()
{
    int i,n,h;
    char str[L],com[7];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s %s",com,str);
        if(com[0]=='i') inser(str);
        else
        {
            if(Find(str)) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 17400
N = int(input())
Temperature, A_target = map(int, input().split())
Height = list(map(int, input().split()))
mini_temp = float('inf')
index = 0

for i in range(N):
    t = Temperature - 0.006 * Height[i]
    diff = abs(t - A_target)
    if (diff < mini_temp):
        index = i
        mini_temp = diff

print(index + 1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  int N; cin >> N;
  vector<vector<int> > G(N);
  G.resize(N);
  vector<P> vp;
  for(int i = 1; i < N; i++){
    int a, b; scanf("%d%d", &a, &b);
    G[a - 1].push_back(b - 1); G[b - 1].push_back(a - 1);
    vp.push_back(P(a - 1, b - 1));
  }
  map<P, int> MAP;
  int MAX_COLOR = 0;
  vector<int> used(N, 0), cs(N, 0);
  used[0] = 1;
  queue<int> que; que.push(0);
  while(que.size()){
    int v = que.front(); que.pop();
    int color = 1;
    for(int i = 0; i < G[v].size(); i++){
      int u = G[v][i];
      if(used[u] != 0) continue;
      if(color == cs[v]) color++;
      used[u] = color;
      cs[u] = color;
      MAP[P(u, v)] = color;
      MAP[P(v, u)] = color;
      color++;
      que.push(u);
    }
    MAX_COLOR = max(MAX_COLOR, int(G[v].size()));
  }
  cout << MAX_COLOR << '\n';
  for(auto p : vp) cout << MAP[p] << '\n';
}

Measured memory_bytes: 20084
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  set<char> al;
  for(char c='a'; c<='z'; c++) al.insert(c);

  string s;
  cin>>s;

  set<char> ss;
  ss.insert(s.begin(), s.end());

  if(al.size()==ss.size()) cout <<"None"<<endl;
  else {
    for(auto c='a'; c<='z'; c++) {
      if(ss.find(c)==ss.end()) {
        cout<<c<<endl;
        break;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

int main() {
  string t;
  cin>>t;
  
  rep(i,t.size()){
    if(t[i]=='?') cout<<'D';
    else cout<<t[i];
  }
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 3728
#!/usr/local/bin/python3

'''
Author: andyli
Time: 2020-06-24 21:10:25
'''

mod = 10**9 + 7

m = int(input())
n = len(input())
t = n+m

fac = [0]*(t+1)
ifac = [0]*(t+1)
pw = [0] * (t+1)
fac[0] = 1
for i in range(1, t+1):
    fac[i] = fac[i-1] * i % mod
ifac[t] = pow(fac[t], mod-2, mod)

for i in range(t-1, -1, -1):
    ifac[i] = ifac[i+1] * (i+1) % mod

pw[0] = 1
for i in range(1, t+1):
    pw[i] = pw[i-1] * 25 % mod

def C(n, m):
    return fac[n]*ifac[m]*ifac[n-m]%mod

ans=0
for i in range(n, t+1):
    ans = (ans + pw[t-i] * C(t, i)) % mod

print(ans)

Measured memory_bytes: 153932
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,k;
    cin >> n >> k;
    int A[n];
    REP(i,n){
        cin >> A[i];
        A[i] %= k;
    }

    int R[n+1];
    R[0] = 0;
    int tasu = 0;
    while(tasu <= n) tasu += k;
    REP(i,n){
        R[i+1] = R[i] + A[i];
        R[i+1] = (R[i+ 1] + tasu -1) % k;
    }
    int ans = 0;
    if(k > n + 1){
        map<int,int> M;
        REP(i,n+1) M[R[i]]++;
    itrfor(itr,M){
        ans += itr->se * (itr->se -1) / 2;
    }
    }
    else{
        int tmp[k] = {};
        int id = 0;
        while(id <= n){
            if(id - k >= 0){
                tmp[ R[id-k]] --;
            }
            ans += tmp[R[id]];
            tmp[R[id]]++;

            id ++;

        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  
  vector<int> v(N + 1);
  v[0] = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == '#') v[i + 1] = v[i] + 1;
    else v[i + 1] = v[i];
  }
  
  vector<int> w(N + 1);
  w[N] = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (S[i] == '.') w[i] = w[i + 1] + 1;
    else w[i] = w[i + 1];
  }

  int ans = N;
  for (int i = 0; i <= N; ++i) {
    ans = min(ans, v[i] + w[i]);
  }

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


Measured memory_bytes: 2180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			int price = Integer.parseInt(br.readLine());
			
			if(price == 0){
				break;
			}
			
			int[] result = new int[5001];
			result[200] = 380; result[400] = 760;
			result[300] = 550;
			result[500] = 850;
			result[100] = 10000000;
			for(int i = 600 ; i <= price ; i+= 100){
				int[] tmpArray = new int[6];
				Arrays.fill(tmpArray, Integer.MAX_VALUE);
				//A??§???????????????
				tmpArray[0] = result[i - 200] + 380;
				//B??§???????????????
				tmpArray[1] = result[i - 300] + 550;
				//C??§???????????????
//				if(result[i - 500] > 0){
				tmpArray[2] = result[i - 500] + 850;
//				}
				//A??§????????§??????
				if(i - 1000 >= 0){
					tmpArray[3] = result[i - 1000] + 1520;
				}
				//B??§????????§??????
				if(i - 1200 >= 0){
					tmpArray[4] = result[i - 1200] + 1870;
				}
				//C??§????????§??????
				if(i - 1500 >= 0){
					tmpArray[5] = result[i - 1500] + 2244;
				}
				
				result[i] = minInArray(tmpArray);
			}
			System.out.println(result[price]);
		}
	}
	
	static int minInArray(int[] array){
		int tmp = Integer.MAX_VALUE;
		
		for(int i = 0; i < array.length ; i++){
			if(tmp > array[i]){
				tmp = array[i];
			}
		}
		
		return tmp;
	}

}

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

public class Main {
  private static boolean isPalindromicNumber(int n) {
    char[] cs = ("" + n).toCharArray();
    return cs[0] == cs[4] && cs[1] == cs[3];
  }
  
  private static int solve(int a, int b) {
    int count = 0;
    for (int n = a; n <= b; n++) {
      if (isPalindromicNumber(n)) {
        count++;
      }
    }
    return count;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    out.println(solve(a, b));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 34132
from sys import stdin
import sys

x,n = [int(x) for x in stdin.readline().rstrip().split()]
p = [int(x) for x in stdin.readline().rstrip().split()]

for i in range(10**4):
    x1 = x-i
    x2 = x+i

    if x1 not in p:
        print (x1)
        sys.exit()

    if x2 not in p:
        print (x2)
        sys.exit()



Measured memory_bytes: 9112
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	total := 0
	if a > b {
		total += a
		a--
	} else {
		total += b
		b--
	}

	if a > b {
		total += a
		a--
	} else {
		total += b
		b--
	}
	fmt.Printf("%d", total)
}

Measured memory_bytes: 512
N,M = map(int, input().split())

red = [0]*(N+1)
red[1] = 1
ball = [1]*(N+1)
for _ in range(M):
  x,y = map(int, input().split())
  if ball[x] ==1 and red[x] == 1:
    red[x] = 0
    red[y] = 1
  elif red[x] == 1:
    red[y] = 1
  ball[x] -= 1
  ball[y] += 1
  
print(sum(red))

Measured memory_bytes: 4596
s = gets.chop
len = s.size()
bit_len = 1 << len
ans = 0
for b in 0..bit_len-1 do
    val = s[0]
    for i in 1..len-1 do
        if (1 << i) & b != 0 then
            val += "+"
        end
        val += s[i]
    end
    ans += eval val
end

p ans / 2

Measured memory_bytes: 1916
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int main() {

	LL n, k; cin >> n >> k;

	vector<LL> tb(20);

	LL t = 1;
	for (int i = 0; i < 20; i++) {
		tb[i] = t;
		t *= 2;
	}

	LL base = 1;
	LL basec = 0;
	while (base < k) {
		base *= 2;
		basec++;
	}

	LL ans = 0;
	for (int i = 1; i < n+1; i++) {

		if (i >= k)break;

		int tmp = 0;
		int x = i;
		while (x < k) {
			x *= 2;
			tmp++;
		}

		ans += tb[basec - tmp];
	}

	double ret = ((ans) / (double)tb[basec]) / (double)n;
	ret += max(n - k + 1, 0LL)/(double)n;

	cout << fixed << setprecision(12) << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	int n;
	int d, x;
	int a[100];
	scanf("%d %d %d", &n, &d, &x);
	REP(i, n) {
		scanf("%d", &a[i]);
	}
	int cnt = 0;
	REP(i, n) {
		cnt++;
		REPS(j, d) {
			if (j*a[i] + 1 <= d) {
				cnt++;
			}
			else {
				break;
			}
		}
	}
	PRINTD(cnt + x);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
//  int a, b, c, d, e, X, Y;
  int a, b, c;
  //  double  c;
//  long long  A[1000001]={};
 int  A[1000001][2]={};
  int  ans[100003]={};
  int  sum[100003]={};
  int  cnt_flag[100003]={};

  int  L[1003]={};


//  long long  a, b, c, d, X, Y;
  long long   d, X, Y;
  long long JPY;
  double BTC;
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  int flag=0;
//  int flag[10000003]={};
  int tmp=0;
//  int min=1000000;
  long long min=10000000001;
  int len=0;
  int cnt=0;
  int cnt0=0;
  int cnt1=0;
  int num=0;
//  double ans=0.0;
//  long long ans=0;
  int max=0;
//  int sum=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d%d%d", &a,&b, &c);
  
  if((a==b)&&(a==c)&&(b==c))  printf("Yes\n");
  else     printf("No\n");
/*    
    for(j=0;j<b;j++){
      if( i==A[j][0])
        ans[j]=-sum[i];
      else if(i==A[j][1])
        ans[j]=ans[j]+sum[i];
      printf("%d\n",ans[j]);
    }
    */

//  printf("%s\n",s);
//    else  
  
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;
    // char alp[26] = {'a', 'b', 'c', "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    string alp = "abcdefghijklmnopqrstuvwxyz";
    int alpI[26] = {0};
    for(int i = 0; i < S.length(); i++) {
        for(int j = 0; j < 26; j++) {
            // cout <<"S: " << S.at(i) << "alp:" << alp[j] << endl;
            if(S.at(i) == alp[j]) {
                alpI[j] += 1;
            }
        }
    }
    
    string out = "";
    for(int i = 0; i < 26; i++) {
        if(alpI[i] == 0) {
            out += alp[i];
            break;
        }
    }
    if(out == "") {
        cout << "None" << endl;
    }else {
        cout << out << endl;
    }

}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stack>
using namespace std;

int main(){
	int n,i,j,flag;
	char ch1[100],ch2[100];
	cin >> n;
	fgets(ch1,100,stdin);
	for(i = 0;i < n;i++){
		fgets(ch1,100,stdin);
		fgets(ch2,100,stdin);
		if(strlen(ch1) > 81 || strlen(ch2) > 81){
			cout << "overflow" << endl;
		}
		else {
			stack<int> st1,st2,sum;
			sum.push(0);
			for(j = 0;j < strlen(ch1);j++) if(ch1[j] != '\n') st1.push(ch1[j] - '0');
			for(j = 0;j < strlen(ch2);j++) if(ch2[j] != '\n') st2.push(ch2[j] - '0');
			while(!st1.empty() || !st2.empty()){
				if(st1.empty()) st1.push(0);
				if(st2.empty()) st2.push(0);
				flag = sum.top();
				sum.pop();
				sum.push((st1.top() + st2.top() + flag) % 10);
				sum.push((st1.top() + st2.top() + flag) / 10);
				st1.pop();
				st2.pop();
			}
			if(sum.top() == 0) sum.pop();
			if(sum.size() > 80) {
				cout << "overflow" << endl;
				continue;
			}
			while(!sum.empty()) {
				cout << sum.top();
				sum.pop();
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353

dp = [[0] * (s + 1) for _ in range(n + 1)]
ans = 0
for i in range(n):
    dp[i][0] += 1
    for j in range(s + 1):
        dp[i + 1][j] += dp[i][j]
        dp[i + 1][j] %= MOD
        if j + a[i] <= s:
            dp[i + 1][j + a[i]] += dp[i][j]
            dp[i + 1][j + a[i]] %= MOD
    ans += dp[i + 1][s]
    ans %= MOD

print(ans)

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

int main()
{
    long int A, B, N;
    cin >> A >> B >> N;
    long long MEM = 0;
    long long ANS = 0;
    long long x;
    long long x_2;
    if (N < B - 1)
    {
        x = N;
    }
    else
    {
        int NB = N / B;
        x = B * NB - 1;
        if (x + B <= N)
        {
            x += B;
        }
    }
    ANS = floor(A * x / B) - A * floor(x / B);
    cout << ANS << endl;
}


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

const int MOD = 1000000007;
int64_t dp[110000][2];
vector<int> edge[110000];

// 0 black
// 1 white

void dfs(int x, int last = -1) {
    dp[x][0] = dp[x][1] = 1;
    for (auto to : edge[x]) {
        if (to == last) continue;
        dfs(to, x);
        dp[x][1] = dp[x][1] * ((dp[to][0] + dp[to][1]) % MOD) % MOD;
        dp[x][0] = dp[x][0] * dp[to][1] % MOD;
    }
}

int main() {
    int n;
    cin >> n;
    rep(i,n-1) {
        int x, y;
        cin >> x >> y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    dfs(1);
    int64_t ans = (dp[1][0] + dp[1][1]) % MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
}

Measured memory_bytes: 14464
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  int t=0,x=0,y=0;
  int tt,xx,yy;
  rep(i,n){
    cin >> tt >> xx >> yy;
    int diss = abs(x-xx) + abs(y-yy);
    int time = tt-t;
    if(diss<=time&&diss%2==time%2){
      t=tt; x=xx; y=yy;
    }else{
      puts("No");
      return 0;
    }
  }

  puts("Yes");

}

Measured memory_bytes: 256
class Dice
  attr_accessor :faces

  # |T F L|
  # |B U R|
  def initialize(faces)
    top, front, right, left, back, bottom = faces
    @faces = [[top, bottom], [front, back], [left, right]]
  end

  def move(commands)
    commands.split('').each do |com|
      case com.upcase.to_sym
      when :E
        faces[0], faces[2] = faces[2], faces[0].reverse
      when :W
        faces[0], faces[2] = faces[2].reverse, faces[0]
      when :N
        faces[0], faces[1] = faces[1], faces[0].reverse
      when :S
        faces[0], faces[1] = faces[1].reverse, faces[0]
      end
    end
  end

  def method_missing(face)
    if %i(top bottom front back left right).include? face
      {
        top:    faces[0][0],
        bottom: faces[0][1],
        front:  faces[1][0],
        back:   faces[1][1],
        left:   faces[2][0],
        right:  faces[2][1]
      }[face]
    else
      super
    end
  end

  def clone
    self.class.new([top, front, right, left, back, bottom])
  end

  def info
    p({ T: top, F: front, R: right, L: left, U: back, B: bottom })
  end
end

$stdin = DATA if $stdin.eof?

dice = Dice.new(gets.split)

gets

patterns = (['N'] * 3 + ['E'] * 3)
ARGF.each_line do |line|
  top, front = line.split
  patterns.permutation do |command|
    test_dice = dice.clone
    command.each do |c|
      test_dice.move(c)
      if test_dice.top == top && test_dice.front == front
        puts test_dice.right
        break
      end
    end
    break if test_dice.top == top && test_dice.front == front
  end
end


__END__
1 2 3 4 5 6
3
6 5
1 3
3 2

Measured memory_bytes: 6560
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int W[120] = {}, sum1 = 0, sum2 = 0;
	int ans = INF;
	cin>>N;
	
	for(int i = 0; i < N; i++){
		cin>>W[i];
		sum2 += W[i];
	}
	
	for(int i = 0; i < N; i++){
		sum1 += W[i];
		sum2 -= W[i];
		
		ans = min(ans,abs(sum1-sum2));
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define INF 1000000000

signed main()
{
    int H, N; cin >> H >> N;
    vi A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    vi dp(H+1, INF);
    dp[0] = 0;
    rep(i, N) {
        rep(j, H+1) {
//            if (dp[j] != INF) {
                int dmg = min(H, j + A[i]);
                chmin(dp[dmg], dp[j] + B[i]);
//            }
        }
#if 0
        rep(j,H+1) {
            if (dp[j]==INF) {
                cout << "_____" << " ";
            } else {
                cout << setw(5)<<dp[j] << " ";
            }
            
        }
        cout << endl;
#endif
    }


    cout << dp[H] << endl;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
        sys.exit()
    else:
        print(0)
        sys.exit()

aa = a-1+(a-1)//x - (a-1)//c - (a-1)//d
bb = b+b//x - b//c - b//d
ans = bb-aa

print(ans)


Measured memory_bytes: 10192
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto K = RD;
	
	auto ans = N % K;
	ans = min(ans, K - ans);

	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 256
s=input()
t=input()
ss=[]
st=[]
for i in (s):
    ss.append(i)
for i in (t):
    st.append(i)
ss.sort()
st.sort(reverse=True)
ans='No'
#print(''.join(ss),''.join(st))
if ''.join(ss)<''.join(st):
    ans='Yes'

print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            printf("%dx%d=%d\n", i, j, i * j);
        }
    }
    return 0;
}

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

#define int long long

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

string K;
int D;
int dp[11111][2][111]; // dp[i桁目][未満フラグ][mod Dした値] = 総数

int rec(int digit, int smaller, int modD) {
  // 桁を超えたら終了
  if (digit >= K.size()) {
    return modD == 0;
  }

  // メモした値なら返す
  if (dp[digit][smaller][modD] != -1) {
    return dp[digit][smaller][modD];
  }

  int lim = (smaller ? 9 : K[digit] - '0'); // 上限値
  int ret = 0;
  for (int num = 0; num <= lim; num++) {
    int t = rec(digit + 1, smaller || (num < lim), (modD + num) % D);
    Add(ret, t);
  }

  return dp[digit][smaller][modD] = ret; // ここでメモ
}

signed main() {
  cin >> K >> D;

  // DPテーブルを初期化
  for (int i = 0; i < 11111; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 111; k++) {
        dp[i][j][k] = -1;
      }
    }
  }

  int ans = rec(0, 0, 0); // メモ化再帰に投げる
  Add(ans, -1LL); // 0になる場合の数を引く
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 20480
#include "bits/stdc++.h"
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }

  int ans=1;
  bool can=false,can2=false;
  for(int i=0;i<n-1;i++){
    if(!can){
      if(a[i]<a[i+1]){
        can2 = true;
      }else if(a[i]>a[i+1]){
        can2 = false;
      }else{
        continue;
      }
      can = true;
      continue;
    }
    if((a[i]>a[i+1] && can2 == true)||(a[i]<a[i+1] && can2 == false)){
      ans++;
      can = false;
    }
  }
  cout << ans;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
   ll N, Y;
   cin >> N >> Y;
   REP(i, N + 1){
      REP(j, N + 1 - i){
         if(10000 * i + 5000 * j + 1000 * (N - i - j) == Y){
            printf("%lld %lld %lld\n", i, j, N - i - j);
            return 0;
         }
      }
   }
   printf("-1 -1 -1\n");
   return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n == (n & (-n))) {
        cout << "No" << endl;
        return 0;
    }
    vector<pair<int, int>> edges;
    for (int i = 2; i < n; i += 2) {
        edges.push_back(make_pair(1, i));
        edges.push_back(make_pair(i, i+1));
        edges.push_back(make_pair(1, i+1 + n));
        edges.push_back(make_pair(i+1 + n, i + n));
    }
    edges.push_back(make_pair(3, 1 + n));
    // Special case when n is even
    if (n % 2 == 0) {
        edges.push_back(make_pair((n ^ (n & (-n))) + 1 + n, n));
        edges.push_back(make_pair(n & (-n), 2*n));
    }
    cout << "Yes" << endl;
    for (auto edge : edges) {
        cout << edge.first << " " << edge.second << "\n";
    }
    return 0;
}


Measured memory_bytes: 4080
n = int(input())
dic = {}
for i in range(n):
	a, b = input().split()
	a = a.zfill(5)  # キーを0埋め5桁
	if a in dic:
		dic[a] = dic[a] + int(b)
	else:
		dic[a] = int(b)

dic = sorted(dic.items())
# 出力部
for i in dic:
	print('{0} {1}'.format(i[0].replace('0', ''), i[1]))


Measured memory_bytes: 5620
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

class union_find():
    
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rank=[0]*(n+1)

    def find_root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.find_root(self.root[x])
            return self.root[x]

    def unite(self,x,y):
        x=self.find_root(x)
        y=self.find_root(y)

        if x==y:
            return 
        elif self.rank[x]>self.rank[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y

            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1

    def same(self,x,y):
        return self.find_root(x)==self.find_root(y)

    def cnt(self,x):
        return -self.root[self.find_root(x)]

n,m=map(int,input().split())
g=union_find(n)
ans=0
for _ in range(m):
    a,b=map(int,input().split())
    g.unite(a,b)


for i in range(1,n+1):
    ans=max(ans,g.cnt(i))
print(ans)

Measured memory_bytes: 14664
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    912 Hours of Solitude
    Quarantine_Day : 38
*/

#include<bits/stdc++.h>

using namespace std;

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

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 50005


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

    int kase; cin>>kase;
    int ans = 0;
    while(kase--){
        int x, y; cin>>x>>y;
        ans += y - x + 1;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256