akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define openfiles ifstream in("input.txt");ofstream out("output.txt");
#define faster ios_base::sync_with_stdio(false);cin.tie();cout.tie();
openfiles;
struct obj
{
    int h,p;
};
int n;
vector<obj> vec;
vector<vector<int> >dp;
const int inf=1000000000000000ll;
bool cmp(obj x,obj y)
{
    return x.h+x.p<y.h+y.p;
}

void init()
{
    faster;
    cin>>n;
    vec.resize(n);
    for(int i=0;i<n;i++)
        cin>>vec[i].h>>vec[i].p;
    sort(vec.begin(),vec.end(),cmp);
    dp.resize(n,vector<int>(n+1,inf));
    dp[0][0]=0;
    dp[0][1]=vec[0].p;
}


void lazyDP()
{
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(dp[i-1][j-1]>vec[i].h)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+vec[i].p);
        }
    }

//    if(pref>n||pref<0||pref<used-1||used<0)
//        return inf;
//    if(dp[pref][used]!=inf)
//        return dp[pref][used];
//    if(lazyDP(pref-1,used-1)>vec[pref].h)
//        dp[pref][used]=lazyDP(pref-1,used);
//    else
//        dp[pref][used]=min(lazyDP(pref-1,used),lazyDP(pref-1,used-1)+vec[pref].p);
//    return dp[pref][used];
}

signed main()
{
    init();
    lazyDP();
    for(int i=n;i>=0;i--)
    {
        if(dp[n-1][i]!=inf)
        {
            cout<<i;
            return 0;
        }
    }
//    for(int i=n;i>=0;i--)
//    {
//        if(lazyDP(n-1,i)!=inf)
//        {
//            cout<<i;
//            return 0;
//        }
//    }
//    cout<<0;
//    return 0;
}



















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

using namespace std;

