akhauriyash/Code-Regression huggingface dataset:
L = input().split()

w=int(L[0])
a=int(L[1])
b=int(L[2])

if a<b:
    if a+w<b:
        move=abs(a+w-b)
        print(move)
    else:
        print(int(0))

elif a>b:
    if b+w<a:
        m=abs(b+w-a)
        print(m)
    else:
        print(int(0))

else:
    print(int(0))        


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

const int M = 3, N = 1e5 + 100;

int n, fen[N], a[M][N];

void input() {
	cin >> n;
	for (int i = 0; i < M; i++)
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
}

void NO() {
	cout << "No\n";
	exit(0);
}

void check_1() {
	for (int i = 0; i < n; i++)
		if (a[0][i] / 3 != a[1][i] / 3 || a[1][i] / 3 != a[2][i] / 3)
			NO();
}

void check_2() {
	for (int i = 0; i < n; i++)
		if (a[1][i] % 3 != 1)
			NO();
}

void check_3() {
	for (int i = 0; i < M; i++)
		for (int j = 0; j < n; j++)
			if (j % 2 != (a[i][j] / 3) % 2)
				NO();
}

void add(int x) {
	for (++x; x < N; x += x & -x)
		fen[x] ^= 1;
}

int get(int x) {
	int res = 0;
	for (; x; x ^= x & -x)
		res ^= fen[x];
	return res;
}

int inversion(vector<int> vec) {
	memset(fen, 0, sizeof fen);
	int res = 0;
	reverse(vec.begin(), vec.end());
	for (int x: vec) {
		res ^= get(x);
		add(x);
	}
	return res;
}

void check_4(int X, int Y) {
	vector<int> vec;
	for (int i = Y; i < n; i += 2)
		vec.push_back(a[0][i] / 3);
	int res = inversion(vec);
	for (int i = X; i < n; i += 2)
		res ^= (a[0][i] > a[2][i]);
	if (res)
		NO();
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	input();
	check_1();
	check_2();
	check_3();
	check_4(0, 1);
	check_4(1, 0);
	cout << "Yes\n";
}


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

ans=0
for i in range(1,len(X)):
    if (X[i]-X[i-1])*A>B:
        ans+=B
    else:
        ans+=(X[i]-X[i-1])*A
print(ans)


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

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


//入力変数
int N = sc.nextInt();
int a[] = new int[N];
for(int i = 0;i<N;i++){
a[i]=sc.nextInt();
}

//入力値変換
Arrays.sort(a);

//出力変数
int ans=0;

//計算
for(int i = 0;i<N;i++){
ans += Math.pow(-1,N-i-1)*a[i];
}

//出力
System.out.println(ans);

}
}


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


int A[105];


int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	int sum = 0;

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

		scanf("%d",&A[i]);
		sum += A[i];
	}

	int count = 0;

	for(int i = 0; i < N; i++){
		if(A[i]*4*M >= sum){

			count++;
		}
	}

	if(count >= M){

		printf("Yes\n");

	}else{

		printf("No\n");
	}

	return 0;
}


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

int main(){
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> v(n,k-q);
	while (q--){
		int a;
		cin >> a;
		v[a-1]++;
	}
	for (int x: v){
		//cout << x << endl;
		x > 0 ? cout << "Yes" << endl : cout << "No" << endl;
	}
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	ll x,y,h;
};

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

	int N=in();
	vector<Data> P(N);
	REP(i,N){
		P[i].x=in();
		P[i].y=in();
		P[i].h=in();
	}

	REP(i,101){
		int cy=i;
		REP(j,101){
			int cx=j;
			int H = -1;
			bool exist=true;
			REP(k,N){
				if(P[k].h>=1){
					H=P[k].h+abs(P[k].x-cx)+abs(P[k].y-cy);
					break;
				}
			}
			REP(k,N){
				int V=max<ll>(H-abs(P[k].x-cx)-abs(P[k].y-cy),0);
				if(P[k].h!=V){
					exist = false;
					break;
				}
			}
			if(exist){
				out(cx,cy,H);
				return 0;
			}
		}
	}
	return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d,mi=100000000;
	cin>>a>>b>>c;
	vector<int>va(a);
	vector<int>vb(b);
	int x,y;
	int mia=100000000,mib=100000000;
	for(int i=0;i<a;i++){
		cin>>va[i];
		mia=min(mia,va[i]);
	}
	for(int i=0;i<b;i++){
		cin>>vb[i];
		mib=min(mib,vb[i]);
	}
	mi=mia+mib;
	for(int i=0;i<c;i++) {
		cin>>x>>y>>d;
		if(va[x-1]+vb[y-1]-d<mi){
			mi=min(mi,va[x-1]+vb[y-1]-d);
		}
	}
	cout<<mi<<endl;
	return 0;
}


