akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using LL = long long;

vector<vector<LL>> WarshallFloyd(auto A) {
  const auto N = A.size();
  for(auto k=0; k<N; ++k) for(auto i=0; i<N; ++i) for(auto j=0; j<N; ++j) A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
  return A;
}

LL solve(const auto& A) {
  if(A!=WarshallFloyd(A)) return -1;

  const auto N = A.size();
  LL sum = 0;
  for(auto i=0; i<N; ++i) for(auto j=0; j<N; ++j) {
    auto p = false;
    for(auto k=0; k<N; ++k) if(k!=i&&k!=j) p |= A[i][j] == A[i][k]+A[k][j];
    if(!p) sum += A[i][j];
  }
  return sum/2;
}

int main() {
  int N;
  cin >> N;
  vector<vector<LL>> A(N, vector<LL>(N));
  for(auto &i: A) for(auto& j: i) cin >> j;
  cout << solve(A) << endl;
}


Measured memory_bytes: 1664
/* Author haleyk10198 */
/* 作者:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))
#define vi vector<int>
#define vvi vector<vi>
#define EPS 1e-9

using namespace std;

int n, a[100010], b[100010], c[100010];
ll rb[100010], pb[100010];

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	for(int i = 0; i < n; i++)
		cin >> b[i];
	
	for(int i = 0; i < n; i++)
		cin >> c[i];
	
	sort(a, a+n), sort(b, b+n), sort(c, c+n);
	
	for(int i = 0, j = 0; i < n; i++){
		while(j < n && b[i] >= c[j])
			j++;
		rb[i] = n-j;
	}
	
	ll tot = accumulate(rb, rb+n, 0LL);
	ll res = 0;
	
	for(int i = 0, j = 0; i < n; i++){
		while(j < n && a[i] >= b[j])
			tot -= rb[j++];
		res += tot;
	}
	
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

ll l[100];

void init()
{
  l[0]=2;
  l[1]=1;
  for (int i=2;i<100;i++)
    l[i]=l[i-1]+l[i-2];
}

int main()
{
  int n;cin>>n;
  init();
  cout<<l[n]<<endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
res=1
z=10**18
for i in a:
    if(i==0):
        res=0
        break
i=n-1
while(i>=0):
    if(a[i]==0):
        res=0
        break
    if(res>z/a[i]):
        res=z+1
        break
    res*=a[i]
    if(a[i]>z):
        break
    i-=1
if(res>z):
    res=-1
print(res)

Measured memory_bytes: 21452
n=int(input())
a=[[""]*3 for ii in range(n)]
for ii in range(n):
  s=input().split()
  #print(s)
  a[ii][0]=s[0]
  a[ii][1]=100-int(s[1])
  a[ii][2]=ii
a.sort()
for ii in range(n):
  print(a[ii][2]+1)

Measured memory_bytes: 3064
var lines = [];
var N; var b = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    N = Number(lines[0]);
    b = lines[1].split(" ").map(value => Number(value));
    var result = [];
    
    // 数列の要素数回ループする
    for (var i = 0; i < N; i++) {
        var target = -1;
        
        // 数列を検索し，削除する要素を決定する
        // 削除可能な要素は，b[j-1] === j となるb[j-1]
        for (var j = 1; j <= b.length; j++) {
            if (b[j - 1] === j) { target = j; }
        }
        
        //削除可能な要素があれば，b[j-1]を削除
        if (target !== -1) result.unshift(b.splice(target - 1, 1));
        
        // 削除可能な要素が無ければ，-1
        else { console.log(-1); return (0) }
    }
    // 結果表示
    for (var i = 0; i < result.length; i++)
        console.log(result[i].toString());
});

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

using namespace std;

int main(){

string s;
  cin >> s;
  
  int res=1000;
  
  for(int i=0;i<s.length()-2;i++){
   res=min(abs(stoi(s.substr(i,3))-753),res);
  
  }

 cout << res << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M;
int A[1<<17],B[1<<17];
bool used[2<<17];
int cumsum[1<<17];
pair<int,int>AB[1<<17];
vector<pair<int,int> >E[1<<17];
vector<pair<int,int> >calc;
main()
{
	cin>>N>>M;
	{//入力をソート・圧縮する
		for(int i=0;i<N;i++)cin>>AB[i].first>>AB[i].second;
		sort(AB,AB+N);
		for(int i=0;i<N;i++)
		{
			A[i]=AB[i].first;
			B[i]=AB[i].second;
		}
		for(int i=0;i<M;i++)
		{
			int L,R;cin>>L>>R;
			L=lower_bound(A,A+N,L)-A;
			R=upper_bound(A,A+N,R)-A;
			if(L<R)E[L].push_back(make_pair(R,i));
		}
	}
	{//掃き出す
		for(int i=0;i<N;i++)
		{
			if(E[i].empty())continue;
			sort(E[i].begin(),E[i].end());
			for(int j=E[i].size()-1;j>=1;j--)//逆順に隣接要素を見る
			{
				int L=E[i][j-1].first,R=E[i][j].first;
				if(L<R)
				{
					E[L].push_back(make_pair(R,E[i][j].second));
					calc.push_back(make_pair(E[i][j-1].second,E[i][j].second));//第 first 行を第 second 行に足した
				}
			}
		}
	}
	{//x'を求める
		for(int i=0;i<N;i++)
		{
			if((B[i]+cumsum[i])%2==1)//爆弾がオンになっている
			{
				if(E[i].empty())//その行に1の要素がない
				{
					cout<<-1<<endl;
					return 0;
				}
				pair<int,int>p=E[i][0];//先頭の要素以外は掃き出されているため使えない
				used[p.second]=true;
				cumsum[i]++;cumsum[p.first]--;//imos法
			}
			cumsum[i+1]+=cumsum[i];
		}
	}
	{//掃き出す操作を巻き戻す
		reverse(calc.begin(),calc.end());
		for(pair<int,int>p:calc)used[p.first]^=used[p.second];//第 second 列を第 first 列に足す
	}
	{//出力
		int cnt=0;
		for(int i=0;i<M;i++)cnt+=used[i];
		cout<<cnt<<endl;
		for(int i=0;i<M;i++)
		{
			if(used[i])cout<<i+1<<(--cnt?" ":"\n");
		}
	}
}

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

template <class T>
inline void read(T &x) {
	static char ch; 
	static bool opt; 
	while (!isdigit(ch = getchar()) && ch != '-'); 
	x = (opt = ch == '-') ? 0 : ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
	if (opt)
		x = ~x + 1; 
}

template <class T>
inline void putint(T x) {
	static char buf[45], *tail = buf; 
	if (!x)
		putchar('0'); 
	else {
		if (x < 0)
			putchar('-'), x = ~x + 1; 
		for (; x; x /= 10) *++tail = x % 10 + '0'; 
		for (; tail != buf; --tail) putchar(*tail); 
	}
}

template <class T>
inline bool tense(T &x, const T &y) {
	return y < x ? x = y, true : false; 
}

template <class T>
inline bool relax(T &x, const T &y) {
	return x < y ? x = y, true : false; 
}

template <class T>
inline T getAbs(const T &x) {
	return x < 0 ? -x : x; 
}

typedef long long s64; 
typedef long double ld; 
typedef std::vector<int> vi; 
typedef std::pair<int, int> pii; 
#define mp(x, y) std::make_pair(x, y)

const int MaxN = 2e5 + 5; 
const int MaxS = MaxN << 2; 

const int INF = 0x3f3f3f3f; 

#define lcc x << 1, l, mid
#define rcc x << 1 | 1, mid + 1, r

int n, m, cur; 
int seg[MaxS], tag[MaxS]; 

inline void upt(int x) {
	seg[x] = std::min(seg[x << 1], seg[x << 1 | 1]); 
}

inline void nodeCover(int x, int l, int r, int val) {
	seg[x] = l - val; 
	tag[x] = val; 
}

inline void dnt(int x, int l, int r) {
	if (tag[x]) {
		int mid = (l + r) >> 1; 
		nodeCover(lcc, tag[x]); 
		nodeCover(rcc, tag[x]); 
		tag[x] = 0; 
	}
}

inline void segCover(int u, int v, int t, int x = 1, int l = 1, int r = m) {
	if (u <= l && r <= v) {
		nodeCover(x, l, r, t); 
		return; 
	}
	dnt(x, l, r); 

	int mid = (l + r) >> 1;
	if (u <= mid) segCover(u, v, t, lcc); 
	if (v >  mid) segCover(u, v, t, rcc); 
	upt(x); 
}

inline int segQuery(int p, int x = 1, int l = 1, int r = m) {
	if (l == r)
		return p - seg[x]; 
	dnt(x, l, r); 

	int mid = (l + r) >> 1;
	return p <= mid ? segQuery(p, lcc) : segQuery(p, rcc); 
}

int main() {
#ifdef orzczk
	freopen("a.in", "r", stdin); 
#endif

	read(n), read(m); 
	cur = 1; 

	for (int i = 1; i <= n; ++i) {
		int l, r; 
		read(l), read(r); 

		if (cur >= l && cur <= r) {
			segCover(cur, r, -INF); 
			cur = r + 1; 
		} else if (cur < l) {
			segCover(l, r, segQuery(l - 1)); 
		}

		if (cur > m) {
			for (int j = i; j <= n; ++j) {
				puts("-1"); 
			}
			return 0; 
		}

		printf("%d\n", i + seg[1]); 
	}

	return 0; 
}

Measured memory_bytes: 7792
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int dp[1<<15][5];

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    
    dp[0][0] = 1;
    for(int i=1; i<1<<10; i++){
        for(int j=1; j<1<<15; j++){
            for(int k=0; k<4; k++){
                if(i*i <= j)
                    dp[j][k+1] += dp[j-i*i][k];
            }
        }
    }
    
    int n;
    while(cin>>n, n){
        int ans = 0;
        for(int i=1; i<=4; i++)
            ans += dp[n][i];
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1832
import sys
s = input()

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print(i+1, i+2)
        sys.exit(0)
    if i < len(s)-2:
        if s[i] == s[i+2]:
            print(i+1, i+3)
            sys.exit(0)
print("-1 -1")
sys.exit(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int n,m,k,ans;
long long a[200004],b[200004];
int main() {
	cin>>n>>m>>k;
	for (int i=1;i<=n;i++) {
	cin>>a[i];
	a[i]=a[i-1]+a[i];
	}
	for(int i=1;i<=m;i++){
    cin>>b[i];
	b[i]=b[i-1]+b[i];
	}
	for(int i=0;i<=n;i++){
        if(k>=a[i]){
		    int res=upper_bound(b+1,b+1+m,k-a[i])-b-1;
		    ans=max(ans,res+i);
	    }
    }
	cout<<ans;
    return 0;
}

Measured memory_bytes: 6672
import java.util.*;

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

      int b = 0;
      int s = 0;
      while(true){
          h =h + 1;
          int a =h*3600;
          if (a > sc){
              h = h - 1;
              break;
          }
      }

      int q = sc - h*3600;

      while(true){
          b = b + 1;
          int a =b*60;
          if ( a > q){
              b -= 1;
              break;
          }
      }



      s = q - b*60;
      System.out.println(String.valueOf(h) + ":" +String.valueOf(b) + ":"+String.valueOf(s));
      }
   }

Measured memory_bytes: 26072
#include <stdio.h>
#include <string.h>

int main(int argc, const char * argv[]) {
    char a[200]={0};
    int x=0,i=0,y=0,z=0,j=0,l=0;
    
    while(1){
        scanf("%s",a);
        l=strlen(a);
        if(a[0]=='-'){
            break;
        }
        scanf("%d",&x);
        for(i=0;i<x;i++){
            scanf("%d",&y);
            z+=y;
        }
        for(j=0;j<l;j++){
            printf("%c",a[(z+j)%l]);
        }
        printf("\n");
        z=0;
    }
    return 0;
}

Measured memory_bytes: 568
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	long long X;
	cin >> X;
	long long total = 100;
	
	int i = 0;
	while(total < X){
		 total += total / 100;
		 //cout << total << endl;
		i++;
	}
	cout << i << endl;
}




Measured memory_bytes: 3644
using System;
using System.Collections.Generic;

namespace AtCoder.AGC025
{
    class a
    {
        static Dictionary<int, long> fact = new Dictionary<int, long>();

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var cnt = 0;
            for(var i = 0; i < line.Length; ++i)
            {
                cnt += line[i] - '0';
            }
            Console.WriteLine(cnt != 1 ? cnt : 10);
        }
    }
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int a=0,b=0;
	for (int i=0; i<3; i++) {
		if (s[i]=='A') a++;
		else b++;
	}
	if (a==1 && b==2) cout << "Yes";
	else if (b==1 && a==2) cout << "Yes";
	else cout << "No";
	return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  
  vector<int> x(n);
  for ( int i = 0; i < n; i++){
    cin >> x[i];
  }
  
  sort(x.begin(),x.end());
  
  int goukei,saishou = 10000000000;
  
  for ( int i = x[0]; i <= x[n-1]; i++){
    goukei = 0;
    for ( int j = 0; j < n; j++){
      goukei += ( x[j] - i ) * ( x[j] - i );
    }
    saishou = min(saishou,goukei);
  }
  
  
  cout << saishou << endl;
  
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back //FASTER THAN PUSH BACK!
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int n)
{
    if(n==0) return 1;
    if(n==1) return a;
    int res=modp(a,n/2);
    if(n%2==0) return (res*res);
    else return (a*res*res);
}

// vi adj[1000000];


void solve()
{
    int t,n,m,i,k,l,r,u,v,w,j,s,sum=0,pos=-1,flag=0,count=0;
    string S,T,U;
    // int a,b;
    cin>>n;
    int powers[120];
    rep(i,0,120) powers[i]=modp(i,5);
    int negpowers[120];
    rep(i,1,120) negpowers[i]=-1LL*powers[i];
    rep(i,120,0)
    {
        rep(j,120,0)
        {
            if(powers[i]-powers[j]==n)
            {
                cout<<i<<" "<<j;
                return;
            }
        }
    }
    rep(i,120,0)
    {
        rep(j,1,120)
        {
            if(powers[i]-negpowers[j]==n)
            {
                cout<<i<<" -"<<j;
                return;
            }
        }
    }

}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    int P[100000],Y[100000];
    vector<int> yd[100001];

    for(int i=0;i<m;i++){
        cin >> P[i] >> Y[i];
        yd[P[i]].push_back(Y[i]);
    }
    for(int i=0;i<n;i++){
        sort(yd[i+1].begin(),yd[i+1].end());
    }
    for(int i=0;i<m;i++){
        printf("%06d%06d\n"
        ,P[i]
        ,int(lower_bound(yd[P[i]].begin(),yd[P[i]].end(),Y[i])-yd[P[i]].begin())+1
        );
    }

}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

class Combi {
private:
  v(ll) fac, inv, finv;
  void init(int N) {
    fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1;
    for (int i = 2; i < N; 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;
    }
  }
public:
  Combi(int N) : fac(N + 1), inv(N + 1), finv(N + 1) { init(N + 1); }
  ll Cmod(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 Pmod(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
  }
};
  
int main() {
  int N,K;
  cin >> N >> K;
  vl A(N);
  rep(i,N) {
    cin >> A[i];
  }
  sort(rng(A));
  Combi C = Combi(N);
  vl nums(N,0);
  rep(i,N) {
    int n = N - i - 1;
    if(n < K-1) break;
    nums[i] = C.Cmod(n,K-1);
  }
  ll ans = 0;
  rep(i,N) {
    ans -= nums[i] * A[i];
    ans = (ans+MOD)%MOD;
  }
  reverse(rng(nums));
  rep(i,N) {
    ans += nums[i] * A[i];
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4224
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

c = 0
for i in range(N):
    taosu = A[i]-B[i]
    if A[i]+A[i+1]-B[i] >= 0:
        taosita = B[i]
    else:
        taosita = A[i]+A[i+1]

    if taosu < 0:
        A[i+1] = A[i+1]+taosu
        if A[i+1] < 0:
            A[i+1] = 0
    c += taosita

print(c)


Measured memory_bytes: 18624
MOD = 10 ** 9 + 7

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % MOD

def p(n, r):
    return g1[n] * g2[n-r] % MOD

maxN = 5*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, maxN + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

def solve():
    N, M = map(int, input().split())
    ans = 0
    for k in range(N+1):
        x = 0
        tmp = p(M-k, N-k)
        x = cmb(N, k) * p(M, k) * tmp * tmp
        if k%2==1:
            x *= -1
        ans = (ans + x) % MOD
    print(ans)

solve()

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

int main(void)
{
  int A, B, C;
  cin >> A >> B >> C;
  string result = "No";

  if (A == B && A != C)
  {
    result = "Yes";
  }
  else if (A == C && A != B)
  {
    result = "Yes";
  }
  else if (B == C && A != B)
  {
    result = "Yes";
  }

  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
    string A,B;
    cin>>A>>B;
    ll lenA = A.size(),lenB = B.size();
    if(lenA>lenB)puts("GREATER");
    else if(lenA<lenB)puts("LESS");
    else
    {
        for(int i=0; i<lenA; i++)
        {
            if(A[i]>B[i])
            {
                puts("GREATER");
                return 0;
            }
            else if(A[i]<B[i])
            {
                puts("LESS");
                return 0;
            }
        }
        puts("EQUAL");
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(){
    int S = 0;
    scanf("%d", &S);
    int h, m, s;
    h = S / 3600;
    S %= 3600;
    m = S / 60;
    S %= 60;
    s = S;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  int n = 1;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == n) {
      n++;
    } else {
      ans++;
    }
  }

  cout << (ans == N ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int i;
	string s;
	cin >> s;
	for(i=1; i<4; ++i){
		if(s[i-1]==s[i]){
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	int a,b;
	scanf("%d %d",&a,&b);

	if(a <= b){

		printf("%d\n",a);

	}else{

		printf("%d\n",a-1);
	}

	return 0;
}


Measured memory_bytes: 3812
#include <iostream>
using namespace std;
int main()
{
    int n = 0, m = 0, i = 0, a[52] = {0}, b[52] = {0}, num[52] = {0};
    cin >> n >> m;
    for(i = 1; i <= m; i++)
    {
        cin >> a[i] >> b[i];
        num[a[i]]++;
        num[b[i]]++;
    }
    for(i = 1; i <= n; i++)
    {
        cout << num[i] << endl;
    }
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
int a,b,k=0;
scanf ("%d%d",&a,&b);
if (a>b){
k=k+a;
a--;
}
else {
k=k+b;
  b--;
}
if (a>b){
k=k+a;
a--;
}
else {
k=k+b;
  b--;
}
printf ("%d",k);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	int n, k, c;
	string s;
	int count = 0;
	cin >> n >> k >> c >> s;
	vector<int> d(k), f(k);
	for(int i = 0; i < n; i++) {
		if (s[i] == 'o') {
			d[count] = i;
			count++;
			i += c;
			if (count == k) break;
		}
	}
	for(int i = n - 1; i >= 0; i--) {
		if (s[i] == 'o') {
			count--;
			f[count] = i;
			i -= c;
			if (count == 0) break;
		}
	}
	bool nun = true;
	rep (i, k) {
		if (d[i] == f[i]) {
			cout << d[i]+1 << endl;
			nun = false;
		}
	}
	if (nun) cout << endl;
	return 0;
}


Measured memory_bytes: 5040
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a1 = 0
a2 = 0
l = []
for i in range(n):
    value = inp()
    if(value > a1):
        a1 = value
    elif(value >= a2):
        a2 = value
    l.append(value)
for t in l:
    if(a1 == t):
        print(a2)
    else:
        print(a1)


Measured memory_bytes: 93324
import sys

N = int(input())
Bs = 2**10

Fs = []
Ps = []
l1 = []
for _ in range(N):
  s = int(input().replace(' ', ''), 2)
  Fs.append(s)
for _ in range(N):
  Ps.append(list(map(int, input().split())))

rlt = -sys.maxsize
for b in range(1,Bs):
  tmp = 0
  for i in range(N):
    t = b&Fs[i]
    t = bin(t)[2:]
    c = t.count('1')
    tmp += Ps[i][c]
  rlt = max(rlt, tmp)
  
print(rlt)
    

Measured memory_bytes: 74088
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <queue>
#include <map>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main() {
    int N;
    cin >> N;
    vi p(N);
    int c = 0;
    for(int i=0; i<N; i++) cin >> p.at(i);

    for(int i=0; i<N; i++){
        if(p.at(i) != i+1){
            c++;
        }
        if(c > 2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <deque>
#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

int main() {
    bool move = false;
    string s;
    cin >> s;

    std::deque<char> result;

    for(char c : s)
        result.push_back(c);

    int Q;
    cin >> Q;

    for( int i = 0; i < Q; ++i) {
        int q;
        cin >> q;

        if (q == 1)
            move = !move;
        else{
            cin >> q;
            char c;
            cin >> c;

            if(move)
            {
                if( q == 1 ) q = 2;
                else q = 1;
            }

            if(q == 1)
                result.push_front(c);
            else
                result.push_back(c);
        }
    }

    if(!move){
        while(!result.empty()) {
            char c = result.front();
            result.pop_front();
            cout << c;
        }
    }
    else{
        while(!result.empty()) {
            char c = result.back();
            result.pop_back();
            cout << c;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    char C[6];
    for(int i=0;i<6;i++)
        cin >> C[i];

    if(C[0] != C[5] || C[1] != C[4] || C[2] != C[3])
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    

}

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

main(){
	for(int i=0; i<9; ++i){
		// クラス名
		char name[16];
		
		// 午前の入場者数, 午後の入場者数
		int a, b;
		
		cin >> name >> a >> b;
		
		// 入場総数
		int x = a + b;
		
		// 収入 (午前200円, 午後300円)
		int y = 200*a + 300*b;
		
		printf("%s %d %d\n",name,x,y);
	}
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    if(a+b==15) {
        cout<<"+\n";
    }
    else
        if(a*b==15)
            cout<<"*\n";
        else
            cout<<"x\n";
    return 0;
}
/**
**/


