akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;

  ll m = n % 1000;

  ll ans = m > 0 ? 1000 - m : 0;

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3688
/** Bismillahir Rahmanir Rahim **/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n, r;
    cin >> n >> r;
    int cnt = 0;
    while (n != 0) {
        n = (n / r);
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <sstream>

using namespace std;

void A();
void B();
void C();
void D();
void E();

int main()
{
	C();
}

void A() {
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
}

void B() {
	int n, m;
	cin >> n >> m;

	vector<int> items(n);

	for (int& num : items) cin >> num;

	int sum = 0;
	for (int num : items) sum += num;

	int popular = 0;

	const double popularAmt = (double)sum / (4 * m);

	for (int num : items) {
		if (num >= popularAmt) popular++;
	}

	if (popular >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}

void C() {

	long long N, K;
	cin >> N >> K;

	long long div = N % K;

	long long m = min(div, abs(div - K));

	cout << m << endl;

}

Measured memory_bytes: 256
/*
 * atcoder/dp_2nd/m.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long
#define MOD 1000000007

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, K;
vector<int> A;

void input() {
  cin >> N >> K;
  int a;
  loop(n,0,N) {
    cin >> a;
    A.push_back(a);
  }
}

ll dp[110][100100];

ll rec(int n, int k) {
  ll &cache = dp[n][k];
  if (~cache) return cache;
  if (n == N) return k == 0;
  ll ways = 0;
  loop(i,0,min(A[n],k)+1) {
    ways += rec(n + 1, k-i);
    ways %= MOD;
  }
  return ways;
}

ll acc[100100];

ll give() {
  for (int n=0; n<N; n++) {
    if (n > 0) {
      acc[0] = 0;
      for (int k=0; k<=K; k++) {
        acc[k+1] = acc[k] + dp[n-1][k];
      }
    }

    for (int k=0; k<=K; k++) {
      if (k == 0) { dp[n][k] = 1; continue; }
      if (n == 0) { dp[n][k] = A[n] >= k; continue; }
      dp[n][k] = (dp[n][k] + acc[k+1] - acc[max(k-A[n], 0)]) % MOD;
    }
  }
  return dp[N-1][K];
}

void solve() {
  memset(dp, 0, sizeof(dp));
  // cout << rec(0, K) << endl;
  cout << give() << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 87040
from itertools import combinations

n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for a, b in combinations(X, 2):
    dist = 0
    for i in range(d):
        dist += (a[i] - b[i]) ** 2
    if dist ** 0.5 % 1 == 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main() {
  int S;
  cin >> S;
  int h = S / 60 / 60;
  int m = (S - h * 3600) / 60;
  int s = S - h * 3600 - m * 60;
  cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define LL long long 

const int maxn=1e5+10;

int A,X,Y,n;
LL Ans,Sum,L[maxn],R[maxn];

struct Point{
	int a,x,y;
	bool operator < (const Point &p) const {return x>p.x;}
}P[maxn];

priority_queue<int> q;

int main()
{
#ifdef h10
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
	int i;
	scanf("%d%d%d",&A,&X,&Y);
	n=A+X+Y;
	for (i=1;i<=n;i++)
	{
		scanf("%d%d%d",&P[i].a,&P[i].x,&P[i].y);
		P[i].x-=P[i].a;
		P[i].y-=P[i].a;
	}
	sort(P+1,P+n+1);

	for (i=1;i<=X+Y;i++)
	{
		Sum+=P[i].x;
		q.push(P[i].y-P[i].x);
		if (i>X) Sum+=q.top(),q.pop();
		L[i]=Sum;
	}
	Sum=0;
	while (!q.empty()) q.pop();
	for (i=n;i>X;i--)
	{
		q.push(P[i].y);
		if (X+Y-i+1>0) Sum+=q.top(),q.pop();
		R[i]=Sum;
	}
	Sum=0;
	for (i=1;i<=n;i++) Sum+=P[i].a;
	for (i=X;i<=X+Y;i++)
		Ans=max(Ans,Sum+L[i]+R[i+1]);
	printf("%lld\n",Ans);
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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 (b<a) { a=b; return 1; } return 0; }

int main() {
	int n;
	cin >> n;
	int temp1 = n / 15;
	int temp2 = n / 5;
	int temp3 = n / 3;
	ll ans = 0;

	for(int i=1; i<=n; i++) {
		if(i % 3 == 0) continue;
		if(i%5 == 0)continue;
		if(i%15==0) continue;
		ans += i;
	}

	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int i,j;
		int a[101];
		map<int,int> m;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			m[a[i]]=1;
		}
		sort(a,a+n);
		int ans=100000000;
		for(i=a[0];i<=a[n-1];i++)
		{
			int t=0;
			for(j=0;j<n;j++)
			{
				t+=(a[j]-i)*(a[j]-i);
			}
			ans=min(ans,t);
		}
		printf("%d\n",ans);
		
	}
}

Measured memory_bytes: 256
/*
* @author:  codancer
* @createTime:  2020-02-16, 20:05:58
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
int main(){
	int n;
	cin>>n;
	vector<string> a(n+1);
	map<string,int> mmp;
	int maxx=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mmp[a[i]]++;
		maxx=max(maxx,mmp[a[i]]);
	}
	set<string> all;
	for(auto v:mmp){
		if(mmp[v.first]==maxx) all.insert(v.first);
	}
	for(string v:all) cout<<v<<endl;
	return 0;
}

Measured memory_bytes: 37888
N = int(input())
W = [int(w) for w in input().split()]

S = sum(W)

A = W.copy()
D = W.copy()
D[0] = S

for n in range(1,N):
  A[n] = A[n] + A[n-1]
  D[n] = abs(S-2*A[n])
  
print(min(D))



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





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

	int zero = 0;
	int one = 0;
	int total = 0;

	for (char c : s) {
		if (c == '0') {
			if (one > 0) {
				one --;
				total += 2;
			} else {
				zero++;
			}
		} else {
			if (zero > 0) {
				zero--;
				total += 2;
			} else {
				one++;
			}
		}
	}

	cout << total << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_NM=2e5,MOD=1e9+7;
ll N,M,K,fact[MAX_NM+1],ifact[MAX_NM+1];
ll f(ll x){
	return (x*(x+1)*(2*x+1)/6-x*(x+1)/2*(2*x+1)+x*x*(x+1))%MOD;
}
ll mpw(ll n,ll m){
	ll ret=1;
	while(m){
		if(m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
ll comb(ll n,ll m){
	return fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M>>K;
	fact[0]=1;
	REP(i,N*M){
		fact[i+1]=fact[i]*(i+1)%MOD;
	}
	ifact[N*M]=minv(fact[N*M]);
	for(ll i=N*M-1;i>=0;i--){
		ifact[i]=ifact[i+1]*(i+1)%MOD;
	}
	cout<<comb(N*M-2,K-2)*((M*M%MOD*f(N)%MOD+N*N%MOD*f(M)%MOD)%MOD)%MOD*minv(2)%MOD<<endl;
}

Measured memory_bytes: 3328
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll cnt = 0;
    map<ll,ll> mp;
    REP(i,n){
        ll t = i+1-a[i];
        cnt += (ll)(mp[t]);
        mp[i+1+a[i]]++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 27444
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  string sa,sb,sc;cin>>sa>>sb>>sc;
  ll a=-1,b=-1,c=-1;
  char cha='a';
  rep(i,400){
    if(cha=='a'){
      a++;
      if(a==sa.size()){
        cout<<"A"<<endl;
        return 0;
      }
      cha=sa[a];
    }
    if(cha=='b'){
      b++;
      if(b==sb.size()){
        cout<<"B"<<endl;
        return 0;
      }
      cha=sb[b];
    }
    if(cha=='c'){
      c++;
      if(c==sc.size()){
        cout<<"C"<<endl;
        return 0;
      }
      cha=sc[c];
    }
  }
}

    

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
//---------------------------------------
string henkan(string inp);   //?°?????????¨??§???????????\?????????
//---------------------------------------

int main(void)
{
	string inp1;
	
	getline(cin, inp1);  //???????????????????????????????????????
	
	cout << henkan(inp1) << endl;

	
	return 0;
}

//------------------------------------------
string henkan(string inp)
{	
	int len = inp.size(); //= inp.length();
	
	for(int i = 0; i < len; i++){
		if(inp[i] >= 'A' && inp[i] <= 'Z'){
			inp[i] += 32;
		}
		else if(inp[i] >= 'a' && inp[i] <= 'z'){
			inp[i] -= 32;
		}
	}
	return inp;
}

Measured memory_bytes: 3188
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	var N int
	N = nextInt()

	w := make([]byte, 0, N)
	w = append(w, 'a')
	word('a', N, w)

}

func word(m byte, n int, s []byte) {
	if len(s) == n {
		fmt.Println(string(s))
		return
	}
	for i := byte('a'); i <= m; i++ {
		word(m, n, append(s, i))
	}
	m++
	word(m, n, append(s, m))
}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInt64() int64 {
	stdin.Scan()
	i, err := strconv.ParseInt(stdin.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextStr() string {
	stdin.Scan()
	i := stdin.Text()
	// if err != nil {
	// 	panic(err)
	// }
	return i
}


Measured memory_bytes: 5632
import sys
A,B,C,X,Y = map(int,input().split())
ans = 0
if A+B > 2*C:
    judge = True
else:
    ans += X*A
    ans += Y*B
    print(ans)
    sys.exit()

    # judge = False

if judge:
    min_XY = min(X,Y)
    if min_XY == 0:
        ans += X*A
        ans += Y*B
        print(ans)
        sys.exit()
    else:
        X -= min_XY
        Y -= min_XY
        ans += 2*C*min_XY
        if X !=0:
            if 2*C*X < A*X:
                ans +=  2*C*X
            else:
                ans += A*X
        if Y !=0:
            if 2*C*Y < B*Y:
                ans +=  2*C*Y
            else:
                ans += B*Y
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <typeinfo>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int x = stoi(s+t);
  for (int i = 1; i <= 10000; i++) {
    if (i * i == x) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    quantity, A, B = map(int, input().split())
    l = list(input())
    yes = 0
    abroad = 0

    for i in range(quantity):
        if l[i] == 'a':
            if yes < (A + B):
                print('Yes')
                yes = yes + 1
            else:
                print('No')
        
        if l[i] == 'b':
            abroad = abroad + 1
            if yes < (A + B) and abroad <= B:
                print('Yes')
                yes = yes + 1

            else:
                print('No')
        
        if l[i] == 'c':
            print('No')

main()

Measured memory_bytes: 9928
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const int N_MAX = 1e5 + 1;

int A, B, Q;

int main() {
    cin >> A >> B >> Q;
    vector< ll > s(A), t(B), x(Q);
    for (int i = 0; i < A; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < Q; i++) {
        ll x;
        cin >> x;

        ll ans;
        auto itr = lower_bound(s.begin(), s.end(), x);
        auto s1 = itr;
        itr = lower_bound(t.begin(), t.end(), *s1);
        auto t1 = itr;
        ans = abs(x - *s1) + abs(*s1 - *t1);
        if (t1 != t.begin()) {
            auto t2 = --itr;
            ans = min(ans, abs(x - *s1) + abs(*s1 - *t2));
        }

        if (s1 != s.begin()) {
            auto s2 = --s1;
            itr = lower_bound(t.begin(), t.end(), *s2);
            t1 = itr;
            ans = min(ans, abs(x - *s2) + abs(*s2 - *t1));
            if (t1 != t.begin()) {
                auto t2 = --t1;
                ans = min(ans, abs(x - *s2) + abs(*s2 - *t2));
            }
        }

        itr = lower_bound(t.begin(), t.end(), x);
        t1 = itr;
        itr = lower_bound(s.begin(), s.end(), *t1);
        s1 = itr;
        ans = min(ans, abs(x - *t1) + abs(*t1 - *s1));
        if (s1 != s.begin()) {
            auto s2 = --s1;
            ans = min(ans, abs(x - *t1) + abs(*t1 - *s2));
        }

        if (t1 != t.begin()) {
            auto t2 = --t1;
            itr = lower_bound(s.begin(), s.end(), *t2);
            s1 = itr;
            ans = min(ans, abs(x - *t2) + abs(*t2 - *s1));
            if (s1 != s.begin()) {
                auto s2 = --s1;
                ans = min(ans, abs(x - *t2) + abs(*t2 - *s2));
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    for(auto&& i : a){
        cin >> i;
    }
    for(auto&& i : b){
        cin >> i;
    }
    for(auto&& i : c){
        cin >> i;
    }
    int ans = accumulate(begin(b), end(b), 0);
    for(int i = 0; i < n - 1; i++){
        if(a[i + 1] - a[i] == 1){
            ans += c[a[i] - 1];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int c1,c5,c10,c50,c100,c500;
	int sum;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	sum = c1 * 1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;
	if(sum >= 1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 584
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ans = 0;
        for (int i = 1; i <= n; i++)
        {
            if (NumberOfDigits(i) % 2 != 0) 
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }

    static int NumberOfDigits(int n)
    {
        int cnt = 1;
        while ((n /= 10) != 0)
        {
            cnt++;
        }
        return cnt;
    }
}

Measured memory_bytes: 13140
N,L=map(int,input().split())
list_apple=[] # 0 index is i1
eat_taste=300 
for i in range(N):
    taste=L+i-1+1
    list_apple.append(taste)
    #print(abs(taste))
    if abs(eat_taste)>=abs(taste):
        eat_taste=taste
    
print("{}".format(sum(list_apple)-eat_taste))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#include<math.h>
int main()
{
    double a,b,c;
    cin>>a;
    long long int d,e,f=0,i,ans=0;
    e=a;
    for(i=1;i<=50000;i++)
    {
        b=i*1.08;
        d=b;
        if(d==e){f=1;ans=i;break;}
    }
    if(f==1)printf("%lld\n",i);
    else printf(":(\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const ll INF = 100100100100;
const int MOD = 1000000007;


int H, W;
vector<string> field;
vector<vector<int>> dist;
queue<P> que;

// 4 direction-vectors
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  cin >> H >> W;
  field.resize(H);
  for(int h = 0; h < H; ++h) cin >> field[h];

  int ans = -1;
  rep(h, H) rep(w, W){
    if (field[h][w] == '#') continue;
    
    dist = vector<vector<int>>(H, vector<int>(W, -1));
    dist[h][w] = 0;
    queue<P>().swap(que);
    que.push(P(h, w));

    // BFS
    while (!que.empty()) {
      P v = que.front();
      que.pop();
      int h, w; tie(h, w) = v;

      // check 4 directions
      rep(dir, 4){
        int nh = h + dx[dir];
        int nw = w + dy[dir];

        // skip if outside the field or on a wall
        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (field[nh][nw] == '#') continue;

        if (dist[nh][nw] != -1) continue;
        dist[nh][nw] = dist[h][w] + 1;
        que.push(P(nh, nw));
      }
    }

    rep(i, H) rep(j, W) if(dist[i][j] > ans) ans = dist[i][j];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

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

const int mod=1000000007;
const int N=200010;

int w[N],c[N],color[N],st[N],fac[N],inv[N],cnt[N];
vi e[N],g[N];
int top;
bool v[N];

int power(int x,int y)
{
	int t=1;
	while (y)
	{
		if (y&1) t=ll(t)*x%mod;
		y>>=1;x=ll(x)*x%mod;
	}
	return t;
}

void dfs(int k)
{
	if (!cnt[c[k]]) {st[++top]=c[k];cnt[c[k]]=1;} else cnt[c[k]]++;
	color[k]=1;
	for (vi::iterator p=e[k].begin();p!=e[k].end();p++)
		if (!color[*p])
		{
			color[*p]=color[k]^1;
			dfs(*p);
		}
}

int main()
{
	int n,x,y;scanf("%d%d%d",&n,&x,&y);
	for (int i=1;i<=n;i++) scanf("%d%d",&c[i],&w[i]);w[0]=mod;
	for (int i=1;i<=n;i++) g[c[i]].pb(i);
	int mi1=1;
	for (int i=2;i<=n;i++) if (w[i]<w[mi1]) mi1=i;
	int mi2=0;
	for (int i=1;i<=n;i++) if (c[i]!=c[mi1]&&w[i]<w[mi2]) mi2=i;
	for (int i=1;i<=n;i++)
	{
		if (c[mi1]!=c[i]&&w[i]+w[mi1]<=y) {e[mi1].pb(i);e[i].pb(mi1);}
		if (mi2&&c[mi2]!=c[i]&&w[i]+w[mi2]<=y) {e[mi2].pb(i);e[i].pb(mi2);}
	}
	for (int i=1;i<=n;i++)
	{
		int mi=0;
		for (vi::iterator p=g[i].begin();p!=g[i].end();p++)
			if (w[*p]<w[mi]) mi=*p;
		for (vi::iterator p=g[i].begin();p!=g[i].end();p++)
			if (mi!=(*p)&&w[mi]+w[*p]<=x) {e[mi].pb(*p);e[*p].pb(mi);}
	}
	fac[0]=1;for (int i=1;i<=n;i++) fac[i]=ll(fac[i-1])*i%mod;
	inv[n]=power(fac[n],mod-2);for (int i=n;i;i--) inv[i-1]=ll(inv[i])*i%mod;
	int ans=1;
	for (int i=1;i<=n;i++) color[i]=cnt[i]=0;
	for (int i=1;i<=n;i++)
		if (!color[i])
		{
            top=0;
			dfs(i);
			int s=0;for (int j=1;j<=top;j++) s+=cnt[st[j]];
			ans=ll(ans)*fac[s]%mod;
			for (int j=1;j<=top;j++) ans=ll(ans)*inv[cnt[st[j]]]%mod;
			for (int j=1;j<=top;j++) cnt[st[j]]=0;
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 25960
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
bool check(string s){
//	cout<<s<<endl;
	int l=s.length();
	rep(i,l){
		if(s[i]==s[l-1-i]){
			
		}
		else return 0;
	}
	return 1;
}
int main(){
	fastio;
	string s;
	cin>>s;
	int n=s.length();
	int ok=1;
	
	rep(i,n/2){
		if(s[i]==s[n-1-i]){
			
		}
		else{
			ok=0;
		}
	}
	string ss="";
	rep(i,(n-1)/2){
		ss+=s[i];
	}
	if(!check(ss)){
		ok=0;
	}
	ss="";
	rb(i,(n+3)/2-1,n-1){
		ss+=s[i];
	}if(!check(ss)){
		ok=0;
	}
	if(ok){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    int a,b;
    cin>>a>>b;
    if(a==b)
    {
        cout<<0;
    }
    else if(a==0)
    {
        if(b>0)
        {
            cout<<b<<endl;
        } else{
            cout<<abs(b)+1<<endl;
        }
    }
    else if(b==0)
    {
        if(a>0)
        {
            cout<<abs(a)+1<<endl;
        }
        else{
            cout<<abs(a)<<endl;
        }
    }
    else if(a>0 && b>0)
    {
        if(a>b)
        {
             cout<<(a-b)+2<<endl;
        }
        else
        {
            cout<<b-a<<endl;
        }
    }
    else if(a>0 && b<0)
    {
        cout<<abs(a+b)+1;
    }
    else if(a<0 && b>0)
    {
        cout<<(abs(a+b)+1)<<endl;
    }
    else
    {
        if(a>b)
        {
                cout<<(abs(a-b)+2)<<endl;
        }
        else
        {
                cout<<abs(b-a)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstring>
#include <climits>
#include <algorithm>
const int MAX_N = 400;

long long f[MAX_N + 1][MAX_N + 1];
int a[MAX_N + 1];

long long dp(int l, int r) {
  if (l == r) return 0;
  auto &ret = f[l][r];
  if (ret != -4485090715960753727ll) return ret;
  ret = LLONG_MAX;
  for (int i = l; i < r; ++i) ret = std::min(ret, dp(l, i) + dp(i + 1, r));
  for (int i = l; i <= r; ++i) ret += a[i];
  return ret;
}

int main() {
  memset(f, -0x3f, sizeof(f));
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  std::cout << dp(1, n);
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
    int a, b;
	cin >> a >> b;
  	if(a%2 && b%2) puts("Yes");
  	else puts("No");
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

Measured memory_bytes: 1588
#include<bits/stdc++.h>
#define SF scanf
#define PF printf
#define MAXN 60
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll dp[MAXN][MAXN],c[MAXN][MAXN]; 
int n;
int main(){
    SF("%d",&n);
    for(int i=0;i<=n;i++) for(int j=0;j<=i;j++){ if(j==0) c[i][j]=1; else c[i][j]=(c[i-1][j-1]+c[i-1][j])%MOD; }
    dp[1][n]=1; dp[1][n-1]=1;
    for(int i=1;i<n;i++)
        for(int j=-i;j<=i;j++){
            for(int sum=max(1,abs(j));sum<=n;sum++){
                if(i+sum>n||(sum+j)%2) continue;
                for(int pos=0;pos<=sum;pos++){
                    int t=sum-pos; int val=(j+pos-t)/2;
                    if(val<-n||val>n) continue;
                    dp[i+sum][val+n]+=dp[i][j+n]*c[i+sum][sum]%MOD*c[sum][pos]%MOD; dp[i+sum][val+n]%=MOD;
                }
            }
        }
    PF("%lld\n",dp[n][n]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}


main() {
   int N; string S;
   cin >> N >> S;
   int R[N],L[N];
   int a=0,b=0;
   rep(i,N-1){
      if(S[i]=='W') a++;
      L[i]=a;
   }
   for(int i=N;i>=1;i--){
      if(S[i]=='E') b++;
      R[i]=b;
   }
   int ans=999999999;
   rep(i,N){
      int pos;
      if(i==0) pos=R[1];
      else if(i==N) pos=L[N-1];
      else pos=R[i+1]+L[i-1];
      ans=min(ans,pos); 
   }
   cout << ans << endl;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()

ll tree[800008];

void update(ll node, ll start, ll end, ll idx, ll val)
{
    if(start == end)
        tree[node] = val;
    else
    {
        ll mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
            update(2*node, start, mid, idx, val);
        else
            update(2*node+1, mid+1, end, idx, val);
        tree[node] = max(tree[2*node],tree[2*node+1]);
    }
}

ll query(ll l, ll r, ll start, ll end, ll node)
{
	if(r<start || l>end)
		return 0;
	if(l<=start && r>=end)
		return tree[node];
	ll mid = (start+end)/2;
	return max(query(l,r,start,mid,2*node),query(l,r,mid+1,end,2*node+1));
}

int main()
{
	fast;
	ll n,x,y,ans=0;
	cin >> n;
	ll h[n];
	input(h,n);
	fr(i,0,n)
	{
		cin >> x;
		if(h[i]==1)
			y=x;
		else
			y=query(1,h[i]-1,1,200002,1)+x;
		ans=max(ans,y);
		update(1,1,200002,h[i],y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 7936
/*
 * atcoder/abc111_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

struct Rank {
  int num, count;
};

const int MAX = 100001;
int N;
int counter[2][MAX];
// 偶奇, 0 = 1位, 1 = 2位
Rank ranks[2][2] = {0};

void solve() {
  cin >> N;
  int v;
  loop(n,0,N) {
    cin >> v;
    counter[n%2][v]++;
  }

  loop(v,1,MAX) {
    loop(n,0,2) {
      Rank& r1 = ranks[n][0];
      Rank& r2 = ranks[n][1];
      int count = counter[n][v];
      if (r1.count < count) {
        r2 = r1;
        r1 = (Rank){ v, count };
      } else if (r2.count < count) {
        r2 = (Rank){ v, count };
      }
    }
  }
  if (ranks[0][0].num != ranks[1][0].num) {
    cout << N - ranks[0][0].count - ranks[1][0].count << endl;
  } else {
    cout << min(N - ranks[0][0].count - ranks[1][1].count, N - ranks[0][1].count - ranks[1][0].count) << endl;
  }
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


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

int main(){
	string s,t;cin>>s>>t;
	int Min=INT_MAX;
	rep(i,s.size()-t.size()+1){
		int cnt=0;
		rep(j,t.size()){
			cnt+=(s[i+j]!=t[j]);
		}
		Min=min(Min,cnt);
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <map>

std::map<int, int> front, back; //前二つの和と後二つの和がそれぞれ何通りあるか

void makeSet(){
	//半分全列挙
	for(int i=0;i<=1000;++i){
		for(int j=0;j<=1000;++j){
			int k=i+j;
			if(front.find(k)==front.end()) front.insert(std::pair<int, int>(k, 1)); else ++front[k];
			if(back.find(k)==back.end()) back.insert(std::pair<int, int>(k, 1)); else ++back[k];
		}
	}
}

int solve(int n){
	int num=0;
	for(std::map<int, int>::iterator i=front.begin(); i!=front.end();++i){
		std::map<int, int>::iterator j=back.find(n-i->first);
		if(j!=back.end()) num+=i->second*j->second;
	}
	return num;
}

int main(){
	makeSet();

	while(true){
		int n;
		std::cin>>n;
		if(std::cin.eof()) break;
		
		std::cout<<solve(n)<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1380
/* # */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
void sol() {
    int n, m; cin >> n >> m;
    vi A(n);
    int total(0), cnt(0);
    int cri = 4 * m;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        total += A[i];
    }
    for (int i = 0; i < n; i++) {
        if (A[i] * 4 * m >= total)
            cnt++;
    }
    if (m <= cnt)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    sol();


    return 0;
}

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

int cnt;
int n;

int partition(int A[], int p, int r)
{
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++)
    {
        if (A[j] <= x)
        {
            i = i + 1;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

int main()
{
    scanf("%d", &n);
    int A[MAX];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }

    int q = partition(A, 0, n - 1);
    for (int i = 0; i < n; i++)
    {
        if (i == q)
        {
            cout << "[" << A[q] << "]";
        }
        else
        {
            cout << A[i];
        }
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3536
#include <stdio.h>
#define MOD 1000000007

int dp[1010][1010];
//dp[n][k]=nをk個以下の整数の和で表す場合の数
//        =nをk以下の整数の和で表す場合の数
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int j=0;j<=m;j++)dp[0][j]=1;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dp[i][j]=(dp[i][j-1]+(i-j>=0?dp[i-j][j]:0))%MOD;
	printf("%d\n",(dp[n][m]-dp[n][m-1]+MOD)%MOD);
}


Measured memory_bytes: 5748
#include <iostream>
#include<math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
	long long N, K;
	cin >> N >> K;

	if (N > K) {
		N = N % K;
	}

	if (N > abs(N - K))N = abs(N - K);
	cout << N << endl;
return 0;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  long x,y,count=1,count2=0;
  cin>>x>>y;
  count2+=x;
  while(count2<=y){
    count2=count2*2;
    if(count2<=y)
    count++;
  }
  cout<<count;
  return 0;
}


Measured memory_bytes: 256
s=input()
i=len(s)

while True:
    if i==0:
        print('YES')
        break
    if 6<i and s[i-7:i] == 'dreamer':
        i-=7
        continue
    if 5<i and s[i-6:i] == 'eraser':
        i-=6
        continue
    if 4<i and s[i-5:i] in ['dream','erase']:
        i-=5
        continue
    print('NO')
    break


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

int prime(int j) {
    if (j == 2) return 1;
    if (j % 2 == 0) return 0;
    for (int i = 3; i <= j / i; i += 2) {
        if (j % i == 0) return 0;
    }
    return 1;
}

int main() {

    int n;
    cin >> n;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int j;
        cin >> j;
        if (prime(j)) ++ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1160
use std::io::Read;
use std::collections::VecDeque;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();

    let mut map: Vec<Vec<usize>> = vec![vec![0; w]; h];
    for y in 0..h {
        for x in 0..w {
            let ai: usize = iterator.next().unwrap().parse().unwrap();
            map[y][x] = ai;
        }
    }

    let mut route = VecDeque::new();
    for y in 0..h {
        if y % 2 == 0 {
            for x in 0..w {
                route.push_back((y, x));
            }
        } else {
            for x in (0..w).rev() {
                route.push_back((y, x));
            }
        }
    }

    let mut logs = Vec::new();
    let mut current = route.pop_front().unwrap();
    while !route.is_empty() {
        let next = route.pop_front().unwrap();
        if map[current.0][current.1] % 2 == 1 {
            logs.push((current.0, current.1, next.0, next.1));
            map[current.0][current.1] -= 1;
            map[next.0][next.1] += 1;
        }
        current = next;
    }

    let mut result = String::new();
    result.push_str(&format!("{}\n", logs.len()));
    for log in logs {
        result.push_str(&format!("{} {} {} {}\n", log.0 + 1, log.1 + 1, log.2 + 1, log.3 + 1));
    }
    result.trim().to_string()
}


Measured memory_bytes: 14260
#include <bits/stdc++.h>
using namespace std;
#define int long long
//ask the right questions.		

int32_t main() 
{
	int N, W;
	cin >> N >>W;
	int weights[N];
	int value[N];

	int x;
	for(int i=0;i<2*N;i++)
	{
		cin >> x;
		if(i%2==0)
		{
			weights[i/2]=x;
		}
		else
		{
			value[(i-1)/2]=x;
		}
	}

	//let denote the max value when you have capacity_left of w and deciding upon nth item.
	int dp[W+1][N+1];

	//trivial case:
	for(int i=0; i<=W; i++)
	{
		dp[i][0]=0;
	}

	//base case
	for(int i=0; i<=N; i++)
	{
		dp[0][i]=0;
	}

	//TIP:
	//you are dciding on the nth item 
	//if you have seen a state which has not seen the nth item before
	//and capacity_left in that state is more than the W[n] then you can include 
	//this item in that state. Take maximum of all such states.  


	// shift j-1 in weights and values
	for(int i=1; i<=W; i++)
	{
		for(int j=1; j<=N; j++)
		{
			//want to take
			int a = 0;
			if(i>=weights[j-1])
			{
				a = dp[ i-weights[j-1] ][j-1] + value[j-1];			
			}
			//dont want to:
			dp[i][j] = max(a, dp[i][j-1]);
		}		
	}

	cout << dp[W][N] <<endl;

	return 0;
	
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

struct query { int a, b, c, d; };

int N, M, ans = -1;

vector<query> queries;

void dfs(vector<int> v){
    if(v.size() != N){
        int s = v.back();
        v.push_back(-1);
        reps(i,s,M){
            v.back() = i;
            dfs(v);
        }
    }else{
        int score = 0;
        for(auto q : queries){
            if(v[q.b]-v[q.a] == q.c) score += q.d;
        }
        ans = max(ans, score);
    }
}

signed main(){
    int Q;
    cin >> N >> M >> Q;
    while(Q--){
        query q;
        cin >> q.a >> q.b >> q.c >> q.d;
        q.a--; q.b--;
        queries.push_back(q);
    }
    vector<int> v(1,1);
    reps(i,1,M){
        v.back() = i;
        dfs(v);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define first fst
#define second scd

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int a[3][3];
  int w[3],h[3];
  rep(i,3){
    rep(j,3) cin>>a[i][j];
  }
  w[0]=0;
  w[1]=a[0][1]-a[0][0];
  w[2]=a[0][2]-a[0][0];
  h[0]=a[0][0];
  h[1]=a[1][0];
  h[2]=a[2][0];
  rep(i,3){
    rep(j,3){
      if(a[i][j]!=w[j]+h[i]){cout<<"No"<<endl;return 0;}
    }
  }
  cout<<"Yes"<<endl;
  

  return 0;
}











Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N;
    scanf("%d", &N);
    if(N%10==7){
        printf("Yes\n");return 0;
    }
    N/=10;
    if(N%10==7){
        printf("Yes\n");return 0;
    }
    N/=10;
    if(N%10==7){
        printf("Yes\n");return 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1664
def partition(li, m, length):
    ini_i = 0
    target = li[length - 1]
    for i, n in enumerate(li[:length - 1]):
        if n <= target:
            li[ini_i], li[i] = li[i], li[ini_i]
            ini_i += 1
    li[ini_i], li[-1] = [li[-1]], li[ini_i]
    print(*li)
length = int(input())
li = [int(n) for n in input().split(" ")]
partition(li, 0, len(li))


Measured memory_bytes: 16364
#include<stdio.h>
int main()
{
    char a,b;
    scanf("%c %c",&a,&b);
    if(a>b)
    {
        printf(">\n");
        //printf("%d > %d.\n",a-55,b-55);
    }
    else if(a<b)
    {
        printf("<\n");
        //printf("%d < %d.\n",a-55,b-55);
    }
    else
    {
        printf("=\n");
        //printf("%d = %d.\n",a-55,b-55);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
vector<int> graph[N];
int label[N];
void dfs(int v, int c){
    label[v] = c;
    for(auto x: graph[v]){
        if(label[x] != -1)
        continue;
        else
        {
            dfs(x, c);
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n, m, k;
    cin>>n>>m>>k;
    for(int i = 0; i < m; i++){
        int x, y;
        cin>>x>>y;
        x--; y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    memset(label, -1, sizeof(label));
    int count = 0;
    for(int i = 0; i < n; i++){
        if(label[i] != -1)  continue;
        dfs(i, count);
        count++;
    }
    vector<int> labelCount(N, 0);
    for(int i = 0; i < n; i++){
        // cout<<"i = "<<i<<" label[i] = "<<label[i]<<endl;
        labelCount[label[i]]++;
    }
    int ans[N];
    for (int i = 0; i < n; i++)
    {
        ans[i] = labelCount[label[i]] - graph[i].size() - 1;
    }
    for(int i = 0; i < k; i++){
        int x, y;
        cin>>x>>y;
        x--; y--;
        if(label[x] == label[y]){
            ans[x]--; ans[y]--;
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 10860
from itertools import repeat

import random

def bitcount(x):
	result = 0
	while x > 0:
		if x % 2 == 1: 
			result += 1

		x //= 2
	return result

ff = {}

def f(x):
	count = 0
	while x != 0:
		count += 1
		#print(x, bitcount(x))
		x = x % bitcount(x)	
	return count

def brute(s):
	chars = [char for char in s]

	result = []

	def flip(i):
		if chars[i] == '1':
			chars[i] = '0'
		else:
			chars[i] = '1'

	for i in range(len(s)):
		flip(i)
		x = int("".join(chars), 2)
		result.append(f(x))
		flip(i)

	return result

def solve(n, s):
	bc = s.count('1')

	x = 0
	pow = 1
	for bit in reversed(range(n)):
		if s[bit] == '1':
			x += pow
		pow *= 2


	mods1 = []
	mod1, mod2 = bc + 1, bc - 1
	mods2 = []

	#print(mod1, mod2)

	pow = 1
	mods1.append(pow % mod1)

	if mod2 != 0:
		mods2.append(pow % mod2)

	for bit in range(1, n):
		if mod1 != 0:
			mods1.append(2 * mods1[bit - 1] % mod1)
		if mod2 != 0:
			mods2.append(2 * mods2[bit - 1] % mod2)

	mods1 = list(reversed(mods1))
	mods2 = list(reversed(mods2))

	#print(mods1)
	#print(mods2)

	x_mod_1 = 0
	x_mod_2 = 0
	for bit in reversed(range(n)):
		if s[bit] == '1':		
			x_mod_1 = (x_mod_1 + mods1[bit]) % mod1
			if mod2 != 0:
				x_mod_2 = (x_mod_2 + mods2[bit]) % mod2

	#print(x_mod_1, x_mod_2)

	result = []

	for bit in reversed(range(n)):
		if s[bit] == '0':
			new_mod = (x_mod_1 + mods1[bit]) % mod1
			result.append(1 + f(new_mod))

		else:
			if mod2 == 0:
				result.append(0)
			else:				
				new_mod = (x_mod_2 - mods2[bit]) % mod2
				#print('new mod', new_mod)
				result.append(1 + f(new_mod))

	return list(reversed(result))


#n = 200000
n = int(input())
s = input()
#s = "".join(list(repeat('1', n)))

sol = solve(n, s)
for x in sol:
	print(x)

#print(brute(s))

Measured memory_bytes: 117888
#include <stdio.h>

int main(void)
{
	int n,x,i,j,k,a;
	while(1)
	{
		a=0;
		scanf("%d%d",&n,&x);
		if(n==0 && x == 0)
		{
			break;
		}
		for(i=1;i<=n-2;i++)
		{
			for(j=i+1;j<n;j++)
			{
				for(k=j+1;k<=n;k++)
				{
					if(i+j+k==x)
					{
						a=a+1;
					}
				}
			}
		}
		printf("%d\n",a);
	}
	return 0;
		
}

Measured memory_bytes: 600
S = input()
mod = 10 ** 9 + 7

ans_old = [0] * 13
ans_old[0] = 1
for s in S:
    ans = [0] * 13
    if s == "?":
        for i in range(10):
            for j in range(13):
                ans[(j*10 + i)%13] = (ans[(j*10 + i)%13] + ans_old[j]) % mod 
    else:
        i = int(s)
        for j in range(13):
            ans[(j*10 + i)%13] = (ans[(j*10 + i)%13] + ans_old[j]) % mod 
    ans_old = ans

print(ans[5])

Measured memory_bytes: 42988
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        String S = sc.next();
      	Boolean ans1 = false;
		Boolean ans2 = false;
		
        if(S.charAt(A) == '-'){
            ans1 = true;
        }
        
        
      for (int i =0; i<A+B+1; i++){
          if(i != A){
            if(S.charAt(i)>='0' && S.charAt(i)<='9'){
            	ans2 = true;
          }
            else{
                ans2 = false;
                break;
            }
          } 
       }
      	
      if(ans1 == true && ans2 == true){
      System.out.println("Yes");
      }
      else{
       System.out.println("No");
      }
   }  	
}

Measured memory_bytes: 21844
fn a_discount_fare() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let read_values : Vec<i32> =
        input.trim_right()
        .split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .collect();
    let x = read_values[0];
    let y = read_values[1];

    println!("{}", x + y / 2);
}

fn main() {
    a_discount_fare();
}


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



int main(){
    ll N; cin >> N;
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll l, r; cin >> l >> r; ans += r-l+1;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
long long dp[21];
int main(void){
    dp[0] = 1;
    for(int i=1; i<21; ++i) dp[i] = i*dp[i-1];
    int n;
    cin >> n;
    cout << dp[n] << endl;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

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

    if(d==0){
        if(n==100){
            cout<<101<<endl;
        }else{
            cout<<n<<endl;
        }
    }else if(d==1){
        if(n==100){
            cout<<10100<<endl;
        }else{
            cout<<n*100<<endl;
        }
    }else{
        if(n==100){
            cout<<1010000<<endl;
        }else{
            cout<<n*10000<<endl;
        }
    }
}

Measured memory_bytes: 256
import itertools
def getAscore(A, Qlist):
    score = 0
    for l in Qlist:
        try:
            if A[l[1]-1]-A[l[0]-1] == l[2]:
                score += l[3]
        except:
            pass
    return score

NMQ = list(map(int,input().split()))
N = NMQ[0]
M = NMQ[1]
Q = NMQ[2]
Qlist = []
for n in range(Q):
    Qlist.append([int(i) for i in input().split()])
allA = list(itertools.combinations_with_replacement(range(1,M+1), N))
max = 0
for A in allA:
    score = getAscore(A, Qlist)
    if score > max:
        max = score
print(max)

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

int main() {
	int N;
	cin >> N;
	
	vector<int> d;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		d.push_back(n);
	}

	int total = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i+1; j < N; j++) {
			//cout << "たこ" << i + 1 << "、たこ" << j + 1 << endl;
			total = total + d[i] * d[j];
		}
	}

	cout << total << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int 
#define fori(i,n) for(i=0; i<n; i++)
#define ford(i,n) for(i=n-1; i>=0; i--)
#define vi vector<int> 
#define vs vector<string>
#define vll vector<ll>
#define di deque<int>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mod1 1000000007
#define mod2 998244353
#define pb push_back
#define fi first
#define se second
#define PI 3.14159265
#define fast_cin() ios::sync_with_stdio(false); cin.tie(nullptr)

using namespace std;


int main(int argc, char const *argv[]){
    fast_cin();
	double a, b, vol, l ,x;
	cin>>a>>b>>x;
	vol = a*a*b/2;
	if(x==vol) cout<<"45.0000000000\n";
	else if(x>vol) cout<< setprecision(9) << atan(2*b/a - 2*x/(a*a*a))*180/PI << "\n";
	else cout<< setprecision(9) << atan((((a*a*b-2*x)/(2*x))+1)*b/a)*180/PI<<"\n";
    return 0;
}



Measured memory_bytes: 256