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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
ll color[100001];
vector<pair<ll,ll> > v[100001];
void dfs(ll cur,ll par,ll dis)
{
    if(dis%2==0)
    color[cur]=0;
    else
    color[cur]=1;
    for(auto x : v[cur])
    {
        if(par!=x.first)
        {
            dfs(x.first,cur,dis+x.second);
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        v[x].pb(mp(y,z));
        v[y].pb(mp(x,z));
    }
    dfs(1,-1,0);
    for(i=1;i<=n;i++)
    cout<<color[i]<<endl;
    return 0;
}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#define re register
using namespace std;
#define gc getchar
#define int long long
inline int read(){
	int t=0,f=0;
	char v=gc();
	while(v<'0')f|=(v=='-'),v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=gc();
	return f?-t:t;
}
int n,a[200002],b[200002],ans,m,v[1000002],cnt,mx;
signed main(){
	n=read();m=read();
	for(re int i=1;i<=n;++i)mx=max(mx,a[i]=read());
	re int l=1,r=mx;
	while(l<=r){
		re int mid=l+r>>1,num=0;
		for(re int i=1;i<=n;++i)num+=(a[i]-1)/mid;
		if(num<=m)ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld",ans);
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;



int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {

    int N;
    int l;
    cin >>N >>l;
    printf("%d",N+1-l);

}


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

int main() {
  int a;
  cin >> a;
  int L = a/100;
  int R = a%100;
  if (1<=L&&L<=12){
    if (1<=R&&R<=12) puts("AMBIGUOUS");
    else puts("MMYY");
  }
  else if (1<=R&&R<=12) puts("YYMM");
  else puts("NA");
  
  
  return 0;
}


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

int main(void) {
	int N; cin >> N;
	map<int, int> mp;
	int d[N];
	int i, sum = 0;

	for (i = 0; i < N; i++) {
		cin >> d[i];
		mp[d[i]] = 1;
	}

	for (pair<int, int>pa : mp) {
		sum += 1;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
s = list(str(input()))

if n <= 2:
    print(0)

C = [[0]*(n+1) for i in range(3)]
for i in range(n):
    for j in range(3):
        C[j][i+1] = C[j][i]
    if s[i] == 'R':
        C[0][i+1] += 1
    elif s[i] == 'G':
        C[1][i+1] += 1
    else:
        C[2][i+1] += 1
#print(C)

D = [[0]*(n+1) for i in range(3)]
s.reverse()
for i in range(n):
    for j in range(3):
        D[j][i+1] = D[j][i]
    if s[i] == 'R':
        D[0][i+1] += 1
    elif s[i] == 'G':
        D[1][i+1] += 1
    else:
        D[2][i+1] += 1
#print(D)
D = [list(reversed(d)) for d in D]
#print(D)

s.reverse()
ans = 0
for i in range(1, n-1):
    #print(ans)
    if s[i] == 'R':
        ans += C[1][i]*D[2][i+1] + C[2][i]*D[1][i+1]
    elif s[i] == 'G':
        ans += C[0][i]*D[2][i+1] + C[2][i]*D[0][i+1]
    else:
        ans += C[0][i]*D[1][i+1] + C[1][i]*D[0][i+1]
    for j in range(1, i+1):
        if i+j >= n:
            continue
        if s[i-j] != s[i+j] and s[i-j] != s[i] and s[i+j] != s[i]:
            ans -= 1
print(ans)
#print(C[0][1], D[2][3])

Measured memory_bytes: 74276
#include <bits/stdc++.h>
using namespace std;
const int N=5e6;
const int X[4]={0,1,0,-1},Y[4]={1,0,-1,0};

  int n,m,l,r;
  int q[N],v[N];
#define C getchar()
void in()
{
  cin>>n>>m;
  C;
  for (int i=0;++i<=n;C)
    for (int j=0;++j<=m;)
      if (C=='#')
			  v[q[++r]=i*m+j]=1;
}

  int d[N];
void wor()
{
  while (++l<=r)
    {
      int x=(q[l]-1)/m,y=(q[l]-1)%m+1;
      for (int i=4;~--i;)
        if (x+X[i]&&x+X[i]<=n&&y+Y[i]&&y+Y[i]<=m)
          {
            int p=(x+X[i])*m+(y+Y[i]);
            if (!v[p])
              v[p]=1,
              q[++r]=p,
              d[p]=d[q[l]]+1;
          }
    }
}

void out()
{
  cout<<d[q[r]];
}

int main()
{
  in();
  wor();
  out();
  exit(0);
} 

Measured memory_bytes: 14592
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*

*/

ll n,p,p2,visited[300010]={},fact[300010]={},ans=1;
vector<ll> plist;

int main(void){
	cin>>n>>p;
	p2=p;
	reg(i,2,300000){
		if(visited[i]==0){
			plist.push_back(i);
			reg(j,2,300000){
				if(j*i>300000)break;
				visited[i*j]=1;
			}
		}
	}
	rep(i,plist.size()){
		while(p%plist[i]==0){
			fact[i]++;
			p/=plist[i];
		}
		rep(j,fact[i]/n)ans*=plist[i];
	}
	if(n==1){
		cout<<p2<<endl;
	}else if(n==2){
		for(ll i=300000;i<=1000000;i++){
			if(p%(i*i)==0){
				ans*=i;
				break;
			}
		}
		cout<<ans<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3328
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
#define ll long long
const int MAXN=100000+10;
int n,m,e,to[MAXN<<1],nex[MAXN<<1],beg[MAXN],w[MAXN<<1],p[MAXN];
ll d[MAXN],inf=1e18;
inline void insert(int x,int y,int z)
{
	to[++e]=y;
	nex[e]=beg[x];
	beg[x]=e;
	w[e]=z;
}
inline void SPFA(int s)
{
	for(register int i=1;i<=n;++i)d[i]=inf;
	d[s]=0;
	p[s]=1;
	queue<int> q;
	q.push(s);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		p[x]=0;
		for(register int i=beg[x];i;i=nex[i])
			if(d[to[i]]>d[x]+w[i])
			{
				d[to[i]]=d[x]+w[i];
				if(!p[to[i]])
				{
					p[to[i]]=1;
					q.push(to[i]);
				}
			}
	}
}
int main()
{
	scanf("%d",&n);
	for(register int i=1;i<n;++i)
	{
		int u,v,k;
		scanf("%d%d%d",&u,&v,&k);
		insert(u,v,k);
		insert(v,u,k);
	}
	int s;
	scanf("%d%d",&m,&s);
	SPFA(s);
	while(m--)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		printf("%lld\n",d[u]+d[v]);
	}
	return 0;
}

Measured memory_bytes: 5760
import sys

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

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

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

        if x == y:
            return

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

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

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, sys.stdin.readline().strip().split())

# 言語iを使える人のリスト
langs = [[] for _ in range(M)]
for i in range(N):
    tmp = list(map(int, sys.stdin.readline().strip().split()))
    K = tmp[0]
    L = tmp[1:]
    for l in L:
        langs[l-1].append(i)

# print(langs)
uf = UnionFind(N)
for peoples in langs:
    for i in range(len(peoples)-1):
        uf.union(peoples[i], peoples[i+1])

# print(uf.group_count())
if uf.group_count() == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 61984
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 999999999
#define llong long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2
5 1 1
100 1 1
)");
#define cin input
#endif

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

	int t1, t2, x1, x2, y1, y2;
	t1 = x1 = y1 = 0;
	int count = 0;

	REP(i, n)
	{
		cin >> t2 >> x2 >> y2;
		int dt = t2 - t1;
		int dist = abs(x2-x1)+abs(y2-y1);

		if (dist>dt)
			break;
		else
		{
			if(dist%2==1 && dt%2==0)
				break;
			else if(dist%2==0 && dt%2==1)
				break;
		}

		t1 = t2;
		x1 = x2;
		y1 = y2;
		count++;
	}

	if (count == n)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll C[501][501];
ll Ac[501][501];



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

    // input
    ll N, M, Q;
    cin >> N >> M >> Q;

    FOR(i, 0, 501){
        FOR(j, 0, 501){
            C[i][j] = 0;
            Ac[i][j] = 0;
        }
    }

    FOR(i, 0, M){
        ll l, r;
        cin >> l >> r;
        C[l][r]++;
    }

    // 累積和
    FOR(i, 0, 501){
        Ac[i][0] = C[i][0];
        FOR(j, 1, 501){
            Ac[i][j] = Ac[i][j-1] + C[i][j];
        }
    }

    // クエリ
    FOR(_, 0, Q){
        ll p, q;
        cin >> p >> q;

        ll sum = 0;
        FOR(i, p, 501){
            sum += Ac[i][q];
        }
        p(sum);
    }
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}



signed main(){
    int K;cin>>K;


    vint ans(50,49-K+K/50*51);

    for(int i=0;i<K%50;i++)ans[i]+=51;

    cout<<50<<endl;
    rep(i,50){
        if(i)cout<<" ";
        cout<<ans[i];
    }cout<<endl;
    return 0;
}


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

int HelloWorld(){
	cout << "Hello World" << endl;
	return 0;
}

int XCubic(){
	int x;
	cin >> x;
	if (1 <= x && x <= 100){
		x = x*x*x;
		cout << x << endl;
		return 0;
	}
	return 1;
}

int Rectangle(){
	int a, b, area, perimeter;

	cin >> a >>b;
	if (1 <= a && b <= 100){
		area = a*b;
		perimeter = (a + b) * 2;
		cout << area << " " << perimeter << endl;
		return 0;
	}
	return 1;
}

int Watch(){
	int S;
	cin >> S;
	
	
	int D = 60;
	int s = S%D;
	int m = (S / D) % D;
	int h = (S / D) / D;
	if (0 <= S && S <= 86400){
		printf("%u:%u:%u\n", h, m, s);
		return 0;
	}
	
	return 1;
}


int main(){
	//HelloWorld();
	//XCubic();
	//Rectangle();
	Watch();
	return 0;
}

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


using namespace std;

int main(){

    int n, m;
    int t[110];
    long long ans = 0;

    cin  >> n;
    for(int i = 0; i < n;i++){
        cin >> t[i];
        ans += t[i];
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        int p, x;
        cin >> p >> x;
        cout << ans - t[p - 1] + x << endl;
    }

    return 0;
}



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

int main() {
	int n, k;
	string s, t;
	cin >> n >> k;
	cin >> s;
	t = s.substr(k-1, 1);
	if (t == "A")
		s.replace(k-1, 1, "a");
	else if (t == "B")
		s.replace(k-1, 1, "b");
	else if (t == "C")
		s.replace(k-1, 1, "c");
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  if(S[0] == 'S'){
    cout << "Cloudy" << endl;
  }else if(S[0] == 'C'){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 300001;
const ll M = 1;
struct point {
    ll x, y;
    ll i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n & 1)
        return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll tmp = fast_exp(x, n >> 1);
        return tmp * tmp % mod;
    }
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    int test = 0;
    while(_--)
    {
        ll n, m, x = 0, y = 0, ans = 0;
        cin >> n;
        ll a[n + 1];
        map<ll,ll> mp;
        for(int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
        for(int i = n; i >= 1; i--)
        {
            ans += mp[-a[i] - i];
            mp[a[i] - i]++;
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 27920
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n;
	vector<ll> v;
	ll a;
	cin >> n;
	rep(i,n*3){
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());

	ll sum = 0;
	for(int i = 1;i<2*n;i+=2){
		sum += v[i];
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 6128
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  uint32_t N, D;
  cin >> N >> D;

  uint32_t check = 2 * D + 1;
  uint32_t res = 0;
  while (N > check) {
    ++res;
    N -= check;
  }
  if (N > 0) ++res;
  cout << res << endl;

  return 0;
}


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

vector<int>E[10];
int dp[11][2000];
int main() {
	int n, k; scanf("%d%d", &n, &k);
	rep(i, n) {
		int c, g; scanf("%d%d", &c, &g); g--;
		E[g].push_back(c);
	}
	rep(i, 10)sort(E[i].begin(), E[i].end(), greater<>());
	dp[0][0] = 0;
	rep(i, 10)rep(j, k + 1) {
		int sum = 0;
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		rep(t, min(k - j, (int)E[i].size())) {
			sum += E[i][t];
			dp[i + 1][j + t + 1] = max(dp[i + 1][j + t + 1], dp[i][j] + sum + t*(t + 1));
		}
	}
	printf("%d\n", dp[10][k]);
}

Measured memory_bytes: 3384
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}



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

#define   ll    long long int

int isPrime(int n)
{
    int i, j, rt = sqrt(n);
    if (n == 2) return 1;
    if (n < 2) return 0;
    for (i = 2; i <= rt; i++)
    {
        if (n % i == 0)
            return 0;
    }
    return 1;
}

int main( )
{
    int x;
    cin >> x;
    while ( 1 )
    {
        if (isPrime(x) == 1){
            cout << x << '\n';
            return 0;
        }
        x++;
    }
    return 0;
}


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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define F first
#define S second
#define mkp make_pair

typedef pair<int, int> pii;

int main() {
	int n, d;
	while(cin >> n >> d, n || d) {
		vector<vector<int>> vv(n);
		vector<int> p(n);
		rep(i, n) {
			int m;
			cin >> m;
			m++;
			vv[i].assign(m, 0);
			rep(j, m - 1) cin >> vv[i][j + 1];
			reep(j, 1, m) {
				vv[i][j] += vv[i][j - 1];
			}
			p[i] = m - 1;
		}
		bool ok = true;
		int cnt = 0;
		while(1) {
			int M = 0;
			int M2 = 0;
			int c = 0;
			rep(i, n) {
				if(M < vv[i][p[i]]) {
					M2 = M;
					M = vv[i][p[i]];
					c = 1;
				}
				else if(M == vv[i][p[i]]) {
					c++;
				}
				else if(M2 < vv[i][p[i]]) {
					M2 = vv[i][p[i]];
				}
			}
			if(M == 0) break;
			bool update = false;
			rep(i, n) {
				int pos;
				if(c == 1 && vv[i][p[i]] == M) {
					pos = lower_bound(vv[i].begin(), vv[i].end(), M2 - d) - vv[i].begin();
				}
				else {
					pos = lower_bound(vv[i].begin(), vv[i].end(), M - d) - vv[i].begin();
				}
				if(p[i] == pos) continue;
				update = true;
				p[i] = pos;
			}
			if(!update) {
				ok = false;
				break;
			}
		}
		if(ok) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

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

int main(){
    int n;
    cin>>n;
    vector<int>dp(3,0);
    for(int days=0;days<n;days++){
        vector<int>a(3);
        cin>>a[0]>>a[1]>>a[2];
        vector<int>new_dp(3,0);
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(i!=j){
                    new_dp[j]=max(new_dp[j],dp[i]+a[j]);
                }
            }
        }
        dp=new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]});
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int n;
int main(){
	scanf("%d",&n);
	if(n==1||(n&(-n))==n){puts("No");return 0;}
	puts("Yes");
	for(int i=2;i<n;i+=2)
		printf("%d %d\n%d %d\n%d %d\n%d %d\n",1,i,i,i+1,n+i+1,1,n+i,n+i+1);
	printf("%d %d\n",n+1,3);
	if(n%2==0)printf("%d %d\n%d %d\n",n+n-(n&(-n))+1,n,n+n,n&(-n));
}

Measured memory_bytes: 2176
def gcd(x,y):
  while y != 0:
    x,y = y,x%y
  return x
a,b,c,d = map(int,input().split())
e = (c*d)//gcd(c,d)
s = b-a+1
s -= b//c - (a-1)//c
s -= b//d - (a-1)//d
s += b//e - (a-1)//e
print(s)
    
    

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

int main() {
    /*変数定義，入力*/
    ll A, B;
    cin >> A >> B;
    

    //ll A, B;cin >> A >> B;
    //vector<ll> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    
    /*出力*/
    cout << A*B << endl;

    /*終了*/
    return 0;
}

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

int binary(vector<int> &a, int tar){
  int begin = 0, end = a.size() - 1, mid = (begin + end)/2;
  while(begin < mid){
    if(a[mid] < tar){
      begin = mid;
    }else{
      end = mid;
    }
    mid = (begin + end)/2;
  }
  return a[mid];
}


int main(int argc, char *argv[]){
  int n, m;
  while(scanf("%d %d\n", &n, &m)){
    if(n == 0 && m == 0)break;
    int point[n + 1];
    point[0] = 0;
    vector<int> a;
    for (int i = 1; i <= n; i++) {
      scanf("%d\n", &point[i]);
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        a.push_back(point[i] + point[j]);
      }
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i: a){
      int tmp = binary(a, m - i);
      if(i + tmp <= m)
        ans = max(ans, i + tmp);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll sm = 0;
    rep(i, k) sm += a[i];
    cout << sm << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();
    
}


Measured memory_bytes: 3624
s = input()
n = int(input())
for i in range(n):
    t = input().split()
    a = int(t[1])
    b = int(t[2])
    if t[0] == "print":
        print(s[a:b+1])
    elif t[0] =="replace":
        s = s[0:a]+t[3]+s[b+1:len(s)]
    elif t[0] == "reverse":
        u = s[a:b+1]
        s = s[0:a]+u[::-1]+s[b+1:len(s)]
        


Measured memory_bytes: 5616
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;
//ll mod = 998244353;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	//t %= mod;
	if (n % 2 == 1)t *= a;
	return t /*% mod*/;
}

//const int INF = 1001001001;
const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
	vector<pair<ll, ll>> res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0;
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({ a, ex });
	}
	if (N != 1) res.push_back({ N, 1 });
	return res;
}


int main() {
	int n;
	cin >> n;
	int t[] = { 0,0,0,0 };
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s == "AC")t[0]++;
		else if (s == "WA")t[1]++;
		else if (s == "TLE")t[2]++;
		else if (s == "RE")t[3]++;
	}
	cout << "AC x " << t[0] << endl;
	cout << "WA x " << t[1] << endl;
	cout << "TLE x " << t[2] << endl;
	cout << "RE x " << t[3] << endl;
	return 0;
}