Measured memory_bytes: 256
#include <stdio.h>
int main( void )
{
	 int A, B;

	 scanf("%d %d", &A, &B);
	 if( A <= 8 && B <= 8 ) {
		 printf("Yay!\n");
	 } else {
		 printf(":(\n");
	 }

	 return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<cstdio>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	Int all = 1;//確率全体の分母
	while (all <= K - 1) {
		all *= 2;
	}

	Int temp = 0;
	for (Int i = 1; i <= min(N,K-1); i++) {
		Int temp1 = i;
		Int temp2 = all;
		while (temp1 <= K - 1) {
			temp1 *= 2;
			temp2 /= 2;
		}
		temp += temp2;
	}

	temp += all * (max(0LL, N - K + 1));

    double ans = 0;
	ans = (double) temp / all / N;

	printf("%.20lf\n", ans);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200005 ;
ll  power(ll  i,ll  j)
{
    if(j==0)
    return 1 ;
    ll t=power(i,j/2)%maa ;
    if(j%2==0)
    return (t%maa*t%maa)%maa ;
    else
    return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
}
vector<ll>v[N] ;
ll num[N],dp[N] ;
ll ans[N] ;
ll n ;
ll fac[N] ;
ll dfs(ll i,ll p)
{
    ll sum=0 ;
    ll ways=1 ;
    ll denom=1 ;

    for(ll j:v[i])
    {
        if(j==p)
            continue ;

        ll no=dfs(j,i) ;
        sum+=no ;
        denom=(denom*fac[no])%maa ;
        ways=(ways*dp[j])%maa ;

    }

    ways=(ways*fac[sum])%maa ;
    ways=(ways*power(denom,maa-2))%maa ;

    dp[i]=ways ;
    return num[i]=sum+1 ;
}
void dfs1(ll i,ll p,ll vl,ll no)
{
    ll cur=vl ;

    for(ll j:v[i])
    {
        if(j==p)
            continue ;

        cur=(cur*dp[j])%maa ;
     //  cout<<j<<" % "<<dp[j]<<endl ;
        cur=(cur*power(fac[num[j]],maa-2))%maa ;
    }
    //cout<<" "<<cur<<" " ;
    cur=(cur*fac[n-1])%maa ;
    cur=(cur*power(fac[no],maa-2))%maa ;

    ans[i]=cur ;
   // cout<<i<<" "<<cur<<" "<<vl<<" "<<no<<endl ;
    //cout<<cur<<endl ;

    for(ll j:v[i])
    {
        if(j==p)
            continue ;

        ll ncur=cur ;

        ncur=(ncur*power(dp[j],maa-2))%maa ;
        ncur=(ncur*power(fac[n-1],maa-2))%maa ;
        ncur=(ncur*fac[n-1-num[j]])%maa ;
        ncur=(ncur*fac[num[j]])%maa ;
         //cout<<j<<"# "<<ncur<<endl ;
        dfs1(j,i,ncur,n-num[j]) ;


    }

}
int main()
{
   fast ;
   ll tests=1 ;
   ///cin>>tests ;
   for(ll testcase=1;testcase<=tests;testcase++)
   {
      ///cout<<"Case #"<<testcase<<": " ;
      ///Read,Think ans Test Properly,then code
      ///Try to avoid using print statements debug on your own
      fac[0]=1 ;
      for(ll i=1;i<N;i++)
      {
          fac[i]=(fac[i-1]*i)%maa ;
      }
      cin>>n ;
      for(ll i=0;i<n-1;i++)
      {
          ll a,b ;
          cin>>a>>b ;
          v[a].pb(b) ;
          v[b].pb(a) ;
      }
      dfs(1,-1) ;
      ans[1]=dp[1] ;
      dfs1(1,-1,1,1) ;

      for(ll i=1;i<=n;i++)
        cout<<ans[i]<<endl ;



    }
}
/// ans ->for answer
/// cur ->for local answer
/// level ->for depth in tree
/// v -> adjacency matrix
/// r -> array
/// s ->string



Measured memory_bytes: 20976
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;

#define pb push_back

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

    ll t,a,b;
    cin>>a>>b;
    if(a==b)
        cout<<"Yes";
    else
        cout<<"No";


    return 0;
}