int main() {
    string str;
    cin >> str;
    
    int ans=0;
    for(int i=1; i<str.size(); i++) {
        if(str[i]!=str[i-1]) ans++;
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll X;
    cin>>X;
    cout<< (ll)(X/500)*1000+(X%500)/5*5<<"\n";    

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 256
import sys

n=int(input())
list=[]
if n==1:
	print(1)
	sys.exit()
list.append(2)
list.append(1)
for i in range(2,87):
	list.append(list[i-1]+list[i-2])
	if n==i:
		print(list[-1])
		sys.exit()

Measured memory_bytes: 3060
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int N=2300000;

inline unsigned long xor128() {
	static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
	unsigned long t=(x^(x<<11));
	x=y; y=z; z=w;
	return (w=((w>>19)^t^(t>>8)));
}

int D,c[26],s[200000][26],t[200000],T[200000];
set<int>st[26];

int main(){
	scanf("%d",&D);
	for(int i=0;i<26;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	for(int i=0;i<D;i++){
		pair<int,int>mx={-1,-1};
		for(int j=0;j<26;j++){
			mx=max(mx,{s[i][j],j});
		}
		t[i]=mx.second;
		st[mx.second].insert(i);
	}
	for(int i=0;i<26;i++){
		st[i].insert(-1);
		st[i].insert(D);
	}
	for(int i=0;i<N;i++){
		int K=xor128()%D;
		pair<int,int>mx={-100000000,-1};
		auto it1=st[t[K]].find(K);
		auto it2=it1;
		it1--;
		auto it3=it2;
		it3++;
		int a=c[t[K]]*((*it3-*it1)*(*it3-*it1-1)/2-(*it3-*it2)*(*it3-*it2-1)/2-(*it2-*it1)*(*it2-*it1-1)/2);
		for(int j=0;j<26;j++){
			if(j==t[K])continue;
			auto it=st[j].lower_bound(K);
			auto jt=it;
			jt--;
			mx=max(mx,{s[K][j]-s[K][t[K]]+c[j]*((*it-*jt)*(*it-*jt-1)/2-(*it-K)*(*it-K-1)/2-(K-*jt)*(K-*jt-1)/2)-a,j});
		}
		if(mx.first>=0){
			st[t[K]].erase(it2);
			t[K]=mx.second;
			st[mx.second].insert(K);
		}
		else if(mx.first>=-(N-i)/300){
			st[t[K]].erase(it2);
			t[K]=mx.second;
			st[mx.second].insert(K);
		}
	}
	for(int i=0;i<D;i++){
		printf("%d\n",t[i]+1);
	}
}


Measured memory_bytes: 3904
using System;

class AtCoder{
	public static void Main(string[] args){
    	var Line = System.Console.ReadLine();
      	string[] ary = Line.Split(' ');
      	
      	int a = 0;
      	int b = 0;
      	foreach(string chr in ary){
        	if(chr=="5"){
            	a++;
            }else if(chr=="7"){
            	b++;
            }
        }
      	
      if(a==2 && b==1){
        Console.WriteLine("YES");
      }else{
      	Console.WriteLine("NO");
      }
    }
}

Measured memory_bytes: 11092
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cassert>
#include<random>
#include<fstream>
#include<chrono>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int          long long
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define rep(i,s,e)   for(int i=(s);i<=(e);i++)
#define brep(i,s,e)  for(int i=(s);i>=(e);i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define VR46         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);ifstream fin("ip.txt");ofstream fout("op.txt");
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25); // less_equal
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7;
const int INF = 0x3F3F3F3F3F3F3F3F;
ld EPS = 1e-12;

signed main()
{
    VR46 // GANDU TEST CASE BNALE
    // int t;cin>>t;rep(test,1,t)
    {
        int n, a, b;
        cin>>n>>a>>b;
        int x = n/(a+b);
        int r = n%(a+b);
        int ans = x*a;
        if( r<=a ) ans += r;
        else ans += a;
        cout<< ans <<endl;
    }
}

Measured memory_bytes: 256
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
const double  EPS= 1e-11 ;
typedef long long ll;
void fast() {

	std::ios_base::sync_with_stdio(0);
}

int main()
{
	int a, b, c, d;
	cin >> a >> b;
	int ans = min(a, b);
	cin >> c >> d;
	ans += min(c, d);
	cout << ans << endl;
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;


int main(void){
    int N;
    cin >> N;
    if(N == 3 || N == 5 || N == 7){
        printf("YES");
        return 0;
    }
    printf("NO");
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < SIZE; ++i) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

LL Bin(LL n, LL k) {
    if(k < 0 || n < k) {
        return 0;

    }
    LL ret = 1;
    for(LL i = 1; i <= k; ++i) {
        ret *= n--;
        ret /= i;

    }
    return ret;
}

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

    LL n, k;
    cin >> n >> k;
    combInit();

    LL res = 0;
    LL mi = k * (k - 1) / 2;
    LL mx = 0;
    int t = n;
    for(int i = 1; i <= k; ++i) {
        mx += t;
        t--;

    }

    for(int i = k; i <= n + 1; ++i) {
        res += mx - mi + 1;
        res %= MOD;
        mx += t;
        mi += i;
        --t;

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8304
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin>>n;
	cout<<(n/2)*((n+1)/2)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<int> memo(n + 1, -1);
    function<int(int)> f = [&memo, &f](int nn) -> int {
        if (memo[nn] != -1) {
            return memo[nn];
        }
        else if (nn == 0) {
            memo[nn] = 1;
        }
        else if (nn == 1) {
            memo[nn] = 1;
        }
        else {
            memo[nn] = f(nn - 1) + f(nn - 2);
        }
        return memo[nn];
    };

    cout << f(n) << endl;
}

Measured memory_bytes: 3088
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] s = S.toCharArray();
        long c = 0;
        long ans = 0;
        for (int i = 0; i < S.length(); i++) {
            if (s[i] == 'W') {
                ans += c;
            } else {
                c++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27160
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a)
#define MAX 100005
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n==1)
        cout<<n-1;
    else if(!n)
        cout<<n+1;
    return 0;
}

Measured memory_bytes: 3620
def func():
    N, K = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    
    dp = [0]*N
    for i in range(1, N):
        L = []
        for j in range(max(0, i-K), i):
            L.append(dp[j] + abs(H[i] - H[j]))
        dp[i] = min(L)

    print(dp[-1])
    
if __name__=="__main__":
    func()

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int h,w;
	cin >> h >> w;
	char a[h][w];
	FOR(i,0,h)FOR(j,0,w)cin >> a[i][j];
	int cy,cx;
	cy = cx = 0;
	bool ans = true;
	while(cy != h-1 || cx != w-1){
		a[cy][cx] = '.';
		char sita = (cy < h-1)?a[cy+1][cx]:'.';
		char migi = (cx < w-1)?a[cy][cx+1]:'.';
		if(sita == '#' && migi == '#'){
			ans = false;
			break;
		}else if(sita == '.' && migi == '.'){
			ans = false;
			break;
		}else{
			if(sita == '#'){
				cy++;
			}else{
				cx++;
			}
		}
	}
	a[h-1][w-1] = '.';
	FOR(i,0,h)FOR(j,0,w){
		if(a[i][j] == '#'){
			ans = false;
			break;
		}
	}
	Possible(ans);
	return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
#define int ll
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define pii pair<int,int>
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define initialize(arr,elem) memset(arr,elem,sizeof(arr))
#define sz size
const int MOD = 1e9+7;
const int MAX_SZ = 21;
const int INF = 1e18+9;

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n, matches[MAX_SZ][MAX_SZ];
int dp[MAX_SZ][(1<<MAX_SZ)];


void rand_shuff(vi &arr){
	random_device rd;
	mt19937 g(rd());
	shuffle(all(arr),g);
}
int solve(int k, bitset<32>& w){
	int cur = w.to_ullong();
	//cout<<k<<" "<<cur<<endl;
	if (dp[k][cur]!= -1) return dp[k][cur];
	if (k==0){
		For(i,0,n){
			if(matches[k][i] && w.test(i)) return 1;
		}
		return 0;
	}
	int res = 0;
	For(i,0,n){
		if (matches[k][i]==1 && w.test(i)){
			w[i] = 0;
			res += solve(k-1,w);
			res %= MOD;
			w[i] = 1;
		}
	}
	return dp[k][cur] = res%MOD;



}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	bitset<32> women(0);
	
	initialize(dp,-1);
	//cout<<women<<endl;
	cin>>n;
	For(i,0,n) women[i] = 1;
	For(i,0,n){
		For(j,0,n) cin>>matches[i][j];
	}
	//cout<<"eeE"<<endl;
	cout<<solve(n-1,women)<<endl;

	return 0;
}


