akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
int main(void){
    char s[200010];
    scanf("%s",s);
    
    int i=0;
    while(strncmp(&s[i], "\0", 1)!=0) i++;
    
    int a=0, z=i-1; 
    while(strncmp(&s[a], "A", 1)!=0) a++;
    while(strncmp(&s[z], "Z", 1)!=0) z--;
    
    printf("%d", z-a+1);
    
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int a[n];
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  int ans[n];
  for(int i = n - 1; i >= 0; i--){
    int s = 0;

    for(int j = 0; j < n / (i + 1) - 1; j++){
      //printf("%d!!!!!!!!\n", ans[]);
      s = (s + ans[(i + 1) * (j + 2) - 1]) % 2;
    }

    ans[i] = (a[i] ^ s);
  }
  int sum = 0;
  for(int i = 0; i < n; i++){
    sum += ans[i];
  }
  printf("%d\n", sum);
  for(int i = 0; i < n; i++){
    if(ans[i]){
      printf("%d ", i + 1);
    }
  }
  if(sum){
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2432
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, k; cin >> n >> k;
    if(n % k == 0) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  char x[60];
  int N, K;
  cin>>N>>K;
  for(int i = 0;i<N;i++){
    cin>>x[i];
    if(x[K-1] == 'A'){
      x[K-1] = 'a';
    }
     if(x[K-1] == 'B'){
      x[K-1] = 'b';
    }
     if(x[K-1] == 'C'){
      x[K-1] = 'c';
    }
  }
  for(int i = 0;i<N;i++){
  cout << x[i];
  }
}
  
  

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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


    int l, r, d;
    cin >> l >> r >> d;

    --l;
    cout << r / d - l / d << endl;
}


Measured memory_bytes: 3612
import numpy as np

def check(board):
    for i in range(3):
        if min(board[i]) == 1:
            return True
        if min(board[:, i]) == 1:
            return True
        if min(np.diag(board)) == 1:
            return True
        if board[0][2] == board[1][1] == board[2][0] == 1:
            return True
    return False


A = np.array([list(map(int, input().split())) for _ in range(3)])
N = int(input())
board = np.zeros((3, 3))
for i in range(N):
    B = int(input())
    board[np.where(A == B)] = 1
if check(board):
    print('Yes')
else:
    print('No')

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

string s="zabcdefghijklmnopqrstuvwxy";

int main(){
  ll n;
  cin>>n;
  vector<int> p;
  ll b=n;;
  while(b>=26){
    p.pb(b%26);
    if(b%26==0) b=b/26-1;
    else b/=26;
  }
  if(b) p.pb(b);
  vector<char> ans;
  rep(i,p.size()){
    ans.pb(s[p[i]]);
  }
  for(int i=ans.size()-1;i>=0;i--) cout<<ans[i];
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct Node{
	int l,r;
	bool operator < (const Node &b)const{return l<b.l;}
}a[N];
int main(){
	int n,x,l,ans=0,now=-1e9;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",&x,&l),a[i].l=x-l,a[i].r=x+l;
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i].l>=now)ans++,now=a[i].r;
		else if(a[i].r<now)now=a[i].r;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