Measured memory_bytes: 256
main :: IO ()
main = do
  s <- getLine :: IO String
  print $ f (reverse s)

f :: String -> Int
f (x:xs) 
  | odd $ length xs = f xs 
  | otherwise = let half = length xs `div` 2 
                   in if take half xs == drop half xs then half * 2 else f xs                              
  


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
int N;
int A[200001];
int main(){
	int N ;
	cin >> N;
	
	for(int i = 1; i <= N; i++){
		cin >> A[i];
	}
	
	int max = INT_MIN;
	int max_i;
	int max2 = INT_MIN;
	int max2_i; 
	for(int i = 1; i <= N ; i++ ){
		if( A[i] >= max ){
			max2_i = max_i;
			max2 = max;
			max_i = i;
			max = A[i];
		}else if( A[i] >= max2 ){
			max2 = A[i];
			max2_i = i;
		}
	}
	
	for(int i = 1; i<= N; i++){
		if(i == max_i) cout << max2 << endl;
		else cout << max << endl;
	}
}

Measured memory_bytes: 2432
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    n, m, k = map(int, input().split())

    u = UnionFind(n)
    f_cnt = [0] * n
    b_cnt = [0] * n

    for _ in range(m):
        a, b = map(int, input().split())
        u.union(a - 1, b - 1)
        f_cnt[a - 1] += 1
        f_cnt[b - 1] += 1

    for _ in range(k):
        c, d = map(int, input().split())
        if u.same(c - 1, d - 1):
            b_cnt[c - 1] += 1
            b_cnt[d - 1] += 1

    print(*[(u.size(i) - f_cnt[i] - b_cnt[i] - 1) for i in range(n)])