Measured memory_bytes: 3640
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64, c: u64, d: u64
    }
    let ret = overlap((a,b), (c,d));
    if let Some(src) = ret {
        println!("{}", src.1 - src.0);
    } else {
        println!("0");
    }
}

fn overlap(a: (u64,u64), b: (u64,u64)) -> Option<(u64,u64)> {
    let left = std::cmp::max(a.0, b.0);
    let right = std::cmp::min(a.1, b.1);
    if left < right {
        Some((left, right))
    } else {
        None
    }
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrr
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            int f = 0;

            List<int> ls = new List<int>();
            int a = 0;
            func function = new func();
            for (int i = 1; i< 1000000; i++)
            {
                if(i == 1)
                {
                    ls.Add(s);
                }
                else
                {
                    ls.Add(function.Freturn(ls[i-2]));
                }

            }
            int ans = 0;
            List<int> lis = new List<int>();
            for(int i = 0; i < 1000000; i++)
            {
                if (lis.Contains(ls[i]) == true)
                {
                    ans = i+1;
                    break;
                }
                else
                {
                    lis.Add(ls[i]);
                }
            }
            Console.WriteLine(ans);

        }
    }
    class func
    {

        public int Freturn(int n)
        {
            if (n % 2 == 0)
            {
                return n / 2;
            }
            else
            {
                return 3 * n + 1;
            }
            ;
        }
    }
}


