akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
#define double long double
const int INF = 1e18, MOD = 2019;

int modpow(int x, int n) {
    return n < 1 ? 1 : modpow(x * x % MOD, n / 2) * (n % 2 ? x : 1) % MOD;
}

int summation(int a) {return a < 1 ? 0 : (a * a + a) / 2;}

signed main() {
    string s;
    int cnt[2222] = {};
    cnt[0]++;
    cin>>s;
    reverse(s.begin(), s.end());
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
        now += modpow(10, i) * (s[i] - '0');
        now %= MOD;
        cnt[now]++;
    }
    int ans = 0;
    for (int i = 0; i < 2020; i++) {
        ans += summation(cnt[i] - 1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3720
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define maxn 200010
using namespace std;
typedef long long ll;
int n;
ll a[maxn];
ll ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)  scanf("%lld",&a[i]);
	for(int i=2;i<=n;i++)
	{
		if(a[i]-a[i-1]>1)
		{
			puts("-1");
			return 0;
		}
	}
	if(a[1])
	{
		puts("-1");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i+1]-a[i]!=1)
		{
			ans+=a[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  int n,x,mn=100000,kl=0;
  cin>>n>>x;
  vector<int>m(n);
  for(int i=0;i<n;i++){
    cin>>m[i];
  }
  for(int i=0;i<n;i++){
    x-=m[i];
    kl++;
  }
  for(int i=0;i<n;i++){
    mn=min(mn,m[i]);
  }
  cout<<kl+x/mn<<endl;
}

    
    
  
  

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

#define PB emplace_back

using namespace std;

const int N = 5e5+100;

int par[N], h[N];

int fat(int x) {
    while(x != par[x]) x = par[x];
    return x;
}

void add(int u, int v) {
    u = fat(u);
    v = fat(v);
    if(u != v) {
        if(h[u] < h[v]) swap(u, v);
        h[u] = max(h[u], h[v] + 1);
        par[v] = u;
    }
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, m;
    cin >> n >> m;
    iota(par, par + n , 0);
    while(m--) {
        int t, u1, u2;
        cin >> t >> u1 >> u2;
        if(t) cout << (fat(u1) == fat(u2)) << '\n';
        else add(u1, u2);
    }
}


Measured memory_bytes: 5056
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
string s;cin>>s;
int n=s.length();
int c=0;
for(int i=1;i<n;i++){
if(s[i]!='9')c=1;}
int p=s[0]-'1';
if(c) cout<<p+9*(n-1);
else cout<<p+1+9*(n-1);
cout<<endl;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
using namespace std;
int main()
{
    int a, b, n, m;
    cin>>a>>b;
    if(a>=13)
        cout<<b<<endl;
    else if(a>=6 && a<=12)
        cout<<b/2<<endl;
    else
        cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H, W;
	cin >> H >> W;
	vector<string> str(H);
	string non(W, '.');
	for(int i = 0; i < H; i++){
		cin >> str.at(i);
		if(str.at(i) == non){
			i--;
			H--;
		}
	}
	for(int i = 0; i < W; i++){
		bool flg = 1;
		char comp = '.';
		for(int j = 0; j < H; j++){
			if(str.at(j).at(i) != comp){
				flg = 0;
				break;
			}
			comp = str.at(j).at(i);
		}
		if(flg){
			for(int j = 0; j < H; j++)
				str.at(j).erase(str.at(j).begin()+i);
			W--;
			i--;
		}
	}
	for(int i = 0; i < H; i++)
		cout << str.at(i) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

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

#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

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

  int n;

  cin >> n;

  long a[n];
  long b[n];

  for (int i=0;i<n;i++) {
    scanf("%ld %ld", &a[i], &b[i]);
  }

  long cnt = 0;

  for (int i=n-1;i>=0;i--) {
    long x = (a[i] + cnt) % b[i];
    if (x) {
      cnt += b[i]-x;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1920
n, a, b = map(int, input().split())

ans = 0
if n == 1:
    if a == b:
        ans = 1
    else:
        ans = 0
else:
    if a > b:
        ans = 0
    else:
        ans =  (a + b *(n - 1)) - (a * (n - 1) + b) + 1
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N; cin >> N;
  int ans = 0;
  vector<int> odd;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (a%2==0) {
      ans += a/2;
    } else {
      odd.push_back(a);
    }
  }
  int a = 0;
  if (odd.size()%2==0) {
    for (int i = 0; i < odd.size(); i++) {
      a += odd[i];
    }
  } else {
    sort(odd.begin(),odd.end());
    for (int i = 1; i < odd.size(); i++) {
      a += odd[i];
    }
  }
  ans += a/2;
  cout << ans << endl;
}



Measured memory_bytes: 3148
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=100005;
int f[N+1],inf[N+1];
int cal(int n,int r)
{
    if(r>n)
        return 0;
    int ans=f[n];
    ans=(ans*inf[r])%hell;
    ans=(ans*inf[n-r])%hell;
    return ans;
}
void solve()
{
    f[0]=1;
    for(int i=1;i<=N;i++)
        f[i]=(i*f[i-1])%hell;
    inf[N]=power(f[N],hell-2,hell);
    for(int i=N-1;i>=0;i--)
        inf[i]=((i+1)*(inf[i+1]))%hell;
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector<pair<int,int> >ve;int fe=0,x,y;int ans=0;
    sort(a,a+n);
    for(int i=0;i<n-1;i++)
    {
        if(a[i]==a[i+1])
            fe++;
        else
        {
            ve.pb(m1(a[i],fe+1));
            fe=0;
        }
    }
    ve.pb(m1(a[n-1],fe+1));
    if(ve.size()==1)
    {
        cout<<0<<endl;
        return;
    }
    int n1=ve.size();int s=0;
    for(int i=0;i<n1;i++)
    {
        x=ve[i].first;
        fe=ve[i].second;
        for(int j=1;j<=min(k,fe);j++)
        {
            y=cal(fe,j);
            y=(y*cal(s,k-j))%hell;
            y=(y*x)%hell;
            ans=(ans+y)%hell;
        }
        s+=fe;
    }
    s=0;
    for(int i=n1-1;i>=0;i--)
    {
        x=ve[i].first;
        fe=ve[i].second;
        for(int j=1;j<=min(k,fe);j++)
        {
            y=cal(fe,j);
            y=(y*cal(s,k-j))%hell;
            y=(y*x)%hell;
            ans=(ans-y+hell)%hell;
        }
        s+=fe;
    }
    cout<<ans<<endl;
}
int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

using namespace std;

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#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 SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int x, y, n[5];  
  char store[5] = {'A', 'B', 'C', 'D', 'E'};

  while(cin >> x >> y, x+y != 0) {
    n[0] = x+y;
    FOR(i, 1, 5) {
      cin >> x >> y;
      n[i] = x+y;
    }

    int p, max = 0;
    REP(i, 5) {
      if(max < n[i]) {
	p = i;
	max = n[i];
      }
    }
    cout << store[p] << ' ' << max << endl;
  }
}

Measured memory_bytes: 1160
class SegmentTree:
    def __init__(self, L, op, ide):
        self.op = op
        self.ide = ide
        self.sz = len(L)
        self.n = 1
        self.s = 1
        for i in range(1000):
            self.n *= 2
            self.s += 1
            if self.n >= self.sz:
                break
        self.node = [self.ide]*(2*self.n-1)

        for i in range(self.sz):
            self.node[i+self.n-1] = L[i]

        for i in range(self.n-2,-1,-1):
            self.node[i] = self.op(self.node[i*2+1],self.node[i*2+2])
    
    def add(self, a, x):
        k = a+self.n-1
        self.node[k] += x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break
    
    def substitute(self, a, x):
        k = a+self.n-1
        self.node[k] = x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break

    def get_one(self, a):
        k = a+self.n-1
        return self.node[k]
    
    def get(self, l, r):
        res = self.ide
        n = self.n
        if self.sz <= r or 0 > l:
            print("ERROR: the indice are wrong.")
            return False

        for i in range(self.s):
            count = 2**i-1
            a = (r+1)//n
            b = (l-1)//n
            if a-b == 3:
                res = self.op(self.node[count+b+1],res)
                res = self.op(self.node[count+b+2],res)
                right = a*n
                left = (b+1)*n-1
                break
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n
                left = (b+1)*n-1
                break
            n = n//2

        #left
        n1 = n//2        
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (left+1)//n1
            b = (l-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                left = (b+1)*n1-1                
            n1 = n1//2

        #right
        n1 = n//2        
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (r+1)//n1
            b = (right-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n1                
            n1 = n1//2
        return res

N,K = list(map(int,input().split()))

P = list(map(int,input().split()))

count = 0
Tag = [0]*N

for i in range(1,N):
    if P[i]<P[i-1]:
        count+=1
    Tag[i]=count


ST1 = SegmentTree(P,max,-10**27)
ST2 = SegmentTree(P,min,10**27)
ans = 0
same_flag = False

for i in range(N-K+1):
    if Tag[i+K-1]==Tag[i]:
        if not same_flag:
            same_flag=True
            ans+=1
    else:
        if i>0:
            M = ST1.get(i,i+K-2)
            m = ST2.get(i,i+K-2)
            if not (P[i-1]<m and P[i+K-1]>M):
                ans+=1
        else:
            ans+=1

print(ans)

Measured memory_bytes: 111820
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int s[100100] = {};
  int n;
  int r = 0;
  cin >> n;
  rep(i,n){
    int t;
    cin >> t;
    if(t > 100000) r++;
    else s[t]++;
  }
  rep(i,100001){
    if(s[i]>i) r+=s[i]-i;
    else if(s[i]<i) r+=s[i];
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 640
def f(a,b): return [Card[a][0], Card[b][1]]
n = int(raw_input())
Card = [[] for _ in [0]*n]
Cost = {}
for i in range(n):
  Card[i] = map(int, raw_input().split())
  Cost[(i, i)] = 0
for i in range(1, n):
  for j in range(0, n-i):
    Cost[(j, j+i)] = min([reduce(lambda a,b: a*b, f(j,j+k)+f(j+k+1,j+i)) + Cost[(j, j+k)]+Cost[(j+k+1, j+i)] for k in range(i)])
print Cost[0, n-1]

Measured memory_bytes: 4524
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
int main() {
	cin >>N;
	vector<int>flag(4, 0);
	vector<char> s = { 'P','W','G','Y' };
	for (int i = 0; i < N; i++) {
		char a;
		cin >> a;
		for (int j = 0; j < 4; j++) {
			if (a == s[j])flag[j] = 1;
		}
	}
	for (int i = 0; i < 4; i++)if (flag[i] == 1)ans++;
	if (ans == 3)cout << "Three";
	else cout << "Four";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
 
  // 入力
  int n;
  scanf("%d",&n);
  int listA[n+1],result;
  for(int i=1;i<n;i++){
    scanf("%d",&listA[i]);
  }

  result=listA[1];
  for(int i=1;i<n-1;i++){
    if(listA[i]<listA[i+1]){
      result+=listA[i];
    }else{
      result+=listA[i+1];
    }
  }
  result+=listA[n-1];
  printf("%d\n",result);  

  return 0;
}

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

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 100248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)


typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;
double X0;
double Y0;
const int MAXN = 5e3+3;

struct Point{
  double x;
  double y;
  Point(double a = 0, double b = 0){
    x = a,y = b;
  }
  bool operator==(const Point p)const {
    return p.x == x && p.y == y;
  }
  bool operator<(const Point &p) const{
    return y<p.y || (y == p.y && x<p.x);
  }
  bool operator<=(const Point &p) const{
    return y<p.y || (y == p.y && x<=p.x);
  }
  Point operator+( Point p){
    return Point(x+p.x,y+p.y);
  }
  Point operator-( Point p){
    return Point(x-p.x,y-p.y);
  }
  Point operator*( double a){
	  return Point(a*x,a*y);
  }
  double operator*( Point p){
    return x*p.x + y*p.y;
  }
  double operator^( Point p){
    return x*p.y - y*p.x;
  }
  double norma2(){
    return x*x + y*y;
  }
  double norma(){
    return sqrt(this->norma2());
  }
};
struct Recta{
	Point P;
	Point V;
	Recta(Point p=Point(0,0),Point q=Point(0,0)){
		P=p;
		V=q;
		}
	Point operator *(Recta M){
		if(((M.V)^V) == 0){
			return Point(inf,inf);
			}
		else{
			double alpha;
			alpha=((M.P-P)^M.V)/(V^M.V);
			return P+V*alpha;
			}
		}
	};
struct Segmento{
	Point P;
	Point V;
	Segmento(Point p=Point(0,0),Point q=Point(0,0)){
		P=p;
		V=q;
		}
	Point operator *(Recta M){
		if(((M.V)^V) == 0){
			return Point(inf,inf);
			}
		else{
			double alpha;
			alpha=((M.P-P)^M.V)/(V^M.V);
			if((alpha<=1)&&(alpha>=0))
			{return P+V*alpha;}
			else
			{return Point(inf,inf);}
			}
		}
	};




int main(){
	string S;
	cin >> S;
	int n=S.length();
	int iseven=0,i,j;
	if(n%2==0){i=n-2;}
	else{i=n-1;}
	while(iseven==0){
		iseven=1;
		for(j=0;j<i/2;j++){
			if(S[j]!=S[j+(i/2)]){iseven=0;j=i/2;}
			}
		i=i-2;
		}
	i=i+2;
		printf("%d",i);
	printf("\n");
	return 0;
	}


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

using namespace std;

int main()
{
    int N;
    string S;
    cin >> N >> S;

    int count = 0;
    for (int i = 0; i < N - 2; i++) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//a^n mod p
//n > 0
//#include <cmath>
long long modpow(long long a, long long n, long long p) {
	a %= p;
	if (a == 0) return 0;
	if (a == 1) return 1;
	long long b = 1, cnt = 0;
	while (b < p && cnt < n) {
		b *= a;
		cnt++;
	}
	if (b < p) return b;
	b %= p;
	return modpow(b, n / cnt, p) * (long long)pow(a, n % cnt) % p;
}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, k;
	cin >> n >> k;

	vll cnt(k + 1, 0);
	ll ans = 0;
	for (ll i = k; i > 0; i--) {
		ll x = k / i;
		cnt[i] = modpow(x, n, p);
		for (ll j = 2 * i; j <= k; j += i) {
			cnt[i] -= cnt[j];
			if (cnt[i] < 0) cnt[i] += p;
		}
		ans += i * cnt[i] % p;
		ans %= p;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c;
    d = a - b;
    if(d > c)
        cout<< 0<<endl;
    else
    {d = abs(c - d);
    cout<< d<<endl;}
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
signed main(){
	int n;
	cin>>n;
	int d=-1;
	while(n){
		n/=2;
		d++;
	}
	cout<<(int)pow(2,d)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;

int main() {
    LL A, B, N;
    scanf("%lld %lld %lld", &A, &B, &N);
    LL q1 = N / B, r1 = N % B;
    if (q1 == 0) printf("%lld\n", (r1 * A) / B);
    else printf("%lld\n", ((B - 1) * A) / B);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


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

int main(){
    string s, t;
    cin >> s >> t;
    bool flag = true;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i])flag = false;
    }
    string ans = "Yes";
    if(!flag)ans = "No";
    
    cout << ans << endl;
}

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

using namespace std;
int a[12];
int main(){
	for(int i=1; i<=10;i++){
		cin>>a[i];
	}
	sort(a+1, a+11);
	cout<<a[10]<<endl;
	cout<<a[9]<<endl;
	cout<<a[8]<<endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
/*
 *  JUST KEEP GOING
 */
#define endl			'\n'
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define For(i,s)        for(auto i:s)
#define Forr(i,s)        for(auto &i:s)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <int,int>
#define vii				vector <ii>
#define vll				vector <pair<ll,ll>>
#define PI				double PPPPPP = 3.14159265358979323846;
#define bit(mask,i) ((mask>>i)&1)

void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 2e5+5,mod=1e9+7;
void solve(){
    string s;
    cin>>s;
    int ans=0,n=sz(s);
    for (int i = 0; i < n; ++i) {
        int cnt=0;
        while(i<n && s[i]=='R'){
            cnt++;
            i++;
        }
        ans=max(ans,cnt);
    }
    cout<<ans;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    run();
    int t=1;
   // cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3652
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.buffer.readline
N,M = map(int,input().split())
g = defaultdict(list)

for i in [0]*M:
    a,b = (map(int,input().split()))
    g[a].append(b)
    g[b].append(a)

f = [False]*N

ans = 0
def rec(s,f_):
    global ans
    f_[s-1] = True
    if sum(f_) == N:
        ans += 1
        return
    for t in g[s]:
        if not f_[t-1]:
            rec(t,f_[:])
    return 
rec(1,f[:])
print(ans)







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

ll sqrtll(ll a) {
  ll x = 1;
  while (x * x <= a) x++;
  return x - 1;
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  cout << (a + sqrtll(4 * a * b) + b < c ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main (void){

  int n,x,y,b,p,sum,i,sum1,sum2=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&x,&y,&b,&p); 
    if(b>=5&&p>=2){
      sum = ((x*b+y*p)*8)/10;
    }else{
      
      sum1 = x*b+y*p;
      sum = sum1;
      if(sum1>((x*5+y*2)*8)/10){
	b = b-5;
	p = p-2;
	if(b<0){
	  b=0;
	}
	if(p<0){
	  p=0;
	}
	sum2 = ((x*b+y*p)*8)/10+((x*5+y*2)*8)/10;
      
    
       if(sum1>sum2){
	sum = sum2;
      }else{
	sum = sum1;
       }
      }
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long mod = 1e9 + 7;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod){
    long long res = 1;
    while(n > 0){
        if(n & 1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^{-1} mod を計算する
long long modinv(long long a, long long mod){
    return modpow(a, mod - 2, mod);
}

struct node{
    vector<ll> fact;
    vector<ll> factr;
    node(ll n):fact(n+1), factr(n+1)  {
        fact[0] = 1;
        for(int i = 1; i<n+1; i++){
            fact[i] = fact[i-1]*i%mod;
        }
        factr[n] = modinv(fact[n],mod);
        for(int i = n; i>0; i--){
            factr[i-1] = factr[i]*i%mod;
        }
    }
    ll mod_pow(ll x, ll n, ll mod){
        ll res = 1;
        while(n>0){
            if(n&1) res = res *x%mod;
            x = x*x%mod;
            n>>=1;
        }
        return res;
    }

    ll modinv(ll a,ll mod){
        return mod_pow(a,mod-2,mod);
    }

    ll comb(ll n,ll m){
        return (fact[n]*factr[n-m]%mod)*factr[m]%mod;
    }

    ll bikuri(ll n){
        return fact[n];
    }
};

int main(){
    long long N, M, ans=0, temp;
    cin >> N >> M;
    node a(M);
    for(int i = 0; i < N+1; i++){
        temp = a.comb(N,i) * a.bikuri(M) % mod;
        temp = temp * a.bikuri(M-i) % mod;
        temp = temp * a.factr[M-N] % mod;
        temp = temp * a.factr[M-N] % mod;
        ans += ((long long)pow(-1,i) * temp);
        ans = (ans+2*mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int N;
   string s;
   cin >> N >> s;
   int cnt_r=0, cnt_b = 0;
   for(int i=0; i < N; i++){
      if(s[i] == 'R'){
         cnt_r++;
      }
      else if(s[i] == 'B'){
         cnt_b++;
      }
   }
   if(cnt_r > cnt_b){
      cout << "Yes" << endl;
   }
   else{
      cout << "No" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x) 	   x.begin(),x.end()	
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
bool compar(const pair<string,ll> &a, const pair<string,ll> &b) 
{ 
    if(a.first==b.first)
    return (a.second < b.second);
    else
    return (a.first < b.first);
}

void comp()
{
	ll i,j,k,m,n,p,w,d,x,y;
	string s;
	cin>>n;
	double temp=(double)n/3.0;
	double ans=1;
	ans=temp*temp;
	ans=ans*temp;
	cout<<fixed<<setprecision(8)<<(double)ans<<endl;
}

int main()
{
    speedup;
    ll i=0,t;
    ll n;
    //cin>>t;
    t=1;
	while(t--)
    {
    	i++;
    	//cout<<"Case #"<<i<<": ";
        comp();
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1,10):
        if i * 111 >= N:
            print(i*111)
            break


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    map<ll,ll> m;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
    }

    ll ans=0;
    for(auto e : m){
        ll x=e.second;
        ans+=x*(x-1)/2;
    }
    rep(i,n){
        ll x=m[a[i]];
        ll sub=x*(x-1)/2-(x-1)*(x-2)/2;
        cout<<ans-sub<<endl;
    }
}

Measured memory_bytes: 12736
main :: IO ()
main = do
  [w,h,n] <- map read . words <$> getLine :: IO [Int]
  solve 0 w 0 h n

solve :: (Eq a, Num a) => Int -> Int -> Int -> Int -> a -> IO ()
solve miX maX miY maY 0 = do print $ res miX maX miY maY
solve miX maX miY maY n = do
  [x,y,a] <- map read . words <$> getLine :: IO [Int]
  case a of
    1 -> solve (max x miX) maX miY maY (n-1)
    2 -> solve miX (min x maX) miY maY (n-1)
    3 -> solve miX maX (max y miY) maY (n-1)
    4 -> solve miX maX miY (min y maY) (n-1)

res :: Int -> Int -> Int -> Int -> Int
res miX maX miY maY = max 0 (maX - miX) * max 0 (maY - miY)


Measured memory_bytes: 1020
class Queue:
    def __init__(self):
        self.list = []
    
    def enqueue(self, element):
        self.list.append(element)

    def dequeue(self):
        item = self.list[0]
        del self.list[0]
        return item
    
    def size(self):
        return len(self.list)

if __name__ == "__main__":
    queue = Queue()
    n, qtm = input().split()
    n, qtm = int(n), int(qtm)
    for i in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue([name, time])
    
    result = []
    time = 0
    while queue.size() > 0:
        proc = queue.dequeue()
        proc_name = proc[0]
        proc_t = proc[1]
        if proc_t > qtm:
            proc = [proc_name, proc_t - qtm]
            queue.enqueue(proc)
            time += qtm
        else:
            time += proc_t
            print(proc_name, time)


Measured memory_bytes: 13016
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Dice dice = new Dice(new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt(),
                                       sc.nextInt(), sc.nextInt(), sc.nextInt()});

        String op = sc.next();
        for (int i = 0; i < op.length(); i++) {
            dice.move(op.charAt(i));
        }
        System.out.println(dice.eyes[dice.now[0]]);
    }

    static class Dice {

        int[] eyes;
        int[/*TOP N E S W BOT*/] now;

        public Dice(int[] eyes) {
            this.eyes = eyes;
            this.now = new int[]{0, 4, 2, 1, 3, 5};
        }

        void move(char way) {
            int tmp;
            switch (way) {
                case 'N':
                    tmp = now[0];
                    now[0] = now[3];
                    now[3] = now[5];
                    now[5] = now[1];
                    now[1] = tmp;
                    break;
                case 'E':
                    tmp = now[0];
                    now[0] = now[4];
                    now[4] = now[5];
                    now[5] = now[2];
                    now[2] = tmp;
                    break;
                case 'S':
                    tmp = now[0];
                    now[0] = now[1];
                    now[1] = now[5];
                    now[5] = now[3];
                    now[3] = tmp;
                    break;
                case 'W':
                    tmp = now[0];
                    now[0] = now[2];
                    now[2] = now[5];
                    now[5] = now[4];
                    now[4] = tmp;
                    break;
            }
        }
    }
}

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

int main()
{
    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  
  string s;
  cin >> s;
  
  int ans = 0, maxans = 0;
  rep(i,n){
    if(s[i] == 'I'){
      ans++;
    }else{
      ans--;
    }
    if(ans > maxans){
      maxans = ans;
    }
  }
  
  cout << maxans << endl;
}

Measured memory_bytes: 3544
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int m = scan.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			int[] count = new int[m];
			for(int i = 0;i < n*m;i++){
				if(scan.nextInt() == 1){
					count[i%m]++;
				}
			}
			int r = m-1;
			int[] rank = new int[m];
			boolean flag = true;
			int mflag = 0;
			while(flag){
				for(int i = m-1;i >= 0;i--){
					count[i]--;
					if(count[i] == 0){
						rank[r] = i+1;
						r--;
						mflag++;
					}
				}
				if(mflag == m){
					flag = false;
				}
			}
			for(int i = 0;i < m;i++){
				if(i != m-1){
					System.out.print(rank[i]+" ");
				}else{
					System.out.println(rank[i]);
				}
			}
		}
	}
}

Measured memory_bytes: 80424
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  for(int i=0;i<S.size();++i) {
    if(S[i]+N>'Z') S[i] = S[i]+N-'Z'+'A'-1;
    else S[i] += N;
  }
  cout<<S<<endl;
}



Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  
  map<long long int, int> count;
  for (int i = 0; i < N; i++) {
    count[A[i]] += 1;
  }
  
  int ans = 0;
  for (int i = N - 1; i>= 0; i--) {
    if (count[A[i]] > 0) {
      long long int target = 1;
      long long int temp = A[i];
      count[A[i]]--;
      while (temp > 0) {
        target *= 2;
        temp /= 2;
      }
      if (count[target - A[i]] > 0) {
        count[target - A[i]]--;
        ans++;
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 26752
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=210, Mod=1e9+7;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,res;
map<int,int> Q;
signed main()
{
    n=read();
    for(ri int i=2;i<=n;i++)
    {
        int x=i;
        for(ri int j=2;j*j<=x;j++)
        {
            if(x%j) continue;
            while(x%j==0) Q[j]++, x/=j;
        }
        if(x>1) Q[x]++;
    }
    res=1;
    for(ri map<int,int>::iterator s=Q.begin();s!=Q.end();s++)
        res=res*(s->second+1)%Mod;
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    vector<int> v;
    int now=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(a[i]!=now){
            v.push_back(cnt);
            now=a[i];
            cnt=1;
        }
        else cnt++;
    }
	v.push_back(cnt);
	sort(v.begin(),v.end());
    int ans=0;
    int s=v.size();
    for(int i=0;i<max(0,s-k);i++)ans+=v[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
long long n,m,i,j,sz[100005],f[100005],sum[100005],fa[100005],px[100005],py[100005],pz[100005],vis[100005],tag[100005];
struct ed
{
	long long id,z;
}a[100005];
bool cmp(ed x,ed y){return x.z<y.z;}
long long fnd(long long x)
{
	if (fa[x]==x) return x;
	return fnd(fa[x]);
}
stack<long long> sx,sy;
void merge(long long x,long long y)
{
	x=fnd(x);y=fnd(y);
	if (sz[x]>sz[y]) swap(x,y);
	sum[y]+=sum[x];
	fa[x]=y;
	if (sz[x]==sz[y]) sz[y]++;
	sx.push(x);
	sy.push(y);
}
void chexiao()
{
	long long x=sx.top(),y=sy.top();
	sx.pop();sy.pop();
	fa[x]=x;sum[y]-=sum[x];
	if (tag[y]) tag[x]=1;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;i++) {scanf("%lld",&sum[i]);}
	for (i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&px[i],&py[i],&pz[i]);
		a[i]=(ed){i,pz[i]};
	}
	for (i=1;i<=n;i++) {sz[i]=1;fa[i]=i;}
	sort(a+1,a+m+1,cmp);
	for (i=1;i<=m;i++)
	{
		long long t=a[i].id;
		if (fnd(px[t])!=fnd(py[t]))
		{
			merge(px[t],py[t]);
			vis[t]=1;
		}
	}
	long long ans=0;
	for (i=m;i;i--)
	{
		long long t=a[i].id;
		if (tag[fnd(px[t])]||sum[fnd(px[t])]>=pz[t]) tag[fnd(px[t])]=1; else ans++;
		if (vis[t]) chexiao();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10496
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int n, k;
const int M = 1e5 ;
int a[M]; 
int dp[M];
int main ()
{
    scanf ("%d%d" , &n , &k );
    for (int i =0 ; i < n ;i++)
        scanf ("%d" ,a+i);
    for (int i = 1; i < n ;i++)
    dp[i] = (int)2e9;
    for (int i = 1; i < n ;i++)
    {
        for (int j=0 ; j <= k && i - j >=0 ;j++)
        {
            dp[i] = min(dp[i] , abs(a[i] - a[i-j]) + dp[i-j] );
        }
    }
    cout << dp[n-1] <<"\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int INF=2000000;
  int i,j,k,n,m,a,b,c,p,q,dp[110][110],dp1[110][110];
  while(1){
  cin >> n >> m;
    if(n==0 && m==0){
      return 0;
    }
  for(i=0;i<m;i++){
    for(j=0;j<m;j++){
      dp[i][j]=INF,dp1[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    cin >> p >> q >> a >> b;
    p--,q--;
    dp[p][q]=a;
    dp1[p][q]=b;
    dp[q][p]=a;
    dp1[q][p]=b;
  }
  for(k=0;k<m;k++){
    for(i=0;i<m;i++){
      for(j=0;j<m;j++){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
        dp1[i][j]=min(dp1[i][j],dp1[i][k]+dp1[k][j]);
      }
    }
  }
  int d;
  cin >> d;
  for(i=0;i<d;i++){
    cin >> a >> b >> c;
    a--,b--;
    if(c==0){
      cout << dp[a][b] << endl;;
    }
    else{
      cout << dp1[a][b] << endl;
    }
  }
  }
  return 0;
}


Measured memory_bytes: 3176
use std::collections::VecDeque;

fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        edge: [(usize, usize); m]
    };
    let mut dp= vec![0; n];
    let mut cnt = vec![0; n];
    let mut g = vec![Vec::new(); n];
    for &e in &edge {
        cnt[e.0-1] += 1;
        g[e.1-1].push(e.0-1);
    }
    let mut qu = VecDeque::new();
    for i in 0..n {
        if cnt[i] == 0 { qu.push_back(i); }
    }
    while !qu.is_empty() {
        let p = qu.pop_front().unwrap();
        for &next in &g[p] {
            dp[next] = dp[next].max(dp[p]+1);
            cnt[next] -= 1;
            if cnt[next] == 0 { qu.push_back(next); }
        }
    }
    println!("{}", dp.iter().max().unwrap());
}


Measured memory_bytes: 10876
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
double tenchoku(double x1, double y1 , double x2 , double y2, double x, double y) {
double a = (y1-y2)/(x1-x2);
double b = -1;
double c = y1-a*x1;
double k = abs(a*x+b*y+c)/sqrt(a*a+b*b);
return k;}
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);}
return res;}
int main(){
cout << fixed << setprecision(10);
ll counter=0;
ll f=0;
ll h,w;
cin>>h>>w;
ll n;
cin>>n;
ll a[h*w]={};
ll ca=0;
for(ll i=1; i<=n; i++){
cin>>f;
for(ll k=0; k<f; k++){
a[ca]=i;
ca++;}}
ca=0;
for(ll i=0; i<h; i++){
if(i%2==0){
for(ll m=0; m<w; m++){
cout<<a[ca]<<" ";
ca++;}
cout<<endl;}
else{
ca+=w-1;
for(ll m=0; m<w; m++){
cout<<a[ca]<<" ";
ca--;}
ca+=w+1;
cout<<endl;}}}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  int n,x,t;
  cin>>n>>x>>t;
  n=ceil(n*1.0/x);
  ///dbg(n);
  cout<<n*t<<nl;
}

int main()
{
    su;
    ///tt
    f();
    return 0;
}


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

#define INF 1000000

typedef std::pair<int,int> to_cost;

std::vector<std::vector<to_cost> >v(10);
std::vector<int>min(10,INF);

void calc(int i){
	for(int j=0;j<v[i].size();j++){
		if(min[i]+v[i][j].second<min[v[i][j].first]){
			min[v[i][j].first]=min[i]+v[i][j].second;
			calc(v[i][j].first);
		}
	}
}

int main(){
	int n;
	std::cin>>n;
	while(n!=0){
		for(int i=0;i<10;i++)v[i].clear();
		int res=INF,res_num;
		std::vector<int>sum(10,0);
		for(int i=0;i<n;i++){
			int a,b,c;
			std::cin>>a>>b>>c;
			v[a].push_back(to_cost(b,c));
			v[b].push_back(to_cost(a,c));
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++)min[j]=INF;
			min[i]=0;
			calc(i);
			for(int j=0;j<10;j++){
				if(min[j]!=INF)sum[i]+=min[j];
			}
		}
		for(int i=0;i<10;i++){
			if(res>sum[i]&&sum[i]!=0)res=sum[i],res_num=i;
		}
		std::cout<<res_num<<" "<<res<<std::endl;
		std::cin>>n;
	}
	return 0;
}

Measured memory_bytes: 1196
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

X = int(input())

@lru_cache(None)
def rec(x):
    if x == 0:
        return True
    if x < 0:
        return False
    return any(rec(x-100-d) for d in range(6))

print(1 if rec(X) else 0)



Measured memory_bytes: 7140
#include <stdbool.h>
#include <stdio.h>
typedef long long ll;
int main() {
	int n, a[200000], pt = 0, cnt = 0, dis[200000] = {0};
	bool isReached[200000] = {0};
	ll k;
	int f;
	scanf("%d%lld", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	isReached[0] = true;
	while (1) {
		// printf("%d", pt);
		pt = a[pt] - 1;
		// printf(">%d\n", pt);
		cnt++;
		if (isReached[pt]) {
			f = (k - dis[pt]) % (cnt - dis[pt]);
			// printf("%lld %d %d\n", k, dis[pt], cnt);
			break;
		}
		dis[pt] = cnt;
		isReached[pt] = true;
		if (cnt == k) {
			printf("%d\n", pt + 1);
			return 0;
		}
	}
	for (int i = 0; i < f; i++) {
		pt = a[pt] - 1;
	}
	printf("%d\n", pt + 1);
	return 0;
}


Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, k;
string s;

string go(string s, int h){
    string ret;
    for(int i = h ; i < n ; i++){
        ret += s[i];
    }
    for(int i = n - 1 ; i >= n - h ; i--){
        ret += s[i];
    }
    return ret;
}
string calc(string s, int k){
    if(k == 0) return s;
    int cnt = 0;
    char c = s.back();
    while(cnt < n && s[n - cnt - 1] == c){
        cnt++;
    }
    if(cnt == n) return s;
    while(k > 1){
        cnt *= 2;
        k--;
        if(cnt >= n){
            return string(n, c);
        }
    }
    while(s.back() == c){
        s.pop_back();
    }
    s += string(cnt, c);
    s = s.substr((int)s.size() - n);
    int r = s.size() - 1;
    while(s[r] == c) r--;
    r++;
    return go(s, r);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k >> s;
    string ans = s;
    ans = min(s, calc(s, k));
    for(int i = 0 ; i <= n ; i++){
        string cur = go(s, i);
        ans = min(ans, calc(cur, k - 1));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3700
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

const int mod = 1000000007;
struct mint{
    ll x;
    mint(ll x=0):x(x%mod){}
    mint& operator+=(const mint a){
        if ((x+= a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if ((x+= mod - a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a) const{
        mint ans(*this);
        return ans+= a;
    }
    mint operator-(const mint a) const{
        mint ans(*this);
        return ans-= a;
    }
    mint operator*(const mint a) const{
        mint ans(*this);
        return ans*= a;
    }
};



int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if (A==B && B == C && A==C) {cout << "Yes"; rn 0;};
    cout << "No";
    rn 0;
}

Measured memory_bytes: 256