Measured memory_bytes: 14128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define gnr(i,l,r) for(int i=int(r)-1; i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;



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

  cin>>n; int a[n]; rep(i,n)cin>>a[i]; stack<int> ans;
  rep(i,n){
    ok=0;
    gnr(j,0,n){
      if(a[j]==j+1){rer(k,j,n-1)a[k]=a[k+1]; a[n-1]=0; ok=true; ans.push(j+1); break;}
    }
    if(!ok){pri1(-1); return 0;}
  }
  rep(i,n){x=ans.top(); pri1(x); ans.pop();}
}

Measured memory_bytes: 256
#include <cstdio>
#include <string.h>

#define MOD 1000000007

typedef long long int lli;
int a[200000];

void EE(lli a, lli b, lli& x, lli& y)
{
    if(a%b == 0)
    {
        x=0;
        y=1;
        return;
    }
    EE(b,a%b,x,y);
    lli temp = x;
    x = y;
    y = temp - y*(a/b);
}

lli inverse(lli a, lli m)
{
    lli x,y;
    EE(a,m,x,y);
    if(x<0) x += m;
    return x;
}

int main(void) {
    int n,duppos1, duppos2;
    memset(a, 0xff, sizeof(a));
    scanf("%d", &n);
    for(int i=0; i<n+1; i++) {
        int j;
        scanf("%d", &j);
        if(a[j] != -1) duppos1 = a[j], duppos2 = i;
        a[j] = i;
    }

    lli sum = n+1;
    lli a = duppos1;
    lli c = (n+1) - duppos2 - 1;
    lli sub = 1;
    for(int k=1; k<=n+1; k++) {
        lli res = sum - sub;
        res %= MOD;
        res += MOD;
        res %= MOD;
        printf("%lld\n", res);
        sum *= (n+1-k);
        sum %= MOD;
        sum *= inverse(k+1, MOD);
        sum %= MOD;
        sub = ((sub * (a+c-k+1)) % MOD) * inverse(k, MOD);
        sub %= MOD;

    }
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};
bool dp[MAX_N]={};