Measured memory_bytes: 21088
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int mini = INF;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        mini = min(mini, a & (-a));
    }   
    int cnt = 0;
    while(mini > 1){cnt++;mini /= 2;}
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define I using
#define can namespace
#define fly std
#define You int
#define have main
#define kakko ()
#define end return
#define He cin 
#define is >>
#define We cout
#define are <<
#define Enterkey endl

I can fly;

You have kakko{
	You a;
	He is a;
	We are a * a * a;
	We are Enterkey;
	end 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
char s[10];
int main()
{
	cin >> s;
	for (int i = 0; i < 4; ++i) s[i] -= '0';
	int a = s[0] * 10 + s[1];
	int b = s[2] * 10 + s[3];
	if (1 <= a && a <= 12) {
		if(1 <= b && b <= 12) puts("AMBIGUOUS");
		else puts("MMYY");
	} 
	else {
		if(1 <= b && b <= 12) puts("YYMM");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

//const int INF = INT_MAX / 2;

int main() {
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	cout << a[0];
	for (int i = 1; i < n; i++) cout << " " << a[i];
	cout << endl;
	for (int i = 1; i < n; i++) {
		int v = a[i];
		int j = i - 1;
		while(j >=0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j+1] = v;
		cout << a[0];
		for (int i = 1; i < n; i++) cout << " " << a[i];
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
using namespace std;
int main(void) {
	string str;
	cin >> str;
	for (int i = 0; i < 19; i++) {
		if (str[i] == ',')
			str[i] = ' ';
	}

	std::cout << str<< std::endl;
	return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  rep(i,m){
    cin >> s[i] >> c[i];
  }

  int ans = 1000;
  int init = (n == 1) ? 0 :
             (n == 2) ? 10 : 100;
  for(int i = init; i <= 999; ++i){
    bool find = true;
    for(int j = 0; j < m; ++j){
      if(n == 1){
        if(c[j] != i % 10) find = false;
      }
      else if (n == 2){
        if(s[j] == 1){
          if(c[j] != i / 10 % 10) find = false;
        }
        else{
          if(c[j] != i % 10) find = false;
        }
      }
      else{
        if(s[j] == 1){
          if(c[j] != i / 100 % 10) find = false;
        }
        else if(s[j] == 2){
          if(c[j] != i / 10 % 10) find = false;
        }
        else{
          if(c[j] != i % 10) find = false;
        }
      }
    }
    if(find){
      ans = min(ans, i);
    }
  }
  if(ans == 1000) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def solve(n, a_list):
    res = 1
    if 0 in a_list:
        return 0
    for i in range(n):
        res *= a_list[i]
        if res > 10 ** 18:
            return -1
    return res


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(2, [1000000000, 1000000000]) == 1000000000000000000
    assert solve(3, [101, 9901, 999999000001]) == -1
    assert solve(31, [4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0]) == 0


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 21716
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct Team{
	int s_point, s_time, num;
	int w_prob[10];
	
	bool operator<(const Team& another) const{
		if (s_point != another.s_point){
			return (s_point > another.s_point);
		}
		if (s_time != another.s_time){
			return (s_time < another.s_time);
		}
		return(num > another.num);
	}
};

int main(void)
{
	int i, j;
	vector<Team> team(50);

	while(1)
	{
		int m, p ,t, r;
		int m2, p2, t2, r2;

		scanf("%d %d %d %d", &m, &t, &p, &r);
		if (m == 0) break;
		
		for (i = 0; i < t; i++){
			 team[i].num = i+1;
			 team[i].s_point = 0;
			 team[i].s_time = 0;
			 for (j = 0; j < p; j++) team[i].w_prob[j] = 0;
		}

		for (i = 0; i < r; i++){
			scanf("%d %d %d %d", &m2, &t2, &p2, &r2);
			if (r2 == 0){
				team[t2 - 1].s_point++;
				team[t2 - 1].s_time += m2 + 20 * team[t2 - 1].w_prob[p2 - 1];
			}
			else{
				team[t2 - 1].w_prob[p2 - 1]++;
			}
		}

		sort(team.begin(), team.begin() + t );
		for (i = 0; i < t; i++){
			printf("%d", team[i].num);
			if (i != t - 1 && team[i].s_point == team[i + 1].s_point && team[i].s_time == team[i + 1].s_time){
				printf("=");
			}
			else if (i != t - 1){
				printf(",");
			}
		}
		printf("\n");
	}
	
	return(0);
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#include <functional>
#include <iomanip>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>

using ll = long long;
ll INF = LLONG_MAX / 4 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
    int n; cin >> n;
    int h[n]; REP (i,n) cin >> h[i];
    bool ok = true;
    for (int i = n - 2; i >= 0; i--) {
        if (h[i] <= h[i+1]) continue;
        if (h[i] == h[i+1]+1) h[i]--;
        else ok = false;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


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

using namespace std;

int n;
int a[100010];

main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    int sum = 0;
    int cur = 0;
    a[n] = 0;
    n++;
    for(int i = 0; i < n; i++){
        sum += abs(a[i] - cur);
        cur = a[i];
    }
    for(int i = 0; i < n; i++){
        int tmp = sum;
        int cur = (i == 0) ? 0 : a[i - 1];
        tmp -= abs(a[i] - cur);
        if(i + 1 < n) tmp -= abs(a[i] - a[i + 1]);
        if(i + 1 < n) tmp += abs(cur - a[i + 1]);
        if(i + 1 < n) cout << tmp << endl;
    }
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


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

int main(int argc, char *argv[]) {

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

	long d = N % K;

	if (N % K == 0) {
		cout << 0 << endl;
	}else if (d < K / 2){
		cout << d << endl;
	}else if (d < K) {
		cout << K - d << endl;
	}

	return 0;
}


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

int main(){
  string a;
  std::cin >> a;
  if(a[0]==a[1]&& a[1]==a[2])std::cout << "No" << '\n';
  else std::cout << "Yes" << '\n';

  return 0;
}
// #include <bits/stdc++.h>
// using namespace std;
// using ll= long long;
// #define rep(i,n) for (ll i = 0; i < (n); ++i)
//
// int main(){
//   string a;
//   std::cin >> a;
//   if(a[0]==a[1] && a[1]==a[2])std::cout << "No" << '\n';
//   else std::cout << "Yes" << '\n';
//
//   return 0;
// }


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int W;
	int H;
	int x;
	int y;
	int r;
	
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if((x < r) || (y < r)){
		printf("No\n");
	}
	else if((W - r >= x) && (H - r >= y)){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
int f(int curr,string&a){
	if(curr>=a.length()-2) return 0;
	if(a[curr]!='A') return f(curr+1,a);
	if(a[curr+1]=='B' && a[curr+2]=='C') return 1+f(curr+3,a);
	return f(curr+1,a);
}
int main(){
	int n;
	cin>>n;
	vector<int>origin(n);
	vector<int>permu_a(n);
	vector<int>permu_b(n);
	for(int i=0; i<n; i++) origin[i] = i+1;
	for(int i=0; i<n; i++) cin>>permu_a[i];
	for(int i=0; i<n; i++) cin>>permu_b[i];
	int curr = 1;
	int lexi_a=0;
	int lexi_b=0;
	do{
		bool match = true;
		for(int i=0; i<n; i++){
			if(permu_a[i]!=origin[i]) match = false;
		}
		if(match) lexi_a = curr;
		match = true;
		for(int i=0; i<n; i++){
			if(permu_b[i]!=origin[i]) match = false;
		}
		if(match) lexi_b = curr;
		curr++;
		if(lexi_a && lexi_b) break;
	}while(next_permutation(origin.begin(),origin.end()));
	cout<<abs(lexi_a-lexi_b);
}

Measured memory_bytes: 3608
import math

epsilon = 1e-10

def get_grad(v1, v2):
    return v1[0] * v2[1] - v1[1] * v2[0]

def run():
    N = int(input())
    for _ in range(N):
        x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
        _v1 = (x2 - x1, y2 - y1)
        _v2 = (x4 - x3, y4 - y3)
        grad = get_grad(_v1, _v2)
        if abs(grad) < epsilon:
            print('YES')
        else:
            print('NO')

if __name__ == '__main__':
    run()




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

int main(){
  int x;
  cin >> x;
  if(400<=x && x <= 599){
    cout << 8 << endl;
  } else if(600<=x && x <= 799){
    cout <<7 << endl;
  }else if(800<=x && x <= 999){
    cout << 6<< endl;
  }else if(1000<=x && x <= 1199){
    cout << 5<< endl;
  }else if(1200<=x && x <= 1399){
    cout << 4<< endl;
  }else if(1400<=x && x <= 1599){
    cout << 3<< endl;
  }else if(1600<=x && x <= 1799){
    cout << 2<< endl;
  }else if(1800<=x && x <= 1999){
    cout << 1<< endl;
  }
}

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

int main() {
  
  // Variables
  string S, T;
  cin >> S >> T;
  int count = 0;
    
  //Main loop
  for (int i = 0; i < S.size(); i++){
    if (S.at(i) != T.at(i)) {
      count++;
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3900
import sys
input = sys.stdin.readline

# A - Range Product
a, b = map(int, input().split())

if a > 0:
	print('Positive')
elif b >= 0:
	print('Zero')
else:
	if b > 0:
		b == 0
	
	if (abs(a)-abs(b)+1) % 2 == 1:
		print('Negative')
	else:
		print('Positive')

Measured memory_bytes: 3060
import collections as col


def convert(x):
    if x % 4 == 0:
        return 4
    elif x % 2 == 0:
        return 2
    else:
        return 1


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

    count = col.Counter(map(convert, a))

    if count[1] >= 1:
        if count[4] >= count[1]:
            print('Yes')
        elif count[1] == count[4] + 1 and count[2] == 0:
            print('Yes')
        else:
            print('No')

    else:  # count[1] == 0
        if count[4] >= 1:
            print('Yes')
        elif count[2] >= 2:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 11436
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class162
    {
        static void Main()
        {
            string S = Console.ReadLine();
            int N = S.Length;
            string s1 = S.Substring(0, (N - 1) / 2);
            string s2 = S.Substring((N + 1) / 2);
            //Console.WriteLine($"{s1} {s2}");

            if (s1 == s2)
            {
                string a1 = "", a2 = "", b1 = "", b2 = "";
                if (s1.Length % 2 == 1)
                {
                    a1 = s1.Substring(0, (s1.Length - 1) / 2);
                    a2 = new string(s1.Substring((s1.Length + 1) / 2).Reverse().ToArray());

                    b1 = s2.Substring(0, (s2.Length - 1) / 2);
                    b2 = new string(s2.Substring((s2.Length + 1) / 2).Reverse().ToArray());
                }
                else
                {
                    a1 = s1.Substring(0, (s1.Length) / 2);
                    a2 = new string(s1.Substring((s1.Length + 1) / 2).Reverse().ToArray());

                    b1 = s2.Substring(0, (s2.Length) / 2);
                    b2 = new string(s2.Substring((s2.Length + 1) / 2).Reverse().ToArray());
                }

                //Console.WriteLine($"{a1} {a2} {b1} {b2}");
                if (a1 == a2 && b1 == b2)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13268
def solve():
    N,M = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    ans = set([i for i in range(1, N+1)])
    for i in range(M):
        A,B = [int(i) for i in input().split()]
        if H[A-1] < H[B-1]:
            if A in ans:
                ans.remove(A)
        elif H[B-1] < H[A-1]:
            if B in ans:
                ans.remove(B)
        else:
            if A in ans:
                ans.remove(A)
            if B in ans:
                ans.remove(B)
    print(len(ans))

if __name__ == "__main__":
    solve()

Measured memory_bytes: 23844
n = int(input())
d = list(map(int,input().split()))
 
from collections import Counter
q=Counter(d)
 
ans = 1
if q[0]!=1 or d[0]!=0:
  print(0)
  exit()
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

Measured memory_bytes: 18932
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int n, m;
int c[26];
int s[400][26];
int t[400], ssc[400];
void input() {
    cin >> n;
    m = 26;
    for (int i = 0; i < m; i++) cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> s[i][j];
        }
    }
}
void output() {
    for (int i = 0; i < n; i++) {
        cout << t[i] + 1 << newl;
    }
}
int score() {
    V<int> last(m, -1);
    int res = 0;
    for (int i = 0; i < n; i++) {
        res += s[i][t[i]];
        last[t[i]] = i;
        for (int j = 0; j < m; j++) {
            res -= c[j] * (i - last[j]);
        }
    }
    return res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    input();
    int lim = 100000;
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rn(0, n - 1), rc(0, m - 1);
    for (int i = 0; i < n; i++) {
        t[i] = rc(mt);
    }
    int now = score();
    cerr << now << newl;
    for (int co = 0; co < lim; co++) {
        int d = rn(mt), i = rc(mt);
        int be = t[d];
        t[d] = i;
        int sc = score();
        if (sc > now) {
            now = sc;
        } else {
            t[d] = be;
        }
    }
    output();
    cerr << now << newl;
}


Measured memory_bytes: 3716
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N, X, Y;
	cin >> N >> X >> Y;
	VI A(N);
	VI B(N);
	VI C(N);
	REP(i, N) {
		cin >> A[i] >> B[i] >> C[i];
	}
	int dp[41][500][500];
	eREP(i, 40) {
		REP(j, 500) {
			REP(k, 500) {
				dp[i][j][k] = LLINF;
			}
		}
	}

	dp[0][0][0] = 0;
	REP(i, N) {
		eREP(j, 400) {
			eREP(k, 400) {

				if (dp[i][j][k] == LLINF)continue;

				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);

				dp[i + 1][j + A[i]][k + B[i]] = min(dp[i + 1][j + A[i]][k + B[i]], dp[i][j][k] + C[i]);
			}
		}
	}

	int ans = LLINF;
	eFOR(i, 1, 400) {
		eFOR(j, 1, 400) {
			if (i*Y == j * X) ans = min(ans, dp[N][i][j]);
		}
	}
	if (ans == LLINF)ans = -1;

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 80384