akhauriyash/Code-Regression huggingface dataset:
import numpy as np


H, W = map(int, input().split())
field = [[c == "." for c in input()] for _ in range(H)]
field = np.array(field, dtype=np.int16)

u = field.copy()
d = field.copy()
l = field.copy()
r = field.copy()

for i in range(1, H):
    u[i] = (u[i - 1] + 1) * u[i]
    d[-i - 1] = (d[-i] + 1) * d[-i - 1]

for j in range(1, W):
    l[:, j] = (l[:, j - 1] + 1) * l[:, j]
    r[:, -j - 1] = (r[:, -j] + 1) * r[:, -j - 1]

print((u + d + l + r - 3).max())


Measured memory_bytes: 79892
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a=0,b=0,c=0,d,n=0,x;
    string s,s1,s2;
    cin >> a >> b >> c >> d;   
    if (abs(a-c)<=d||(abs(a-c)<=2*d  && abs(a-b)<=d && abs(b-c)<=d) ) 
    cout << "Yes" << endl;

    else cout << "No" << endl;
    return 0;
} 

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

int A, B, C;

int main() {
	cin >> A >> B >> C;
	for (int i = 0; i < 10000; i++) {
		int Z = B*i + C;
		if (Z%A == 0) { cout << "YES" << endl; return 0; }
	}
	cout << "NO" << endl;
	return 0;
}

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

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
};

struct segment{ point a,b; };

struct circle{ point p; double r; };

double dot(point a, point b) { return (a.x * b.x + a.y * b.y); }

double cross(point a, point b) { return (a.x * b.y - a.y * b.x); }

int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}

double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

double distance_ls_p(point a, point b, point c) {
  if ( dot(b-a, c-a) < EPS ) return vec_abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return vec_abs(c-b);
  return abs(cross(b-a, c-a)) / vec_abs(b-a);
}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

int crossCS(point a, point b, circle c){
  double res=distance_ls_p(a,b,c.p);
  double ac=dist(a,c.p);
  double bc=dist(b,c.p);

  if(res>c.r || (ac<c.r && bc<c.r))return 0;
  else if(c.r-res<EPS ||(ac<c.r && bc>=c.r)||(ac>=c.r && bc<c.r))return 1;
  else return 2;
}

vector<segment> construct_edge(point* p, int n){
  vector<segment>seg,seg2;
  segment temp;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
	temp.a=p[i];
	temp.b=p[j];
	seg.push_back(temp);
      }
    }
  }

  int t=seg.size();
  for(int i=0;i<t;i++){
    int fg=0;
    for(int j=0;j<t;j++){
      if(i!=j && vec_abs(seg[i].b-seg[j].a)<=EPS){
	if(ccw(seg[i].a,seg[i].b,seg[j].b)==1){
	  fg=1;
	  break;
	}
      }
    }
    if(!fg)seg2.push_back(seg[i]);
  }
  return seg2;
}

int point_contain(vector<segment> ps, point p, int n){
  int cnt=ccw(ps[0].a,ps[0].b,p);

  for(int i=0;i<n;i++)
    if(cnt!=ccw(ps[i].a,ps[i].b,p))return 0;
  
  return 1;
}

int crossCP(point* ps, circle C, int sz){

  double ans=0;

  for(int i=0;i<sz;i++){
    double tmp=dist(ps[i],C.p);
    if(tmp>ans)ans=tmp;
  }

  if(C.r>=ans)return 2;

  vector<segment>t=construct_edge(ps,sz);

  int tsz=t.size();
  int res1=point_contain(t,C.p,tsz);

  double res2=100000000;
  for(int i=0;i<tsz;i++)
    res2=min(res2,distance_ls_p(t[i].a,t[i].b,C.p));

  if(res1 && C.r<=res2)return 1;
  else if(!res1 && C.r<res2)return 4;
  else return 3;
}