int main() {
	int s,w;
    cin>>s>>w;
    if(s>w){
        cout<<"safe"<<endl;
    }else{
        cout<<"unsafe"<<endl;
    }
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,n,h) for(int i = n; i < h; ++i)
#define rep3(l,n,h) for(int l = n; l <= h; ++l)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int  main(void) {
        int n,s,t;
        cin >> n >> t;
    vector<int> m;
        int b[n][2];
        for(int i = 0; i < n; i++){
            for(int k = 0; k < 2; k++){
                cin >> b[i][k];
            }
        }
    int ans = INT_MAX;
        for(int l = 0; l < n; l++){
                if(t >= b[l][1]){
                    ans = min(ans, b[l][0]);
            }
        }
        if(ans != INT_MAX){
            cout << ans;
        }else{
            cout << "TLE";
        }

}

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: map(fn, readline().split())
gete = lambda fn: fn(readline())


N, W = geta(int)
cur = [0] * (W+1) 

for i in range(N):
    w, v = geta(int)
    update = cur[:]
    for j in range(w,W+1):
        tmp = cur[j-w] + v
        if tmp > cur[j]: update[j] = tmp
    
    cur = update

print(cur[W])


Measured memory_bytes: 82116
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int X, A, B;
    cin >> X >> A >> B;
    cout << (X - A) % B << endl;
    return 0;
}


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