Measured memory_bytes: 344320
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  string s; cin >> s;
  int r = 0, b = 0;
  for (char &c: s) {
    if (c == 'R') r++;
    else b++;
  }
  cout << (r > b ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int a = scanner.nextInt();
    int b = scanner.nextInt();
    if (a > 0) {
      System.out.println("Positive");
    } else if (b >= 0) {
      System.out.println("Zero");
    } else if ((b - a + 1) % 2 == 0) {
      System.out.println("Positive");
    } else {
      System.out.println("Negative");
    }
  }
}


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

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

ll lcm(ll a,ll b){
  return (a / gcd(a,b))*b;
}

int main(){
  ll d[10],v[10];

  int n;
  while( cin >> n , n){
    for(int i = 0 ; i < n ; i++ ){
      cin >> d[i] >> v[i];
      ll G = gcd(d[i],v[i]);
      d[i]/=G;
      v[i]/=G;
    }
    ll dlc = d[0];
    for(int i = 1 ; i < n ; i++ ){
      dlc = lcm(dlc,d[i]);
    }
    for(int i = 0 ; i < n ; i++ ){
      v[i] = v[i]*(dlc/d[i]); 
    }
    ll vgc = v[0];
    for(int i = 1 ; i < n ; i++ ){
      vgc = gcd(vgc,v[i]);
    }
    for(int i = 0 ; i < n ; i++ ){
      cout << v[i]/vgc << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1164
import itertools
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split()))for _ in range(q)]
print(max(sum(d for a,b,c,d in abcd if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(range(m),n)))

Measured memory_bytes: 9032
#17D8101028I tou koutetsu  2019/10/3
#ID:tanghaozhe 
#python

n=int(input())
X=list(map(int,input().split()))
curX=[]
for index,i in enumerate(X):
	curX.append(i)
	for j in range(index,0,-1):
		# print(curX,"j=",j)
		if j>0 and curX[j]<curX[j-1]:
			tmp=curX[j-1]
			curX[j-1]=curX[j]
			curX[j]=tmp
	res=curX+X[index+1:]
	print(' '.join(str(e) for e in res))






Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
long long num(long long l,long long m){
  return l/m;
}

int main() {
  long long a,b; cin>>a>>b;  
  long long x; cin>>x;
  if(a==0) cout<<num(b,x)+1<<endl;
  else cout<<num(b,x)-num(a-1,x)<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int S = sc.nextInt();
        int count = 0;

        for (int x = 0; x <= K; x++) {
            for (int y = 0; y <= K; y++) {
                int z = S - x - y;
                if (0 <= z && z <= K) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
}

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

int main(void){
  int n;
  int sum;
  int max,min;


  while(1){

    max = 0;
    min = 500;

  cin >> n;

  if( n == 0 ) break;

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

    sum = 0;
    int s[5];

    for( int j = 0 ; j < 5 ; j++ ){

      cin >> s[j];

      sum += s[j];

    }

    if( max < sum ) max = sum;
    if( min > sum ) min = sum;

  }

  cout << max << " " << min << endl;

  }

  return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
#define ld long double

using namespace std;	

int main() {	
	int l, r, d;
	scanf ("%d%d%d", &l, &r, &d);
	printf ("%d\n", r / d - (l - 1) / d);	
	
	return 0;
}


Measured memory_bytes: 3796
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define INF 1000000007
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
    ll H, W;
    cin >> H >> W;
    ll ans = H * W;
    if (H == 1 || W == 1) ans = 1;
    ans % 2 == 0 ? ans /= 2 : ans = ans / 2 + 1;
    cout << ans << endl;
    return 0;
}


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

int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i ++){
        cin >> A.at(i);
    }

    bool kyoka = true;

    for(int i = 0; i < N; i ++){
        if(A.at(i) % 2 == 0){
            if(A.at(i) % 3 != 0 && A.at(i) % 5 != 0){
                kyoka = false;
            }
        }
    }

    if(kyoka){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	if (s[n - 1] == 's') {
		s += "es";
	} else {
		s += 's';
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 3572
package main

import (
"bufio"
"fmt"
	"math"
	"os"
"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n, d := nextInt(), nextInt()
	points := make([][]int, n)
	for i := 0; i < n; i++ {
		p := make([]int, d)
		for j := 0; j < d; j++ {
			p[j] = nextInt()
		}
		points[i] = p
	}

	c := 0
	for i := 0; i < n; i++ {
		for j := i+1; j < n; j++ {
			a, b := points[i], points[j]
			dis := 0
			for k := 0; k < d; k++ {
				dis += (a[k] - b[k]) * (a[k] - b[k])
			}

			sq := int(math.Sqrt(float64(dis)))
			if sq*sq == dis {
				c++
			}
		}
	}

	fmt.Println(c)
}

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

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

  int num=a[0];
  for(int i=1;i<n-1;i++){
    num-=a[i];
    num*=(-1);
  }
  int c=(a[n-1]-num)/2;

  for(int i=0;i<n-1;i++){
    cout<<c*2<<" ";
    c=a[i]-c;
  }
  cout<<c*2<<endl;

  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 1e5 + 5;
int pre[maxn], sum[maxn], x[maxn], y[maxn];
long long ans[maxn];
int find(int x)
{
    return x == pre[x] ? x : pre[x] = find(pre[x]); //这里一开始写错了，写成了x = find。。
}
void join(int a, int b)
{
    a = find(a), b = find(b);
    if(a != b)
    {
        sum[a] += sum[b];
        sum[b] = 0;
        pre[b] = a;
    }
}
int main()
{
    int n, m;
    while(cin >> n >> m)
    {
        for(int i = 0; i < maxn; i++) sum[i] = 1, pre[i] = i;
        memset(ans, 0, sizeof(ans));
        for(int i = 1; i <= m; i++)
        {
            scanf("%d%d", &x[i], &y[i]);
        }
        long long cnt = n;
        ans[m+1] = cnt * (cnt-1) / 2;
        for(int i = m; i >= 2; i--)
        {
            int xx = find(x[i]), yy = find(y[i]);
            if(xx != yy)
            {
                ans[i] = ans[i+1] - sum[xx] * sum[yy];
                join(x[i], y[i]);
            }
            else
                ans[i] = ans[i+1];
        }
        for(int i = 2; i <= m+1; i++)
            printf("%lld\n", ans[i]);
    }

    return 0;
}



Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;

struct node{
  int val;
  vector<int> next;
  node(){
    val = -1;
  }
  node(int a){
    val = a;
  }
};

int n;
string s;
vector<node> tree;

int make(int p, int v)
{
  string tmp;
  for(int i = p; i < s.size(); i++){
    if(s[i] == '['){
      tree.push_back(node());
      tree[v].next.push_back(tree.size()-1);
      i = make(i+1, tree.size()-1);
    }
    else if(s[i] == ']'){
      if(tmp != ""){
        tree[v].val = atoi(tmp.c_str());
      }
      return i;
    }
    else{
      tmp += s[i];
    }
  }
}

int calc(int v)
{
  if(tree[v].val != -1){
    return (tree[v].val + 1) / 2;
  }
  vector<int> vec;
  for(int i = 0; i < tree[v].next.size(); i++){
    vec.push_back(calc(tree[v].next[i]));
  }
  sort(vec.begin(), vec.end());
  int ret = 0;
  for(int i = 0; i < ((int)vec.size()+1)/2; i++) ret += vec[i];
  return ret;
}

int main(void)
{
  cin >> n;
  for(int t = 0; t < n; t++){
    cin >> s;

    tree.clear();
    tree.push_back(node());

    make(0, 0);
    cout << calc(0) << endl;
  }

  return 0;
}



Measured memory_bytes: 3280
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int n, m, a, ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int temp = 0;
		for (int j = 0; j < m; j++) {
			cin >> a;
			temp += a;
		}
		ans = max(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

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

typedef struct card{
	char suit, value;
}C;

void Bubble(C c[],int n)
{
	int i, j;
	for (i = 0; i < n; i++) {
		for (j = n - 1; j >= i+1; j--) {
			if (c[j].value < c[j-1].value) swap(c[j], c[j - 1]);
		}
	}
}

void Selection(C c[], int n) 
{
	int i, j, minj;
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (c[j].value < c[minj].value)minj = j;
		}
		swap(c[i], c[minj]);
	}
}

bool isStable(C c1[],C c2[],int n) {
	for (int i = 0; i < n; i++) {
		if (c1[i].suit != c2[i].suit) return false;
	}
	return true;
}

void print(C c[], int n)
{
	for (int i = 0; i < n; i++) {
		if (i > 0)cout << " ";
		cout << c[i].suit << c[i].value;
	}
	cout << endl;
}

int main()
{
	C c1[100], c2[100];
	int n;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c1[i].suit >> c1[i].value;
	}

	for (int i = 0; i < n; i++) c2[i] = c1[i];

	Bubble(c1, n);
	Selection(c2, n);

	print(c1, n);
	cout << "Stable" << endl;
	print(c2, n);
	if (isStable(c1, c2, n)) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}

	return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main() {
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
 
	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}
 
	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
}

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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ma = 0;
	for (int i = 1; i < n; i++) {
		string l, r;
		l = s.substr(0, i);
		r = s.substr(i);
		set<char>ls, rs;
		for (int i = 0; i < l.length(); i++)ls.insert(l.at(i));
		for (int i = 0; i < r.length(); i++)rs.insert(r.at(i));
		vector<char>as;
		set_intersection(ls.begin(), ls.end(), rs.begin(), rs.end(), back_inserter(as));
		int x = as.size();
		ma = max(ma, x);
	}
	cout << ma << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>