int main(void){
  point p[3];
  vector<segment> t;
  circle C;
  string ans="zabcd";

  while(true){
    for(int i=0;i<3;i++){
      cin >> p[i].x >> p[i].y;
      if(p[i].x==0 && p[i].y==0)return 0;
    }
    cin >> C.p.x >> C.p.y >> C.r;

    int res=crossCP(p,C,3);
    cout << ans[res] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vvl a(2, vl(n));
    rep(i, 2) {
        rep(j, n) {
            cin >> a[i][j];
        }
    }

    ll ans = 0;
    rep(i, n) {
        ll now = 0;
        exrep(j, 0, i) {
            now += a[0][j];
        }
        exrep(j, i, n-1) {
            now += a[1][j];
        }
        chmax(ans, now);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
function abs() {
    echo $(($1>0?$1:-$1))
}
function min() {
    echo $(($1>$2?$2:$1))
}

read x
ans=753
for((i=0;i<${#x}-2;++i))
do
    t=`abs $((${x:i:3} - 753))`
    ans=`min $ans $t`
done
echo $ans


Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]==',')cout<<" ";
        else cout<<s[i];
    }
    cout<<endl;
    return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n>>m>>k;

	cout<<min((n+k),min(m+k,n+m))<<endl;



}


Measured memory_bytes: 256
import sys
import numpy as np  # noqa
import numba  # noqa
from numba import njit, b1, i4, i8, f8  # noqa

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit((i8, i8, i8[:]), cache=True)
def main(N, D, XY):
    count = 0
    for i in range(N):
        x, y = XY[i*2:i*2 + 2]
        if abs(x) > D or abs(y) > D:
            continue
        if x**2 + y ** 2 <= D**2:
            count += 1
    return count


N, D = map(int, readline().split())
XY = np.array(read().split(), np.int64)

print(main(N, D, XY))


Measured memory_bytes: 134084
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int K;
string s;
int iter;




int main()
{

	cin >> s >> K;



	REP(i,s.length()){
		if(s[i] == 'a')
			continue;
		if('z' - s[i] < K){
			K -= 'z' - s[i] + 1;
			s[i] = 'a';
			iter = i+1;
			continue;
		}
	}
	K %= 26;
	if(K>0){
		s[s.length()-1] += K;
	}

	cout << s << endl;


}


Measured memory_bytes: 512
S = input()
T = input()
sdic = {}
tdic = {}
flag = True
for s, t in zip(S, T):
  if s not in sdic:
    sdic[s] = t
  if t not in tdic:
    tdic[t] = s
  if sdic[s] != t or tdic[t] != s:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 74032
S = list(input())
n = len(S)
S1 = S[:(n-1)//2]
S2 = S[(n+3)//2-1:]
ans = "Yes"
for i in range(n//2):
	if S[i] != S[-(i+1)]:ans="No"
for i in range(len(S1)//2):
	if S1[i] != S1[-(i+1)]:ans="No"
for i in range(len(S2)//2):
	if S2[i] != S2[-(i+1)]:ans="No"
print(ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from math import *

N = int(input())
def primes(n):
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1, int(n**0.5)//3+1):
        if sieve[i]:
            k = 3*i+1|1
            sieve[k*k//3::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2, 3] + [3*i+1|1 for i in range(1, n//3-correction) if sieve[i]]
ps = primes(55556)
ps = [x for x in ps if x % 5 == 1]
print(*ps[:N])


Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solveA();
	}
	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = sc.nextInt();
		if (A <= X && A + B >= X) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}
		return ;
	}
}

Measured memory_bytes: 21716
#include<stdio.h>
#include <math.h>

int main(void){
    long n,m,a,tmp=0;
    scanf("%ld %ld",&n,&m);
    for(long i=0;i<m;i++){
        scanf("%ld",&a);
        tmp+=a;
    }
    if(tmp>n){
        printf("-1");
    }else{
        printf("%ld",n-tmp);
    }
}

Measured memory_bytes: 1736
n, k = map(int, input().split())
a = list(map(int, input().split()))

if n == k:
  print("1")
  exit()

b = min(a)

i = 0
result = 0
while i < n:
  if a[i] == b:
    i += 1
    continue
  result += 1
  hoge = i + k
  if i + k > n:
    break
  if min(a[i:hoge]) == b:
    i += k
  else:
    i += k - 1

print(result)

Measured memory_bytes: 14008
//b
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;	

int main(){
	
	string str;
	cin>>str;
	
	int cnt[512]={0};
	
	for(int i=0; i<str.size(); ++i){
		
		cnt[(int)(str[i])]++;
	}
	
	cout << min(cnt[(int)('K')], min(cnt[(int)('U')], min(cnt[(int)('P')], cnt[(int)('C')]))) << endl;
	
	return 0;	
}

Measured memory_bytes: 1188
#include <stdio.h>
 
int main() {
 
  int a;
  int min = 13000;
  int max = -1;
  int x,y,p,b,n;
  int i,j;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++) {
 
 
    scanf("%d %d %d %d",&x,&y,&b,&p);
    min = x*b+y*p;
 
    if(b < 5) b = 5;
    if(p < 2) p = 2;
       
      if((double)(x*b+y*p)*0.8 < min) min = (double)(x*b+y*p)*0.8;
      
 
    printf("%d\n",min);
    
  }
 
 
  return 0;
 
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int n, a[110];
  cin >> n;

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

  for (int i = 0; i < n; ++i)
  {
    if (a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0))
    {
      cout << "DENIED" << endl;
      return 0;
    }
  }

  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {
	
	string s;
	long long int k;
	long long int point = 0;

	cin >> s;
	cin >> k;

	FOR(i, 0, s.size() - 1) {
		point = i + 1;
		if (s[i] != '1') {
			cout << s[i] << endl;
			break;
		}
		if (point == k) {
			cout << 1 << endl;
			break;
		}
		if (i == s.size() - 1) {
			cout << 1 << endl;
			break;
		}
		
	}


	return 0;
}

Measured memory_bytes: 256
# マンハッタン距離のように移動
# H + W - 1 ならPossible

H,W = map(int,input().split())

cnt = 0
for _ in range(H):
    cnt += list(input()).count("#")

if cnt == H + W - 1:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 2940
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		
		long[] a = new long[n];
		Arrays.setAll(a, i -> sc.nextLong());
		
		long sum = 0;
		for (int i = 1; i < n; i++) {
			long dif = a[i - 1] + a[i] - x;
			
			if (dif > 0) {
				if (a[i] >= dif) {
					a[i] -= dif;
				} else {
					a[i - 1] -= dif - a[i];
					a[i] = 0;
				}
				sum += dif;
			}
		}
		
		System.out.println(sum);

		
		sc.close();
	}
}




Measured memory_bytes: 51684
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int INF=1e18;

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

    int N,M; cin>>N>>M;
    vector<int> a(M),T(M);
    for(int i=0;i<M;i++){
        int k; cin>>a[i]>>k;
        while(k--){
            int t; cin>>t;
            t--;
            T[i]|=1<<t;
        }
        // cout<<(bitset<10>)T[i]<<endl;
    }

    vector<int> dp(1<<N,INF);
    dp[0]=0;
    for(int i=0;i<M;i++){
        for(int S=0;S<(1<<N);S++){
            chmin(dp[S|T[i]],dp[S]+a[i]);
        }
    }
    int ans=dp[(1<<N)-1];
    cout<<(ans==INF? -1:ans)<<endl;
    return 0;
}

Measured memory_bytes: 256
N,M,K = gets.split.map(&:to_i)
Mod = 998244353

D,U = [1,N-1],[1,1]
[K,N/2].min.times{|i| i+=2
	D << D[-1] *(N-i) % Mod
	U << Mod - U[Mod%i] * (Mod/i) % Mod # 謎
}
1.upto(U.size-1){|i|
	U[i] = U[i-1] * U[i] % Mod  # 謎
}
Com = lambda{|r| r = [N-1-r,r].min
	D[r] * U[r] % Mod
}

p (0..K).inject(0){|a,k|
	(a + Com[k] * M * (M-1).pow(N-1-k,Mod)) % Mod
}


Measured memory_bytes: 16232
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (A + B >= C)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;

	}

	return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 1e5 + 5;