public class Main{

	private static final long mod =(long)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);

	   int n=sc.nextInt();
	   if(n==1) {
	     System.out.println(0);
	   }else if(n==2) {
	     System.out.println(2);
	   }else {
	     System.out.println(((pow(10,n)%mod-2l*pow(9,n)%mod+pow(8,n)%mod)+mod)%mod);
	   }
	}


	static boolean vis[]=new boolean[10001];
	      static long gcd(long a, long b) 
	      { 
	          if (a == 0) 
	              return b; 
	          return gcd(b % a, a); 
	      } 

static long nCr(int n,int r) {
  int dp[][]=new int[1000001][3];
  for(int i=0;i<3;i++) {
    dp[0][i]=0;
  }
  for(int i=0;i<1000001;i++) {
    dp[i][0]=1;
  }
  for(int i=1;i<1000001;i++) {
    for(int j=0;j<3;j++) {
      if(i==j||j==0) {
        dp[i][j]=1;
      }else {
        dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
      }
    }
  }
  return dp[n][r];
}
static long pow(long x,long y) {
  long res=1l;
  while(y!=0) {
    if(y%2==1) {
      res=x*res%mod;
    }
    y/=2;
    x=x*x%mod;
  }
  return res;
}     
}

Measured memory_bytes: 36048
//#include<bits/stdc++.h>
//#include<cmath>
//#include<string>
//#include<sstream>
#include<iostream>
using namespace std;
int main()
{
	int n{0};
	cin>>n;
	int p[n]={0};
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	}
	int a[n-1];
	for(int i=0;i<n-1;i++)
	{
		if(p[i]<p[i+1])
		{
			a[i]=1;
		}
		else
		{
			a[i]=0;
		}
	}
	int count=0;
	for(int i=0;i<n-2;i++)
	{
		if(a[i]==a[i+1])
		{
			count++;
		}
	}
	cout<<count;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