def comInit(MOD, n):
    fact=[1,1] # fact[n]はnの階乗
    invr=[0,1] # invr[n]はnの逆元
    invr_fact=[1,1] # invr_fact[n]は逆元の階乗

    for i in range(2,n+1):
        fact.append(fact[-1]*i%MOD)
        invr.append(-invr[MOD%i]*(MOD//i)%MOD)
        invr_fact.append(invr_fact[-1]*invr[-1]%MOD)
    return fact,invr_fact

def calCom(n,k,MOD,fact,invr_fact):
    k=min(k,n-k)
    return fact[n]*invr_fact[k]*invr_fact[n-k]%MOD

n,k = map(int,input().split())
mod = 10**9+7
dp = [None] * min(n-k+1,k)
dp[0] = (1 * (n-k+1)) % mod
print(dp[0])
f,inv = comInit(mod,n)
for i in range(1,k):
    if i>k-1 or n-k<i:
        print(0)
        continue
    print((calCom(k-1,i,mod,f,inv) * calCom(n-k+1,i+1,mod,f,inv))%mod)


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define int long long int
#define rep(i,a,b)	for(i=a;i<b;i++)
using namespace std;
struct abc{
	int a,b,c;
};
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int n;
	cin >> n;
	abc aa[n];
	for(int i=0;i<n;i++){
		cin >> aa[i].a >> aa[i].b >> aa[i].c;
	}
	int x,y,z;
	for(int i=1;i<n;i++){
		x=max(aa[i-1].b,aa[i-1].c);
		y=max(aa[i-1].a,aa[i-1].c);
		z=max(aa[i-1].a,aa[i-1].b);
		aa[i].a+=x;
		aa[i].b+=y;
		aa[i].c+=z;
	}
	x=aa[n-1].a;
	x=max(x,aa[n-1].b);
	x=max(x,aa[n-1].c);
	cout<<x;

	return 0;
}

Measured memory_bytes: 5880
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
using ull = unsigned long long;

const int MAX_N = 21;
const int MAX_MASK = 1 << (MAX_N + 1);
const ull MOD = 1e9 + 7;
ull dp[MAX_N + 1][MAX_MASK];
ull inp[MAX_N + 1];

int main() {
	ios_base::sync_with_stdio(false);
	for (size_t i = 0; i <= MAX_N; i++) {
		for (size_t j = 0; j < MAX_MASK; j++) {
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;

	int N; cin >> N;
	for (size_t i = 1; i <= N; i++) {
		ull mask = 0;
		for (size_t j = 0; j < N; j++) {
			ull val; cin >> val;
			mask |= val << j;
		}
		inp[i] = mask;
	}

	ull MASK = 1 << N;
	for (size_t i = 1; i <= N; i++) {
		for (size_t mask = 0; mask < MASK; mask++) {
			if (__builtin_popcount(mask) == i - 1) {
				for (size_t bit = 0; bit <= N; bit++) {
					if ((1 << bit) & inp[i] && !((1 << bit) & mask)) {
						dp[i][(1 << bit) | mask] = (dp[i][(1 << bit) | mask] + dp[i - 1][mask]) % MOD;
					}
				}
			}
		}
	}
	cout << dp[N][(1 << N) - 1] << endl;
	return 0;
}

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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  int current = 1;
  int result = 0;
  while (current < b) {
    current += (a-1);
    result++;
  }

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


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

int main(){
    string s; cin >> s;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for(int i=0;i<s.size()-2;i++){
        if(s[i]==s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	string s,t;
	cin>>n>>s>>t;
	
	REP(i,n){
		cout<<s[i]<<t[i];
	}
	cout<<endl;
}


Measured memory_bytes: 256
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define pf(a)           printf("%lld\n", a)
#define sf(a)           scanf("%lld", &a)
#define line(a)         getline(cin,(a))
#define ll              long long int
#define MAX             2134567891
#define MID(l,r)        (l+r)>>1
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define per(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define T_C(t)          printf("Case %lld: ",t)
#define TC(t)           printf("Case %lld:\n",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb(a)           push_back(a)
#define ff              first
#define ss              second
#define MOD             1000000007///10^9
#define p6              1000007 ///10^6->6 zero after 1 **
#define hlw             printf("hlw\n");
#define SN              4*p6
#define NN              111
#define N               p6

ll x[N],y[N],z[N],n;
string s,S;
vector<ll>v;
//map <ll,ll> mp;

int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc,in,mod,loc,diff,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
    cin>>s;
    l=s.size();
    for(i=0,j=l-1;i<j;i++,j--)
    {
        if(s[i]!=s[j])
        {
            cout<<"No\n";
            return 0;
        }
    }
    for(i=0,j=l/2-1;i<j;i++,j--)
    {
        if(s[i]!=s[j])
        {
            //cout<<i<<" "<<j<<endl;
            cout<<"No\n";
            return 0;
        }
    }

    for(i=l/2+1,j=l-1;i<j;i++,j--)
    {
        if(s[i]!=s[j])
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
}
    return 0;
}

/*

*/
/// Check for constraint 0 or 1?
/// long long or double? sqrt or division will work fine??


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = (int)2e5 + 5;

int nl, n;
int x[N], y[N];
LL sx[N], sy[N], ans;

void Solve(int *x, int *y) {
  for (int i = 1; i <= n; ++i) {
    sx[i] = sx[i - 1] + x[i] * 2;
  }
  for (int i = n; i >= 1; --i) {
    sy[i] = sy[i + 1] + y[i] * 2;
  }
  for (int i = 1; i <= n; ++i) {
    int lim = i + (n - i) / 2;
    if ((n - i) & 1) {
      ans = max(ans, sx[lim] - sx[i - 1] + sy[lim + 1] - y[lim + 1]);
    } else {
      ans = max(ans, sx[lim] - sx[i - 1] + sy[lim + 1] - x[lim]);
    }
  }
}

int main() {
  scanf("%d%d", &nl, &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x[i]);
    y[i] = nl - x[i];
  }
  Solve(x, y);
  reverse(x + 1, x + 1 + n);
  reverse(y + 1, y + 1 + n);
  Solve(y, x);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;
int a[510][510];


int main(){
    int n,m;
    cin>>n>>m;
    vector<int> x(m);
    for(int i=0;i<m;i++) cin>>x[i];
    sort(x.begin(), x.end());
    vector<int> dis(m-1);
    for(int i=0;i<m-1;i++) dis[i]=x[i+1]-x[i];
    sort(dis.begin(), dis.end(), greater<int>());
    int ans=*x.rbegin()-*x.begin();
    for(int i=0;i<min(n-1,m-1);i++){
        ans-=dis[i];
    }
    cout<<max(0,ans)<<endl;

}

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

using namespace std;
typedef long long ll;

int N;
map <string, int> m;

int main()
{
    ios_base::sync_with_stdio(0);
    
    cin >> N;
    int cv = 0;
    for (int i = 0; i < N; i++)
    {
        string s; cin >> s;
        m[s]++;
        cv = max (cv, m[s]);
    }

    for (auto it : m)
    {
        if (it.second == cv)
            cout << it.first << "\n";
    }
}

Measured memory_bytes: 23808
N, M, *X = map(int, open(0).read().split())
X = sorted(X)
if N >= M:
  print(0)
  exit(0)
D = []
for i in range(M-1):
  D.append(abs(X[i] - X[i+1]))
D = list(reversed(sorted(D)))
print(X[M-1] - X[0] - sum(D[:N-1]))

Measured memory_bytes: 13964
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int n;
	cin >> n;

	for (int i = n; true; i++) {
		if (i % 10 == i / 100 && i % 10 == (i / 10) % 10) {
			COUT(i);
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 256
package main

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

func gcd(a, b int) int {
    if b == 0 {
        return a
    }
    return gcd(b, a%b)
}

func gcd3(a, b, c int) int {
	return gcd(gcd(a, b), c)
}

// 文字列を1行取得
func StrStdin() (stringInput string) {
    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    stringInput = scanner.Text()

    stringInput = strings.TrimSpace(stringInput)
    return
}

// 整数値1つ取得
func IntStdin() (int, error) {
    stringInput := StrStdin()
    return strconv.Atoi(strings.TrimSpace(stringInput))
}

func main() {
	K, _ := IntStdin()
	
	ans := 0
	for i := 1; i <= K; i++ {
		for j := i; j <= K; j++ {
			for k := j; k <= K; k++ {
				a := gcd3(i, j, k)
				if i == j && j == k {
					ans += a
				} else if i == j || j == k {
					ans += a * 3
				} else {
					ans += a * 3 * 2
				}
			}
		}
	}
	fmt.Println(ans)
}



Measured memory_bytes: 1780
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=1e5+10;

int n,m;
int dis[MAXN];
bool vis[MAXN];
vector<pair<int,int> > E[MAXN];

bool dfs(int u) {
  vis[u]=1;
  vector<pair<int,int> >::iterator it;
  for (it=E[u].begin(); it!=E[u].end(); it++) {
    int v=(*it).first;
    int d=(*it).second;
    if (!vis[v]) {
      dis[v]=dis[u]+d;
      if (!dfs(v)) {
        return false;
      }
    } else if (dis[u]+d!=dis[v]) {
      return false;
    }
  }
  return true;
}
int main() {
  cin>>n>>m;
  int u,v,w;
  int i;
  for (i=1; i<=m; i++) {
    cin>>u>>v>>w;
    E[u].push_back(make_pair(v,w));
    E[v].push_back(make_pair(u,-w));
  }
  for (i=1; i<=n; i++) {
    if (!vis[i]) {
      if (!dfs(i)) {
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  ll n,k;
  cin >>n >>k;
  ll a[n],ans=200000000000000,res;

  rep(i,n) cin >> a[i];
  sort(a,a+n);
  rep(i,n-k+1){
    res=a[i+k-1]-a[i];
    ans=min(ans,res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
typedef long long ll;
#define SIZE(x) ((int)(x).size())
#define UQ(v) v.erase(unique(v,begin(),v,end()),v.end());
ll INF = 1LL <<30;
#define pb push_back 
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
ll mod7 = 1000000007;
ll mod9 = 1000000009;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)

//vector< vector<int> > v (max1, vector<in t>(max2) );

int main() {
	using namespace std;
	int n;
	cin >>n;

	vector<int>a(n);
	rep(i, n)cin>>a[i];
	int l = 0, r = 0;
	ll ans = 0, m = 0, b = 0;
	while (l<n) {
		while(r<n and (m + a[r] == (m^a[r])))m+=a[r++];
		ans += r-l;
		m -= a[l++];
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    
   static int N;
   static int count;
   static ArrayList<ArrayList<Integer>> al;       
    
  public static void main(String[] args) {
      
       Scanner sc = new Scanner(System.in);              
              
       N = sc.nextInt();
       int M = sc.nextInt();
       
       al = new ArrayList<>();
       
       for(int i = 0; i < N; i++){
	   al.add(new ArrayList<>());
       } 
       
       for(int i = 0; i < M; i++) {
	   int a = sc.nextInt() - 1;
	   int b = sc.nextInt() - 1;
	   al.get(a).add(b);
	   al.get(b).add(a);
       }

       count = 0;
       boolean[] reach = new boolean[N];
       dfs(0, 0, reach);
       System.out.println(count);           
  } 
  
   static void dfs(int now, int num, boolean[] reach) {
		if (num == N - 1) {
			count++;
			return;
		}
                
		for (Integer v : al.get(now)) {
			reach[now] = true;
			if (!reach[v]) dfs(v, num + 1, reach);
			reach[now] = false;
		}          
                
   }
  
}

Measured memory_bytes: 21972
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Measured memory_bytes: 26088
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++){
		if((a*i)%b==c){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
map<int, int> cnt;
int main() {
  int a, b;
  cin >> a >> b;
  if (a > 9 || b > 9)
    cout << -1;
  else
    cout << a * b;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {

			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			
			String s, p;
			s = reader.readLine();
			p = reader.readLine();
			
			s = s.concat(s);
			
			if (s.contains(p)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24404
#include<cstdio>
using namespace std;

int main()
{
	int k,x;
	scanf("%d%d",&k,&x);
	for(int i=x-k+1;i<=x+k-1;i++){
		if(i>=-1000000&&i<=1000000)printf("%d ",i);
	}
	printf("\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep2(i, 1, n){
    if(s.at(i) == 'E') ans++;
  }
  int bf = ans;
  rep2(i, 1, n){
    int add = bf;
    if(s.at(i) == 'E') add--;
    if(s.at(i-1) == 'W') add++;
    ans = min(ans, add);
    bf = add;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n, h, x, y;
    cin >> n >> h;
    int mx = 0;
    vector<int> b(n);
    for (int i = 0; i < n;++i) {
        cin >> x >> y;
        mx = max(mx, x);
        b.at(i) = y;
    }
    int sum = 0;
    int cnt = 0;
    sort(b.rbegin(), b.rend());
    for (int j : b) {
        if (j > mx) {
            sum += j;
            cnt++;
            if (sum >= h) {
                cout << cnt << endl;
                return 0;
            }
        }
    }
    int rest = h - sum;
    cout << (rest % mx == 0 ? rest / mx : rest / mx + 1) + cnt << endl;
}


Measured memory_bytes: 640
object Main{
  def time(s:Int):Unit = {
    var a = s / 3600
    var aa = s - a * 3600
    var b = aa / 60
    var c = aa - b * 60
    print(a)
    print(":")
    print(b)
    print(":")
    println(c)
  }
  def main(args:Array[String]){
    var sc = new java.util.Scanner(System.in)
    var s = sc.nextInt
    time(s)
  }
}

Measured memory_bytes: 45044
import java.util.LinkedList;
import java.util.Scanner;
import java.util.*;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() -1 ;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();

	}
	

	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		for (int i = 0; i < totalVertex; i++) {
			for (int j = 0; j < totalVertex-1; j++) {
				
			if (adjList.get(i).contains(j)) {
				System.out.print(1 + " ");
			}
			else System.out.print(0 + " ");
			
		}
			if ((adjList.get(i).contains(totalVertex-1))) {
				System.out.println(1);
			}
			else System.out.println(0);
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
		
	}
}


Measured memory_bytes: 31148
//coded b vishal mourya - the legendary coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(a,b) for(ll i = a ; i < b ; i++ )
#define fj(a,b) for(ll j = a ; j < b ; j++ )
#define fk(a,b) for(ll k = a ; k < b ; k++ )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main(void){
    fasthoja;
    string s;  cin >> s;
    
    if( s[ s.length() -1 ] == 's' ) {
        s += "es";
    }
    else
        s += 's';
        
        cout << s << "\n";

 return 0;
}


Measured memory_bytes: 3660
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
int a[MAXN],n;
void A(){puts("First");exit(0);}
void B(){puts("Second");exit(0);}
void win(int o){o?B():A();}
int gcd(int a,int b){return a==0?b:gcd(b%a,a);}
void work(int now)
{
	int sum=0,val=0;bool tf=false;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)tf=true;
		sum^=(a[i]-1)&1;val+=(a[i]&1);
	}
	if(tf==true)(sum&1)?(win(now)):(win(now^1));
	if(val>1)((n-val)&1)?(win(now)):(win(now^1));
	for(int i=1;i<=n;i++)if(a[i]&1)a[i]--;int g=0;
	for(int i=1;i<=n;i++)g=gcd(g,a[i]);
	for(int i=1;i<=n;i++)a[i]/=g;
	work(now^1);
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	work(0);
	return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main () {
	cin.tie(0);
	cin.sync_with_stdio(0);

	ll x = 1, y = 1;

	int n;
	cin >> n;

	while(n--) {
		int a, b;
		cin >> a >> b;
		ll u = (x + a - 1) / a;
		ll v = (y + b - 1) / b;
		ll z = max(u, v);
		x = a * z;
		y = b * z;
	}

	cout << (x + y);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin>>c;
  if(c=='A'){cout<<'T';}
  else if(c=='T'){cout<<'A';}
  else if(c=='G'){cout<<'C';}
  else if(c=='C'){cout<<'G';}
}

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

typedef long long ll;

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

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

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

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

#define pii pair<int,int>

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

int main()
{
	int n;
	cin >> n;
	int count[3];	//0:4の倍数の数, 1:2の倍数かつ4の倍数でない, 2;奇数
	count[0] = count[1] = count[2] = 0;
	FOR(i,0,n){
		int a;
		cin >> a;
		if(a % 4 == 0){
			count[0]++;
		}else if(a % 2 == 0){
			count[1]++;
		}else{
			count[2]++;
		}
	}
	if(count[1] > 0)count[2]++;
	bool ans = true;
	if(count[0]+1 < count[2])ans = false;
	Yes(ans);
	return 0;
}


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

long long int myabs(long long int input){
    if(input < 0){
        input *= -1;
    }
    return input;
}

int main() {

    int n;

    cin >> n;

    vector<long long int> v;

    for(int i=0; i<n; i++){
        long long int a;
        cin >> a;
        v.push_back(a);
    }

    vector<long long int> Cumulative_Sum;

    Cumulative_Sum.push_back(v[0]);

    for(int i=0; i<n-1 ;i++){
        Cumulative_Sum.push_back(Cumulative_Sum[i] + v[i+1]);
    }

    long long int ans = myabs(Cumulative_Sum[n-1] - Cumulative_Sum[0] - Cumulative_Sum[0]);

    for(int i=1; i<n-1; i++){
        ans = min(ans,myabs(Cumulative_Sum[n-1] - Cumulative_Sum[i] - Cumulative_Sum[i]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int mod_pow(int x,int y){
	int res=1;
	while(y>0){
		if(y&1)res*=x;
		x*=x;
		res%=mod;x%=mod;
		y>>=1;
	}
	return res;
}
bool prime(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0)return false;
	}
	return x!=1;
}
int sum[114514];
void init(){
	for(int i=1;i<100000;i++){
		if(prime(i)&&prime((i+1)/2)){
			sum[i]++;
		}
		sum[i+1]+=sum[i];
	}
}
int n;
signed main(){
	init();
	cin>>n;
	while(n--){
		int l,r;cin>>l>>r;
		cout<<sum[r]-sum[l-1]<<endl;
	}
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
    char a;
    cin >> a;
    if(a=='A'){
        cout << "T" << endl;
    }else if(a=='T'){
        cout << "A" << endl;
    }else if(a=='C'){
        cout << "G" << endl;
    }else if(a=='G'){
        cout << "C" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#define _GLIBCXX_DEBUG
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく


//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

bool E[2005][2005];
vector<bool> seen;
typedef pair<int, int> P;
typedef tuple<int, int, int> Tu;
//typedef pair<string, int> P;
int D[2005];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

int main() {
    int N, M; cin >> N >> M;
    vector<int> retu(N);
    int vote = 0;
    for (int i = 0; i < N; i++) { 
        cin >> retu.at(i); 
        vote += retu.at(i);
    }
    sort(retu.begin(), retu.end());
    reverse(retu.begin(), retu.end());
    int ans = 0;
    int div = 0;
    for (int i = 0; i < N; i++) {
        if (vote % (4 * M) != 0)  div = vote / (4 * M) + 1;
        else  div = vote / (4 * M);
        if (retu.at(i) >= div) {
            
        }
        else {
            if (i < M) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	cin>>str;
	int sum=str.length();
	int l=0,r=1;
	while(r<str.length())
	{
		if(str[l]=='S'&&str[r]=='T') 
		{
			str.erase(l,2);
			sum=sum-2;
			l--,r--;
		}
		else
		{
			l++,r++;
		}
	}
	cout<<sum<<endl;
	return 0;
 } 


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

int main(){
    int N=read();
    printf("%d",N*N*N);
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define ZERO(a) memset(a,0,sizeof(a))

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin>>n;
  string s;
  cin>>s;

  ll dp[n+1][n+1];
  REP(i,n+1)REP(j,n+1)dp[i][j]=0;
  REP(i,n)dp[0][i]=1;

  for(ll i=1; i<n; i++){
    vll cum(n+3);
    for(ll j=0; j<=n; j++)
      cum[j+1] = cum[j]+dp[i-1][j];

    for(ll j=0; j<=n-(i+1); j++){
      if(s[i-1] == '<')
        dp[i][j]=(cum[n-(i-1+1)+1]-cum[j+1]+MOD)%MOD;
      else
        dp[i][j]=(cum[j+1]-cum[0]+MOD)%MOD;
    }
  }

  ll ans = dp[n-1][0];
  cout<<ans<<endl;

}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding space */
vi G[100];
int n,m;
int ans = 0;
void dfs(int state,int p){
  //cerr << bitset<30>(state) << endl;
  if(__builtin_popcount(state) == n){ans++; return;}
  for(auto np : G[p]){
    if(state & (1<<np))  continue;
    dfs(state | ( 1 << np ) , np);
  }
}

int main(){
  cin >> n >> m;
  rep(i,m){
    int a,b; cin >> a >> b;
    a--,b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  dfs(1,0);
  cout << ans << endl;
}


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

int main() {
	int A, B; cin >> A >> B;
	int ans;
	if (A > B) {
		ans = A + (A - 1);
	}
	else if (B > A) {
		ans = B + (B - 1);
	}
	else {
		ans = A + B;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    ll val1[100100];
    ll val2[100100];
    cin >> n;
    ll back1;
    ll back2;
    ll sumdis = 0;
    imfor(i, n) {
        int a;
        cin >> a;
        if (i == 0) {
            val1[i] = abs(a);
            back1 = a;
        }
        else if (i == 1) {
            val1[i] = abs(a - back1);
            val2[i] = abs(a);
            back2 = back1;
            back1 = a;
        }
        else {
            val1[i] = abs(a - back1);
            val2[i] = abs(a - back2);
            back2 = back1;
            back1 = a;
        }
        sumdis += val1[i];
    }
    val1[n] = abs(back1);
    val2[n] = abs(back2);
    sumdis += val1[n];
    imfor(i, n) {
        cout << sumdis - (val1[i] + val1[i + 1] - val2[i + 1]) << endl;
    }
}

Measured memory_bytes: 2816
#include <iostream>
#include<math.h>
using namespace std;

int main()
{
   long long n;
   long long d;
   cin >> n >> d;
   int c = 0;
   while(n--){
       long long a,b;
       cin >> a >> b;
       long double sum = (sqrt((a*a) + (b*b)));
       if(sum <= d){
           c++;
       }
   }
   cout << c;
    return 0;
}


Measured memory_bytes: 3188
MOD = 10 ** 9 + 7
r1, c1, r2, c2 = map(int, input().split())

def getInvs(n, MOD):
    invs = [0] * (n+1)
    invs[1] = 1
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(c2+r2+1, MOD)

combi_c2 = []
combi_c1_1 = []
for i in range(c2+r2+2):
    if i <= c2:
        combi_c2.append(int(i == c2))
    else:
        c = combi_c2[-1]
        combi_c2.append((c * i * invs[i-c2+1]) % MOD)
    if i <= c1-1:
        combi_c1_1.append(int(i == c1-1))
    else:
        c = combi_c1_1[-1]
        combi_c1_1.append((c * i * invs[i-c1]) % MOD)

ans = 0
t = 1
b = 1
for x in range(r2+2, c2+r2+2):
    t *= x
    t %= MOD
for x in range(1, c2+1):
    t *= invs[x]
    t %= MOD
for x in range(r2+2, c1+r2+1):
    b *= x
    b %= MOD
for x in range(1, c1):
    b *= invs[x]
    b %= MOD

ans = t - b
ans %= MOD
for i in range(r2, r1, -1):
    t = (t * ((i+c2+1)-c2) * invs[(i+c2+1)]) % MOD
    b = (b * ((i+c1-1+1)-(c1-1)) * invs[i+c1]) % MOD
    ans += t - b
    ans %= MOD
print(ans)

Measured memory_bytes: 212364
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
vector<int>g[123456];
vector<int>ans;
bool used[123456];
int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int now = 1;
    ans.push_back(now);
    used[now] = true;
    while(1){
        bool flag = false;
        for(int x:g[now]){
            if(!used[x]){
                now = x;
                used[now] = true;
                ans.push_back(now);
                flag = true;
                break;
            }
        }
        if(!flag)break;
    }
    reverse(ans.begin(),ans.end());
    now = 1;
    while(1){
        bool flag = false;
        for(int x:g[now]){
            if(!used[x]){
                now = x;
                used[now] = true;
                ans.push_back(now);
                flag = true;
                break;
            }
        }
        if(!flag)break;
    }
    cout << ans.size() << endl;
    rep(i,ans.size()){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 7416
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for(ll i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(ll i=0;i<(n);i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

ll way[1002][1002];
ll dp[1002][1002];
int main(){
    while(true){
	ll h,w,n;
	memset(dp,0ll,sizeof(dp));
	memset(way,0ll,sizeof(way));
	cin >> h >> w >> n;
	if(h == 0 && w == 0 && n == 0) break;
	REP(i,h)REP(j,w) {
	    cin >> way[i+1][j+1];
	}
	dp[1][1] = n-1;
	REP(i,h)REP(j,w){
	    if(i == 0 && j == 0) continue;
	    ll u = 0;
	    ll l = 0;
	    if(i > 0){
		if(dp[i][j+1]%2 == 0) u = dp[i][j+1]/2;
		else if(way[i][j+1] == 0) u = 1 + dp[i][j+1]/2;
		else u = dp[i][j+1]/2;
	    }
	    if(j > 0){
		if(dp[i+1][j]%2 == 0) l = dp[i+1][j]/2;
		else if(way[i+1][j] == 1) l = 1 + dp[i+1][j]/2;
		else l = dp[i+1][j]/2;
	    }
	    dp[i+1][j+1] = u + l;
	}
	ll x = 1;
	ll y = 1;
	while(x <= w && y <= h){
	    if( (way[y][x] + dp[y][x])%2 == 1){
		x++;
	    }else y++;
	}
	printf("%d %d\n",y,x);
    }
    return 0;
}

Measured memory_bytes: 16840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll x,k,d;
    scanf("%lld%lld%lld",&x,&k,&d);
    x=abs(x);
    if(x/d>=k)
        printf("%lld\n",x-k*d);
    else
    {
        k-=x/d;
        x-=x/d*d;
        if(k%2==0) printf("%lld\n",x);
        else
        {
            x=x-d;
            x=abs(x);
            printf("%lld\n",x);
        }
    }
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, count_P = 0, count_W = 0, count_G = 0, count_Y = 0;
  string S;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "P") {
      count_P++;
    }
    else if (S == "W") {
      count_W++;
    }
    else if (S == "G") {
      count_G++;
    }
    else {
      count_Y++;
    }
  }
  if (count_Y == 0) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}



int main() {
	int n, k, q;
	cin >> n >> k >> q;
	
	vector<int> num(n);

	REP(i, n) {
		scanf("%d", &num[i]);
	}


	int ans = INT_MAX;

	REP(cc, n) {
		int base = num[cc];
		
		int con = 1;
		rep(i, cc + 1, n) {
			if (num[i] >= base) con++;
			else break;
		}
		for (int i = cc - 1; 0 <= i; i--) {
			if (num[i] >= base) con++;
			else break;
		}

		if (con < k) continue;

		int canc = 0;
		int cur = 0;
		vector<int> cand;

		REP(i, n) {
			if (num[i] >= base) {
				cur++;
			}
			else if (cur) {
				canc += max(0, cur - k + 1);

				if (cur - k + 1 > 0) {
					multiset<int> pq;
					rep(j, i - cur, i) {
						pq.insert(num[j]);
					}
					auto itr = pq.begin();
					REP(j, cur - k + 1) {
						cand.push_back(*itr);
						itr++;
					}
				}

				cur = 0;
			}
		}


		canc += max(0, cur - k + 1);
		if (cur - k + 1 > 0) {
			multiset<int> pq;
			rep(j, n - cur, n) {
				pq.insert(num[j]);
			}
			auto itr = pq.begin();
			REP(j, cur - k + 1) {
				cand.push_back(*itr);
				itr++;
			}
		}

		sort(ALL(cand));

		if (canc >= q) {
			ans = min(ans, cand[q-1]-base);
		}
	}





	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main()
{
	int n, m, gcd = 1;
	vector<int> divisor;

	cin >> n >> m;

	for(int i = 1; i * i <= m; ++i)
	{
		if(m % i == 0)
		{
			divisor.push_back(i);
			divisor.push_back(m / i);
		}
	}

	for(int i = 0; i < divisor.size(); ++i)
	{
		if(m / divisor[i] >= n)
		{
			gcd = max(gcd, divisor[i]);
		}
	}

	cout << gcd << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

string s, t;
int c1[26], c2[26];
vector<int> a, b;

int main() {
	cin >> s >> t;

	rep(i, s.size()) c1[s[i] - 'a']++;
	rep(i, t.size()) c2[t[i] - 'a']++;

	rep(i, 26) {
		if (c1[i]) a.push_back(c1[i]);
		if (c2[i]) b.push_back(c2[i]);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	if (a.size() != b.size()) {
		cout << "No" << endl;
		return 0;
	}
	
	bool ans = true;
	rep(i, a.size()) {
		if (a[i] != b[i]) {
			ans = false;
			break;
		}
	}

	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;
const int mod = 998244353;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int n,X,fac[101100],Ifac[101011];
inline ll ksm (ll x,ll y){ll res=1;while(y){if(y&1) res=res*x%mod;x=x*x%mod;y>>=1;}return res;}
inline void Init(){
	Ifac[0]=fac[0]=1;
	for(rint i=1;i<=10000;++i) fac[i]=1ll*fac[i-1]*i%mod;
	Ifac[10000]=ksm(fac[10000],mod-2);
	for(rint i=9999;i;--i) Ifac[i]=1ll*(i+1)*Ifac[i+1]%mod;
}
inline int C(int a,int b){/*debug(a);debug(b);*/if(a<b) return 0;return 1ll*fac[a]*Ifac[b]%mod*Ifac[a-b]%mod;}
inline int pls(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int get(int len){
	int Ans=0;
	if(2*len<X||(X%2==1)) Ans=1;
	for(rint i=len;i<=2*len-1;++i){
		if(i<X) Ans=pls(Ans,C(len,i-len));
		else {
			if((i-X)%2==0) continue;
//			debug(i);
			int o=(i-X+1)/2;
			if(2*o>=len) continue;
			int p=len-2*o,q=i-4*o;
			if(q>=p)Ans=pls(Ans,C(p,q-p));
		}
	}
	return Ans;
}
int main()
{	
	n=read(),X=read();
	Init();
	ll Ans=0;
	for(rint i=0;i<=n;++i){
		Ans=pls(Ans,1ll*C(n,i)*get(i)%mod);
	}cout<<Ans;
	return 0;
}	

Measured memory_bytes: 384