int n, N, Q;
ll q[maxn];
ll a[maxn];
int st[maxn];
int tot;

ll coeff[maxn], cnt[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> Q;
    q[0] = n;
    N = n;
    for(int i = 1;i <= Q;i++){
        cin >> q[i];
    }
    tot = 0;
    for(int i = 0;i <= Q;i++){
        while(tot > 0 and q[st[tot]] >= q[i]){
            tot--;
        }
        st[++tot] = i;
    }
    for(int i = 1;i <= tot;i++){
        a[i] = q[st[i]];
    }
    n = tot;
    memset(coeff, 0, sizeof(coeff));
    coeff[n] = 1;
    for(int i = n;i >= 1;i--){
        ll val = a[i];
        while(val > 0){
            int id = upper_bound(a + 1, a + i, val) - a - 1;
            if(id > 0){
                ll times = val / a[id];
                ll left = val % a[id];
                val = left;
                coeff[id] += times * coeff[i]; 
            }else{
                cnt[val] += coeff[i];
                val = 0;
            }
        }
    }
    for(int i = a[1];i >= 1;i--){
        cnt[i] += cnt[i + 1];
    }
    for(int i = 1;i <= N;i++){
        cout << cnt[i] << endl; 
    }
    return 0;
}


Measured memory_bytes: 5248
#include <iostream>

using namespace std;

class A {
	int a, b;
public:
	void solve()
	{
		cin >> a >> b;

		if ((a & 1) && (b & 1)) cout << "Odd" << endl;
		else cout << "Even" << endl;
	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

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

#define int long long
#define endl '\n'



const int N = 2e5 + 100;
const int mod = 1e9 + 7;

#define ll int
ll power(ll a, ll b, ll m = mod){if(b < 0)b += m-1; ll r = 1; while(b){if(b&1)r=(r*a)%m; a = (a*a)%m; b>>=1;}return r;}

int fact[N+10], ifact[N+10];
void pre(int N){
   fact[0] = 1;
   for (int i = 1; i <= N; ++i)
   {
      fact[i] = (i*fact[i-1])%mod;
   }
   ifact[N] = power(fact[N], -1);
   for (int i = N-1; i >= 0; --i)
   {
      ifact[i] = ((i+1)*ifact[i+1])%mod;
   }
}

int nCr(int n, int r){
   if(n < r or n < 0 or r < 0)return 0;
   return ((fact[n]*ifact[r])%mod * ifact[n-r])%mod;
}

int32_t main(){

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

   pre(N);
   int n, k;
   cin >> n >> k;

   int ans = 0;
   k = min(k, n-1);
   for (int zeros = 0; zeros <= k; ++zeros)
   {
      int rem = n - zeros;
      int a = nCr(n, zeros);
      int b = nCr(n-1, rem-1);
      ans += a*b % mod;
      ans %= mod;
   }

   cout<<ans;
   return 0;
}

Measured memory_bytes: 3456
N,M = map(int,input().split())
abc= [list(map(int,input().split())) for _ in [0]*M]
d = [[10000*N]*N for _ in [0]*N]
for a,b,c in abc:
    d[a-1][b-1]=c
    d[b-1][a-1]=c
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j],d[i][k]+d[k][j])
ans=sum(d[a-1][b-1]<c for a,b,c in abc)
print(ans)

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