//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long int;
//// 任意長整数型
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;



int main(int argc, char *argv[])
{
	int N, K;
	//input
	cin >> N >> K;

	vector<ll> x, y;
	for (int i = 0; i < N; ++i){
		ll xi, yi;
		cin >> xi >> yi;
		x.push_back(xi);
		y.push_back(yi);
	}


	//calc
	ll min_area = LLONG_MAX;
	for (int i = 0; i < N; i++){//x1
		for (int j = 0; j < N; j++){//x2
			for (int k = 0; k < N; k++){//y1
				for (int l = 0; l < N; l++){//y2
					int count_point_in_rect = 0;
					for (int m = 0; m < N; m++){
						if (min(x[i], x[j]) <= x[m] && x[m] <= max(x[i], x[j]) &&
							min(y[k], y[l]) <= y[m] && y[m] <= max(y[k], y[l])){
							count_point_in_rect++;
						}
					}

					if (K <= count_point_in_rect){
						ll current_area = abs(x[i] - x[j]) * abs(y[k] - y[l]);
						if (current_area != 0 && current_area < min_area){
							min_area = current_area;
						}
					}
				}
			}
		}
	}


	//ans
	cout << min_area << endl;

	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

int main(){
  // 入力
  long int X;
  cin >> X;

  long int result = 0;
  long int kane = 100;
  while (1) {
    if (kane >= X ) {
      break;
    }
    kane = kane * 1.01;
    result++;
  }
  

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>

#define SIZE 200000

using namespace std;

int main() {
    long long int i,j,k,n,M,K,Q,X,A,B,C;
  //  long long int A[100][100];
  long long int s;
   cin >> A >> B >> C >> K;

   if (K <= A) {
     s = K;
   }
   else {
     s = A;
     K -= A;

     if (K > B) {
       K -= B;
       s -= K;
     }
   }

   cout << s << endl;
  return 0;

}


Measured memory_bytes: 3596
N, M, C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
A = N.times.map { gets.split.map(&:to_i) } # 2次元配列の入力
total = 0
ans = 0
(0..N - 1).each do |y|
  (0..M - 1).each do |x|
    total += (A[y][x] * B[x])
    total += C if x == M - 1
  end
  ans += 1 if total.positive?
  total = 0
end
puts ans

Measured memory_bytes: 1788
import bisect

A, B, Q = map(int, input().split())
S = [-float('inf')] + [int(input()) for _ in range(A)] + [float('inf')]
T = [-float('inf')] + [int(input()) for _ in range(B)] + [float('inf')]

for _ in range(Q):
    answer = float('inf')
    x = int(input())
    si = bisect.bisect_left(S, x)    
    ti = bisect.bisect_left(T, x)
    for s in [S[si-1], S[si]]:
        for t in [T[ti-1], T[ti]]:
            d = min(abs(s-x), abs(t-x)) + abs(t-s)            
            answer = min(answer, d)
    print(answer)

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

int main(){
  int R, D, x2000;
  cin >> R >> D >> x2000;

  int num = 1;
  while (num <= 10){
    x2000 = R * x2000 - D;
    cout << x2000 << endl;
    num++;
  }
}

Measured memory_bytes: 384
def main():
  n=int(input())
  num=[int(i) for i in input().split()]
  mod=10**9+7

  import math
  if max(num)==0:
    print(0)
    exit()
  l=math.ceil(math.log(max(num),2))

  ans=[0]*l
  tmp1,tmp2,tmp3=0,0,0
  for i in range(l):
    ans[i]=tmp3
    cnt=0
    for j in range(n):
      if (num[j]>>i)&1:
        cnt+=1
    tmp1=cnt*(n-cnt)
    tmp2=(ans[i]+tmp1)%2
    tmp3=(ans[i]+tmp1)//2
    ans[i]=tmp2

  a_append=ans.append
  while tmp3>0:
    a_append(tmp3%2)
    #print(tmp3)
    tmp3//=2
  #print(ans)
  ans=int(''.join([str(i) for i in ans[::-1]]),2)%mod
  print(ans)
  
if __name__=='__main__':
  main()


Measured memory_bytes: 123056
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)){
    cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}
}


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