const int BIG_NUM = 1e9;

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

    int x, a;
    cin >> x >> a;
    if(x < a) {
        cout << "0";
    } else {
        cout << "10";
    }
    return 0;
}


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

int main(){

  long long int ans,x,y,z,k,a,b,c;
  vector<long long int> v,va,vb,vc;

  cin >> x >> y >> z >> k;
  if(x*y*z < k){
    k = x*y*z;
  }

  for(int i=0;i<x;i++){
    cin >> a;
    va.push_back(a);
  }
  sort(va.begin(), va.end(), greater<long long int>());

  for(int i=0;i<y;i++){
    cin >> b;
    vb.push_back(b);
  }
  sort(vb.begin(), vb.end(), greater<long long int>());

  for(int i=0;i<z;i++){
    cin >> c;
    vc.push_back(c);
  }
  sort(vc.begin(), vc.end(), greater<long long int>());

  for(int i=0;i<x;i++){
    for(int j=0;j<y;j++){
      for(int l=0;l<z;l++){
        if(i*j*l<=k){
          v.push_back(va[i]+vb[j]+vc[l]);
        }
        else{break;}
      }
    }
  }
  sort(v.begin(), v.end(), greater<long long int>());

  for(int i=0;i<k;i++){
    cout << v[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 35184
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
 
int main(){
int d,n;
cin>>d>>n;
if (n==100){
  n=101;
  for (;d--;) n*=100;
  cout<<n;return 0;
  }
for (;d--;) n*=100;
cout<<n;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv vector<vector<int> >
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



int main(){
int n;cin>>n;
vector<tuple<int,int,int>>a;
rep(i,n){
  int x,y,h;
  cin>>x>>y>>h;
  a.emplace_back(h,x,y);
}
sort(all(a));
reverse(all(a));
ll hi=0;
rep(i,101){
  rep(j,101){
    rep(k,n){
      ll hi2=0;
      hi2=get<0>(a.at(k))+abs(get<1>(a.at(k))-i)+abs(get<2>(a.at(k))-j);
      //cout<<hi2<<endl;
      if(get<0>(a.at(k))==0){
        ll iti=abs(get<1>(a.at(k))-i)+abs(get<2>(a.at(k))-j);
        
        if(hi-iti<=0){
          
          if(k==n-1){
         cout<<i<<" "<<j<<" "<<hi<<endl;
         return 0;
       } 
          continue;
          
        }
        else break;
      }
      if(hi2<1)break;
      if(k==0)hi=hi2;
      if(hi==hi2){
       if(k==n-1){
         cout<<i<<" "<<j<<" "<<hi<<endl;
         return 0;
       } 
        continue;
      }
      else break;
    }

  }
}


return 0;
}

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

int main(){
  int k=0;
  string S;
  string T;
  cin >> S >> T;
    for(int i=0; i<3; i++){
    if(S.at(i)==T.at(i)){
      k++;
    }
      else{
        continue;
      }
    }
  cout << k << endl;
  }

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N, M;
	priority_queue<P, vector<P>, greater<P> > A;
	llong B, C;

	cin >> N >> M;

	P in;
	for (int i = 0; i < N; i++) {
		cin >> in.first;
		in.second = 1;
		A.push(in);
	}

	for (int i = 0; i < M; i++) {
		cin >> B >> C;
		llong era = B;
		while(era) {
			if (A.top().first >= C)
				break;
			if (A.top().second <= era) {
				era -= A.top().second;
				A.pop();
			} else {
				P next = A.top();
				next.second -= era;
				era = 0;
				A.pop();
				A.push(next);
			}
		}
		A.push(P(C, B-era));
	}

	llong ans = 0;
	while(A.size()) {
		// cerr << A.top().first << " " << A.top().second << endl;
		ans += A.top().first * A.top().second;
		A.pop();
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2420
N,W = map(int,input().split())

items = tuple(tuple(map(int,input().split())) for _ in range(N))

V = sum(v for w,v in items)

dp = [float('inf')]*(V+1)
dp[0] = 0
for w,v in items:
  for j in reversed(range(V-v+1)):
    dp[j+v] = min(dp[j+v], dp[j]+w)

print(max(v for v,w in enumerate(dp) if w <= W))

Measured memory_bytes: 112852
def f(n, m)
  if n == 1
    return 1
  else
    return (f(n - 1, m) + m - 1) % n + 1
  end
end

def main(input = STDIN)
  while (n, m = input.gets.split(" ").map(&:to_i)) != [0, 0]
    puts f(n, m)
  end
end
main

Measured memory_bytes: 6200