using namespace std;

int main() {
  int sTime;
  cin >> sTime;
  int sec = sTime % 60;
  int tmp = sTime / 60;
  int min = tmp % 60;
  int hour = tmp / 60;
  cout << hour << ":" << min << ":" << sec << endl;
  
  return 0;
}



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

int main() {
	int n, m, l;
	long long A[100][100], B[100][100], C[100][100];

	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> B[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			C[i][j] = 0;
			for (int k = 0; k < m; k++) {
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			if (j) cout << " ";
			cout << C[i][j];
		}
		cout << endl;
	}

	return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

using namespace std;

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

#define St first
#define Nd second
#define Pb push_back
#define Mp make_pair
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

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

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)


// ************* MAIN *******************

int N, B[200001], S[200001];
void solve() {
    cin>>N;
    memset(S,0,sizeof(S));
    REP(i,1,N-1) {
        cin>>B[i];
    }
    REV(i, N-1,1) {
        S[B[i]]++;
    }
    REP(i,1,N) cout << S[i] << endl;
}
/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test
*/
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    // cin>>T;
    for (int t = 1; t <= T; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
const int MAX_V = 10010;
const int INF = 1e9;
typedef pair<int, int> P;

struct WarshallFloyd{
    int n;
    const int INF = 1e6;
    vector<vector<int> > d;
    WarshallFloyd(int _n){
        n = _n;
        d.resize(n, vector<int>(n));
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                d[i][j] = INF;
            }
            d[i][i] = 0;
        }
    }
    void build(){
        for(int k = 0; k < n; k++){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
    }
};

int n, m, r;
int d[1010][210];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1){
        cin >> n >> m;
        if(n + m == 0) break;
        WarshallFloyd wfl(n), wfs(n);
        rep(i, 0, m){
            int x, y, t; char c;
            cin >> x >> y >> t >> c;
            x--; y--;
            if(c == 'L'){
                wfl.d[x][y] = t;
                wfl.d[y][x] = t;
            }else{
                wfs.d[x][y] = t;
                wfs.d[y][x] = t;
            }
        }
        cin >> r;
        vector<int> z(r);
        rep(i, 0, r){
            cin >> z[i];
            z[i]--;
        }
        wfl.build();
        wfs.build();
        rep(i, 0, r) rep(j, 0, n) d[i][j] = INF;
        d[0][z[0]] = 0;
        rep(i, 1, r){
            rep(j, 0, n){
                if(d[i - 1][j] >= INF) continue;                
                rep(k, 0, n){
                    int tmp = wfl.d[z[i - 1]][j] + wfs.d[j][k] + wfl.d[k][z[i]];
                    if(j == k) tmp = wfl.d[z[i - 1]][z[i]];
                    // cout << i << ' ' << j << ' ' << k << ' ' << tmp << endl;
                    d[i][k] = min(d[i][k], d[i - 1][j] + tmp);
                }
            }
        }
        int ans = INF;
        rep(i, 0, n) ans = min(ans, d[r - 1][i]);
        cout << ans << endl;
    }
}


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

using LL = long long;
const LL M = 1e9 + 7;

int main() {
  string S;
  cin >> S;
  reverse(begin(S), end(S));

  LL p = 1;
  vector<LL> dp(13);
  dp[0] = 1;
  for(auto c: S) {
    vector<LL> nex(13);
    if(c == '?') for(auto k=0; k<10; ++k) for(auto i=0; i<13; ++i) (nex[(i+k*p)%13] += dp[i])%= M;
    else         for(auto i=0; i<13; ++i) (nex[(i+(c-'0')*p)%13] += dp[i]) %= M;
    dp = nex;
    (p *= 10) %= 13;
  }
  cout << dp[5] << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  int i,j,n,taro_p=0,hana_p=0;
  char taro[101], hana[101];

  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%s %s", taro, hana);

    for(j=0;;j++){
      if(taro[j] > hana[j]){
        taro_p += 3;
        break;
      }else if(taro[j] < hana[j]){
        hana_p += 3;
        break;
      }else if(taro[j] + hana[j] == 0){
        hana_p++;
        taro_p++;
        break;
      }
    }
  }

  printf("%d %d\n", taro_p , hana_p);
  return 0;
}
  
      

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define endl        '\n'
#define pi          2*acos(0.0)
#define pb(a)       push_back(a)
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define mod         1000000007
#define inf         1000000000000000001
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define all(x)      (x).begin(), (x).end()
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;