int main()
{
    int n,T,i,j,k;
    cin>>n;
    vector<long long>v(n+3);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    cin>>T;
    while(T--)
    {
        long long l,r;
        cin>>l>>r;
        reverse(v.begin()+l,v.begin()+r);
    }
    long long ans=0;
    for(i=0;i<n;i++,ans++)
    {
        if(ans!=0)cout<<" ";
        cout<<v[i];
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3104
#include<iostream>

using namespace std;

int arr[100];

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
	int a,b;
    cin >> a >> b;
    arr[a]++;
    arr[b]++;
  }
  for(int i=1;i<=n;i++)cout << arr[i] << '\n';
}

Measured memory_bytes: 256
N = int(input())

pos_x=0
pos_y=0
t_now=0
flg = True
for i in range(N):
    t,x,y = map(int,input().split())
    t_del = t-t_now
    res = (t_del-abs(pos_x-x)-abs(pos_y-y))
    if (res>=0) & (res%2==0):
        t_now = t
        pos_x = x
        pos_y=y
        pass
    else:
        flg = False
        break

if flg == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 73652
#include <cstdio>
#include <algorithm>
#define maxn 105
using namespace std;
int dp[maxn][maxn];
char s[maxn][maxn];
int main(){
	int h,w,i,j;
	scanf("%d%d",&h,&w);
	for(i=1;i<=h;i++)scanf("%s",s[i]+1);
	for(i=1;i<=h;i++)
		for(j=1;j<=w;j++)
			dp[i][j]=210;
	dp[1][1]=(s[1][1]=='#');
	for(i=1;i<=h;i++)
		for(j=1;j<=w;j++){
			dp[i][j+1]=min(dp[i][j+1],dp[i][j]+(s[i][j]!=s[i][j+1]));
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(s[i][j]!=s[i+1][j]));
		}
	printf("%d\n",(dp[h][w]+1)/2);
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::fastout;