Measured memory_bytes: 3996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007
#define rep(i,n) for(ll i=0;i<n;i++)

int main(void){
  vector<int> a(3);
  rep(i,3)cin >> a[i];
  int ans=0;
  sort(a.begin(),a.end());
  for(int i=1;i<3;i++){
    ans+=abs(a[i]-a[i-1]);
  }

  cout << ans << endl;
  return 0;

}


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

using namespace std;

int main() {
  int n, l; cin >> n >> l;
  vector<string> s(n);
  for(int i=0; i<n; ++i) {
    cin >> s.at(i);
  }
  sort(s.begin(),s.end());
  for(int i=0; i<n; ++i) {
    cout << s[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3596
def cwrlp(data,r):
	if r <= 0:
		return []
	
	result = []
	_cwrlp(data, r, 0, [], result)
	return result

def _cwrlp(data, r, start, progress, result):
	if r == 0:
		result.append(progress)
		return
	
	for i in range(start, len(data)):
		_cwrlp(data, r-1, i, progress + [data[i]], result)

n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

#dataset = cwrlp(range(1,m+1),n)

#print(dataset)
ret = 0
for da in cwrlp(range(1,m+1),n):
#	print(da)
	ans = 0
	for i in range(q):
		a = abcd[i][0]
		b = abcd[i][1]
		c = abcd[i][2]
		if(da[b-1]-da[a-1] == c):
			d = abcd[i][3]
			ans += d
#			print(a,b,c,d,ans)
	ret = max(ret,ans)
print(ret)

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


int main()
{
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  rep(i, n)
    cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  ll ans = 0;
  priority_queue<int> q;
  rep(i, m + 1)
  {
    while (a.back().first <= i)
    {
      q.push(a.back().second);
      a.erase(a.end() - 1);
    }
    if (!q.empty())
    {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    string s;
    cin>>s;
    ll i;
    ll flag=0;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            exit(0);
        }

    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s[102];
int a[100005];
int b[100005];
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main(void){
    int n,x; cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    a[n]=x;
    sort(a,a+n+1);
    int ans=a[1]-a[0];
    for(int i=0;i<n;i++){
        b[i]=a[i+1]-a[i];
        ans=gcd(ans,b[i]);
    }
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << a-b+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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 ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int a, b, c; cin >> a >> b >> c;
  if (a + b + c >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}


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

using namespace std;

int n;
vector<int>g[100001];
bool use[100001];
int d[100001];
bool color[100001];

void solve(int u, int dd,bool c) {
  use[u] = true;
  if(d[u] > dd) {
    d[u] = dd;
    color[u] = c;
  }


  for(int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if(!use[v]) {
      solve(v,dd+1,c);
    }
  }
}
      
int main() {
  cin >> n;
  for(int i = 0; i < n-1; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  fill(d,d+100001,1e9);
  solve(0,0,true);
  fill(use,use+100001,false);
  solve(n-1,0,false);

  int black = 0;
  int white = 0;
  for(int i = 0; i < n; i++) {
    if(color[i]) black++;
    else white++;
  }

  if(black > white) cout << "Fennec" <<endl;
  else cout << "Snuke" << endl;
}
  
  


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

int N;
double p[3009];
double dp[3009][3009];

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

    dp[0][0] = 1;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= i; j++) {
            dp[i + 1][j + 1] += dp[i][j] * p[i + 1];
            dp[i + 1][j] += dp[i][j] * (1 - p[i + 1]);
        }
    }

    double res = 0;
    for(int j = (N + 1) / 2; j <= N; j++)
        res += dp[N][j];

    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 69120
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    ll n,k,i,j;
    cin>>n;
    ll a[n+1],b[n+1],c[n];
    vector<pair<ll,ll> > v[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[n+1][3];
    memset(dp,0,sizeof(dp));
    dp[1][0]=a[0];
    dp[1][1]=b[0];
    dp[1][2]=c[0];
    for(i=2;i<=n;i++)
    {
        dp[i][0]=a[i-1]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i-1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i-1]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n][2],max(dp[n][1],dp[n][0]))<<endl;
    return 0;
}

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

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


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

using namespace std;

int n, d, x[50][50], ans, mark[1000005];

double fabs(double x)
{
    return x < 0 ? -x : x;
}

bool equal(double x, double y)
{
    if (fabs(x - y) <= 1e-8) return true;
    return false;
}

int main(void)
{
    scanf("%d%d", &n, &d);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= d; ++j)
            scanf("%d", &x[i][j]);
    for (int i = 1; i <= 1000; ++i)
        mark[i * i] = true;
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j) {
            int tmp = 0;
            for (int k = 1; k <= d; ++k)
                tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            if (mark[tmp]) ++ans;
        }
    printf("%d\n", ans);
    return 0;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back

const int MOD = 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    vector<int> suf(N + 1, 0);
    for (int i = N - 1; i >= 0; i--) {
        suf[i] = suf[i + 1] + a[i];
        suf[i] %= MOD;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += a[i] * (suf[i + 1]);
        ans %= MOD;
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 6348
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger a = BigInteger.valueOf(sc.nextLong());
		BigInteger b = BigInteger.valueOf(sc.nextLong());
		BigInteger c = BigInteger.valueOf(sc.nextLong());
		sc.close();

		BigInteger right = c.subtract(a).subtract(b);
		if (right.compareTo(BigInteger.ZERO) < 0) {
			System.out.println("No");
			return;
		}
		right = right.pow(2);
		BigInteger left = BigInteger.valueOf(4).multiply(a).multiply(b);
		if (left.compareTo(right) < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

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

  if (a == b && b == c && a % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (a == b && b == c && a % 2 == 1) {
    cout << "0" << endl;
    return 0;
  } else {
    int ans = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
      int d, e, f;
      d = (b + c) / 2;
      e = (c + a) / 2;
      f = (a + b) / 2;
      a = d;
      b = e;
      c = f;
      ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(D, C, S, T):
    satisfaction = 0
    last = [-1] * 26
    for i, t in enumerate(T):
        t -= 1
        satisfaction += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            satisfaction -= c * (i - last[j])
        print(satisfaction)

if __name__ == '__main__':
    input = sys.stdin.readline
    D = int(input())
    *C, = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    main(D, C, S, T)


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

void fnInput(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

int fnRcsSch(int nPos, int nTrgSu, int nTrgKin, vector<int>& rvnNumMoney)
{
  vector<int> vnMoney{10000, 5000, 1000};

  if (nPos == rvnNumMoney.size())
    if (nTrgKin)
      return 0;
    else
      return 1;

  if (nPos == 2)
  {
    rvnNumMoney[nPos] = nTrgSu;
    return fnRcsSch(nPos + 1, nTrgSu - nTrgSu, nTrgKin - vnMoney[nPos] * nTrgSu, rvnNumMoney);
  }
  else
    for (int i = 0; i <= nTrgSu; i++)
    {
      rvnNumMoney[nPos] = i;
      if (fnRcsSch(nPos + 1, nTrgSu - i, nTrgKin - vnMoney[nPos] * i, rvnNumMoney))
        return 1;
    }

  return 0;
}

int fnExhSch(int nTrgSu, int nTrgKin)
{
  vector<int> vnNumMoney(3);

  if (fnRcsSch(0, nTrgSu, nTrgKin, vnNumMoney))
    cout << vnNumMoney[0] << " " << vnNumMoney[1] << " " << vnNumMoney[2] << endl;
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;
  
  fnInput(nTrgSu, nTrgKin);
  fnExhSch(nTrgSu, nTrgKin);

  return 0;
}
 

Measured memory_bytes: 256
c = [list(map(int, input().split())) for i in range(3)]

b = list(c[0])
a = [0, c[1][0] - b[0], c[2][0] - b[0]]
for i in range(3):
    for j in range(3):
        if c[i][j] != a[i] + b[j]:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3060
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse = True)

ok = 0
ng = n

while ng - ok > 1:
    mid = ok + (ng-ok)//2
    get = a[mid] + m
    flag = 1
    if get < a[p-1]:
        flag = 0

    cap = 0
    for i in range(n):
        if i < p-1:
            cap += m
        elif mid <= i:
            cap += m
        else:
            cap += max(get - a[i], 0)
    if cap < m*v:
        flag = 0

    if flag:
        ok = mid
    else:
        ng = mid

print(ok+1)


Measured memory_bytes: 85496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N;
  cin >> N;
  set<string> S;
  rep(i, N){
    string s;
    cin >> s;
    S.insert(s);
  }
  cout << sz(S) << endl;
}

Measured memory_bytes: 19180
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;

struct UnionFind {
  vector<int> parent; // parent[root] is the negative of the size.
  UnionFind(int n) : parent(n, -1) { };
  bool unite(int u, int v) { 
    u = root(u); v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v]; parent[v] = u;
    return true;
  }
  bool find(int u, int v) { return root(u) == root(v); }
  int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
  int size(int u) { return -parent[root(u)]; }
};

signed main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; ++i) cin >> a[i] >> b[i];
    vector<int> c(k), d(k);
    for (int i = 0; i < k; ++i) cin >> c[i] >> d[i];
    vector<int> adj(n, 0), blk(n,0);
    UnionFind fr(n), bl(n);
    
    for (int i = 0; i < m; ++i){
        ++adj[a[i] - 1], ++adj[b[i] - 1];
        fr.unite(a[i] - 1, b[i] - 1);
    }
    for (int i = 0; i < k; ++i){
        bl.unite(c[i] - 1, d[i] - 1);
        if (fr.find(c[i] - 1, d[i] - 1)) ++blk[c[i] - 1], ++blk[d[i] - 1];
    }

    for (int i = 0; i < n; ++i) cout << (i ? " " : "") << fr.size(i)-1 - adj[i]-blk[i];
    //cout << endl;
    //for (int i = 0; i < n; ++i) cerr << fr.size(i)-1 << "-" << adj[i] << "-" << blk[i] << "\n";
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int a[maxn];
int n, k;
ll ans;
inline void solve(int l,int r) {
	if(l == r) return void(ans += a[l] >= 0);
	std::vector<ll> v0, v1;
	int mid = l + r >> 1; ll s = 0;
	for(int i = mid;i >= l;--i) v0.push_back(s += a[i]);
	std::sort(v0.begin(), v0.end()), s = 0;
	for(int i = mid + 1;i <= r;++i) {
		s += a[i], ans += v0.end() - std::lower_bound(v0.begin(), v0.end(), - s);
	}
	solve(l, mid), solve(mid + 1, r);
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	rep(i, 1, n) cin >> a[i], a[i] -= k;
	solve(1, n);
	cout << ans << '\n';
}


Measured memory_bytes: 2792
require 'matrix'

n, m = gets.split.map(&:to_i)
arr, ary = [], []

n.times{ arr << gets.split.map(&:to_i) }
m.times{ ary << gets.to_i}

ma = Matrix[*arr]
mb = Matrix.column_vector(ary)
mc = ma * mb

mc.each do |c|
  puts c
end

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

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);

        while (true) {
            final int n = scanner.nextInt();
            if (n == 0) {
                break;
            }
            int[] pages = new int[n];
            for (int i = 0; i < pages.length; i++) {
                pages[i] = scanner.nextInt();
            }
            Arrays.sort(pages);
            int index = 0;
            while (index < pages.length) {
                int start = index++;
                while (index < pages.length && pages[index - 1] + 1== pages[index]) {
                    index++;
                }
                if (start + 1 < index) {
                    System.out.print(String.format("%d-%d", pages[start], pages[index - 1]));
                } else {
                    System.out.print(pages[start]);
                }
                if (index < pages.length) {
                    System.out.print(' ');
                }
            }
            System.out.println();
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <set>
#include <cstring>
using namespace std;
int main(){
	int n;
	cin >> n;
	set<string> s;
	string t;
	for(int i = 0;i < n;i++){
		cin >> t;
		s.insert(t);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 19060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false; cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  lli n = s.size();
  lli ans = n;
  for (lli i=1; i<n; ++i) {
    if (s[i-1] != s[i])
      ans = min(ans, max(i, n-i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int N,Q;
char s[200010];
char t[200010];
char d[200010];
int check(int p)
{
	int x = p;
	for(int i = 1;i <= Q;i++){
		if(t[i]==s[x]){
			if(d[i]=='R') x++;
			else x--;
		}
		if(x<=0) return 0;
		if(x>N) return 1;
	}
	if(x==N) return 2;
	else if(x==1) return 3;
	else return 4;
}
int main()
{
	scanf("%d%d",&N,&Q);
	for(int i = 1;i <= N;i++) cin>>s[i];
	for(int i = 1;i <= Q;i++){
		cin>>t[i]>>d[i];
	}
	int l = 1,r = N;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)==0){
			l = mid+1;
		}
		else r = mid-1;
	}
	int num = N-l+1;
	int ll = 1,rr=N;
	while(ll<=rr){
		int midmid = (ll+rr)/2;
		if(check(midmid)==1){
			rr = midmid-1;
		}
		else{
			ll = midmid+1;
		}
	}
	num = num - (N-rr);
	cout<<num<<endl;
	return 0;
}

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

typedef long long ll;

const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> num(N);
    for (int i=0;i<N-1;i++) {
        int A;
        cin >> A;
        A--;
        num[A]++;
    }
    for (int i=0;i<N;i++){
        cout << num[i] << "\n";
    }


    return 0;
}

Measured memory_bytes: 4048
#include<iostream>

using namespace std;
typedef long long ll;

int main() {
	ll r, d, x2000;
	cin >> r >> d >> x2000;
	for (int i = 1; i <= 10; i++) {
		x2000 = r*x2000 - d;
		cout << x2000 << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long LL;
#define INF 0x3f3f3f3f3f3f3f3fLL

LL n,a,b,c,d;
map<LL,LL> f;

void upd(LL &x,LL y){
	x=min(x,y);
}

LL dfs(LL x){
	if (!x) return 0;
	if (x==1) return d;
	if (f.count(x)) return f[x];
	f[x]=INF;
	if (INF/x>=d) upd(f[x],x*d);
	LL t=x/2; upd(f[x],dfs(t)+a+d*(x-t*2));
	t=x/2+1; upd(f[x],dfs(t)+a+d*(t*2-x));
	t=x/3; upd(f[x],dfs(t)+b+d*(x-t*3));
	t=x/3+1; upd(f[x],dfs(t)+b+d*(t*3-x));
	t=x/5; upd(f[x],dfs(t)+c+d*(x-t*5));
	t=x/5+1; upd(f[x],dfs(t)+c+d*(t*5-x));
	return f[x];
}

void solve(){
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	f.clear();
	printf("%lld\n",dfs(n));
}

int main(){
	LL T; scanf("%lld",&T);
	while (T--) solve();
	
	return 0;
}
			

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

int compare_int_up(const void *a,const void *b)
{
  return *(int*)a-*(int*)b;
}

int compare_int_down(const void *a,const void *b)
{
  return *(int*)b-*(int*)a;
}

int main(void){


  int a[21];
  int six[6];
  int L;
  int i,j;
  int max;
  int min;
  int temp;
  int ansi;
  int ansj;
  char c;
  
  while(1){

    scanf("%d %d",&a[0],&L);

    getchar();

    if(a[0]==0 && L==0){
      break;
    }

    for(i=0;i<6;i++){
      six[i]=0;
    }

    for(i=0;i<20;i++){

      temp=a[i];
      
      for(j=L-1;j>=0;j--){
	six[j]=temp%10;
	temp/=10;
      }

      qsort(six,L,sizeof(int),compare_int_down);
      for(j=0,max=0;j<L;j++){	
	max*=10;
	max+=six[j];
      }
    
      qsort(six,L,sizeof(int),compare_int_up);

      for(j=0,min=0;j<L;j++){	
	min*=10;
	min+=six[j];
      }
    
      a[i+1]=max-min;

    }  
  
    c=0;

    /*for(i=0;i<21;i++){
      printf("%d,",a[i]);
    }
    printf("\n");*/

    for(j=0;j<21;j++){

      temp=a[j];
      ansj=j;
      for(i=0;i<21;i++){
	if(temp==a[i] && i>j && c==0){
	  ansi=i;
	  c=1; 
	}
      }  

      if(c==1){
	break;
      }

    }

    printf("%d %d %d\n",ansj,a[ansj],ansi-ansj);

  }

  return 0;

}

Measured memory_bytes: 608
import sys

def main():
	while True:
		m = input()
		if m == 0: return 0
		dp = {}
		dp[(0, 0)] = 1
		for i in xrange(m):
			v, c = map(int, raw_input().split())
			for j in xrange(1001):
				for k in xrange(c + 1):
					key = (i + 1, j + v * k)
					dp.setdefault(key, 0)
					dp[key] += dp.get((i, j), 0)
		n = input()
		for i in range(n):
			x = input()
			print dp.get((m, x), 0)

if __name__ == '__main__':
	sys.exit(main())

Measured memory_bytes: 7392
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

using P=vector<int>;

int sz;

P mul(const P &a,const P &b){
  P ret(sz);
  for(int i=0;i<sz;i++){
    ret[i]=b[a[i]];
  }
  return ret;
}

P pow_p(P a,ll x){
  P ret(sz);
  for(int i=0;i<sz;i++){ret[i]=i;}
  while(x>0){
    if(x&1){ret=mul(ret,a);}
    a=mul(a,a);
    x>>=1;
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<ll> A(N);
  sz=N-1;
  cin>>A;
  vector<ll> dif(N-1);
  for(int i=0;i+1<N;i++){dif[i]=A[i+1]-A[i];}
  ll M,K;
  cin>>M>>K;
  vector<int> uku(sz);
  for(int i=0;i<sz;i++){uku[i]=i;}
  for(int i=0;i<M;i++){
    ll a;
    cin>>a;
    a--;
    swap(uku[a-1],uku[a]);
  }
  uku=pow_p(uku,K);
  for(int i=1;i<N;i++){
    A[i]=A[i-1]+dif[uku[i-1]];
  }
  for(auto &I:A){cout<<I<<endl;}  

  
  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>

struct node{
	int dst;
	bool isEven;
};

std::vector<int> color;
std::vector<std::vector<node>> graph;

void dfs(int x, int c){
	color[x]=c;

	for(int i=0; i<graph[x].size(); i++){
		if(color[graph[x][i].dst]==-1)
			dfs(graph[x][i].dst, c);

	}
}

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

	color.resize(n, -1);
	graph.resize(n);

	for(int i=0; i<m; i++){
		int tmpS, tmpD, tmpW;
		std::cin>>tmpS>>tmpD>>tmpW;
		graph[tmpS-1].push_back({tmpD-1, tmpW%2==0});
		graph[tmpD-1].push_back({tmpS-1, tmpW%2==0});
	}

	int c= 0;
	for(int i=0; i<n; i++){
		if(color[i]!=-1)
			continue;

		dfs(i, c);
		c++;
	}

	std::cout<<c<<std::endl;

	return 0;
}

Measured memory_bytes: 9216
import sys
import math

n, h = map(int, input().split())
a = 0
b = []

for i in range(n):
    x, y = map(int, input().split())
    a = max(a, x)
    b.append(y)

b.sort(reverse=True)

b = [x for x in b if x > a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

if len(b) == 0:
    i = -1

ans = i + 1 + math.ceil(h / a)

print(ans)

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

using namespace std;

using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  string S;
  cin >> S;
  auto kai = [](string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
  };
  if(kai(S)) {
    int N = (int) S.size();
    string X = S.substr(0, (N - 1) / 2);
    string U = S.substr((N - 1) / 2 + 1);
    if(kai(X) && kai(U)) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  } else {

    cout << "No\n";
  }
}


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

using namespace std;
using ll=long long;
ll N;


ll func(ll n)
{
  ll ret = 0;
  for(ll i = 1; i * i <= n; i++)
  {
    if(n % i == 0)
    {
      ret++;
      if(i * i != n)
      {
          ret++;
      }
    }
  }
  return ret;
}

int main()
{
    cin >> N;
    ll sum = 0;
    for(ll i = 1;i <= N;i++)
    {
        ll dn = N / i;
        sum += (dn*(dn+1)*i)/2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3192
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&b!=c)||(a==c&&a!=b)||(b==c&&a!=c))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

int n, s;

ll dfs(int v, int sum, int depth) {
	ll res = 0;
	if (depth == n) {
		if (sum == s) return 1;
		else return 0;
	}
	REP(i, v + 1, 10) {
		ll tmp = dfs(i, sum + i, depth + 1);
		res += tmp;
		if (false) {
			cout << "dfs(" << i << "," << sum + i << "," << depth + 1
				<< ") = " << tmp << endl;
		}
	}
	return res;
}

int main() {
	while (1) {
		cin >> n >> s;
		if (n == 0) break;
		// dump(dfs(2, 6, 3));
		cout << dfs(-1, 0, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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--)
#define mp make_pair
#define fi first
#define sc second
ll a[3];
int main(){
	REP(i,3)
		cin >> a[i];
	sort(a,a+3);

	if(a[0] == 5 && a[1] == 5 && a[2] == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=1e16;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define MOD 1000000007
int main(){
	int n,m;
	cin>>n>>m;
	vi a(n);
	rep(i,n)cin>>a[i];
	vi b(m);
	rep(i,m)cin>>b[i];
	ll sum=0,sum1=0;
	rep(i,n-1){
		ll t=(i+1)*(ll)(n-i-1)%MOD;
		ll s=(a[i+1]-a[i])%MOD;
		sum+=t*s%MOD;
		sum%=MOD;
	}
	rep(i,m-1){
		ll t=(i+1)*(ll)(m-i-1)%MOD;
		ll s=(b[i+1]-b[i])%MOD;
		sum1+=t*s%MOD;
		sum1%=MOD;
	}
	cout<<sum*sum1%MOD<<endl;
}








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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;


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

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

    fill_n(dp, n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        if (i+1 < n) {
            dp[i+1] = min(dp[i+1], dp[i] + abs(a[i]-a[i+1]));
        }
        if (i+2 < n) {
            dp[i+2] = min(dp[i+2], dp[i] + abs(a[i]-a[i+2]));
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}



Measured memory_bytes: 1024
n = int(input())
blueList = [input() for _ in range(n)]
m = int(input())
redList = [input() for _ in range(m)]
max_score = 0
for i in blueList:
    score = blueList.count(i) - redList.count(i)
    if max_score < score:
        max_score = score
print(max_score)

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

int main() {
  int n;
  while(cin >> n && n) {
    int max=0,min=1000000000;
    for(int i=0; i<n; i++) {
      int sum=0;
      for(int j=0; j<5; j++) {
	int x;
	cin >> x;
	sum+=x;
      }
      if(max<sum) max=sum;
      if(min>sum) min=sum;
    }
    cout << max << " " << min << endl;
  }
  return 0;
}


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

int main(){
    ll N,M;
    cin >> N >> M;
    vector<int> array(N); //順列の一覧
    vector<vector<int>> pass(M,vector<int>(2));
    rep(i,N){
        array.at(i) = i+1;
    }
    rep(i,M){
        cin >> pass.at(i).at(0) >> pass.at(i).at(1);
    }
    int counter = 0;
    ll length = 0;
    bool finished = false,reach = false;
    do{
        if(array.at(0)!=1){
            break;
        }
        reach = false;
        rep(i,N-1){//arrayを最後まで見る
            finished = true;
            rep(j,M){ //passの中にarray.at(i)とarray.at(i+1)を繋ぐものがあるか
                if(pass.at(j).at(0)==min(array.at(i),array.at(i+1)) 
                && pass.at(j).at(1)==max(array.at(i),array.at(i+1)) ){
                    finished = false;
                    break;//あったらOKでまだ探索、finishedをfalseにしてbreak;
                }
            }
            if(finished){
                break;//見つからなかった場合
            }
            if(i==N-2){
                reach = true;
            }
        }
        if(reach){
            counter++;
        }
    }while(next_permutation(array.begin(),array.end()));
    cout << counter << endl; 
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>

#define MAX 2000001

int heap=0;

void maxHeapify(int *, int);
void buildMaxHeap(int *);
int heapExtractMax(int *);
void maxHeapInsert(int *,int);
void heapIncreaseKey(int *,int,int);

int main(){
  int key,value;
  int A[MAX];
  char str[10];

  while(1){
    scanf("%s",str);

    if(str[0]=='i'){
      scanf("%d",&key);
      maxHeapInsert(A,key);
    }

    else if(str[1]=='x'){
      value=heapExtractMax(A);
      printf("%d\n",value);
    }

    else break;
  }
      
  return 0;
}

void maxHeapify(int *A, int i){
  int left,right,largest,tmp;

  left=2*i;
  right=left+1;

  if(left<=heap && A[left]>A[i]) largest=left;
  else largest=i;
  if(right<=heap && A[right]>A[largest]) largest=right;

  if(largest!=i){
    tmp=A[largest];
    A[largest]=A[i];
    A[i]=tmp;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;

  for(i=heap/2;1<=i;i--) maxHeapify(A,i);
}

int heapExtractMax(int *A){
  int max;

  max=A[1];
  A[1]=A[heap];
  heap--;
  maxHeapify(A,1);
  
  return max;
  
}

void maxHeapInsert(int *A,int key){
  heap++;
  A[heap]=-1*MAX;
  heapIncreaseKey(A,heap,key);
}

void heapIncreaseKey(int *A,int i,int key){
  int tmp;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    tmp=A[i];
    A[i]=A[i/2];
    A[i/2]=tmp;
    i=i/2;
  }
}



Measured memory_bytes: 5648
import java.util.Scanner;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
        for(int i = 0;i < str.length();i++){
            char c = str.charAt(i);
            if(i%2 == 0 && c == 'L'){
                System.out.println("No");
                break;
            }
            if(i%2 == 1 && c == 'R'){
                System.out.println("No");
                break;
            }
            if(i == str.length()-1)
                System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21460
import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;
public class Main {
	public static void merge(long arr[], int l, int m, int r) 
    { 
        // Find sizes of two subarrays to be merged 
        int n1 = m - l + 1; 
        int n2 = r - m; 
  
        /* Create temp arrays */
        long L[] = new long [n1]; 
        long R[] = new long [n2]; 
  
        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i) 
            L[i] = arr[l + i]; 
        for (int j=0; j<n2; ++j) 
            R[j] = arr[m + 1+ j]; 
  
  
        /* Merge the temp arrays */
  
        // Initial indexes of first and second subarrays 
        int i = 0, j = 0; 
  
        // Initial index of merged subarry array 
        int k = l; 
        while (i < n1 && j < n2) 
        { 
            if (L[i] <= R[j]) 
            { 
                arr[k] = L[i]; 
                i++; 
            } 
            else
            { 
                arr[k] = R[j]; 
                j++; 
            } 
            k++; 
        } 
  
        /* Copy remaining elements of L[] if any */
        while (i < n1) 
        { 
            arr[k] = L[i]; 
            i++; 
            k++; 
        } 
  
        /* Copy remaining elements of R[] if any */
        while (j < n2) 
        { 
            arr[k] = R[j]; 
            j++; 
            k++; 
        } 
    } 
	 public static void sort(long arr[], int l, int r) 
	    { 
	        if (l < r) 
	        { 
	            // Find the middle point 
	            int m = (l+r)/2; 
	  
	            // Sort first and second halves 
	            sort(arr, l, m); 
	            sort(arr , m+1, r); 
	  
	            // Merge the sorted halves 
	            merge(arr, l, m, r); 
	        } 
	    } 
	 private static int gcd(int n, int l) {
	        if (l == 0)
	            return n;
	        return gcd(l, n % l);
	    }
	public static void main(String[] args) throws Exception
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();int k=sc.nextInt()-1;
		sc.nextLine();
		String s=sc.nextLine();
		for(int i=0;i<n;i++)
		{
			if(i!=k)
				System.out.print(s.charAt(i));
			else
				System.out.print(Character.toLowerCase(s.charAt(i)));
		}
	}
}


Measured memory_bytes: 21588
# メイン関数
def main():
    # 入力データ
    s = input()
    t = input()

    # dpテーブルの作成
    dp = [[0] * (len(t)+1) for i in range(len(s)+1)]
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

    # 部分列の復元
    ans = ''
    i = len(s)
    j = len(t)
    while i != 0 and j != 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            i -= 1
            j -= 1
            ans = s[i] + ans

    # 解答の出力
    print(ans)
    return


# 実行
if __name__ == '__main__':
    main()


Measured memory_bytes: 144300
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> L(N + 1);
  L[0] = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == '>'){
      L[i + 1] = L[i] + 1;
    } else {
      L[i + 1] = L[i];
    }
  }
  vector<int> R(N + 1);
  R[N] = 0;
  for (int i = N - 1; i >= 0; i--){
    if (S[i] == '<'){
      R[i] = R[i + 1] + 1;
    } else {
      R[i] = R[i + 1];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    int tmp;
    if (S[i] == '>'){
      if (L[i + 1] > R[i + 1]){
        tmp = L.end() - lower_bound(L.begin(), L.end(), L[i + 1] - R[i + 1]);
      } else {
        tmp = R.rend() - upper_bound(R.rbegin(), R.rend(), R[i + 1] - L[i + 1]);
      }
    }
    if (S[i] == '<'){
      if (L[i] >= R[i]){
        tmp = L.end() - upper_bound(L.begin(), L.end(), L[i] - R[i]);
      } else {
        tmp = R.rend() - upper_bound(R.rbegin(), R.rend(), R[i] - L[i] - 1);
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3988
#include <stdio.h>

#define M 250

int main(){
  int hp,i,tree[M+1];

  scanf("%d",&hp);
  for(i=1;i<=hp;i++){
    scanf("%d",&tree[i]);
  }

    for(i=1;i<=hp;i++){
      printf("node %d: key = %d, ",i,tree[i]);
      if(i/2>=1) printf("parent key = %d, ",tree[i/2]);

      if(i*2<=hp) printf("left key = %d, ",tree[i*2]);
      if(i*2+1<=hp) printf("right key = %d, ",tree[i*2+1]);

      printf("\n");
    }
    return 0;
}



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

void solve(long long X, long long N, std::vector<long long> p) {
    ll min = 10000;
    ll ans = 0;
    for (ll i = 0; i <= 101; i++) {
        bool exists = false;
        rep(j, N) {
            if (p[j] == i) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            if (min > abs(X - i)) {
                ans = i;
                min = abs(X - i);
            }
        }
    }
    cout << ans << endl;
}

int main() {
    long long X;
    scanf("%lld", &X);
    long long N;
    scanf("%lld", &N);
    std::vector<long long> p(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
 
int main(){fastio
    ll t1,t2,a1,a2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    if(a1>b1){
        swap(a1,b1);
        swap(a2,b2);
    }
    if(a2<b2){
        cout<<0;return 0;
    }
    ll dis=a1*t1+a2*t2-b1*t1-b2*t2;
    if(dis<0){
        cout<<0;return 0;
    }
    if(dis==0){
        cout<<"infinity"<<endl;return 0;
    }
    
    /*
    ll sa=a1*t1+a2*t2;
    ll sb=b1*t1+b2*t2;
    ll ans=1;
    cout<<sa<<" "<<sb<<endl;
     */
    //cout<<dis<<endl;
    ll k=(b1*t1-a1*t1)/dis;
        if((b1*t1-a1*t1)%dis==0){
            cout<<2*k<<endl;
        }else{
            cout<<2*k+1<<endl;
        }
    
    
    
    return 0;
}

/*
 120 157
 339 381
 555 213
 */


Measured memory_bytes: 256