int main()
{
    //freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
    unsyncIO;
    string s, ans;
    cin >> s;
    vector<char> vch;
    for (int i = 0; i < (int) s.length(); i++) {
        if(s[i] != 'B')
            vch.pb(s[i]);
        else if(s[i] == 'B') {
            if(!vch.empty()) {
                vch.pop_back();
            }
        }
    }
    for (int i = 0; i < (int) vch.size(); i++) {
        cout << vch[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINV(A, N) REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl

int
main()
{
  CIN2(T, X);

  ANS((float)T / X);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define se second
ll power(ll x, ll y, ll mod = 2e18) {ll ans = 1;x %= mod;while(y){if(y&1) ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}

ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m,a = t; t = y; y = x - q * y; x = t; } if(x < 0) x += m0;return x;}

int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}

ll binsearch(std::vector<ll>& nums, ll target) {ll n = nums.size();ll l = 0;ll r = n-1;while(l<=r){ll mid = l+ (r-l)/2;if(nums[mid]==target)return mid;else if(nums[mid]>target)r = mid-1;else l = mid+1;}return -1;}

using namespace std;

int main()
{
   fastio
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   if(k<=a)
   {
       cout<<k<<endl;
   }
   else if(a<k&&k<=a+b)
   {
       cout<<a<<endl;
   }
   else if(k>a+b)
   {
       cout<<a-(k-(a+b));
   }


}




Measured memory_bytes: 3652
x=int(input())
import math

def is_prime(n):
	if n == 1:
		return 0
	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return 0
	return 1
	
while is_prime(x)==0:
	x+=1
print(x)

Measured memory_bytes: 2940
X, Y, Z, K = map(int, input().split())

A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)

ABC = []
for a in range(X):
    for b in range(Y):
        if (a + 1) * (b + 1) > K:
            break
        for c in range(Z):
            if (a + 1) * (b + 1) * (c + 1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])

ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])


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

int main(){
    int N; cin >> N;
    vector<int> V(N),C(N);
    for(int i=0;i<N;i++){
        cin >> V[i];
    }
    for(int i=0;i<N;i++){
        cin >> C[i];
    }
    int cnt = 0;
    for(int i=0;i<N;i++){
        if(V[i]-C[i]>=0){
            cnt += V[i]-C[i];
        }
    }
    cout << cnt << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<setprecision(6); cout<<fixed;
  #ifdef DEBUG
  freopen("ip.txt","r",stdin);
  clock_t tStart = clock();
  #endif

  ll n,sum=0; cin>>n; ll temp=n;
  while(temp) {sum+=temp%10; temp/=10;}
  if(n%sum==0) cout<<"Yes\n";
  else cout<<"No\n";


  #ifdef DEBUG
	cout<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)<<"s.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APoor solver = new APoor();
        solver.solve(1, in, out);
        out.close();
    }

    static class APoor {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int a = s.nextInt();
            int b = s.nextInt();
            int c = s.nextInt();
            if (a == b && a != c) {
                out.println("Yes");
                return;
            }

            if (a == c && a != b) {
                out.println("Yes");
                return;
            }

            if (b == c && b != a) {
                out.println("Yes");
                return;
            }

            out.println("No");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21332
N, M, C = tuple(map(int, input().split()))
B = list(map(int, input().split()))
res = 0

for i in range(N):
    A = list(map(int, input().split()))
    ans = C
    for j in range(M):
        ans += A[j] * B[j]

    if ans > 0:
        res += 1

print(res)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
using namespace std;
int main(){
	int N, Q; string S; 
	cin >> N >> S >> Q; 
	int D[1000010] = {}; 
	int M[1000010] = {}; 
	int C[1000010] = {}; 
	for(int i = 1; i <= N; i++){
		if(S[i-1] == 'D') D[i] = D[i-1] + 1; 
		else D[i] = D[i-1]; 
		if(S[i-1] == 'M') M[i] = M[i-1] + 1; 
		else M[i] = M[i-1]; 
		if(S[i-1] == 'C') C[i] = C[i-1] + 1; 
		else C[i] = C[i-1]; 
	}
	for(int q = 0; q < Q; q++){
		int K; cin >> K; 
		long long ans = 0; 
		for(int i = 0; i < N; i++){
			if(S.at(i) == 'D'){
				ans -= (long long) M[i+1] * (C[min(i+K, N)] - C[i]); 
			}
			if(S.at(i) == 'C'){
				ans += (long long) M[i+1] * (D[i+1] - D[max(i+1-K, 0)]); 
			}			
		}
		cout << ans << endl; 
	}
}

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

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

	sort(S.begin(), S.end());

	for (int i = 0; i < S.length()-1; i++) {
		if (S[i] == S[i + 1]) {
			cout << "no" << endl;
			return 0;
		}
	}

	cout << "yes" << endl;

}

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