#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }

    let mut appear = [0; 1000001];
    for v in &a {
        appear[*v] += 1;
    }

    let mut ans = 0;
    a.sort();
    for v in &a {
        if appear[*v] == 1 {
            ans += 1;
        }
        if appear[*v] > 0 {
            for i in (*v .. 1000001).step_by(*v) {
                appear[i] = 0;
            }
        }
    }

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


Measured memory_bytes: 9544
#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>;

int main(){
	string st;
	cin >> st;
	int f = 0;
	rep(i, 3){
    	if(st.at(i) == st.at(i+1)) f = 1;
    }
	if(f == 1){
    	cout << "Bad" << endl;
    }else{
    	cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
long long loc[100005];
int main(){
    long long n,a,b,st,m,m1,m2,l_b,r_b;
    scanf("%lld%lld%lld",&n,&a,&b);
    for(long long i=1;i<=n;i++)
     scanf("%lld",&loc[i]);
    st=loc[1];
    sort(loc,loc+n+1);
    l_b=loc[1];r_b=loc[n];
    for(long long i=1;i<=n;i++)
     if(loc[i]==st) m=i;
    long long lef=0,righ=0;
    long long now;
    now=st;
    bool flag=false;
    m1=m;m2=m;
    long long res=0;
    if(m==1){
     for(long long i=2;i<=n;i++)
      res+=min( (loc[i]-loc[i-1])*a,b );
     printf("%lld",res);
     return 0;
    }
    if(m==n){
     for(long long i=n;i>=2;i--)
      res+=min( (loc[i]-loc[i-1])*a,b );
     printf("%lld",res);
     return 0;
    }
    while(now<r_b){
     if(now==l_b) {
      flag=true;
      now=loc[m+1];
      lef+=min( ((loc[m+1]-loc[m1])*a),b );
      m1=m+1;continue;
     }
     if(!flag){
      lef+=min( ((loc[m1]-loc[m1-1])*a),b );
      now=loc[m1-1];
      m1--;
     }
     else {
      lef+=min( ((loc[m1+1]-loc[m1])*a),b );
      now=loc[m1+1];
      m1++;
     }
    }
    flag=false;now=st;
    while(now>l_b){
     if(now==r_b){
      flag=true;
      now=loc[m-1];
      righ+=min( ((loc[m2]-loc[m-1])*a),b );
      m2=m-1;continue;
     }
     if(!flag){
      righ+=min( ((loc[m2+1]-loc[m2])*a),b );
      now=loc[m2+1];
      m2++;
     }
     else {
      righ+=min( ((loc[m2]-loc[m2-1])*a),b );
      now=loc[m2-1];
      m2--;
     }
    }
    printf("%lld",min(lef,righ));
    return 0;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2


int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/

const int inf = 100000000;
const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int a[1005],b[1005],c[1005],dis[1005][1005];

int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n,m;

    cin >> n >> m;

    for(int i=1 ; i<=m ; i++){
        cin >> a[i] >> b[i] >> c[i];
    }


    for(int i=1 ; i<=n ; i++){
        for(int k=1 ; k<=n ; k++){
            if(i==k){
                dis[i][k]=0;
            }else {
                dis[i][k]=inf;
            }
        }
    }

    for(int i=1 ; i<=m ; i++){
        dis[a[i]][b[i]] = min(dis[a[i]][b[i]], c[i]);
        dis[b[i]][a[i]] = min(dis[b[i]][a[i]], c[i]);
    }

    for(int k=1 ; k<=n ; k++){
        for(int i=1 ; i<=n ; i++){
            for(int j=1 ; j<=n ; j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }


    int ans=m;
    for(int i=1 ; i<=m ; i++){
        bool sortest=false;
        for(int k=1 ; k<=n ; k++){
            if(dis[k][a[i]]+c[i]==dis[k][b[i]]) sortest=true;
        }
        if(sortest) ans-=1;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define p 1000000007
using namespace std;

int n,i,j,k,l,r,q,ans;
int Next[100005],f[100005],g[100005];
long long a[100005],A,B;

void add(int &a,int b){a+=b;if(a>=p)a-=p;}

int main()
{
	scanf("%d%lld%lld",&n,&A,&B);
	for(i=1;i<=n;++i)scanf("%lld",&a[i]);
	if(A<B)swap(A,B);
	Next[n]=n;
	for(i=n-1;i>=1;--i)
	if(a[i+1]-a[i]>=B)Next[i]=Next[i+1];
	else Next[i]=i;
	g[1]=1;g[Next[1]+2]=p-1;
	if(Next[1]==n)ans=1;
	for(i=1;i<=n;++i)
	{
		add(g[i],g[i-1]);
		add(f[i],g[i]);
		if(i<n)
		{
			if(i==1||a[i+1]-a[i-1]>=B)
			{
				for(;q<=n&&a[q]-a[i]<A;++q);
				l=q;r=Next[i+1]+1;
				if(l<=r)
				{
					add(g[l],f[i]);
					add(g[r+1],p-f[i]);
				}
			}
		}
		if((i==n||i==1||a[i+1]-a[i-1]>=B)&&(i==n||Next[i+1]==n))add(ans,f[i]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<assert.h>
#include<numeric>
#define rep(i,a,b) for(int (i)=(a);i<(b);i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

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

ll pow_mod(ll x, ll y, ll mod) {
	if (y == 0)return 1;

	if (y == 1)return x % mod;

	return (pow_mod(x, y - 1, mod) * x) % mod;
}

bool landmap[55][55];

int H, W;

int d[55][55];

int white = 0;

int bfs() {
	queue<P> que;
	rep(i, 0, H) {
		rep(j, 0, W)d[i][j] = INF;
	}
	que.push(P(0, 0));
	d[0][0] = 0;
	while (que.size()) {
		P p = que.front();
		que.pop();
		if (p.first == H - 1 && p.second == W - 1)break;
		rep(i, 0, 4) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (0 <= nx && nx < H && 0 <= ny && ny < W && landmap[nx][ny] && d[nx][ny] == INF) {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[H - 1][W - 1];
}

int main() {
	cin >> H >> W;
	rep(i, 0, H) {
		string s;
		cin >> s;
		rep(j, 0, W) {
			if (s[j] == '.') {
				landmap[i][j] = 1;
				white++;
			}
			else landmap[i][j] = 0;
		}
	}
	int res = bfs();
	if (res == INF)cout << -1;
	else cout << white - res - 1;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#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)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

bool is_ok(const string& S, const string& T) {
  int S_size = S.size();
  if (S_size + 1 != T.size()) return false;
  rep(i, S_size) {
    if (S[i] != T[i]) return false;
  }
  return true;
}

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

  string S, T;
  cin >> S >> T;

  if (is_ok(S, T)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
const int inf = 1<<30;
using vs  = vector<string>;
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

int n, m;
vs info;
map<string, int> memo;

int rec(string s){
  int c = 0;
  rep(i,m) if(s[i] == '1') c++;
  if(c <= 1) return 0;

  if(memo.count(s)) return memo[s];

  int res = inf;
  rep(i,n){ // i番目の質問をするとき
    string zero = s, one = s;
    rep(j,m){ // j番目のもの
      if(s[j] == '0') continue; // もう区別されている
      if(info[j][i] == '0') one[j] = 0;
      else zero[j] = 0;
    }
    if(zero == s or one == s) continue;
    int tmp = max(rec(zero), rec(one));
    chmin(res, tmp);
  }
  memo[s] = res+1;
  return res+1;
}

int main(){
  while(cin >> n >> m, n){
    info.resize(m);
    rep(i,m) cin >> info[i];

    memo.clear();
    string all;
    rep(i,m) all += '1';
    cout << rec(all) << endl;
  }
}


Measured memory_bytes: 7580
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int a[200005];
int b[200005],c[200005];
int main()
{
    int n,lenb,lenc,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(n==1)
    {
        printf("%d\n",a[1]);
        return 0;
    }
    lenb=lenc=1;
    for(i=1;i<=n;i+=2)
        b[lenb++]=a[i];
    for(i=2;i<=n;i+=2)
        c[lenc++]=a[i];
    lenb--;
    lenc--;
    if(n%2==0)
    {
        for(i=lenc;i>=1;i--)
            printf("%d ",c[i]);
        for(i=1;i<lenb;i++)
            printf("%d ",b[i]);
        printf("%d\n",b[i]);
    }
    else
    {
        for(i=lenb;i>=1;i--)
            printf("%d ",b[i]);
        for(i=1;i<lenc;i++)
            printf("%d ",c[i]);
        printf("%d\n",c[lenc]);
    }
    return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;;
ll asc_cmp(ll x,ll y){if(x<y)return -1;else if(x==y)return 0;else return 1;}
ll desc_cmp(ll x,ll y){if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    char s[20],t[20];scanf("%s %s",s,t);
    int a,b;scanf("%d %d",&a,&b);
    char u[20];scanf("%s",u);

    if(!strcmp(s,u)){
        printf("%d %d",a-1,b);
    }else{
        printf("%d %d",a,b-1);
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define log(x,b) (log(x)/log(b))
using namespace std;

int32_t main()
{
    int n,x;
    cin>>n>>x;
    vector<int>v;
    for(int i=0;i<n;i++){
        int x;cin>>x;v.push_back(x);
    }
    int cnt=0;
    for(int i=0;i<n-1;i++){
        if(v[i]>=x)cnt+=v[i]-x,v[i]=x;
        int b=v[i]+v[i+1];
        if(b>=x){
            if(b-x>=v[i+1]){
                cnt+=v[i+1];
                v[i+1]=0;
            }
            else{
                cnt+=b-x;
                v[i+1]-=b-x;
            }
        }
    }

    cout<<cnt<<endl;

    return 0;
}


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

int n;
string s;

void transform(string& s) {
	for(int i = 0; i < s.size(); i++)
		s[i]--;
}

void divide(string& s) {
	for(int i = 0; i < s.size(); i++)
		s[i] = (s[i] == '2') ? '1' : '0';
}

bool odd(string s) {
	ll ans = 0;

	ll x = n-1;

	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '1') {
			bool odd = 1;
			int k = i;
			if(x < k) continue;
			for(int j = 0; k > 0 && odd; j++, k /= 2) {
				if((i&(1<<j)) && !(x&(1<<j)))
					odd = 0;
			}

			if(odd)
				ans ^= 1;
		}
	}

	return ans;
}

bool containOne(string s) {
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '1') return 1;
	}
	return 0;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> s;
	transform(s);

	if(odd(s))
		cout << "1" << '\n';
	else if(containOne(s))
		cout << "0" << '\n';
	else {
		divide(s);
		if(odd(s))
			cout << "2" << '\n';
		else
			cout << "0" << '\n';
	}

	return 0;
}

Measured memory_bytes: 2332