int main()
{
    int n, l[100];
    char a[52];
    string s;

    for( int i = 0; i < 26; i++ )
        a[i] = 'a' + i;
    for( int i = 26; i < 52; i++ )
        a[i] = 'A' + i - 26;

    while( cin >> n )
    {
        if( n == 0 )
            break;
        for( int i = 0; i < n; i++ )
            cin >> l[i];
        
        cin >> s;

        int j = 0;
        for( int i = 0; i < s.size(); i++ )
        {
            if( 'a' <= s[i] && s[i] <= 'z' )
            {
                if( s[i] - 'a' - l[j] < 0 )
                    s[i] = a[s[i]-'a'+52-l[j]];
                else
                    s[i] = a[s[i]-'a'-l[j]];
            }
            else
            {
                if( s[i] - 'A' + 26 - l[j] < 0 )
                    s[i] = a[52+s[i]-'A'+26-l[j]];
                else
                    s[i] = a[s[i]-'A'+26-l[j]];
            }
            j++;
            if( j == n )
                j = 0;
        }
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 3184
N = int(raw_input())
S = raw_input()
l = [0] * N
r = [0] * N
w = 0
e = 0
for i in range(N-1):
  w += (1 if S[i]=="W" else 0)
  l[i+1] = w
  e += (1 if S[N-1-i]=="E" else 0)
  r[N-1-i-1] = e
ret = N
for i in range(N):
  ret = min(ret, l[i]+r[i])
print ret

Measured memory_bytes: 31576
def calculate(a, b):
    if a < b :
        a, b = b, a
    
    while b > 0:
        a, b = b, a%b

    return a

N = int(input())
A_list = list(map(int, input().split()))
gcd_num = A_list[0]
for i in range(1, N):
    gcd_num = calculate(gcd_num, A_list[i])
print(gcd_num)


Measured memory_bytes: 14224
#include <cstdio>
#include <algorithm>
using namespace std;
#define LL long long
#define REP(a,b,c) for(int a=b;a<=c;++a)
#define RREP(a,b,c) for(int a=b;a>=c;--a)

struct node {
	int r,op,a;
}x[300000];
int ans[300000];
int n,m,tim,q,p;
int l,r,y;
int a,b,c,d;

inline bool cmp(node a,node b) {return a.r<b.r;}

int main() {
	scanf("%d%d",&m,&n); y=0,l=0,r=m; d=-1;
	REP(i,1,n) {scanf("%d",&a); x[++p]=(node){a,0,0};}
	scanf("%d",&q); REP(i,1,q) {scanf("%d%d",&a,&b); x[++p]=(node){a,i,b};}
	sort(x+1,x+p+1,cmp);
	REP(i,1,p) {
		if(x[i].op) {
			c=d*(x[i].r-tim);
			if(x[i].a<=l) c+=y;
			else if(x[i].a>=r) c+=y+(r-l);
			else c+=y+(x[i].a-l);
			if(c<0) c=0; if(c>m) c=m; ans[x[i].op]=c;
		} else {
			y+=d*(x[i].r-tim); d=-d; tim=x[i].r;
			if(y<0) {
				if(y+(r-l)<=0) y=l=r=0;
				else {l-=y,y=0;}
			}
			if(y+(r-l)>m) {
				if(y>m) y=l=r=m;
				else r=m+l-y;
			}
		}
	} REP(i,1,q) printf("%d\n",ans[i]); return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

ll x;

void solve() {
  for (ll i=1;i<=x;i++) {
    if (i * (i+1) / 2 >= x) {
      cout << i << endl;
      return;
    }
  }
}

int main() {
  cin >> x;
  solve();
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
#define N 100000
 
typedef struct{
  char name[10];
  int time;
}process;
 
void enq(process);
process deq(void);
 
int head=0, tail=0, max;
process Process[N];
 
int main(){
  int i, n, q, sum=0;
  process p;
 
  scanf("%d%d", &n, &q);
   
  if( n<1 || 100000<n ) exit(1);
  if( q<1 || 1000 < q ) exit(2);
        
  for( i=0 ; i<n ; i++ ){
    scanf("%s%d", p.name, &p.time);
     
    if( strlen(p.name)<1 || 10<strlen(p.name) ) exit(3);
    if( p.time<1 || 50000<p.time ) exit(4);
    enq(p);
  }
 
  while(1){
    if(head == tail) break;
    if(Process[head].time > q){
      p = deq();
      p.time -=q;
      enq(p);
      sum += q;
    }
    else{
      p = deq();
      printf("%s %d\n", p.name, p.time + sum);
      sum += p.time;
    }
  }
 
  return 0;
}
 
void enq(process p){
  Process[tail] = p;
  if(tail+1 == N){
    tail = 0;
  }
  else tail++;
}
 
process deq(){
  process  x;
 
  x = Process[head];
  if(head+1 == N){
    head = 0;
  }
  else head++;
  return x;
}

Measured memory_bytes: 2160
#include<algorithm>
#include<cstdio>
#include<vector>

using namespace std;

typedef pair<int, int> i_i;

#define rep(i, n) for(i = 0;i < n;++i)
#define int(x) int x; scanf("%d",&x)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define pb push_back
#define all(x) (x).begin(), (x).end()

struct rsqsegtree{
  vector<int> t;
  int re;
  int n;
  void use(int N){
    re = 0; n = N;
    int i, j;
    for(i = 0;;++i)if((1 << i) >= n)break;
    ++i; t.resize(1 << i); t[0] = 1 << i;
    for(i = 1;i < t[0];++i)t[i] = re;
    t[0] >>= 1;
    return;
  }
  void update(int at, int data){
    t[t[0] + at] += data;
    int tmp;
    for(int x = t[0] + at;x >= 2;x >>= 1)
    t[x >> 1] = (t[(x >> 1) << 1] + t[((x >> 1) << 1) + 1]);
    return;
  }
  int query(int l, int r, int k, int kl, int kr){
    if(k >= t.size())return re;
    if(kl >= r || kr <= l)return re;
    if(l <= kl && kr <= r)return t[k];
    return query(l, r, k * 2, kl, (kl + kr) >> 1) + query(l, r, k * 2 + 1, (kl + kr) >> 1, kr);
  }
  int getsum(int l, int r){ return query(l, r, 1, 0, t[0]); }
  void deb(void){
    int x = 1;
    t[0] *= 2;
    printf("t[0] : %d\n", t[0]);
    for(int i = 1;i < t[0];++i){
      printf("%11d", t[i]);
      if(i == (1 << x) - 1){ puts(""); ++x; }
    }
    t[0] /= 2;
    return;
  }
};

struct query{
  int q, y, l, r;
};
bool ysort(query qwe, query rty){
  if(qwe.y != rty.y)return qwe.y < rty.y;
  return qwe.q > rty.q;
}

rsqsegtree ST;
query Q[300000];
vector<int> x;
int qh = 0;

int inv(int d){
  int l = 0, r = x.size(), m;
  for(;l + 1 < r;){
    m = l + (r - l) / 2;
    if(d == x[m])return m;
    if(d > x[m])l = m;
    else r = m;
  }
  return l;
}

signed main(void){
  int i, j;
  int(n);
  rep(i, n){
    int4(x1, y1, x2, y2);
    if(x1 == x2){
      Q[qh++] = (query){1, min(y1, y2), x1, 0};
      Q[qh++] = (query){-1, max(y1, y2), x1, 0};
      x.pb(x1);
    }else{
      Q[qh++] = (query){0, y1, min(x1, x2), max(x1, x2)};
      x.pb(x1);
      x.pb(x2);
    }
  }
  sort(Q, Q + qh, ysort);
  sort(all(x));
  x.erase(unique(all(x)), x.end());

  ST.use(x.size());
  int res = 0;
  rep(i, qh){
    if(Q[i].q == 0)res += ST.getsum(inv(Q[i].l), inv(Q[i].r) + 1);
    else ST.update(inv(Q[i].l), Q[i].q);
  }
  printf("%d\n", res);

  return 0;
}

Measured memory_bytes: 6452
import java.util.HashMap;
import java.util.Scanner;

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

		int n = sc.nextInt();
		String[] s = new String[n];

		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
		}

		HashMap<Character, Integer> hm = new HashMap<>();

		for (int i = 0; i < n; i++) {
			hm.put(s[i].charAt(0), hm.getOrDefault(s[i].charAt(0), 0) + 1);
		}

		char[] c = { 'M', 'A', 'R', 'C', 'H' };
		int[] ar = new int[5];
		for (int i = 0; i < ar.length; i++) {
			ar[i] = hm.getOrDefault(c[i], 0);
			//			System.out.println(ar[i]);
		}

		long ans = 0l;
		ans += (long) ar[0] * ar[1] * ar[2];
		ans += (long) ar[0] * ar[1] * ar[3];
		ans += (long) ar[0] * ar[1] * ar[4];
		ans += (long) ar[0] * ar[2] * ar[3];
		ans += (long) ar[0] * ar[2] * ar[4];
		ans += (long) ar[0] * ar[3] * ar[4];
		ans += (long) ar[1] * ar[2] * ar[3];
		ans += (long) ar[1] * ar[2] * ar[4];
		ans += (long) ar[1] * ar[3] * ar[4];
		ans += (long) ar[2] * ar[3] * ar[4];

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 51644
a = int(input())

ans_cnt = 0

for idx in range(a):
	idx_unit = list(str(idx + 1))
	idx_count = 0
	for item in idx_unit:
		idx_count += len(item)
	
	if idx_count % 2 == 1:
#		print(idx_count)
		ans_cnt += 1

print(ans_cnt)



Measured memory_bytes: 2940
import java.util.*;
import java.util.stream.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.next();
		String s = sc.next();
		System.out.println(IntStream.range(1, s.length()).filter(i -> s.charAt(i - 1) != s.charAt(i)).count() + 1);
	}
}


Measured memory_bytes: 29168
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    if a[i]%2==0:
        if a[i]%3==0 or a[i]%5==0:
            pass
        else:
            print("DENIED")
            break
else:
    print("APPROVED")

Measured memory_bytes: 63980
while True:
    list = input().split()
    a = int(list[0])
    op = list[1]
    b = int(list[2])
    if op == '?':
        break
    elif op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(a//b)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n, a, b, c, d, hasil;
int main(){
	while(cin >> n){
		hasil = 0;
		for(int j = 0; j <= 9; j++){
			for(int k = 0; k <= 9; k++){
				for(int l = 0; l <= 9; l++){
					for(int m = 0; m <= 9; m++){
						if(j + k + l + m == n){
							hasil++;
						}
					}
				}
			}
		}
		cout << hasil << "\n";	
	}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
    cout<<fixed<<setprecision(12);
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    double xx,yy;
    xx=x2-x1;
    yy=y2-y1;
    cout<<sqrt(xx*xx+yy*yy)<<endl;
    return 0;
}



Measured memory_bytes: 3276
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define nn 655360
#define ll long long
#define mod 998244353
#define lf double
using namespace std;
ll L,n;
ll sum[nn];
ll ascsum[nn];ll p[nn];
ll ans=0;
ll len[nn];
void upd(ll x)
{
	ans=max(ans,x);
}
ll getsum(ll l,ll r)
{
	return sum[r]-sum[l-1];
}
ll solve()
{
	for(int i=1;i<=n;i++) len[i]=p[i]-p[i-1];
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+len[i],ascsum[i]=ascsum[i-1]+len[i]*i*2;
	for(int i=1;i<n;i++)// go to right
	{
		if((n-i+1)%2==1)
		{
			ll cl=(n-i+2)/2,cr=(n-i)/2;
		
			ll res=0;
			res+=sum[i]*(cl+cr);//cout<<i<<":"<<res<<"\n";
			res+=-ascsum[i+cl-1]+ascsum[i]+getsum(i+1,i+cl-1)*(2*i+2+cl+cr-2);//cout<<i<<":"<<res<<"\n";
			res+=ascsum[n]-ascsum[n-cr+1]+getsum(n-cr+2,n)*(cl+cr-3-2*n);//cout<<i<<":"<<res<<"\n";
			res+=(cl+cr-1)*(L-p[n]);//	cout<<i<<":"<<res<<"\n";
			upd(res);
		}
		else 
		{
			ll cl=(n-i+1)/2,cr=(n-i+1)/2;
			ll res=0;
			res+=sum[i]*(cl+cr);
			res+=-ascsum[i+cl-1]+ascsum[i]+getsum(i+1,i+cl-1)*(2*i+2+cl+cr-2);
			res+=ascsum[n]-ascsum[n-cr+1]+getsum(n-cr+2,n)*(cl+cr-3-2*n);
			res+=(cl+cr-1)*(L-p[n]);
			upd(res);
		}
	}
//	n--;
}
int main()
{
	cin>>L>>n;

	for(int i=1;i<=n;i++) scanf("%lld",&p[i]);
	if(n==1)
	{
		cout<<max(p[1],L-p[1]);
		exit(0);
	}
	solve();
	for(int i=1;i<=n;i++) p[i]=L-p[i];
	reverse(p+1,p+n+1);
	solve();
	cout<<ans;
    return 0;
}

Measured memory_bytes: 12032
S = input()
n = len(S)
pattern1 = [i % 2 for i in range(n)]
pattern2 = [i % 2 for i in range(1, n+1)]
ans1 = 0
ans2 = 0
for i in range(n):
    s = S[i]
    if s == str(pattern1[i]):
        ans1 += 1
    if s == str(pattern2[i]):
        ans2 += 1
else:
    ans = min(ans1, ans2)
print(ans)


Measured memory_bytes: 10600
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - *3 or /2
            int n = int.Parse(Console.ReadLine());
            var a = ReadLine();

            //操作を実行した回数
            int count = 0;

            for(int i = 0; i < n; i++)
            {
                while (a[i] % 2 == 0)
                {
                    a[i] /= 2;
                    count++;
                }
            }

            Console.WriteLine(count);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int N, M; cin >> N >> M;
  if (N < 1  || N > 9 || M < 1 || M > 9) {
    cout << -1 << endl;
  } else {
    cout << N*M << endl;
  }
              
  
}


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

char bt[9][8] = {
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};

int main(){
    int N;
    for(scanf("%d", &N); N--;){
        char mes[1280];
        scanf(" %s", mes);
        int len = strlen(mes);
        int prv = 0, count = 0;
        for(int i = 0; i < len; i++){
            if(mes[i] == '0'){
                if(prv > 0){
                    --prv;
                    printf("%c", bt[prv][--count % strlen(bt[prv])]);
                }
                count = 0;
            }else{
                count++;
            }
            prv = mes[i] - '0';
        }
        if(prv > 0){
            --prv;
            printf("%c", bt[prv][--count % strlen(bt[prv])]);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1176